Future History In The Minibuffer

Bozhidar Batsov has a lovely post on searching the future history of the minibuffer. We all know about using Meta+p to search backwards in the minibuffer history and that you can also use Meta+n to search forward from one of the old entries. It turns out, though, that you can search forward even without searching backwards first. What you get is what Emacs calls the future history of the minibuffer. What this means is dependent on the command you’re using but the idea is that it will present you with one or more likely choices. For example, if you invoke Meta+n on a find-file command, you will get the file at point if there is one.

That alone is useful to know but there are many other commands that benefit from this. These include, query-replace, occur, and others. See Batsov’s post for a longer list with explanations of what you get. Sometimes the future history will include several choices and you can scroll through them in the usual way using Meta+n and Meta+p.

When the command lists the default explicitly, you can use Meta+n to bring it into the minibuffer for editing in case it’s not exactly what you want. I wrote about this back in 2019 but that post didn’t begin to tell the whole future history story.

It turns out to be easy to enable this in your own code. See Batsov’s code for some examples.

This is one of those things that I, at least, find easy to forget. It’s a really useful facility and well worth internalizing.

This entry was posted in General and tagged . Bookmark the permalink.