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

Re: PATCH: Add CORRECT_NOCOMPSYS option



On Sat, 04 Apr 2009 19:37:17 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Apr 5,  2:07am, Frank Terbeck wrote:
> }
> } 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.
> 
> My reservation about this is that the leading-underscore naming
> convention is (1) just that, a convention, and (2) specific to this
> implementation of the completion system -- the whole idea of putting
> the completion system into shell code was to remove this kind of
> dependency from the base shell and make it possible for anyone to
> implement their own system (admittedly increasingly unlikely at
> this point, but still).
> 
> A more general solution would be an fignore-type variable, which
> compinit could set to the value "_*" or some such thing.

Right, here's a more general solution.  Shout if I've missed something.

Index: Doc/Zsh/options.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/options.yo,v
retrieving revision 1.80
diff -u -r1.80 options.yo
--- Doc/Zsh/options.yo	26 Mar 2009 15:21:39 -0000	1.80
+++ Doc/Zsh/options.yo	5 Apr 2009 18:11:45 -0000
@@ -1007,6 +1007,9 @@
 Note that, when the tt(HASH_LIST_ALL) option is not set or when some
 directories in the path are not readable, this may falsely report spelling
 errors the first time some commands are used.
+
+The shell variable tt(CORRECT_IGNORE) may be set to a pattern to
+match words that will never be offered as corrections.
 )
 pindex(CORRECT_ALL)
 pindex(NO_CORRECT_ALL)
Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.52
diff -u -r1.52 params.yo
--- Doc/Zsh/params.yo	3 Mar 2009 21:04:53 -0000	1.52
+++ Doc/Zsh/params.yo	5 Apr 2009 18:11:46 -0000
@@ -797,6 +797,14 @@
 The number of columns for this terminal session.
 Used for printing select lists and for the line editor.
 )
+vindex(CORRECT_IGNORE)
+item(tt(CORRECT_IGNORE))(
+If set, is treated as a pattern during spelling correction.  Any
+potential correction that matches the pattern is ignored.  For example,
+if the value is `tt(_*)' then completion functions (which, by
+convention, have names beginning with `tt(_)') will never be offered
+as spelling corrections.
+)
 vindex(DIRSTACKSIZE)
 item(tt(DIRSTACKSIZE))(
 The maximum size of the directory stack.  If the
Index: Src/utils.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/utils.c,v
retrieving revision 1.220
diff -u -r1.220 utils.c
--- Src/utils.c	24 Mar 2009 16:14:33 -0000	1.220
+++ Src/utils.c	5 Apr 2009 18:11:47 -0000
@@ -2236,6 +2236,7 @@
 
 static int d;
 static char *guess, *best;
+static Patprog spckpat;
 
 /**/
 static void
@@ -2243,6 +2244,9 @@
 {
     int nd;
 
+    if (spckpat && pattry(spckpat, hn->nam))
+	return;
+
     nd = spdist(hn->nam, guess, (int) strlen(guess) / 4 + 1);
     if (nd <= d) {
 	best = hn->nam;
@@ -2257,7 +2261,7 @@
 mod_export void
 spckword(char **s, int hist, int cmd, int ask)
 {
-    char *t;
+    char *t, *correct_ignore;
     int x;
     char ic = '\0';
     int ne;
@@ -2293,6 +2297,14 @@
 	    break;
     if (**s == Tilde && !*t)
 	return;
+
+    if ((correct_ignore = getsparam("CORRECT_IGNORE")) != NULL) {
+	tokenize(correct_ignore = dupstring(correct_ignore));
+	remnulargs(correct_ignore);
+	spckpat = patcompile(correct_ignore, 0, NULL);
+    } else
+	spckpat = NULL;
+
     if (**s == String && !*t) {
 	guess = *s + 1;
 	if (itype_end(guess, IIDENT, 1) == guess)



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



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