Since my first answer doesn't directly give you what you want, I thought I'd come up with a real solution. This is what I have:
(defvar my-execute-extended-command-source-buffer nil
"var holding the buffer to which the extended-execute-command should apply")
(defvar in-my-execute-extended-command nil
"internal use - indicates whether we're in a 'recursive edit' of sorts")
(defun my-execute-extended-command (command)
"home-grown version of execute-extended-command that supports re-hosting the buffer"
(interactive (list (if in-my-execute-extended-command
nil
(let ((in-my-execute-extended-command t))
(setq my-execute-extended-command-source-buffer (current-buffer))
(completing-read "My-x " obarray 'commandp t nil 'extended-command-history nil nil)))))
(if in-my-execute-extended-command
(progn (setq my-execute-extended-command-source-buffer (current-buffer))
(select-window (minibuffer-window)))
(switch-to-buffer my-execute-extended-command-source-buffer)
(call-interactively (symbol-function (intern command)))))
I've tested it this way. I bound it to a key (F10
in my case b/c I didn't want to lose M-x
). Then, with two windows open, each showing a different buffer (say A and B):
- From window showing buffer A:
F10 isearch-for
- Switch from minibuffer to window showing A:
C-x o
- Switch from window showing A to that showing B:
C-x o
- "re-host" the command from buffer B:
F10
- Now back in the minibuffer, finish the command
ward RET
When I started typing a search term, the search applied to buffer B.
This only replaces the M-x
functionality, not the commands invoked from M-x
. Also, this version does not support the prefix argument.
Hopefully this is what you want.