1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-21 10:40:53 +03:00
kakoune/rc/clang.kak

55 lines
2.2 KiB
Plaintext
Raw Normal View History

decl str clang_options
decl -hidden str clang_tmp_dir
decl -hidden str-list clang_completions
def clang-complete %{
%sh{
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
mkfifo ${dir}/fifo
echo "set buffer clang_tmp_dir ${dir}"
2014-10-31 23:53:36 +03:00
echo "write ${dir}/buf"
}
# end the previous %sh{} so that its output gets interpreted by kakoune
# before launching the following as a background task.
%sh{
dir=${kak_opt_clang_tmp_dir}
echo "eval -draft %{
edit! -fifo ${dir}/fifo *clang-output*
set buffer filetype make
set buffer _make_current_error_line 0
hook -group clang-cleanup buffer BufCloseFifo .* %{
nop %sh{ rm -r ${dir} }
rmhooks buffer clang-cleanup
}
}"
2014-11-06 22:17:13 +03:00
# this runs in a detached shell, asynchronously, so that kakoune does
# not hang while clang is running. As completions references a cursor
# position and a buffer timestamp, only valid completions should be
# displayed.
(
pos=-:${kak_cursor_line}:${kak_cursor_column}
cd $(dirname ${kak_buffile})
2014-10-31 23:53:36 +03:00
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
2014-11-06 22:17:13 +03:00
compl=$(clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${dir}/buf 2> ${dir}/fifo |
grep ^COMPLETION: | grep -v '(Hidden)' | sed -re 's/^COMPLETION: (.+) : (.*)/\1@\2/; s/:/\\:/g' | uniq | paste -s -d ':')
2014-10-31 23:53:36 +03:00
echo "eval -client ${kak_client} %[ echo completed; set 'buffer=${kak_buffile}' clang_completions %[${header}:${compl}] ]" | kak -p ${kak_session}
) > /dev/null 2>&1 < /dev/null &
}
}
def clang-enable-autocomplete %{
2014-11-06 22:17:13 +03:00
set window completers %rec{option=clang_completions:%opt{completers}}
hook window -group clang-autocomplete InsertIdle .* %{ try %{
2014-10-30 03:50:09 +03:00
exec -draft <a-h><a-k>(\.|->|::).\'<ret>
echo 'completing...'
clang-complete
} }
}
2013-04-11 16:30:02 +04:00
def clang-disable-autocomplete %{
set window completers %sh{ echo "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' }
rmhooks window clang-autocomplete
}