diff options
| author | Justin Burkett | 2021-06-21 14:46:51 -0400 |
|---|---|---|
| committer | Justin Burkett | 2021-06-21 14:46:51 -0400 |
| commit | 465d2fb2e4540257ad515f37f2cb4e419b286f8c (patch) | |
| tree | 1b7b95dbae2c50b9bbf6b38282732500cf2c674f | |
| parent | 8d6d81da4c7be4c929e908b1737dfd6d4c2aaa63 (diff) | |
| download | emacs-465d2fb2e4540257ad515f37f2cb4e419b286f8c.tar.gz emacs-465d2fb2e4540257ad515f37f2cb4e419b286f8c.zip | |
Fix add-keymap-based-bindings and associated test
| -rw-r--r-- | which-key-tests.el | 25 | ||||
| -rw-r--r-- | which-key.el | 12 |
2 files changed, 18 insertions, 19 deletions
diff --git a/which-key-tests.el b/which-key-tests.el index eeedb557370..04617377999 100644 --- a/which-key-tests.el +++ b/which-key-tests.el | |||
| @@ -29,20 +29,17 @@ | |||
| 29 | 29 | ||
| 30 | (ert-deftest which-key-test--keymap-based-bindings () | 30 | (ert-deftest which-key-test--keymap-based-bindings () |
| 31 | (let ((map (make-sparse-keymap)) | 31 | (let ((map (make-sparse-keymap)) |
| 32 | (emacs-lisp-mode-map (copy-keymap emacs-lisp-mode-map))) | 32 | (prefix-map (make-sparse-keymap))) |
| 33 | (emacs-lisp-mode) | 33 | (define-key prefix-map "x" 'ignore) |
| 34 | (define-key map "x" 'ignore) | 34 | (define-key map "\C-a" 'complete) |
| 35 | (define-key emacs-lisp-mode-map "\C-c\C-a" 'complete) | 35 | (define-key map "\C-b" prefix-map) |
| 36 | (define-key emacs-lisp-mode-map "\C-c\C-b" map) | 36 | (which-key-add-keymap-based-replacements map |
| 37 | (which-key-add-keymap-based-replacements emacs-lisp-mode-map | 37 | "C-a" '("mycomplete" . complete) |
| 38 | "C-c C-a" '("mycomplete" . complete) | 38 | "C-b" "mymap") |
| 39 | "C-c C-b" "mymap") | 39 | (should (equal |
| 40 | (should (equal | 40 | (which-key--get-keymap-bindings map) |
| 41 | (which-key--maybe-replace '("C-c C-a" . "complete")) | 41 | '(("C-a" . "mycomplete") |
| 42 | '("C-c C-a" . "mycomplete"))) | 42 | ("C-b" . "mymap")))))) |
| 43 | (should (equal | ||
| 44 | (which-key--maybe-replace '("C-c C-b" . "")) | ||
| 45 | '("C-c C-b" . "mymap"))))) | ||
| 46 | 43 | ||
| 47 | (ert-deftest which-key-test--prefix-declaration () | 44 | (ert-deftest which-key-test--prefix-declaration () |
| 48 | "Test `which-key-declare-prefixes' and | 45 | "Test `which-key-declare-prefixes' and |
diff --git a/which-key.el b/which-key.el index d6baa70b537..ec3f760159b 100644 --- a/which-key.el +++ b/which-key.el | |||
| @@ -914,11 +914,13 @@ both have the same effect for the \"C-x C-w\" key binding, but | |||
| 914 | the latter causes which-key to verify that the key sequence is | 914 | the latter causes which-key to verify that the key sequence is |
| 915 | actually bound to write-file before performing the replacement." | 915 | actually bound to write-file before performing the replacement." |
| 916 | (while key | 916 | (while key |
| 917 | (let ((string (if (stringp replacement) | 917 | (cond ((consp replacement) |
| 918 | replacement | 918 | (define-key keymap (kbd key) replacement)) |
| 919 | (car-safe replacement))) | 919 | ((stringp replacement) |
| 920 | (command (cdr-safe replacement))) | 920 | (define-key keymap (kbd key) (cons replacement |
| 921 | (define-key keymap (kbd key) (cons string command))) | 921 | (lookup-key keymap (kbd key))))) |
| 922 | (t | ||
| 923 | (user-error "replacement is neither a cons cell or a string"))) | ||
| 922 | (setq key (pop more) | 924 | (setq key (pop more) |
| 923 | replacement (pop more)))) | 925 | replacement (pop more)))) |
| 924 | (put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defun) | 926 | (put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defun) |