I've got er/expand-region behaving very strangely and I don't understand what I did wrong (besides upgrading to Emacs 25.1.50).

If I've got this in an elisp file:

(defun foo (p) (* 2 2) p)

(that piece of code is just an example)

and I'm on the asterisk and start doing expand-region I get:

  • "*"(OK)
  • "* 2 2" (OK)
  • "* 2 2)" (WRONG)
  • "(* 2 2)" (kinda OK I guess)
  • "(* 2 2) p)" (WRONG)
  • "(defun foo (p) (* 2 2) p)" (kinda OK I guess)

I've got the exact same problem with Clojure files.

Previously er/expand-region used to select things in between matching parenthesis. The problem is that now I need more keypresses to select what I want and I keep ending up with unbalanced elisp / Clojure code because I cut/kill non-balanced pieces of code.

I tried both calling er/expand-region using the shortcut or calling it manually: same result. From my testing it looks like, say, when in Clojure the clojure-mode-expansion list is used etc.

I'm not familiar at all with how er/expand-region works internally but it's as if something was called before er/mark-inside-pairs and er/mark-outside-pairs and that that thing was matching the right parenthesis.

Any idea as to what went wrong and how I could fix this?

I tried both my old er/expand-region and the latest ELPA one.

  • 1
    I am on the latest version of emacs-25 dev branch but I cannot replicate what you are seeing; my expansion proceeds in this order: "*", "* 2 2", "(* 2 2)", "defun foo (p) (* 2 2) p", "(defun foo (p) (* 2 2) p)". Feb 25, 2016 at 17:55
  • @Kaushal Modi: thank you very much for trying, it's exactly how it behaved for me previously (I was on Emacs 25.0.50, not 25.1.50 previously). I'll keep trying to make it work: I have not idea what went wrong. I'll delete / re-install and try several versions (I'll see what I kind find on melpa, melpa-stable, try with my old Emacs [which I still have working in another user directory], etc.). Feb 25, 2016 at 18:45
  • @Kaushal Modi: actually I love expand-region and I'm so used to it working in the way/order you described that I keep making mistakes now that it's doing "weird non balanced expands" :-/ Feb 25, 2016 at 18:46
  • First try it in an emacs -Q session .. In that session, load just this one package and see if you can recreate the same problem with er/expand-region. Most likely it will work fine and then you would need to bisect your init.el to find the culprit. Feb 25, 2016 at 18:52
  • Are you using the latest expand-region version from MELPA?
    – user227
    Feb 26, 2016 at 22:12

2 Answers 2


I think this is related to some breaking changes in Emacs 25.0.*


I'm still running 25.0.* and solved the problem by installing expand-region from MELPA where a fix to workaround Emacs versions 25+ has been implemented.

Note: Do not use the version (0.10.0) in MELPA stable since it does not work.

  • I am using the latest version of expand-region form Melpa and latest build of emacs from its emacs-25 branch as of today (25.0.93.x) and things are working fine as expected. Apr 29, 2016 at 17:46

The latest official Emacs release is 24.5, and the developer of expand-region is not supporting development versions (i.e., 25+). This is not unreasonable, as there are frequent changes in the Emacs 25 branch that break and un-break expand-region, such as demonstrated in the question here. Keeping up with them would be a big job for little benefit.

Solutions to the problem:

  • stick to an official Emacs release (i.e., 24.5)
  • if you use a development version of Emacs, stick to a specific release that works with expand-region. Test builds of new versions before you replace your old versions
  • I am using the latest version of expand-region form Melpa and latest build of emacs from its emacs-25 branch as of today (25.0.93.x) and things are working fine as expected. Apr 29, 2016 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.