From 346825df86466cf151be61b9429ef2c1734e66ea Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Sun, 27 Jun 1999 05:33:04 +0000 Subject: zsh-3.1.5-pws-24 --- Completion/Core/_approximate | 4 +- Completion/Core/_expand | 2 +- Completion/Core/_list | 2 +- Completion/Core/_match | 20 +++++++- Completion/Core/_path_files | 16 +++++-- Completion/Core/compdump | 17 ++++--- Completion/Core/compinit | 108 +++++++++++++++---------------------------- Completion/Core/compinstall | 56 +++++++++------------- 8 files changed, 100 insertions(+), 125 deletions(-) (limited to 'Completion/Core') diff --git a/Completion/Core/_approximate b/Completion/Core/_approximate index c63416901..61f21c5b9 100644 --- a/Completion/Core/_approximate +++ b/Completion/Core/_approximate @@ -89,14 +89,14 @@ fi # Get the number of errors to accept. -if [[ "$cfgacc" = *[nN]* && NUMERIC -ne 1 ]]; then +if [[ "$cfgacc" = *[nN]* && ${NUMERIC:-1} -ne 1 ]]; then # Stop if we also have a `!'. [[ "$cfgacc" = *\!* ]] && return 1 # Prefer the numeric argument if that has a sensible value. - comax="$NUMERIC" + comax="${NUMERIC:-1}" else comax="${cfgacc//[^0-9]}" fi diff --git a/Completion/Core/_expand b/Completion/Core/_expand index aca3839d4..58e184657 100644 --- a/Completion/Core/_expand +++ b/Completion/Core/_expand @@ -17,7 +17,7 @@ # In this case, expansion of substitutions will be done if the # expression evaluates to `1'. For example, with # -# compconf expand_substitute='NUMERIC != 1' +# compconf expand_substitute='${NUMERIC:-1} != 1' # # substitution will be performed only if given an explicit numeric # argument other than `1', as by typing ESC 2 TAB. diff --git a/Completion/Core/_list b/Completion/Core/_list index 0d5651c23..28a5161d1 100644 --- a/Completion/Core/_list +++ b/Completion/Core/_list @@ -14,7 +14,7 @@ # will be done if the expression evaluates to `1'. # For example, with # -# compconf list_condition='NUMERIC != 1' +# compconf list_condition='${NUMERIC:-1} != 1' # # delaying will be done only if given an explicit numeric argument # other than `1'. diff --git a/Completion/Core/_match b/Completion/Core/_match index 3c639935c..251c65381 100644 --- a/Completion/Core/_match +++ b/Completion/Core/_match @@ -9,7 +9,7 @@ # expand-or-complete function because otherwise the pattern will # be expanded using globbing. # -# Configuration key used: +# Configuration keys used: # # match_original # If this is set to a `only', pattern matching will only be tried @@ -18,6 +18,11 @@ # no completions, matching will be tried again with a `*' inserted # at the cursor position. If this key is not set or set to an empty # string, matching will only be attempted with the `*' inserted. +# +# match_insert +# If this is set to a string starting with `unambig', menucompletion +# will only be turned on if no unambiguous string could be built +# that is at least as long as the original string. local tmp opm="$compstate[pattern_match]" ret=0 @@ -37,7 +42,12 @@ if [[ -n "$compconfig[match_original]" ]]; then compstate[pattern_match]="$opm" compstate[matcher]="$compstate[total_matchers]" - (( ret )) && return 0 + if (( ret )); then + [[ "$compconfig[match_insert]" = unambig* && + $#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] && + compstate[pattern_insert]=unambiguous + return 0 + fi fi # No completion with inserting `*'? @@ -50,4 +60,10 @@ _complete && ret=1 compstate[pattern_match]="$opm" compstate[matcher]="$compstate[total_matchers]" +if (( ! ret )); then + [[ "$compconfig[match_insert]" = unambig* && + $#compstate[unambiguous] -ge ${#:-${PREFIX}${SUFFIX}} ]] && + compstate[pattern_insert]=unambiguous +fi + return 1-ret diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index d0d1c6a0a..58f343367 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -11,12 +11,17 @@ # with one of the suffixes thus given are treated like files with one # of the suffixes in the `fignore' array in normal completion. # -# This function supports one configuration key: +# This function supports two configuration keys: # # path_expand # If this is set to a non-empty string, the partially typed path # from the line will be expanded as far as possible even if trailing # pathname components can not be completed. +# +# path_cursor +# If this is set to an non-empty string, the cursor will be placed +# in the path after the ambiguous pathname component even when using +# menucompletion. local linepath realpath donepath prepath testpath exppath local tmp1 tmp2 tmp3 tmp4 i orig pre suf tpre tsuf @@ -304,10 +309,11 @@ for prepath in "$prepaths[@]"; do # it as far as possible. if [[ -n $menu ]]; then + [[ -n "$compconfig[path_cursor]" ]] && compstate[to_end]='' if [[ "$tmp3" = */* ]]; then compadd -Uf -p "$linepath$testpath" -s "/${tmp3#*/}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ - "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \ + "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" -M 'r:|/=* r:|=*' \ "$group[@]" "$expl[@]" -i "$IPREFIX" -I "$ISUFFIX" \ - "${(@)tmp1%%/*}" else @@ -371,9 +377,9 @@ done exppaths=( "${(@)exppaths:#$orig}" ) if [[ -n "$compconfig[path_expand]" && - $#exppaths -ne 0 && nm -eq compstate[nmatches] ]]; then - compadd -U -S '' "$group[@]" "$expl[@]" -i "$IPREFIX" -I "$ISUFFIX" \ - -p "$linepath" - "${(@)exppaths}" + $#exppaths -eq 0 && nm -eq compstate[nmatches] ]]; then + compadd -QU -S '' "$group[@]" "$expl[@]" -i "$IPREFIX" -I "$ISUFFIX" \ + -M 'r:|/=* r:|=*' -p "$linepath" - "${(@)exppaths}" fi [[ nm -eq compstate[nmatches] ]] diff --git a/Completion/Core/compdump b/Completion/Core/compdump index 5ee04e028..f2729acc5 100644 --- a/Completion/Core/compdump +++ b/Completion/Core/compdump @@ -1,4 +1,4 @@ -# This is a file to be sourced to dump the definitions for new-style +# This is a function to dump the definitions for new-style # completion defined by 'compinit' in the same directory. The output # should be directed into the "compinit.dump" in the same directory as # compinit. If you rename init, just stick .dump onto the end of whatever @@ -9,12 +9,14 @@ # To do this, simply remove the .dump file, start a new shell, and # create the .dump file as before. Again, compinit -d handles this # automatically. -# -# It relies on KSH_ARRAYS not being set. # Print the number of files used for completion. This is used in compinit # to see if auto-dump should re-dump the dump-file. +emulate -L zsh + +typeset _d_file _d_f _d_bks _d_line _d_als + _d_file=${compconfig[dumpfile]-${0:h}/compinit.dump} typeset -U _d_files @@ -22,8 +24,6 @@ _d_files=( ${^~fpath}/_(|*[^~])(N:t) ) print "#files: $#_d_files" > $_d_file -unset _d_files - # First dump the arrays _comps and _patcomps. The quoting hieroglyphyics # ensure that a single quote inside a variable is itself correctly quoted. @@ -44,11 +44,13 @@ print >> $_d_file # Now dump the key bindings. We dump all bindings for zle widgets # whose names start with a underscore. # We need both the zle -C's and the bindkey's to recreate. +# We can ignore any zle -C which rebinds a standard widget (second +# argument to zle does not begin with a `_'). _d_bks=() zle -lL | while read -rA _d_line; do - if [[ ${_d_line[5]} = _* ]]; then + if [[ ${_d_line[3]} = _* && ${_d_line[5]} = _* ]]; then print -r - ${_d_line} _d_bks=($_d_bks ${_d_line[3]}) fi @@ -86,4 +88,5 @@ done >> $_d_file print >> $_d_file -unset _d_line _d_zle _d_bks _d_als _d_f _f_file +unfunction compdump +autoload -U compdump diff --git a/Completion/Core/compinit b/Completion/Core/compinit index 23bc94cf9..e078cc33c 100644 --- a/Completion/Core/compinit +++ b/Completion/Core/compinit @@ -41,15 +41,13 @@ # See the file `compdump' for how to speed up initialisation. # If we got the `-d'-flag, we will automatically dump the new state (at -# the end). -# `-f dir' is used to pass down the directory where this file was -# found. This is necessary if functionargzero is not set. -# If we were given an argument, this will be taken as the name of the -# file in which to store the dump. - -_i_fdir='' -_i_dumpfile='' -_i_autodump=0 +# the end). This takes the dumpfile as an argument. + +emulate -L zsh + +typeset _i_dumpfile _i_files _i_line _i_done _i_dir _i_autodump=0 +typeset _i_tag _i_file + while [[ $# -gt 0 && $1 = -[df] ]]; do if [[ "$1" = -d ]]; then _i_autodump=1 @@ -59,56 +57,27 @@ while [[ $# -gt 0 && $1 = -[df] ]]; do shift fi elif [[ "$1" = -f ]]; then - # Used by compinstall to pass down directory where compinit was found + # Not used any more; use _compdir shift - _i_fdir="$1" shift fi done -# Get the directory if we don't have it already and we can -if [[ -z "$_i_fdir" && -o functionargzero && $0 = */* ]]; then - _i_fdir=${0:h} -fi # The associative array containing the definitions for the commands. # Definitions for patterns will be stored in the normal array `_patcomps'. -typeset -A _comps +typeset -gA _comps _patcomps=() # This is the associative array used for configuration. -typeset -A compconfig +typeset -gA compconfig # Standard initialisation for `compconfig'. if [[ -n $_i_dumpfile ]]; then # Explicitly supplied dumpfile. compconfig[dumpfile]="$_i_dumpfile" -elif [[ -o functionargzero ]]; then - # We can deduce it from the name of this script - compconfig[dumpfile]="$0.dump" -elif [[ -n $_i_fdir ]]; then - # We were told what directory to use. - compconfig[dumpfile]="$_i_fdir/compinit.dump" else - compconfig[dumpfile]='' -fi - -if [[ -n $compconfig[dumpfile] ]]; then - # Check the file is writeable. If it doesn't exist, the - # only safe way is to try and create it. - if [[ -f $compconfig[dumpfile] ]]; then - [[ -w $compconfig[dumpfile] ]] || compconfig[dumpfile]='' - elif touch $compconfig[dumpfile] >& /dev/null; then - rm -f $compconfig[dumpfile] - else - compconfig[dumpfile]='' - fi -fi - -if [[ -z $compconfig[dumpfile] ]]; then - # If no dumpfile given, or it was not writeable, then use - # user's ZDOTDIR. compconfig[dumpfile]="${ZDOTDIR:-$HOME}/.zcompdump" fi @@ -215,7 +184,11 @@ compdef() { fi # Define the widget. - zle -C "$func" "$1" "$func" + if [[ $1 = .* ]]; then + zle -C "$func" "$1" "$func" + else + zle -C "$func" ".$1" "$func" + fi shift # And bind the keys... @@ -321,22 +294,32 @@ _i_files=( ${^~fpath:/.}/_(|*[^~])(N:t) ) if [[ $#_i_files -lt 20 ]]; then # Too few files: we need some more directories # Assume that we need to add the compinit directory to fpath. - if [[ -n $_i_fdir ]]; then - if [[ $_i_fdir = */Core ]]; then + if [[ -n $_compdir ]]; then + if [[ $_compdir = */Core ]]; then # Add all the Completion subdirectories - fpath=(${_i_fdir:h}/*(/) $fpath) - elif [[ -d $_i_fdir/Core ]]; then + fpath=(${_compdir:h}/*(/) $fpath) + elif [[ -d $_compdir/Core ]]; then # Likewise - fpath=(${_i_fdir}/*(/) $fpath) - else - fpath=($_i_fdir $fpath) + fpath=(${_compdir}/*(/) $fpath) fi _i_files=( ${^~fpath:/.}/_(|*[^~])(N:t) ) fi fi + +# Rebind the standard widgets +for _i_line in complete-word delete-char-or-list expand-or-complete \ + expand-or-complete-prefix list-choices menu-complete \ + menu-expand-or-complete reverse-menu-complete; do + zle -C $_i_line .$_i_line _main_complete +done +zle -la menu-select && zle -C menu-select .menu-select _main_complete + _i_done='' +# Make sure compdump is available, even if we aren't going to use it. +autoload -U compdump compinstall + # If we have a dump file, load it. if [[ -f "$compconfig[dumpfile]" ]]; then @@ -345,7 +328,6 @@ if [[ -f "$compconfig[dumpfile]" ]]; then builtin . "$compconfig[dumpfile]" _i_done=yes fi - unset _i_line fi if [[ -z "$_i_done" ]]; then for _i_dir in $fpath; do @@ -369,30 +351,12 @@ if [[ -z "$_i_done" ]]; then done done - bindkey | - while read -rA _i_line; do - case "$_i_line[2]" in - (complete-word) ;& - (delete-char-or-list) ;& - (expand-or-complete) ;& - (expand-or-complete-prefix) ;& - (list-choices) ;& - (menu-complete) ;& - (menu-expand-or-complete) ;& - (reverse-menu-complete) - zle -C _complete_$_i_line[2] $_i_line[2] _main_complete - bindkey "${_i_line[1][2,-2]}" _complete_$_i_line[2] - ;; - esac - done - - unset _i_dir _i_line _i_file _i_tag - # If autodumping was requested, do it now. - if [[ -n ${_i_fdir} && $_i_autodump = 1 ]]; then - builtin . ${_i_fdir}/compdump + if [[ $_i_autodump = 1 ]]; then + compdump fi fi -unset _i_files _i_initname _i_done _i_autodump _i_fdir _i_dumpfile +unfunction compinit +autoload -U compinit diff --git a/Completion/Core/compinstall b/Completion/Core/compinstall index 5086cc7d2..255565b3f 100644 --- a/Completion/Core/compinstall +++ b/Completion/Core/compinstall @@ -3,7 +3,7 @@ # available in some directory; they should have been installed with the # the shell (except we haven't written that yet). # -# Source this script (e.g. `. /path/compinstall') and answer the questions. +# Run this script as a function and answer the questions. # # Normally, this will alter ~/.zshrc (or wherever ZDOTDIR puts it), but you # can make that unwritable and it will leave the lines in a temporary file @@ -23,33 +23,13 @@ # - Could add code for setting other completers and options. # - Could add keys for context-sensitive help. -# Save the options. We will need to trap ^C to make sure they get -# restored properly. -typeset -A _ci_options -_ci_options=($(setopt kshoptionprint;setopt)) -[[ -o kshoptionprint ]] || _ci_options[kshoptionprint]=off -[[ -o monitor ]] && _ci_options[monitor]=on -[[ -o zle ]] && _ci_options[zle]=on - -emulate zsh - -TRAPINT() { - unsetopt ${(k)_ci_options[(R)off]} - setopt ${(k)_ci_options[(R)on]} - - unset _ci_options _ci_f _ci_fdir _ci_files _ci_dumpfile _ci_lines - unset _ci_type _ci_completer _ci_accept _ci_cprompt _ci_startline - unset _ci_endline _ci_ifile _ci_tmpf _ci_defaults _ci_compconf _ci_warn - unset _ci_dtype _ci_existing _ci_line - - if (( $1 )); then - print Aborted. - unfunction TRAPINT - return 1 - fi - return 0 -} +emulate -L zsh + +typeset _ci_options _ci_f _ci_fdir _ci_files _ci_dumpfile _ci_lines +typeset _ci_type _ci_completer _ci_accept _ci_cprompt _ci_startline +typeset _ci_endline _ci_ifile _ci_tmpf _ci_compconf _ci_warn +typeset _ci_dtype _ci_existing _ci_line # Look for the defaults. _ci_startline='# The following lines were added by compinstall' @@ -60,6 +40,7 @@ _ci_lines='' _ci_existing='' typeset -A _ci_defaults + if [[ -f $_ci_ifile ]]; then # This assumes the lines haven't been altered by the user too much # after they were added. @@ -83,10 +64,12 @@ if [[ -f $_ci_ifile ]]; then fi _ci_existing="${_ci_existing} $_ci_line " - elif [[ $_ci_line[1] = . && $_ci_line[2] = */compinit ]]; then - # parse the line sourcing compinit - [[ $_ci_line[3] = -f ]] && _ci_fdir=$_ci_line[4] + elif [[ $_ci_line[1] = compinit ]]; then + # parse the line running compinit + [[ $_ci_line[2] = -f ]] && _ci_fdir=$_ci_line[3] [[ $_ci_line[-2] = -d ]] && _ci_dumpfile=$_ci_line[-1] + elif [[ $_ci_line[1] = _compdir=* ]]; then + _ci_fdir=${_ci_line[1]##_compdir=} elif [[ $_ci_line[1] = compconf ]]; then # parse a compconf component as second argument (should be completer) [[ $_ci_line[2] = completer=* ]] && @@ -94,7 +77,7 @@ if [[ -f $_ci_ifile ]]; then [[ $_ci_line[-1] == \\ ]] && _ci_compconf=1 _ci_existing="${_ci_existing}$_ci_line " - elif [[ $_ci_line[1] != \#* ]]; then + elif [[ $_ci_line[1] != \#* && $_ci_line[1] != (autoload|\[\[) ]]; then if [[ -z $_ci_warn ]]; then _ci_warn=1 print "Warning: existing lines in compinstall setup not understood:" @@ -166,7 +149,7 @@ fi # Set up the dumpfile _ci_dtype=existing if [[ -z $_ci_dumpfile ]]; then - _ci_dumpfile="${_ci_fdir}/compinit.dump" + _ci_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump" _ci_dtype=standard fi @@ -184,7 +167,6 @@ else I will force completion to dump its status, which will speed up the shell's start-up considerably. However, I can't write the file I'd like to, namely ${_ci_dumpfile}. Please edit a replacement." - _ci_dumpfile='~/.compinit.dump' vared _ci_dumpfile while ! touch ${~_ci_dumpfile} >& /dev/null; do print "Sorry, I can't write that either. Try again." @@ -193,7 +175,10 @@ ${_ci_dumpfile}. Please edit a replacement." [[ -s $_ci_dumpfile ]] || rm -f $_ci_dumpfile fi -_ci_lines="${_ci_lines}. $_ci_fdir/compinit -f $_ci_fdir -d" +_ci_lines="${_ci_lines}_compdir=$_ci_fdir +[[ -z \$fpath[(r)\$_compdir] ]] && fpath=(\$_compdir \$fpath) +autoload -U compinit +compinit -d" [[ $_ci_dtype != standard ]] && _ci_lines="${_ci_lines} $_ci_dumpfile" _ci_lines="${_ci_lines} " @@ -363,6 +348,7 @@ $_ci_lines$_ci_endline" >>$_ci_ifile && print "\nSuccessfully appended lines to $_ci_ifile." fi -TRAPINT 0 +unfunction compinstall +autoload -U compinstall return 0 -- cgit 1.4.1