From d00f73c3672b2783f14e3a27b35d34c218657506 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 12 Aug 1999 21:25:12 +0000 Subject: zsh-workers/7420 --- Completion/Base/_first | 2 +- Completion/Builtins/_zftp | 2 +- Completion/Core/_main_complete | 4 +- Completion/Core/_normal | 28 +++++--- Completion/User/_colors | 24 +++++++ Completion/User/_pbm | 145 ++++++++++++++++++++++++++++++++++++++++- Completion/User/_x_options | 2 +- Doc/Zsh/compsys.yo | 13 ++-- Src/Zle/zle_tricky.c | 4 ++ 9 files changed, 203 insertions(+), 21 deletions(-) create mode 100644 Completion/User/_colors diff --git a/Completion/Base/_first b/Completion/Base/_first index c33e91ff0..694bb8c63 100644 --- a/Completion/Base/_first +++ b/Completion/Base/_first @@ -55,7 +55,7 @@ # # on menu-completion and make sure that no other # # completion function is called by setting _compskip. # compstate[insert]=menu -# _compskip=1 +# _compskip=all # return # fi # (( i++ )) diff --git a/Completion/Builtins/_zftp b/Completion/Builtins/_zftp index 8792e21a7..32d32c2b7 100644 --- a/Completion/Builtins/_zftp +++ b/Completion/Builtins/_zftp @@ -1,7 +1,7 @@ #compdef -p zf* # Don't try any more completion after this. -_compskip=1 +_compskip=all # Completion for zftp builtin and zf* functions. The functions # zfcd_match and zfget_match (used for old-style completion) diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index e71267677..4ac45d2cc 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -42,7 +42,7 @@ # state than the global one for which you are completing. -local comp ret=1 +local comp ret=1 _compskip setopt localoptions nullglob rcexpandparam unsetopt markdirs globsubst shwordsplit nounset ksharrays @@ -80,4 +80,6 @@ _lastcomp[isuffix]="$ISUFFIX" _lastcomp[qiprefix]="$QIPREFIX" _lastcomp[qisuffix]="$QISUFFIX" +unset _compskip + return ret diff --git a/Completion/Core/_normal b/Completion/Core/_normal index 6da653021..d4e948e41 100644 --- a/Completion/Core/_normal +++ b/Completion/Core/_normal @@ -29,17 +29,19 @@ fi # See if there are any matching pattern completions. -for i in "$_patcomps[@]"; do - pat="${i% *}" - val="${i#* }" - if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then - "$val" && ret=0 - if (( $+_compskip )); then - unset _compskip - return ret +if [[ "$_compskip" != *patterns* ]]; then + for i in "$_patcomps[@]"; do + pat="${i% *}" + val="${i#* }" + if [[ "$cmd1" == $~pat || "$cmd2" == $~pat ]]; then + "$val" && ret=0 + if [[ "$_compskip" = *patterns* || "$_compskip" = all ]]; then + unset _compskip + return ret + fi fi - fi -done + done +fi # Now look up the two names in the normal completion array. @@ -54,9 +56,15 @@ fi # And generate the matches, probably using default completion. if [[ -z "$comp" ]]; then + if [[ "$_compskip" = *default* ]]; then + unset _compskip + return 1 + fi name=-default- comp="$_comps[-default-]" fi [[ -z "$comp" ]] || "$comp" && ret=0 +unset _compskip + return ret diff --git a/Completion/User/_colors b/Completion/User/_colors new file mode 100644 index 000000000..4e9ee2030 --- /dev/null +++ b/Completion/User/_colors @@ -0,0 +1,24 @@ +#autoload + +if (( ! $+_color_cache )); then + local file + + # Cache of color names doesn't exist yet, create it. + + if [[ -f /usr/lib/X11/rgb.txt ]]; then + file=/usr/lib/X11/rgb.txt + elif [[ -f /usr/local/lib/X11/rgb.txt ]]; then + file=/usr/local/lib/X11/rgb.txt + fi + + if [[ -n "$file" ]]; then + _color_cache=( "${(@)${(@f)$(< $file)}[2,-1]##* }" ) + else + + # Stupid default value. + + _color_cache=(white black gray red blue green) + fi +fi + +compadd - "$_color_cache[@]" diff --git a/Completion/User/_pbm b/Completion/User/_pbm index 1e5cb16cb..5ee328cd9 100644 --- a/Completion/User/_pbm +++ b/Completion/User/_pbm @@ -1,8 +1,147 @@ #compdef -p p[bgpn]m* -local pat +local pat opts ret=1 -_compskip=1 +# No other completion functions, please. + +_compskip=all + +if (( ! $+_pbm_options )); then + + # Most of the stuff is done by table lookup in these arrays. + + typeset -gA _pbm_options _pbm_arg_options + + # Options with arguments, per command. + + _pbm_arg_options=( + pbmreduce 'value' + pbmtext 'font:_files:-g:*.(#i)pbm' + pbmtolj 'resolution' + pbmtolps 'dpi' + pbmtomacp 'l r t b' + pgmcrater 'number height ysize width xsize gamma' + pgmkernel 'weight' + pgmnorm 'bpercent bvalue wpercent wvalue' + pgmoil 'n' + pgmtexture 'd' + pgmtopbm 'value' + pgmtoppm 'map:_files:-g:*.(#i)ppm' + ppmbrighten 's v' + ppmdither 'dim red green blue' + ppmforge 'dimension hour inclination tilt mesh power glaciers ice saturation seed stars xsize width ysize height' + ppmnorm 'bpercent bvalue wpercent wvalue' + ppmquant 'map:_files:-g:*.(#i)ppm' + ppmtoacad 'background aspect' + ppmtoicr 'windowname expand display' + ppmtomitsu 'sharpness:compadd:1:2:3:4 enlarge:compadd:1:2:3 media:compadd:A:A4:AS:A4S copy:compadd:1:2:3:4:5:6:7:8:9' + ppmtopj 'gamma xpos ypos back:compadd:dark:lite render:compadd:none:snap:bw:dither:diffuse:monodither:monodiffuse:clusterdither:monoclusterdither' + ppmtopjxl 'gamma xshift yshift xsize width xscale ysize height yscale' + ppmtouil 'name' + ppmtoxpm 'name' + pnmalias 'fgcolor:_colors bgcolor:_colors weight' + pnmcomp 'xoff yoff alpha:_files:-g:*.(#i)pgm' + pnmhistmap 'max' + pnmindex 'size across colors' + pnmmargin 'color:_colors' + pnmscale 'xsize width ysize height xscale yscale xysize' + pnmtoddif 'resolution' + pnmtofits 'min max' + pnmtops 'scale dpi width height' + pnmtosgi 'imagename' + pnmtotiff 'predictor rowsperstrip' + pnmtoxwd 'pseudodepth' + ) + + # Options without arguments. + + _pbm_options=( + pbmclean 'connect' + pbmmake 'white black gray' + pbmmask 'expand' + pbmreduce 'floyd fs threshold' + pbmtoepsi 'bbonly' + pgmenhance '1 2 3 4 5 6 7 8 9' + pgmramp 'lr tb rectangle ellipse' + pgmtopbm 'floyd fs threshold dither8 d8 cluster3 c3 cluster4 c4 cluster8 c8' + ppmbrighten 'n' + ppmdist 'intensity frequency' + ppmforge 'clouds night' + ppmpat 'gingham2 g2 gingham3 g3 madras tartan poles squig camo anticamo' + ppmquant 'floyd fs' + ppmqvga 'd q v' + ppmtoacad 'dxb poly white 8' + ppmtobmp 'os2 windows' + ppmtogif 'interlace' + ppmtoicr 'rle' + ppmtoilbm 'hamif' + ppmtomap 'sort square' + ppmtomitsu 'dpi300 tiny' + ppmtopj 'rle center' + ppmtopjxl 'nopack presentation dark diffuse cluster dither' + ppmtosixel 'raw margin' + ppmtotga 'mono cmap rgb norle' + pnmalias 'bonly fonly balias falias' + pnmarith 'add subtract multiply' + pnmcat 'white black leftright lr topbottom tb jtop jbottom jleft jright' + pnmcomp 'invert' + pnmcrop 'white black' + pnmflip 'leftright lr topbottom tb transpose xy rotate90 r90 ccw rotate270 r270 cw rotate180 r180' + pnmhistmap 'black white verbose' + pnmindex 'black' + pnmmargin 'white black' + pnmpad 'white black' + pnmpaste 'replace or and xor' + pnmrotate 'noantialias' + pnmshear 'noantialias' + pnmtops 'turn noturn rle runlength' + pnmtorast 'standard rle' + pnmtosgi 'verbatim rle' + pnmtotiff 'none packbits lzw g3 g4 2d fill msb2lsb lsb2msb' + pnmtoxwd 'directcolor' + ) +fi + +opts=( $=_pbm_arg_options[$words[1]] ) +if (( $#opts )); then + + # This Command has options with arguments. The options are already in + # `opts'. Now we see if we are after one of these options on the line. + + local after="$opts[(I)${words[CURRENT-1][2,-1]}(|:*)]" + + if (( after )); then + + # We are. If the string contains a colon, anything after it is a + # colon-separated list of words. We just execute this list of words + # as a command with its arguments. + + if [[ "$after" = *:* ]]; then + after="${${opts[after]#*:}//:/ }" + [[ -z "$after" ]] || $=after + fi + return + fi + + # Otherwise we just add the option names. + + compadd -J options - -${^=opts%%:*} +fi + +# And the names of the options without arguments. + +opts=( $=_pbm_options[$words[1]] ) +(( $#opts )) && compadd -J options - -${^=opts} + +# A small special case here: the first argument of `ppmmake' is a +# color. More of these could be added. + +if [[ "$words[1]" = ppmmake && CURRENT -eq 2 ]]; then + _colors + return +fi + +# Generate the filenames. if [[ "$words[1]" = pnm* ]]; then pat='*.(#i)p[bgp]m' @@ -10,4 +149,4 @@ else pat="*.(#i)${words[1][1,3]}" fi -_path_files -g "$pat" || _files -g '*.(#i)p[bgp]m' +_path_files -J files -g "$pat" || _files -J files -g '*.(#i)p[bgp]m' diff --git a/Completion/User/_x_options b/Completion/User/_x_options index fddec2af4..51b602a33 100644 --- a/Completion/User/_x_options +++ b/Completion/User/_x_options @@ -3,7 +3,7 @@ # A simple pattern completion, just as an example. if [ "$words[CURRENT-1]" = "-display" ]; then - _compskip='' + _compskip=all _hosts -S :0 else compadd -P- -J options - display name xrm diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 466e612ed..025003675 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -334,8 +334,12 @@ for completing the name of a parameter expansion within braces item(tt(-first-))( for adding completions before any other other completion functions are tried (similar to the `tt(-T)' flag of tt(compctl)); if this -function sets the tt(_compskip) parameter to any value, the completion -system will not call any other function to generate matches. +function sets the tt(_compskip) parameter to `tt(all)', no other +completion functions will be called, if it is set to a string +containing `tt(patterns)', no pattern completion functions will be +called, and if it is set to a string containing `tt(default)' the +function for the `tt(-default-)' context will not be called, but +functions defined for commands will. ) item(tt(-default-))( for generating completions when no special completion function is used @@ -684,8 +688,9 @@ the tt(words) array, decrements the tt(CURRENT) parameter, then calls this function. When calling a function defined for a pattern, this function also -checks if the parameter tt(_compskip) is set. If it was set by the -function called, no further completion functions are called. With this +checks if the parameter tt(_compskip) is set and uses the value in the +same way it is used after calling the completion function for the +tt(-first-) context. With this one can write a pattern completion function that keeps other functions from being tried simply by setting this parameter to any value. ) diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index 347eb9ffa..ed32d312f 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -5338,6 +5338,10 @@ makecomplistcall(Compctl cc) offs = lip + lp; cc->refc++; ccont = 0; + if (!cc->ylist && !cc->gname) { + endcmgroup(NULL); + begcmgroup("default", 0); + } makecomplistor(cc, str, lincmd, lip, 0); offs = ooffs; isuf = oisuf; -- cgit 1.4.1