fix(multiple-cursors): check evil-local-mode instead of the global one

For evil compatibility (switching to emacs state during multiple
cursors), when evil is enabled locally by evil-local-mode but not
globally by evil-mode, using the former to check is more accurate.

Also make the state variables local since MC maybe used for multiple
buffers: activate current buffer and while not deactivating here, go to
another buffer and activate there.
This commit is contained in:
Daanturo 2023-04-16 21:32:38 +07:00 committed by Henrik Lissner
parent 6aa9ebae64
commit 23c0eeba45

View file

@ -175,12 +175,12 @@
(when (modulep! :editor evil) (when (modulep! :editor evil)
(evil-define-key* '(normal emacs) mc/keymap [escape] #'mc/keyboard-quit) (evil-define-key* '(normal emacs) mc/keymap [escape] #'mc/keyboard-quit)
(defvar +mc--compat-evil-prev-state nil) (defvar-local +mc--compat-evil-prev-state nil)
(defvar +mc--compat-mark-was-active nil) (defvar-local +mc--compat-mark-was-active nil)
(add-hook! 'multiple-cursors-mode-enabled-hook (add-hook! 'multiple-cursors-mode-enabled-hook
(defun +multiple-cursors-compat-switch-to-emacs-state-h () (defun +multiple-cursors-compat-switch-to-emacs-state-h ()
(when (and (bound-and-true-p evil-mode) (when (and (bound-and-true-p evil-local-mode)
(not (memq evil-state '(insert emacs)))) (not (memq evil-state '(insert emacs))))
(setq +mc--compat-evil-prev-state evil-state) (setq +mc--compat-evil-prev-state evil-state)
(when (region-active-p) (when (region-active-p)
@ -210,7 +210,7 @@
;; how evil deals with regions ;; how evil deals with regions
(defadvice! +multiple--cursors-adjust-mark-for-evil-a (&rest _) (defadvice! +multiple--cursors-adjust-mark-for-evil-a (&rest _)
:before #'mc/edit-lines :before #'mc/edit-lines
(when (and (bound-and-true-p evil-mode) (when (and (bound-and-true-p evil-local-mode)
(not (memq evil-state '(insert emacs)))) (not (memq evil-state '(insert emacs))))
(if (> (point) (mark)) (if (> (point) (mark))
(goto-char (1- (point))) (goto-char (1- (point)))