Rework ctags.kak to read from all the different tag files.
Ensure tags files are not read twice through different paths. Handle paths containings space correctly Closes #802, to which much credits goes for this change.
This commit is contained in:
parent
b6acafc8ec
commit
10fa6afa08
|
@ -7,30 +7,39 @@ decl str-list ctagsfiles 'tags'
|
||||||
|
|
||||||
def -params ..1 \
|
def -params ..1 \
|
||||||
-shell-candidates '
|
-shell-candidates '
|
||||||
( for tags in $(printf %s\\n "${kak_opt_ctagsfiles}" | tr \':\' \'\n\'); do
|
printf %s\\n "$kak_opt_ctagsfiles" | tr \':\' \'\n\' |
|
||||||
namecache=$(dirname ${tags})/.kak.$(basename ${tags}).namecache
|
while read -r candidate; do
|
||||||
if [ -z "$(find ${namecache} -prune -newer ${tags})" ]; then
|
[ -f "$candidate" ] && readlink -f "$candidate"
|
||||||
cat ${tags} | cut -f 1 | uniq > ${namecache}
|
done | awk \'!x[$0]++\' | # remove duplicates
|
||||||
fi
|
while read -r tags; do
|
||||||
cat ${namecache}
|
namecache=$(dirname "$tags")/.kak.$(basename "$tags").namecache
|
||||||
done )' \
|
if [ -z "$(find "$namecache" -prune -newer "$tags")" ]; then
|
||||||
|
cut -f 1 "$tags" | uniq > "$namecache"
|
||||||
|
fi
|
||||||
|
cat "$namecache"
|
||||||
|
done' \
|
||||||
-docstring %{tag [<symbol>]: jump to a symbol's definition
|
-docstring %{tag [<symbol>]: jump to a symbol's definition
|
||||||
If no symbol is passed then the current selection is used as symbol name} \
|
If no symbol is passed then the current selection is used as symbol name} \
|
||||||
tag \
|
tag \
|
||||||
%{ %sh{
|
%{ %sh{
|
||||||
export tagname=${1:-${kak_selection}}
|
export tagname=${1:-${kak_selection}}
|
||||||
for tags in $(printf %s\\n "${kak_opt_ctagsfiles}" | tr ':' '\n'); do
|
printf %s\\n "$kak_opt_ctagsfiles" | tr ':' '\n' |
|
||||||
export tagroot="$(readlink -f $(dirname "$tags"))/"
|
while read -r candidate; do
|
||||||
readtags -t "${tags}" ${tagname} | awk -F '\t|\n' '
|
[ -f "$candidate" ] && readlink -f "$candidate"
|
||||||
/[^\t]+\t[^\t]+\t\/\^.*\$?\// {
|
done | awk '!x[$0]++' | # remove duplicates
|
||||||
re=$0;
|
while read -r tags; do
|
||||||
sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re);
|
printf '!TAGROOT\t%s\n' "$(readlink -f $(dirname "$tags"))/"
|
||||||
keys=re; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys);
|
readtags -t "$tags" $tagname
|
||||||
out = out " %{" $2 " {MenuInfo}" re "} %{eval -collapse-jumps %{ try %{ edit %{" ENVIRON["tagroot"] $2 "}; exec %{/\\Q" keys "<ret>vc} } catch %{ echo %{unable to find tag} } } }"
|
done | awk -F '\t|\n' '
|
||||||
}
|
/^!TAGROOT\t/ { tagroot=$2 }
|
||||||
/[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{eval -collapse-jumps %{ edit %{" ENVIRON["tagroot"] $2 "} %{" $3 "}}}" }
|
/[^\t]+\t[^\t]+\t\/\^.*\$?\// {
|
||||||
END { print length(out) == 0 ? "echo -color Error no such tag " ENVIRON["tagname"] : "menu -markup -auto-single " out }'
|
re=$0;
|
||||||
done
|
sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re);
|
||||||
|
keys=re; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys);
|
||||||
|
out = out " %{" $2 " {MenuInfo}" re "} %{eval -collapse-jumps %{ try %{ edit %{" tagroot $2 "}; exec %{/\\Q" keys "<ret>vc} } catch %{ echo %{unable to find tag} } } }"
|
||||||
|
}
|
||||||
|
/[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{eval -collapse-jumps %{ edit %{" tagroot $2 "} %{" $3 "}}}" }
|
||||||
|
END { print length(out) == 0 ? "echo -color Error no such tag " ENVIRON["tagname"] : "menu -markup -auto-single " out }'
|
||||||
}}
|
}}
|
||||||
|
|
||||||
def tag-complete -docstring "Insert completion candidates for the current selection into the buffer's local variables" %{ eval -draft %{
|
def tag-complete -docstring "Insert completion candidates for the current selection into the buffer's local variables" %{ eval -draft %{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user