]> git.eshelyaron.com Git - emacs.git/commitdiff
Tell direction in prompts for '(previous|next)-matching-history-element'
authorJim Porter <jporterbugs@gmail.com>
Sat, 11 May 2024 18:41:11 +0000 (11:41 -0700)
committerEshel Yaron <me@eshelyaron.com>
Thu, 23 May 2024 07:44:53 +0000 (09:44 +0200)
Previously, this always said "Previous" for
'previous-matching-history-element' (likewise "Next").  Now, the prompt
accounts for a negative prefix argument changing the search direction
(bug#70882).

* lisp/simple.el (previous-matching-history-element)
(next-matching-history-element): Consult numeric prefix argument to
determine the prompt string.

(cherry picked from commit 44d1687f1f6bc3d261aa2344a714b1f3397b3039)

lisp/simple.el

index 1ba3c6dddf96f0b0df2644544648b8eafe67fdc6..32bc4599a1dfb9892ff1dfd0ccd971e85c38b17a 100644 (file)
@@ -2958,11 +2958,13 @@ Normally, history elements are matched case-insensitively if
 makes the search case-sensitive.
 See also `minibuffer-history-case-insensitive-variables'."
   (interactive
-   (let* ((enable-recursive-minibuffers t)
+   (let* ((n (prefix-numeric-value current-prefix-arg))
+          (enable-recursive-minibuffers t)
          (regexp (read-from-minibuffer
-                   (format-prompt "Previous element matching regexp"
+                   (format-prompt "%s element matching regexp"
                                   (and minibuffer-history-search-history
-                                       (car minibuffer-history-search-history)))
+                                       (car minibuffer-history-search-history))
+                                  (if (>= n 0) "Previous" "Next"))
                   nil minibuffer-local-map nil
                   'minibuffer-history-search-history
                   (car minibuffer-history-search-history))))
@@ -2970,9 +2972,9 @@ See also `minibuffer-history-case-insensitive-variables'."
      (list (if (string= regexp "")
               (if minibuffer-history-search-history
                   (car minibuffer-history-search-history)
-                (user-error "No previous history search regexp"))
+                 (user-error "No history search regexp"))
             regexp)
-          (prefix-numeric-value current-prefix-arg))))
+           n)))
   (unless (zerop n)
     (if (and (zerop minibuffer-history-position)
             (null minibuffer-text-before-history))
@@ -3030,20 +3032,23 @@ Normally, history elements are matched case-insensitively if
 `case-fold-search' is non-nil, but an uppercase letter in REGEXP
 makes the search case-sensitive."
   (interactive
-   (let* ((enable-recursive-minibuffers t)
-         (regexp (read-from-minibuffer "Next element matching (regexp): "
-                                       nil
-                                       minibuffer-local-map
-                                       nil
-                                       'minibuffer-history-search-history
-                                       (car minibuffer-history-search-history))))
+   (let* ((n (prefix-numeric-value current-prefix-arg))
+          (enable-recursive-minibuffers t)
+          (regexp (read-from-minibuffer
+                   (format-prompt "%s element matching regexp"
+                                  (and minibuffer-history-search-history
+                                       (car minibuffer-history-search-history))
+                                  (if (>= n 0) "Next" "Previous"))
+                   nil minibuffer-local-map nil
+                   'minibuffer-history-search-history
+                   (car minibuffer-history-search-history))))
      ;; Use the last regexp specified, by default, if input is empty.
      (list (if (string= regexp "")
               (if minibuffer-history-search-history
                   (car minibuffer-history-search-history)
-                (user-error "No previous history search regexp"))
+                 (user-error "No history search regexp"))
             regexp)
-          (prefix-numeric-value current-prefix-arg))))
+           n)))
   (previous-matching-history-element regexp (- n)))
 
 (defvar minibuffer-temporary-goal-position nil)