about summary refs log tree commit diff
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-03-23 23:59:08 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-03-23 23:59:08 +0000
commit993db7cf0267b4d9c7f8faaa40af8948ba26a2e2 (patch)
treea7124bd5d1ce193f582e10873b229cc0b3214507
parent2b38f6f4e5b78c26ae617dfe6974a2de98d1e455 (diff)
downloadzsh-993db7cf0267b4d9c7f8faaa40af8948ba26a2e2.tar.gz
zsh-993db7cf0267b4d9c7f8faaa40af8948ba26a2e2.tar.xz
zsh-993db7cf0267b4d9c7f8faaa40af8948ba26a2e2.zip
zsh-workers/10210
-rw-r--r--Completion/Commands/_next_tags62
-rw-r--r--Completion/Core/_main_complete17
-rw-r--r--Completion/Core/compinit3
-rw-r--r--Doc/Zsh/compsys.yo14
4 files changed, 52 insertions, 44 deletions
diff --git a/Completion/Commands/_next_tags b/Completion/Commands/_next_tags
index 818b73fe0..028ba4d61 100644
--- a/Completion/Commands/_next_tags
+++ b/Completion/Commands/_next_tags
@@ -1,49 +1,45 @@
-#autoload
+#compdef -k complete-word \C-xn
 
-# To use this, put _next_tags at the beginning of the completer style,
-# define it as a completion widget and bind it to a key, e.g.:
-#
-#  zle -C _next_tags complete-word _next_tags
-#  bindkey '^Xn' _next_tags
-#
-# Makes it be bound to ^Xn.
-
-
-# Main widget/completer.
+# Main widget.
 
 _next_tags() {
+  local comp
 
-  if [[ $#funcstack -gt 1 ]]; then
+  if [[ -z $compstate[old_list] ]]; then
+    comp=()
+  else
+    comp=(_complete)
+  fi
 
-    # Called as completer, probably `remove' our helper function. A better
-    # test would be nice, but I think one should still be able to edit the
-    # current word between attempts to complete it.
+  (( $+_sort_tags )) || _next_tags_not=
 
-    [[ $_next_tags_pre != ${LBUFFER%${PREFIX}} ]] && unset _sort_tags
+  _sort_tags=_next_tags_sort
+  _next_tags_pre="${LBUFFER%${PREFIX}}"
+  _next_tags_not="$_next_tags_not $_lastcomp[tags]"
 
-    return 1
-  else
-    local comp
+  _main_complete "$comp[@]"
 
-    if [[ -z $compstate[old_list] ]]; then
-      comp=()
-    else
-      comp=(_next_tags _complete)
-    fi
+  [[ $compstate[insert] = automenu ]] &&
+     compstate[insert]=automenu-unambiguous
 
-    (( $+_sort_tags )) || _next_tags_not=
+  compstate[insert]=''
+  compstate[list]='list force'
 
-    _sort_tags=_next_tags_sort
-    _next_tags_pre="${LBUFFER%${PREFIX}}"
-    _next_tags_not="$_next_tags_not $_lastcomp[tags]"
+  compprefuncs=( "$compprefuncs[@]" _next_tags_pre )
+}
 
-    _main_complete "$comp[@]"
+# Pre-completion function.
 
-    [[ $compstate[insert] = automenu ]] &&
-       compstate[insert]=automenu-unambiguous
+_next_tags_pre() {
 
-    compstate[insert]=''
-    compstate[list]='list force'
+  # Probably `remove' our sort function. A better test would be nice, but
+  # I think one should still be able to edit the current word between
+  # attempts to complete it.
+
+  if [[ $_next_tags_pre != ${LBUFFER%${PREFIX}} ]]; then
+    unset _sort_tags
+  else
+    compprefuncs=( "$compprefuncs[@]" _next_tags_pre )
   fi
 }
 
diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete
index fedea9b51..244f06b7e 100644
--- a/Completion/Core/_main_complete
+++ b/Completion/Core/_main_complete
@@ -19,7 +19,7 @@
 setopt localoptions nullglob rcexpandparam extendedglob
 unsetopt markdirs globsubst shwordsplit nounset ksharrays
 
-local ctxt post ret=1 tmp _compskip format _comp_ignore \
+local ctxt func funcs ret=1 tmp _compskip format _comp_ignore \
       _completers _completer _completer_num curtag \
       _matchers _matcher _matcher_num _comp_tags \
       context state line opt_args val_args curcontext="$curcontext" \
@@ -68,6 +68,14 @@ _last_menu_style=()
 _completers=( "$@" )
 _completer_num=1
 
+# Call the pre-functions.
+
+funcs=( "$compprefuncs[@]" )
+compprefuncs=()
+for func in "$funcs[@]"; do
+  "$func"
+done
+
 for _completer; do
   ctxt=":completion:${curcontext/::/:${_completer[2,-1]}-${(M)#_completers[1,_completer_num]:#$_completer}:}:"
 
@@ -190,10 +198,11 @@ fi
 
 # Now call the post-functions.
 
-for post in "$comppostfuncs[@]"; do
-  "$post"
-done
+funcs=( "$comppostfuncs[@]" )
 comppostfuncs=()
+for func in "$funcs[@]"; do
+  "$func"
+done
 
 _lastcomp=( "${(@kv)compstate}" )
 _lastcomp[completer]="$_completer"
diff --git a/Completion/Core/compinit b/Completion/Core/compinit
index a421c2d8d..014729e90 100644
--- a/Completion/Core/compinit
+++ b/Completion/Core/compinit
@@ -98,9 +98,10 @@ else
   _comp_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump"
 fi
 
-# This can hold names of functions that are to be called after all
+# These can hold names of functions that are to be called before/after all
 # matches have been generated.
 
+compprefuncs=()
 comppostfuncs=()
 
 # Loading it now ensures that the `funcstack' parameter is always correct.
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 1fc57de86..79ad8df50 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -1581,12 +1581,6 @@ value of the completer functions to decide if other completers should be
 called. If the return value is zero, no other completers are tried and the
 tt(_main_complete) function returns.
 
-Immediately before returning the tt(_main_complete) function calls all
-functions whose names are given in the tt(comppostfuncs) array and
-then resets it to an empty array. This can be used by completion
-functions or by other ZLE widgets calling completion to register code
-that is to be executed after all matches have been added.
-
 The following completer functions are contained in the distribution (users
 may write their own):
 
@@ -1980,6 +1974,14 @@ generating matches all follow the convention of returning zero if they
 generated completions and non-zero if no matching completions could be 
 added.
 
+When writing completion functions or other ZLE widgets that call
+completion, it might be interesting to know about two more features
+offered by the tt(_main_complete) function. The arrays
+tt(compprefuncs) and tt(comppostfuncs) may be set to contain names of
+functions that are to be called immediately before or after completion 
+has been tried. The functions will only be called once, unless they
+put themselves into the array again.
+
 startitem()
 findex(_funcall)
 item(tt(_funcall) var(return) var(name) [ var(args) ... ])(