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.
This commit is contained in:
Brian Leung
2021-01-11 16:42:03 +01:00
committed by Lars Ingebrigtsen
parent 26ed7c7345
commit d0d5e40a5d
2 changed files with 10 additions and 16 deletions

View 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))

View 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)