about summary refs log tree commit diff
path: root/Completion/Commands
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>2000-03-13 10:26:17 +0000
committerTanaka Akira <akr@users.sourceforge.net>2000-03-13 10:26:17 +0000
commit8b53e5de541bcdb93502acc31177755082e513b5 (patch)
tree28285bd4caf42a47f7fc4c10c8966aac657acdc3 /Completion/Commands
parent963043760fdda262131532a724f0d6b1606888d5 (diff)
downloadzsh-8b53e5de541bcdb93502acc31177755082e513b5.tar.gz
zsh-8b53e5de541bcdb93502acc31177755082e513b5.tar.xz
zsh-8b53e5de541bcdb93502acc31177755082e513b5.zip
zsh-workers/10108
Diffstat (limited to 'Completion/Commands')
-rw-r--r--Completion/Commands/.distfiles1
-rw-r--r--Completion/Commands/_next_tags70
2 files changed, 71 insertions, 0 deletions
diff --git a/Completion/Commands/.distfiles b/Completion/Commands/.distfiles
index 804e65be3..45378a009 100644
--- a/Completion/Commands/.distfiles
+++ b/Completion/Commands/.distfiles
@@ -2,4 +2,5 @@ DISTFILES_SRC='
     .distfiles
     _bash_completions _correct_filename _correct_word _expand_word 
     _history_complete_word _read_comp _most_recent_file _complete_help
+    _next_tags
 '
diff --git a/Completion/Commands/_next_tags b/Completion/Commands/_next_tags
new file mode 100644
index 000000000..8bd3f5921
--- /dev/null
+++ b/Completion/Commands/_next_tags
@@ -0,0 +1,70 @@
+#compdef -k complete-word \C-xn
+
+# Main widget/completer.
+
+_next_tags() {
+
+  if [[ $#funcstack -gt 1 ]]; then
+
+    # 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.
+
+    [[ $_next_tags_pre != ${LBUFFER%${PREFIX}} ]] && unset _sort_tags
+
+    return 1
+  else
+    local comp
+
+    if [[ -z $compstate[old_list] ]]; then
+      comp=()
+    else
+      comp=(_next_tags _complete)
+    fi
+
+    (( $+_sort_tags )) || _next_tags_not=
+
+    _sort_tags=_next_tags_sort
+    _next_tags_pre="${LBUFFER%${PREFIX}}"
+    _next_tags_not="$_next_tags_not $_lastcomp[tags]"
+
+    _main_complete "$comp[@]"
+
+    [[ $compstate[insert] = automenu ]] &&
+       compstate[insert]=automenu-unambiguous
+
+    compstate[insert]=''
+    compstate[list]='list force'
+  fi
+}
+
+# Helper function for sorting tags. Most of this is copied from _tags.
+
+_next_tags_sort() {
+  local order tags tag nodef
+
+  zstyle -a ":completion:${curcontext}:" tag-order order ||
+    order=( 'arguments values' options globbed-files directories all-files )
+
+  # But we also remove the tags we've already tried...
+
+  tags=( "${(@)order:#(${(j:|:)~${=_next_tags_not}})}" )
+
+  # ... unless that would remove all offered tags.
+
+  [[ $#tags -ne $#order && "$tags" != *(${(j:|:)~argv})* ]] &&
+    tags=( $order ) _next_tags_not=
+
+  for tag in $tags; do
+    case $tag in
+    -)     nodef=yes;;
+    *\(\)) "${${tag%%[ 	]#\(\)}##[ 	]#}" "$@";;
+    \!*)   comptry "${(@)argv:#(${(j:|:)~${=tag[2,-1]}})}";;
+    ?*)    comptry ${=tag};;
+    esac
+  done
+
+  [[ -z "$nodef" ]] && comptry "$@"
+}
+
+[[ -o kshautoload ]] || _next_tags "$@"