zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Zsh workers <zsh-workers@zsh.org>
Subject: PATCH: completion of X colours
Date: Mon, 06 Jul 2020 17:49:19 +0200	[thread overview]
Message-ID: <8691-1594050559.938587@nS9U.7ujg.aulP> (raw)
In-Reply-To: <8691-1594050559.938587.ref@nS9U.7ujg.aulP>

Completion of X colors seems to have stopped working at some point. This
makes it check if the showrgb command is installed and if so, uses it.

I've also taken the opportunity to rename the cache variable. Using
"cache" consistently as a prefix makes them easier to identify. And I
think we try to declare them explicitly with typeset -g now.

Oliver

diff --git a/Completion/X/Type/_x_color b/Completion/X/Type/_x_color
index 960eae6d3..845a35686 100644
--- a/Completion/X/Type/_x_color
+++ b/Completion/X/Type/_x_color
@@ -10,25 +10,28 @@
 
 local expl
 
-if (( ! $+_color_cache )); then
+if (( ! $+_cache_x_colors )); then
+  typeset -ga _cache_x_colors
   local file
 
   # Cache of color names doesn't exist yet, create it.
 
   zstyle -s ":completion:${curcontext}:colors" path file
   if [[ -n "$file" ]]; then
-    _color_cache=( "${(@)${(@f)$(< $file)}[2,-1]##*		}" )
+    _cache_x_colors=( "${(@)${(@f)$(< $file)}[2,-1]##*		}" )
+  elif (( $+commands[showrgb] )); then
+    _cache_x_colors=( "${(@)${(@)${(@f)$(_call_program colors showrgb)}[2,-1]##*		}:#* *}" )
   else
     file=( /usr/{lib,{{X11R6,openwin},local{,/X11{,R6}}}/lib}/X11/rgb.txt(N) )
 
     (( $#file )) &&
-        _color_cache=( "${(@)${(@)${(@f)$(< $file[1])}[2,-1]##*		}:#* *}" )
+        _cache_x_colors=( "${(@)${(@)${(@f)$(< $file[1])}[2,-1]##*		}:#* *}" )
   fi
 
   # Stupid default value.
 
-  (( $#_color_cache )) || _color_cache=(white black gray red blue green)
+  (( $#_cache_x_colors )) || _cache_x_colors=(white black gray red blue green)
 fi
 
 _wanted colors expl 'color specification' compadd "$@" -M \
-    'm:{a-z}={A-Z} m:-=\  r:[^ A-Z0-9]||[ A-Z0-9]=* r:|=*' -a - _color_cache
+    'm:{a-z}={A-Z} m:-=\  r:[^ A-Z0-9]||[ A-Z0-9]=* r:|=*' -a - _cache_x_colors

       reply	other threads:[~2020-07-06 15:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <8691-1594050559.938587.ref@nS9U.7ujg.aulP>
2020-07-06 15:49 ` Oliver Kiddle [this message]
2020-07-07 11:08   ` also document conventions in the style guide (was Re: PATCH: completion of X colours) Oliver Kiddle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8691-1594050559.938587@nS9U.7ujg.aulP \
    --to=okiddle@yahoo.co.uk \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).