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
|
||||||
|
while read -r tags; do
|
||||||
|
namecache=$(dirname "$tags")/.kak.$(basename "$tags").namecache
|
||||||
|
if [ -z "$(find "$namecache" -prune -newer "$tags")" ]; then
|
||||||
|
cut -f 1 "$tags" | uniq > "$namecache"
|
||||||
fi
|
fi
|
||||||
cat ${namecache}
|
cat "$namecache"
|
||||||
done )' \
|
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"
|
||||||
|
done | awk '!x[$0]++' | # remove duplicates
|
||||||
|
while read -r tags; do
|
||||||
|
printf '!TAGROOT\t%s\n' "$(readlink -f $(dirname "$tags"))/"
|
||||||
|
readtags -t "$tags" $tagname
|
||||||
|
done | awk -F '\t|\n' '
|
||||||
|
/^!TAGROOT\t/ { tagroot=$2 }
|
||||||
/[^\t]+\t[^\t]+\t\/\^.*\$?\// {
|
/[^\t]+\t[^\t]+\t\/\^.*\$?\// {
|
||||||
re=$0;
|
re=$0;
|
||||||
sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re);
|
sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re);
|
||||||
keys=re; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys);
|
keys=re; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys);
|
||||||
out = out " %{" $2 " {MenuInfo}" re "} %{eval -collapse-jumps %{ try %{ edit %{" ENVIRON["tagroot"] $2 "}; exec %{/\\Q" keys "<ret>vc} } catch %{ echo %{unable to find tag} } } }"
|
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 %{" ENVIRON["tagroot"] $2 "} %{" $3 "}}}" }
|
/[^\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 }'
|
END { print length(out) == 0 ? "echo -color Error no such tag " ENVIRON["tagname"] : "menu -markup -auto-single " out }'
|
||||||
done
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
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