From fcf3e9e138c2089822527cfdeb04e706b6ee38d2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 28 Nov 2013 18:45:39 +0000 Subject: [PATCH] Improve ctags support * cleanup tag command * add a tag-complete command * add a gentags command for launching ctags in the background --- src/rc/ctags.kak | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/src/rc/ctags.kak b/src/rc/ctags.kak index 237e94f7..26db6314 100644 --- a/src/rc/ctags.kak +++ b/src/rc/ctags.kak @@ -25,18 +25,25 @@ def -shell-params \ fi }} +def tag-complete %{ eval -draft %{ + exec hb^\w+$ + %sh{ ( + compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq) + compl=${compl//:/\\:} + compl=${compl//$'\n'/:} + compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}" + echo "set buffer=$kak_bufname completions '${compl}'" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} + ) >& /dev/null < /dev/null & } +}} + def funcinfo %{ eval -draft %{ - exec [(B; + exec [(B[a-zA-Z_]+\( %sh{ - if [[ "$kak_selection" =~ [a-zA-Z_]+\( ]]; then - sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*(class|struct|namespace):(\S+).*signature:(.*)$/\4 [\3::\1]/') - if [[ -n "$sigs" ]]; then - echo "eval -client ${kak_client} %{info -anchor right '$sigs'}" - exit - fi + sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*(class|struct|namespace):(\S+).*signature:(.*)$/\4 [\3::\1]/') + if [[ -n "$sigs" ]]; then + echo "eval -client ${kak_client} %{info -anchor right '$sigs'}" fi - echo info } } } @@ -49,3 +56,18 @@ def ctags-enable-autoinfo %{ } def ctags-disable-autoinfo %{ rmhooks window ctags-autoinfo } + +decl str ctagsopts "-R ." + +def gentags %{ + echo launching tag generation in the background + %sh{ ( + if ctags -f .tags.kaktmp ${kak_opt_ctagsopts}; then + mv .tags.kaktmp tags + msg="tags generation complete" + else + msg="tags generation failed" + fi + echo "eval -client $kak_client echo ${msg}" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session} + ) >& /dev/null < /dev/null & } +}