aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFederico Tedin2019-12-05 10:30:17 +0100
committerLars Ingebrigtsen2019-12-05 10:30:28 +0100
commit3586fef263ccf3b68cc1289d55ef44a3d9ac7e1d (patch)
tree9afa19b840fbef8fc61a3efbc4e148904195596c
parent9027084793831031926c12d3bdfa132ec6ac4e60 (diff)
downloademacs-3586fef263ccf3b68cc1289d55ef44a3d9ac7e1d.tar.gz
emacs-3586fef263ccf3b68cc1289d55ef44a3d9ac7e1d.zip
Make HIST arg of read-from-minibuffer work with buffer-local vars
* lisp/simple.el (minibuffer-history-values): New function, should be used to access the minibuffer input history variable when the minibuffer might be active. If the variable is buffer-local, the previous buffer's value will be used. (goto-history-element): Use the new function to access the minibuffer history. (minibuffer-history-isearch-wrap): Use the new function to access the minibuffer history. * src/minibuf.c (read_minibuf): Switch to previous buffer temporarily before updating history list (Bug#38317). (read-from-minibuffer): Extend documentation to mention that the result of using the command will be added to the history list by default. * doc/lispref/minibuf.texi (Minibuffer History): Mention the possibility of using a buffer-local variable as history. * etc/NEWS: Announce changes.
-rw-r--r--doc/lispref/minibuf.texi3
-rw-r--r--etc/NEWS6
-rw-r--r--lisp/simple.el18
-rw-r--r--src/minibuf.c20
4 files changed, 39 insertions, 8 deletions
diff --git a/doc/lispref/minibuf.texi b/doc/lispref/minibuf.texi
index 4a218fe7378..dde30ce67f7 100644
--- a/doc/lispref/minibuf.texi
+++ b/doc/lispref/minibuf.texi
@@ -547,7 +547,8 @@ to the minibuffer input function (@pxref{Initial Input}).
547 If you don't specify @var{history}, then the default history list 547 If you don't specify @var{history}, then the default history list
548@code{minibuffer-history} is used. For other standard history lists, 548@code{minibuffer-history} is used. For other standard history lists,
549see below. You can also create your own history list variable; just 549see below. You can also create your own history list variable; just
550initialize it to @code{nil} before the first use. 550initialize it to @code{nil} before the first use. If the variable is
551buffer local, then each buffer will have its own input history list.
551 552
552 Both @code{read-from-minibuffer} and @code{completing-read} add new 553 Both @code{read-from-minibuffer} and @code{completing-read} add new
553elements to the history list automatically, and provide commands to 554elements to the history list automatically, and provide commands to
diff --git a/etc/NEWS b/etc/NEWS
index 20b86173e93..d4f31aeb85d 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -522,6 +522,12 @@ Note that this key binding will not work on MS-Windows systems if
522key binding with an upper case letter - if you can type it, you can 522key binding with an upper case letter - if you can type it, you can
523bind it. 523bind it.
524 524
525+++
526** 'read-from-minibuffer' now works with buffer-local history variables.
527The HIST argument of 'read-from-minibuffer' now works correctly with
528buffer-local variables. This means that different buffers can have
529their own separated input history list if desired.
530
525 531
526* Editing Changes in Emacs 27.1 532* Editing Changes in Emacs 27.1
527 533
diff --git a/lisp/simple.el b/lisp/simple.el
index 47ce0364d14..5e4cd8f5bc0 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2041,7 +2041,7 @@ See also `minibuffer-history-case-insensitive-variables'."
2041 (null minibuffer-text-before-history)) 2041 (null minibuffer-text-before-history))
2042 (setq minibuffer-text-before-history 2042 (setq minibuffer-text-before-history
2043 (minibuffer-contents-no-properties))) 2043 (minibuffer-contents-no-properties)))
2044 (let ((history (symbol-value minibuffer-history-variable)) 2044 (let ((history (minibuffer-history-value))
2045 (case-fold-search 2045 (case-fold-search
2046 (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped 2046 (if (isearch-no-upper-case-p regexp t) ; assume isearch.el is dumped
2047 ;; On some systems, ignore case for file names. 2047 ;; On some systems, ignore case for file names.
@@ -2141,6 +2141,14 @@ the end of the list of defaults just after the default value."
2141 (append def all) 2141 (append def all)
2142 (cons def (delete def all))))) 2142 (cons def (delete def all)))))
2143 2143
2144(defun minibuffer-history-value ()
2145 "Return the value of the minibuffer input history list.
2146If `minibuffer-history-variable' points to a buffer-local variable and
2147the minibuffer is active, return the buffer-local value for the buffer
2148that was current when the minibuffer was activated."
2149 (buffer-local-value minibuffer-history-variable
2150 (window-buffer (minibuffer-selected-window))))
2151
2144(defun goto-history-element (nabs) 2152(defun goto-history-element (nabs)
2145 "Puts element of the minibuffer history in the minibuffer. 2153 "Puts element of the minibuffer history in the minibuffer.
2146The argument NABS specifies the absolute history position in 2154The argument NABS specifies the absolute history position in
@@ -2169,8 +2177,8 @@ negative number -N means the Nth entry of \"future history.\""
2169 (user-error (if minibuffer-default 2177 (user-error (if minibuffer-default
2170 "End of defaults; no next item" 2178 "End of defaults; no next item"
2171 "End of history; no default available"))) 2179 "End of history; no default available")))
2172 (if (> nabs (if (listp (symbol-value minibuffer-history-variable)) 2180 (if (> nabs (if (listp (minibuffer-history-value))
2173 (length (symbol-value minibuffer-history-variable)) 2181 (length (minibuffer-history-value))
2174 0)) 2182 0))
2175 (user-error "Beginning of history; no preceding item")) 2183 (user-error "Beginning of history; no preceding item"))
2176 (unless (memq last-command '(next-history-element 2184 (unless (memq last-command '(next-history-element
@@ -2192,7 +2200,7 @@ negative number -N means the Nth entry of \"future history.\""
2192 (setq minibuffer-returned-to-present t) 2200 (setq minibuffer-returned-to-present t)
2193 (setq minibuffer-text-before-history nil)) 2201 (setq minibuffer-text-before-history nil))
2194 (t (setq elt (nth (1- minibuffer-history-position) 2202 (t (setq elt (nth (1- minibuffer-history-position)
2195 (symbol-value minibuffer-history-variable))))) 2203 (minibuffer-history-value)))))
2196 (insert 2204 (insert
2197 (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth)) 2205 (if (and (eq minibuffer-history-sexp-flag (minibuffer-depth))
2198 (not minibuffer-returned-to-present)) 2206 (not minibuffer-returned-to-present))
@@ -2445,7 +2453,7 @@ or to the last history element for a backward search."
2445 ;; beginning/end of the history, wrap the search to the first/last 2453 ;; beginning/end of the history, wrap the search to the first/last
2446 ;; minibuffer history element. 2454 ;; minibuffer history element.
2447 (if isearch-forward 2455 (if isearch-forward
2448 (goto-history-element (length (symbol-value minibuffer-history-variable))) 2456 (goto-history-element (length (minibuffer-history-value)))
2449 (goto-history-element 0)) 2457 (goto-history-element 0))
2450 (setq isearch-success t) 2458 (setq isearch-success t)
2451 (goto-char (if isearch-forward (minibuffer-prompt-end) (point-max)))) 2459 (goto-char (if isearch-forward (minibuffer-prompt-end) (point-max))))
diff --git a/src/minibuf.c b/src/minibuf.c
index 1e87c5044af..bdae01dbc58 100644
--- a/src/minibuf.c
+++ b/src/minibuf.c
@@ -353,7 +353,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
353 Lisp_Object histvar, Lisp_Object histpos, Lisp_Object defalt, 353 Lisp_Object histvar, Lisp_Object histpos, Lisp_Object defalt,
354 bool allow_props, bool inherit_input_method) 354 bool allow_props, bool inherit_input_method)
355{ 355{
356 Lisp_Object val; 356 Lisp_Object val, previous_buffer = Fcurrent_buffer ();
357 ptrdiff_t count = SPECPDL_INDEX (); 357 ptrdiff_t count = SPECPDL_INDEX ();
358 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method; 358 Lisp_Object mini_frame, ambient_dir, minibuffer, input_method;
359 Lisp_Object enable_multibyte; 359 Lisp_Object enable_multibyte;
@@ -698,7 +698,20 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
698 698
699 /* Add the value to the appropriate history list, if any. */ 699 /* Add the value to the appropriate history list, if any. */
700 if (! (NILP (Vhistory_add_new_input) || NILP (histstring))) 700 if (! (NILP (Vhistory_add_new_input) || NILP (histstring)))
701 call2 (intern ("add-to-history"), Vminibuffer_history_variable, histstring); 701 {
702 ptrdiff_t count2 = SPECPDL_INDEX ();
703
704 /* If possible, switch back to the previous buffer first, in
705 case the history variable is buffer-local. */
706 if (BUFFER_LIVE_P (XBUFFER (previous_buffer)))
707 {
708 record_unwind_current_buffer ();
709 Fset_buffer (previous_buffer);
710 }
711
712 call2 (intern ("add-to-history"), Vminibuffer_history_variable, histstring);
713 unbind_to (count2, Qnil);
714 }
702 715
703 /* If Lisp form desired instead of string, parse it. */ 716 /* If Lisp form desired instead of string, parse it. */
704 if (expflag) 717 if (expflag)
@@ -879,6 +892,9 @@ Fifth arg HIST, if non-nil, specifies a history list and optionally
879 starting from 1 at the beginning of the list. If HIST is the symbol 892 starting from 1 at the beginning of the list. If HIST is the symbol
880 `t', history is not recorded. 893 `t', history is not recorded.
881 894
895 If `history-add-new-input' is non-nil (the default), the result will
896 be added to the history list using `add-to-history'.
897
882Sixth arg DEFAULT-VALUE, if non-nil, should be a string, which is used 898Sixth arg DEFAULT-VALUE, if non-nil, should be a string, which is used
883 as the default to `read' if READ is non-nil and the user enters 899 as the default to `read' if READ is non-nil and the user enters
884 empty input. But if READ is nil, this function does _not_ return 900 empty input. But if READ is nil, this function does _not_ return