editor/multiple-cursors: refactor :mc ex command
This commit is contained in:
parent
9664f68c5f
commit
5999dc6af9
1 changed files with 32 additions and 30 deletions
|
@ -51,39 +51,41 @@ pauses cursors."
|
||||||
(evil-define-command +multiple-cursors:evil-mc (beg end type pattern &optional flags 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.
|
"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
|
This leaves the cursor where the final cursor would be. If BANG, then treat
|
||||||
literal. PATTERN is a delimited regexp (the same that :g or :s uses)."
|
PATTERN as literal. PATTERN is a delimited regexp (the same that :g or :s uses).
|
||||||
:move-point nil
|
FLAGS can be g and/or i; which mean the same thing they do in
|
||||||
|
`evil-ex-substitute'."
|
||||||
:evil-mc t
|
:evil-mc t
|
||||||
(interactive "<R><//!><!>")
|
(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"))
|
||||||
(require 'evil-mc)
|
(require 'evil-mc)
|
||||||
(setq evil-mc-pattern
|
(let ((m (evil-ex-make-pattern
|
||||||
(cons (evil-ex-make-search-pattern
|
(if bang (regexp-quote pattern) pattern)
|
||||||
(if bang (regexp-quote pattern) pattern))
|
(cond ((memq ?i flags) 'insensitive)
|
||||||
(list beg end type)))
|
((memq ?I flags) 'sensitive)
|
||||||
(evil-with-restriction beg end
|
((not +multiple-cursors-evil-mc-ex-case)
|
||||||
(let ((point (point)))
|
evil-ex-search-case)
|
||||||
(save-excursion
|
(t +multiple-cursors-evil-mc-ex-case))
|
||||||
(goto-char (point-min))
|
(or (and +multiple-cursors-evil-mc-ex-global
|
||||||
(while (eq (evil-ex-find-next (evil-mc-get-pattern) 'forward t) t)
|
(not (memq ?g flags)))
|
||||||
(goto-char (1- (point)))
|
(and (not +multiple-cursors-evil-mc-ex-global)
|
||||||
(when (/= point (point))
|
(memq ?g flags))))))
|
||||||
(evil-mc-run-cursors-before)
|
(evil-mc-run-cursors-before)
|
||||||
(evil-mc-make-cursor-at-pos (point)))
|
(setq evil-mc-pattern (cons m (list beg end type)))
|
||||||
(goto-char
|
(evil-with-restriction beg end
|
||||||
(if (memq ?g flags)
|
(goto-char beg)
|
||||||
(line-beginning-position 2)
|
(while (eq (evil-ex-find-next m 'forward t) t)
|
||||||
(1+ (point))))))))
|
(evil-mc-make-cursor-at-pos (1- (point)))
|
||||||
(evil-exit-visual-state)
|
(unless (evil-ex-pattern-whole-line m)
|
||||||
|
(goto-char (line-beginning-position 2)))))
|
||||||
(evil-mc-goto-cursor
|
(evil-mc-goto-cursor
|
||||||
(if (= (evil-visual-direction) 1)
|
(if (= (evil-visual-direction) 1)
|
||||||
(evil-mc-find-last-cursor)
|
(evil-mc-find-last-cursor)
|
||||||
(evil-mc-find-first-cursor))
|
(evil-mc-find-first-cursor))
|
||||||
nil)
|
nil)
|
||||||
(evil-mc-undo-cursor-at-pos (point))
|
(evil-mc-undo-cursor-at-pos (1- (point)))
|
||||||
(if (evil-mc-has-cursors-p)
|
(if (evil-mc-has-cursors-p)
|
||||||
(evil-mc-print-cursors-info "Created")
|
(evil-mc-print-cursors-info "Created")
|
||||||
(evil-mc-message "No cursors were created")))
|
(evil-mc-message "No cursors were created"))))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue