|
| 1 | +# expand-region.el |
| 2 | + |
| 3 | +Expand region increases the selected region by semantic units. Just keep |
| 4 | +pressing the key until it selects what you want. |
| 5 | + |
| 6 | +An example: |
| 7 | + |
| 8 | + (setq alphabet-start "abc def") |
| 9 | + |
| 10 | +With the cursor at the `c`, it starts by marking the entire word `abc`, then |
| 11 | +expand to the contents of the quotes `abc def`, then to the entire quote |
| 12 | +`"abc def"`, then to the contents of the sexp `setq alphabet-start "abc def"` |
| 13 | +and finally to the entire sexp. |
| 14 | + |
| 15 | +You can set it up like this: |
| 16 | + |
| 17 | + (require 'expand-region) |
| 18 | + (global-set-key (kbd "C-=") 'er/expand-region) |
| 19 | + |
| 20 | +You can contract the region again with a negative prefix, if you expand too far. |
| 21 | + |
| 22 | +## Video |
| 23 | + |
| 24 | +You can [watch an intro to expand-region at Emacs Rocks](http://emacsrocks.com/e09.html). |
| 25 | + |
| 26 | +## Language support |
| 27 | + |
| 28 | +Expand region works fairly well with most languages, due to the general |
| 29 | +nature of the basic expansions: |
| 30 | + |
| 31 | + er/mark-word |
| 32 | + er/mark-symbol |
| 33 | + er/mark-method-call |
| 34 | + er/mark-comment |
| 35 | + er/mark-comment-block |
| 36 | + er/mark-inside-quotes |
| 37 | + er/mark-outside-quotes |
| 38 | + er/mark-inside-pairs |
| 39 | + er/mark-outside-pairs |
| 40 | + |
| 41 | +However, most languages also will benefit from some specially crafted |
| 42 | +expansions. For instance, expand-region comes with these extra expansions for |
| 43 | +html-mode: |
| 44 | + |
| 45 | + er/mark-html-attribute |
| 46 | + er/mark-inner-tag |
| 47 | + er/mark-outer-tag |
| 48 | + |
| 49 | +You can add your own expansions to the languages of your choice simply by |
| 50 | +creating a function that looks around point to see if it's inside or looking |
| 51 | +at the construct you want to mark, and if so - mark it. |
| 52 | + |
| 53 | +There's plenty of examples to look at in these files. |
| 54 | + |
| 55 | +After you make your function, add it to a buffer-local version of |
| 56 | +the `er/try-expand-list`. |
| 57 | + |
| 58 | +**Example:** |
| 59 | + |
| 60 | +Let's say you want expand-region to also mark paragraphs and pages in |
| 61 | +text-mode. Incidentally Emacs already comes with `mark-paragraph` and |
| 62 | +`mark-page`. To add it to the try-list, do this: |
| 63 | + |
| 64 | + (defun er/add-text-mode-expansions () |
| 65 | + (make-variable-buffer-local 'er/try-expand-list) |
| 66 | + (setq er/try-expand-list (append |
| 67 | + er/try-expand-list |
| 68 | + '(mark-paragraph |
| 69 | + mark-page)))) |
| 70 | + |
| 71 | + (add-hook 'text-mode-hook 'er/add-text-mode-expansions) |
| 72 | + |
| 73 | +Add that to its own file, and add it to the `expand-region.el`-file, |
| 74 | +where it says "Mode-specific expansions" |
| 75 | + |
| 76 | +**Warning:** Badly written expansions might slow down expand-region |
| 77 | +dramatically. Remember to exit quickly before you start traversing |
| 78 | +the entire document looking for constructs to mark. |
| 79 | + |
| 80 | +## Contribute |
| 81 | + |
| 82 | +If you make some nice expansions for your favorite mode, it would be |
| 83 | +great if you opened a pull-request. The repo is at: |
| 84 | + |
| 85 | + https://github.com/magnars/expand-region.el |
| 86 | + |
| 87 | +All changes must be accompanied by feature tests. |
| 88 | +They are written in [Ecukes](http://ecukes.info), a Cucumber for Emacs. |
| 89 | + |
| 90 | +To fetch the test dependencies: |
| 91 | + |
| 92 | + $ cd /path/to/expand-region |
| 93 | + $ git submodule init |
| 94 | + $ git submodule update |
| 95 | + |
| 96 | +Run the tests with: |
| 97 | + |
| 98 | + $ ./util/ecukes/ecukes features |
| 99 | + |
| 100 | +If feature tests are missing for the mode you are changing, please make |
| 101 | +sure to add a set of basic tests around the functionality you're changing. |
| 102 | + |
| 103 | +## Contributors |
| 104 | + |
| 105 | +* [Josh Johnston](https://github.com/joshwnj) contributed `er/contract-region` |
| 106 | +* [Le Wang](https://github.com/lewang) contributed consistent handling of the mark ring, expanding into pairs/quotes just left of the cursor, and general code clean-up. |
| 107 | +* [Matt Briggs](https://github.com/mbriggs) contributed expansions for ruby-mode. |
| 108 | +* [Ivan Andrus](https://github.com/gvol) contributed expansions for python-mode, text-mode, LaTeX-mode and nxml-mode. |
| 109 | +* [Raimon Grau](https://github.com/kidd) added support for when transient-mark-mode is off. |
| 110 | +* [Gleb Peregud](https://github.com/gleber) contributed expansions for erlang-mode. |
| 111 | +* [fgeller](https://github.com/fgeller) and [edmccard](https://github.com/edmccard) contributed better support for python and its multiple modes. |
| 112 | + |
| 113 | +Thanks! |
| 114 | + |
| 115 | +## License |
| 116 | + |
| 117 | +Copyright (C) 2011 Magnar Sveen |
| 118 | + |
| 119 | +Author: Magnar Sveen <[email protected]> |
| 120 | +Keywords: marking region |
| 121 | + |
| 122 | +This program is free software; you can redistribute it and/or modify |
| 123 | +it under the terms of the GNU General Public License as published by |
| 124 | +the Free Software Foundation, either version 3 of the License, or |
| 125 | +(at your option) any later version. |
| 126 | + |
| 127 | +This program is distributed in the hope that it will be useful, |
| 128 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 129 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 130 | +GNU General Public License for more details. |
| 131 | + |
| 132 | +You should have received a copy of the GNU General Public License |
| 133 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
0 commit comments