From 9fe19fa72efb89a1fd09de4ca39c87ff66506804 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 21 Nov 2015 12:08:28 +0000 Subject: [PATCH] ctags.kak: rename gentags to ctags-generate and add ctags-update Both use proper locking of the tag file, and ctags-update can update the tags file for a single file. --- rc/ctags.kak | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/rc/ctags.kak b/rc/ctags.kak index 35f26b69..af9bfc39 100644 --- a/rc/ctags.kak +++ b/rc/ctags.kak @@ -59,17 +59,37 @@ def ctags-enable-autoinfo -docstring "Automatically display ctags information ab def ctags-disable-autoinfo -docstring "Disable automatic ctags information displaying" %{ rmhooks window ctags-autoinfo } -decl str ctagsopts "-R ." +decl str ctagsopts "-R" +decl str ctagspaths "." -def gentags -docstring 'Generate tag file asynchronously' %{ +def ctags-generate -docstring 'Generate tag file asynchronously' %{ echo -color Information "launching tag generation in the background" %sh{ ( - if ctags -f .tags.kaktmp ${kak_opt_ctagsopts}; then + while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done + trap 'rmdir .tags.kaklock' EXIT + + if ctags -f .tags.kaktmp ${kak_opt_ctagsopts} ${kak_opt_ctagspaths}; then mv .tags.kaktmp tags msg="tags generation complete" else msg="tags generation failed" fi + echo "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } } + +def update-tags -docstring 'Update tags for the given file' %{ + %sh{ ( + while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done + trap 'rmdir .tags.kaklock' EXIT + + if ctags -f .file_tags.kaktmp ${kak_opt_ctagsopts} $kak_bufname; then + grep -Fv "$(printf '\t%s\t' "$kak_bufname")" tags | grep -v '^!' | sort --merge - .file_tags.kaktmp > .tags.kaktmp + mv .tags.kaktmp tags + msg="tags updated for $kak_bufname" + else + msg="tags update failed for $kak_bufname" + fi + ) > /dev/null 2>&1 < /dev/null & } +}