emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 100bd21 001/399: counsel.el (counsel-M-x): Optionally expa


From: Oleh Krehel
Subject: [elpa] master 100bd21 001/399: counsel.el (counsel-M-x): Optionally expand aliases
Date: Sat, 20 Jul 2019 14:56:36 -0400 (EDT)

branch: master
commit 100bd2130b6963bbdcb0bec346abee2d9e2d829e
Author: Andrew Schwartzmeyer <address@hidden>
Commit: Andrew Schwartzmeyer <address@hidden>

    counsel.el (counsel-M-x): Optionally expand aliases
    
    Added support via `counsel-M-x-transformer` to show the expansion of an
    alias in a manner similar to how keybindings are shown. For example, if
    `rb` is aliased to `revert-buffer`, and bound to `C-c r`, `M-x rb` will
    show `rb (revert-buffer) (C-c r)`.
    
    Currently the expansion is in the same font as the command, which looks
    nice, but it would be easy to add support for a custom face.
    
    The boolean `counsel-alias-expand` was introduced to enable or disable
    this functionality, with it defaulting to non-nil.
---
 counsel.el | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/counsel.el b/counsel.el
index 97423ec..ee78d9f 100644
--- a/counsel.el
+++ b/counsel.el
@@ -748,22 +748,30 @@ With prefix arg MODE a query for the symbol help mode is 
offered."
   "Face used by `counsel-M-x' for key bindings."
   :group 'ivy-faces)
 
+(defcustom counsel-alias-expand t
+  "When non-nil, show the expansion of aliases in `counsel-M-x'."
+  :type 'boolean
+  :group 'ivy)
+
 (defun counsel-M-x-transformer (cmd)
   "Return CMD annotated with its active key binding, if any."
-  (let ((key (where-is-internal (intern cmd) nil t)))
-    (if (not key)
-        cmd
-      ;; Prefer `<f2>' over `C-x 6' where applicable
-      (let ((i (cl-search [?\C-x ?6] key)))
-        (when i
-          (let ((dup (vconcat (substring key 0 i) [f2] (substring key (+ i 
2))))
-                (map (current-global-map)))
-            (when (equal (lookup-key map key)
-                         (lookup-key map dup))
-              (setq key dup)))))
-      (setq key (key-description key))
-      (put-text-property 0 (length key) 'face 'counsel-key-binding key)
-      (format "%s (%s)" cmd key))))
+  (let ((alias (symbol-function (intern cmd)))
+        (key (where-is-internal (intern cmd) nil t)))
+    (concat cmd
+            (when (and (symbolp alias) counsel-alias-expand)
+              (format " (%s)" alias))
+            (when key
+              ;; Prefer `<f2>' over `C-x 6' where applicable
+              (let ((i (cl-search [?\C-x ?6] key)))
+                (when i
+                  (let ((dup (vconcat (substring key 0 i) [f2] (substring key 
(+ i 2))))
+                        (map (current-global-map)))
+                    (when (equal (lookup-key map key)
+                                 (lookup-key map dup))
+                      (setq key dup)))))
+              (setq key (key-description key))
+              (put-text-property 0 (length key) 'face 'counsel-key-binding key)
+              (format " (%s)" key)))))
 
 (defvar amx-initialized)
 (defvar amx-cache)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]