[Top][All Lists]

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

master d0d5e40 3/3: Make comint-read-input-ring skip uninteresting text

From: Lars Ingebrigtsen
Subject: master d0d5e40 3/3: Make comint-read-input-ring skip uninteresting text in .zsh_history
Date: Mon, 11 Jan 2021 10:42:43 -0500 (EST)

branch: master
commit d0d5e40a5d90eac440d82fb34e7b470c8d07c004
Author: Brian Leung <leungbk@mailfence.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make comint-read-input-ring skip uninteresting text in .zsh_history
    * lisp/comint.el (comint-read-input-ring): Simplify (bug#45606).
    * lisp/shell.el (shell-mode): Add "~/.zsh_history".
    * lisp/comint.el (comint-read-input-ring): Bind
    `comint-input-ring-file-prefix' in anticipation of a buffer switch.
    * lisp/comint.el (comint-read-input-ring): Skip the separator.
    Because re-search-backward moves point to the beginning of the match,
    and since we don't want the separator appearing in the output, we skip
    over it.
    This is required to properly detect instances of the value that zsh
    uses for `comint-input-ring-file-prefix'; if the
    `comint-input-ring-file-prefix' is ':potato', the subsequent
    invocation `looking-at' sees '\n:potato' for all entries after the one
    at the very beginning of the history file.
 lisp/comint.el | 25 +++++++++----------------
 lisp/shell.el  |  1 +
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index 2e683a7..3476fd1 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -979,6 +979,7 @@ See also `comint-input-ignoredups' and 
                (ring (make-ring ring-size))
                 ;; Use possibly buffer-local values of these variables.
                 (ring-separator comint-input-ring-separator)
+                (ring-file-prefix comint-input-ring-file-prefix)
                 (history-ignore comint-input-history-ignore)
                 (ignoredups comint-input-ignoredups))
@@ -990,22 +991,14 @@ See also `comint-input-ignoredups' and 
                (while (and (< count comint-input-ring-size)
                            (re-search-backward ring-separator nil t)
                            (setq end (match-beginning 0)))
-                 (setq start
-                       (if (re-search-backward ring-separator nil t)
-                           (progn
-                             (when (and comint-input-ring-file-prefix
-                                        (looking-at
-                                         comint-input-ring-file-prefix))
-                               ;; Skip zsh extended_history stamps
-                               (goto-char (match-end 0)))
-                             (match-end 0))
-                         (progn
-                           (goto-char (point-min))
-                           (when (and comint-input-ring-file-prefix
-                                      (looking-at
-                                       comint-input-ring-file-prefix))
-                             (goto-char (match-end 0)))
-                           (point))))
+                 (goto-char (if (re-search-backward ring-separator nil t)
+                                (match-end 0)
+                              (point-min)))
+                 (when (and ring-file-prefix
+                            (looking-at ring-file-prefix))
+                   ;; Skip zsh extended_history stamps
+                   (goto-char (match-end 0)))
+                 (setq start (point))
                  (setq history (buffer-substring start end))
                  (goto-char start)
                  (when (and (not (string-match history-ignore history))
diff --git a/lisp/shell.el b/lisp/shell.el
index c179dd2..0f86615 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -603,6 +603,7 @@ buffer."
             (or hfile
                 (cond ((string-equal shell "bash") "~/.bash_history")
                       ((string-equal shell "ksh") "~/.sh_history")
+                      ((string-equal shell "zsh") "~/.zsh_history")
                       (t "~/.history")))))
       (if (or (equal comint-input-ring-file-name "")
              (equal (file-truename comint-input-ring-file-name)

reply via email to

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