syl20bnr / evil-iedit-state

Slick Evil states for iedit.
GNU General Public License v3.0
58 stars 25 forks source link

Restrict to visual selection (Enhancement) #4

Open hlissner opened 9 years ago

hlissner commented 9 years ago

We have 'iedit-restrict-function and 'iedit-restrict-current-line (even 'iedit-expand-down-a-line and 'iedit-expand-up-a-line), and iedit has 'iedit-restrict-region but it isn't interactive. It'd be nice to exploit evil's visual mode to restrict matches to a selected region.

I have an implementation of this in my emacs.d that maps SPC (in visual mode) to the following lambda:

(lambda ()
  (interactive)
  (if (iedit-current-occurrence-string)
      (let ((current-prefix-arg '(4)))
        (iedit-done)
        (call-interactively 'iedit-mode)
        (save-excursion (iedit-restrict-region (region-beginning) (region-end)))
        (evil-previous-line))
    (call-interactively 'evil-ret))))))

Unfortunately, while this does cut down on matches, it won't add new matches to an expanded restricted region (yet).

EDIT: Now it does, updated the lambda.

I can extract it into, say, a 'evil-iedit-restrict-region, for a PR if this interests you.

braham-snyder commented 7 years ago

how difficult do you suppose it would be to make it an operator? i.e., evil-iedit-state/iedit-mode on a region or symbol, then, e.g., 3ap to restrict to matches of the original region or symbol within the next three paragraphs?

hlissner commented 7 years ago

@braham-snyder I've taken this idea and since written evil-multiedit. The default config lets you visually select a region and press RET to restrict matches to that region. I can look into adding an operator to do that, it wouldn't be difficult.