unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Surprising behavior of (comint-insert-previous-argument)
@ 2016-11-24  4:01 Dima Kogan
  0 siblings, 0 replies; only message in thread
From: Dima Kogan @ 2016-11-24  4:01 UTC (permalink / raw)
  To: Emacs Development

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.

dima



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-11-24  4:01 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-24  4:01 Surprising behavior of (comint-insert-previous-argument) Dima Kogan

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).