I notice that some of the evil around operators are greedy. As in they grab space around the surrounding delimiters. One such operator is the a"
.
Assuming that my cursor is |
when I use va"
the selection contains a whitespace around it. *
denotes the beginning and end of the visual selection.
Adam said to Eve "Hello| World". ;; before
Adam said to Eve* "Hello World"*. ;; after
^
I realize this was done to emulate vim precisely, however, I find that in my editing this is far less useful than just selecting the delimiters and everything in the delimiters. I'd like to change all of these surround operators to match only until their delimiters. For evil-a-quote
for example, I'd like the output the be what's shown below:
Adam said to Eve *"Hello World"*.
Hoping this would be as simple as changing a parameter, I checkout evil-a-double-quote
.
(evil-define-text-object evil-a-double-quote (count &optional beg end type)
"Select a double-quoted expression."
:extend-selection nil
(evil-select-quote ?\" beg end type count t))
Unfortunately setting :extend-selection
to nil
did not disable the greedy selection.
In the documentation I read that evil-select-quote
returns (beg end)
where beg
and end
are locations.
Right now my best idea is to replace evil-select-quote
sexp with something like this:
(let ((beg (save-excursion (re-search-backward "\"")))
(end (save-excursion (re-search-forward "\""))))
(if (and beg end)
(list beg end)
(error "No matching delimiters found")))
Another idea is to surround the output of evil-select-quote
in a while
loop which will shrink the boundaries of the range by 1 character as long as the at least one of the boundaries is a whitespace character.
Both of these ways are doable but they seem like they could be a bit of work considering that I want to make all operators non-greedy, not just evil-a-quote
.
Does anyone have a suggestion on how to do this simply?
a"
included whitespace. The Vim manual says it includes trailing whitespace, or if there is none, leading whitespace. On the other hand the manual also saysa(
does not include whitespace outside the parenthesis. I'm sure there is a good reason for both behaviors... Maybea(
is designed for code anda"
for prose? (Imagine what you'd usually wantda"
andda(
to do.)expand-region
. I use it successfully with Evil.(use-package expand-region :ensure t :bind ("C-=" . er/expand-region))
github.com/magnars/expand-region.el