2013-03-14 17:12:14 +04:00
|
|
|
decl str clang_filename
|
|
|
|
decl str clang_options
|
|
|
|
|
|
|
|
def clang-complete %{
|
|
|
|
%sh{
|
|
|
|
filename=$(mktemp -d -t kak-clang.XXXXXXXX)/buffer.cpp
|
|
|
|
echo "setb clang_filename $filename"
|
|
|
|
echo "write $filename"
|
|
|
|
}
|
|
|
|
# end the previous %sh{} so that its output gets interpreted by kakoune
|
|
|
|
# before launching the following as a background task.
|
|
|
|
%sh{
|
2013-03-19 16:57:23 +04: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 17:12:14 +04:00
|
|
|
# displayed.
|
|
|
|
(
|
2013-03-19 16:57:23 +04:00
|
|
|
pos=-:${kak_cursor_line}:${kak_cursor_column}
|
|
|
|
cd $(dirname ${kak_bufname})
|
|
|
|
output=$(clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${kak_opt_clang_filename} |
|
2013-07-25 00:41:41 +04:00
|
|
|
grep -E "^COMPLETION:[^:]+:" | perl -pe 's/^COMPLETION:[^:]+: +//; s/:/\\:/g; s/\[#.*?#\]|<#.*?#>(, *|\))?|\{#.*?#\}\)?//g')
|
2013-03-14 17:12:14 +04:00
|
|
|
rm -r $(dirname ${kak_opt_clang_filename})
|
2013-07-25 00:41:41 +04:00
|
|
|
completions="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
2013-03-14 17:12:14 +04:00
|
|
|
for cmp in ${output}; do
|
2013-07-25 00:41:41 +04:00
|
|
|
completions="${completions}:${cmp}"
|
2013-03-14 17:12:14 +04:00
|
|
|
done
|
2013-09-25 22:04:52 +04:00
|
|
|
echo "eval -client $kak_client %[ echo completed; setb completions '${completions}' ]" | socat -u stdin UNIX-CONNECT:/tmp/kak-${kak_session}
|
2013-03-14 17:12:14 +04:00
|
|
|
) >& /dev/null < /dev/null &
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def clang-enable-autocomplete %{
|
2013-04-11 16:30:02 +04:00
|
|
|
hook window -id clang-autocomplete InsertIdle .* %{ eval -draft %{
|
2013-03-14 23:40:43 +04:00
|
|
|
exec <a-h>
|
2013-09-13 01:52:43 +04:00
|
|
|
%sh{ [[ $kak_selection =~ .*(\.|->|::).$ ]] && echo "exec <a-space>; eval -client $kak_client echo 'completing...'; clang-complete" }
|
2013-03-14 17:12:14 +04:00
|
|
|
}}
|
|
|
|
}
|
2013-04-11 16:30:02 +04:00
|
|
|
|
|
|
|
def clang-disable-autocomplete %{ rmhooks window clang-autocomplete }
|