all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Matthew Bauer <mjbauer95@gmail.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 36034@debbugs.gnu.org
Subject: bug#36034: [PATCH] Zsh extended_history shows up in comint input ring
Date: Mon, 24 Jun 2019 18:45:51 -0400	[thread overview]
Message-ID: <3FE84EF1-D1F2-4F8B-B89C-C147C922F32D@gmail.com> (raw)
In-Reply-To: <m3ftnyk46o.fsf@gnus.org>

[-- Attachment #1: Type: text/plain, Size: 2788 bytes --]



> On Jun 24, 2019, at 6:51 AM, Lars Ingebrigtsen <larsi@gnus.org> wrote:
> 
> Matthew Bauer <mjbauer95@gmail.com> writes:
> 
>> +(defcustom comint-input-ring-file-prefix nil
>> +  "If non-nil, the prefix to skip when parsing the input ring file.
>> +This is useful in Zsh when the extended_history option is on."
>> +  :type 'boolean
>> +  :group 'comint)
> 
> This doesn't really seem like a user-level variable, so it should just
> be a defvar, I think.

Seems reasonable, I updated the patch.

> 
>>                  (setq start
>>                        (if (re-search-backward comint-input-ring-separator
>>                                                nil t)
>> -                           (match-end 0)
>> -                         (point-min)))
>> +                           (progn
>> +                             (when (and
>> +                                    comint-input-ring-file-prefix
>> +                                    (looking-at (concat comint-input-ring-separator
>> +                                                        comint-input-ring-file-prefix)))
>> +                               ;; Skip zsh extended_history stamps
>> +                               (re-search-forward comint-input-ring-file-prefix
>> +                                                  nil t))
>> +                             (match-end 0))
> 
> The re-search-forward here doesn't seem necessary -- can't you just go
> to (match-end 0) here instead?

Without re-search-forward, the “start” integer would just be the character right after the newline. re-search-forward skips that prefix.

>> +                         (progn
>> +                           (goto-char (point-min))
>> +                           (if (and comint-input-ring-file-prefix
>> +                                    (looking-at comint-input-ring-file-prefix))
>> +                               (progn
>> +                                 (re-search-forward comint-input-ring-file-prefix
>> +                                                    nil t)
>> +                                 (match-end 0))
>> +                             (point-min)))))
> 
> And I don't understand this bit.  This is when we didn't find
> comint-input-ring-separator, right?  But you still want to skip
> comint-input-ring-file-prefix?
> 
> If you want to skip it anyway, then you can just have the check (and the
> skip) after the if statement…
> 

This is for the very first line which will not have a newline before it. In this case, we want to skip the prefix as well. This is part of why we need special handling for “prefix" and tricks like this don’t work:

https://emacs.stackexchange.com/a/22295 <https://emacs.stackexchange.com/a/22295>


[-- Attachment #2.1: Type: text/html, Size: 7920 bytes --]

[-- Attachment #2.2: 0001-Add-zsh-extended_history-handling-for-comint.el-inpu.patch --]
[-- Type: application/octet-stream, Size: 3972 bytes --]

From ad957ff66cb9d48a1ae7772758b40e534392f097 Mon Sep 17 00:00:00 2001
From: Matthew Bauer <mjbauer95@gmail.com>
Date: Sun, 23 Jun 2019 18:08:32 -0400
Subject: [PATCH] Add zsh extended_history handling for comint.el input ring
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Adds handling of the Zsh extended_history to comint.el input
ring. This means that the timestamp doesn’t show up when reading
through history from other shells. The lines look like this:

: <beginning time>:<elapsed seconds>;<command>

This patch skips the part before <command> when the ‘shell’ is
zsh. This is done through the comint-input-ring-file-prefix
variable. When set, this will skip a prefix of the file when loading
into the input ring. This matches the behavior of Zsh. Zsh documents
it here:

http://zsh.sourceforge.net/Doc/Release/Options.html#History
---
 lisp/comint.el | 24 ++++++++++++++++++++++--
 lisp/shell.el  |  6 +++++-
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/lisp/comint.el b/lisp/comint.el
index 56e38e24ac..dbf239b463 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -249,6 +249,10 @@ to set this in a mode hook, rather than customize the default value."
 		 file)
   :group 'comint)
 
+(defvar comint-input-ring-file-prefix nil
+  "The prefix to skip when parsing the input ring file.
+This is useful in Zsh when the extended_history option is on.")
+
 (defcustom comint-scroll-to-bottom-on-input nil
   "Controls whether input to interpreter causes window to scroll.
 If nil, then do not scroll.  If t or `all', scroll all windows showing buffer.
@@ -978,8 +982,24 @@ See also `comint-input-ignoredups' and `comint-write-input-ring'."
                  (setq start
                        (if (re-search-backward comint-input-ring-separator
                                                nil t)
-                           (match-end 0)
-                         (point-min)))
+                           (progn
+                             (when (and
+                                    comint-input-ring-file-prefix
+                                    (looking-at (concat comint-input-ring-separator
+                                                        comint-input-ring-file-prefix)))
+                               ;; Skip zsh extended_history stamps
+                               (re-search-forward comint-input-ring-file-prefix
+                                                  nil t))
+                             (match-end 0))
+                         (progn
+                           (goto-char (point-min))
+                           (if (and comint-input-ring-file-prefix
+                                    (looking-at comint-input-ring-file-prefix))
+                               (progn
+                                 (re-search-forward comint-input-ring-file-prefix
+                                                    nil t)
+                                 (match-end 0))
+                             (point-min)))))
                  (setq history (buffer-substring start end))
                  (goto-char start)
                  (when (and (not (string-match comint-input-history-ignore
diff --git a/lisp/shell.el b/lisp/shell.el
index e30825cd66..25f6892d96 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -600,7 +600,11 @@ buffer."
       ;; Bypass a bug in certain versions of bash.
       (when (string-equal shell "bash")
         (add-hook 'comint-preoutput-filter-functions
-                  'shell-filter-ctrl-a-ctrl-b nil t)))
+                  'shell-filter-ctrl-a-ctrl-b nil t))
+
+      ;; Skip extended history for zsh.
+      (when (string-equal shell "zsh")
+        (setq-local comint-input-ring-file-prefix ": [[:digit:]]+:[[:digit:]]+;")))
     (comint-read-input-ring t)))
 
 (defun shell-apply-ansi-color (beg end face)
-- 
2.21.0


[-- Attachment #2.3: Type: text/html, Size: 206 bytes --]

  reply	other threads:[~2019-06-24 22:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-31 20:30 bug#36034: [PATCH] Zsh extended_history shows up in comint input ring Matthew Bauer
2019-06-23 16:53 ` Lars Ingebrigtsen
2019-06-23 22:27   ` Matthew Bauer
2019-06-24 10:51     ` Lars Ingebrigtsen
2019-06-24 22:45       ` Matthew Bauer [this message]
2019-06-25 11:05         ` Lars Ingebrigtsen
2019-06-29 21:35           ` Matthew Bauer
2019-07-04 13:37             ` Lars Ingebrigtsen
2020-01-20 19:43               ` Stefan Kangas
2020-03-18 15:05               ` Matthew Bauer
2020-08-10 11:11                 ` Lars Ingebrigtsen
2019-06-24 10:51     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3FE84EF1-D1F2-4F8B-B89C-C147C922F32D@gmail.com \
    --to=mjbauer95@gmail.com \
    --cc=36034@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.