From 5284e904cc7e9dc1e5dd57de94f0dd789db74d15 Mon Sep 17 00:00:00 2001 From: justbur Date: Tue, 26 Apr 2016 09:07:12 -0400 Subject: [PATCH 1/5] Add support for god-mode Needs to be explicitly activated by calling (which-key-enable-god-mode-support) --- which-key.el | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/which-key.el b/which-key.el index ae58344153c..1504519d856 100644 --- a/which-key.el +++ b/which-key.el @@ -501,6 +501,30 @@ sequence. prefix-title is a string. The title is displayed alongside the actual current key sequence when `which-key-show-prefix' is set to either top or echo.") +;; God-mode +(defvar which-key--god-mode-support-enabled nil + "Support god-mode if non-nil. This is experimental, +so you need to explicitly opt-in for now. Please report any +problems at github.") + +(defvar which-key--god-mode-key-string nil + "Holds key string to use for god-mode support.") + +(defadvice god-mode-lookup-command (before which-key--god-mode-advice disable) + (setq which-key--god-mode-key-string (ad-get-arg 0))) + +(defun which-key-enable-god-mode-support (&optional disable) + "Enable support for god-mode if non-nil. This is experimental, +so you need to explicitly opt-in for now. Please report any +problems at github. If DISABLE is non-nil disable support." + (interactive "P") + (setq which-key--god-mode-support-enabled (null disable)) + (if disable + (ad-disable-advice 'god-mode-lookup-command + 'before 'which-key--god-mode-advice) + (ad-enable-advice 'god-mode-lookup-command + 'before 'which-key--god-mode-advice))) + ;;;###autoload (define-minor-mode which-key-mode "Toggle which-key-mode." @@ -2054,6 +2078,10 @@ Finally, show the buffer." (error (progn (message "which-key error in key-chord handling") [key-chord]))))) + (when (and which-key--god-mode-support-enabled + (bound-and-true-p god-local-mode) + (eq this-command 'god-mode-self-insert)) + (setq prefix-keys (kbd which-key--god-mode-key-string))) (cond ((and (> (length prefix-keys) 0) (or (keymapp (key-binding prefix-keys)) ;; Some keymaps are stored here like iso-transl-ctl-x-8-map @@ -2067,6 +2095,9 @@ Finally, show the buffer." ;; executed (or (and which-key-allow-evil-operators (bound-and-true-p evil-this-operator)) + (and which-key--god-mode-support-enabled + (bound-and-true-p god-local-mode) + (eq this-command 'god-mode-self-insert)) (null this-command))) (which-key--create-buffer-and-show prefix-keys) (when which-key-idle-secondary-delay From bfc5c38b6d4de1bfc250b407dc8d99209f424953 Mon Sep 17 00:00:00 2001 From: justbur Date: Tue, 26 Apr 2016 09:18:20 -0400 Subject: [PATCH 2/5] Add third-party support section to readme --- README.org | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index f3b29526986..74baeb27811 100644 --- a/README.org +++ b/README.org @@ -13,7 +13,6 @@ to a certain extent. ** Table of Contents :TOC@4: - [[#which-key-][which-key ]] - - [[#whats-new][What's New]] - [[#introduction][Introduction]] - [[#install][Install]] - [[#melpa][MELPA]] @@ -39,6 +38,10 @@ to a certain extent. - [[#method-2-bind-your-own-keys][Method 2: Bind your own keys]] - [[#face-customization-options][Face Customization Options]] - [[#other-options][Other Options]] + - [[#support-for-third-party-libraries][Support for Third-Party Libraries]] + - [[#key-chord][Key-chord]] + - [[#evil-operators][Evil operators]] + - [[#god-mode][God-mode]] - [[#more-examples][More Examples]] - [[#nice-display-with-split-frame][Nice Display with Split Frame]] - [[#status][Status]] @@ -52,7 +55,6 @@ minor mode of course. *** Manually Add which-key.el to your =load-path= and require. Something like - #+BEGIN_SRC emacs-lisp (add-to-list 'load-path "path/to/which-key.el") (require 'which-key) @@ -434,6 +436,24 @@ shown. ;; Set to t to show the count of keys shown vs. total keys in the mode line. (setq which-key-show-remaining-keys nil) #+END_SRC +** Support for Third-Party Libraries + Some support is provided for third-party libraries which don't use standard + methods of looking up commands. Some of these need to be enabled + explicitly. This code includes some hacks, so please report any problems. +*** Key-chord + Enabled by default. +*** Evil operators + Evil motions and text objects following an operator like =d= are not all + looked up in a standard way. Support is controlled through + =which-key-allow-evil-operators= which should be non-nil if evil is loaded + before which-key and through =which-key-show-operator-state-maps= which + needs to be enabled explicitly because it is more of a hack. The former + allows for the inner and outer text object maps to show, while the latter + shows motions as well. +*** God-mode + Call =(which-key-enable-god-mode-support)= after loading god-mode to enable + support for god-mode key sequences. This is new and experimental, so please + report any issues. ** More Examples *** Nice Display with Split Frame Unlike guide-key, which-key looks good even if the frame is split into several From 137ccbbac7beff6899c694a673cd913a1789ed5a Mon Sep 17 00:00:00 2001 From: justbur Date: Tue, 26 Apr 2016 09:18:48 -0400 Subject: [PATCH 3/5] Add third-party section to which-key.el --- which-key.el | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/which-key.el b/which-key.el index 1504519d856..1153b072d05 100644 --- a/which-key.el +++ b/which-key.el @@ -326,21 +326,6 @@ prefixes in `which-key-paging-prefixes'" "No longer applies. See `which-key-C-h-dispatch'" "2015-12-2") -(defcustom which-key-allow-evil-operators (boundp 'evil-this-operator) - "Allow popup to show for evil operators. The popup is normally - inhibited in the middle of commands, but setting this to - non-nil will override this behavior for evil operators." - :group 'which-key - :type 'boolean) - -(defcustom which-key-show-operator-state-maps nil - "Experimental: Try to show the right keys following an evil -command that reads a motion, such as \"y\", \"d\" and \"c\" from -normal state. This is experimental, because there might be some -valid keys missing and it might be showing some invalid keys." - :group 'which-key - :type 'boolean) - (defcustom which-key-hide-alt-key-translations t "Hide key translations using Alt key if non nil. These translations are not relevant most of the times since a lot @@ -501,6 +486,25 @@ sequence. prefix-title is a string. The title is displayed alongside the actual current key sequence when `which-key-show-prefix' is set to either top or echo.") + +;; Third-party library support + +;; Evil +(defcustom which-key-allow-evil-operators (boundp 'evil-this-operator) + "Allow popup to show for evil operators. The popup is normally + inhibited in the middle of commands, but setting this to + non-nil will override this behavior for evil operators." + :group 'which-key + :type 'boolean) + +(defcustom which-key-show-operator-state-maps nil + "Experimental: Try to show the right keys following an evil +command that reads a motion, such as \"y\", \"d\" and \"c\" from +normal state. This is experimental, because there might be some +valid keys missing and it might be showing some invalid keys." + :group 'which-key + :type 'boolean) + ;; God-mode (defvar which-key--god-mode-support-enabled nil "Support god-mode if non-nil. This is experimental, From 9a5d4c5b15bf3efd9f3f9875cd2849f222046689 Mon Sep 17 00:00:00 2001 From: justbur Date: Tue, 26 Apr 2016 14:16:08 -0400 Subject: [PATCH 4/5] Fix minor issues with god-mode support Make sure advice is activated for god-mode-lookup-command Check for null which-key--god-mode-key-string --- which-key.el | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/which-key.el b/which-key.el index 1153b072d05..23f71917451 100644 --- a/which-key.el +++ b/which-key.el @@ -523,11 +523,13 @@ so you need to explicitly opt-in for now. Please report any problems at github. If DISABLE is non-nil disable support." (interactive "P") (setq which-key--god-mode-support-enabled (null disable)) + (ad-deactivate 'god-mode-lookup-command) (if disable (ad-disable-advice 'god-mode-lookup-command 'before 'which-key--god-mode-advice) (ad-enable-advice 'god-mode-lookup-command - 'before 'which-key--god-mode-advice))) + 'before 'which-key--god-mode-advice)) + (ad-activate 'god-mode-lookup-command)) ;;;###autoload (define-minor-mode which-key-mode @@ -2085,7 +2087,8 @@ Finally, show the buffer." (when (and which-key--god-mode-support-enabled (bound-and-true-p god-local-mode) (eq this-command 'god-mode-self-insert)) - (setq prefix-keys (kbd which-key--god-mode-key-string))) + (setq prefix-keys (when which-key--god-mode-key-string + (kbd which-key--god-mode-key-string)))) (cond ((and (> (length prefix-keys) 0) (or (keymapp (key-binding prefix-keys)) ;; Some keymaps are stored here like iso-transl-ctl-x-8-map From cc2a561a16ff8d1206603525343f26854395206c Mon Sep 17 00:00:00 2001 From: justbur Date: Tue, 26 Apr 2016 14:26:25 -0400 Subject: [PATCH 5/5] Add advice for god-mode support to hide popup The standard way to hide the popup before the command is not working. --- which-key.el | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/which-key.el b/which-key.el index 23f71917451..a78d49562a6 100644 --- a/which-key.el +++ b/which-key.el @@ -514,22 +514,36 @@ problems at github.") (defvar which-key--god-mode-key-string nil "Holds key string to use for god-mode support.") -(defadvice god-mode-lookup-command (before which-key--god-mode-advice disable) +(defadvice god-mode-lookup-command + (before which-key--god-mode-lookup-command-advice disable) (setq which-key--god-mode-key-string (ad-get-arg 0))) +(defadvice god-mode-self-insert + (after which-key--god-mode-self-insert-advice disable) + (which-key--hide-popup)) + (defun which-key-enable-god-mode-support (&optional disable) "Enable support for god-mode if non-nil. This is experimental, so you need to explicitly opt-in for now. Please report any problems at github. If DISABLE is non-nil disable support." (interactive "P") (setq which-key--god-mode-support-enabled (null disable)) - (ad-deactivate 'god-mode-lookup-command) (if disable - (ad-disable-advice 'god-mode-lookup-command - 'before 'which-key--god-mode-advice) - (ad-enable-advice 'god-mode-lookup-command - 'before 'which-key--god-mode-advice)) - (ad-activate 'god-mode-lookup-command)) + (progn + (ad-disable-advice + 'god-mode-lookup-command + 'before 'which-key--god-mode-lookup-command-advice) + (ad-disable-advice + 'god-mode-self-insert + 'after 'which-key--god-mode-self-insert-advice)) + (ad-enable-advice + 'god-mode-lookup-command + 'before 'which-key--god-mode-lookup-command-advice) + (ad-enable-advice + 'god-mode-self-insert + 'after 'which-key--god-mode-self-insert-advice)) + (ad-activate 'god-mode-lookup-command) + (ad-activate 'god-mode-self-insert)) ;;;###autoload (define-minor-mode which-key-mode