zsh-workers
 help / color / mirror / code / Atom feed
* list-color && extended_glob
@ 2008-07-05 18:59 Frank Terbeck
  2008-07-05 19:49 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Frank Terbeck @ 2008-07-05 18:59 UTC (permalink / raw)
  To: zsh workers

Hello workers.

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

Regards, Frank

-- 
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
                                                  -- RFC 1925


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: list-color && extended_glob
  2008-07-05 18:59 list-color && extended_glob Frank Terbeck
@ 2008-07-05 19:49 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2008-07-05 19:49 UTC (permalink / raw)
  To: zsh workers

On Sat, 05 Jul 2008 20:59:36 +0200
Frank Terbeck <ft@bewatermyfriend.org> 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@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-05 19:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-05 18:59 list-color && extended_glob Frank Terbeck
2008-07-05 19:49 ` Peter Stephenson

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