aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Pluim2023-02-02 11:37:45 +0100
committerRobert Pluim2023-02-03 10:14:43 +0100
commite444115d026c809395d4d248a99bb467bc87bb1d (patch)
tree5852150f21b1f6ed0b958343ae85e4e8cbb7f1d1
parent96ea27278b43ae5ea72643881015944a819f7974 (diff)
downloademacs-e444115d026c809395d4d248a99bb467bc87bb1d.tar.gz
emacs-e444115d026c809395d4d248a99bb467bc87bb1d.zip
Improve keymap-global-set and keymap-local-set interactive use fix
* lisp/keymap.el (keymap-global-set, keymap-local-set): Add optional `interactive' arg and use it to decide when to convert the key specification to a string. Add `advertised-calling-convention' declarations. (Bug#61149)
-rw-r--r--lisp/keymap.el18
1 files changed, 10 insertions, 8 deletions
diff --git a/lisp/keymap.el b/lisp/keymap.el
index 201a49cef8c..4f02639ffe2 100644
--- a/lisp/keymap.el
+++ b/lisp/keymap.el
@@ -65,7 +65,7 @@ DEFINITION is anything that can be a key's definition:
65 (setq definition (key-parse definition))) 65 (setq definition (key-parse definition)))
66 (define-key keymap (key-parse key) definition)) 66 (define-key keymap (key-parse key) definition))
67 67
68(defun keymap-global-set (key command) 68(defun keymap-global-set (key command &optional interactive)
69 "Give KEY a global binding as COMMAND. 69 "Give KEY a global binding as COMMAND.
70COMMAND is the command definition to use; usually it is 70COMMAND is the command definition to use; usually it is
71a symbol naming an interactively-callable function. 71a symbol naming an interactively-callable function.
@@ -75,13 +75,14 @@ KEY is a string that satisfies `key-valid-p'.
75Note that if KEY has a local binding in the current buffer, 75Note that if KEY has a local binding in the current buffer,
76that local binding will continue to shadow any global binding 76that local binding will continue to shadow any global binding
77that you make with this function." 77that you make with this function."
78 (declare (compiler-macro (lambda (form) (keymap--compile-check key) form))) 78 (declare (compiler-macro (lambda (form) (keymap--compile-check key) form))
79 (interactive "KSet key globally:\nCSet key %s globally to command: ") 79 (advertised-calling-convention (key command) "29.1"))
80 (unless (stringp key) 80 (interactive "KSet key globally: \nCSet key %s globally to command: \np")
81 (when interactive
81 (setq key (key-description key))) 82 (setq key (key-description key)))
82 (keymap-set (current-global-map) key command)) 83 (keymap-set (current-global-map) key command))
83 84
84(defun keymap-local-set (key command) 85(defun keymap-local-set (key command &optional interactive)
85 "Give KEY a local binding as COMMAND. 86 "Give KEY a local binding as COMMAND.
86COMMAND is the command definition to use; usually it is 87COMMAND is the command definition to use; usually it is
87a symbol naming an interactively-callable function. 88a symbol naming an interactively-callable function.
@@ -90,12 +91,13 @@ KEY is a string that satisfies `key-valid-p'.
90 91
91The binding goes in the current buffer's local map, which in most 92The binding goes in the current buffer's local map, which in most
92cases is shared with all other buffers in the same major mode." 93cases is shared with all other buffers in the same major mode."
93 (declare (compiler-macro (lambda (form) (keymap--compile-check key) form))) 94 (declare (compiler-macro (lambda (form) (keymap--compile-check key) form))
94 (interactive "KSet key locally:\nCSet key %s locally to command: ") 95 (advertised-calling-convention (key command) "29.1"))
96 (interactive "KSet key locally: \nCSet key %s locally to command: \np")
95 (let ((map (current-local-map))) 97 (let ((map (current-local-map)))
96 (unless map 98 (unless map
97 (use-local-map (setq map (make-sparse-keymap)))) 99 (use-local-map (setq map (make-sparse-keymap))))
98 (unless (stringp key) 100 (when interactive
99 (setq key (key-description key))) 101 (setq key (key-description key)))
100 (keymap-set map key command))) 102 (keymap-set map key command)))
101 103