From b2b19e7196cb34e3147005680e49b50db2ce547f Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 27 Jan 2022 03:15:04 +0100 Subject: [PATCH] fix(multiple-cursors): contextually activate minor mode evil-mc's design is bizarre. Its variables and hooks are lazy loaded rather than declared at top-level, some hooks aren't defined or documented, it's a bit initializer-function drunk, and its minor modes are intended to be perpetually active -- even when no cursors are active (causing #6021). I undo all of that here. Fix: #6021 --- modules/editor/multiple-cursors/config.el | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/editor/multiple-cursors/config.el b/modules/editor/multiple-cursors/config.el index 2aa174871..6feb40ac6 100644 --- a/modules/editor/multiple-cursors/config.el +++ b/modules/editor/multiple-cursors/config.el @@ -53,7 +53,19 @@ (defvar evil-mc-key-map (make-sparse-keymap)) :config - (global-evil-mc-mode +1) + ;; HACK evil-mc's design is bizarre. Its variables and hooks are lazy loaded + ;; rather than declared at top-level, some hooks aren't defined or + ;; documented, it's a bit initializer-function drunk, and its minor modes + ;; are intended to be perpetually active -- even when no cursors are active + ;; (causing #6021). I undo all of that here. + (evil-mc-define-vars) + (add-hook 'evil-mc-before-cursors-created #'evil-mc-pause-incompatible-modes) + (add-hook 'evil-mc-before-cursors-created #'evil-mc-initialize-active-state) + (add-hook 'evil-mc-after-cursors-deleted #'evil-mc-teardown-active-state) + (add-hook 'evil-mc-after-cursors-deleted #'evil-mc-resume-incompatible-modes) + (advice-add #'evil-mc-initialize-hooks :override #'ignore) + (advice-add #'evil-mc-initialize-active-state :before #'turn-on-evil-mc-mode) + (advice-add #'evil-mc-teardown-active-state :after #'turn-off-evil-mc-mode) ;; REVIEW This is tremendously slow on macos and windows for some reason. (setq evil-mc-enable-bar-cursor (not (or IS-MAC IS-WINDOWS)))