[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master f516b84 09/21: Add which-key-enable-extended-define-key cu
From: |
Justin Burkett |
Subject: |
[elpa] master f516b84 09/21: Add which-key-enable-extended-define-key customization option |
Date: |
Mon, 8 Jan 2018 22:46:55 -0500 (EST) |
branch: master
commit f516b84eab1e307d3ffaa181324dca12c3951936
Author: Justin Burkett <address@hidden>
Commit: Justin Burkett <address@hidden>
Add which-key-enable-extended-define-key customization option
Adds supporting which-key--process-define-key-args.
The docstring for the option is
Advise `define-key' to make which-key aware of definitions of the form
(define-key KEYMAP KEY '("DESCRIPTION" . DEF))
With the advice, this definition will have the side effect of creating a
replacement in `which-key-replacement-alist' that replaces DEF with
DESCRIPTION
when the key sequence ends in KEY. Using a cons cell like this is a valid
definition for `define-key'. All this does is to make which-key aware of it.
Since many higher level keybinding functions use `define-key' internally,
this
will affect most if not all of those as well.
This variable must be set before loading which-key.
---
which-key.el | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/which-key.el b/which-key.el
index e0c0356..22bed08 100644
--- a/which-key.el
+++ b/which-key.el
@@ -476,6 +476,24 @@ it."
:group 'which-key
:type 'boolean)
+(defcustom which-key-enable-extended-define-key nil
+ "Advise `define-key' to make which-key aware of definitions of the form
+
+ \(define-key KEYMAP KEY '(\"DESCRIPTION\" . DEF))
+
+With the advice, this definition will have the side effect of
+creating a replacement in `which-key-replacement-alist' that
+replaces DEF with DESCRIPTION when the key sequence ends in
+KEY. Using a cons cell like this is a valid definition for
+`define-key'. All this does is to make which-key aware of it.
+
+Since many higher level keybinding functions use `define-key'
+internally, this will affect most if not all of those as well.
+
+This variable must be set before loading which-key."
+ :group 'which-key
+ :type 'boolean)
+
;; Hooks
(defcustom which-key-init-buffer-hook '()
"Hook run when which-key buffer is initialized."
@@ -890,6 +908,24 @@ If AT-ROOT is non-nil the binding is also placed at the
root of MAP."
(which-key-define-key-recursively df key def t)))
map))
+(defun which-key--process-define-key-args (keymap key def)
+ "When DEF takes the form (\"DESCRIPTION\". DEF), add an entry
+to `which-key-replacement-alist' so that this binding is replaced
+in which-key with DESCRIPTION. This function is meant to be used
+as :before advice for `define-key'."
+ (when (and (consp def)
+ (stringp (car def))
+ (symbolp (cdr def))
+ (cdr def))
+ (let ((key-desc (regexp-quote (key-description key))))
+ (push (cons (cons (format "%s\\'" key-desc)
+ (format "\\`%s\\'" (symbol-name (cdr def))))
+ (cons nil (car def)))
+ which-key-replacement-alist))))
+
+(when which-key-enable-extended-define-key
+ (advice-add #'define-key :before #'which-key--process-define-key-args))
+
;;; Functions for computing window sizes
(defun which-key--text-width-to-total (text-width)
- [elpa] master updated (a86cf29 -> 56b0fc8), Justin Burkett, 2018/01/08
- [elpa] master 917d2ba 03/21: Improve echo area note for which-key-show-major-mode, Justin Burkett, 2018/01/08
- [elpa] master 70d63a8 02/21: Add which-key-show-major-mode, Justin Burkett, 2018/01/08
- [elpa] master 6d2e17c 01/21: Update which-key version for GNU ELPA, Justin Burkett, 2018/01/08
- [elpa] master 6e8df96 04/21: Consolidate use of binding filters, Justin Burkett, 2018/01/08
- [elpa] master 2934852 05/21: Mention which-key-show-major-mode in README, Justin Burkett, 2018/01/08
- [elpa] master 78a2943 08/21: Fix ordering of default replacement-alist, Justin Burkett, 2018/01/08
- [elpa] master 159f0f9 07/21: Add notes about paging commands not working with minibuffer, Justin Burkett, 2018/01/08
- [elpa] master f516b84 09/21: Add which-key-enable-extended-define-key customization option,
Justin Burkett <=
- [elpa] master 3ff8f48 10/21: Allow null DEF in which-key--process-define-key-args, Justin Burkett, 2018/01/08
- [elpa] master 555c5c1 13/21: Demote errors in which-key--process-define-key-args, Justin Burkett, 2018/01/08
- [elpa] master 0a212c7 11/21: Fix travis build, Justin Burkett, 2018/01/08
- [elpa] master c7e5f76 18/21: Merge pull request #183 from tarsiiformes/silencio, Justin Burkett, 2018/01/08
- [elpa] master 6247cb5 16/21: Simplify implementation of define-key based replacements, Justin Burkett, 2018/01/08
- [elpa] master 1694c6d 15/21: Improve which-key--process-define-key-args, Justin Burkett, 2018/01/08
- [elpa] master b6d04b3 12/21: Fix .travis.yml, Justin Burkett, 2018/01/08
- [elpa] master 7150aa9 14/21: Announce which-key-enable-extended-define-key in README, Justin Burkett, 2018/01/08
- [elpa] master 7559a79 20/21: Version 3.1.0, Justin Burkett, 2018/01/08
- [elpa] master ef384e7 19/21: Fix and improve define-key based replacements, Justin Burkett, 2018/01/08