Letzte Änderung
Zusammenfassung: smex update patch on github
Eingefügt:
> See also [https://github.com/nonsequitur/smex/pull/4 Update smex after function calls that are likely to define new commands]
Smex is a M-x enhancement for Emacs. Built on top of IDO, it provides a convenient interface to your recently and most frequently used commands. And to all the other commands, too.
Extras: Limit commands to those relevant to the active major mode. Show frequently used commands that have no key bindings.
Via package.el, el-get or http://github.com/nonsequitur/smex/blob/master/smex.el?raw=true
http://github.com/nonsequitur/smex/
I install smex with the following code to make emacs startup a little faster. This delays initializing smex until it’s needed. IMO, smex should load without this hack. Just have smex call ‘smex-initialize’ when it’s needed instead of having the user do it. --LeWang
(global-set-key [(meta x)] (lambda ()
(interactive)
(or (boundp 'smex-cache)
(smex-initialize))
(global-set-key [(meta x)] 'smex)
(smex)))
(global-set-key [(shift meta x)] (lambda ()
(interactive)
(or (boundp 'smex-cache)
(smex-initialize))
(global-set-key [(shift meta x)] 'smex-major-mode-commands)
(smex-major-mode-commands)))
How to modify smex so that typing a space will insert a hyphen ‘-’ like in normal M-x?
(defadvice smex (around space-inserts-hyphen activate compile)
(let ((ido-cannot-complete-command
`(lambda ()
(interactive)
(if (string= " " (this-command-keys))
(insert ?-)
(funcall ,ido-cannot-complete-command)))))
ad-do-it))
If there is only one match it will be completed instead of inserting a hyphen (which may well be a desirable thing). To avoid that, fset ido-complete-space to that lambda form above, then fset it back after ad-do-it (flet doesn’t work for interactive functions).
See also ido-complete-space-or-hyphen.
I don’t like to have smex update every time I run (auto-update is usually good enough, and is noticeably faster). But it’s annoying when I manually load a file and the new commands are not in smex. So I add a smex-update to after-load-functions.
(defun smex-update-after-load (unused)
(when (boundp 'smex-cache)
(smex-update)))
(add-hook 'after-load-functions 'smex-update-after-load)See also Update smex after function calls that are likely to define new commands
You can see mnemonical commands (within completion) before the others with this code snippet:
(defadvice ido-set-matches-1 (after ido-acronym-matches activate)
(if (> (length ido-text) 1)
(let ((regex (concat "^" (mapconcat 'char-to-string ido-text "[^-]*-")
"[^-]*$")))
(setq ad-return-value
(append (reverse (remove-if-not (lambda (i)
(string-match regex i)) items))
ad-return-value)))))
e.g. without this code the completion of ‘ffow’ shows:
{ ediff-show-registry | Buffer-menu-1-window | Buffer-menu-2-window ...
with:
{ find-file-other-window | find-function-other-window | ediff-show-registry ...
Warning: as you can see, this is an advice for ‘ido-set-matches-1’ and it’s run on every ‘ido-completing-read’. Is there a way to ignore all calls but smex?