If you don't specify @var{history}, then the default history list
@code{minibuffer-history} is used. For other standard history lists,
see below. You can also create your own history list variable; just
-initialize it to @code{nil} before the first use.
+initialize it to @code{nil} before the first use. If the variable is
+buffer local, then each buffer will have its own input history list.
Both @code{read-from-minibuffer} and @code{completing-read} add new
elements to the history list automatically, and provide commands to
key binding with an upper case letter - if you can type it, you can
bind it.
++++
+** 'read-from-minibuffer' now works with buffer-local history variables.
+The HIST argument of 'read-from-minibuffer' now works correctly with
+buffer-local variables. This means that different buffers can have
+their own separated input history list if desired.
+
\f
* Editing Changes in Emacs 27.1
(null minibuffer-text-before-history))
(setq minibuffer-text-before-history
(minibuffer-contents-no-properties)))
- (let ((history (symbol-value minibuffer-history-variable))
+ (let ((history (minibuffer-history-value))
(case-fold-search
(if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped
;; On some systems, ignore case for file names.
(append def all)
(cons def (delete def all)))))
+(defun minibuffer-history-value ()
+ "Return the value of the minibuffer input history list.
+If `minibuffer-history-variable' points to a buffer-local variable and
+the minibuffer is active, return the buffer-local value for the buffer
+that was current when the minibuffer was activated."
+ (buffer-local-value minibuffer-history-variable
+ (window-buffer (minibuffer-selected-window))))
+
(defun goto-history-element (nabs)
"Puts element of the minibuffer history in the minibuffer.
The argument NABS specifies the absolute history position in
(user-error (if minibuffer-default
"End of defaults; no next item"
"End of history; no default available")))
- (if (> nabs (if (listp (symbol-value minibuffer-history-variable))
- (length (symbol-value minibuffer-history-variable))
+ (if (> nabs (if (listp (minibuffer-history-value))
+ (length (minibuffer-history-value))
0))
(user-error "Beginning of history; no preceding item"))
(unless (memq last-command '(next-history-element
(setq minibuffer-returned-to-present t)
(setq minibuffer-text-before-history nil))
(t (setq elt (nth (1- minibuffer-history-position)
- (symbol-value minibuffer-history-variable)))))
+ (minibuffer-history-value)))))
(insert
(if (and (eq minibuffer-history-sexp-flag (minibuffer-depth))
(not minibuffer-returned-to-present))
;; beginning/end of the history, wrap the search to the first/last
;; minibuffer history element.
(if isearch-forward
- (goto-history-element (length (symbol-value minibuffer-history-variable)))
+ (goto-history-element (length (minibuffer-history-value)))
(goto-history-element 0))
(setq isearch-success t)
(goto-char (if isearch-forward (minibuffer-prompt-end) (point-max))))
Lisp_Object histvar, Lisp_Object histpos, Lisp_Object defalt,
bool allow_props, bool inherit_input_method)
{
- Lisp_Object val;
+ Lisp_Object val, previous_buffer = Fcurrent_buffer ();
ptrdiff_t count = SPECPDL_INDEX ();
Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
Lisp_Object enable_multibyte;
/* Add the value to the appropriate history list, if any. */
if (! (NILP (Vhistory_add_new_input) || NILP (histstring)))
- call2 (intern ("add-to-history"), Vminibuffer_history_variable, histstring);
+ {
+ ptrdiff_t count2 = SPECPDL_INDEX ();
+
+ /* If possible, switch back to the previous buffer first, in
+ case the history variable is buffer-local. */
+ if (BUFFER_LIVE_P (XBUFFER (previous_buffer)))
+ {
+ record_unwind_current_buffer ();
+ Fset_buffer (previous_buffer);
+ }
+
+ call2 (intern ("add-to-history"), Vminibuffer_history_variable, histstring);
+ unbind_to (count2, Qnil);
+ }
/* If Lisp form desired instead of string, parse it. */
if (expflag)
starting from 1 at the beginning of the list. If HIST is the symbol
`t', history is not recorded.
+ If `history-add-new-input' is non-nil (the default), the result will
+ be added to the history list using `add-to-history'.
+
Sixth arg DEFAULT-VALUE, if non-nil, should be a string, which is used
as the default to `read' if READ is non-nil and the user enters
empty input. But if READ is nil, this function does _not_ return