[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Surprising behavior of (comint-insert-previous-argument)

From: Dima Kogan
Subject: Surprising behavior of (comint-insert-previous-argument)
Date: Wed, 23 Nov 2016 20:01:18 -0800
User-agent: mu4e 0.9.17; emacs

Hi. Currently (comint-insert-previous-argument) acts in strange ways in
certain conditions, and I'd like to get some input before proposing
specific patches. Largely this function exists to emulate the behavior
of M-. in bash and zsh. There are 2 issues:

1. Normally M-. in bash and zsh inserts the last token in the previous
command. (comint-insert-previous-argument) does this too, but gets
caught up if "&" appears in the input. It has special logic to detect
background commands (trailing &), and to not output the token itself.
This logic has a bug, and gets confused in cases where "&" doesn't mean
"background process". For instance, if the previous command was

    echo 1 && echo 2

then it should insert 2, but it inserts 1 instead. This can be fixed
with this trivial patch:

    diff --git a/lisp/comint.el b/lisp/comint.el
    index b9c65b0..a816ac8 100644
    --- a/lisp/comint.el
    +++ b/lisp/comint.el
    @@ -2669,7 +2669,7 @@ comint-insert-previous-argument
       (set-marker comint-insert-previous-argument-last-start-pos (point))
       ;; Insert the argument.
       (let ((input-string (comint-previous-input-string 0)))
    -    (when (string-match "[ \t\n]*&" input-string)
    +    (when (string-match "[ \t\n]*&[ \t\n]*$" input-string)
           ;; strip terminating '&'
           (setq input-string (substring input-string 0 (match-beginning 0))))
         (insert (comint-arguments input-string index index)))

I don't think this is ideal, however. bash and zsh don't have this logic
at all, and in the case of the previous command being something like

    echo 1 &

both bash and zsh simply insert "&", instead of "1", which is what emacs
does. I propose to cull that logic entirely, which will remove this bug,
and mimic what bash and zsh do.

2. bash and zsh differ about handling the parameters to M-. . In bash,
an argument to M-. will insert the Nth argument, counting from the
beginning. zsh does the same, but counts from the end. Emacs currently
does what bash does. I propose to add a customization parameter to
select the zsh behavior, leaving the default as is.

Please advice.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]