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

Re: list-color && extended_glob



On Sat, 05 Jul 2008 20:59:36 +0200
Frank Terbeck <ft@xxxxxxxxxxxxxxxxxxx> wrote:
> Let's assume someone wants colorful completion for kill(1):
> 
> [snip]
> autoload -U compinit && compinit
> zmodload -i zsh/complist
> zstyle ':completion:*:kill:*' command 'ps xf -u $USER -o pid,%cpu,cmd'
> zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
> [snap]
> 
> This only works, if you also setopt extendedglob. If you do not want
> that option set this way of coloring the completion list will not
> work.
> 
> Would it be possible to silently set extendedglob for all style
> evaluations (similar to the fact, that it is set in all completion
> functions by default)?

The problem is not with the style, which sets ZLS_COLORS for later use.
By the time it is examined the completion function has exited and the
top-level options are in effect.

The documentation for ZLS_COLORS, however, implies that extended
globbing is always applied in patterns of this form, and without it
they're pretty useless, so I think it's reasonable to ensure that this
is the case.

Index: Doc/Zsh/mod_complist.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/mod_complist.yo,v
retrieving revision 1.23
diff -u -r1.23 mod_complist.yo
--- Doc/Zsh/mod_complist.yo	16 May 2008 11:49:21 -0000	1.23
+++ Doc/Zsh/mod_complist.yo	5 Jul 2008 19:47:08 -0000
@@ -100,7 +100,8 @@
 (`tt(*)') followed by any string. The var(value) given for such a
 string will be used for all files whose name ends with the string.
 The var(name) may also be an equals sign (`tt(=)') followed by a
-pattern.  The var(value) given for this pattern will be used for all
+pattern; the tt(EXTENDED_GLOB) option will be turned on for evaluation
+of the pattern.  The var(value) given for this pattern will be used for all
 matches (not just filenames) whose display string are matched by
 the pattern.  Definitions for both of these take precedence over the
 values defined for file types and the form with the leading asterisk 
Index: Src/Zle/complist.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v
retrieving revision 1.116
diff -u -r1.116 complist.c
--- Src/Zle/complist.c	16 May 2008 09:37:56 -0000	1.116
+++ Src/Zle/complist.c	5 Jul 2008 19:47:11 -0000
@@ -1923,6 +1923,7 @@
 complistmatches(UNUSED(Hookdef dummy), Chdata dat)
 {
     static int onlnct = -1;
+    static int extendedglob;
 
     Cmgroup oamatches = amatches;
 
@@ -1945,6 +1946,8 @@
      * useful outside.
      */
     pushheap();
+    extendedglob = opts[EXTENDEDGLOB];
+    opts[EXTENDEDGLOB] = 1;
 
     getcols();
 
@@ -1958,6 +1961,7 @@
 	noselect = 1;
 	amatches = oamatches;
 	popheap();
+	opts[EXTENDEDGLOB] = extendedglob;
 	return 1;
     }
     if (inselect || mlbeg >= 0)
@@ -1990,6 +1994,7 @@
 	if (asklist()) {
 	    amatches = oamatches;
 	    popheap();
+	    opts[EXTENDEDGLOB] = extendedglob;
 	    return (noselect = 1);
 	}
     }
@@ -2034,6 +2039,7 @@
     amatches = oamatches;
 
     popheap();
+    opts[EXTENDEDGLOB] = extendedglob;
 
     return noselect;
 }


-- 
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