Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: Add CORRECT_NOCOMPSYS option



---

The documentation snippet pretty much tells the story. Without the new
option set, you get:

% nautilus
zsh: correct 'nautilus' to '_nautilus'? (YNEA)

With the option set, it goes directly to:
% nautilus
zsh: command not found: nautilus

I think it's a reasonable solution, that a) removes this (to me)
annoying warning and b) makes a lot of sense, if you want to use the
command_not_found_handler() feature.

This certainly is not perfect. A better solution would be to disallow
_commandname type function names from being the result of a correction
without completely disabling correction.

Still, I think this would work fairly well in most cases.
Per default, the option is disabled, which means zsh will behave
exactly like it does now. No change at all.

Regards, Frank

 Doc/Zsh/options.yo |   14 ++++++++++++++
 Src/options.c      |    1 +
 Src/utils.c        |   15 ++++++++++++++-
 Src/zsh.h          |    1 +
 4 files changed, 30 insertions(+), 1 deletions(-)

diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 6b3ba34..c6b99dd 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1015,6 +1015,20 @@ pindex(NOCORRECTALL)
 item(tt(CORRECT_ALL) (tt(-O)))(
 Try to correct the spelling of all arguments in a line.
 )
+pindex(CORRECT_NOCOMPSYS)
+pindex(NO_CORRECT_NOCOMPSYS)
+pindex(CORRECTNOCOMPSYS)
+pindex(NOCORRECTNOCOMPSYS)
+item(tt(CORRECT_NOCOMPSYS))(
+When using the function based completion system compsys, the function that
+handles completions for a command is usually named tt(_<command>). When using
+correction, those functions will look like the most probable target for the
+correction code. For the user, it usually does not make sense to call these
+functions by hand.
+
+This option causes zsh to tt(not attempt correction) if a function of the
+previously described name exists.
+)
 pindex(DVORAK)
 pindex(NO_DVORAK)
 pindex(NODVORAK)
diff --git a/Src/options.c b/Src/options.c
index d310f34..14b4da8 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -115,6 +115,7 @@ static struct optname optns[] = {
 {{NULL, "completeinword",     0},			 COMPLETEINWORD},
 {{NULL, "correct",	      0},			 CORRECT},
 {{NULL, "correctall",	      0},			 CORRECTALL},
+{{NULL, "correctnocompsys",   0},			 CORRECTNOCOMPSYS},
 {{NULL, "cshjunkiehistory",   OPT_EMULATE|OPT_CSH},	 CSHJUNKIEHISTORY},
 {{NULL, "cshjunkieloops",     OPT_EMULATE|OPT_CSH},	 CSHJUNKIELOOPS},
 {{NULL, "cshjunkiequotes",    OPT_EMULATE|OPT_CSH},	 CSHJUNKIEQUOTES},
diff --git a/Src/utils.c b/Src/utils.c
index cf37582..79e1105 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2257,7 +2257,7 @@ spscan(HashNode hn, UNUSED(int scanflags))
 mod_export void
 spckword(char **s, int hist, int cmd, int ask)
 {
-    char *t;
+    char *t, *funame;
     int x;
     char ic = '\0';
     int ne;
@@ -2282,6 +2282,19 @@ spckword(char **s, int hist, int cmd, int ask)
 	    return;
     }
     t = *s;
+
+    if (cmd && isset(CORRECTNOCOMPSYS)) {
+	x = (int)strlen(t);
+	funame = (char *)zalloc(x + 2);
+	*funame = '_';
+	strncpy(funame + 1, t, x);
+	funame[x + 1] = '\0';
+	if (shfunctab->getnode(shfunctab, funame)) {
+	    free(funame);
+	    return;
+	}
+	free(funame);
+    }
     if (*t == Tilde || *t == Equals || *t == String)
 	t++;
     for (; *t; t++)
diff --git a/Src/zsh.h b/Src/zsh.h
index 3c1623c..0558739 100644
--- a/Src/zsh.h
+++ b/Src/zsh.h
@@ -1856,6 +1856,7 @@ enum {
     COMPLETEINWORD,
     CORRECT,
     CORRECTALL,
+    CORRECTNOCOMPSYS,
     CPRECEDENCES,
     CSHJUNKIEHISTORY,
     CSHJUNKIELOOPS,
-- 
1.6.2.1.136.g8e24



Messages sorted by: Reverse Date, Date, Thread, Author