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

PATCH: Add $patchars and $dis_patchars to zsh/parameter module, update completers



Two patches, the first adds $patchars and $dis_patchars to the
zsh/parameter module, the second uses these to update the _enable and
_disable completers. It also fixes a typo 'enable -b' in the docs.

---
 Doc/Zsh/mod_parameter.yo  |  8 ++++++++
 Src/Modules/parameter.c   | 40 ++++++++++++++++++++++++++++++++++++++++
 Src/Modules/parameter.mdd |  2 +-
 Src/pattern.c             |  3 ++-
 Test/V01zmodload.ztst     |  2 ++
 5 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo
index 5948d74..32d4796 100644
--- a/Doc/Zsh/mod_parameter.yo
+++ b/Doc/Zsh/mod_parameter.yo
@@ -57,6 +57,14 @@ vindex(dis_reswords)
 item(tt(dis_reswords))(
 Like tt(reswords) but for disabled reserved words.
 )
+vindex(patchars)
+item(tt(patchars))(
+This array contains the enabled pattern characters.
+)
+vindex(dis_patchars)
+item(tt(dis_patchars))(
+Like tt(patchars) but for disabled pattern characters.
+)
 vindex(aliases)
 item(tt(aliases))(
 This maps the names of the regular aliases currently enabled to their
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index a029c9c..22148f9 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -759,6 +759,38 @@ disreswordsgetfn(UNUSED(Param pm))
     return getreswords(DISABLED);
 }
 
+/* Functions for the patchars special parameter. */
+
+/**/
+static char **
+getpatchars(int dis)
+{
+    int i;
+    char **ret, **p;
+
+    p = ret = (char **) zhalloc(ZPC_COUNT * sizeof(char *));
+
+    for (i = 0; i < ZPC_COUNT; i++)
+	if (zpc_strings[i] && !dis == !zpc_disables[i])
+	    *p++ = dupstring(zpc_strings[i]);
+
+    *p = NULL;
+
+    return ret;
+}
+
+static char **
+patcharsgetfn(UNUSED(Param pm))
+{
+    return getpatchars(0);
+}
+
+static char **
+dispatcharsgetfn(UNUSED(Param pm))
+{
+    return getpatchars(1);
+}
+
 /* Functions for the options special parameter. */
 
 /**/
@@ -2018,6 +2050,10 @@ static const struct gsu_array reswords_gsu =
 { reswordsgetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array disreswords_gsu =
 { disreswordsgetfn, arrsetfn, stdunsetfn };
+static const struct gsu_array patchars_gsu =
+{ patcharsgetfn, arrsetfn, stdunsetfn };
+static const struct gsu_array dispatchars_gsu =
+{ dispatcharsgetfn, arrsetfn, stdunsetfn };
 static const struct gsu_array dirs_gsu =
 { dirsgetfn, dirssetfn, stdunsetfn };
 static const struct gsu_array historywords_gsu =
@@ -2038,6 +2074,8 @@ static struct paramdef partab[] = {
 	    &pmdisfunctions_gsu, getpmdisfunction, scanpmdisfunctions),
     SPECIALPMDEF("dis_galiases", 0,
 	    &pmdisgaliases_gsu, getpmdisgalias, scanpmdisgaliases),
+    SPECIALPMDEF("dis_patchars", PM_ARRAY|PM_READONLY,
+	    &dispatchars_gsu, NULL, NULL),
     SPECIALPMDEF("dis_reswords", PM_ARRAY|PM_READONLY,
 	    &disreswords_gsu, NULL, NULL),
     SPECIALPMDEF("dis_saliases", 0,
@@ -2072,6 +2110,8 @@ static struct paramdef partab[] = {
 	    &pmoptions_gsu, getpmoption, scanpmoptions),
     SPECIALPMDEF("parameters", PM_READONLY,
 	    NULL, getpmparameter, scanpmparameters),
+    SPECIALPMDEF("patchars", PM_ARRAY|PM_READONLY,
+	    &patchars_gsu, NULL, NULL),
     SPECIALPMDEF("reswords", PM_ARRAY|PM_READONLY,
 	    &reswords_gsu, NULL, NULL),
     SPECIALPMDEF("saliases", 0,
diff --git a/Src/Modules/parameter.mdd b/Src/Modules/parameter.mdd
index eb48d5f..a91a5dc 100644
--- a/Src/Modules/parameter.mdd
+++ b/Src/Modules/parameter.mdd
@@ -2,6 +2,6 @@ name=zsh/parameter
 link=either
 load=yes
 
-autofeatures="p:parameters p:commands p:functions p:dis_functions p:funcfiletrace p:funcsourcetrace p:funcstack p:functrace p:builtins p:dis_builtins p:reswords p:dis_reswords p:options p:modules p:dirstack p:history p:historywords p:jobtexts p:jobdirs p:jobstates p:nameddirs p:userdirs p:aliases p:dis_aliases p:galiases p:dis_galiases p:saliases p:dis_saliases"
+autofeatures="p:parameters p:commands p:functions p:dis_functions p:funcfiletrace p:funcsourcetrace p:funcstack p:functrace p:builtins p:dis_builtins p:reswords p:dis_reswords p:patchars p:dis_patchars p:options p:modules p:dirstack p:history p:historywords p:jobtexts p:jobdirs p:jobstates p:nameddirs p:userdirs p:aliases p:dis_aliases p:galiases p:dis_galiases p:saliases p:dis_saliases"
 
 objects="parameter.o"
diff --git a/Src/pattern.c b/Src/pattern.c
index 9a358da..f297836 100644
--- a/Src/pattern.c
+++ b/Src/pattern.c
@@ -236,7 +236,8 @@ static const char zpc_chars[ZPC_COUNT] = {
  * Corresponding strings used in enable/disable -p.
  * NULL means no way of turning this on or off.
  */
-static const char *zpc_strings[ZPC_COUNT] = {
+/**/
+const char *zpc_strings[ZPC_COUNT] = {
    NULL, NULL, "|", NULL, "~", "(", "?", "*", "[", "<",
    "^", "#", NULL, "?(", "*(", "+(", "!(", "@("
 };
diff --git a/Test/V01zmodload.ztst b/Test/V01zmodload.ztst
index ea908e9..3580bac 100644
--- a/Test/V01zmodload.ztst
+++ b/Test/V01zmodload.ztst
@@ -183,6 +183,7 @@
 >p:dis_builtins
 >p:dis_functions
 >p:dis_galiases
+>p:dis_patchars
 >p:dis_reswords
 >p:dis_saliases
 >p:funcfiletrace
@@ -200,6 +201,7 @@
 >p:nameddirs
 >p:options
 >p:parameters
+>p:patchars
 >p:reswords
 >p:saliases
 >p:userdirs
-- 
1.8.2-rc3

>From 51d1638eeda9e38773ae4bb0e48908aabf74ca3e Mon Sep 17 00:00:00 2001
From: Mikael Magnusson <mikachu@xxxxxxxxx>
Date: Wed, 9 Oct 2013 17:28:53 +0200
Subject: PATCH 2/2: Update _enable and _disable for -p, fix related typo in
 docs

---
 Completion/Zsh/Command/_disable | 9 +++++----
 Completion/Zsh/Command/_enable  | 8 +++++---
 Doc/Zsh/builtins.yo             | 2 +-
 3 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/Completion/Zsh/Command/_disable b/Completion/Zsh/Command/_disable
index 3b627fb..68be75f 100644
--- a/Completion/Zsh/Command/_disable
+++ b/Completion/Zsh/Command/_disable
@@ -1,9 +1,10 @@
 #compdef disable
 
 _arguments -C -s -A "-*" -S \
-  "(-f -r -s)-a[act on regular or global aliases]:*:regular or global aliases:(${(k)aliases} ${(k)galiases})" \
-  "(-a -r -s)-f[act on functions]:*:functions:(${(k)functions})" \
-  "(-a -f -s)-r[act on reserved words]:*:reserved-words:compadd -k reswords" \
-  "(-a -f -r)-s[act on suffix aliases]:*:suffix aliases:(${(k)saliases})" \
+  "(-f -r -s -p)-a[act on regular or global aliases]:*:regular or global aliases:(${(k)aliases} ${(k)galiases})" \
+  "(-a -r -s -p)-f[act on functions]:*:functions:(${(k)functions})" \
+  "(-a -f -s -p)-r[act on reserved words]:*:reserved-words:compadd -k reswords" \
+  "(-a -f -r -p)-s[act on suffix aliases]:*:suffix aliases:(${(k)saliases})" \
+  "(-a -f -r -s)-p[act on pattern characters]:*:pattern characters:compadd -k patchars" \
   '-m[treat arguments as patterns]' \
   "*:builtin command:(${(k)builtins})"
diff --git a/Completion/Zsh/Command/_enable b/Completion/Zsh/Command/_enable
index c5f8b2c..f773782 100644
--- a/Completion/Zsh/Command/_enable
+++ b/Completion/Zsh/Command/_enable
@@ -1,8 +1,10 @@
 #compdef enable
 
 _arguments -C -s -A "-*" -S \
-  "(-f -r)-a[act on aliases]:*:aliases:(${(k)dis_aliases})" \
-  "(-a -r)-f[act on functions]:*:functions:(${(k)dis_functions})" \
-  "(-a -f)-r[act on reserved words]:*:reserved-words:compadd -k dis_reswords" \
+  "(-f -r -s -p)-a[act on regular or global aliases]:*:aliases:(${(k)dis_aliases} ${(k)dis_galiases})" \
+  "(-a -r -s -p)-f[act on functions]:*:functions:(${(k)dis_functions})" \
+  "(-a -f -s -p)-r[act on reserved words]:*:reserved-words:compadd -k dis_reswords" \
+  "(-a -f -r -p)-s[act on suffix aliases]:*:suffix aliases:(${(k)dis_saliases})" \
+  "(-a -f -r -s)-p[act on pattern characters]:*:pattern characters:compadd -k dis_patchars" \
   '-m[treat arguments as patterns]' \
   "*:builtin command:(${(k)dis_builtins})"
diff --git a/Doc/Zsh/builtins.yo b/Doc/Zsh/builtins.yo
index 8e46a88..2cc33d2 100644
--- a/Doc/Zsh/builtins.yo
+++ b/Doc/Zsh/builtins.yo
@@ -471,7 +471,7 @@ problems in scripts and functions are altered.  If the tt(-L) switch is given,
 the options tt(LOCAL_OPTIONS), tt(LOCAL_PATTERNS) and tt(LOCAL_TRAPS)
 will be set as
 well, causing the effects of the tt(emulate) command and any tt(setopt),
-tt(disable -p) or tt(enable -b), and tt(trap) commands to be local to
+tt(disable -p) or tt(enable -p), and tt(trap) commands to be local to
 the immediately surrounding shell
 function, if any; normally these options are turned off in all emulation
 modes except tt(ksh). The tt(-L) switch is mutually exclusive with the
-- 
1.8.2-rc3



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