Change :mc to take delimited pattern

This used to take a regexp after a space: ':mc REGEXP'. It now is
delimited, like :g or :s, e.g.

  :mc/REGEXP/FLAGS
  :mc/[a-z]
  :mc/abc/g
This commit is contained in:
Henrik Lissner 2019-08-30 20:41:45 -04:00
parent 075bc1797b
commit f763bf2fd0
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -45,12 +45,14 @@ pauses cursors."
(evil-mc-make-cursor-here)))) (evil-mc-make-cursor-here))))
;;;###autoload (autoload '+multiple-cursors:evil-mc "editor/multiple-cursors/autoload/evil-mc" nil t) ;;;###autoload (autoload '+multiple-cursors:evil-mc "editor/multiple-cursors/autoload/evil-mc" nil t)
(evil-define-command +multiple-cursors:evil-mc (beg end type pattern &optional bang) (evil-define-command +multiple-cursors:evil-mc (beg end type pattern &optional flags bang)
"Create mc cursors at each match of PATTERN within BEG and END, and leave the "Create mc cursors at each match of PATTERN within BEG and END.
cursor at the final match. If BANG, then treat PATTERN as literal."
This leaves the cursor at the final match. If BANG, then treat PATTERN as
literal. PATTERN is a delimited regexp (the same that :g or :s uses)."
:move-point nil :move-point nil
:evil-mc t :evil-mc t
(interactive "<R><//g><!>") (interactive "<R><//!><!>")
(unless (and (stringp pattern) (unless (and (stringp pattern)
(not (string-empty-p pattern))) (not (string-empty-p pattern)))
(user-error "A regexp pattern is required")) (user-error "A regexp pattern is required"))
@ -59,9 +61,19 @@ cursor at the final match. If BANG, then treat PATTERN as literal."
(cons (evil-ex-make-search-pattern (cons (evil-ex-make-search-pattern
(if bang (regexp-quote pattern) pattern)) (if bang (regexp-quote pattern) pattern))
(list beg end type))) (list beg end type)))
(save-excursion (evil-with-restriction beg end
(evil-with-restriction beg end (let ((point (point)))
(evil-mc-make-cursors-for-all))) (save-excursion
(goto-char (point-min))
(while (eq (evil-ex-find-next (evil-mc-get-pattern) 'forward t) t)
(goto-char (1- (point)))
(when (/= point (point))
(evil-mc-run-cursors-before)
(evil-mc-make-cursor-at-pos (point)))
(goto-char
(if (memq ?g flags)
(line-beginning-position 2)
(1+ (point))))))))
(evil-exit-visual-state) (evil-exit-visual-state)
(evil-mc-goto-cursor (evil-mc-goto-cursor
(if (= (evil-visual-direction) 1) (if (= (evil-visual-direction) 1)