Reputation: 637
I want to set up a sort of ISearch mode replacement in Emacs, where I can run a command after every input to the minibuffer. Is it possible?
EDIT 1:
The idea is to completely replace ISearch with my own mode. Ideally, I'd like it to have most of the functionality that ISearch has (like highlighting results as you type). To implement some, I'd need to run a command after every key is input. Is there a way to trigger a function when the minibuffer change, or should I use something that isn't the minibuffer?
EDIT 2:
To be more specific, basically I am looking to take a string from the minibuffer and highlight all matches in the buffer, much like in ISearch mode. So essentially, after each letter, symbol, or number inputted into the minibuffer, I'd like to be able to recognize that change and run some arbitrary elisp. Similar to how helm recognizes input and updates search results.
Upvotes: 5
Views: 583
Reputation: 28531
You wan to use minibuffer-with-setup-hook
and in the setup hook, you'll want to either use post-command-hook
or after-change-functions
.
E.g.
(defun my-update-function (beg end len)
(let ((str (minibuffer-contents)))
<update-search-result>))
..(minibuffer-with-setup-hook
(lambda ()
(add-hook 'after-change-functions #'my-update-function))
...(read-string ...) ...)
Upvotes: 4
Reputation: 30701
See variable minibuffer-exit-hook
.
In general, for this kind of question, look for a variable whose name ends in hook
(or function
or functions
). Use commands such as apropos
to find a variable (or function) whose name contains various substrings (e.g. -hook
, minibuf
).
Your question is, however, a bit unclear. Will you actually be using Isearch, or are you going to replace Isearch with something that uses the minibuffer? Please specify more precisely what you are doing.
FYI - Isearch does not use the minibuffer (except when you use M-e
to edit the search string).
Update after your Edit 1:
Now I'm afraid your question is too broad, and risks being closed for that reason. You are essentially vaguely asking how to implement some kind of a replacement for Isearch.
If you want to do something after each command, see post-command-hook
. But beware that nearly every key press is a command invocation.
Update after your Edit 2:
In that case, consider looking at what other libraries do in this regard. For example, highlight.el
(e.g. hlt-highlight-symbol
), highlight-symbol.el
, color-moccur.el
, Icicles (e.g. icicle-occur
), and Helm (e.g. helm-swoop
). Some of those, such as Icicles and Helm, provide incremental highlighting update as you describe. Others highlight a given name that is entered in the minibuffer (i.e., using RET
, not just characters typed in the minibuffer).
But you might want to specify what you want that is different from what such libraries already do. Your question still seems overly broad, to me.
In general, things such as Isearch that do incremental updating read key presses and respond accordingly. They may do this from the minibuffer or at top level, but the point is that they generally do not require a user to enter something in the minibuffer, using RET
. They respond after each key press (or each command invocation, e.g. via post-command-hook
).
Upvotes: 1