From d658d3e2bb1cdde7a58b244fac67a539f4c1cbad Mon Sep 17 00:00:00 2001 From: Sven Wischnowsky Date: Tue, 16 May 2000 11:44:57 +0000 Subject: fixed configuration of menu-selection with menu style; pseudo-context `-command-line-', handy for completion in vared (11408) --- ChangeLog | 5 ++ Completion/Core/_main_complete | 10 ++-- Completion/Core/_normal | 116 ++++++++++++++++++++++++++++++----------- Doc/Zsh/compsys.yo | 6 ++- 4 files changed, 103 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 96ba287d7..aef560ddd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2000-05-16 Sven Wischnowsky + * 11408: Completion/Core/_main_complete, Completion/Core/_normal, + Doc/Zsh/compsys.yo: fixed configuration of menu-selection with + menu style; pseudo-context `-command-line-', handy for completion + in vared + * 11407: Completion/Base/_tilde, Completion/Core/_path_files: avoid tilde- and parameter-completion in quotes diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index 34566d2d4..be96ce6f2 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -168,9 +168,11 @@ if [[ $compstate[old_list] = keep || nm -gt 1 ]]; then if [[ "$compstate[insert]" = *menu* ]]; then if [[ -n "$_menu_style[(r)no-select*]" ]]; then unset MENUSELECT - elif [[ -n "$_menu_style[(r)select=long*]" && tmp -gt LINES ]]; then - zmodload -i zsh/complist - MENUSELECT=0 + elif [[ -n "$_menu_style[(r)select=long*]" ]]; then + if [[ tmp -gt LINES ]]; then + zmodload -i zsh/complist + MENUSELECT=0 + fi else sel=( "${(@M)_menu_style:#select*}" ) @@ -191,6 +193,8 @@ if [[ $compstate[old_list] = keep || nm -gt 1 ]]; then zmodload -i zsh/complist MENUSELECT="$min" + else + unset MENUSELECT fi fi fi diff --git a/Completion/Core/_normal b/Completion/Core/_normal index 19da6d79b..52f0bb352 100644 --- a/Completion/Core/_normal +++ b/Completion/Core/_normal @@ -1,54 +1,110 @@ -#autoload +#compdef -command-line- -local comp cmd1 cmd2 pat val name +local comp command cmd1 cmd2 pat val name i ret=1 _compskip="$_compskip" +local curcontext="$curcontext" + +# If we get the option `-s', we don't reset `_compskip'. This ensures +# that a value set in the function for the `-first-' context is kept, +# but that we still use pattern functions when we were called form +# another completion function. + +[[ "$1" = -s ]] || _compskip='' # Completing in command position? If not we set up `cmd1' and `cmd2' as -# two strings we have search in the completion definition arrays (e.g. +# two strings we have to search in the completion definition arrays (e.g. # a path and the last path name component). -if [[ $CONTEXT == command ]]; then +command="$words[1]" +if [[ CURRENT -eq 1 ]]; then + curcontext="${curcontext%:*:*}:-command-:" + comp="$_comps[-command-]" - [[ -z "$comp" ]] || "$comp" "$@" - return -elif [[ "$COMMAND[1]" == '=' ]]; then - eval cmd1\=$COMMAND - cmd2="$COMMAND[2,-1]" -elif [[ "$COMMAND" == */* ]]; then - cmd1="$COMMAND" - cmd2="${COMMAND:t}" + [[ -z "$comp" ]] || "$comp" && ret=0 + + return ret else - cmd1="$COMMAND" - eval cmd2=$(whence -p $COMMAND) + if [[ "$command[1]" == '=' ]]; then + eval cmd1\=$command + cmd2="$command[2,-1]" + curcontext="${curcontext%:*:*}:${cmd2}:" + elif [[ "$command" == */* ]]; then + cmd1="$command" + cmd2="${command:t}" + curcontext="${curcontext%:*:*}:${cmd2}:" + else + cmd1="$command" + cmd2="$commands[$command]" + curcontext="${curcontext%:*:*}:${cmd1}:" + fi 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" "$@" - if (( $+_compskip )); then - unset _compskip - return +if [[ "$_compskip" != (all|*patterns*) ]]; then + for i in "${(@)_patcomps[(K)$cmd1]}"; do + "$i" && ret=0 + if [[ "$_compskip" = *patterns* ]]; then + break + elif [[ "$_compskip" = all ]]; then + _compskip='' + return ret fi - fi -done + done + for i in "${(@)_patcomps[(K)$cmd2]}"; do + "$i" && ret=0 + if [[ "$_compskip" = *patterns* ]]; then + break + elif [[ "$_compskip" = all ]]; then + _compskip='' + return ret + fi + done +fi # Now look up the two names in the normal completion array. name="$cmd1" comp="$_comps[$cmd1]" -if [[ -z "$comp" ]]; then - name="$cmd2" - comp="$_comps[$cmd2]" -fi +[[ -z "$comp" ]] && name="$cmd2" comp="$_comps[$cmd2]" # And generate the matches, probably using default completion. -if [[ -z "$comp" ]]; then +if [[ -n "$comp" ]]; then + _compskip=patterns + "$comp" && ret=0 + [[ "$_compskip" = (all|*patterns*) ]] && return ret +elif [[ "$_compskip" != *default* ]]; then name=-default- comp="$_comps[-default-]" fi -[[ -z "$comp" ]] || "$comp" "$@" + +if [[ "$_compskip" != (all|*patterns*) ]]; then + for i in "${(@)_postpatcomps[(K)$cmd1]}"; do + _compskip=default + "$i" && ret=0 + if [[ "$_compskip" = *patterns* ]]; then + break + elif [[ "$_compskip" = all ]]; then + _compskip='' + return ret + fi + done + for i in "${(@)_postpatcomps[(K)$cmd2]}"; do + _compskip=default + "$i" && ret=0 + if [[ "$_compskip" = *patterns* ]]; then + break + elif [[ "$_compskip" = all ]]; then + _compskip='' + return ret + fi + done +fi + +[[ "$name" = -default- && -n "$comp" && "$_compskip" != (all|*default*) ]] && + "$comp" && ret=0 + +_compskip='' + +return ret diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 45bae9f0d..e6f7bf8b3 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -2096,7 +2096,11 @@ named `tt(_tilde)'). Before trying to find a function for a specific context, tt(_complete) checks if the parameter `tt(compcontext)' is set to a non-empty value. If it is, the value is taken as the name of the context to use -and the function defined for that context will be called. +and the function defined for that context will be called. For this +purpose, there is a special context named tt(-command-line-) that +completes whole command lines (commands and their arguments) and is +not used by the completion system itself, but has a function handling +completion for it. ) findex(_approximate) item(tt(_approximate))( -- cgit 1.4.1