emacs-diffs
[Top][All Lists]
Advanced

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

master 38c9b0b: Make the history traversal functions in coming more regu


From: Lars Ingebrigtsen
Subject: master 38c9b0b: Make the history traversal functions in coming more regular
Date: Tue, 8 Dec 2020 11:15:50 -0500 (EST)

branch: master
commit 38c9b0bbdd1c95dc34af4aaf27183fd27aba1c9e
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make the history traversal functions in coming more regular
    
    * lisp/comint.el (comint-previous-matching-input): Allow restoring
    the input on wraps (bug#7885).
    (comint-previous-matching-input-from-input): Restore input on wraps.
---
 lisp/comint.el | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index 2873416..628a93d 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -1224,7 +1224,7 @@ Moves relative to START, or `comint-input-ring-index'."
        (process-mark (get-buffer-process (current-buffer))))
    (point-max)))
 
-(defun comint-previous-matching-input (regexp n)
+(defun comint-previous-matching-input (regexp n &optional restore)
   "Search backwards through input history for match for REGEXP.
 \(Previous history elements are earlier commands.)
 With prefix argument N, search for Nth previous match.
@@ -1235,16 +1235,24 @@ If N is negative, find the next or Nth next match."
     ;; Has a match been found?
     (if (null pos)
        (user-error "Not found")
-      ;; If leaving the edit line, save partial input
-      (if (null comint-input-ring-index)       ;not yet on ring
-         (setq comint-stored-incomplete-input
-               (funcall comint-get-old-input)))
-      (setq comint-input-ring-index pos)
-      (unless isearch-mode
-       (let ((message-log-max nil))    ; Do not write to *Messages*.
-         (message "History item: %d" (1+ pos))))
-      (comint-delete-input)
-      (insert (ring-ref comint-input-ring pos)))))
+      (if (and comint-input-ring-index
+               restore
+               (or (and (< n 0)
+                        (< comint-input-ring-index pos))
+                   (and (> n 0)
+                        (> comint-input-ring-index pos))))
+          ;; We have a wrap; restore contents.
+          (comint-restore-input)
+        ;; If leaving the edit line, save partial input
+        (if (null comint-input-ring-index) ;not yet on ring
+           (setq comint-stored-incomplete-input
+                 (funcall comint-get-old-input)))
+        (setq comint-input-ring-index pos)
+        (unless isearch-mode
+         (let ((message-log-max nil))  ; Do not write to *Messages*.
+           (message "History item: %d" (1+ pos))))
+        (comint-delete-input)
+        (insert (ring-ref comint-input-ring pos))))))
 
 (defun comint-next-matching-input (regexp n)
   "Search forwards through input history for match for REGEXP.
@@ -1272,7 +1280,7 @@ If N is negative, search forwards for the -Nth following 
match."
            comint-input-ring-index nil))
     (comint-previous-matching-input
      (concat "^" (regexp-quote comint-matching-input-from-input-string))
-     n)
+     n t)
     (when (eq comint-move-point-for-matching-input 'after-input)
       (goto-char opoint))))
 



reply via email to

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