reimplemented ctags-search command
This commit is contained in:
parent
92972bed4f
commit
3e85406ec1
|
@ -25,27 +25,38 @@ If no symbol is passed then the current selection is used as symbol name} \
|
||||||
ctags-search \
|
ctags-search \
|
||||||
%{ evaluate-commands %sh{
|
%{ evaluate-commands %sh{
|
||||||
realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) }
|
realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) }
|
||||||
export tagname=${1:-${kak_selection}}
|
export tagname="${1:-${kak_selection}}"
|
||||||
eval "set -- $kak_opt_ctagsfiles"
|
eval "set -- $kak_opt_ctagsfiles"
|
||||||
for candidate in "$@"; do
|
for candidate in "$@"; do
|
||||||
[ -f "$candidate" ] && realpath "$candidate"
|
[ -f "$candidate" ] && realpath "$candidate"
|
||||||
done | awk '!x[$0]++' | # remove duplicates
|
done | awk '!x[$0]++' | # remove duplicates
|
||||||
while read -r tags; do
|
while read -r tags; do
|
||||||
printf '!TAGROOT\t%s\n' "$(realpath "${tags%/*}")/"
|
printf '!TAGROOT\t%s\n' "$(realpath "${tags%/*}")/"
|
||||||
readtags -t "$tags" $tagname
|
readtags -t "$tags" "$tagname"
|
||||||
done | awk -F '\t|\n' '
|
done | awk -F '\t|\n' '
|
||||||
/^!TAGROOT\t/ { tagroot=$2 }
|
/^!TAGROOT\t/ { tagroot=$2 }
|
||||||
/[^\t]+\t[^\t]+\t\/\^.*\$?\// {
|
/[^\t]+\t[^\t]+\t\/\^.*\$?\// {
|
||||||
re=$0;
|
opener = "\\{"; closer = "\\}"
|
||||||
sub(".*\t/\\^", "", re); sub("\\$?/$", "", re); gsub("(\\{|\\}|\\\\E).*$", "", re);
|
line = $0; sub(".*\t/\\^", "", line); sub("\\$?/$", "", line);
|
||||||
keys=re; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys);
|
menu_info = line; gsub("!", "!!", menu_info); gsub(/^[\t+ ]+/, "", menu_info); gsub(opener, "\\"opener, menu_info); gsub(/\t/, " ", menu_info);
|
||||||
out = out " %{" $2 " {MenuInfo}" re "} %{evaluate-commands %{ try %{ edit %{" path($2) "}; execute-keys %{/\\Q" keys "<ret>vc} } catch %{ echo %{unable to find tag} } } }"
|
keys = line; gsub(/</, "<lt>", keys); gsub(/\t/, "<c-v><c-i>", keys); gsub("!", "!!", keys); gsub("&", "&&", keys); gsub("#", "##", keys); gsub("\\|", "||", keys); gsub("\\\\/", "/", keys);
|
||||||
}
|
menu_item = $2; gsub("!", "!!", menu_item);
|
||||||
/[^\t]+\t[^\t]+\t[0-9]+/ { out = out " %{" $2 ":" $3 "} %{evaluate-commands %{ edit %{" path($2) "} %{" $3 "}}}" }
|
edit_path = path($2); gsub("&", "&&", edit_path); gsub("#", "##", edit_path); gsub("\\|", "||", edit_path);
|
||||||
END { print ( length(out) == 0 ? "echo -markup %{{Error}no such tag " ENVIRON["tagname"] "}" : "menu -markup -auto-single " out ) }
|
select = $1; gsub(/</, "<lt>", select); gsub(/\t/, "<c-v><c-i>", select); gsub("!", "!!", select); gsub("&", "&&", select); gsub("#", "##", select); gsub("\\|", "||", select);
|
||||||
|
out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|/\\Q" keys "<ret>vc| & catch %& echo -markup %|{Error}unable to find tag| &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
|
||||||
# Ensure x is an absolute file path, by prepending with tagroot
|
}
|
||||||
function path(x) { return x ~/^\// ? x : tagroot x }'
|
/[^\t]+\t[^\t]+\t[0-9]+/ {
|
||||||
|
opener = "{"; closer = "}"
|
||||||
|
menu_item = $2; gsub("!", "!!", menu_item);
|
||||||
|
select = $1; gsub(/</, "<lt>", select); gsub(/\t/, "<c-v><c-i>", select); gsub("!", "!!", select); gsub("&", "&&", select); gsub("#", "##", select); gsub("\\|", "||", select);
|
||||||
|
menu_info = $3; gsub("!", "!!", menu_info); gsub(opener, "\\"opener, menu_info);
|
||||||
|
edit_path = path($2); gsub("!", "!!", edit_path); gsub("#", "##", edit_path); gsub("&", "&&", edit_path); gsub("\\|", "||", edit_path);
|
||||||
|
line_number = $3;
|
||||||
|
out = out "%!" menu_item ": {MenuInfo}" menu_info "! %!evaluate-commands %# try %& edit -existing %|" edit_path "|; execute-keys %|" line_number "gx| & catch %& echo -markup %|{Error}unable to find tag| &; try %& execute-keys %|s\\Q" select "<ret>| & # !"
|
||||||
|
}
|
||||||
|
END { print ( length(out) == 0 ? "echo -markup %{{Error}no such tag " ENVIRON["tagname"] "}" : "menu -markup -auto-single " out ) }
|
||||||
|
# Ensure x is an absolute file path, by prepending with tagroot
|
||||||
|
function path(x) { return x ~/^\// ? x : tagroot x }'
|
||||||
}}
|
}}
|
||||||
|
|
||||||
define-command ctags-complete -docstring "Insert completion candidates for the current selection into the buffer's local variables" %{ evaluate-commands -draft %{
|
define-command ctags-complete -docstring "Insert completion candidates for the current selection into the buffer's local variables" %{ evaluate-commands -draft %{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user