]> git.eshelyaron.com Git - emacs.git/commitdiff
Make comint-read-input-ring skip uninteresting text in .zsh_history
authorBrian Leung <leungbk@mailfence.com>
Mon, 11 Jan 2021 15:42:03 +0000 (16:42 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Mon, 11 Jan 2021 15:42:03 +0000 (16:42 +0100)
* 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
lisp/shell.el

index 2e683a757246cc3aed52a7531dd3d51915648774..3476fd146cbff967eabcc49e462b9264c560be82 100644 (file)
@@ -979,6 +979,7 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
                (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))
           (with-temp-buffer
@@ -990,22 +991,14 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
                (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))
index c179dd24d3f7501490c80082d8adc924cf0c1b15..0f866158fe39c02d78fcf6d3db7388dafe13204e 100644 (file)
@@ -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)