Skip to content
This repository

Emacs extension to increase selected region by semantic units.

branch: master

Merge pull request #139 from zenspider/enh-ruby-mode

Better expansions for enh-ruby-mode.
latest commit 49514a1dc0
Magnar Sveen authored
Octocat-spinner-32 features Improve speed of basic expansions March 14, 2014
Octocat-spinner-32 .gitignore Use Carton for dev-dependencies and CI March 11, 2013
Octocat-spinner-32 .travis.yml Update path to cask November 11, 2013
Octocat-spinner-32 Cask Move from Carton to Cask August 11, 2013
Octocat-spinner-32 README.md Add @titaniumbones to list of contributors. March 14, 2014
Octocat-spinner-32 cc-mode-expansions.el require er-basic-expansions in cc-mode-expansions January 01, 2014
Octocat-spinner-32 clojure-mode-expansions.el fix byte compile warning for clojure-mode-expansions December 31, 2013
Octocat-spinner-32 cperl-mode-expansions.el A trivial test case for cperl sub-routine expension. March 02, 2013
Octocat-spinner-32 css-mode-expansions.el Turn er/enable-mode-expansions into a function. October 25, 2012
Octocat-spinner-32 enh-ruby-mode-expansions.el Cleanup per magnar's feedback. April 06, 2014
Octocat-spinner-32 er-basic-expansions.el Improve speed of basic expansions March 14, 2014
Octocat-spinner-32 erlang-mode-expansions.el Turn er/enable-mode-expansions into a function. October 25, 2012
Octocat-spinner-32 expand-region-core.el fix regression by reverting a change to expand-region-core.el January 04, 2014
Octocat-spinner-32 expand-region-custom.el Enable text-mode-expansions by default except for a few modes October 18, 2012
Octocat-spinner-32 expand-region-pkg.el Release 0.10.0 January 26, 2014
Octocat-spinner-32 expand-region.el fix main byte compiler warnings January 03, 2014
Octocat-spinner-32 feature-mode-expansions.el Turn er/enable-mode-expansions into a function. October 25, 2012
Octocat-spinner-32 html-mode-expansions.el fix html-mode byte compiler warnings January 03, 2014
Octocat-spinner-32 js-mode-expansions.el Bugfix: Update function name in js-mode. January 04, 2014
Octocat-spinner-32 js2-mode-expansions.el fix js2-mode byte compiler warnings January 03, 2014
Octocat-spinner-32 jsp-expansions.el Replace all uses of `looking-back` June 10, 2013
Octocat-spinner-32 latex-mode-expansions.el fix latex-mode byte compiler warnings January 03, 2014
Octocat-spinner-32 nxml-mode-expansions.el fix nxml-mode byte compiler warnings January 03, 2014
Octocat-spinner-32 octave-expansions.el add function declaration for octave-mod function January 05, 2014
Octocat-spinner-32 python-el-expansions.el add require python, rename functions January 05, 2014
Octocat-spinner-32 python-el-fgallina-expansions.el Improve er/mark-python-block-and-decorator November 23, 2012
Octocat-spinner-32 python-mode-expansions.el py-goto-beyond-clause not known, use py-end-of-clause-bol March 07, 2014
Octocat-spinner-32 ruby-mode-expansions.el remove unnecessary local file variable January 25, 2014
Octocat-spinner-32 run-tests.sh Move from Carton to Cask August 11, 2013
Octocat-spinner-32 run-travis-ci.sh Travis: Disable fgallina tests below Emacs 24.3 April 08, 2013
Octocat-spinner-32 sml-mode-expansions.el add function declaration for sml-mode byte compilation warning January 05, 2014
Octocat-spinner-32 text-mode-expansions.el Turn er/enable-mode-expansions into a function. October 25, 2012
Octocat-spinner-32 the-org-mode-expansions.el Add tests for org-mode, and fix a bug in #136 March 14, 2014
Octocat-spinner-32 watch-tests.watchr Use Carton for dev-dependencies and CI March 11, 2013
Octocat-spinner-32 web-mode-expansions.el Fix web-mode-expansions that must never have worked January 27, 2014
README.md

expand-region.el Build Status

Expand region increases the selected region by semantic units. Just keep pressing the key until it selects what you want.

An example:

(setq alphabet-start "abc def")

With the cursor 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)

You can contract the region again with a negative prefix, if you expand too far.

Video

You can watch an intro to expand-region at Emacs Rocks.

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-symbol-with-prefix
er/mark-next-accessor
er/mark-method-call
er/mark-inside-quotes
er/mark-outside-quotes
er/mark-inside-pairs
er/mark-outside-pairs
er/mark-comment
er/mark-url
er/mark-email
er/mark-defun

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 add it to the expand-region.el-file, 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

All changes must be accompanied by feature tests. They are written in Ecukes, a Cucumber for Emacs.

To fetch the test dependencies, install cask if you haven't already, then:

$ cd /path/to/expand-region
$ cask

Run the tests with:

$ ./run-tests.sh

If feature tests are missing for the mode you are changing, please make sure to add a set of basic tests around the functionality you're changing.

Contributors

  • Josh Johnston contributed er/contract-region
  • Le Wang contributed consistent handling of the mark ring, expanding into pairs/quotes just left of the cursor, and general code clean-up.
  • Raimon Grau added support for when transient-mark-mode is off.
  • Roland Walker added option to copy the contents of the most recent action to a register, and some fixes.
  • Damien Cassou added option to continue expanding/contracting with fast keys after initial expand.
  • Sylvain Rousseau fixed loads of little annoyances.
  • Ryan Mulligan cleaned up a lot of byte compilation warnings.

Language specific contributions

Thanks!

Changelog

From 0.9 to 0.10

  • Smarter expansion of ruby heredoc contents (Steve Purcell)
  • Add enh-ruby-mode expansions (Bradley Wright)
  • Add basic expansion er/mark-defun
  • Big cleanup of byte compilation warnings (Ryan Mulligan)
  • Better performance
  • Lots of bugfixes

From 0.8 to 0.9

  • Improve org-, clojure-, python-, latex-, cc- and ruby-modes
  • Add basic expansions: email and url
  • Add sml-mode expansions (Alexis Gallagher)
  • Add cperl-mode expansions (Kang-min Liu)
  • Add octave-mode expansions (Mark Hepburn)
  • Add web-mode expansions (Rotem Yaari)
  • Use Carton for dev-dependencies
  • Fix bad behavior in minibuffer (Sylvain Rousseau)
  • More robust comment expansions
  • Improve loading of expansions for all major modes

From 0.7 to 0.8

  • Improve js-, ruby-, python- and latex-modes
  • Support built-in javascript-mode
  • Handle narrowed buffers correctly
  • Include mode-specific expansions when autoloading
  • Provide option to copy the contents of the most recent action to a register
  • Add cc-mode specific expansions
  • Add customization to turn off skipping whitespace when expanding
  • Continue expanding/contracting with one key press (optional)

License

Copyright (C) 2011-2013 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/.

Something went wrong with that request. Please try again.