From 126d61aa861c16dccd0f38cc9219db7d9abe1cb1 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 27 Mar 2014 22:00:14 +0000 Subject: [PATCH] port clang.kak to awk rather than perl --- rc/clang.kak | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/rc/clang.kak b/rc/clang.kak index 7051ba4c..8f325d33 100644 --- a/rc/clang.kak +++ b/rc/clang.kak @@ -17,14 +17,28 @@ def clang-complete %{ ( pos=-:${kak_cursor_line}:${kak_cursor_column} cd $(dirname ${kak_buffile}) - 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 | - grep -E "^COMPLETION:[^:]+:" | perl -pe 's/^COMPLETION:[^:]+: +//; s/:/\\:/g; s/\[#.*?#\]|<#.*?#>(, *|\))?|\{#.*?#\}\)?//g') + clang++ -x c++ -fsyntax-only ${kak_opt_clang_options} -Xclang -code-completion-at=${pos} - < ${kak_opt_clang_filename} 2>&1 | awk -e ' + function rmblocks(opening, closing, val, res) { + while (match(val, opening)) { + res = res substr(val, 1, RSTART-1) + val = substr(val, RSTART + RLENGTH) + if (match(val, closing)) + val = substr(val, RSTART + RLENGTH) + } + return res val + } + BEGIN { out = ENVIRON["kak_cursor_line"] "." ENVIRON["kak_cursor_column"] "@" ENVIRON["kak_timestamp"] } + /^COMPLETION:[^:]+:/ { + gsub("^COMPLETION:[^:]+: +", ""); gsub(":", "\\:") + c = rmblocks("\\[#", "#\\]", rmblocks("<#", "#>", rmblocks("\\{#", "#\\}", $0))) + gsub("\\((, )+\\)", "(", c) + out = out ":" c + } + END { + cmd = "kak -p " ENVIRON["kak_session"] + print "eval -client " ENVIRON["kak_client"] " %[ echo completed; set buffer clang_completions %[" out "] ]" | cmd + }' rm -r $(dirname ${kak_opt_clang_filename}) - completions="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" - for cmp in ${output}; do - completions="${completions}:${cmp}" - done - echo "eval -client $kak_client %[ echo completed; set buffer clang_completions '${completions}' ]" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } }