zsh-workers
 help / color / mirror / code / Atom feed
* interactivecomments and preexec
@ 2013-07-21 19:45 Stephane Chazelas
  2013-07-21 20:28 ` Bart Schaefer
  2013-07-22  8:44 ` Stephane Chazelas
  0 siblings, 2 replies; 13+ messages in thread
From: Stephane Chazelas @ 2013-07-21 19:45 UTC (permalink / raw)
  To: zsh-workers

% alias a='echo #'
% setopt interactivecomments
% preexec() print -r "<$1>"
% a test
<a # test>

Why not <a test>?

-- 
Stephane


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

* Re: interactivecomments and preexec
  2013-07-21 19:45 interactivecomments and preexec Stephane Chazelas
@ 2013-07-21 20:28 ` Bart Schaefer
  2013-07-22  7:00   ` Stephane Chazelas
  2013-07-22  9:53   ` Peter Stephenson
  2013-07-22  8:44 ` Stephane Chazelas
  1 sibling, 2 replies; 13+ messages in thread
From: Bart Schaefer @ 2013-07-21 20:28 UTC (permalink / raw)
  To: zsh-workers

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

Comments are stripped before alias expansion.

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

* Re: interactivecomments and preexec
  2013-07-21 20:28 ` Bart Schaefer
@ 2013-07-22  7:00   ` Stephane Chazelas
  2013-07-22  9:53   ` Peter Stephenson
  1 sibling, 0 replies; 13+ messages in thread
From: Stephane Chazelas @ 2013-07-22  7:00 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-workers

2013-07-21 13:28:17 -0700, Bart Schaefer:
> Comments are stripped before alias expansion.

Well, they appear to be after alias expansion as well then,
since:

~$ alias a='echo test #'
~$ setopt interactivecomments
~$ a q'qwe
test

See how the unmatched quote was successfully ignored. Also, if I
press the Up key, I get:

~$ a # q'qwe                                                                                                                                                                              7:57

That is, the issue is not only with preexec.

-- 
Stephane


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

* Re: interactivecomments and preexec
  2013-07-21 19:45 interactivecomments and preexec Stephane Chazelas
  2013-07-21 20:28 ` Bart Schaefer
@ 2013-07-22  8:44 ` Stephane Chazelas
  1 sibling, 0 replies; 13+ messages in thread
From: Stephane Chazelas @ 2013-07-22  8:44 UTC (permalink / raw)
  To: zsh-workers

2013-07-21 20:45:24 +0100, Stephane Chazelas:
> % alias a='echo #'
> % setopt interactivecomments
> % preexec() print -r "<$1>"
> % a test
> <a # test>
> 
> Why not <a test>?
[...]

Note that I think it worked before because I remember using it
in things like:

http://www.zsh.org/mla/users/2007/msg01195.html

(though in that particular one I mention "untested", and trying
zsh from some old ubuntus (4.3.4, 4.3.10), the behavior is
different in that it outputs "<a>" instead of "<a # test>", but
is not I as expect either).

-- 
Stephane


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

* Re: interactivecomments and preexec
  2013-07-21 20:28 ` Bart Schaefer
  2013-07-22  7:00   ` Stephane Chazelas
@ 2013-07-22  9:53   ` Peter Stephenson
  2013-07-22 18:30     ` Peter Stephenson
  1 sibling, 1 reply; 13+ messages in thread
From: Peter Stephenson @ 2013-07-22  9:53 UTC (permalink / raw)
  To: zsh-workers

On Sun, 21 Jul 2013 13:28:17 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> Comments are stripped before alias expansion.

I think you're slightly missing the issue (as I did, until I looked more
closely): what preexec shows is inconsistent, giving you the unexpanded
alias first, then a bit of the expanded alias, then the argument.  This
can't be right.

pws


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

* Re: interactivecomments and preexec
  2013-07-22  9:53   ` Peter Stephenson
@ 2013-07-22 18:30     ` Peter Stephenson
  2013-07-22 20:02       ` Peter Stephenson
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Stephenson @ 2013-07-22 18:30 UTC (permalink / raw)
  To: zsh-workers

On Mon, 22 Jul 2013 10:53:32 +0100
Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Sun, 21 Jul 2013 13:28:17 -0700
> Bart Schaefer <schaefer@brasslantern.com> wrote:
> > Comments are stripped before alias expansion.
> 
> I think you're slightly missing the issue (as I did, until I looked more
> closely): what preexec shows is inconsistent, giving you the unexpanded
> alias first, then a bit of the expanded alias, then the argument.  This
> can't be right.

Not just in preexec, either; if you use up-arrow, you get the extraneous
"#" in the middle of the line.

Try this.  Seems to work here but not extensively tested elsewhere.

diff --git a/Src/lex.c b/Src/lex.c
index ac87e5e..4a9b110 100644
--- a/Src/lex.c
+++ b/Src/lex.c
@@ -778,6 +778,7 @@ gettok(void)
 	    bptr = tokstr = (char *)hcalloc(bsiz = 32);
 	    add(c);
 	}
+	ihwend();
 	while ((c = ingetc()) != '\n' && !lexstop) {
 	    hwaddc(c);
 	    addtoline(c);

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: interactivecomments and preexec
  2013-07-22 18:30     ` Peter Stephenson
@ 2013-07-22 20:02       ` Peter Stephenson
  2013-07-22 20:22         ` Stephane Chazelas
  0 siblings, 1 reply; 13+ messages in thread
From: Peter Stephenson @ 2013-07-22 20:02 UTC (permalink / raw)
  To: zsh-workers

On Mon, 22 Jul 2013 19:30:12 +0100
Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> +	ihwend();

Oops, should be hwend(), which is a function pointer that points to
ihwend() in the case of interactive history.  Now fixed.

pws


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

* Re: interactivecomments and preexec
  2013-07-22 20:02       ` Peter Stephenson
@ 2013-07-22 20:22         ` Stephane Chazelas
  2013-07-22 20:27           ` Stephane Chazelas
  2013-07-22 20:30           ` Peter Stephenson
  0 siblings, 2 replies; 13+ messages in thread
From: Stephane Chazelas @ 2013-07-22 20:22 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

2013-07-22 21:02:03 +0100, Peter Stephenson:
> On Mon, 22 Jul 2013 19:30:12 +0100
> Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> > +	ihwend();
> 
> Oops, should be hwend(), which is a function pointer that points to
> ihwend() in the case of interactive history.  Now fixed.
[...]

Thanks,

though that works with `zsh -f`, that doesn't seem to work with
those options:

options=(autolist on printexitvalue off kshzerosubscript off histreduceblanks on chaselinks off extendedglob on histnostore off automenu on globcomplete off unset on listpacked off promptsubst on shwordsplit off pathdirs off kshtypeset off listtypes on warncreateglobal off promptbang off dotglob off braceexpand on listbeep off correctall off privileged off numericglobsort off histverify on trackall on histsubstpattern off cbases off rcquotes off posixaliases off histfindnodups off bashautolist off sharehistory off overstrike off kshautoload off incappendhistory on promptcr on mailwarn off pushdignoredups off interactive on ignoreeof off globsubst off rematchpcre off monitor on histsavebycopy on histbeep on debugbeforecmd on magicequalsubst off rmstarsilent off posixjobs off hashcmds on posixtraps off extendedhistory off notify on kshoptionprint off histexpiredupsfirst off glob on posixcd off braceccl off badpattern on longlistjobs off banghist off dvorak off alwaystoend off hashall on globalexport on ksharrays off correct on autonamedirs off histexpand off typesetsilent off rmstarwait off histnofunctions off autoparamslash on trapsasync off sunkeyboardhack off promptsp on histsavenodups on autocd on allexport off posixidentifiers off cshjunkiehistory off autopushd on completeinword off completealiases off aliases on autocontinue on appendhistory on singlelinezle off hashlistall on ignoreclosebraces off recexact off localoptions off interactivecomments off errexit off cshjunkiequotes off markdirs off hashdirs on cdablevars off rcexpandparam off vi off printeightbit off multifuncdef on xtrace off login off cshjunkieloops off histappend on histignorespace on evallineno on shfileexpansion off rcs on functionargzero on errreturn off combiningchars off histignoredups off histfcntllock off beep on autoremoveslash on hup on globdots off autoparamkeys on shnullcmd off multibyte on zle on promptpercent on flowcontrol off continueonerror off autoresume off globassign off caseglob on shortloops on bsdecho off cprecedences off log on transientrprompt on verbose off ignorebraces off equals on menucomplete off cshnullglob off casematch on promptvars on histallowclobber off bareglobqual on shinstdin on restricted off pushdminus off nullglob off chasedots off mailwarning off listambiguous off cshnullcmd off bashrematch off octalzeroes off exec on multios off emacs off nomatch on pathscript off localtraps off stdin on onecmd off kshglob off clobber on posixbuiltins off alwayslastprompt on pushdtohome off histignorealldups on hashexecutablesonly off pushdsilent off shoptionletters off physical off sourcetrace off histlexwords off bgnice on globalrcs on posixstrings off checkjobs on shglob off singlecommand off listrowsfirst off )

Cheers,
Stephane


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

* Re: interactivecomments and preexec
  2013-07-22 20:22         ` Stephane Chazelas
@ 2013-07-22 20:27           ` Stephane Chazelas
  2013-07-22 20:30           ` Peter Stephenson
  1 sibling, 0 replies; 13+ messages in thread
From: Stephane Chazelas @ 2013-07-22 20:27 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

2013-07-22 21:22:16 +0100, Stephane Chazelas:
> 2013-07-22 21:02:03 +0100, Peter Stephenson:
> > On Mon, 22 Jul 2013 19:30:12 +0100
> > Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> > > +	ihwend();
> > 
> > Oops, should be hwend(), which is a function pointer that points to
> > ihwend() in the case of interactive history.  Now fixed.
> [...]
> 
> Thanks,
> 
> though that works with `zsh -f`, that doesn't seem to work with
> those options:
[...]

The culprit is histreduceblanks here.

Actually that patch reverts to the old behavior like in 4.3.10.
Except that in 4.3.10, if you typed:

: # whatever

Pressing the Up key would bring you that same line, while now it
brings you ": #".

-- 
Stephane


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

* Re: interactivecomments and preexec
  2013-07-22 20:22         ` Stephane Chazelas
  2013-07-22 20:27           ` Stephane Chazelas
@ 2013-07-22 20:30           ` Peter Stephenson
  2013-07-22 20:37             ` Stephane Chazelas
  1 sibling, 1 reply; 13+ messages in thread
From: Peter Stephenson @ 2013-07-22 20:30 UTC (permalink / raw)
  To: zsh-workers

On Mon, 22 Jul 2013 21:22:17 +0100
Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
> 2013-07-22 21:02:03 +0100, Peter Stephenson:
> > On Mon, 22 Jul 2013 19:30:12 +0100
> > Peter Stephenson <p.w.stephenson@ntlworld.com> wrote:
> > > +	ihwend();
> > 
> > Oops, should be hwend(), which is a function pointer that points to
> > ihwend() in the case of interactive history.  Now fixed.
> [...]
> 
> Thanks,
> 
> though that works with `zsh -f`, that doesn't seem to work with
> those options:

It does for me.  You have 
 
extendedglob on
interactivecomments off
badpattern on

so "#" is not a comment, it's a bad pattern because it doesn't follow
another string, which is what the shell reports.  Up arrow and output
from preexec give the unexpanded command line regardless.  But I don't
know what you're claiming doesn't work.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


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

* Re: interactivecomments and preexec
  2013-07-22 20:30           ` Peter Stephenson
@ 2013-07-22 20:37             ` Stephane Chazelas
  2013-07-22 20:39               ` Stephane Chazelas
  0 siblings, 1 reply; 13+ messages in thread
From: Stephane Chazelas @ 2013-07-22 20:37 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: zsh-workers

2013-07-22 21:30:56 +0100, Peter Stephenson:
[...]
> It does for me.  You have 
>  
> extendedglob on
> interactivecomments off
> badpattern on
[...]

Sorry, that was my "options" before I issued "setopt
interactivecomments", see my other email about
"histreduceblanks" being the source of the problem.

-- 
Stephane


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

* Re: interactivecomments and preexec
  2013-07-22 20:37             ` Stephane Chazelas
@ 2013-07-22 20:39               ` Stephane Chazelas
  2013-07-24 14:43                 ` Peter Stephenson
  0 siblings, 1 reply; 13+ messages in thread
From: Stephane Chazelas @ 2013-07-22 20:39 UTC (permalink / raw)
  To: Peter Stephenson, zsh-workers

2013-07-22 21:37:02 +0100, Stephane Chazelas:
> 2013-07-22 21:30:56 +0100, Peter Stephenson:
> [...]
> > It does for me.  You have 
> >  
> > extendedglob on
> > interactivecomments off
> > badpattern on
> [...]
> 
> Sorry, that was my "options" before I issued "setopt
> interactivecomments", see my other email about
> "histreduceblanks" being the source of the problem.
[...]

Or, to make it clearer, to reproduce:

zsh -f

setopt histreduceblanks interactivecomments
: # blah

Press <Up> here.

And:

alias a=': #'
a blah

Press <Up> here.

-- 
Stephane


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

* Re: interactivecomments and preexec
  2013-07-22 20:39               ` Stephane Chazelas
@ 2013-07-24 14:43                 ` Peter Stephenson
  0 siblings, 0 replies; 13+ messages in thread
From: Peter Stephenson @ 2013-07-24 14:43 UTC (permalink / raw)
  To: zsh-workers

On Mon, 22 Jul 2013 21:39:28 +0100
Stephane Chazelas <stephane.chazelas@gmail.com> wrote:
> Or, to make it clearer, to reproduce:
> 
> zsh -f
> 
> setopt histreduceblanks interactivecomments
> : # blah
> 
> Press <Up> here.

Finally remembered what I'm doing next...

diff --git a/Src/hist.c b/Src/hist.c
index 561e2ac..5e962e9 100644
--- a/Src/hist.c
+++ b/Src/hist.c
@@ -927,7 +927,8 @@ hbegin(int dohist)
 void
 histreduceblanks(void)
 {
-    int i, len, pos, needblank, spacecount = 0;
+    int i, len, pos, needblank, spacecount = 0, trunc_ok;
+    char *lastptr, *ptr;
 
     if (isset(HISTIGNORESPACE))
 	while (chline[spacecount] == ' ') spacecount++;
@@ -939,6 +940,12 @@ histreduceblanks(void)
     if (chline[len] == '\0')
 	return;
 
+    /* Remember where the delimited words end */
+    if (chwordpos)
+	lastptr = chline + chwords[chwordpos-1];
+    else
+	lastptr = chline;
+
     for (i = 0, pos = spacecount; i < chwordpos; i += 2) {
 	len = chwords[i+1] - chwords[i];
 	needblank = (i < chwordpos-2 && chwords[i+2] > chwords[i+1]);
@@ -949,7 +956,25 @@ histreduceblanks(void)
 	}
 	pos += len + needblank;
     }
-    chline[pos] = '\0';
+
+    /*
+     * A terminating comment isn't recorded as a word.
+     * Only truncate the line if just whitespace remains.
+     */
+    trunc_ok = 1;
+    for (ptr = lastptr; *ptr; ptr++) {
+	if (!inblank(*ptr)) {
+	    trunc_ok = 0;
+	    break;
+	}
+    }
+    if (trunc_ok) {
+	chline[pos] = '\0';
+    } else {
+	ptr = chline + pos;
+	while ((*ptr++ = *lastptr++))
+	    ;
+    }
 }
 
 /**/


pws


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

end of thread, other threads:[~2013-07-24 14:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-21 19:45 interactivecomments and preexec Stephane Chazelas
2013-07-21 20:28 ` Bart Schaefer
2013-07-22  7:00   ` Stephane Chazelas
2013-07-22  9:53   ` Peter Stephenson
2013-07-22 18:30     ` Peter Stephenson
2013-07-22 20:02       ` Peter Stephenson
2013-07-22 20:22         ` Stephane Chazelas
2013-07-22 20:27           ` Stephane Chazelas
2013-07-22 20:30           ` Peter Stephenson
2013-07-22 20:37             ` Stephane Chazelas
2013-07-22 20:39               ` Stephane Chazelas
2013-07-24 14:43                 ` Peter Stephenson
2013-07-22  8:44 ` Stephane Chazelas

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).