zsh-users
 help / color / mirror / code / Atom feed
* Auto-correct and newly-added commands
@ 2011-11-14 18:31 Daniel Serodio (lists)
  2011-11-15  4:16 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Serodio (lists) @ 2011-11-14 18:31 UTC (permalink / raw)
  To: zsh-users

When I add a command to a directory that's included in PATH, the first 
time I try to run this command, zsh tries to auto-correct it, to which I 
reply "n".

It it possible to have zsh automatically run "rehash" after I reply no 
to an auto-correct prompt, so it "learns" this new command?

Thanks in advance,
Daniel Serodio


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

* Re: Auto-correct and newly-added commands
  2011-11-14 18:31 Auto-correct and newly-added commands Daniel Serodio (lists)
@ 2011-11-15  4:16 ` Bart Schaefer
  2011-11-18 12:50   ` Daniel Serodio
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2011-11-15  4:16 UTC (permalink / raw)
  To: zsh-users

On Nov 14,  4:31pm, Daniel Serodio (lists) wrote:
}
} It it possible to have zsh automatically run "rehash" after I reply no 
} to an auto-correct prompt, so it "learns" this new command?

Hrm.  The direct answer is "no" but:

That would certainly seem logical.  Also it seems strange to load up
the command tables and check them for proper spellings when the word
that is being checked is not in the command position to begin with.

What this patch does is reset the incremental path search in the event
the correction is rejected.  That allows whatever hashing options the
user has specified to kick in at the time the path is searched during
command execution, rather than having to test them all here.

Index: Src/utils.c
--- ../zsh-forge/current/Src/utils.c	2011-09-25 15:52:55.000000000 -0700
+++ Src/utils.c	2011-11-14 19:58:34.000000000 -0800
@@ -2498,16 +2498,18 @@
 	return;
     if (!(*s)[0] || !(*s)[1])
 	return;
-    if (shfunctab->getnode(shfunctab, *s) ||
-	builtintab->getnode(builtintab, *s) ||
-	cmdnamtab->getnode(cmdnamtab, *s) ||
-	aliastab->getnode(aliastab, *s)  ||
-	reswdtab->getnode(reswdtab, *s))
-	return;
-    else if (isset(HASHLISTALL)) {
-	cmdnamtab->filltable(cmdnamtab);
-	if (cmdnamtab->getnode(cmdnamtab, *s))
+    if (cmd) {
+	if (shfunctab->getnode(shfunctab, *s) ||
+	    builtintab->getnode(builtintab, *s) ||
+	    cmdnamtab->getnode(cmdnamtab, *s) ||
+	    aliastab->getnode(aliastab, *s)  ||
+	    reswdtab->getnode(reswdtab, *s))
 	    return;
+	else if (isset(HASHLISTALL)) {
+	    cmdnamtab->filltable(cmdnamtab);
+	    if (cmdnamtab->getnode(cmdnamtab, *s))
+		return;
+	}
     }
     t = *s;
     if (*t == Tilde || *t == Equals || *t == String)
@@ -2621,6 +2623,8 @@
 		fflush(shout);
 		zbeep();
 		x = getquery("nyae \t", 0);
+		if (cmd && x == 'n')
+		    pathchecked = path;
 	    } else
 		x = 'n';
 	} else


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

* Re: Auto-correct and newly-added commands
  2011-11-15  4:16 ` Bart Schaefer
@ 2011-11-18 12:50   ` Daniel Serodio
  2011-11-18 15:07     ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Serodio @ 2011-11-18 12:50 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Bart Schaefer wrote:
> On Nov 14,  4:31pm, Daniel Serodio (lists) wrote:
> }
> } It it possible to have zsh automatically run "rehash" after I reply no
> } to an auto-correct prompt, so it "learns" this new command?
>
> Hrm.  The direct answer is "no" but:
>
> That would certainly seem logical.  Also it seems strange to load up
> the command tables and check them for proper spellings when the word
> that is being checked is not in the command position to begin with.
Hmm, maybe my explanation wasn't clear (or I don't understand your 
reply), but I only have problem with real commands (in the beginning of 
the line), not with their arguments. Or did you mention "words not in 
the command position" from reviewing the code and not my explanation?
> What this patch does is reset the incremental path search in the event
> the correction is rejected.  That allows whatever hashing options the
> user has specified to kick in at the time the path is searched during
> command execution, rather than having to test them all here.
This sounds like what I need, but when I tried to apply this patch, it 
failed (both on zsh 4.3.12 and on a fresh git clone).

Where should I apply this patch?

Thanks,
Daniel Serodio
> Index: Src/utils.c
> --- ../zsh-forge/current/Src/utils.c	2011-09-25 15:52:55.000000000 -0700
> +++ Src/utils.c	2011-11-14 19:58:34.000000000 -0800
> @@ -2498,16 +2498,18 @@
>   	return;
>       if (!(*s)[0] || !(*s)[1])
>   	return;
> -    if (shfunctab->getnode(shfunctab, *s) ||
> -	builtintab->getnode(builtintab, *s) ||
> -	cmdnamtab->getnode(cmdnamtab, *s) ||
> -	aliastab->getnode(aliastab, *s)  ||
> -	reswdtab->getnode(reswdtab, *s))
> -	return;
> -    else if (isset(HASHLISTALL)) {
> -	cmdnamtab->filltable(cmdnamtab);
> -	if (cmdnamtab->getnode(cmdnamtab, *s))
> +    if (cmd) {
> +	if (shfunctab->getnode(shfunctab, *s) ||
> +	    builtintab->getnode(builtintab, *s) ||
> +	    cmdnamtab->getnode(cmdnamtab, *s) ||
> +	    aliastab->getnode(aliastab, *s)  ||
> +	    reswdtab->getnode(reswdtab, *s))
>   	    return;
> +	else if (isset(HASHLISTALL)) {
> +	    cmdnamtab->filltable(cmdnamtab);
> +	    if (cmdnamtab->getnode(cmdnamtab, *s))
> +		return;
> +	}
>       }
>       t = *s;
>       if (*t == Tilde || *t == Equals || *t == String)
> @@ -2621,6 +2623,8 @@
>   		fflush(shout);
>   		zbeep();
>   		x = getquery("nyae \t", 0);
> +		if (cmd&&  x == 'n')
> +		    pathchecked = path;
>   	    } else
>   		x = 'n';
>   	} else
>


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

* Re: Auto-correct and newly-added commands
  2011-11-18 12:50   ` Daniel Serodio
@ 2011-11-18 15:07     ` Bart Schaefer
  2011-11-23 20:21       ` Daniel Serodio (lists)
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2011-11-18 15:07 UTC (permalink / raw)
  To: zsh-users

On Nov 18, 10:50am, Daniel Serodio wrote:
} Subject: Re: Auto-correct and newly-added commands
}
} Bart Schaefer wrote:
} > On Nov 14,  4:31pm, Daniel Serodio (lists) wrote:
} > }
} > } It it possible to have zsh automatically run "rehash" after I reply no
} > } to an auto-correct prompt, so it "learns" this new command?
} >
} > That would certainly seem logical.  Also it seems strange to load up
} > the command tables and check them for proper spellings when the word
} > that is being checked is not in the command position to begin with.
} Hmm, maybe my explanation wasn't clear (or I don't understand your 
} reply), but I only have problem with real commands (in the beginning of 
} the line), not with their arguments. Or did you mention "words not in 
} the command position" from reviewing the code and not my explanation?

The latter (that's the first hunk of the patch).

} > What this patch does is reset the incremental path search in the event
} > the correction is rejected.  That allows whatever hashing options the
} > user has specified to kick in at the time the path is searched during
} > command execution, rather than having to test them all here.
} This sounds like what I need, but when I tried to apply this patch, it 
} failed (both on zsh 4.3.12 and on a fresh git clone).

I'm not sure why it would have failed on 4.3.12, but it's already been
committed to sourceforge CVS so a fresh git of the very latest probably
won't need to have it applied.

What was the failure message from patch?  Did you use "patch -p0" ?
 
} Where should I apply this patch?

For your purposes you only need the second hunk with two lines added.
Try manually deleting the first hunk and then applying the second:

} > @@ -2621,6 +2623,8 @@
} >   		fflush(shout);
} >   		zbeep();
} >   		x = getquery("nyae \t", 0);
} > +		if (cmd&&  x == 'n')
} > +		    pathchecked = path;
} >   	    } else
} >   		x = 'n';
} >   	} else


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

* Re: Auto-correct and newly-added commands
  2011-11-18 15:07     ` Bart Schaefer
@ 2011-11-23 20:21       ` Daniel Serodio (lists)
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Serodio (lists) @ 2011-11-23 20:21 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer wrote:
> On Nov 18, 10:50am, Daniel Serodio wrote:
> } Subject: Re: Auto-correct and newly-added commands
> }
> } Bart Schaefer wrote:
> }>  On Nov 14,  4:31pm, Daniel Serodio (lists) wrote:
> }>  }
> }>  } It it possible to have zsh automatically run "rehash" after I reply no
> }>  } to an auto-correct prompt, so it "learns" this new command?
> }>
> }>  That would certainly seem logical.  Also it seems strange to load up
> }>  the command tables and check them for proper spellings when the word
> }>  that is being checked is not in the command position to begin with.
> } Hmm, maybe my explanation wasn't clear (or I don't understand your
> } reply), but I only have problem with real commands (in the beginning of
> } the line), not with their arguments. Or did you mention "words not in
> } the command position" from reviewing the code and not my explanation?
>
> The latter (that's the first hunk of the patch).
>
> }>  What this patch does is reset the incremental path search in the event
> }>  the correction is rejected.  That allows whatever hashing options the
> }>  user has specified to kick in at the time the path is searched during
> }>  command execution, rather than having to test them all here.
> } This sounds like what I need, but when I tried to apply this patch, it
> } failed (both on zsh 4.3.12 and on a fresh git clone).
>
> I'm not sure why it would have failed on 4.3.12, but it's already been
> committed to sourceforge CVS so a fresh git of the very latest probably
> won't need to have it applied.
>
> What was the failure message from patch?  Did you use "patch -p0" ?
I used patch -p0 on zsh-4.3.12 sources root directory:

patching file Src/utils.c
Hunk #1 FAILED at 2498.
Hunk #2 FAILED at 2623.
2 out of 2 hunks FAILED -- saving rejects to file Src/utils.c.rej
>
> } Where should I apply this patch?
>
> For your purposes you only need the second hunk with two lines added.
> Try manually deleting the first hunk and then applying the second:
I've applied this hunk by manually typing and it works like a charm.

Thanks a lot,
Daniel Serodio


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

end of thread, other threads:[~2011-11-23 20:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-14 18:31 Auto-correct and newly-added commands Daniel Serodio (lists)
2011-11-15  4:16 ` Bart Schaefer
2011-11-18 12:50   ` Daniel Serodio
2011-11-18 15:07     ` Bart Schaefer
2011-11-23 20:21       ` Daniel Serodio (lists)

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