help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [External] : Re: Operating the HIST feature of completing-read


From: Drew Adams
Subject: RE: [External] : Re: Operating the HIST feature of completing-read
Date: Tue, 12 Jul 2022 14:28:53 +0000

> Here is practically how history works:
> 
> 1) First you define history variable:
> (defvar my-history nil "...previous inputs.") ⇒ my-history
> 
> 2) You use the history variable:
> (completing-read "X: " '("a" "b") nil nil nil 'my-history) ⇒ "a"
> 
> 3) Now you may inspect history variable:
> my-history ⇒ ("a")
> 
> 4) Now you may inspect the file (find-file "~/.emacs.d/history")
>    where history variable will be recorded so that
>    history works over Emacs sessions
> 
> 5) You may browse through history by using M-n and M-p as to easy
>    selection of your previously recorded choices (history).

Good summary.  Some more:

1. If you don't pass a value as the HIST arg to
minibuffer-reading functions such as `completing-read'
then the implied, general history variable is used:
`minibuffer-history'.

IOW, your minibuffer-input history is always
recorded in a history variable, whether or not you
pass a HIST variable.

If you want to keep a separate history list for some
interactions then pass a separate history variable.
If you don't care about keeping a separate list for
some inputs then don't pass an explicit HIST.

2. How do you make use of the history list currently
available during a read from the minibuffer?  As
Jean mentioned, use `M-p' and `M-n' to cycle among
historical inputs.  Or use `M-r' and `M-s' to access
them directly by matching regexps.

3. Ask Emacs!

`C-h r', `i histor TAB', choose a candidate such as
`history of minibuffer input'.  That takes you to
node `Minibuffer History' in the Emacs manual:

https://www.gnu.org/software/emacs/manual/html_node/emacs/Minibuffer-History.html

`C-h i m el', `i histor TAB', choose a candidate
such as `history list'.  That takes you to node
`Minibuffer History' in the Elisp manual:

https://www.gnu.org/software/emacs/manual/html_node/elisp/Minibuffer-History.html

Emacs answers your questions.  And by asking Emacs
you learn to converse with Emacs, i.e., to ask it
better, posing your questions using terms that
Emacs understands best.  (And those terms are also
those best understood by the Emacs community, if
you do ask outside Emacs itself.)

Do yourself a favor and learn to communicate with
Emacs more fluently.  There are many levels/layers
to explore & learn, and each opens doors to others.

Learning how to talk with Emacs is more productive
than posing lots of one-off questions here and
there.  And if you do pose questions about Emacs
outside Emacs then the most helpful questions will
be about ways how to converse with Emacs (asking
about asking Emacs).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]