]> git.eshelyaron.com Git - emacs.git/commitdiff
Use buffer local value of 'history-add-new-input' in minibuffer
authorEshel Yaron <me@eshelyaron.com>
Sun, 11 Feb 2024 15:18:48 +0000 (16:18 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sun, 11 Feb 2024 15:18:48 +0000 (16:18 +0100)
Avoid let-binding 'history-add-new-input', since that affects all nested
recursive minibuffers, and instead use a buffer-local setting in the
appropriate minibuffer.

* doc/lispref/minibuf.texi (Minibuffer History): Update.
* lisp/emacs-lisp/crm.el (completing-read-multiple): Use
'history-add-new-input' instead of manually removing raw input from
minibuffer history.
* lisp/isearch.el (isearch-edit-string)
* lisp/replace.el (query-replace-read-from)
(query-replace-read-to, read-regexp)
* lisp/simple.el (read-from-kill-ring): Set 'history-add-new-input'
locally in the minibuffer, instead of let-binding it.
* src/minibuf.c (read_minibuf): Use 'history-add-new-input' local value.

doc/lispref/minibuf.texi
lisp/emacs-lisp/crm.el
lisp/isearch.el
lisp/replace.el
lisp/simple.el
src/minibuf.c

index 96143f4126ea1387b549b3f25a9d044342a11d4b..e79ce280936b8f362107bf2afb4cb7fee1d82ac3 100644 (file)
@@ -700,9 +700,9 @@ duplicates, and to add @var{newelt} to the list even if it is empty.
 @end defun
 
 @defvar history-add-new-input
-If the value of this variable is @code{nil}, standard functions that
-read from the minibuffer don't add new elements to the history list.
-This lets Lisp programs explicitly manage input history by using
+If the value of this variable is @code{nil} in a minibuffer, Emacs
+doesn't add new elements to the history list of that minibuffer.  This
+lets Lisp programs explicitly manage input history by using
 @code{add-to-history}.  The default value is @code{t}.
 @end defvar
 
index 87b6cffffcda18138bcea18dca5c4a9148d660cf..b1e728c67fa6e6f4ded5f22f640773176611baf1 100644 (file)
@@ -420,15 +420,17 @@ with empty strings removed."
             crm-separator))
          (crm-canonical-separator (cdr-safe crm-separator))
          (string (minibuffer-with-setup-hook
-                     #'completing-read-multiple-mode
+                     (lambda ()
+                       (setq-local history-add-new-input nil)
+                       (completing-read-multiple-mode))
                    (completing-read prompt (apply-partially #'crm--table table)
                                     predicate require-match initial-input hist
                                     def inherit-input-method)))
          (results (split-string string crm-current-separator t)))
-    (when-let ((hist-var (and hist (not (eq hist t))
+    (when-let ((hist-var (and history-add-new-input
+                              hist (not (eq hist t))
                               (if (consp hist) (car hist) hist)))
                (hist-list (symbol-value hist)))
-      (when (string= (car hist-list) string) (pop (symbol-value hist)))
       (dolist (res results) (add-to-history hist-var res)))
     results))
 
index a139a6fb84e1f5fafab612a841c4ff1abf093235..814ab919d5eaec00b6a05dc2ec3b95575c121edc 100644 (file)
@@ -1844,10 +1844,6 @@ The following additional command keys are active while editing.
   (interactive)
   (with-isearch-suspended
    (let* ((message-log-max nil)
-         ;; Don't add a new search string to the search ring here
-         ;; in `read-from-minibuffer'. It should be added only
-         ;; by `isearch-update-ring' called from `isearch-done'.
-         (history-add-new-input nil)
          ;; Binding minibuffer-history-symbol to nil is a work-around
          ;; for some incompatibility with gmhist.
          (minibuffer-history-symbol)
@@ -1855,7 +1851,13 @@ The following additional command keys are active while editing.
          (minibuffer-allow-text-properties t))
      (setq isearch-new-string
           (minibuffer-with-setup-hook
-               (minibuffer-lazy-highlight-setup)
+               (let ((setup (minibuffer-lazy-highlight-setup)))
+                 (lambda ()
+                   ;; Don't add a new search string to the search ring here
+                  ;; in `read-from-minibuffer'. It should be added only
+                  ;; by `isearch-update-ring' called from `isearch-done'.
+                  (setq-local history-add-new-input nil)
+                   (funcall setup)))
              (read-from-minibuffer
              (isearch-message-prefix nil isearch-nonincremental)
              (cons isearch-string (1+ (or (isearch-fail-pos)
index fa460a16063b4b896d744934395fa77fa3771dd5..61a1cc7714c00c0e0abaa8b548e0858afcff878e 100644 (file)
@@ -205,8 +205,7 @@ by this function to the end of values available via
 Prompt with PROMPT.  REGEXP-FLAG non-nil means the response should be a regexp.
 The return value can also be a pair (FROM . TO) indicating that the user
 wants to replace FROM with TO."
-  (let* ((history-add-new-input nil)
-         (separator-string
+  (let* ((separator-string
           (when query-replace-from-to-separator
             ;; Check if the first non-whitespace char is displayable
             (if (char-displayable-p
@@ -254,7 +253,8 @@ wants to replace FROM with TO."
                 (lambda ()
                   (setq-local text-property-default-nonsticky
                               (append '((separator . t) (face . t))
-                                      text-property-default-nonsticky)))
+                                      text-property-default-nonsticky)
+                              history-add-new-input nil))
               (if regexp-flag
                   (read-regexp
                    (if query-replace-read-from-regexp-default
@@ -342,11 +342,13 @@ Prompt with PROMPT.  REGEXP-FLAG non-nil means the response
 should a regexp."
   (query-replace-compile-replacement
    (save-excursion
-     (let* ((history-add-new-input nil)
-           (to (read-from-minibuffer
-                (format "%s %s with: " prompt (query-replace-descr from))
-                nil nil nil
-                query-replace-to-history-variable from t)))
+     (let* ((to
+             (minibuffer-with-setup-hook
+                 (lambda () (setq-local history-add-new-input nil))
+                 (read-from-minibuffer
+                 (format "%s %s with: " prompt (query-replace-descr from))
+                 nil nil nil
+                 query-replace-to-history-variable from t))))
        (add-to-history query-replace-to-history-variable to nil t)
        (add-to-history 'query-replace-defaults (cons from to) nil t)
        to))
@@ -903,18 +905,18 @@ regexp from the user."
         (suggestions (if (listp defaults) defaults (list defaults)))
         (suggestions (append suggestions (read-regexp-suggestions)))
         (suggestions (delete-dups (delq nil (delete "" suggestions))))
-        ;; Do not automatically add default to the history for empty input.
-        (history-add-new-input nil)
          ;; `read-regexp--case-fold' dynamically bound and may be
          ;; altered by `M-c'.
          (read-regexp--case-fold case-fold-search)
-        (input (read-from-minibuffer
-                 (if (string-match-p ":[ \t]*\\'" prompt)
-                     prompt
-                   (format-prompt prompt (and (length> default 0)
-                                              (query-replace-descr default))))
-                nil read-regexp-map
-                 nil (or history 'regexp-history) suggestions t))
+        (input (minibuffer-with-setup-hook
+                    (lambda () (setq-local history-add-new-input nil))
+                  (read-from-minibuffer
+                   (if (string-match-p ":[ \t]*\\'" prompt)
+                       prompt
+                     (format-prompt prompt (and (length> default 0)
+                                                (query-replace-descr default))))
+                  nil read-regexp-map
+                   nil (or history 'regexp-history) suggestions t)))
          (result (if (equal input "")
                     ;; Return the default value when the user enters
                     ;; empty input.
index a7b77d10a130017e563b2f3e8ff065eaa8d06923..e80e33a963062732aa67d20be7baaf4db297925c 100644 (file)
@@ -6503,8 +6503,7 @@ variable to determine how strings should be escaped."
 PROMPT is a string to prompt with."
   ;; `current-kill' updates `kill-ring' with a possible interprogram-paste
   (current-kill 0)
-  (let* ((history-add-new-input nil)
-         (history-pos (when yank-from-kill-ring-rotate
+  (let* ((history-pos (when yank-from-kill-ring-rotate
                         (- (length kill-ring)
                            (length kill-ring-yank-pointer))))
          (ellipsis (if (char-displayable-p ?…) "…" "..."))
@@ -6538,14 +6537,7 @@ PROMPT is a string to prompt with."
                       s))
                   read-from-kill-ring-history)))
     (minibuffer-with-setup-hook
-        (lambda ()
-          ;; Allow ‘SPC’ to be self-inserting
-          (use-local-map
-           (let ((map (make-sparse-keymap)))
-             (set-keymap-parent map (current-local-map))
-             (define-key map " " nil)
-             (define-key map "?" nil)
-             map)))
+        (lambda () (setq-local history-add-new-input nil))
       (completing-read
        prompt
        (completion-table-with-metadata
index 2815d5c283475f7a0e0bd91bfda0c618265ec01c..9d6e365f133e07078aac5f116bd3a24682d27e90 100644 (file)
@@ -585,6 +585,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
   /* String to add to the history.  */
   Lisp_Object histstring;
   Lisp_Object histval;
+  bool nohist = false;
 
   Lisp_Object empty_minibuf;
 
@@ -902,6 +903,9 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
   /* Don't allow the user to undo past this point.  */
   bset_undo_list (current_buffer, Qnil);
 
+  /* Cache the buffer-local value. */
+  nohist = NILP (find_symbol_value (Qhistory_add_new_input));
+
   recursive_edit_1 ();
 
   /* If cursor is on the minibuffer line,
@@ -965,7 +969,7 @@ read_minibuf (Lisp_Object map, Lisp_Object initial, Lisp_Object prompt,
   /* Add the value to the appropriate history list, if any.  This is
      done after the previous buffer has been made current again, in
      case the history variable is buffer-local.  */
-  if (! (NILP (Vhistory_add_new_input) || NILP (histstring)))
+  if (! (nohist || NILP (histstring)))
     call2 (Qadd_to_history, histvar, histstring);
 
   /* If Lisp form desired instead of string, parse it.  */
@@ -2266,6 +2270,7 @@ syms_of_minibuf (void)
   Fset (Qcustom_variable_history, Qnil);
 
   DEFSYM (Qminibuffer_history, "minibuffer-history");
+  DEFSYM (Qhistory_add_new_input, "history-add-new-input");
   DEFSYM (Qbuffer_name_history, "buffer-name-history");
   Fset (Qbuffer_name_history, Qnil);