feature/evil: refactor multiple-cursors compat config

This commit is contained in:
Henrik Lissner 2018-05-04 15:06:05 +02:00
parent 27153d128c
commit f319034c5a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -434,22 +434,22 @@ the new algorithm is confusing, like in python or ruby."
(setq +evil--mc-compat-evil-prev-state nil)
(setq +evil--mc-compat-mark-was-active nil))))
(add-hook 'multiple-cursors-mode-enabled-hook '+evil|mc-compat-switch-to-emacs-state)
(add-hook 'multiple-cursors-mode-disabled-hook '+evil|mc-compat-back-to-previous-state)
(add-hook 'multiple-cursors-mode-enabled-hook #'+evil|mc-compat-switch-to-emacs-state)
(add-hook 'multiple-cursors-mode-disabled-hook #'+evil|mc-compat-back-to-previous-state)
;; When running edit-lines, point will return (position + 1) as a
;; result of how evil deals with regions
(defun +evil*mc/edit-lines (&rest _)
(when (+evil--visual-or-normal-p)
(if (> (point) (mark))
(goto-char (1- (point)))
(push-mark (1- (mark))))))
(advice-add #'mc/edit-lines :before #'+evil*mc/edit-lines)
(defun +evil|mc-evil-compat-rect-switch-state ()
(if rectangular-region-mode
(+evil|mc-compat-switch-to-emacs-state)
(setq +evil--mc-compat-evil-prev-state nil)))
;; When running edit-lines, point will return (position + 1) as a
;; result of how evil deals with regions
(defadvice mc/edit-lines (before change-point-by-1 activate)
(when (+evil--visual-or-normal-p)
(if (> (point) (mark))
(goto-char (1- (point)))
(push-mark (1- (mark))))))
(add-hook 'rectangular-region-mode-hook '+evil|mc-evil-compat-rect-switch-state)
(defvar mc--default-cmds-to-run-once nil))