* [PATCH] Add CORRECT_IGNORE_NAME for file names pattern ignored during CORRECT_ALL
@ 2014-04-24 22:05 Tomoki Sekiyama
2014-04-25 16:01 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Tomoki Sekiyama @ 2014-04-24 22:05 UTC (permalink / raw)
To: zsh-workers
When CORRECT_ALL is enabled, spell checking for file names may suggest
unwanted correction for command arguments. For example, if a file named
'.status' exists in current directory, `git status' will ask:
zsh: correct 'status' to '.status' [nyae]?
With this patch, we can avoid this by set CORRECT_IGNORE_NAME shell variable
to '.*', that means dotfile names shouldn't be suggested.
---
Doc/Zsh/options.yo | 3 +++
Doc/Zsh/params.yo | 7 +++++++
Src/utils.c | 11 ++++++++++-
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index fbcf28c..96df041 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1098,6 +1098,9 @@ pindex(CORRECTALL)
pindex(NOCORRECTALL)
item(tt(CORRECT_ALL) (tt(-O)))(
Try to correct the spelling of all arguments in a line.
+
+The shell variable tt(CORRECT_IGNORE_NAME) may be set to a pattern to
+match file names that will never be offered as corrections.
)
pindex(DVORAK)
pindex(NO_DVORAK)
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 8d95355..f01c4bd 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -917,6 +917,13 @@ of file names, as applied by the tt(CORRECT_ALL) option (so with the
example just given files beginning with `tt(_)' in the current
directory would still be completed).
)
+vindex(CORRECT_IGNORE_NAME)
+item(tt(CORRECT_IGNORE_NAME))(
+If set, is treated as a pattern during spelling correction of file names.
+Any file names correction that matches the pattern is ignored. For example,
+if the value is `tt(.*)' then dot file names will never be offered
+as spelling corrections. This is useful with the tt(CORRECT_ALL) option.
+)
vindex(DIRSTACKSIZE)
item(tt(DIRSTACKSIZE))(
The maximum size of the directory stack, by default there is no limit. If the
diff --git a/Src/utils.c b/Src/utils.c
index e1fd7a3..c092464 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2491,7 +2491,7 @@ getquery(char *valid_chars, int purge)
static int d;
static char *guess, *best;
-static Patprog spckpat;
+static Patprog spckpat, spnamepat;
/**/
static void
@@ -2562,6 +2562,13 @@ spckword(char **s, int hist, int cmd, int ask)
} else
spckpat = NULL;
+ if ((correct_ignore = getsparam("CORRECT_IGNORE_NAME")) != NULL) {
+ tokenize(correct_ignore = dupstring(correct_ignore));
+ remnulargs(correct_ignore);
+ spnamepat = patcompile(correct_ignore, 0, NULL);
+ } else
+ spnamepat = NULL;
+
if (**s == String && !*t) {
guess = *s + 1;
if (itype_end(guess, IIDENT, 1) == guess)
@@ -3783,6 +3790,8 @@ mindist(char *dir, char *mindistguess, char *mindistbest)
if (!(dd = opendir(unmeta(dir))))
return mindistd;
while ((fn = zreaddir(dd, 0))) {
+ if (spnamepat && pattry(spnamepat, fn))
+ continue;
nd = spdist(fn, mindistguess,
(int)strlen(mindistguess) / 4 + 1);
if (nd <= mindistd) {
--
1.9.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add CORRECT_IGNORE_NAME for file names pattern ignored during CORRECT_ALL
2014-04-24 22:05 [PATCH] Add CORRECT_IGNORE_NAME for file names pattern ignored during CORRECT_ALL Tomoki Sekiyama
@ 2014-04-25 16:01 ` Bart Schaefer
2014-04-25 16:09 ` Peter Stephenson
2014-04-28 14:11 ` [PATCH] Add CORRECT_IGNORE_FILE " Tomoki Sekiyama
0 siblings, 2 replies; 4+ messages in thread
From: Bart Schaefer @ 2014-04-25 16:01 UTC (permalink / raw)
To: zsh-workers
On Apr 24, 6:05pm, Tomoki Sekiyama wrote:
}
} When CORRECT_ALL is enabled, spell checking for file names may suggest
} unwanted correction for command arguments.
}
} With this patch, we can avoid this by set CORRECT_IGNORE_NAME shell variable
} to '.*', that means dotfile names shouldn't be suggested.
No particular argument against this except the usual recent one about
continuing to clutter up the parameter namespace.
I do wonder if CORRECT_IGNORE_FILE or CORRECT_ALL_IGNORE or even
CORRECT_FIGNORE might be better names for the shell variable. Opinions?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Add CORRECT_IGNORE_NAME for file names pattern ignored during CORRECT_ALL
2014-04-25 16:01 ` Bart Schaefer
@ 2014-04-25 16:09 ` Peter Stephenson
2014-04-28 14:11 ` [PATCH] Add CORRECT_IGNORE_FILE " Tomoki Sekiyama
1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 2014-04-25 16:09 UTC (permalink / raw)
To: zsh-workers
On Fri, 25 Apr 2014 09:01:49 -0700
Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Apr 24, 6:05pm, Tomoki Sekiyama wrote:
> }
> } When CORRECT_ALL is enabled, spell checking for file names may suggest
> } unwanted correction for command arguments.
> }
> } With this patch, we can avoid this by set CORRECT_IGNORE_NAME shell variable
> } to '.*', that means dotfile names shouldn't be suggested.
>
>
> No particular argument against this except the usual recent one about
> continuing to clutter up the parameter namespace.
>
> I do wonder if CORRECT_IGNORE_FILE or CORRECT_ALL_IGNORE or even
> CORRECT_FIGNORE might be better names for the shell variable. Opinions?
I was going to suggest CORRECT_IGNORE_FILE, or maybe even
ZSH_CORRECT_IGNORE_FILE to use the pseudo-namespace we've got with many
recent parameters (making them inconsistent with older ones).
pws
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] Add CORRECT_IGNORE_FILE for file names pattern ignored during CORRECT_ALL
2014-04-25 16:01 ` Bart Schaefer
2014-04-25 16:09 ` Peter Stephenson
@ 2014-04-28 14:11 ` Tomoki Sekiyama
1 sibling, 0 replies; 4+ messages in thread
From: Tomoki Sekiyama @ 2014-04-28 14:11 UTC (permalink / raw)
To: zsh-workers
It seems 'CORRECT_IGNORE_FILE' most acceptable, so I changed the name
of shell variable.
=====
Add CORRECT_IGNORE_FILE for file names pattern ignored during CORRECT_ALL
When CORRECT_ALL is enabled, spell checking for file names may suggest
unwanted correction for command arguments. For example, if a file named
'.status' exists in current directory, `git status' will ask:
zsh: correct 'status' to '.status' [nyae]?
With this patch, we can avoid this by set CORRECT_IGNORE_FILE shell variable
to '.*', that means dotfile names shouldn't be suggested.
---
Doc/Zsh/options.yo | 3 +++
Doc/Zsh/params.yo | 7 +++++++
Src/utils.c | 11 ++++++++++-
3 files changed, 20 insertions(+), 1 deletion(-)
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index fbcf28c..f7e11d2 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -1098,6 +1098,9 @@ pindex(CORRECTALL)
pindex(NOCORRECTALL)
item(tt(CORRECT_ALL) (tt(-O)))(
Try to correct the spelling of all arguments in a line.
+
+The shell variable tt(CORRECT_IGNORE_FILE) may be set to a pattern to
+match file names that will never be offered as corrections.
)
pindex(DVORAK)
pindex(NO_DVORAK)
diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index 8d95355..ec7a1f2 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -917,6 +917,13 @@ of file names, as applied by the tt(CORRECT_ALL) option (so with the
example just given files beginning with `tt(_)' in the current
directory would still be completed).
)
+vindex(CORRECT_IGNORE_FILE)
+item(tt(CORRECT_IGNORE_FILE))(
+If set, is treated as a pattern during spelling correction of file names.
+Any file names correction that matches the pattern is ignored. For example,
+if the value is `tt(.*)' then dot file names will never be offered
+as spelling corrections. This is useful with the tt(CORRECT_ALL) option.
+)
vindex(DIRSTACKSIZE)
item(tt(DIRSTACKSIZE))(
The maximum size of the directory stack, by default there is no limit. If the
diff --git a/Src/utils.c b/Src/utils.c
index e1fd7a3..9439227 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2491,7 +2491,7 @@ getquery(char *valid_chars, int purge)
static int d;
static char *guess, *best;
-static Patprog spckpat;
+static Patprog spckpat, spnamepat;
/**/
static void
@@ -2562,6 +2562,13 @@ spckword(char **s, int hist, int cmd, int ask)
} else
spckpat = NULL;
+ if ((correct_ignore = getsparam("CORRECT_IGNORE_FILE")) != NULL) {
+ tokenize(correct_ignore = dupstring(correct_ignore));
+ remnulargs(correct_ignore);
+ spnamepat = patcompile(correct_ignore, 0, NULL);
+ } else
+ spnamepat = NULL;
+
if (**s == String && !*t) {
guess = *s + 1;
if (itype_end(guess, IIDENT, 1) == guess)
@@ -3783,6 +3790,8 @@ mindist(char *dir, char *mindistguess, char *mindistbest)
if (!(dd = opendir(unmeta(dir))))
return mindistd;
while ((fn = zreaddir(dd, 0))) {
+ if (spnamepat && pattry(spnamepat, fn))
+ continue;
nd = spdist(fn, mindistguess,
(int)strlen(mindistguess) / 4 + 1);
if (nd <= mindistd) {
--
1.9.0
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-04-28 14:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-24 22:05 [PATCH] Add CORRECT_IGNORE_NAME for file names pattern ignored during CORRECT_ALL Tomoki Sekiyama
2014-04-25 16:01 ` Bart Schaefer
2014-04-25 16:09 ` Peter Stephenson
2014-04-28 14:11 ` [PATCH] Add CORRECT_IGNORE_FILE " Tomoki Sekiyama
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).