diff --git a/modules/editor/multiple-cursors/autoload/evil-mc.el b/modules/editor/multiple-cursors/autoload/evil-mc.el index 5b5928182..c4ca6cd46 100644 --- a/modules/editor/multiple-cursors/autoload/evil-mc.el +++ b/modules/editor/multiple-cursors/autoload/evil-mc.el @@ -45,12 +45,14 @@ pauses cursors." (evil-mc-make-cursor-here)))) ;;;###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) - "Create mc cursors at each match of PATTERN within BEG and END, and leave the -cursor at the final match. If BANG, then treat PATTERN as literal." +(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. + +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 :evil-mc t - (interactive "") + (interactive "") (unless (and (stringp pattern) (not (string-empty-p pattern))) (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 (if bang (regexp-quote pattern) pattern)) (list beg end type))) - (save-excursion - (evil-with-restriction beg end - (evil-mc-make-cursors-for-all))) + (evil-with-restriction beg end + (let ((point (point))) + (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-mc-goto-cursor (if (= (evil-visual-direction) 1)