Skip to content

Commit

Permalink
Patch smex to show keybindings.
Browse files Browse the repository at this point in the history
Upstream pull request: nonsequitur/smex#55
  • Loading branch information
Wilfred committed Nov 14, 2015
1 parent ee90b2f commit c50b576
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions elpa/smex-20150822.1146/smex.el
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,28 @@ Set this to nil to disable fuzzy matching."
(setq commands (mapcar #'symbol-name commands))
(smex-read-and-run commands)))

(defun smex-extract-command-name (pretty-name)
"Given a string \"foo (C-c f)\", return \"foo\"."
(car (split-string pretty-name " ")))

(defun smex-find-keybinding (command)
"Find the first keybinding for COMMAND, if one exists.
Uses the currently active keymap."
(let* ((keybindings (where-is-internal command))
(first-binding (car keybindings)))
(when first-binding
(key-description first-binding))))

(defun smex-completing-read (choices initial-input)
(let ((ido-completion-map ido-completion-map)
(ido-setup-hook (cons 'smex-prepare-ido-bindings ido-setup-hook))
(ido-enable-prefix nil)
(ido-enable-flex-matching smex-flex-matching)
(ido-max-prospects 10)
(minibuffer-completion-table choices))
(ido-completing-read (smex-prompt-with-prefix-arg) choices nil nil
initial-input 'extended-command-history (car choices))))
(smex-extract-command-name
(ido-completing-read (smex-prompt-with-prefix-arg) choices nil nil
initial-input 'extended-command-history (car choices)))))

(defun smex-prompt-with-prefix-arg ()
(if (not current-prefix-arg)
Expand Down Expand Up @@ -184,7 +197,14 @@ Set this to nil to disable fuzzy matching."
(setq smex-ido-cache (smex-convert-for-ido smex-cache)))

(defun smex-convert-for-ido (command-items)
(mapcar (lambda (command-item) (symbol-name (car command-item))) command-items))
(mapcar (lambda (command-item)
(let* ((command (car command-item))
(keybinding (smex-find-keybinding command))
(command-name (symbol-name command)))
(if keybinding
(format "%s (%s)" command-name keybinding)
command-name)))
command-items))

(defun smex-restore-history ()
"Rearranges `smex-cache' according to `smex-history'"
Expand Down

0 comments on commit c50b576

Please sign in to comment.