I can add not an exact answer to your question, but a workflow that eliminates the need for it.
I use smex instead of execute-extended-command.
Once in the minibuffer of smex:
RET calls execute-extended-command
C-h f calls smex-describe-function
M-. calls smex-find-function
I don't like the default bindings, so I've customized them:
The "easiest way" is to just define your own version of describe-function, and bind that to C-h f.
Take the vanilla code, and change only the call to completing-read so that it uses the same history list that M-x (execute-extended-command) uses, which is extended-command-history.
(defun my-describe-function (function)
"Display the full documentation of ...
Please note that it's very easy to invoke the command from its Help buffer. After typing C-h f just type M-x M-n RET. This works because in a new Help buffer the command name is at the top of the buffer under the cursor, and M-n retrieves it to the minibuffer.
However, if you want to add a command to extended-command-history every time you visit its ...
Based on xuchunyang's answer, I was able to add helm-M-x to helm sources.
(helm-build-sync-source "Emacs commands"
:candidates (lambda ()
(lambda (elt) (when (commandp elt) (push elt cmds))))
Check out https://github.com/syl20bnr/spacemacs/issues/13100.
There was a breaking change in Helm which removed the fuzzy- variables you defined.
In place, you have to set the following variables in your init.el:
(setq helm-completion-style 'emacs)
(setq completion-styles '(flex))
(setq helm-completion-style 'emacs)
The key sequence M-x calls execute-extended-command.
That command uses read-extended-command for reading from minibuffer.
In read-extended-command the c-function completing-read does the main job.
But, the INITIAL-INPUT argument for that command is hard-coded to nil.
We should not temporarily advise completing-read since that function can be compiled-in. ...
You may want to try ivy + ivy-rich.
The relevant section of the documentation has this screenshot:
You need to include the following lines in your init.el:
(setq ivy-use-virtual-buffers t)
(setq enable-recursive-minibuffers t)
(global-set-key (kbd "M-x") 'counsel-M-x)
The quick and dirty way is to pretend you pressed *.
(defun execute-my-extended-command (&rest args)
"Read a command name to call, favoring commands that begin with `*'.
Like `execute-extended-command', but when called interactively, preload a
leading `*' into the minibuffer."
Others have mentioned smex and icicles which give such completions. I'll add Helm. Install from MELPA with M-x package-install helm. (helm-mode t) will turn it on globally. It doesn't steal your M-x key for itself, so also add (global-set-key (kbd "M-x") 'helm-M-x) to give it the key.
C-xz calls repeat which repeats the most recently-excuted command.
Note especially that you can keep repeating the command with only the final key in the sequence. e.g. C-xzzzzz
C-x z runs the command repeat (found in global-map), which is an
interactive autoloaded compiled Lisp function in ‘repeat.el’.
It is bound to C-x z.
The generate-new-buffer function is not an interactive command, and so it cannot be called using M-x. Commands are lisp functions that have an (interactive) form to define how arguments can be provided interactively. M-x can only be used to call such commands.
If you wanted you could write your own command to wrap a function like generate-new-buffer:
You need to distinguish between
interactive command. The latter is also a function, but with the addition of (interactive) to its body.
You can run the latter, but not the former, by binding commands to
keys or calling them by name via M-x. See the elisp manual
links above more more details.
You can use the following command which is independent of the used completion framework because it uses completing-read:
(defun execute-binding+ (arg)
"Completing read a command and execute it.
With ARG non-nil only present commands without a key binding
otherwise only those which have one."
(let ((cmd (completing-read
There is a smex package that among other persists all M-x calls between emacs sessions in MRU.
You can either call smex directly instead of general execute-extended-command or call counsel-M-x (ivy+counsel packages) that will use smex under the hood.
I was thinking helm-m-x could do the same but if not, I believe it could be extended in the similar manner.
You can use savehist-mode to do what you want, if you customize savehist-additional-variables to add command-history to it.
M-x puts each executed command on command-history as a list of the command and the arguments you (implicitly or explicitly) provided. It is not a plain minibuffer history, so it isn't handled automatically by savehist-mode. But if you ...
If you use helm-M-x, there is no need to type C-h f to look up commands's documentation, just use C-j or C-z while running helm-M-x to toggle the display of documentation.
See also Helm M-x's features.
In Icicles you get such completion using S-TAB (by default - you can change the key, of course).
TAB gives you prefix completion. (Or vanilla Emacs completion - e.g., *insert TAB will do as @abo-abo indicated.)
S-TAB gives you "apropos"-style (i.e., regexp) completion, which of course includes substring completion.
Just use a different ...
Have you changed the value of smex-auto-update? The default is t.
smex-auto-update is a compiled Lisp function in `smex.el'.
(smex-auto-update &optional IDLE-TIME)
Update Smex when Emacs has been idle for IDLE-TIME.