From e6282df1155e8d9b08b2e518a452c1997973f1ce Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Fri, 12 Nov 1999 15:28:24 +0000 Subject: manual/8630 --- Completion/Core/compinit | 266 ++++++++--------------------------------------- 1 file changed, 42 insertions(+), 224 deletions(-) (limited to 'Completion/Core/compinit') diff --git a/Completion/Core/compinit b/Completion/Core/compinit index 1b88cc8f0..0f614f322 100644 --- a/Completion/Core/compinit +++ b/Completion/Core/compinit @@ -108,13 +108,9 @@ fi compconfig[correct_prompt]='correct to:' (( ${+compconfig[completer]} )) || compconfig[completer]=_complete -# This holds the tag/priority definitions. +# This holds the style definitions. -typeset -gA comptags - -(( ${+comptags[any]} )) || comptags[any]='*=100' - -typeset -gA override_tags +typeset -gA _compstyles # This can hold names of functions that are to be called after all # matches have been generated. @@ -378,243 +374,65 @@ compconf() { fi } -# Function to set tags and priorities. - -comptag() { - local i opt list tag val - - while getopts "lL" opt; do - if [[ "$opt" = l ]]; then - [[ -z "$list" ]] && list=yes - else - list=long - fi - done - shift OPTIND-1 - - if (( $# )); then - if [[ -n $list ]]; then - for i; do - if [[ $list = long ]]; then - (( ${+comptags[$i]} )) && print "comptag $i='$comptags[$i]'" - else - print $comptags[$i] - fi - done - else - for i; do - tag="${i%%([-+]|)\=*}" - val="${${i#*(|[-+])\=}#+}" - case "$i" in - *+\=*) - if [[ -n "$comptags[$tag]" ]]; then - comptags[$tag]="${val}:${comptags[$tag]}" - else - comptags[$tag]="$val" - fi - ;; - *\=+*) - if [[ -n "$comptags[$tag]" ]]; then - comptags[$tag]="${comptags[$tag]}:${val}" - else - comptags[$tag]="$val" - fi - ;; - *-\=*) - if [[ -n "$comptags[$tag]" ]]; then - comptags[$tag]="${${${comptags[$tag]//:${val}\=[^:]##}#${val}\=*:}%:${val}\=[^:]##}" - [[ "$comptags[$tag]" = ${val}\=* ]] && unset "comptags[$tag]" - fi - ;; - *\=*) - comptags[${i%%\=*}]="${i#*\=}" - ;; - *) - unset "compconfig[$i]" - ;; - esac - done - fi - else - for i in ${(ok)comptags}; do - if [[ $list = long ]]; then - print "comptag $i='$comptags[$i]'" - else - print ${(r:25:)i} "$comptags[$i]" - fi - done - fi -} - -# First suggested function for new configuration interface. +# Very simple interface for setting styles: # -# Example: +# compstyle context -styles... context -styles ... # -# conf1 \ -# argument = 1 \ -# value = 1 with describe \ -# option = 2 with describe and hide \ -# file = 3 \ -# path in '*dvi*' = 1 \ -# else = 2 \ -# glob = 1 \ -# job = never - -conf1() { - local tag pat prio - - while (( $# )); do +# Where context is of the form cmd-pat:ctxt-pat:tag-pat. +# +# This will be improved if needed. Promised. - tag="$1" - shift +compstyle() { + if (( ! $# )); then + local pat - while (( $# )); do + for pat in "${(@k)_compstyles}"; do + print -- "${(r:20:: :)pat} -- ${_compstyles[$pat]#??}" + done - if [[ "$1" = in ]]; then - pat="$2" - shift 2 - else - pat='*' - [[ "$1" = else ]] && shift - fi + return 0 + fi - style='' + local sep pat test + typeset -Z 2 num - if [[ "$1" = is ]]; then - prio=0 - style="[${2}]" - shift 2 - elif [[ "$1" = \= ]]; then - if [[ "$2" = n(o|ever) ]]; then - prio=-1 - shift 2 - else - prio="$2" - shift 2 - - if [[ "$1" = with ]]; then - while [[ "$1" = (with|and) ]]; do - style="${style},${2}" - shift 2 - done - style="[${style[2,-1]}]" - fi - fi - else - echo "$0: missing priority: $1" - return 1 - fi - if [[ -n "$comptags[$tag]" ]]; then - comptags[$tag]="${comptags[$tag]}:${pat}=${prio}${style}" - else - comptags[$tag]="${pat}=${prio}${style}" + while (( $# )); do + num=0 + for pat in "${(s:,:)1}"; do + if [[ "$pat" = \* ]]; then + (( num += 3 )) + elif [[ "$pat" = any ]]; then + (( num += 2 )) + elif [[ "$pat" != "$pat:q" ]]; then + (( num++ )) fi - - [[ "$1" = (in|else|\=) ]] || break - done - done - return 0 -} + pat="$1" + shift -# Second suggested function for new configuration interface. -# -# Example: -# -# conf2 \ -# for '*dvi*' do \ -# glob and path or \ -# file \ -# else do \ -# glob or \ -# path or \ -# file \ -# for '*p[bgpn]m*' do \ -# argument and option with describe and with hide \ -# else do \ -# argument or \ -# value with describe or \ -# option with describe \ -# for 'kill' do \ -# no job but \ -# process \ -# else do \ -# process and job - -conf2() { - local pat prio tag style + sep=$argv[(I)[^-]*] - while (( $# )); do - - if [[ "$1" = for ]]; then - pat="$2" - shift 2 - elif [[ "$1" = (else|always) ]]; then - pat="*" - shift + if (( sep )); then + _compstyles[$pat]="${num}${(j.:.)${(@)argv[1,sep-1]#-}}" + shift sep-1 else - echo "$0: missing context: $1" - return 1 + _compstyles[$pat]="${num}${(j.:.)${(@)argv#-}}" + break fi + done - shift 1 - - prio=1 - - while (( $# )); do - - if [[ "$1" = no ]]; then - while [[ "$1" != (but|for|else|always) ]]; do - if [[ -n "$comptags[$2]" ]]; then - comptags[$2]="${comptags[$2]}:${pat}=-1" - else - comptags[$2]="${pat}=-1" - fi - - shift 2 - done - - [[ "$1" != but ]] && break - - shift - fi - - while (( $# )); do - - tag="$1" - shift - - style='' - if [[ "$1" = with ]]; then - shift - while true; do - style="${style},${1}" - [[ "$2" != and || "$3" != with ]] && break - shift 3 - done - shift - fi - - [[ -n "$style" ]] && style="[${style[2,-1]}]" - - if [[ -n "$comptags[$tag]" ]]; then - comptags[$tag]="${comptags[$tag]}:${pat}=${prio}${style}" - else - comptags[$tag]="${pat}=${prio}${style}" - fi + return 0 +} - [[ "$1" != and ]] && break +# Default styles. - shift - done +compstyle '*,*,*' -description=yes -prefix-needed=yes -prefix-hidden=no - [[ "$1" != or ]] && break +# Helper function for `_tags'. Will be moved into C-code. - (( prio++ )) - shift - done - done +comptry() { + _tags=( "$_tags[@]" ":${(j.:.)argv}:" ) } # Utility function to call a function if it exists. -- cgit 1.4.1