From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 730 invoked from network); 5 Apr 2009 00:07:53 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 5 Apr 2009 00:07:53 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 95441 invoked from network); 5 Apr 2009 00:07:46 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Apr 2009 00:07:46 -0000 Received: (qmail 29520 invoked by alias); 5 Apr 2009 00:07:37 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26803 Received: (qmail 29495 invoked from network); 5 Apr 2009 00:07:35 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 5 Apr 2009 00:07:35 -0000 Received: from smtprelay03.ispgateway.de (smtprelay03.ispgateway.de [80.67.18.15]) by bifrost.dotsrc.org (Postfix) with ESMTP id EF81C8026E28 for ; Sun, 5 Apr 2009 02:07:18 +0200 (CEST) Received: from [83.135.207.17] (helo=fsst.voodoo.lan) by smtprelay03.ispgateway.de with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.68) (envelope-from ) id 1LqFtO-0004Ef-Ed for zsh-workers@sunsite.dk; Sun, 05 Apr 2009 02:07:18 +0200 Received: from hawk by fsst.voodoo.lan with local (Exim 4.69) (envelope-from ) id 1LqFtH-0001E1-0m for zsh-workers@sunsite.dk; Sun, 05 Apr 2009 02:07:11 +0200 From: Frank Terbeck To: zsh-workers@sunsite.dk Subject: PATCH: Add CORRECT_NOCOMPSYS option Date: Sun, 5 Apr 2009 02:07:10 +0200 Message-Id: <1238890030-4683-1-git-send-email-ft@bewatermyfriend.org> X-Mailer: git-send-email 1.6.2.1.136.g8e24 X-Df-Sender: 430444 X-Virus-Scanned: ClamAV 0.92.1/9204/Sat Apr 4 03:22:15 2009 on bifrost X-Virus-Status: Clean --- 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(_). 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