Run hook when mc is disabled

This commit is contained in:
Johannes Lippmann 2021-11-11 13:57:23 +01:00 committed by Magnar Sveen
parent 588daf8c52
commit 4975afedb3
3 changed files with 25 additions and 8 deletions

View File

@ -355,7 +355,9 @@ With zero ARG, skip the last one and mark next."
(when point-first (exchange-point-and-mark)))))
(if (> (mc/num-cursors) 1)
(multiple-cursors-mode 1)
(multiple-cursors-mode 0)))
(progn
(multiple-cursors-mode 0)
(run-hooks 'multiple-cursors-mode-disabled-hook))))
(defun mc--select-thing-at-point (thing)
(let ((bound (bounds-of-thing-at-point thing)))
@ -402,7 +404,9 @@ With zero ARG, skip the last one and mark next."
(mc/pop-state-from-overlay first)))
(if (> (mc/num-cursors) 1)
(multiple-cursors-mode 1)
(multiple-cursors-mode 0))))))
(progn
(multiple-cursors-mode 0)
(run-hooks 'multiple-cursors-mode-disabled-hook)))))))
;;;###autoload
(defun mc/mark-all-in-region-regexp (beg end)
@ -427,7 +431,9 @@ With zero ARG, skip the last one and mark next."
(error "Search failed for %S" search)))
(goto-char (match-end 0))
(if (< (mc/num-cursors) 3)
(progn
(multiple-cursors-mode 0)
(run-hooks 'multiple-cursors-mode-disabled-hook))
(mc/pop-state-from-overlay (mc/furthest-cursor-before-point))
(multiple-cursors-mode 1))))))

View File

@ -106,7 +106,9 @@
(progn
(mc/mark-next-lines 1)
(mc/reverse-regions)
(multiple-cursors-mode 0))
(multiple-cursors-mode 0)
(multiple-cursors-mode-disabled-hook)
)
(unless (use-region-p)
(mc/execute-command-for-all-cursors 'mark-sexp))
(setq mc--strings-to-replace (nreverse (mc--ordered-region-strings)))

View File

@ -433,7 +433,9 @@ the original cursor, to inform about the lack of support."
(unless mc--executing-command-for-fake-cursor
(if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode
(progn
(multiple-cursors-mode 0)
(run-hooks 'multiple-cursors-mode-disabled-hook))
(when this-original-command
(let ((original-command (or mc--this-command
(command-remapping this-original-command)
@ -487,7 +489,9 @@ you should disable multiple-cursors-mode."
"Deactivate mark if there are any active, otherwise exit multiple-cursors-mode."
(interactive)
(if (not (use-region-p))
(progn
(multiple-cursors-mode 0)
(run-hooks 'multiple-cursors-mode-disabled-hook))
(deactivate-mark)))
(defun mc/repeat-command ()
@ -588,13 +592,18 @@ They are temporarily disabled when multiple-cursors are active.")
(mc/enable-temporarily-disabled-minor-modes)
(run-hooks 'multiple-cursors-mode-disabled-hook)))
(add-hook 'after-revert-hook #'(lambda () (multiple-cursors-mode 0)))
(add-hook 'after-revert-hook
#'(lambda () (progn
(multiple-cursors-mode 0)
(run-hooks 'multiple-cursors-mode-disabled-hook))))
(defun mc/maybe-multiple-cursors-mode ()
"Enable multiple-cursors-mode if there is more than one currently active cursor."
(if (> (mc/num-cursors) 1)
(multiple-cursors-mode 1)
(multiple-cursors-mode 0)))
(progn
(multiple-cursors-mode 0)
(run-hooks 'multiple-cursors-mode-disabled-hook))))
(defmacro unsupported-cmd (cmd msg)
"Adds command to list of unsupported commands and prevents it