aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Burkett2021-06-21 13:35:38 -0400
committerJustin Burkett2021-06-21 13:36:25 -0400
commitfc8855187f087635de4162071882405861460e05 (patch)
treed4bb960a183c7a38abaf46cad9f02668d66bcced
parenta55b90844c837e157c289ad4b10f5f2e3a4d53ff (diff)
downloademacs-fc8855187f087635de4162071882405861460e05.tar.gz
emacs-fc8855187f087635de4162071882405861460e05.zip
Remove pseudo binding stuff
It's not necessary anymore with manual parsing of the keymaps
-rw-r--r--which-key.el89
1 files changed, 17 insertions, 72 deletions
diff --git a/which-key.el b/which-key.el
index e6ac0c4f19a..5c2ca802f74 100644
--- a/which-key.el
+++ b/which-key.el
@@ -525,24 +525,6 @@ it."
525 :group 'which-key 525 :group 'which-key
526 :type 'boolean) 526 :type 'boolean)
527 527
528(defcustom which-key-enable-extended-define-key nil
529 "Advise `define-key' to make which-key aware of definitions of the form
530
531 \(define-key KEYMAP KEY '(\"DESCRIPTION\" . DEF))
532
533With the advice, this definition will have the side effect of
534creating a replacement in `which-key-replacement-alist' that
535replaces DEF with DESCRIPTION when the key sequence ends in
536KEY. Using a cons cell like this is a valid definition for
537`define-key'. All this does is to make which-key aware of it.
538
539Since many higher level keybinding functions use `define-key'
540internally, this will affect most if not all of those as well.
541
542This variable must be set before loading which-key."
543 :group 'which-key
544 :type 'boolean)
545
546;; Hooks 528;; Hooks
547(defcustom which-key-init-buffer-hook '() 529(defcustom which-key-init-buffer-hook '()
548 "Hook run when which-key buffer is initialized." 530 "Hook run when which-key buffer is initialized."
@@ -938,8 +920,7 @@ actually bound to write-file before performing the replacement."
938 replacement 920 replacement
939 (car-safe replacement))) 921 (car-safe replacement)))
940 (command (cdr-safe replacement))) 922 (command (cdr-safe replacement)))
941 (define-key keymap (which-key--pseudo-key (kbd key)) 923 (define-key keymap (kbd key) (cons string command)))
942 `(which-key ,(cons string command))))
943 (setq key (pop more) 924 (setq key (pop more)
944 replacement (pop more)))) 925 replacement (pop more))))
945(put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defun) 926(put 'which-key-add-keymap-based-replacements 'lisp-indent-function 'defun)
@@ -1044,19 +1025,6 @@ If AT-ROOT is non-nil the binding is also placed at the root of MAP."
1044 (which-key-define-key-recursively df key def t))) 1025 (which-key-define-key-recursively df key def t)))
1045 map)) 1026 map))
1046 1027
1047(defun which-key--process-define-key-args (keymap key def)
1048 "When DEF takes the form (\"DESCRIPTION\". DEF), make sure
1049which-key uses \"DESCRIPTION\" for this binding. This function is
1050meant to be used as :before advice for `define-key'."
1051 (with-demoted-errors "Which-key extended define-key error: %s"
1052 (when (and (consp def)
1053 (stringp (car def))
1054 (symbolp (cdr def)))
1055 (define-key keymap (which-key--pseudo-key key) `(which-key ,def)))))
1056
1057(when which-key-enable-extended-define-key
1058 (advice-add #'define-key :before #'which-key--process-define-key-args))
1059
1060;;; Functions for computing window sizes 1028;;; Functions for computing window sizes
1061 1029
1062(defun which-key--text-width-to-total (text-width) 1030(defun which-key--text-width-to-total (text-width)
@@ -1493,20 +1461,6 @@ local bindings coming first. Within these categories order using
1493 (string-match-p binding-regexp 1461 (string-match-p binding-regexp
1494 (cdr key-binding))))))) 1462 (cdr key-binding)))))))
1495 1463
1496(defun which-key--get-pseudo-binding (key-binding &optional prefix)
1497 (let* ((key (kbd (car key-binding)))
1498 (pseudo-binding (key-binding (which-key--pseudo-key key prefix))))
1499 (when pseudo-binding
1500 (let* ((command-replacement (cadr pseudo-binding))
1501 (pseudo-desc (car command-replacement))
1502 (pseudo-def (cdr command-replacement)))
1503 (when (and (stringp pseudo-desc)
1504 (or (null pseudo-def)
1505 ;; don't verify keymaps
1506 (keymapp pseudo-def)
1507 (eq pseudo-def (key-binding key))))
1508 (cons (car key-binding) pseudo-desc))))))
1509
1510(defsubst which-key--replace-in-binding (key-binding repl) 1464(defsubst which-key--replace-in-binding (key-binding repl)
1511 (cond ((or (not (consp repl)) (null (cdr repl))) 1465 (cond ((or (not (consp repl)) (null (cdr repl)))
1512 key-binding) 1466 key-binding)
@@ -1542,26 +1496,23 @@ local bindings coming first. Within these categories order using
1542 "Use `which-key--replacement-alist' to maybe replace KEY-BINDING. 1496 "Use `which-key--replacement-alist' to maybe replace KEY-BINDING.
1543KEY-BINDING is a cons cell of the form \(KEY . BINDING\) each of 1497KEY-BINDING is a cons cell of the form \(KEY . BINDING\) each of
1544which are strings. KEY is of the form produced by `key-binding'." 1498which are strings. KEY is of the form produced by `key-binding'."
1545 (let* ((pseudo-binding (which-key--get-pseudo-binding key-binding prefix))) 1499 (let* ((replacer (if which-key-allow-multiple-replacements
1546 (if pseudo-binding 1500 #'which-key--replace-in-repl-list-many
1547 pseudo-binding 1501 #'which-key--replace-in-repl-list-once)))
1548 (let* ((replacer (if which-key-allow-multiple-replacements 1502 (pcase
1549 #'which-key--replace-in-repl-list-many 1503 (apply replacer
1550 #'which-key--replace-in-repl-list-once))) 1504 (list key-binding
1551 (pcase 1505 (cdr-safe (assq major-mode which-key-replacement-alist))))
1552 (apply replacer 1506 (`(replaced . ,repl)
1553 (list key-binding 1507 (if which-key-allow-multiple-replacements
1554 (cdr-safe (assq major-mode which-key-replacement-alist)))) 1508 (pcase (apply replacer (list repl which-key-replacement-alist))
1555 (`(replaced . ,repl)
1556 (if which-key-allow-multiple-replacements
1557 (pcase (apply replacer (list repl which-key-replacement-alist))
1558 (`(replaced . ,repl) repl)
1559 ('() repl))
1560 repl))
1561 ('()
1562 (pcase (apply replacer (list key-binding which-key-replacement-alist))
1563 (`(replaced . ,repl) repl) 1509 (`(replaced . ,repl) repl)
1564 ('() key-binding)))))))) 1510 ('() repl))
1511 repl))
1512 ('()
1513 (pcase (apply replacer (list key-binding which-key-replacement-alist))
1514 (`(replaced . ,repl) repl)
1515 ('() key-binding))))))
1565 1516
1566(defsubst which-key--current-key-list (&optional key-str) 1517(defsubst which-key--current-key-list (&optional key-str)
1567 (append (listify-key-sequence (which-key--current-prefix)) 1518 (append (listify-key-sequence (which-key--current-prefix))
@@ -1593,12 +1544,6 @@ which are strings. KEY is of the form produced by `key-binding'."
1593 (or (eq lookup (intern (cdr keydesc))) 1544 (or (eq lookup (intern (cdr keydesc)))
1594 (and (keymapp lookup) (string= (cdr keydesc) "Prefix Command")))))) 1545 (and (keymapp lookup) (string= (cdr keydesc) "Prefix Command"))))))
1595 1546
1596(defun which-key--pseudo-key (key &optional prefix)
1597 "Replace the last key in the sequence KEY by a special symbol
1598in order for which-key to allow looking up a description for the key."
1599 (let ((seq (listify-key-sequence key)))
1600 (vconcat (or prefix (butlast seq)) [which-key] (last seq))))
1601
1602(defun which-key--maybe-get-prefix-title (keys) 1547(defun which-key--maybe-get-prefix-title (keys)
1603 "KEYS is a string produced by `key-description'. 1548 "KEYS is a string produced by `key-description'.
1604A title is possibly returned using 1549A title is possibly returned using