From e9fc54538d3fb0a313bf2905c571b2a1052ae3c6 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 30 May 2018 23:28:50 +1000 Subject: [PATCH] Convert some of the rc/ scripts to the new list syntax Other scripts relying on lists are broken at the moment, and will be fixed. This commit is a proof of concept of the new way to work with lists. --- rc/base/ctags.kak | 10 +++--- rc/core/c-family.kak | 10 +++--- rc/core/kakrc.kak | 2 +- rc/extra/clang.kak | 72 ++++++++++++++++++++++-------------------- rc/extra/git-tools.kak | 24 +++++++------- rc/extra/jedi.kak | 2 +- 6 files changed, 63 insertions(+), 57 deletions(-) diff --git a/rc/base/ctags.kak b/rc/base/ctags.kak index 50b73233..4e77e2a1 100644 --- a/rc/base/ctags.kak +++ b/rc/base/ctags.kak @@ -3,14 +3,14 @@ # This script requires the readtags command available in ctags source but # not installed by default -declare-option -docstring "colon separated list of paths to tag files to parse when looking up a symbol" \ +declare-option -docstring "list of paths to tag files to parse when looking up a symbol" \ str-list ctagsfiles 'tags' define-command -params ..1 \ -shell-candidates %{ realpath() { ( path=$(readlink "$1"); cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) } - printf %s\\n "$kak_opt_ctagsfiles" | tr ':' '\n' | - while read -r candidate; do + eval "set -- $kak_opt_ctagsfiles" + for candidate in "$@"; do [ -f "$candidate" ] && realpath "$candidate" done | awk '!x[$0]++' | # remove duplicates while read -r tags; do @@ -26,8 +26,8 @@ If no symbol is passed then the current selection is used as symbol name} \ %{ evaluate-commands %sh{ realpath() { ( path=$(readlink "$1"); cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) } export tagname=${1:-${kak_selection}} - printf %s\\n "$kak_opt_ctagsfiles" | tr ':' '\n' | - while read -r candidate; do + eval "set -- $kak_opt_ctagsfiles" + for candidate in "$@"; do [ -f "$candidate" ] && realpath "$candidate" done | awk '!x[$0]++' | # remove duplicates while read -r tags; do diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 9cdd5c49..2b888f70 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -330,17 +330,19 @@ define-command -hidden c-family-insert-include-guards %{ hook -group c-family-insert global BufNewFile .*\.(h|hh|hpp|hxx|H) c-family-insert-include-guards declare-option -docstring "colon separated list of path in which header files will be looked for" \ - str-list alt_dirs ".:.." + str-list alt_dirs '.' '..' define-command c-family-alternative-file -docstring "Jump to the alternate file (header/implementation)" %{ evaluate-commands %sh{ - alt_dirs=$(printf %s\\n "${kak_opt_alt_dirs}" | tr ':' '\n') file="${kak_buffile##*/}" file_noext="${file%.*}" dir=$(dirname "${kak_buffile}") + # Set $@ to alt_dirs + eval "set -- ${kak_opt_alt_dirs}" + case ${file} in *.c|*.cc|*.cpp|*.cxx|*.C|*.inl|*.m) - for alt_dir in ${alt_dirs}; do + for alt_dir in "$@"; do for ext in h hh hpp hxx H; do altname="${dir}/${alt_dir}/${file_noext}.${ext}" if [ -f ${altname} ]; then @@ -351,7 +353,7 @@ define-command c-family-alternative-file -docstring "Jump to the alternate file done ;; *.h|*.hh|*.hpp|*.hxx|*.H) - for alt_dir in ${alt_dirs}; do + for alt_dir in "$@"; do for ext in c cc cpp cxx C m; do altname="${dir}/${alt_dir}/${file_noext}.${ext}" if [ -f ${altname} ]; then diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index 80e45a1b..05a26fb8 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -43,7 +43,7 @@ evaluate-commands %sh{ # Add the language's grammar to the static completion list printf '%s\n' "hook global WinSetOption filetype=kak %{ - set-option window static_words '$(join "${keywords}:${attributes}:${types}:${values}" ':')' + set-option window static_words $(join "${keywords} ${attributes} ${types} ${values}" ' ')' set-option -- window extra_word_chars '-' }" diff --git a/rc/extra/clang.kak b/rc/extra/clang.kak index e5c1b9ff..85cbb219 100644 --- a/rc/extra/clang.kak +++ b/rc/extra/clang.kak @@ -50,7 +50,7 @@ The syntaxic errors detected during parsing are shown when auto-diagnostics are /^COMPLETION:/ && ! /\(Hidden\)/ { id=$2 gsub(/ +$/, "", id) - gsub(/:/, "\\:", id) + gsub(/~/, "~~", id) gsub(/\|/, "\\|", id) gsub(/[[{<]#|#[}>]/, "", $3) @@ -59,10 +59,10 @@ The syntaxic errors detected during parsing are shown when auto-diagnostics are gsub(/ +$/, "", $3) desc=$4 ? $3 "\\n" $4 : $3 - gsub(/:/, "\\:", desc) + gsub(/~/, "~~", desc) gsub(/\|/, "\\|", desc) if (id in docstrings) - docstrings[id]=docstrings[id] "\\n" desc + docstrings[id]=docstrings[id] "\n" desc else docstrings[id]=desc } @@ -72,31 +72,30 @@ The syntaxic errors detected during parsing are shown when auto-diagnostics are gsub(/(^|[^[:alnum:]_])(operator|new|delete)($|[^{}_[:alnum:]]+)/, "{keyword}&{}", menu) gsub(/(^|[[:space:]])(int|size_t|bool|char|unsigned|signed|long)($|[[:space:]])/, "{type}&{}", menu) gsub(/[^{}_[:alnum:]]+/, "{operator}&{}", menu) - print id "|" docstrings[id] "|" menu + printf "%%~%s|%s|%s~ ", id, docstrings[id], menu } - }' | paste -s -d ':' - | sed -e "s/\\\\n/\\n/g; s/'/\\\\'/g") + }') printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang completion done' - set-option 'buffer=${kak_buffile}' clang_completions '${header}:${compl}'" | kak -p ${kak_session} + set-option 'buffer=${kak_buffile}' clang_completions ${header} ${compl}" | kak -p ${kak_session} else clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr printf %s\\n "evaluate-commands -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} fi flags=$(cat ${dir}/stderr | sed -rne " - /^:[0-9]+:([0-9]+:)? (fatal )?error/ { s/^:([0-9]+):.*/\1|{red}█/; p } - /^:[0-9]+:([0-9]+:)? warning/ { s/^:([0-9]+):.*/\1|{yellow}█/; p } - " | paste -s -d ':' -) + /^:[0-9]+:([0-9]+:)? (fatal )?error/ { s/^:([0-9]+):.*/'\1|{red}█'/; p } + /^:[0-9]+:([0-9]+:)? warning/ { s/^:([0-9]+):.*/'\1|{yellow}█'/; p } + " | paste -s -d ' ' -) errors=$(cat ${dir}/stderr | sed -rne " /^:[0-9]+:([0-9]+:)? ((fatal )?error|warning)/ { - s/^:([0-9]+):([0-9]+:)? (.*)/\1|\3/ - s/'/\\\\'/g; s/:/\\\\:/g; p - }" | sort -n | paste -s -d ':' -) + s/'/''/g; s/^:([0-9]+):([0-9]+:)? (.*)/'\1|\3'/; p + }" | sort -n | paste -s -d ' ' -) sed -e "s||${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo - printf %s\\n "set-option 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}} - set-option 'buffer=${kak_buffile}' clang_errors '${kak_timestamp}:${errors}'" | kak -p ${kak_session} + printf %s\\n "set-option 'buffer=${kak_buffile}' clang_flags ${kak_timestamp} ${flags} + set-option 'buffer=${kak_buffile}' clang_errors ${kak_timestamp} ${errors}" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } } @@ -115,7 +114,7 @@ define-command -hidden clang-show-completion-info %[ try %[ ] ] define-command clang-enable-autocomplete -docstring "Enable automatic clang completion" %{ - set-option window completers "option=clang_completions:%opt{completers}" + set-option window completers "option=clang_completions" %opt{completers} hook window -group clang-autocomplete InsertIdle .* %{ try %{ execute-keys -draft (\.|->|::).\z @@ -128,7 +127,7 @@ define-command clang-enable-autocomplete -docstring "Enable automatic clang comp } define-command clang-disable-autocomplete -docstring "Disable automatic clang completion" %{ - set-option window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' } + evaluate-commands %sh{ printf "set-option window completers "; printf %s\\n "'${kak_opt_completers}'" | sed -e "s/'option=clang_completions'//g" } remove-hooks window clang-autocomplete unalias window complete clang-complete } @@ -136,11 +135,15 @@ define-command clang-disable-autocomplete -docstring "Disable automatic clang co define-command -hidden clang-show-error-info %{ update-option buffer clang_errors # Ensure we are up to date with buffer changes evaluate-commands %sh{ - desc=$(printf %s\\n "${kak_opt_clang_errors}" | - sed -e "s/\([^\\]\):/\1\n/g" | - sed -ne "/^${kak_cursor_line}|.*/ { s/^[[:digit:]]\+|//g; s/'/\\\\'/g; s/\\\\:/:/g; p }") + eval "set -- ${kak_opt_clang_errors}" + shift # skip timestamp + for error in "$@"; do + if [ "${error%%|*}" == "$kak_cursor_line" ]; then + desc=$(printf '%s%s\n' "$desc" "${error##*|}") + fi + done if [ -n "$desc" ]; then - printf %s\\n "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" + printf %s\\n "info -anchor ${kak_cursor_line}.${kak_cursor_column} '$desc'" fi } } @@ -160,19 +163,20 @@ define-command clang-disable-diagnostics -docstring "Disable automatic error rep define-command clang-diagnostics-next -docstring "Jump to the next line that contains an error" %{ update-option buffer clang_errors # Ensure we are up to date with buffer changes evaluate-commands %sh{ - printf "%s\n" "${kak_opt_clang_errors}" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | ( - while IFS='|' read candidate rest; do - first_line=${first_line-$candidate} - if [ "$candidate" -gt $kak_cursor_line ]; then - line=$candidate - break - fi - done - line=${line-$first_line} - if [ -n "$line" ]; then - printf %s\\n "execute-keys ${line} g" - else - echo "echo -markup '{Error}no next clang diagnostic'" + eval "set -- ${kak_opt_clang_errors}" + shift # skip timestamp + for error in "$@"; do + candidate=${error%%|*} + first_line=${first_line-$candidate} + if [ "$candidate" -gt $kak_cursor_line ]; then + line=$candidate + break fi - ) + done + line=${line-$first_line} + if [ -n "$line" ]; then + printf %s\\n "execute-keys ${line} g" + else + echo "echo -markup '{Error}no next clang diagnostic'" + fi } } diff --git a/rc/extra/git-tools.kak b/rc/extra/git-tools.kak index 3c73a981..6d400bb8 100644 --- a/rc/extra/git-tools.kak +++ b/rc/extra/git-tools.kak @@ -70,14 +70,14 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide- function send_flags(text, flag, i) { if (line == "") { return; } text=substr(sha,1,8) " " dates[sha] " " authors[sha] - gsub(":", "\\:", text) # gsub("|", "\\|", text) - flag=line "|" text + gsub("~", "~~", text) + flag="%~" line "|" text "~" for ( i=1; i < count; i++ ) { - flag=flag ":" line+i "|" text + flag=flag " %~" line+i "|" text "~" } cmd = "kak -p " ENVIRON["kak_session"] - print "set-option -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags %{" flag "}" | cmd + print "set-option -add buffer=" ENVIRON["kak_bufname"] " git_blame_flags " flag | cmd close(cmd) } /^([0-9a-f]{40}) ([0-9]+) ([0-9]+) ([0-9]+)/ { @@ -109,39 +109,39 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide- if ($from_count == 0 and $to_count > 0) { for $i (0..$to_count - 1) { $line = $to_line + $i; - $flags .= ":$line|\{green\}+"; + $flags .= " $line|\{green\}+"; } } elsif ($from_count > 0 and $to_count == 0) { if ($to_line == 0) { - $flags .= ":1|\{red\}‾"; + $flags .= " 1|\{red\}‾"; } else { - $flags .= ":$to_line|\{red\}_"; + $flags .= " $to_line|\{red\}_"; } } elsif ($from_count > 0 and $from_count == $to_count) { for $i (0..$to_count - 1) { $line = $to_line + $i; - $flags .= ":$line|\{blue\}~"; + $flags .= " $line|\{blue\}~"; } } elsif ($from_count > 0 and $from_count < $to_count) { for $i (0..$from_count - 1) { $line = $to_line + $i; - $flags .= ":$line|\{blue\}~"; + $flags .= " $line|\{blue\}~"; } for $i ($from_count..$to_count - 1) { $line = $to_line + $i; - $flags .= ":$line|\{green\}+"; + $flags .= " $line|\{green\}+"; } } elsif ($to_count > 0 and $from_count > $to_count) { for $i (0..$to_count - 2) { $line = $to_line + $i; - $flags .= ":$line|\{blue\}~"; + $flags .= " $line|\{blue\}~"; } $last = $to_line + $to_count - 1; - $flags .= ":$last|\{blue+u\}~"; + $flags .= " $last|\{blue+u\}~"; } } } diff --git a/rc/extra/jedi.kak b/rc/extra/jedi.kak index df259ead..317ea555 100644 --- a/rc/extra/jedi.kak +++ b/rc/extra/jedi.kak @@ -1,7 +1,7 @@ declare-option -hidden str jedi_tmp_dir declare-option -hidden completions jedi_completions declare-option -docstring "colon separated list of path added to `python`'s $PYTHONPATH environment variable" \ - str-list jedi_python_path + str jedi_python_path define-command jedi-complete -docstring "Complete the current selection" %{ evaluate-commands %sh{