zsh-workers
 help / color / mirror / code / Atom feed
From: Frank Terbeck <ft@bewatermyfriend.org>
To: zsh-workers@sunsite.dk
Subject: PATCH: Add CORRECT_NOCOMPSYS option
Date: Sun,  5 Apr 2009 02:07:10 +0200	[thread overview]
Message-ID: <1238890030-4683-1-git-send-email-ft@bewatermyfriend.org> (raw)

---

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


             reply	other threads:[~2009-04-05  0:07 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-05  0:07 Frank Terbeck [this message]
2009-04-05  2:37 ` Bart Schaefer
2009-04-05 12:23   ` Frank Terbeck
2009-04-05 18:13   ` Peter Stephenson
2009-04-05 22:11     ` Bart Schaefer
2009-04-06  9:09       ` Peter Stephenson
2009-05-27 16:30         ` Richard Hartmann
2009-05-27 16:59           ` Peter Stephenson
2009-05-27 19:12             ` Greg Klanderman
2009-05-28  8:48               ` Richard Hartmann
2009-05-28  9:25                 ` Frank Terbeck
2009-05-28 18:44                   ` Greg Klanderman
2009-05-28 19:03                     ` Frank Terbeck
2009-05-28 19:35                     ` Peter Stephenson
2009-05-28 22:56                       ` Greg Klanderman
2009-05-29  8:32                         ` Peter Stephenson
2009-05-29 14:38                           ` Greg Klanderman
2009-05-29 14:49                             ` Peter Stephenson
2011-03-01 20:39                 ` PATCH: zstyle to control completion of functions/parameters beginning with underscore Greg Klanderman
2011-03-01 21:11                   ` Peter Stephenson
2011-03-01 22:07                     ` Greg Klanderman
2011-03-02  1:05                   ` Oliver Kiddle
2011-03-02 18:49                     ` Greg Klanderman
2011-03-02 23:30                       ` Bart Schaefer
2011-03-03 15:33                         ` Greg Klanderman
2011-03-03 16:11                           ` Greg Klanderman
2011-03-03 16:54                           ` Bart Schaefer
2011-03-06 20:07                             ` Greg Klanderman
2011-03-06 22:02                               ` Bart Schaefer
2011-03-08 15:13                                 ` Greg Klanderman
2011-03-09 18:41                                 ` Greg Klanderman
2011-03-10 15:54                                   ` Bart Schaefer
2011-03-10 16:44                                     ` Greg Klanderman
2011-03-10 17:10                                       ` Bart Schaefer
2011-03-10 18:01                                         ` Greg Klanderman
2011-03-11 17:01                                     ` Greg Klanderman
2011-03-03 16:58                           ` Oliver Kiddle
2011-03-02  1:13                   ` Richard Hartmann

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=1238890030-4683-1-git-send-email-ft@bewatermyfriend.org \
    --to=ft@bewatermyfriend.org \
    --cc=zsh-workers@sunsite.dk \
    /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 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).