From: Dima Kogan <dima@secretsauce.net>
To: Emacs Development <emacs-devel@gnu.org>
Subject: Surprising behavior of (comint-insert-previous-argument)
Date: Wed, 23 Nov 2016 20:01:18 -0800 [thread overview]
Message-ID: <87eg215xwx.fsf@secretsauce.net> (raw)
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
reply other threads:[~2016-11-24 4:01 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=87eg215xwx.fsf@secretsauce.net \
--to=dima@secretsauce.net \
--cc=emacs-devel@gnu.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.