aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Leung2021-01-11 16:42:03 +0100
committerLars Ingebrigtsen2021-01-11 16:42:03 +0100
commitd0d5e40a5d90eac440d82fb34e7b470c8d07c004 (patch)
tree78271eca4b8e4f89b619ce94a1bcfb55d45cbc2e
parent26ed7c734557043827f02629dbba00031358e64a (diff)
downloademacs-d0d5e40a5d90eac440d82fb34e7b470c8d07c004.tar.gz
emacs-d0d5e40a5d90eac440d82fb34e7b470c8d07c004.zip
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.
-rw-r--r--lisp/comint.el25
-rw-r--r--lisp/shell.el1
2 files changed, 10 insertions, 16 deletions
diff --git a/lisp/comint.el b/lisp/comint.el
index 2e683a75724..3476fd146cb 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -979,6 +979,7 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
979 (ring (make-ring ring-size)) 979 (ring (make-ring ring-size))
980 ;; Use possibly buffer-local values of these variables. 980 ;; Use possibly buffer-local values of these variables.
981 (ring-separator comint-input-ring-separator) 981 (ring-separator comint-input-ring-separator)
982 (ring-file-prefix comint-input-ring-file-prefix)
982 (history-ignore comint-input-history-ignore) 983 (history-ignore comint-input-history-ignore)
983 (ignoredups comint-input-ignoredups)) 984 (ignoredups comint-input-ignoredups))
984 (with-temp-buffer 985 (with-temp-buffer
@@ -990,22 +991,14 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
990 (while (and (< count comint-input-ring-size) 991 (while (and (< count comint-input-ring-size)
991 (re-search-backward ring-separator nil t) 992 (re-search-backward ring-separator nil t)
992 (setq end (match-beginning 0))) 993 (setq end (match-beginning 0)))
993 (setq start 994 (goto-char (if (re-search-backward ring-separator nil t)
994 (if (re-search-backward ring-separator nil t) 995 (match-end 0)
995 (progn 996 (point-min)))
996 (when (and comint-input-ring-file-prefix 997 (when (and ring-file-prefix
997 (looking-at 998 (looking-at ring-file-prefix))
998 comint-input-ring-file-prefix)) 999 ;; Skip zsh extended_history stamps
999 ;; Skip zsh extended_history stamps 1000 (goto-char (match-end 0)))
1000 (goto-char (match-end 0))) 1001 (setq start (point))
1001 (match-end 0))
1002 (progn
1003 (goto-char (point-min))
1004 (when (and comint-input-ring-file-prefix
1005 (looking-at
1006 comint-input-ring-file-prefix))
1007 (goto-char (match-end 0)))
1008 (point))))
1009 (setq history (buffer-substring start end)) 1002 (setq history (buffer-substring start end))
1010 (goto-char start) 1003 (goto-char start)
1011 (when (and (not (string-match history-ignore history)) 1004 (when (and (not (string-match history-ignore history))
diff --git a/lisp/shell.el b/lisp/shell.el
index c179dd24d3f..0f866158fe3 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -603,6 +603,7 @@ buffer."
603 (or hfile 603 (or hfile
604 (cond ((string-equal shell "bash") "~/.bash_history") 604 (cond ((string-equal shell "bash") "~/.bash_history")
605 ((string-equal shell "ksh") "~/.sh_history") 605 ((string-equal shell "ksh") "~/.sh_history")
606 ((string-equal shell "zsh") "~/.zsh_history")
606 (t "~/.history"))))) 607 (t "~/.history")))))
607 (if (or (equal comint-input-ring-file-name "") 608 (if (or (equal comint-input-ring-file-name "")
608 (equal (file-truename comint-input-ring-file-name) 609 (equal (file-truename comint-input-ring-file-name)