2013-11-12 20:21:07 +01:00
|
|
|
decl -hidden str clang_filename
|
2013-03-14 14:12:14 +01:00
|
|
|
decl str clang_options
|
2014-03-15 04:14:23 +01:00
|
|
|
decl str-list clang_completions
|
2013-03-14 14:12:14 +01:00
|
|
|
|
|
|
|
def clang-complete %{
|
|
|
|
%sh{
|
|
|
|
filename=$(mktemp -d -t kak-clang.XXXXXXXX)/buffer.cpp
|
2013-10-30 10:38:40 +01:00
|
|
|
echo "set buffer clang_filename $filename"
|
2013-03-14 14:12:14 +01:00
|
|
|
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 13:57:23 +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-03-06 04:35:38 +01:00
|
|
|
output=$(clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${kak_opt_clang_filename} 2>&1 | tee /tmp/kak-clang-out |
|
2013-07-24 22:41:41 +02:00
|
|
|
grep -E "^COMPLETION:[^:]+:" | perl -pe 's/^COMPLETION:[^:]+: +//; s/:/\\:/g; s/\[#.*?#\]|<#.*?#>(, *|\))?|\{#.*?#\}\)?//g')
|
2013-03-14 14:12:14 +01:00
|
|
|
rm -r $(dirname ${kak_opt_clang_filename})
|
2013-07-24 22:41:41 +02:00
|
|
|
completions="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}"
|
2013-03-14 14:12:14 +01:00
|
|
|
for cmp in ${output}; do
|
2013-07-24 22:41:41 +02:00
|
|
|
completions="${completions}:${cmp}"
|
2013-03-14 14:12:14 +01:00
|
|
|
done
|
2014-03-15 04:14:23 +01:00
|
|
|
echo "eval -client $kak_client %[ echo completed; set buffer clang_completions '${completions}' ]" | 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-03-15 04:14:23 +01:00
|
|
|
set window completers %sh{ echo "'option=clang_completions:${kak_opt_completers}'" }
|
2013-11-07 19:50:16 +01:00
|
|
|
hook window -id clang-autocomplete InsertIdle .* %{ try %{
|
2014-01-25 19:49:44 +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
|
|
|
|
}
|