zsh-workers
 help / color / Atom feed
* PATCH: completion of X colours
       [not found] <8691-1594050559.938587.ref@nS9U.7ujg.aulP>
@ 2020-07-06 15:49 ` Oliver Kiddle
  2020-07-07 11:08   ` also document conventions in the style guide (was Re: PATCH: completion of X colours) Oliver Kiddle
  0 siblings, 1 reply; 2+ messages in thread
From: Oliver Kiddle @ 2020-07-06 15:49 UTC (permalink / raw)
  To: Zsh workers

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

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

* also document conventions in the style guide (was Re: PATCH: completion of X colours)
  2020-07-06 15:49 ` PATCH: completion of X colours Oliver Kiddle
@ 2020-07-07 11:08   ` Oliver Kiddle
  0 siblings, 0 replies; 2+ messages in thread
From: Oliver Kiddle @ 2020-07-07 11:08 UTC (permalink / raw)
  To: zsh-workers

I wrote:
> 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.

Perhaps this should be documented as a convention. This adds a paragraph
to the style-guide. On checking over the style guide, I noticed some
minor errors and I think there is value in explicitly recommending the
use of imperative mood form for per-match descriptions. That is the
form used when telling someone to do something. So e.g. "skip matching
files". It's not uncommon that people write "skips matching files" which
is both longer and the lack of an explicit sentence subject is more
jarring.

Oliver

diff --git a/Etc/completion-style-guide b/Etc/completion-style-guide
index 53d522764..cb5504370 100644
--- a/Etc/completion-style-guide
+++ b/Etc/completion-style-guide
@@ -44,7 +44,10 @@ Descriptions:
 
 Descriptions should not have a trailing full stop and initial capital
 letter. Though capitals are fine where you have an acronym which
-generally appears in uppercase. 
+generally appears in uppercase. Prefer the use of the imperative
+mood as it is both shorter and is more natural in the absence of
+an explicit subject for a sentence, e.g. "recurse subdirectories"
+instead of "recurses subdirectories", as if orders are being given.
 
 It is a good idea to copy descriptions from the command's man page or
 --help output. If you do this, be careful that the description still
@@ -121,7 +124,7 @@ supported. The functions are merely updated to reflect the latest stable
 version. Exceptions to this can be made where are particular version
 continues to be commonly distributed. Where there is more than one variant
 of the same command however (e.g., the command takes different options
-different platforms), the separate variants should be supported.
+on different platforms), the separate variants should be supported.
 
 Contexts, tags and all that
 ---------------------------
@@ -433,7 +436,7 @@ keep things consistent).
 Descriptions
 ------------
 
-Always use description. This is important. Really. *Always* use
+Always use descriptions. This is important. Really. *Always* use
 descriptions. If you have just written down a `compadd' without a
 "$expl[@]" (or equivalent), you have just made an error. Even in
 helper functions where you use a "$@": if you can't be sure that there 
@@ -486,6 +489,20 @@ is all you need to make your function work correctly with both tags
 and description at the same time.
 
 
+Caching
+-------
+
+Where generating matches takes a long time it can be useful to save
+the list for reuse in subsequent completion attempts.  If you use
+a global variable, prefix the name of it with `_cache_' and explicitly
+declare it with `typeset -g'.  In many cases this is sufficient but
+where generating matches takes especially long or the list is
+especially large, use the `_store_cache` mechanism to allow for a
+persistent cache.  When caching matches, also consider whether
+generated matches might be affected by style settings for limited
+contexts and adapt to allow such configuration to work.
+
+
 Misc. remarks
 -------------
 
@@ -513,7 +530,7 @@ Misc. remarks
 6)  When matches with a common prefix such as option names are generated,
     add them *with* the prefix (like `-', `+', or `--' for options).
     Then check the `prefix-needed' style to see if the matches are to be
-    added when the prefix is on the line and use the `prefix-hidden'
+    added when the prefix is not on the line and use the `prefix-hidden'
     style to see if the prefix should be listed or not.
 7)  If at all possible, completion code for a command or a suite of
     commands should go into only one file. If a command has sub-commands,

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

end of thread, back to index

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

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git