Subject: bug#36034: [PATCH] Zsh extended_history shows up in comint input ring

From: Lars Ingebrigtsen <[email-masked]>
Date: Mon, 24 Jun 2019 12:51:08 +0200

Matthew Bauer <[email-masked]> writes:

> Yes, it does apply for any comint buffer that uses
> comint-read-input-ring. i had originally thought this was only used by
> shell-mode, but you are correct that it is used by others. Ive added
> defcustom handling to the patch to properly account for this.

Looks less dangerous now.  :-)

Some comments:

> +(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.

>                   (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?

> +                         (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...

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no