From a20f5fc6a28bcafa444191e5a715406b9fe9dbdb Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Sat, 23 Apr 2016 08:47:01 +0300 Subject: [PATCH] Pass a generic pattern to `printf` calls, use `echo` when possible --- rc/base/ctags.kak | 10 +++++----- rc/base/dlang.kak | 2 +- rc/base/golang.kak | 2 +- rc/base/lua.kak | 12 ++++++------ rc/base/perl.kak | 2 +- rc/base/ruby.kak | 2 +- rc/base/spell.kak | 16 ++++++++-------- rc/core/c-family.kak | 22 +++++++++++----------- rc/core/commenting.kak | 10 +++++----- rc/core/doc.kak | 14 +++++++------- rc/core/formatter.kak | 4 ++-- rc/core/grep.kak | 2 +- rc/core/kakrc.kak | 2 +- rc/core/make.kak | 2 +- rc/core/man.kak | 12 ++++++------ rc/core/python.kak | 2 +- rc/core/tmux.kak | 12 +++++++----- rc/core/x11.kak | 8 ++++---- rc/extra/autorestore.kak | 8 ++++---- rc/extra/clang.kak | 37 +++++++++++++------------------------ rc/extra/editorconfig.kak | 6 +++--- rc/extra/flake8.kak | 2 +- rc/extra/git-tools.kak | 34 +++++++++++++++++----------------- rc/extra/jedi.kak | 12 ++++++------ rc/extra/modeline.kak | 18 +++++++++--------- rc/extra/moon.kak | 12 ++++++------ rc/extra/tmux-repl.kak | 8 +++++--- rc/extra/x11-repl.kak | 4 ++-- 28 files changed, 135 insertions(+), 142 deletions(-) diff --git a/rc/base/ctags.kak b/rc/base/ctags.kak index 8c970553..e46c4b34 100644 --- a/rc/base/ctags.kak +++ b/rc/base/ctags.kak @@ -7,7 +7,7 @@ decl str-list ctagsfiles 'tags' def -params 0..1 \ -shell-completion ' - ( for tags in $(printf %s "${kak_opt_ctagsfiles}" | tr \':\' \'\n\'); + ( for tags in $(printf %s\\n "${kak_opt_ctagsfiles}" | tr \':\' \'\n\'); do readtags -t "${tags}" -p "$1" done ) | cut -f 1 | sort | uniq' \ -docstring 'Jump to tag definition' \ @@ -15,7 +15,7 @@ def -params 0..1 \ %{ %sh{ export tagname=${1:-${kak_selection}} ( - for tags in $(printf %s "${kak_opt_ctagsfiles}" | tr ':' '\n'); do + for tags in $(printf %s\\n "${kak_opt_ctagsfiles}" | tr ':' '\n'); do readtags -t "${tags}" ${tagname} done ) | awk -F '\t|\n' -e ' @@ -34,7 +34,7 @@ def tag-complete -docstring "Insert completion candidates for the current select %sh{ ( compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq | sed -e 's/:/\\:/g' | sed -e 's/\n/:/g' ) compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}" - printf %s "set buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} + printf %s\\n "set buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } }} @@ -45,7 +45,7 @@ def ctags-funcinfo -docstring "Display ctags information about a selected functi %sh{ sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*((class|struct|namespace):(\S+))?.*signature:(.*)$/\5 [\4::\1]/') if [ -n "$sigs" ]; then - printf %s "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" + printf %s\\n "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" fi } } @@ -75,7 +75,7 @@ def ctags-generate -docstring 'Generate tag file asynchronously' %{ msg="tags generation failed" fi - printf %s "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session} + printf %s\\n "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } } diff --git a/rc/base/dlang.kak b/rc/base/dlang.kak index b1e1b7be..b8de00c4 100644 --- a/rc/base/dlang.kak +++ b/rc/base/dlang.kak @@ -53,7 +53,7 @@ addhl -group /dlang/code regex "\b(this)\b\s*[^(]" 1:value decorators="disable|property|nogc|safe|trusted|system" # Add the language's grammar to the static completion list - printf %s "hook global WinSetOption filetype=dlang %{ + printf %s\\n "hook global WinSetOption filetype=dlang %{ set window static_words '${keywords}:${attributes}:${types}:${values}:${decorators}' }" | sed 's,|,:,g' diff --git a/rc/base/golang.kak b/rc/base/golang.kak index 7836ccc1..37d6c95d 100644 --- a/rc/base/golang.kak +++ b/rc/base/golang.kak @@ -36,7 +36,7 @@ addhl -group /golang/code regex %{-?([0-9]*\.(?!0[xX]))?\b([0-9]+|0[xX][0-9a-fA- values="false|true|nil" # Add the language's grammar to the static completion list - printf %s "hook global WinSetOption filetype=golang %{ + printf %s\\n "hook global WinSetOption filetype=golang %{ set window static_words '${keywords}:${attributes}:${types}:${values}' }" | sed 's,|,:,g' diff --git a/rc/base/lua.kak b/rc/base/lua.kak index 83c861dc..c72ca832 100644 --- a/rc/base/lua.kak +++ b/rc/base/lua.kak @@ -35,12 +35,12 @@ addhl -group /lua/code regex \b(and|break|do|else|elseif|end|false|for|function| def lua-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ case $kak_buffile in *spec/*_spec.lua) - altfile=$(eval printf %s $(printf %s $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) - [ ! -f $altfile ] && printf %s "echo -color Error 'implementation file not found'" && exit + altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) + [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit ;; *.lua) path=$kak_buffile - dirs=$(while [ $path ]; do printf %s $path; path=${path%/*}; done | tail -n +2) + dirs=$(while [ $path ]; do printf %s\\n $path; path=${path%/*}; done | tail -n +2) for dir in $dirs; do altdir=$dir/spec if [ -d $altdir ]; then @@ -48,13 +48,13 @@ def lua-alternative-file -docstring 'Jump to the alternate file (implementation break fi done - [ ! -d $altdir ] && printf %s "echo -color Error 'spec/ not found'" && exit + [ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit ;; *) - printf %s "echo -color Error 'alternative file not found'" && exit + echo "echo -color Error 'alternative file not found'" && exit ;; esac - printf %s "edit $altfile" + printf %s\\n "edit $altfile" }} def -hidden _lua_filter_around_selections %{ diff --git a/rc/base/perl.kak b/rc/base/perl.kak index 02d67413..8ca8b624 100644 --- a/rc/base/perl.kak +++ b/rc/base/perl.kak @@ -44,7 +44,7 @@ addhl -group /perl/comment fill comment values="ARGV|STDERR|STDOUT|ARGVOUT|STDIN|__DATA__|__END__|__FILE__|__LINE__|__PACKAGE__" # Add the language's grammar to the static completion list - printf %s "hook global WinSetOption filetype=perl %{ + printf %s\\n "hook global WinSetOption filetype=perl %{ set window static_words '${keywords}:${attributes}:${values}' }" | sed 's,|,:,g' diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak index ae008c02..4e1b8961 100644 --- a/rc/base/ruby.kak +++ b/rc/base/ruby.kak @@ -65,7 +65,7 @@ addhl -group /ruby/code regex \b([A-Za-z]\w*:)|([$@][A-Za-z]\w*)|(\W\K:[A-Za-z]\ meta="require|include" # Add the language's grammar to the static completion list - printf %s "hook global WinSetOption filetype=ruby %{ + printf %s\\n "hook global WinSetOption filetype=ruby %{ set window static_words '${keywords}:${attributes}:${values}:${meta}' }" | sed 's,|,:,g' diff --git a/rc/base/spell.kak b/rc/base/spell.kak index bacff0c7..00bcdae3 100644 --- a/rc/base/spell.kak +++ b/rc/base/spell.kak @@ -5,13 +5,13 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe try %{ addhl ranges 'spell_regions' } %sh{ file=$(mktemp -d -t kak-spell.XXXXXXXX)/buffer - printf %s "write ${file}" - printf %s "set buffer spell_tmp_file ${file}" + printf %s\\n "write ${file}" + printf %s\\n "set buffer spell_tmp_file ${file}" } %sh{ if [ $# -ge 1 ]; then if [ ${#1} -ne 2 -a ${#1} -ne 5 ]; then - printf %s "echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)" + echo 'echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)' rm -r $(dirname $kak_opt_spell_tmp_file) exit 1 else @@ -25,20 +25,20 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe while read line; do case $line in \&*) - begin=$(printf %s "$line" | cut -d ' ' -f 4 | sed 's/:$//') + begin=$(printf %s\\n "$line" | cut -d ' ' -f 4 | sed 's/:$//') ;& '#'*) - word=$(printf %s "$line" | cut -d ' ' -f 2) - begin=${begin:-$(printf %s "$line" | cut -d ' ' -f 3)} + word=$(printf %s\\n "$line" | cut -d ' ' -f 2) + begin=${begin:-$(printf %s\\n "$line" | cut -d ' ' -f 3)} end=$((begin + ${#word})) - # printf %s "echo -debug -- line: $line_num, word: $word, begin: $begin, end: $end" + # printf %s\\n "echo -debug -- line: $line_num, word: $word, begin: $begin, end: $end" regions="$regions:$line_num.$begin,$line_num.$end|Error" ;; '') ((++line_num)) ;; *) ;; esac done - printf %s "set buffer spell_regions %{$regions}" + printf %s\\n "set buffer spell_regions %{$regions}" } rm -r $(dirname $kak_opt_spell_tmp_file) } diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index b2ad69fb..a481fa0d 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -77,7 +77,7 @@ def -hidden _c-family-indent-on-closing-curly-brace %[ maybe_at='' fi - printf '%s' ' + printf %s\\n ' addhl -group / regions -default code FT \ string %{MAYBEAT(?%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O" + echo 'exec ggi%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O' ;; pragma) - printf %s "exec ggi#pragmaonce" + echo 'exec ggi#pragmaonce' ;; *);; esac @@ -233,7 +233,7 @@ hook global BufNew .*\.(h|hh|hpp|hxx|H) _c-family-insert-include-guards decl str-list alt_dirs ".;.." def c-family-alternative-file -docstring "Jump to the alternate file (header/implementation)" %{ %sh{ - alt_dirs=$(printf %s "${kak_opt_alt_dirs}" | sed -e 's/;/ /g') + alt_dirs=$(printf %s\\n "${kak_opt_alt_dirs}" | sed -e 's/;/ /g') file=$(basename "${kak_buffile}") dir=$(dirname "${kak_buffile}") @@ -257,13 +257,13 @@ def c-family-alternative-file -docstring "Jump to the alternate file (header/imp done ;; *) - printf %s "echo -color Error 'extension not recognized'" + echo "echo -color Error 'extension not recognized'" exit ;; esac if [ -f ${altname} ]; then - printf %s "edit '${altname}'" + printf %s\\n "edit '${altname}'" else - printf %s "echo -color Error 'alternative file not found'" + echo "echo -color Error 'alternative file not found'" fi }} diff --git a/rc/core/commenting.kak b/rc/core/commenting.kak index 9cf9b11b..8cec5de7 100644 --- a/rc/core/commenting.kak +++ b/rc/core/commenting.kak @@ -8,18 +8,18 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{ %sh{ function exec_proof { ## Replace the '<' sign that is interpreted differently in `exec` - printf %s "$@" | sed 's,<,,g' + printf %s\\n "$@" | sed 's,<,,g' } readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%%:*}") readonly closing=$(exec_proof "${kak_opt_comment_selection_chars##*:}") if [ -z "${opening}" ] || [ -z "${closing}" ]; then - printf %s "The \`comment_selection_chars\` variable is empty, couldn't comment the selection" >&2 + echo "echo -debug 'The \`comment_selection_chars\` variable is empty, could not comment the selection'" exit fi - printf %s "try %{ + printf %s\\n "try %{ ## The selection is empty exec -draft %{\A[\h\v\n]*\z} @@ -43,11 +43,11 @@ def comment-line -docstring "Comment/uncomment the current line" %{ readonly opening_escaped="\Q${opening}\E" if [ -z "${opening}" ]; then - printf %s "The \`comment_line_chars\` variable is empty, couldn't comment the line" >&2 + echo "echo -debug 'The \`comment_line_chars\` variable is empty, could not comment the line'" exit fi - printf %s " + printf %s\\n " ## Select the content of the line, without indentation exec %{I} diff --git a/rc/core/doc.kak b/rc/core/doc.kak index 26c404ae..066f0fc8 100644 --- a/rc/core/doc.kak +++ b/rc/core/doc.kak @@ -10,7 +10,7 @@ def -hidden -params 1..2 _doc-open %{ rm ${manout} if [ "${retval}" -eq 0 ]; then - printf %s " + printf %s\\n " edit! -scratch '*doc*' exec |cat${colout}gg nop %sh{rm ${colout}} @@ -18,11 +18,11 @@ def -hidden -params 1..2 _doc-open %{ " if [ $# -gt 1 ]; then - needle=$(printf %s "$2" | sed 's,<,,g') - printf %s "try %{ exec '%(?i)^\h+[^\n]*?\Q${needle}\E\'' } catch %{ exec gg }" + needle=$(printf %s\\n "$2" | sed 's,<,,g') + printf %s\\n "try %{ exec '%(?i)^\h+[^\n]*?\Q${needle}\E\'' } catch %{ exec gg }" fi else - printf %s "echo -color Error %{doc '$@' failed: see *debug* buffer for details}" + printf %s\\n "echo -color Error %{doc '$@' failed: see *debug* buffer for details}" rm ${colout} fi } @@ -31,7 +31,7 @@ def -hidden -params 1..2 _doc-open %{ def -params 1..2 \ -shell-completion %{ find "${kak_runtime}/../doc/kak/manpages/" -type f -iname "*$@*.gz" -printf '%f\n' | while read l; do - printf %s "${l%.*}" + printf %s\\n "${l%.*}" done } \ doc -docstring "Open a buffer containing the documentation about a given subject" %{ @@ -40,10 +40,10 @@ def -params 1..2 \ shift if [ ! -f "${PATH_DOC}" ]; then - printf %s "echo -color Error No such doc file: ${PATH_DOC}" + printf %s\\n "echo -color Error No such doc file: ${PATH_DOC}" exit fi - printf %s "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@" + printf %s\\n "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@" } } diff --git a/rc/core/formatter.kak b/rc/core/formatter.kak index 38985dc4..8dbbf42f 100644 --- a/rc/core/formatter.kak +++ b/rc/core/formatter.kak @@ -6,9 +6,9 @@ def format -docstring "Format the entire buffer with an external utility" %{ readonly x=$((kak_cursor_column - 1)) readonly y="${kak_cursor_line}" - printf %s "exec -draft %{%|${kak_opt_formatcmd// /}}" + printf %s\\n "exec -draft %{%|${kak_opt_formatcmd// /}}" ## Try to restore the position of the cursor as it was prior to formatting - printf %s "exec gg ${y}g ${x}l" + printf %s\\n "exec gg ${y}g ${x}l" fi } } diff --git a/rc/core/grep.kak b/rc/core/grep.kak index 0745a7bf..e1cddf03 100644 --- a/rc/core/grep.kak +++ b/rc/core/grep.kak @@ -12,7 +12,7 @@ def -params .. -file-completion \ ( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & fi - printf %s "eval -try-client '$kak_opt_toolsclient' %{ + printf %s\\n "eval -try-client '$kak_opt_toolsclient' %{ edit! -fifo ${output} -scroll *grep* set buffer filetype grep set buffer _grep_current_line 0 diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index 81e556b9..ca32c4fd 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -16,7 +16,7 @@ addhl -group / regions -default code kakrc \ values="default|black|red|green|yellow|blue|magenta|cyan|white" # Add the language's grammar to the static completion list - printf %s "hook global WinSetOption filetype=kak %{ + printf %s\\n "hook global WinSetOption filetype=kak %{ set window static_words '${keywords}:${values}' }" | sed 's,|,:,g' diff --git a/rc/core/make.kak b/rc/core/make.kak index 9f6fdc2c..a08c9b1f 100644 --- a/rc/core/make.kak +++ b/rc/core/make.kak @@ -7,7 +7,7 @@ def -params .. make -docstring "Make utility wrapper" %{ %sh{ mkfifo ${output} ( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - printf %s "eval -try-client '$kak_opt_toolsclient' %{ + printf %s\\n "eval -try-client '$kak_opt_toolsclient' %{ edit! -fifo ${output} -scroll *make* set buffer filetype make set buffer _make_current_error_line 0 diff --git a/rc/core/man.kak b/rc/core/man.kak index 6529646b..f59872f7 100644 --- a/rc/core/man.kak +++ b/rc/core/man.kak @@ -25,25 +25,25 @@ def -hidden -params .. _man %{ %sh{ col -b -x > ${colout} < ${manout} rm ${manout} if [ "${retval}" -eq 0 ]; then - printf %s "edit! -scratch '*man*' + printf %s\\n "edit! -scratch '*man*' exec |cat${colout}gk nop %sh{rm ${colout}} set buffer filetype man" else - printf %s "echo -color Error %{man '$@' failed: see *debug* buffer for details }" + printf %s\\n "echo -color Error %{man '$@' failed: see *debug* buffer for details }" rm ${colout} fi } } def -params .. \ -shell-completion %{ - prefix=$(printf %s "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null) + prefix=$(printf %s\\n "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null) for page in /usr/share/man/*/${prefix}*.[1-8]*; do candidate=$(basename ${page%%.[1-8]*}) - pagenum=$(printf %s "$page" | sed 's,^.*\.\([1-8].*\)\..*$,\1,') + pagenum=$(printf %s\\n "$page" | sed 's,^.*\.\([1-8].*\)\..*$,\1,') case $candidate in *\*) ;; - *) printf %s\\n $candidate\($pagenum\);; + *) printf %s\\n "$candidate($pagenum)";; esac done } \ @@ -56,5 +56,5 @@ def -params .. \ subject=${subject%%\(*} fi - printf %s "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject" + printf %s\\n "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject" } } diff --git a/rc/core/python.kak b/rc/core/python.kak index 7ba8035f..7172440b 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -35,7 +35,7 @@ addhl -group /python/comment fill comment types="bool|buffer|bytearray|complex|dict|file|float|frozenset|int|list|long|memoryview|object|set|str|tuple|unicode|xrange" # Add the language's grammar to the static completion list - printf %s "hook global WinSetOption filetype=python %{ + printf %s\\n "hook global WinSetOption filetype=python %{ set window static_words '${values}:${meta}:${keywords}:${types}' }" | sed 's,|,:,g' diff --git a/rc/core/tmux.kak b/rc/core/tmux.kak index 7e4aa1b7..3b469ac7 100644 --- a/rc/core/tmux.kak +++ b/rc/core/tmux.kak @@ -5,8 +5,10 @@ hook global KakBegin .* %{ %sh{ if [ -n "$TMUX" ]; then - printf %s "alias global focus tmux-focus" - printf %s "alias global new tmux-new-horizontal" + echo " + alias global focus tmux-focus + alias global new tmux-new-horizontal + " fi } } @@ -15,7 +17,7 @@ hook global KakBegin .* %{ def -hidden -params 1.. tmux-new-impl %{ %sh{ if [ -z "$TMUX" ]; then - printf %s "echo -color Error This command is only available in a tmux session" + echo "echo -color Error 'This command is only available in a tmux session'" exit fi tmux_args="$1" @@ -41,9 +43,9 @@ def -docstring "focus given client" \ -params 0..1 -client-completion \ tmux-focus %{ %sh{ if [ $# -gt 1 ]; then - printf %s "echo -color Error 'too many arguments, use focus [client]'" + echo "echo -color Error 'too many arguments, use focus [client]'" elif [ $# -eq 1 ]; then - printf %s "eval -client '$1' focus" + printf %s\\n "eval -client '$1' focus" elif [ -n "${kak_client_env_TMUX}" ]; then TMUX="${kak_client_env_TMUX}" tmux select-pane -t "${kak_client_env_TMUX_PANE}" > /dev/null fi diff --git a/rc/core/x11.kak b/rc/core/x11.kak index 7d1ea77f..bf932298 100644 --- a/rc/core/x11.kak +++ b/rc/core/x11.kak @@ -12,7 +12,7 @@ decl str termcmd %sh{ 'xfce4-terminal -e ' ; do terminal=${termcmd%% *} if which $terminal > /dev/null 2>&1; then - printf %s "'$termcmd'" + printf %s\\n "'$termcmd'" exit fi done @@ -23,7 +23,7 @@ def -docstring 'create a new kak client for current session' \ -command-completion \ x11-new %{ %sh{ if [ -z "${kak_opt_termcmd}" ]; then - printf %s "echo -color Error 'termcmd option is not set'" + echo "echo -color Error 'termcmd option is not set'" exit fi if [ $# -ne 0 ]; then kakoune_params="-e '$@'"; fi @@ -34,9 +34,9 @@ def -docstring 'focus given client\'s window' \ -params 0..1 -client-completion \ x11-focus %{ %sh{ if [ $# -gt 1 ]; then - printf %s "echo -color Error 'too many arguments, use focus [client]'" + echo "echo -color Error 'too many arguments, use focus [client]'" elif [ $# -eq 1 ]; then - printf %s "eval -client '$1' focus" + printf %s\\n "eval -client '$1' focus" else xdotool windowactivate $kak_client_env_WINDOWID > /dev/null fi diff --git a/rc/extra/autorestore.kak b/rc/extra/autorestore.kak index a809f15d..8f5acbf2 100644 --- a/rc/extra/autorestore.kak +++ b/rc/extra/autorestore.kak @@ -14,12 +14,12 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi latest_backup_path=$(find "${buffer_dirname}" -maxdepth 1 -type f -readable -newer "${kak_bufname}" -name "\.${buffer_basename}\.kak\.*" -printf '%A@/%p\n' 2>/dev/null \ | sort -n -t. -k1 | sed -nr 's/^[^\/]+\///;$p') if [ -z "${latest_backup_path}" ]; then - printf %s "eval -draft %{ autorestore-purge-backups }"; - exit; + echo 'eval -draft %{ autorestore-purge-backups }' + exit fi ## Replace the content of the buffer with the content of the backup file - printf %s " + printf %s\\n " exec -draft %{ %d!cat${latest_backup_path}d } echo -color Information 'Backup restored' " @@ -28,7 +28,7 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi ## the current buffer has been saved ## If the autorestore_purge_restored option has been unset right after the ## buffer was restored, do not remove the backup - printf %s " + printf %s\\n " hook -group autorestore global BufWritePost (.+/)?${kak_bufname} %{ nop %sh{ if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; then diff --git a/rc/extra/clang.kak b/rc/extra/clang.kak index 6658fa33..f4c51f14 100644 --- a/rc/extra/clang.kak +++ b/rc/extra/clang.kak @@ -9,14 +9,14 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe %sh{ dir=$(mktemp -d -t kak-clang.XXXXXXXX) mkfifo ${dir}/fifo - printf %s "set buffer clang_tmp_dir ${dir}" - printf %s "write ${dir}/buf" + printf %s\\n "set buffer clang_tmp_dir ${dir}" + printf %s\\n "write ${dir}/buf" } # end the previous %sh{} so that its output gets interpreted by kakoune # before launching the following as a background task. %sh{ dir=${kak_opt_clang_tmp_dir} - printf %s "eval -draft %{ + printf %s\\n "eval -draft %{ edit! -fifo ${dir}/fifo *clang-output* set buffer filetype make set buffer _make_current_error_line 0 @@ -72,11 +72,11 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe print id "|" docstrings[id] "|" menu } }' | paste -s -d ':' | sed -e "s/\\\\n/\\n/g; s/'/\\\\'/g") - printf %s "eval -client ${kak_client} echo 'clang completion done' + printf %s\\n "eval -client ${kak_client} echo 'clang completion done' set '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 "eval -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} + printf %s\\n "eval -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} fi flags=$(cat ${dir}/stderr | sed -rne " @@ -90,7 +90,7 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe sed -e "s||${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo - printf %s "set 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}} + printf %s\\n "set 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}} set 'buffer=${kak_buffile}' clang_errors '${errors}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } @@ -102,14 +102,9 @@ def -hidden clang-show-completion-info %[ try %[ eval -draft %[ exec '{(^\(b' %sh[ -<<<<<<< f877c388fea0e794f663d62e3508c5d11832601e - desc=$(echo "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D") -======= - # desc=$(printf %s "${kak_opt_clang_completions}" | sed -e 's/\([^\\]\):/\1\n/g;' | sed -ne "/^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\:/:/g; p }") - desc=$(printf %s "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D") ->>>>>>> Replace non POSIX calls to `echo` with `printf %s` + desc=$(printf %s\\n "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D") if [ -n "$desc" ]; then - printf %s "eval -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" + printf %s\\n "eval -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" fi ] ] ] ] @@ -128,21 +123,15 @@ def clang-enable-autocomplete -docstring "Enable completion with clang" %{ } def clang-disable-autocomplete -docstring "Disable automatic clang completion" %{ - set window completers %sh{ printf %s "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' } + set window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=clang_completions://g' } rmhooks window clang-autocomplete unalias window complete clang-complete } def -hidden clang-show-error-info %{ %sh{ -<<<<<<< f877c388fea0e794f663d62e3508c5d11832601e - desc=$(printf %s "${kak_opt_clang_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }") + desc=$(printf %s\\n "${kak_opt_clang_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }") if [ -n "$desc" ]; then - echo "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" -======= - printf %s "${kak_opt_clang_errors}" | grep "^${kak_cursor_line},.*" | if read line; then - desc=$(printf %s "${line}" | sed -e "s/^[[:digit:]]\+,//g; s/'/\\\\'/g") - printf %s "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" ->>>>>>> Replace non POSIX calls to `echo` with `printf %s` + printf %s\\n "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" fi } } @@ -169,9 +158,9 @@ def clang-diagnostics-next -docstring "Jump to the next line that contains an er done line=$((line == -1 ? first_line : line)) if [ ${line} -ne -1 ]; then - printf %s "exec ${line} g" + printf %s\\n "exec ${line} g" else - printf %s 'echo -color Error no next clang diagnostic' + echo 'echo -color Error no next clang diagnostic' fi ) } } diff --git a/rc/extra/editorconfig.kak b/rc/extra/editorconfig.kak index b7734d99..7bfcfe0b 100644 --- a/rc/extra/editorconfig.kak +++ b/rc/extra/editorconfig.kak @@ -1,16 +1,16 @@ def editorconfig-load -docstring "Set indentation options according to editorconfig file" %{ %sh{ - command -v editorconfig >/dev/null 2>&1 || { printf %s "echo -color Error The editorconfig tool could not be found"; exit 1; } + command -v editorconfig >/dev/null 2>&1 || { echo 'echo -color Error The editorconfig tool could not be found'; exit 1; } editorconfig $kak_buffile | awk -F= -- \ '{ if ($1 == "indent_style" && $2 == "tab") { - print "set buffer indentwidth 0" + print "set buffer indentwidth 0" } else if ($1 == "indent_size" && $2 ~ "[0-9]+") { print "set buffer indentwidth", $2 } else if ($1 == "tab_width" && $2 ~ "[0-9]+") { - print "set buffer tabstop", $2 + print "set buffer tabstop", $2 } else if ($1 == "end_of_line") { if ($2 == "lf" || $2 == "crlf") { diff --git a/rc/extra/flake8.kak b/rc/extra/flake8.kak index cc390041..c07c1259 100644 --- a/rc/extra/flake8.kak +++ b/rc/extra/flake8.kak @@ -44,7 +44,7 @@ def flake8-lint -params 0..1 -docstring "Lint the contents of the current buffer } def -hidden flake8-show-error-info %{ %sh{ - desc=$(printf %s "${kak_opt_flake8_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }") + desc=$(printf %s\\n "${kak_opt_flake8_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }") if [ -n "$desc" ]; then echo "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" fi diff --git a/rc/extra/git-tools.kak b/rc/extra/git-tools.kak index d3948ee7..b088df51 100644 --- a/rc/extra/git-tools.kak +++ b/rc/extra/git-tools.kak @@ -26,10 +26,10 @@ decl line-flags git_diff_flags face GitBlame default,magenta def -params 1.. \ - -docstring %sh{printf "%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}"} \ + -docstring %sh{printf '%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}'} \ -shell-completion %{ shift $(expr ${kak_token_to_complete}) - prefix=$(printf %s "${1}" | cut -c1-${kak_pos_in_token} 2>/dev/null) + prefix=$(printf %s\\n "${1}" | cut -c1-${kak_pos_in_token} 2>/dev/null) ( for cmd in add rm blame commit checkout diff hide-blame log show show-diff status update-diff; do expr "${cmd}" : "^\(${prefix}.*\)$" @@ -48,7 +48,7 @@ def -params 1.. \ mkfifo ${output} ( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - printf %s "eval -try-client '$kak_opt_docsclient' %{ + printf %s\\n "eval -try-client '$kak_opt_docsclient' %{ edit! -fifo ${output} *git* set buffer filetype '${filetype}' hook -group fifo buffer BufCloseFifo .* %{ @@ -60,7 +60,7 @@ def -params 1.. \ run_git_blame() { ( - printf %s "eval -client '$kak_client' %{ + printf %s\\n "eval -client '$kak_client' %{ try %{ addhl flag_lines GitBlame git_blame_flags } set buffer=$kak_bufname git_blame_flags '$kak_timestamp' }" | kak -p ${kak_session} @@ -120,9 +120,9 @@ def -params 1.. \ # Handle case where message needs not to be edited if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit"; then if git commit "$@" > /dev/null 2>&1; then - printf %s 'echo -color Information Commit succeeded' + echo 'echo -color Information Commit succeeded' else - printf %s 'echo -color Error Commit failed' + echo 'echo -color Error Commit failed' fi exit fi <<-EOF @@ -132,13 +132,13 @@ def -params 1.. \ # fails, and generate COMMIT_EDITMSG GIT_EDITOR='' EDITOR='' git commit > /dev/null 2>&1 msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG" - printf %s "edit '$msgfile' + printf %s\\n "edit '$msgfile' hook buffer BufWritePost '.*\Q$msgfile\E' %{ %sh{ if git commit -F '$msgfile' --cleanup=strip $@ > /dev/null; then - printf %s 'eval -client $kak_client echo -color Information Commit succeeded' - printf %s 'delbuf' + printf %s\\n 'eval -client $kak_client echo -color Information Commit succeeded' + printf %s\\n 'delbuf' else - printf %s 'eval -client $kak_client echo -color Error Commit failed' + printf %s\\n 'eval -client $kak_client echo -color Error Commit failed' fi } }" } @@ -147,13 +147,13 @@ def -params 1.. \ show|log|diff|status) show_git_cmd_output "$@" ;; blame) shift; run_git_blame "$@" ;; hide-blame) - printf %s "try %{ + printf %s\\n "try %{ set buffer=$kak_bufname git_blame_flags '' rmhl hlflags_git_blame_flags }" ;; show-diff) - printf %s "try %{ addhl flag_lines default,black git_diff_flags }" + echo 'try %{ addhl flag_lines default,black git_diff_flags }' update_diff ;; update-diff) update_diff ;; @@ -165,19 +165,19 @@ def -params 1.. \ add) name="${2:-${kak_buffile}}" if git add -- "${name}" > /dev/null 2>&1; then - printf %s "echo -color Information 'git: added ${name}'" + printf %s\\n "echo -color Information 'git: added ${name}'" else - printf %s "echo -color Error 'git: unable to add ${name}'" + printf %s\\n "echo -color Error 'git: unable to add ${name}'" fi ;; rm) name="${2:-${kak_buffile}}" if git rm -- "${name}" > /dev/null 2>&1; then - printf %s "echo -color Information 'git: removed ${name}'" + printf %s\\n "echo -color Information 'git: removed ${name}'" else - printf %s "echo -color Error 'git: unable to remove ${name}'" + printf %s\\n "echo -color Error 'git: unable to remove ${name}'" fi ;; - *) printf %s "echo -color Error %{unknown git command '$1'}"; exit ;; + *) printf %s\\n "echo -color Error %{unknown git command '$1'}"; exit ;; esac }} diff --git a/rc/extra/jedi.kak b/rc/extra/jedi.kak index 3e1d98ed..bc295fe9 100644 --- a/rc/extra/jedi.kak +++ b/rc/extra/jedi.kak @@ -6,12 +6,12 @@ def jedi-complete -docstring "Complete the current selection with jedi" %{ %sh{ dir=$(mktemp -d -t kak-jedi.XXXXXXXX) mkfifo ${dir}/fifo - printf %s "set buffer jedi_tmp_dir ${dir}" - printf %s "write ${dir}/buf" + printf %s\\n "set buffer jedi_tmp_dir ${dir}" + printf %s\\n "write ${dir}/buf" } %sh{ dir=${kak_opt_jedi_tmp_dir} - printf %s "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" + printf %s\\n "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" ( cd $(dirname ${kak_buffile}) header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" @@ -23,8 +23,8 @@ def jedi-complete -docstring "Complete the current selection with jedi" %{ print ':'.join([(str(c.name).replace("|", "\\|") + "|" + str(c.docstring()).replace("|", "\\|")).replace(":", "\\:") + "|" + str(c.name).replace("|", "\\|") for c in script.completions()]).replace("'", r"\\\\'") END ) - printf %s "${compl}" > /tmp/kak-jedi-out - printf %s "eval -client ${kak_client} 'echo completed; set %{buffer=${kak_buffile}} jedi_completions \'${header}:${compl}\''" | kak -p ${kak_session} + printf %s\\n "${compl}" > /tmp/kak-jedi-out + printf %s\\n "eval -client ${kak_client} 'echo completed; set %{buffer=${kak_buffile}} jedi_completions \'${header}:${compl}\''" | kak -p ${kak_session} rm -r ${dir} ) > /dev/null 2>&1 < /dev/null & } @@ -41,7 +41,7 @@ def jedi-enable-autocomplete -docstring "Add jedi completion candidates to the c } def jedi-disable-autocomplete -docstring "Disable jedi completion" %{ - set window completers %sh{ printf %s "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' } + set window completers %sh{ printf %s\\n "'${kak_opt_completers}'" | sed -e 's/option=jedi_completions://g' } rmhooks window jedi-autocomplete unalias window complete jedi-complete } diff --git a/rc/extra/modeline.kak b/rc/extra/modeline.kak index b31e3856..e1d2a5a7 100644 --- a/rc/extra/modeline.kak +++ b/rc/extra/modeline.kak @@ -35,17 +35,17 @@ def -hidden _modeline-parse %{ case "${value}" in unix) tr="eolformat lf";; dos) tr="eolformat crlf";; - *) printf %s "Unsupported file format: ${value}" >&2;; + *) printf %s\\n "echo -debug 'Unsupported file format: ${value}'";; esac ;; ft) ;& filetype) tr="filetype ${value}";; bomb) tr="BOM utf8";; nobomb) tr="BOM none";; - *) printf %s "Unsupported vim variable: ${key}" >&2;; + *) printf %s\\n "echo -debug 'Unsupported vim variable: ${key}'";; esac - [ -n "${tr}" ] && printf %s "set buffer ${tr}" + [ -n "${tr}" ] && printf %s\\n "set buffer ${tr}" } # Pass a few whitelisted options to kakoune directly @@ -63,12 +63,12 @@ def -hidden _modeline-parse %{ BOM ) - printf %s "${OPTS_ALLOWED[@]}" | grep -qw "${key}" || { - printf %s "Unsupported kakoune variable: ${key}" >&2; + printf %s\\n "${OPTS_ALLOWED[@]}" | grep -qw "${key}" || { + printf %s\\n "echo -debug 'Unsupported kakoune variable: ${key}'"; return; } - printf %s "set buffer ${key} ${value}" + printf %s\\n "set buffer ${key} ${value}" } # The following subshell will keep the actual options of the modeline, and strip: @@ -77,7 +77,7 @@ def -hidden _modeline-parse %{ # It will also convert the ':' seperators beween the option=value pairs # More info: http://vimdoc.sourceforge.net/htmldoc/options.html#modeline options=( - $(printf %s "${kak_selection}" | sed -r \ + $(printf %s\\n "${kak_selection}" | sed -r \ -e 's/^(.+\s\w+:\s?(set?)?\s)//' \ -e 's/:?\s[^a-zA-Z0-9_=-]+$//' \ -e 's/:/ /g') @@ -88,7 +88,7 @@ def -hidden _modeline-parse %{ *vim:*) type_selection="vim";; *kak:*) ;& *kakoune:*) type_selection="kakoune";; - *) printf %s "echo -debug Unsupported modeline format";; + *) echo "echo -debug Unsupported modeline format";; esac [ -n "${type_selection}" ] || exit 1 @@ -101,7 +101,7 @@ def -hidden _modeline-parse %{ kakoune) tr=$(translate_opt_kakoune "${name_option}" "${value_option}");; esac - [ -n "${tr}" ] && printf %s "${tr}" + [ -n "${tr}" ] && printf %s\\n "${tr}" done } } diff --git a/rc/extra/moon.kak b/rc/extra/moon.kak index b18e91e0..4edb36b6 100644 --- a/rc/extra/moon.kak +++ b/rc/extra/moon.kak @@ -39,12 +39,12 @@ addhl -group /moon/code regex \b(and|break|catch|class|continue|do|else(if)?|exp def moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ case $kak_buffile in *spec/*_spec.moon) - altfile=$(eval printf %s $(printf %s $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) - [ ! -f $altfile ] && printf %s "echo -color Error 'implementation file not found'" && exit + altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) + [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit ;; *.moon) path=$kak_buffile - dirs=$(while [ $path ]; do printf %s $path; path=${path%/*}; done | tail -n +2) + dirs=$(while [ $path ]; do printf %s\\n $path; path=${path%/*}; done | tail -n +2) for dir in $dirs; do altdir=$dir/spec if [ -d $altdir ]; then @@ -52,13 +52,13 @@ def moon-alternative-file -docstring 'Jump to the alternate file (implementation break fi done - [ ! -d $altdir ] && printf %s "echo -color Error 'spec/ not found'" && exit + [ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit ;; *) - printf %s "echo -color Error 'alternative file not found'" && exit + echo "echo -color Error 'alternative file not found'" && exit ;; esac - printf %s "edit $altfile" + printf %s\\n "edit $altfile" }} def -hidden _moon_filter_around_selections %{ diff --git a/rc/extra/tmux-repl.kak b/rc/extra/tmux-repl.kak index 7d5b36d6..f576bcab 100644 --- a/rc/extra/tmux-repl.kak +++ b/rc/extra/tmux-repl.kak @@ -4,8 +4,10 @@ hook global KakBegin .* %{ %sh{ if [ -n "$TMUX" ]; then - printf %s "alias global repl tmux-repl-horizontal" - printf %s "alias global send-text tmux-send-text" + echo " + alias global repl tmux-repl-horizontal + alias global send-text tmux-send-text + " fi } } @@ -13,7 +15,7 @@ hook global KakBegin .* %{ def -hidden -params 1..2 tmux-repl-impl %{ %sh{ if [ -z "$TMUX" ]; then - printf %s "echo -color Error This command is only available in a tmux session" + echo "echo -color Error This command is only available in a tmux session" exit fi tmux_args="$1" diff --git a/rc/extra/x11-repl.kak b/rc/extra/x11-repl.kak index 0d03ecd1..1cf2db3f 100644 --- a/rc/extra/x11-repl.kak +++ b/rc/extra/x11-repl.kak @@ -4,7 +4,7 @@ def -docstring 'create a new window for repl interaction' \ -command-completion \ x11-repl %{ %sh{ if [ -z "${kak_opt_termcmd}" ]; then - printf %s "echo -color Error 'termcmd option is not set'" + echo "echo -color Error 'termcmd option is not set'" exit fi if [ $# -eq 0 ]; then cmd="bash"; else cmd="$1"; fi @@ -13,7 +13,7 @@ def -docstring 'create a new window for repl interaction' \ def x11-send-text -docstring "send selected text to the repl window" %{ nop %sh{ - printf %s "${kak_selection}" | xsel -i + printf %s\\n "${kak_selection}" | xsel -i wid=$(xdotool getactivewindow) xdotool search --name kak_repl_window windowactivate xdotool key --clearmodifiers "Shift+Insert"