bo0ts/expand-region.el — comment on commit 83644ffdee46786bdc3db0d54be286493b3c1e95
File:  line 0
By gvol:

Yes. It happens whenever an `er/mark-*` function selects a region which starts with characters from `er--space-str` and selects the same region if called again. For example `mark-defun` in `emacs-lisp-mode` selects the line before as well (if it's blank). Then `er/expand-region` skips past these characters (for good reason) before starting the expansion. The problem is that the newly selected region starts before the value of `start` that is saved when in fact it was the same as before.

The problem is a little more general though since, for example, `mark-defun` in `emacs-lisp-mode` selects the final newline and `er/mark-outside-pairs` does not. This means that if I add the following to `er/try-expand-list` I will select essentially the same region twice which I find undesirable. Maybe it would be best to check if the new region differs only by characters in `er--space-str` both at the beginning and the end.

(defun er/mark-defun ()
"Mark a top level function definition based on current major mode."
(interactive)
(er--setup)
(mark-defun)
;;(skip-chars-forward er--space-str)
)

The more I think about it, the more I think it should be fixed in `er/expand-region` rather than relying on the `er/mark-*` functions to be "well behaved". Indeed it might be desirable to have those whitespace characters selected rather than skipping past. It's also not useful to increase the selection when it only differs by whitespace.