Dernière modification majeure (modifications mineures suivantes)
Résumé : smex update patch on github
Modifié(e) :
< == Discussion ==
à
> == Customization/Hacks ==
Modifié(e) :
< Does anyone know how to modify smex so that typing a space will insert a hyphen '-' like in normal M-x?
< : Space already has the function of paging through the list of possible completions. But what's even better than typing a space is not typing anything; I see that in smex you can just type the function name as one word without hyphens, and it still works, including auto-completion. BTW, I think smex is very cool! -- ThomasKappler
< [new:IstaZahn:2010-06-17 16:16 UTC]
< : I disagree that not typing anything is better than typing a space. Commands often have a word-like structure, and the separation is important. So I'm adding my voice the the request for a way to restore the old functionality and have the space key insert a hyphen.
< [new]
< : This issue is not specific to Smex and a fix would benefit all Ido users. It will be addressed by the next Smex release.
< [new:IstaZahn:2010-06-19 03:14 UTC]
< : I did not mean to imply that the issue is specific to smex. Indeed, the same issue occurs when following the instructions to add [http://www.emacswiki.org/emacs/InteractivelyDoThings#toc5/ M-x support to ido]. Thanks for taking this on, it will really make it easier for me to use smex!
< [new:Anonymous:2011-03-10 04:41 UTC]
< : I, too, want this effect, especially since omitting the hyphen seems to make the completion function do *alot* more work; i.e. when the next character in the command name is a hyphen and you omit the hyphen, there's a noticable lag as you type the rest of the characters in the name (try typing M-x backward-delete-char-untabify). Here's an easy fix, though if there is only one match it will be completed instead of inserting a hyphen, which may well be a desirable thing:
à
> === Hyphen on Space ===
> How to modify smex so that typing a space will insert a hyphen ‘-’ like in normal M-x?
Modifié(e) :
< : To not have it complete if there's only one match, fset ##ido-complete-space## to that lambda form above, then fset it back after ##ad-do-it## (##flet## doesn't work for interactive functions).
< [new]
< /Wicked cool./ Is it inspired by this [http://www.vimeo.com/1013263 video]? :)
< [new:Ian Yang:2012-12-07 07:20 UTC]
< I wrote a function that will also test whether hyphen can be inserted when press space. See [https://github.com/doitian/ido-complete-space-or-hyphen ido-complete-space-or-hyphen].
à
> 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 [https://github.com/doitian/ido-complete-space-or-hyphen ido-complete-space-or-hyphen].
> === Update less often ===
Modifié(e) :
< == Using acronyms ==
à
> === Using acronyms ===
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?