GNU-devel ELPA - expand-region

expand-region Atom Feed

Description
Increase selected region by semantic units.
Latest
expand-region-1.0.0.0.20240919.142744.tar (.sig), 2024-Sep-19, 260 KiB
Maintainer
Magnar Sveen <magnars@gmail.com>
Website
https://github.com/magnars/expand-region.el
Browse ELPA's repository
CGit or Gitweb
Badge

To install this package from Emacs, use package-install or list-packages.

Full description

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)

There's also `er/contract-region` if you expand too far.

## Video

You can [watch an intro to expand-region at Emacs Rocks](http://emacsrocks.com/e09.html).

## 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 ()
      (setq-local er/try-expand-list (append
                                er/try-expand-list
                                '(mark-paragraph
                                  mark-page))))

    (er/enable-mode-expansions 'text-mode #'er/add-text-mode-expansions)

Add that to its own file, and require 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

Changes to `expand-region-core` itself must be accompanied by feature tests.
They are written in [Ecukes](http://ecukes.info), a Cucumber for Emacs.

To fetch the test dependencies:

    $ cd /path/to/expand-region
    $ git submodule init
    $ git submodule update

Run the tests with:

    $ ./util/ecukes/ecukes features

If you want to add feature-tests for your mode-specific expansions as well,
that is utterly excellent.

## Contributors

* [Josh Johnston](https://github.com/joshwnj) contributed `er/contract-region`
* [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.
* [Matt Briggs](https://github.com/mbriggs) contributed expansions for ruby-mode.
* [Ivan Andrus](https://github.com/gvol) contributed expansions for python-mode, text-mode, LaTeX-mode and nxml-mode.
* [Raimon Grau](https://github.com/kidd) added support for when transient-mark-mode is off.
* [Gleb Peregud](https://github.com/gleber) contributed expansions for erlang-mode.
* [fgeller](https://github.com/fgeller) and [edmccard](https://github.com/edmccard) contributed better support for python and its multiple modes.
* [François Févotte](https://github.com/ffevotte) contributed expansions for C and C++.
* [Roland Walker](https://github.com/rolandwalker) added option to copy the contents of the most recent action to a register, and some fixes.
* [Damien Cassou](https://github.com/DamienCassou) added option to continue expanding/contracting with fast keys after initial expand.

Thanks!

Old versions

expand-region-1.0.0.0.20240119.103925.tar.lz2024-Mar-3138.2 KiB
expand-region-1.0.0.0.20240104.172133.tar.lz2024-Jan-0438.4 KiB
expand-region-1.0.0.0.20231020.62055.tar.lz2023-Oct-2038.2 KiB
expand-region-0.11.0.0.20231015.205154.tar.lz2023-Oct-1638.2 KiB
expand-region-0.11.0.0.20231015.151149.tar.lz2023-Oct-1527.7 KiB
expand-region-0.11.0.0.20200225.182539.tar.lz2020-Dec-1426.6 KiB
expand-region-0.11.0.0.20200225.132539.tar.lz2021-Oct-0926.6 KiB