zsh-workers
 help / color / mirror / code / Atom feed
* [BUG?] - history word expansion for commands with interactive comments
@ 2018-01-08  9:31 ` JB M
  2018-01-08 10:21   ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: JB M @ 2018-01-08  9:31 UTC (permalink / raw)
  To: zsh-workers

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

Hello,

on a somewhat recent version of ZSH, it seems that the comment character is
considered part of the arguments of commands ending with a comment:

jbm gandia:~[1310]% zsh -f

gandia% echo $ZSH_VERSION
5.3.1

gandia% setopt interactive_comments

gandia% echo $histchars[3]
#

gandia% echo test # My comment sentence.
test

gandia% echo !:$
echo #

gandia% echo 'another test' ### Several commenting characters
another test

gandia% echo !:$
echo #

gandia% echo yet another test # My comment here
yet another test

gandia% echo !:*
echo yet another test #
yet another test


I would find it more helpful to have the commenting character not
considered part of the arguments, like bash does.

-- jbm

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG?] - history word expansion for commands with interactive comments
  2018-01-08  9:31 ` [BUG?] - history word expansion for commands with interactive comments JB M
@ 2018-01-08 10:21   ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2018-01-08 10:21 UTC (permalink / raw)
  To: zsh-workers

On Mon, 8 Jan 2018 10:31:14 +0100
JB M <jbm.lists@gmail.com> wrote:
> on a somewhat recent version of ZSH, it seems that the comment character is
> considered part of the arguments of commands ending with a comment:
> gandia% echo test # My comment sentence.
> test
> 
> gandia% echo !:$
> echo #

Hmm, that doesn't look particularly useful.

We might get away with something like this.

pws

diff --git a/Src/hist.c b/Src/hist.c
index 177250f..e08984f 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -46,6 +46,9 @@ void (*hwaddc) _((int));
 void (*hwbegin) _((int));
 
 /**/
+void (*hwabort) _((void));
+
+/**/
 void (*hwend) _((void));
 
 /**/
@@ -250,6 +253,7 @@ hist_context_save(struct hist_stack *hs, int toplevel)
     hs->hungetc = hungetc;
     hs->hwaddc = hwaddc;
     hs->hwbegin = hwbegin;
+    hs->hwabort = hwabort;
     hs->hwend = hwend;
     hs->addtoline = addtoline;
     hs->hlinesz = hlinesz;
@@ -294,6 +298,7 @@ hist_context_restore(const struct hist_stack *hs, int toplevel)
     hungetc = hs->hungetc;
     hwaddc = hs->hwaddc;
     hwbegin = hs->hwbegin;
+    hwabort = hs->hwabort;
     hwend = hs->hwend;
     addtoline = hs->addtoline;
     hlinesz = hs->hlinesz;
@@ -986,6 +991,11 @@ nohw(UNUSED(int c))
 }
 
 static void
+nohwabort(void)
+{
+}
+
+static void
 nohwe(void)
 {
 }
@@ -1057,6 +1067,7 @@ hbegin(int dohist)
 	hungetc = inungetc;
 	hwaddc = nohw;
 	hwbegin = nohw;
+	hwabort = nohwabort;
 	hwend = nohwe;
 	addtoline = nohw;
     } else {
@@ -1066,6 +1077,7 @@ hbegin(int dohist)
 	hungetc = ihungetc;
 	hwaddc = ihwaddc;
 	hwbegin = ihwbegin;
+	hwabort = ihwabort;
 	hwend = ihwend;
 	addtoline = iaddtoline;
 	if (!isset(BANGHIST))
@@ -1571,6 +1583,16 @@ ihwbegin(int offset)
     chwords[chwordpos++] = hptr - chline + offset;
 }
 
+/* Abort current history word, not needed */
+
+/**/
+void
+ihwabort(void)
+{
+    if (chwordpos%2)
+	chwordpos--;
+}
+
 /* add a word to the history List */
 
 /**/
diff --git a/Src/lex.c b/Src/lex.c
index c2a5966..2379804 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -677,7 +677,7 @@ gettok(void)
 		(char *)hcalloc(lexbuf.siz = LEX_HEAP_SIZE);
 	    add(c);
 	}
-	hwend();
+	hwabort();
 	while ((c = ingetc()) != '\n' && !lexstop) {
 	    hwaddc(c);
 	    addtoline(c);
diff --git a/Src/zsh.h b/Src/zsh.h
index 92f7576..ba2f8cd 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -2992,6 +2992,7 @@ struct hist_stack {
     void (*hungetc) _((int));
     void (*hwaddc) _((int));
     void (*hwbegin) _((int));
+    void (*hwabort) _((void));
     void (*hwend) _((void));
     void (*addtoline) _((int));
     unsigned char *cstack;


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-08 10:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CGME20180108093217epcas3p1ca24c2c8aca1afabe08df88a2a425a8d@epcas3p1.samsung.com>
2018-01-08  9:31 ` [BUG?] - history word expansion for commands with interactive comments JB M
2018-01-08 10:21   ` Peter Stephenson

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

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).