[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/undo-tree acd7549 070/195: Prevent global-undo-tree-mod
From: |
Stefan Monnier |
Subject: |
[elpa] externals/undo-tree acd7549 070/195: Prevent global-undo-tree-mode being enabled in incompatible major-modes. |
Date: |
Sat, 28 Nov 2020 13:41:24 -0500 (EST) |
branch: externals/undo-tree
commit acd7549dbeef62acdf3b4b5d66c1eab212e963ea
Author: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Commit: Toby S. Cubitt <toby-undo-tree@dr-qubit.org>
Prevent global-undo-tree-mode being enabled in incompatible major-modes.
turn-on-undo-tree-mode (used in the globalized minor-mode definition) now
avoids enabling undo-tree-mode if the undo command is remapped by the
buffer's
keymaps, or if the default bindings ("C-/" and "C-_") have been overridden
anywhere *except* in the global keymap (if users rebind the undo keys, it
will
almost invariably be in the global keymap), or if the buffer's major-mode is
listed in undo-tree-incompatible-major-modes.
---
undo-tree.el | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 52 insertions(+), 2 deletions(-)
diff --git a/undo-tree.el b/undo-tree.el
index bdcae7e..90aaf17 100644
--- a/undo-tree.el
+++ b/undo-tree.el
@@ -612,6 +612,11 @@
;; enabled in the visualizer when `default-major-mode' is set to something
;; other than `fundamental-mode' (thanks to Michael Heerdegen for suggesting
;; this fix)
+;; * modified `turn-on-undo-tree-mode' to avoid turning on `undo-tree-mode' if
+;; the buffer's `major-mode' implements its own undo system, by checking
+;; whether `undo' is remapped, the default "C-/" or "C-_" bindings have been
+;; overridden, or the `major-mode' is listed in
+;; `undo-tree-incompatible-major-modes'
;;
;; Version 0.3
;; * implemented undo-in-region
@@ -724,6 +729,12 @@ when `undo-tree-mode' is enabled."
:group 'undo-tree
:type 'string)
+(defcustom undo-tree-incompatible-major-modes nil
+ "List of major-modes in which `undo-tree-mode' should not be enabled.
+\(See `turn-on-undo-tree-mode'.\)"
+ :group 'undo-tree
+ :type '(repeat symbol))
+
(defcustom undo-tree-visualizer-spacing 3
"Horizontal spacing in undo-tree visualization.
Must be a postivie odd integer."
@@ -2233,8 +2244,47 @@ Within the undo-tree visualizer, the following keys are
available:
(defun turn-on-undo-tree-mode ()
- "Enable undo-tree-mode."
- (undo-tree-mode 1))
+ "Enable `undo-tree-mode' in the current buffer, when appropriate.
+Some major modes implement their own undo system, which should
+not normally be overridden by `undo-tree-mode'. This command does
+not enable `undo-tree-mode' in such buffers. If you want to force
+`undo-tree-mode' to be enabled regardless, use (undo-tree-mode 1)
+instead.
+
+The heuristic used to detect major modes in which
+`undo-tree-mode' should not be used is to check whether either
+the `undo' command has been remapped, or the default undo
+keybindings (C-/ and C-_) have been overridden somewhere other
+than in the global map. In addition, `undo-tree-mode' will not be
+enabled if the buffer's `major-mode' appears in
+`undo-tree-incompatible-major-modes'."
+ (interactive)
+ (if (or (key-binding [remap undo])
+ (undo-tree-overridden-undo-bindings-p)
+ (memq major-mode undo-tree-incompatible-major-modes))
+ (when (interactive-p)
+ (message "Incompatible major-mode `%s'; undo-tree-mode NOT enabled"
+ major-mode))
+ (undo-tree-mode 1)))
+
+
+(defun undo-tree-overridden-undo-bindings-p ()
+ "Returns t if default undo bindings are overridden, nil otherwise.
+Checks if either of the default undo key bindings (\"C-/\" or
+\"C-_\") are overridden in the current buffer by any keymap other
+than the global one. (So global redefinitions of the default undo
+key bindings do not count.)"
+ (let ((binding1 (lookup-key (current-global-map) [?\C-/]))
+ (binding2 (lookup-key (current-global-map) [?\C-_])))
+ (global-set-key [?\C-/] 'undo)
+ (global-set-key [?\C-_] 'undo)
+ (unwind-protect
+ (or (and (key-binding [?\C-/])
+ (not (eq (key-binding [?\C-/]) 'undo)))
+ (and (key-binding [?\C-_])
+ (not (eq (key-binding [?\C-_]) 'undo))))
+ (global-set-key [?\C-/] binding1)
+ (global-set-key [?\C-_] binding2))))
(define-globalized-minor-mode global-undo-tree-mode
- [elpa] externals/undo-tree 0ed621d 062/195: Implemented undo-in-region., (continued)
- [elpa] externals/undo-tree 0ed621d 062/195: Implemented undo-in-region., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 8b1bae6 060/195: Implemented keyboard selection in visualizer., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 309f4bc 066/195: Define region-active-p if not already defined, for compatibility, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree e32f45e 072/195: Use correct faces and show registers in visualizer when displaying timestamps., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 2bfab98 079/195: Bumped copyright year for new release., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree a93e78f 071/195: Discard position entries from changesets created by undoing or redoing., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 45380b2 087/195: Suppress branch point messages when undo/redoing from undo-tree-set., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree db55cea 068/195: Bumped compyright year and corrected license wording., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 3255044 065/195: Fixed bugs in undo-list-transfer-to-tree and undo-list-rebuild-from-tree, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 07e934a 080/195: Added term-mode to undo-tree-incompatible-major-modes., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree acd7549 070/195: Prevent global-undo-tree-mode being enabled in incompatible major-modes.,
Stefan Monnier <=
- [elpa] externals/undo-tree 79b382b 083/195: Fixed bug in undo-list-pop-changeset when called with non-null DISCARD-POS., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 6680aab 086/195: Create proper registerv structure when storing undo state in register., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree cd06456 073/195: Modified slightly misleading message in turn-on-undo-tree-mode., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 98170c6 075/195: Added additional check to more reliably identify marker undo elements., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 89bf725 081/195: Prevent undo history being discarded on major-mode switch, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 2b0395a 096/195: Added called-interactively-p compatibility hack for Emacs <= 23.1, Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree b42fe10 076/195: Fixed bug in undo-list-transfer-to-tree., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree 897f2ff 089/195: Let-bind inhibit-read-only instead of setting and restoring buffer-read-only., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree adca566 094/195: Allow undo-tree-visualizer-diff variable to be customized., Stefan Monnier, 2020/11/28
- [elpa] externals/undo-tree da54994 117/195: When discarding root, erase previous link of new root., Stefan Monnier, 2020/11/28