forked from magnars/expand-region.el
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b8d34c3
Showing
5 changed files
with
629 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# expand-region.el | ||
|
||
Expand region increases the region by semantic units for each run. | ||
|
||
As an example: | ||
|
||
(setq alphabet-start "abc def") | ||
|
||
With the cursur at the c, it starts by marking the entire word `abc`, then | ||
expand to the contents of the quotes `abc def`, then to the entire quote | ||
`"abc def"`, then to the contents of the sexp `setq alphabet-start "abc def"` | ||
and finally to the entire sexp. | ||
|
||
You can set it up like this: | ||
|
||
(require 'expand-region) | ||
(global-set-key (kbd "C-@") 'er/expand-region) | ||
|
||
## Language support | ||
|
||
Expand region works fairly well with most languages, due to the general | ||
nature of the basic expansions: | ||
|
||
er/mark-word | ||
er/mark-symbol | ||
er/mark-method-call | ||
er/mark-inside-quotes | ||
er/mark-outside-quotes | ||
er/mark-inside-pairs | ||
er/mark-outside-pairs | ||
|
||
However, most languages also will benefit from some specially crafted | ||
expansions. For instance, expand-region comes with these extra expansions for | ||
html-mode: | ||
|
||
er/mark-html-attribute | ||
er/mark-inner-tag | ||
er/mark-outer-tag | ||
|
||
You can add your own expansions to the languages of your choice simply by | ||
creating a function that looks around point to see if it's inside or looking | ||
at the construct you want to mark, and if so - mark it. | ||
|
||
There's plenty of examples to look at in these files. | ||
|
||
After you make your function, add it to a buffer-local version of | ||
the `er/try-expand-list`. | ||
|
||
Example: | ||
|
||
Let's say you want expand-region to also mark paragraphs and pages in | ||
text-mode. Incidentally Emacs already comes with `mark-paragraph` and | ||
`mark-page`. To add it to the try-list, do this: | ||
|
||
(defun er/add-text-mode-expansions () | ||
(make-variable-buffer-local 'er/try-expand-list) | ||
(setq er/try-expand-list (append | ||
er/try-expand-list | ||
'(mark-paragraph | ||
mark-page)))) | ||
|
||
(add-hook 'text-mode-hook 'er/add-text-mode-expansions) | ||
|
||
Add that to its own file, and include it at the bottom of this one, | ||
where it says "Mode-specific expansions" | ||
|
||
**Warning:** Badly written expansions might slow down expand-region | ||
dramatically. Remember to exit quickly before you start traversing | ||
the entire document looking for constructs to mark. | ||
|
||
## Contribute | ||
|
||
If you make some nice expansions for your favorite mode, it would be | ||
great if you opened a pull-request. The repo is at: | ||
|
||
https://github.com/magnars/expand-region.el | ||
|
||
## License | ||
|
||
Copyright (C) 2011 Magnar Sveen | ||
|
||
Author: Magnar Sveen <magnars@gmail.com> | ||
Keywords: marking region | ||
|
||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
;;; css-mode-expansions.el --- CSS-specific expansions for expand-region | ||
|
||
;; Copyright (C) 2011 Magnar Sveen | ||
|
||
;; Author: Magnar Sveen <magnars@gmail.com> | ||
;; Keywords: marking region | ||
|
||
;; This program is free software; you can redistribute it and/or modify | ||
;; it under the terms of the GNU General Public License as published by | ||
;; the Free Software Foundation, either version 3 of the License, or | ||
;; (at your option) any later version. | ||
|
||
;; This program is distributed in the hope that it will be useful, | ||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
;; GNU General Public License for more details. | ||
|
||
;; You should have received a copy of the GNU General Public License | ||
;; along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
;;; Commentary: | ||
|
||
;; For now I have only found the need for mark-css-declaration. | ||
;; | ||
;; Feel free to contribute any other expansions for CSS at | ||
;; | ||
;; https://github.com/magnars/expand-region.el | ||
|
||
;;; Code: | ||
|
||
(defun er/mark-css-declaration () | ||
"Marks one CSS declaration, eg. font-weight: bold;" | ||
(interactive) | ||
(search-backward-regexp "[;{] ?" (line-beginning-position)) | ||
(forward-char) | ||
(set-mark (point)) | ||
(search-forward ";" (line-end-position)) | ||
(exchange-point-and-mark)) | ||
|
||
(defun er/add-css-mode-expansions () | ||
"Adds CSS-specific expansions for buffers in css-mode" | ||
(make-variable-buffer-local 'er/try-expand-list) | ||
(setq er/try-expand-list (append | ||
er/try-expand-list | ||
'(er/mark-css-declaration)))) | ||
|
||
(add-hook 'css-mode-hook 'er/add-css-mode-expansions) | ||
|
||
(provide 'css-mode-expansions) | ||
|
||
;; css-mode-expansions.el ends here |
Oops, something went wrong.