2013-03-14 14:12:14 +01:00
|
|
|
decl str clang_options
|
2014-04-03 20:00:42 +02:00
|
|
|
|
2014-10-24 19:46:42 +02:00
|
|
|
decl -hidden str clang_tmp_dir
|
2014-04-03 20:00:42 +02:00
|
|
|
decl -hidden str-list clang_completions
|
2013-03-14 14:12:14 +01:00
|
|
|
|
|
|
|
def clang-complete %{
|
|
|
|
%sh{
|
2014-10-24 19:46:42 +02:00
|
|
|
dir=$(mktemp -d -t kak-clang.XXXXXXXX)
|
|
|
|
mkfifo ${dir}/fifo
|
|
|
|
echo "set buffer clang_tmp_dir ${dir}"
|
2014-10-31 21:53:36 +01:00
|
|
|
echo "write ${dir}/buf"
|
2013-03-14 14:12:14 +01:00
|
|
|
}
|
|
|
|
# end the previous %sh{} so that its output gets interpreted by kakoune
|
|
|
|
# before launching the following as a background task.
|
|
|
|
%sh{
|
2014-10-24 19:46:42 +02:00
|
|
|
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
|
2014-11-05 22:12:29 +01:00
|
|
|
hook -group clang-cleanup buffer BufCloseFifo .* %{
|
|
|
|
nop %sh{ rm -r ${dir} }
|
|
|
|
rmhooks buffer clang-cleanup
|
|
|
|
}
|
2014-10-24 19:46:42 +02:00
|
|
|
}"
|
2014-11-06 20:17:13 +01: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
|
2013-03-14 14:12:14 +01:00
|
|
|
# displayed.
|
|
|
|
(
|
2013-03-19 13:57:23 +01:00
|
|
|
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
2014-03-02 02:07:29 +01:00
|
|
|
cd $(dirname ${kak_buffile})
|
2014-10-31 21:53:36 +01:00
|
|
|
header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
2014-11-06 20:17:13 +01: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/; s/:/\\:/g' | uniq | paste -s -d ':')
|
2014-10-31 21:53:36 +01:00
|
|
|
|
|
|
|
echo "eval -client ${kak_client} %[ echo completed; set 'buffer=${kak_buffile}' clang_completions %[${header}:${compl}] ]" | kak -p ${kak_session}
|
2014-03-06 04:35:38 +01:00
|
|
|
) > /dev/null 2>&1 < /dev/null &
|
2013-03-14 14:12:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def clang-enable-autocomplete %{
|
2014-11-06 20:17:13 +01:00
|
|
|
set window completers %rec{option=clang_completions:%opt{completers}}
|
2014-06-16 21:42:12 +02:00
|
|
|
hook window -group clang-autocomplete InsertIdle .* %{ try %{
|
2014-10-30 01:50:09 +01:00
|
|
|
exec -draft <a-h><a-k>(\.|->|::).\'<ret>
|
2013-10-31 20:14:44 +01:00
|
|
|
echo 'completing...'
|
|
|
|
clang-complete
|
2013-11-07 19:50:16 +01:00
|
|
|
} }
|
2013-03-14 14:12:14 +01:00
|
|
|
}
|
2013-04-11 14:30:02 +02:00
|
|
|
|
2014-03-15 04:14:23 +01:00
|
|
|
def clang-disable-autocomplete %{
|
|
|
|
set window completers %sh{ echo "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' }
|
|
|
|
rmhooks window clang-autocomplete
|
|
|
|
}
|