diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Completion/Commands/.distfiles | 2 | ||||
-rw-r--r-- | Completion/Commands/_complete_tag | 57 | ||||
-rw-r--r-- | Doc/Zsh/compsys.yo | 12 |
4 files changed, 76 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog index 085a0afd2..aa222bf0d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2000-05-23 Peter Stephenson <pws@cambridgesiliconradio.com> + + * 11537: Completion/Command/_complete_tag, + Completion/Command/.distfiles, Doc/Zsh/compsys.yo: new + _complete_tag function. + 2000-05-23 Sven Wischnowsky <wischnow@zsh.org> * 11536: Doc/Zsh/mod_zutil.yo: doc clarifications for zparseopts diff --git a/Completion/Commands/.distfiles b/Completion/Commands/.distfiles index 139c9e514..dc4355785 100644 --- a/Completion/Commands/.distfiles +++ b/Completion/Commands/.distfiles @@ -2,5 +2,5 @@ DISTFILES_SRC=' .distfiles _bash_completions _complete_debug _correct_filename _correct_word _expand_word _history_complete_word _read_comp _most_recent_file - _complete_help _next_tags + _complete_help _next_tags _complete_tag ' diff --git a/Completion/Commands/_complete_tag b/Completion/Commands/_complete_tag new file mode 100644 index 000000000..4470a2ad4 --- /dev/null +++ b/Completion/Commands/_complete_tag @@ -0,0 +1,57 @@ +#compdef -k complete-word \C-xt + +# Complete tags using either TAGS or tags. Looks up your directory +# hierarchy to find one. If both exist, uses TAGS. +# +# You can override the choice of tags file with $TAGSFILE (for TAGS) +# or $tagsfile (for tags). +# +# Could be rewritten by some sed expert to use sed instead of perl. + +emulate -L zsh + +# Tags file to look for +local c_Tagsfile=${TAGSFILE:-TAGS} c_tagsfile=${tagsfile:-tags} expl +# Max no. of directories to scan up through +integer c_maxdir=10 +# Context. +local curcontext="$curcontext" +local -a c_tags_array + +if [[ -z "$curcontext" ]]; then + curcontext="complete-tag:::" +else + curcontext="complete-tag:${curcontext#*:}" +fi + +local c_path= +integer c_idir +while [[ ! -f $c_path$c_Tagsfile && + ! -f $c_path$c_tagsfile && $c_idir -lt $c_maxdir ]]; do + (( c_idir++ )) + c_path=../$c_path +done + +if [[ -f $c_path$c_Tagsfile ]]; then + # prefer the more comprehensive TAGS, which unfortunately is a + # little harder to parse. + # could do this with sed, just can't be bothered to work out how, + # after quarter of an hour of trying, except for + # rm -f =sed; ln -s /usr/local/bin/perl /usr/bin/sed + # but that's widely regarded as cheating. + c_tags_array=($(sed -n \ + -e 's/^\(.*[a-zA-Z_0-9]\)[[ '$'\t'':;,()]*'$'\177''.*$/\1/' \ + -e 's/^.*[^a-zA-Z_0-9]//' \ + -e '/^[a-zA-Z_].*/p' $c_path$c_Tagsfile)) +# c_tags_array=($(perl -ne '/([a-zA-Z_0-9]+)[ \t:;,\(]*\x7f/ && +# print "$1\n"' $c_path$c_Tagsfile)) + _main_complete - '' _wanted etags expl 'emacs tags' \ + compadd -a c_tags_array +elif [[ -f $c_tagspath ]]; then + # tags doesn't have as much in, but the tag is easy to find. + # we can use awk here. + c_tags_array=($(awk '{ print $1 }' $c_path$c_Tagsfile)) + _main_complete - '' _wanted vtags expl 'vi tags' compadd -a c_tags_array +else + return 1 +fi diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 3f7b20bee..518974014 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -2460,6 +2460,18 @@ a trace of the shell commands executed by the completion system. Each completion attempt gets its own file. A command to view each of these files is pushed onto the editor buffer stack. ) +findex(_complete_tag (^Xt)) +item(tt(_complete_tag (^Xt)))( +This widget completes symbol tags created by the tt(etags) or tt(ctags) +programmes (note there is no connection with the completion system's tags) +stored in a file tt(TAGS), in the format used by tt(etags), or tt(tags), in the +format created by tt(ctags). It will look back up the path hierarchy for +the first occurrence of either file; if both exist, the file tt(TAGS) is +preferred. You can specify the full path to a tt(TAGS) or tt(tags) file by +setting the parameter tt($TAGSFILE) or tt($tagsfile) respectively. +The corresponding completion tags used are tt(etags) and tt(vtags), after +emacs and vi respectively. +) enditem() texinode(Completion Functions)(Completion Directories)(Bindable Commands)(Completion System) |