Permalink
Browse files

Use `execute-extended-command` for running commands

Fixes #28
  • Loading branch information...
1 parent 10838c3 commit 3dd03c0ad948c7ac964a110cc7acc976e3ae3b5a @nonsequitur committed Aug 9, 2013
Showing with 4 additions and 60 deletions.
  1. +0 −3 README.markdown
  2. +4 −57 smex.el
View
@@ -83,9 +83,6 @@ Smex keeps track of.
### Prompt
Set `smex-prompt-string` for a custom prompt.
-### Ignore menu bar bindings
-Enable `smex-key-advice-ignore-menu-bar` to ignore clues to menu bar bindings.
-
## Changelog
### 2.1
View
61 smex.el
@@ -59,11 +59,6 @@ Must be set before initializing Smex."
:type 'string
:group 'smex)
-(defcustom smex-key-advice-ignore-menu-bar nil
- "If non-nil, `smex-key-advice' ignores `menu-bar' bindings"
- :type 'boolean
- :group 'smex)
-
(defcustom smex-flex-matching t
"Enables Ido flex matching. On by default.
Set this to nil to disable fuzzy matching."
@@ -101,25 +96,15 @@ Set this to nil to disable fuzzy matching."
(lambda (ignore) (smex-update) (smex-read-and-run smex-ido-cache ido-text))))
(defun smex-read-and-run (commands &optional initial-input)
- (let ((chosen-item (intern (smex-completing-read commands initial-input))))
+ (let* ((chosen-item-name (smex-completing-read commands initial-input))
+ (chosen-item (intern chosen-item-name)))
(if smex-custom-action
(let ((action smex-custom-action))
(setq smex-custom-action nil)
(funcall action chosen-item))
(unwind-protect
- (progn (setq prefix-arg current-prefix-arg)
- ;; Set the chosen command as the current command, like in
- ;; `execute-extended-command'
- (setq this-command chosen-item)
- (setq real-this-command chosen-item)
- (command-execute chosen-item 'record))
- (smex-rank chosen-item)
- (smex-show-key-advice chosen-item)
- ;; Todo: Is there a better way to manipulate 'last-repeatable-command'
- ;; from the inside of an interactively called function?
- ;; (This is unneeded in Emacs >=24.3 when `real-this-command' has been set.)
- (run-at-time 0.01 nil (lambda (cmd) (setq last-repeatable-command cmd))
- chosen-item)))))
+ (execute-extended-command current-prefix-arg chosen-item-name)
@grammati

grammati Jan 9, 2014

This change seems to be causing M-x to fail for me, with "Wrong number of arguments: execute-extended-command, 2". Emacs 24.2.1 on OSX.

@nonsequitur

nonsequitur Jan 9, 2014

Owner

This has been fixed in Emacs-24.3-universal-10.6.8.dmg (http://emacsformacosx.com/builds). Would it be possible for you to upgrade?

@grammati

grammati Jan 9, 2014

Sure, thanks for the quick reply. I'll let my co-workers know that they should upgrade too.

@sinewalker

sinewalker Jan 28, 2014

I was also bitten by this. I figured it out only because I had a newer emacs on one machine than on the one it broke with. Would it be possible to catch the exception and warn? Or do something smarter with chosen-item name (when (string-lessp version "24.3.0")) ? It may save some headache for others who do package upgrades through ELPA.

I couldn't find any mention of execute-extended-command from emacs' release notes either, so it's a trap for casual players... ;-) I guess because the new param is optional, it didn't warrant them mentioning it. Anyway, the only thing that tipped me off (yes, I should have come to smex's commit log first...) was that C-h f execute-extended-command on 24.2 is a function in C code, whereas in 24.3 it's part of simple.el. Then I had my "ah hah" moment and upgraded emacs :-)

+ (smex-rank chosen-item)))))
(defun smex-major-mode-commands ()
"Like `smex', but limited to commands that are relevant to the active major mode."
@@ -402,44 +387,6 @@ Returns nil when reaching the end of the list."
(interactive)
(smex-do-with-selected-item 'find-function))
-(defvar smex-old-message nil
- "A temporary storage used by `smex-show-key-advice'")
-
-(defun smex-show-key-advice (command)
- "Shows the keybinding for command, if available. Like `execute-extended-command'."
- (let ((advice (smex-key-advice command)))
- (when advice
- (if (current-message)
- (progn
- (run-at-time 2 nil (lambda (advice)
- (setq smex-old-message (current-message))
- (smex-unlogged-message advice)) advice)
-
- (run-at-time 4.5 nil (lambda (advice)
- (if (equal (current-message) advice)
- (smex-unlogged-message smex-old-message))) advice))
- (smex-unlogged-message advice)))))
-
-(defun smex-key-advice (command)
- (let ((keys (where-is-internal command)))
- (if smex-key-advice-ignore-menu-bar
- (setq keys (smex-filter-out-menu-bar-bindings keys)))
- (if keys
- (format "You can run the command `%s' with %s"
- command
- (mapconcat 'key-description keys ", ")))))
-
-(defsubst smex-filter-out-menu-bar-bindings (keys)
- (delq nil (mapcar (lambda (key-vec)
- (unless (equal (aref key-vec 0) 'menu-bar)
- key-vec))
- keys)))
-
-(defun smex-unlogged-message (string)
- "Bypasses logging in *Messages*"
- (let (message-log-max)
- (message "%s" string)))
-
(defun smex-extract-commands-from-keymap (map)
(let (commands)
(smex-parse-keymap map commands)

0 comments on commit 3dd03c0

Please sign in to comment.