• Stars
    star
    1,367
  • Rank 34,394 (Top 0.7 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created almost 13 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Emacs extension to increase selected region by semantic units.

Build Status Coverage Status GNU ELPA MELPA MELPA Stable

expand-region.el

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)

If you expand too far, you can contract the region by pressing - (minus key), or by prefixing the shortcut you defined with a negative argument: C-- C-=.

Maintenance warning

I use this package every day, and have been doing so for years. It just works. At least, it works for all my use cases. And if it breaks somehow, I fix it.

However, it has become painfully clear to me that I don't have time to fix problems I don't have. It's been years since I could keep pace with the issues and pull requests. Whenever I try, I keep getting feedback that my fix isn't good enough by some standard I don't particularly care about.

So, I have closed the issue tracker and the pull requests. I hope you can happily use this package, just like I do. If it doesn't work for you, then I'm sorry. Thankfully Emacs is infinitely malleable, you can probably fix it yourself.

TLDR: I am still maintaining this package, but I am no longer crowdsourcing a list of issues.

Video

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

Installation

I highly recommend installing expand-region through elpa.

It's available on MELPA:

M-x package-install expand-region

Via use-package:

(use-package expand-region
  :bind ("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-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.
  • Lefteris Karapetsas added subword-mode expansions.

Language specific contributions

Thanks!

Changelog

From 0.11 to 0.12 (WIP)

  • Option expand-region-subword-enabled to enable subword expansions
  • Improve web-mode expansions (Renato F)
  • Fixes for cc-mode expansions (Wilfred Hughes)
  • Fixes for org-mode expansions (Wilfred Hughes)
  • Fix unnecessary unfolding in org-mode
  • Fix bug with transient-mark-mode (Russell Black)
  • Fix problems with auto-loading (Philippe Vaucher, Wilfred Hughes)

From 0.10 to 0.11

  • Option expand-region-smart-cursor to keep cursor at beginning of region if it is there (Andrea Orru)
  • Add subword-mode expansions (Lefteris Karapetsas)
  • Improve enh-ruby-mode expansions (Ryan Davis)
  • Improve nxml-mode expansions (Maksim Grinman)
  • Improve org-mode expansions (Matt Price)
  • Improve js-mode expansions
  • Better performance
  • Lots of bugfixes

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-2019 Magnar Sveen

Author: Magnar Sveen [email protected] 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/.

More Repositories

1

multiple-cursors.el

Multiple cursors for emacs.
Emacs Lisp
2,294
star
2

dash.el

A modern list library for Emacs
Emacs Lisp
1,669
star
3

s.el

The long lost Emacs string manipulation library.
Emacs Lisp
1,030
star
4

prone

Better exception reporting middleware for Ring.
Clojure
512
star
5

optimus

A Ring middleware for frontend performance optimization.
Clojure
364
star
6

stasis

Some Clojure functions for creating static websites.
Clojure
348
star
7

parens-of-the-dead

A series of zombie-themed games written with Clojure and ClojureScript.
Clojure
153
star
8

mark-multiple.el

An extension to emacs that sorta lets you mark several regions at once
Emacs Lisp
113
star
9

string-edit.el

Avoid escape nightmares by editing strings in a separate buffer
Emacs Lisp
105
star
10

tagedit

A collection of paredit-like functions for editing in html-mode.
Emacs Lisp
99
star
11

multifiles.el

Work in progress: View and edit parts of multiple files in one buffer
Emacs Lisp
76
star
12

fold-this.el

Fold the active region in Emacs
Emacs Lisp
73
star
13

change-inner.el

Emacs version of vim's ci and co commands
Emacs Lisp
64
star
14

angular-snippets.el

Yasnippets for AngularJS
Emacs Lisp
45
star
15

autolint

Autolint watches your files for jslint-errors
JavaScript
43
star
16

kaocha-runner.el

An emacs package for running Kaocha tests via CIDER.
Emacs Lisp
34
star
17

smart-forward.el

semantic navigation based on expand-region.el
Emacs Lisp
31
star
18

java-time-literals

A Clojure library that defines literals for java.time classes.
Clojure
29
star
19

hardcore-mode.el

Disable arrow keys + optionally backspace and return
Emacs Lisp
28
star
20

confair

Confair is a configuration library for Clojure.
Clojure
26
star
21

parens-of-the-dead-s2

The code for Parens of the Dead season 2
Clojure
23
star
22

emacsd-reboot

Reboot of .emacs.d
Emacs Lisp
23
star
23

yesql-ghosts

Display ghostly yesql defqueries inline, in Emacs
Emacs Lisp
18
star
24

emacsrocks.com

The emacsrocks.com site implemented in Clojure with Stasis and Optimus
Clojure
16
star
25

catenate

A deprecated Ring middleware to serve concatenated static files with cache buster URLs in production.
Clojure
16
star
26

realize

Realizing clojure data structures, no more laziness
Clojure
15
star
27

test-with-files

A Clojure library to easily write tests with files.
Clojure
15
star
28

datomic-type-extensions

A Clojure library that wraps Datomic API functions to add type extensions.
Clojure
14
star
29

datoms-differ

Find the diff between two txes in datoms.
Clojure
14
star
30

datomic-snippets

Yasnippets for Datomic.
Emacs Lisp
14
star
31

mapdown

A lightweight markup format to turn strings into maps in Clojure.
Clojure
13
star
32

zombie-clj

An zombie themed web game made with Clojure and ClojureScript
Clojure
13
star
33

cljs-styles

Vendor prefixes for React inline styles with ClojureScript.
Clojure
13
star
34

html5-walker

Search and replace in HTML5 strings.
Clojure
12
star
35

what-the-emacsd

The code for http://whattheemacsd.com
HTML
11
star
36

www.parens-of-the-dead.com

The code that generates parens-of-the-dead.com
Clojure
11
star
37

kaocha-noyoda

Don't talk like yoda. This kaocha plugin lets you write `(is (= actual expected))`.
Clojure
11
star
38

Zombie-TDD

Bli med når jeg lager et nettspill fra scratch med javascript på både frontend og backend. Det blir zombier, mafia og testdrevet utvikling.
JavaScript
10
star
39

annoying-arrows-mode.el

Emacs gets annoyed when you navigate around your document one char at a time.
Emacs Lisp
10
star
40

helpful-loader

A Clojure library to load resources with helpful error messages.
Clojure
9
star
41

buster-mode

A minor mode for emacs to speed up development when writing tests with Buster.JS
Emacs Lisp
8
star
42

stubadub

A small stubbing library for Clojure and ClojureScript
Clojure
8
star
43

bang.el

Used to be a modern list library for Emacs (renamed to dash)
Emacs Lisp
8
star
44

optimus-angular

Angular.JS optimizations for Optimus
Clojure
8
star
45

buster.tmbundle

TextMate bundle for Buster.js
6
star
46

java-time-dte

Datomic type extensions for java.time classes
Clojure
6
star
47

optimus-img-transform

An Optimus image transformation middleware.
Clojure
6
star
48

simplezen.el

A simple subset of zencoding-mode for Emacs
Emacs Lisp
5
star
49

zombieclj-s02

Koden til ZombieCLJ Sesong 2
CSS
5
star
50

server-facade

Code and slides belonging to my JavaZone-talk about wrapping your ajax-calls to get cleaner code and nicer testing.
JavaScript
4
star
51

blockout

Recreating one of my first games for the web to learn Canvas.
JavaScript
4
star
52

naive-xml-reader

A naive Clojure library that turns XML into maps.
Clojure
4
star
53

norsk-extreme-startup

Oversatt til norsk og tilpassett FINN
Ruby
3
star
54

roll20-scripts

Scripts for roll20
JavaScript
3
star
55

optimus-jsx

A React JSX asset loader for Optimus.
JavaScript
3
star
56

crappy-jsp-mode

Seriously, this is not a good jsp-mode, it just solves some of my problems
Emacs Lisp
3
star
57

optimus-less

A LESS asset loader for Optimus.
Clojure
3
star
58

zombieclj.no

Koden bak www.zombieclj.no
Clojure
2
star
59

zombieclj-s2

Koden for andre sesong av Zombie CLJ.
CSS
2
star
60

mytomatoes.clj

mytomatoes.com rescue operation
Clojure
2
star
61

creator.js

A tiny library for creating create-methods for your objects.
JavaScript
2
star
62

buster-snippets.el

Yasnippets for the Buster test framework.
Emacs Lisp
2
star