diff --git a/colors/base16.kak b/colors/base16.kak index 055b5d95f..b46e77abe 100644 --- a/colors/base16.kak +++ b/colors/base16.kak @@ -2,7 +2,7 @@ ## base16.kak by lenormf ## -%sh{ +evaluate-commands %sh{ black_lighterer='rgb:383838' black_lighter='rgb:2D2D2D' black_light='rgb:1C1C1C' diff --git a/colors/gruvbox.kak b/colors/gruvbox.kak index 56203bb6b..d17abc811 100644 --- a/colors/gruvbox.kak +++ b/colors/gruvbox.kak @@ -1,6 +1,6 @@ # gruvbox theme -%sh{ +evaluate-commands %sh{ gray="rgb:928374" red="rgb:fb4934" green="rgb:b8bb26" diff --git a/colors/lucius.kak b/colors/lucius.kak index 8ca99c6eb..670888b41 100644 --- a/colors/lucius.kak +++ b/colors/lucius.kak @@ -1,6 +1,6 @@ # lucius theme -%sh{ +evaluate-commands %sh{ # first we define the lucius colors as named colors lucius_darker_grey="rgb:303030" lucius_dark_grey="rgb:444444" diff --git a/colors/reeder.kak b/colors/reeder.kak index dd19cd24c..c1cb083b3 100644 --- a/colors/reeder.kak +++ b/colors/reeder.kak @@ -3,7 +3,7 @@ ## a light theme inspired after https://github.com/hyspace/st2-reeder-theme ## -%sh{ +evaluate-commands %sh{ white="rgb:f9f8f6" white_light="rgb:f6f5f0" black="rgb:383838" diff --git a/colors/solarized-dark.kak b/colors/solarized-dark.kak index 25134f7c6..3b92c709e 100644 --- a/colors/solarized-dark.kak +++ b/colors/solarized-dark.kak @@ -1,6 +1,6 @@ # Solarized Dark -%sh{ +evaluate-commands %sh{ base03='rgb:002b36' base02='rgb:073642' base01='rgb:586e75' diff --git a/colors/solarized-light.kak b/colors/solarized-light.kak index 1ffefeb1b..831d5d326 100644 --- a/colors/solarized-light.kak +++ b/colors/solarized-light.kak @@ -1,6 +1,6 @@ # Solarized Light -%sh{ +evaluate-commands %sh{ base03='rgb:002b36' base02='rgb:073642' base01='rgb:586e75' diff --git a/colors/tomorrow-night.kak b/colors/tomorrow-night.kak index 59065ff67..5e8b79364 100644 --- a/colors/tomorrow-night.kak +++ b/colors/tomorrow-night.kak @@ -2,7 +2,7 @@ ## Tomorrow-night, adapted by nicholastmosher ## -%sh{ +evaluate-commands %sh{ foreground="rgb:c5c8c6" background="rgb:272727" selection="rgb:373b41" diff --git a/colors/zenburn.kak b/colors/zenburn.kak index ac7f2ab96..c98828fa2 100644 --- a/colors/zenburn.kak +++ b/colors/zenburn.kak @@ -1,6 +1,6 @@ # zenburn theme -%sh{ +evaluate-commands %sh{ # define some named colors zentext="rgb:cfcfcf" zenselectionbg="rgb:3f7fcc" diff --git a/doc/interfacing.asciidoc b/doc/interfacing.asciidoc index 0d922b5be..4e8b883c6 100644 --- a/doc/interfacing.asciidoc +++ b/doc/interfacing.asciidoc @@ -55,7 +55,7 @@ The common pattern to do that is to use a fifo buffer: [source,bash] ----- -%sh{ +evaluate-commands %sh{ # Create a temporary fifo for communication output=$(mktemp -d -t kak-temp-XXXXXXXX)/fifo mkfifo ${output} @@ -113,7 +113,7 @@ decl str plugin_completions hook global BufSetOption filetype=my_filetype %{ set -add buff completers option=plugin_completions } -%sh{ +evaluate-commands %sh{ # ask Kakoune to write current buffer to temporary file filename=$(mktemp -t kak-temp.XXXXXXXX) echo "set buffer plugin_filename '$filename' diff --git a/doc/pages/changelog.asciidoc b/doc/pages/changelog.asciidoc index 679948d13..874e5214e 100644 --- a/doc/pages/changelog.asciidoc +++ b/doc/pages/changelog.asciidoc @@ -5,6 +5,9 @@ released versions. == Development version +* `%sh{...}` strings are not reparsed automatically anymore, they need + to go through an explicit `evaluate-commands` + * The `-allow-override` switch from `define-command` has been renamed `-override`. diff --git a/rc/base/autowrap.kak b/rc/base/autowrap.kak index 1f8ef8be7..6e6e371b5 100644 --- a/rc/base/autowrap.kak +++ b/rc/base/autowrap.kak @@ -21,7 +21,7 @@ define-command -hidden autowrap-cursor %{ evaluate-commands -save-regs '/"|^@m' } catch %{ ## if we're adding characters in the middle of a sentence, use ## the `fmtcmd` command to wrap the entire paragraph - %sh{ + evaluate-commands %sh{ if [ "${kak_opt_autowrap_format_paragraph}" = true ] \ && [ -n "${kak_opt_autowrap_fmtcmd}" ]; then format_cmd=$(printf %s "${kak_opt_autowrap_fmtcmd}" \ diff --git a/rc/base/ctags.kak b/rc/base/ctags.kak index 70069a19f..bfdefe217 100644 --- a/rc/base/ctags.kak +++ b/rc/base/ctags.kak @@ -23,7 +23,7 @@ define-command -params ..1 \ -docstring %{ctags-search []: jump to a symbol's definition If no symbol is passed then the current selection is used as symbol name} \ ctags-search \ - %{ %sh{ + %{ 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' | @@ -47,7 +47,7 @@ If no symbol is passed then the current selection is used as symbol name} \ define-command ctags-complete -docstring "Insert completion candidates for the current selection into the buffer's local variables" %{ evaluate-commands -draft %{ execute-keys hb^\w+$ - %sh{ { + nop %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\\n "set-option buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} @@ -58,7 +58,7 @@ define-command ctags-funcinfo -docstring "Display ctags information about a sele evaluate-commands -draft %{ try %{ execute-keys -no-hooks '[(;B[a-zA-Z_]+\(' - %sh{ + evaluate-commands %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\\n "evaluate-commands -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" @@ -81,7 +81,7 @@ declare-option -docstring "path to the directory in which the tags file will be define-command ctags-generate -docstring 'Generate tag file asynchronously' %{ echo -markup "{Information}launching tag generation in the background" - %sh{ { + nop %sh{ ( while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done trap 'rmdir .tags.kaklock' EXIT @@ -93,11 +93,11 @@ define-command ctags-generate -docstring 'Generate tag file asynchronously' %{ fi printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session} - } > /dev/null 2>&1 < /dev/null & } + ) > /dev/null 2>&1 < /dev/null & } } define-command ctags-update-tags -docstring 'Update tags for the given file' %{ - %sh{ { + nop %sh{ ( while ! mkdir .tags.kaklock 2>/dev/null; do sleep 1; done trap 'rmdir .tags.kaklock' EXIT @@ -113,5 +113,5 @@ define-command ctags-update-tags -docstring 'Update tags for the given file' %{ fi printf %s\\n "evaluate-commands -client $kak_client echo -markup '{Information}${msg}'" | kak -p ${kak_session} - } > /dev/null 2>&1 < /dev/null & } + ) > /dev/null 2>&1 < /dev/null & } } diff --git a/rc/base/d.kak b/rc/base/d.kak index 9cb995169..0b732eb5b 100644 --- a/rc/base/d.kak +++ b/rc/base/d.kak @@ -37,7 +37,7 @@ add-highlighter shared/d/code regex "\b(this)\b\s*[^(]" 1:value add-highlighter shared/d/code regex "((?:~|\b)this)\b\s*\(" 1:function add-highlighter shared/d/code regex '#\s*line\b.*' 0:meta -%sh{ +evaluate-commands %sh{ # Grammar keywords="abstract|alias|align|asm|assert|auto|body|break|case|cast" diff --git a/rc/base/file.kak b/rc/base/file.kak index ce947b19c..073e9ce0a 100644 --- a/rc/base/file.kak +++ b/rc/base/file.kak @@ -1,4 +1,4 @@ -hook global BufOpenFile .* %{ %sh{ +hook global BufOpenFile .* %{ evaluate-commands %sh{ if [ -z "${kak_opt_filetype}" ]; then mime=$(file -b --mime-type "${kak_buffile}") case "${mime}" in diff --git a/rc/base/go.kak b/rc/base/go.kak index 89bd3239c..61308f7b3 100644 --- a/rc/base/go.kak +++ b/rc/base/go.kak @@ -25,7 +25,7 @@ add-highlighter shared/go/comment fill comment add-highlighter shared/go/code regex %{-?([0-9]*\.(?!0[xX]))?\b([0-9]+|0[xX][0-9a-fA-F]+)\.?([eE][+-]?[0-9]+)?i?\b} 0:value -%sh{ +evaluate-commands %sh{ # Grammar keywords="break|default|func|interface|select|case|defer|go|map|struct" keywords="${keywords}|chan|else|goto|package|switch|const|fallthrough|if|range|type" diff --git a/rc/base/lint.kak b/rc/base/lint.kak index e02caa16c..0f1453f33 100644 --- a/rc/base/lint.kak +++ b/rc/base/lint.kak @@ -9,7 +9,7 @@ declare-option -hidden int lint_error_count declare-option -hidden int lint_warning_count define-command lint -docstring 'Parse the current buffer with a linter' %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-lint.XXXXXXXX) mkfifo "$dir"/fifo printf '%s\n' "evaluate-commands -no-hooks write -sync $dir/buf" @@ -72,7 +72,7 @@ define-command lint -docstring 'Parse the current buffer with a linter' %{ define-command -hidden lint-show %{ update-option buffer lint_errors - %sh{ + evaluate-commands %sh{ desc=$(printf '%s\n' "$kak_opt_lint_errors" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | sed -ne "/^$kak_cursor_line\.[^|]\+|.*/ { s/^[^|]\+|//g; s/'/\\\\'/g; s/\\\\:/:/g; p; }") if [ -n "$desc" ]; then @@ -97,7 +97,7 @@ define-command lint-disable -docstring "Disable automatic diagnostics of the cod define-command lint-next-error -docstring "Jump to the next line that contains an error" %{ update-option buffer lint_errors - %sh{ + evaluate-commands %sh{ printf '%s\n' "$kak_opt_lint_errors" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | { while IFS='|' read -r candidate rest do @@ -118,7 +118,7 @@ define-command lint-next-error -docstring "Jump to the next line that contains a define-command lint-previous-error -docstring "Jump to the previous line that contains an error" %{ update-option buffer lint_errors - %sh{ + evaluate-commands %sh{ printf '%s\n' "$kak_opt_lint_errors" | sed -e 's/\([^\\]\):/\1\n/g' | tail -n +2 | sort -t. -k1,1 -rn | { while IFS='|' read -r candidate rest do diff --git a/rc/base/lua.kak b/rc/base/lua.kak index 4fc145d7b..568708b7a 100644 --- a/rc/base/lua.kak +++ b/rc/base/lua.kak @@ -27,7 +27,7 @@ add-highlighter shared/lua/code regex \b(and|break|do|else|elseif|end|false|for| # Commands # ‾‾‾‾‾‾‾‾ -define-command lua-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ +define-command lua-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ evaluate-commands %sh{ case $kak_buffile in *spec/*_spec.lua) altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) diff --git a/rc/base/markdown.kak b/rc/base/markdown.kak index e5491ca14..154d76a22 100644 --- a/rc/base/markdown.kak +++ b/rc/base/markdown.kak @@ -11,7 +11,7 @@ hook global BufCreate .*[.](markdown|md|mkd) %{ # Highlighters # ‾‾‾‾‾‾‾‾‾‾‾‾ -%sh{ +evaluate-commands %sh{ languages=" c cabal clojure coffee cpp css cucumber d diff dockerfile fish gas go haml haskell html ini java javascript json julia kak kickstart latex diff --git a/rc/base/ocaml.kak b/rc/base/ocaml.kak index 1052e0573..07d0569b5 100644 --- a/rc/base/ocaml.kak +++ b/rc/base/ocaml.kak @@ -47,7 +47,7 @@ hook global WinSetOption filetype=(?!ocaml).* %{ # Macro # ‾‾‾‾‾ -%sh{ +evaluate-commands %sh{ keywords=and:as:asr:assert:begin:class:constraint:do:done:downto:else:end:exception:external:false:for:fun:function:functor:if:in:include:inherit:initializer:land:lazy:let:lor:lsl:lsr:lxor:match:method:mod:module:mutable:new:nonrec:object:of:open:or:private:rec:sig:struct:then:to:true:try:type:val:virtual:when:while:with echo " add-highlighter shared/ocaml/code regex \b($(printf $keywords | tr : '|'))\b 0:keyword diff --git a/rc/base/perl.kak b/rc/base/perl.kak index 5c0a3862b..34b884349 100644 --- a/rc/base/perl.kak +++ b/rc/base/perl.kak @@ -22,7 +22,7 @@ add-highlighter shared/perl/double_string fill string add-highlighter shared/perl/single_string fill string add-highlighter shared/perl/comment fill comment -%sh{ +evaluate-commands %sh{ # Grammar keywords="else|lock|qw|elsif|lt|qx|eq|exp|ne|sub|for|no|my|not|tr|goto|and|foreach|or|break|exit|unless|cmp|ge|package|until|continue|gt|while|if|qq|xor|do|le|qr|return" attributes="END|AUTOLOAD|BEGIN|CHECK|UNITCHECK|INIT|DESTROY" diff --git a/rc/base/ruby.kak b/rc/base/ruby.kak index c615c595c..b595f6720 100644 --- a/rc/base/ruby.kak +++ b/rc/base/ruby.kak @@ -49,7 +49,7 @@ add-highlighter shared/ruby/literal fill meta add-highlighter shared/ruby/code regex \b([A-Za-z]\w*:(?!:))|([$@][A-Za-z]\w*)|((?]: focus the given client If no client is passed then the current one is used} \ -params ..1 -client-completion \ - screen-focus %{ %sh{ + screen-focus %{ evaluate-commands %sh{ if [ $# -eq 1 ]; then printf %s\\n " evaluate-commands -client '$1' focus diff --git a/rc/base/spell.kak b/rc/base/spell.kak index cd5a82777..19fd5f7b0 100644 --- a/rc/base/spell.kak +++ b/rc/base/spell.kak @@ -10,12 +10,12 @@ Formats of language supported: - language code above followed by a dash or underscore with an ISO country code, e.g. 'en-US'} \ spell %{ try %{ add-highlighter window ranges 'spell_regions' } - %sh{ + evaluate-commands %sh{ file=$(mktemp -d "${TMPDIR:-/tmp}"/kak-spell.XXXXXXXX)/buffer printf 'eval -no-hooks write -sync %s\n' "${file}" printf 'set-option buffer spell_tmp_file %s\n' "${file}" } - %sh{ + evaluate-commands %sh{ if [ $# -ge 1 ]; then if [ ${#1} -ne 2 ] && [ ${#1} -ne 5 ]; then echo "echo -markup '{Error}Invalid language code (examples of expected format: en, en_US, en-US)'" @@ -57,7 +57,7 @@ Formats of language supported: } } -define-command spell-next %{ %sh{ +define-command spell-next %{ evaluate-commands %sh{ anchor_line="${kak_selection_desc%%.*}" anchor_col="${kak_selection_desc%%,*}" anchor_col="${anchor_col##*.}" @@ -101,7 +101,7 @@ define-command spell-next %{ %sh{ fi } } -define-command spell-replace %{ %sh{ +define-command spell-replace %{ evaluate-commands %sh{ if [ -n "$kak_opt_spell_lang" ]; then options="-l '$kak_opt_spell_lang'" fi diff --git a/rc/base/sql.kak b/rc/base/sql.kak index c0b5608ac..2a1613a00 100644 --- a/rc/base/sql.kak +++ b/rc/base/sql.kak @@ -18,7 +18,7 @@ add-highlighter shared/ regions -default code sql \ comment '#' '$' '' \ comment '/\*' '\*/' '' -%sh{ +evaluate-commands %sh{ # Keywords keywords="ALTER|AS|ASC|AUTO_INCREMENT|CHECK|CONSTRAINT|CREATE|DATABASE|DEFAULT|DELETE|DESC|DISTINCT|DROP" keywords="${keywords}|EXISTS|FOREIGN KEY|FROM|FULL JOIN|FULL OUTER JOIN|GROUP BY|HAVING|INDEX|INNER JOIN" diff --git a/rc/base/tmux.kak b/rc/base/tmux.kak index c688617fb..3a17669d4 100644 --- a/rc/base/tmux.kak +++ b/rc/base/tmux.kak @@ -2,20 +2,18 @@ # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ ## The default behaviour for the `new` command is to open an horizontal pane in a tmux session -hook global KakBegin .* %{ - %sh{ - if [ -n "$TMUX" ]; then - echo " - alias global focus tmux-focus - alias global new tmux-new-horizontal - " - fi - } +hook global KakBegin .* %sh{ + if [ -n "$TMUX" ]; then + echo " + alias global focus tmux-focus + alias global new tmux-new-horizontal + " + fi } ## Temporarily override the default client creation command define-command -hidden -params 1.. tmux-new-impl %{ - %sh{ + evaluate-commands %sh{ tmux=${kak_client_env_TMUX:-$TMUX} if [ -z "$tmux" ]; then echo "echo -markup '{Error}This command is only available in a tmux session'" @@ -43,7 +41,7 @@ define-command tmux-new-window -params .. -command-completion -docstring "Create define-command -docstring %{tmux-focus []: focus the given client If no client is passed then the current one is used} \ -params ..1 -client-completion \ - tmux-focus %{ %sh{ + tmux-focus %{ evaluate-commands %sh{ if [ $# -eq 1 ]; then printf %s\\n "evaluate-commands -client '$1' focus" elif [ -n "${kak_client_env_TMUX}" ]; then diff --git a/rc/base/x11.kak b/rc/base/x11.kak index 484cee9b6..1c4f6df68 100644 --- a/rc/base/x11.kak +++ b/rc/base/x11.kak @@ -16,7 +16,7 @@ A shell command is appended to the one set in this option at runtime} \ 'xfce4-terminal -e ' ; do terminal=${termcmd%% *} if command -v $terminal >/dev/null 2>&1; then - printf %s\\n "'$termcmd'" + printf %s\\n "$termcmd" exit fi done @@ -26,7 +26,7 @@ define-command -docstring %{x11-new []: create a new kak client for the The optional arguments will be passed as arguments to the new client} \ -params .. \ -command-completion \ - x11-new %{ %sh{ + x11-new %{ evaluate-commands %sh{ if [ -z "${kak_opt_termcmd}" ]; then echo "echo -markup '{Error}termcmd option is not set'" exit @@ -38,7 +38,7 @@ The optional arguments will be passed as arguments to the new client} \ define-command -docstring %{x11-focus []: focus a given client's window If no client is passed, then the current client is used} \ -params ..1 -client-completion \ - x11-focus %{ %sh{ + x11-focus %{ evaluate-commands %sh{ if [ $# -eq 1 ]; then printf %s\\n "evaluate-commands -client '$1' focus" else diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index 962a4b618..1b1402f38 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -127,7 +127,7 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel ] ] # Regions definition are the same between c++ and objective-c -%sh{ +evaluate-commands %sh{ for ft in c cpp objc; do if [ "${ft}" = "objc" ]; then maybe_at='@?' @@ -155,7 +155,7 @@ define-command -hidden c-family-insert-on-newline %[ evaluate-commands -itersel # c specific add-highlighter shared/c/code regex %{\b-?(0x[0-9a-fA-F]+|\d+)[fdiu]?|'((\\.)?|[^'\\])'} 0:value -%sh{ +evaluate-commands %sh{ # Grammar keywords="asm break case continue default do else for goto if return sizeof switch while" @@ -199,7 +199,7 @@ add-highlighter shared/cpp/code regex %{(?i)(?%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O' @@ -332,7 +332,7 @@ hook -group c-family-insert global BufNewFile .*\.(h|hh|hpp|hxx|H) c-family-inse declare-option -docstring "colon separated list of path in which header files will be looked for" \ str-list alt_dirs ".:.." -define-command c-family-alternative-file -docstring "Jump to the alternate file (header/implementation)" %{ %sh{ +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%.*}" diff --git a/rc/core/comment.kak b/rc/core/comment.kak index 3e017ed04..4dee7df7f 100644 --- a/rc/core/comment.kak +++ b/rc/core/comment.kak @@ -111,7 +111,7 @@ hook global BufSetOption filetype=ruby %{ } define-command comment-block -docstring '(un)comment selections using block comments' %{ - %sh{ + evaluate-commands %sh{ if [ -z "${kak_opt_comment_block_begin}" ] || [ -z "${kak_opt_comment_block_end}" ]; then echo "fail \"The 'comment_block' options are empty, could not comment the selection\"" fi @@ -138,7 +138,7 @@ define-command comment-block -docstring '(un)comment selections using block comm } define-command comment-line -docstring '(un)comment selected lines using line comments' %{ - %sh{ + evaluate-commands %sh{ if [ -z "${kak_opt_comment_line}" ]; then echo "fail \"The 'comment_line' option is empty, could not comment the line\"" fi diff --git a/rc/core/doc.kak b/rc/core/doc.kak index 8398fb74f..1f14cfcf4 100644 --- a/rc/core/doc.kak +++ b/rc/core/doc.kak @@ -11,7 +11,7 @@ define-command -hidden -params 4 doc-render-regex %{ execute-keys \%s %arg{1} execute-keys -draft s %arg{2} d execute-keys "%arg{3}" - %sh{ + evaluate-commands %sh{ ranges=$(echo "$kak_selections_desc" | sed -e "s/:/|$4:/g; s/\$/|$4/") echo "update-option buffer doc_render_ranges" echo "set-option -add buffer doc_render_ranges '$ranges'" @@ -54,7 +54,7 @@ define-command -hidden doc-parse-anchors %{ define-command doc-jump-to-anchor -params 1 %{ update-option buffer doc_anchors - %sh{ + evaluate-commands %sh{ range=$(printf "%s" "$kak_opt_doc_anchors" | tr ':' '\n' | grep "$1" | head -n1) if [ -n "$range" ]; then printf '%s\n' "select '${range%|*}'; execute-keys vv" @@ -66,7 +66,7 @@ define-command doc-jump-to-anchor -params 1 %{ define-command doc-follow-link %{ update-option buffer doc_links - %sh{ + evaluate-commands %sh{ printf "%s" "$kak_opt_doc_links" | awk -v RS=':' -v FS='[.,|#]' ' BEGIN { l=ENVIRON["kak_cursor_line"]; @@ -136,7 +136,7 @@ define-command -params 1..2 \ } \ doc -docstring %{doc []: open a buffer containing documentation about a given topic An optional keyword argument can be passed to the function, which will be automatically selected in the documentation} %{ - %sh{ + evaluate-commands %sh{ readonly page="${kak_runtime}/doc/${1}.asciidoc" if [ -f "${page}" ]; then if [ $# -eq 2 ]; then diff --git a/rc/core/formatter.kak b/rc/core/formatter.kak index 1e4a7f86a..40c384448 100644 --- a/rc/core/formatter.kak +++ b/rc/core/formatter.kak @@ -2,18 +2,18 @@ declare-option -docstring "shell command to which the contents of the current bu str formatcmd define-command format -docstring "Format the contents of the current buffer" %{ evaluate-commands -draft -no-hooks %{ - %sh{ + evaluate-commands %sh{ if [ -n "${kak_opt_formatcmd}" ]; then path_file_tmp=$(mktemp "${TMPDIR:-/tmp}"/kak-formatter-XXXXXX) printf %s\\n " write -sync \"${path_file_tmp}\" - %sh{ + evaluate-commands %sh{ readonly path_file_out=\$(mktemp \"${TMPDIR:-/tmp}\"/kak-formatter-XXXXXX) if cat \"${path_file_tmp}\" | eval \"${kak_opt_formatcmd}\" > \"\${path_file_out}\"; then printf '%s\\n' \"execute-keys \\%|cat'\${path_file_out}'\" - printf '%s\\n' \"%sh{ rm -f '\${path_file_out}' }\" + printf '%s\\n' \"nop %sh{ rm -f '\${path_file_out}' }\" else printf '%s\\n' \" evaluate-commands -client '${kak_client}' echo -markup '{Error}formatter returned an error (\$?)' diff --git a/rc/core/grep.kak b/rc/core/grep.kak index a1fb357ae..c634abee4 100644 --- a/rc/core/grep.kak +++ b/rc/core/grep.kak @@ -7,7 +7,7 @@ declare-option -hidden int grep_current_line 0 define-command -params .. -file-completion \ -docstring %{grep []: grep utility wrapper All the optional arguments are forwarded to the grep utility} \ - grep %{ %sh{ + grep %{ evaluate-commands %sh{ output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-grep.XXXXXXXX)/fifo mkfifo ${output} if [ $# -gt 0 ]; then diff --git a/rc/core/kakrc.kak b/rc/core/kakrc.kak index 616669c66..80e45a1b3 100644 --- a/rc/core/kakrc.kak +++ b/rc/core/kakrc.kak @@ -15,16 +15,16 @@ add-highlighter shared/ regions -default code kakrc \ comment (^|\h)\K# $ '' \ double_string %{(^|\h)\K"} %{(?' '<' \ + shell '(^|\h)\K%?%sh\{' '\}' '\{' \ + shell '(^|\h)\K%?%sh\(' '\)' '\(' \ + shell '(^|\h)\K%?%sh\[' '\]' '\[' \ + shell '(^|\h)\K%?%sh<' '>' '<' \ shell '(^|\h)\K-shell-(completion|candidates)\h+%\{' '\}' '\{' \ shell '(^|\h)\K-shell-(completion|candidates)\h+%\(' '\)' '\(' \ shell '(^|\h)\K-shell-(completion|candidates)\h+%\[' '\]' '\[' \ shell '(^|\h)\K-shell-(completion|candidates)\h+%<' '>' '<' -%sh{ +evaluate-commands %sh{ # Grammar keywords="edit write write-all kill quit write-quit write-all-quit map unmap alias unalias buffer buffer-next buffer-previous delete-buffer add-highlighter remove-highlighter diff --git a/rc/core/make.kak b/rc/core/make.kak index 62c0881a1..e171300ed 100644 --- a/rc/core/make.kak +++ b/rc/core/make.kak @@ -10,7 +10,7 @@ declare-option -hidden int make_current_error_line define-command -params .. \ -docstring %{make []: make utility wrapper All the optional arguments are forwarded to the make utility} \ - make %{ %sh{ + make %{ evaluate-commands %sh{ output=$(mktemp -d "${TMPDIR:-/tmp}"/kak-make.XXXXXXXX)/fifo mkfifo ${output} ( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & diff --git a/rc/core/makefile.kak b/rc/core/makefile.kak index 1e830120b..c54735a05 100644 --- a/rc/core/makefile.kak +++ b/rc/core/makefile.kak @@ -18,7 +18,7 @@ add-highlighter shared/makefile/evaluate-commands fill value add-highlighter shared/makefile/content regex ^[\w.%-]+\h*:\s 0:variable add-highlighter shared/makefile/content regex [+?:]= 0:operator -%sh{ +evaluate-commands %sh{ # Grammar keywords="ifeq|ifneq|ifdef|ifndef|else|endif|define|endef" diff --git a/rc/core/man.kak b/rc/core/man.kak index 9925098e1..b1ae14330 100644 --- a/rc/core/man.kak +++ b/rc/core/man.kak @@ -27,7 +27,7 @@ hook global WinSetOption filetype=(?!man).* %{ remove-hooks window man-hooks } -define-command -hidden -params 2..3 man-impl %{ %sh{ +define-command -hidden -params 2..3 man-impl %{ evaluate-commands %sh{ buffer_name="$1" shift manout=$(mktemp "${TMPDIR:-/tmp}"/kak-man-XXXXXX) @@ -57,7 +57,7 @@ define-command -params ..1 \ -docstring %{man []: manpage viewer wrapper If no argument is passed to the command, the selection will be used as page The page can be a word, or a word directly followed by a section number between parenthesis, e.g. kak(1)} \ - man %{ %sh{ + man %{ evaluate-commands %sh{ subject=${1-$kak_selection} ## The completion suggestions display the page number, strip them if present diff --git a/rc/core/python.kak b/rc/core/python.kak index da451413e..de6aa4790 100644 --- a/rc/core/python.kak +++ b/rc/core/python.kak @@ -41,7 +41,7 @@ add-highlighter shared/python/docstring/py-docstring/docstring fill string add-highlighter shared/python/comment fill comment -%sh{ +evaluate-commands %sh{ # Grammar values="True|False|None|self|inf" meta="import|from" diff --git a/rc/core/sh.kak b/rc/core/sh.kak index bc917cc56..a3289ee80 100644 --- a/rc/core/sh.kak +++ b/rc/core/sh.kak @@ -13,7 +13,7 @@ add-highlighter shared/sh/single_string fill string add-highlighter shared/sh/comment fill comment add-highlighter shared/sh/heredoc fill string -%sh{ +evaluate-commands %sh{ # Grammar keywords="alias|bind|builtin|caller|case|cd|command|coproc|declare|do|done" keywords="${keywords}|echo|elif|else|enable|esac|exit|fi|for|function|help" diff --git a/rc/extra/autorestore.kak b/rc/extra/autorestore.kak index e2709c502..f8e3e14d1 100644 --- a/rc/extra/autorestore.kak +++ b/rc/extra/autorestore.kak @@ -3,7 +3,7 @@ declare-option -docstring "remove backups once they've been restored" \ ## Insert the content of the backup file into the current buffer, if a suitable one is found define-command autorestore-restore-buffer -docstring "Restore the backup for the current file if it exists" %{ - %sh{ + evaluate-commands %sh{ buffer_basename="${kak_buffile##*/}" buffer_dirname=$(dirname "${kak_buffile}") @@ -49,7 +49,7 @@ define-command autorestore-restore-buffer -docstring "Restore the backup for the ## Remove all the backups that have been created for the current buffer define-command autorestore-purge-backups -docstring "Remove all the backups of the current buffer" %{ - %sh{ + evaluate-commands %sh{ [ ! -f "${kak_buffile}" ] && exit buffer_basename="${kak_bufname##*/}" diff --git a/rc/extra/clang.kak b/rc/extra/clang.kak index 61a3708a7..e5c1b9fff 100644 --- a/rc/extra/clang.kak +++ b/rc/extra/clang.kak @@ -10,7 +10,7 @@ define-command -params ..1 \ -docstring %{Parse the contents of the current buffer The syntaxic errors detected during parsing are shown when auto-diagnostics are enabled} \ clang-parse %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-clang.XXXXXXXX) mkfifo ${dir}/fifo printf %s\\n "set-option buffer clang_tmp_dir ${dir}" @@ -18,7 +18,7 @@ The syntaxic errors detected during parsing are shown when auto-diagnostics are } # end the previous %sh{} so that its output gets interpreted by kakoune # before launching the following as a background task. - %sh{ + evaluate-commands %sh{ dir=${kak_opt_clang_tmp_dir} printf %s\\n "evaluate-commands -draft %{ edit! -fifo ${dir}/fifo -debug *clang-output* @@ -106,7 +106,7 @@ define-command clang-complete -docstring "Complete the current selection" %{ cla define-command -hidden clang-show-completion-info %[ try %[ evaluate-commands -draft %[ execute-keys {( ^\( b \A\w+\z - %sh[ + evaluate-commands %sh[ desc=$(printf %s\\n "${kak_opt_clang_completions}" | sed -e "{ s/\([^\\]\):/\1\n/g }" | sed -ne "/^${kak_selection}|/ { s/^[^|]\+|//; s/|.*$//; s/\\\:/:/g; p }") if [ -n "$desc" ]; then printf %s\\n "evaluate-commands -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" @@ -135,7 +135,7 @@ 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 - %sh{ + 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 }") @@ -159,7 +159,7 @@ 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 - %sh{ + 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} diff --git a/rc/extra/dockerfile.kak b/rc/extra/dockerfile.kak index db3597baa..9c127cfd4 100644 --- a/rc/extra/dockerfile.kak +++ b/rc/extra/dockerfile.kak @@ -18,7 +18,7 @@ add-highlighter shared/ regions -default code dockerfile \ string "'" "'" '' \ comment '#' $ '' -%sh{ +evaluate-commands %sh{ # Grammar keywords="ADD|ARG|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|HEALTHCHECK|LABEL" keywords="${keywords}|MAINTAINER|RUN|SHELL|STOPSIGNAL|USER|VOLUME|WORKDIR" diff --git a/rc/extra/editorconfig.kak b/rc/extra/editorconfig.kak index 23a5ebd30..18fc3e9e5 100644 --- a/rc/extra/editorconfig.kak +++ b/rc/extra/editorconfig.kak @@ -5,7 +5,7 @@ declare-option -hidden bool editorconfig_trim_trailing_whitespace false define-command editorconfig-load -params ..1 -docstring "editorconfig-load [file]: set formatting behavior according to editorconfig" %{ remove-hooks buffer editorconfig-hooks - %sh{ + evaluate-commands %sh{ command -v editorconfig >/dev/null 2>&1 || { echo 'echo -markup "{Error}editorconfig could not be found"'; exit 1; } editorconfig "${1:-$kak_buffile}" | awk -F= -- ' /indent_style=/ { indent_style = $2 } @@ -39,7 +39,7 @@ define-command editorconfig-load -params ..1 -docstring "editorconfig-load [file } ' } - hook buffer BufWritePre %val{buffile} -group editorconfig-hooks %{ %sh{ + hook buffer BufWritePre %val{buffile} -group editorconfig-hooks %{ evaluate-commands %sh{ if [ ${kak_opt_editorconfig_trim_trailing_whitespace} = "true" ]; then printf %s\\n "try %{ execute-keys -draft %{ %s\h+$d } }" fi diff --git a/rc/extra/git-tools.kak b/rc/extra/git-tools.kak index 166e80449..3c73a9818 100644 --- a/rc/extra/git-tools.kak +++ b/rc/extra/git-tools.kak @@ -24,9 +24,9 @@ set-face global GitBlame default,magenta set-face global GitDiffFlags default,black define-command -params 1.. \ - -docstring %sh{printf '%%{git []: git wrapping helper + -docstring %sh{printf 'git []: git wrapping helper All the optional arguments are forwarded to the git utility -Available 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}'} \ +Available 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-candidates %{ if [ $kak_token_to_complete -eq 0 ]; then printf "add\nrm\nblame\ncommit\ncheckout\ndiff\nhide-blame\nlog\nshow\nshow-diff\nstatus\nupdate-diff\n" @@ -38,7 +38,7 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide- esac fi } \ - git %{ %sh{ + git %{ evaluate-commands %sh{ show_git_cmd_output() { local filetype case "$1" in @@ -166,7 +166,7 @@ Available commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide- GIT_EDITOR='' EDITOR='' git commit "$@" > /dev/null 2>&1 msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG" printf %s "edit '$msgfile' - hook buffer BufWritePost '.*\Q$msgfile\E' %{ %sh{ + hook buffer BufWritePost '.*\Q$msgfile\E' %{ evaluate-commands %sh{ if git commit -F '$msgfile' --cleanup=strip $* > /dev/null; then printf %s 'evaluate-commands -client $kak_client echo -markup %{{Information}Commit succeeded}; delete-buffer' else diff --git a/rc/extra/go-tools.kak b/rc/extra/go-tools.kak index 439715ec3..91f5c8259 100644 --- a/rc/extra/go-tools.kak +++ b/rc/extra/go-tools.kak @@ -5,7 +5,7 @@ # Needs the following tools in the path: # - jq for json deserializaton -%sh{ +evaluate-commands %sh{ for dep in gocode goimports gogetdoc jq; do if ! command -v $dep > /dev/null 2>&1; then echo "echo -debug %{Dependency unmet: $dep, please install it to use go-tools}" @@ -20,12 +20,12 @@ declare-option -hidden str go_complete_tmp_dir declare-option -hidden completions gocode_completions define-command go-complete -docstring "Complete the current selection with gocode" %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) printf %s\\n "set-option buffer go_complete_tmp_dir ${dir}" printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" } - %sh{ + nop %sh{ dir=${kak_opt_go_complete_tmp_dir} ( gocode_data=$(gocode -f=godit --in=${dir}/buf autocomplete ${kak_cursor_byte_offset}) @@ -63,12 +63,12 @@ declare-option -hidden str go_format_tmp_dir define-command -params ..1 go-format \ -docstring "go-format [-use-goimports]: custom formatter for go files" %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) printf %s\\n "set-option buffer go_format_tmp_dir ${dir}" printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" } - %sh{ + evaluate-commands %sh{ dir=${kak_opt_go_format_tmp_dir} if [ "$1" = "-use-goimports" ]; then fmt_cmd="goimports -srcdir '${kak_buffile}'" @@ -94,12 +94,12 @@ declare-option -hidden str go_doc_tmp_dir # FIXME text escaping define-command -hidden -params 1..2 gogetdoc-cmd %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-go.XXXXXXXX) printf %s\\n "set-option buffer go_doc_tmp_dir ${dir}" printf %s\\n "evaluate-commands -no-hooks write ${dir}/buf" } - %sh{ + evaluate-commands %sh{ dir=${kak_opt_go_doc_tmp_dir} ( printf %s\\n "${kak_buffile}" > ${dir}/modified @@ -172,7 +172,7 @@ define-command go-jump -docstring "Jump to the symbol definition" %{ gogetdoc-cmd "jump" 1 } -define-command go-share-selection -docstring "Share the selection using the Go Playground" %{ %sh{ +define-command go-share-selection -docstring "Share the selection using the Go Playground" %{ evaluate-commands %sh{ snippet_id=$(printf %s\\n "${kak_selection}" | curl -s https://play.golang.org/share --data-binary @-) printf "echo https://play.golang.org/p/%s" ${snippet_id} } } diff --git a/rc/extra/iterm.kak b/rc/extra/iterm.kak index 90252c054..b7fe50037 100644 --- a/rc/extra/iterm.kak +++ b/rc/extra/iterm.kak @@ -3,19 +3,17 @@ ## The default behaviour for the `new` command is to open an vertical pane in ## an iTerm session if not in a tmux session. -hook global KakBegin .* %{ - %sh{ - if [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ]; then - echo " - alias global new iterm-new-vertical - alias global focus iterm-focus - " - fi - } +hook global KakBegin .* %sh{ + if [ "$TERM_PROGRAM" = "iTerm.app" ] && [ -z "$TMUX" ]; then + echo " + alias global new iterm-new-vertical + alias global focus iterm-focus + " + fi } define-command -hidden -params 1.. iterm-new-split-impl %{ - %sh{ + nop %sh{ direction="$1" shift if [ $# -gt 0 ]; then kakoune_params="-e \\\"$*\\\""; fi @@ -41,7 +39,7 @@ define-command -params .. -command-completion \ -docstring %{iterm-new-tab []: create a new tab All optional arguments are forwarded to the new kak client} \ iterm-new-tab %{ - %sh{ + nop %sh{ if [ $# -gt 0 ]; then kakoune_params="-e \\\"$*\\\""; fi cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' kak -c '${kak_session}' ${kakoune_params}" osascript \ @@ -57,7 +55,7 @@ define-command -params .. -command-completion \ -docstring %{iterm-new-window []: create a new window All optional arguments are forwarded to the new kak client} \ iterm-new-window %{ - %sh{ + nop %sh{ if [ $# -gt 0 ]; then kakoune_params="-e \\\"$*\\\""; fi cmd="env PATH='${PATH}' TMPDIR='${TMPDIR}' kak -c '${kak_session}' ${kakoune_params}" osascript \ @@ -70,7 +68,7 @@ All optional arguments are forwarded to the new kak client} \ define-command -params ..1 -client-completion \ -docstring %{iterm-focus []: focus the given client If no client is passed then the current one is used} \ - iterm-focus %{ %sh{ + iterm-focus %{ evaluate-commands %sh{ if [ $# -eq 1 ]; then printf %s\\n "evaluate-commands -client '$1' focus" else diff --git a/rc/extra/jedi.kak b/rc/extra/jedi.kak index c48cb71c5..df259ead0 100644 --- a/rc/extra/jedi.kak +++ b/rc/extra/jedi.kak @@ -4,13 +4,13 @@ declare-option -docstring "colon separated list of path added to `python`'s $PYT str-list jedi_python_path define-command jedi-complete -docstring "Complete the current selection" %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-jedi.XXXXXXXX) mkfifo ${dir}/fifo printf %s\\n "set-option buffer jedi_tmp_dir ${dir}" printf %s\\n "evaluate-commands -no-hooks write -sync ${dir}/buf" } - %sh{ + evaluate-commands %sh{ dir=${kak_opt_jedi_tmp_dir} printf %s\\n "evaluate-commands -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" ( diff --git a/rc/extra/modeline.kak b/rc/extra/modeline.kak index 17fcd30db..ece6d97ac 100644 --- a/rc/extra/modeline.kak +++ b/rc/extra/modeline.kak @@ -11,7 +11,7 @@ declare-option -docstring "amount of lines that will be checked at the beginning int modelines 5 define-command -hidden modeline-parse-impl %{ - %sh{ + evaluate-commands %sh{ # Translate a vim option into the corresponding kakoune one translate_opt_vim() { readonly key="$1" diff --git a/rc/extra/moon.kak b/rc/extra/moon.kak index bee113ec5..c4835d4b8 100644 --- a/rc/extra/moon.kak +++ b/rc/extra/moon.kak @@ -30,7 +30,7 @@ add-highlighter shared/moon/code regex \b(and|break|catch|class|continue|do|else # Commands # ‾‾‾‾‾‾‾‾ -define-command moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ +define-command moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ evaluate-commands %sh{ case $kak_buffile in *spec/*_spec.moon) altfile=$(eval printf %s\\n $(printf %s\\n $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) diff --git a/rc/extra/nim.kak b/rc/extra/nim.kak index 7aa3bf374..cc7bb23de 100644 --- a/rc/extra/nim.kak +++ b/rc/extra/nim.kak @@ -23,7 +23,7 @@ add-highlighter shared/nim/code regex \b(0[xXocCbB])?[\d_]+('[iIuUfFdD](8|16|32| add-highlighter shared/nim/code regex \b\d+\.\d+\b 0:value add-highlighter shared/nim/code regex %{'[^'\n]'} 0:string -%sh{ +evaluate-commands %sh{ # Grammar keywords="addr|and|as|asm|atomic|bind|block|break|case|cast|concept|const" keywords="${keywords}|continue|converter|defer|discard|distinct|div|do|elif" diff --git a/rc/extra/pony.kak b/rc/extra/pony.kak index 43a41b141..8a7b34ec5 100644 --- a/rc/extra/pony.kak +++ b/rc/extra/pony.kak @@ -22,7 +22,7 @@ add-highlighter shared/pony/double_string fill string add-highlighter shared/pony/comment fill comment -%sh{ +evaluate-commands %sh{ # Grammar values="true|false|None|this" meta='use' diff --git a/rc/extra/racer.kak b/rc/extra/racer.kak index e7f677797..3b3524a34 100644 --- a/rc/extra/racer.kak +++ b/rc/extra/racer.kak @@ -2,12 +2,12 @@ declare-option -hidden str racer_tmp_dir declare-option -hidden completions racer_completions define-command racer-complete -docstring "Complete the current selection with racer" %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) printf %s\\n "set-option buffer racer_tmp_dir ${dir}" printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" } - %sh{ + nop %sh{ dir=${kak_opt_racer_tmp_dir} ( cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))" @@ -95,12 +95,12 @@ define-command racer-disable-autocomplete -docstring "Disable racer completion" } define-command racer-go-definition -docstring "Jump to where the rust identifier below the cursor is defined" %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) printf %s\\n "set-option buffer racer_tmp_dir ${dir}" printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" } - %sh{ + evaluate-commands %sh{ dir=${kak_opt_racer_tmp_dir} cursor="${kak_cursor_line} $((${kak_cursor_column} - 1))" racer_data=$(racer --interface tab-text find-definition ${cursor} "${kak_buffile}" "${dir}/buf" | head -n 1) @@ -122,12 +122,12 @@ define-command racer-go-definition -docstring "Jump to where the rust identifier } define-command racer-show-doc -docstring "Show the documentation about the rust identifier below the cursor" %{ - %sh{ + evaluate-commands %sh{ dir=$(mktemp -d "${TMPDIR:-/tmp}"/kak-racer.XXXXXXXX) printf %s\\n "set-option buffer racer_tmp_dir ${dir}" printf %s\\n "evaluate-commands -no-hooks %{ write ${dir}/buf }" } - %sh{ + evaluate-commands %sh{ dir=${kak_opt_racer_tmp_dir} cursor="${kak_cursor_line} ${kak_cursor_column}" racer_data=$(racer --interface tab-text complete-with-snippet ${cursor} "${kak_buffile}" "${dir}/buf" | sed -n 2p ) diff --git a/rc/extra/ranger.kak b/rc/extra/ranger.kak index 76e014533..4bb49a7bd 100644 --- a/rc/extra/ranger.kak +++ b/rc/extra/ranger.kak @@ -3,7 +3,7 @@ define-command ranger-open-on-edit-directory \ -docstring 'Start the ranger file system explorer when trying to edit a directory' %{ - hook global RuntimeError "\d+:\d+: '\w+' (.*): is a directory" %{ %sh{ + hook global RuntimeError "\d+:\d+: '\w+' (.*): is a directory" %{ evaluate-commands %sh{ directory=$kak_hook_param_capture_1 echo ranger $directory }} @@ -13,7 +13,7 @@ define-command \ -params .. -file-completion \ -docstring %{ranger []: open the file system explorer to select buffers to open All the optional arguments are forwarded to the ranger utility} \ - ranger %{ %sh{ + ranger %{ evaluate-commands %sh{ if [ -n "${TMUX}" ]; then tmux split-window -h \ ranger $@ --cmd " \ diff --git a/rc/extra/tmux-repl.kak b/rc/extra/tmux-repl.kak index 43d460b84..a0873874e 100644 --- a/rc/extra/tmux-repl.kak +++ b/rc/extra/tmux-repl.kak @@ -1,30 +1,28 @@ # http://tmux.github.io/ # ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ -hook global KakBegin .* %{ - %sh{ - if [ -n "$TMUX" ]; then - VERSION_TMUX=$(tmux -V | cut -d' ' -f2) - VERSION_TMUX=${VERSION_TMUX%%.*} +hook global KakBegin .* %sh{ + if [ -n "$TMUX" ]; then + VERSION_TMUX=$(tmux -V | cut -d' ' -f2) + VERSION_TMUX=${VERSION_TMUX%%.*} - if [ "${VERSION_TMUX}" = "master" ] \ - || [ "${VERSION_TMUX}" -ge 2 ]; then - echo " - alias global repl tmux-repl-horizontal - alias global send-text tmux-send-text - " - else - echo " - alias global repl tmux-repl-disabled - alias global send-text tmux-repl-disabled - " - fi + if [ "${VERSION_TMUX}" = "master" ] \ + || [ "${VERSION_TMUX}" -ge 2 ]; then + echo " + alias global repl tmux-repl-horizontal + alias global send-text tmux-send-text + " + else + echo " + alias global repl tmux-repl-disabled + alias global send-text tmux-repl-disabled + " fi - } + fi } define-command -hidden -params 1..2 tmux-repl-impl %{ - %sh{ + evaluate-commands %sh{ if [ -z "$TMUX" ]; then echo "echo -markup '{Error}This command is only available in a tmux session'" exit @@ -68,7 +66,7 @@ define-command -hidden tmux-send-text -params 0..1 -docstring "tmux-send-text [t } } -define-command -hidden tmux-repl-disabled %{ %sh{ +define-command -hidden tmux-repl-disabled %{ evaluate-commands %sh{ VERSION_TMUX=$(tmux -V) printf %s "echo -markup %{{Error}The version of tmux is too old: got ${VERSION_TMUX}, expected >= 2.x}" } } diff --git a/rc/extra/x11-repl.kak b/rc/extra/x11-repl.kak index 57b4c1407..6ec8175e3 100644 --- a/rc/extra/x11-repl.kak +++ b/rc/extra/x11-repl.kak @@ -3,7 +3,7 @@ define-command -docstring %{x11-repl []: create a new window for repl All optional parameters are forwarded to the new window} \ -params .. \ -command-completion \ - x11-repl %{ %sh{ + x11-repl %{ evaluate-commands %sh{ if [ -z "${kak_opt_termcmd}" ]; then echo "echo -markup '{Error}termcmd option is not set'" exit diff --git a/share/kak/kakrc b/share/kak/kakrc index fb8d16c79..03ef7139d 100644 --- a/share/kak/kakrc +++ b/share/kak/kakrc @@ -6,7 +6,7 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ printf %s\\n "${basename%.*}" done | sort -u } \ - colorscheme %{ %sh{ + colorscheme %{ evaluate-commands %sh{ find_colorscheme() { find -L "${1}" -type f -name "${2}".kak | head -n 1 } @@ -25,7 +25,7 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ fi }} -%sh{ +evaluate-commands %sh{ autoload_directory() { find -L "$1" -type f -name '*\.kak' \ -exec printf 'try %%{ source "%s" } catch %%{ echo -debug Autoload: could not load "%s" }\n' '{}' '{}' \; diff --git a/src/command_manager.cc b/src/command_manager.cc index 94182f4df..9429b3341 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -171,6 +171,7 @@ Token parse_percent_token(Reader& reader, bool throw_on_unterminated) { kak_assert(*reader == '%'); ++reader; + const auto type_start = reader.pos; while (reader and iswalpha(*reader)) ++reader; @@ -441,26 +442,10 @@ void CommandManager::execute(StringView command_line, Context& context, const ShellContext& shell_context) { CommandParser parser(command_line); - struct ShellParser { - ShellParser(String&& str) : output{std::move(str)}, parser{output} {} - String output; - CommandParser parser; - }; - Vector shell_parser_stack; - - auto next_token = [&] { - while (not shell_parser_stack.empty()) - { - if (auto shell_token = shell_parser_stack.back().parser.read_token(true)) - return shell_token; - shell_parser_stack.pop_back(); - } - return parser.read_token(true); - }; BufferCoord command_coord; - Vector params; - while (Optional token_opt = next_token()) + Vector params; + while (Optional token_opt = parser.read_token(true)) { auto& token = *token_opt; if (params.empty()) @@ -471,9 +456,6 @@ void CommandManager::execute(StringView command_line, execute_single_command(params, context, shell_context, command_coord); params.clear(); } - // Shell expand are retokenized - else if (token.type == Token::Type::ShellExpand) - shell_parser_stack.emplace_back(expand_token(token, context, shell_context)); else if (token.type == Token::Type::ArgExpand and token.content == '@') params.insert(params.end(), shell_context.params.begin(), shell_context.params.end()); diff --git a/src/commands.cc b/src/commands.cc index a40a7f87c..1cf8acddd 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1702,14 +1702,14 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) } else { - const bool transient = c.flags() & Context::Flags::Draft; - auto original_jump_list = transient ? Optional{} : c.jump_list(); - auto jump = transient ? Optional{} : c.selections(); + const bool collapse_jumps = not (c.flags() & Context::Flags::Draft) and context.has_buffer(); + auto original_jump_list = collapse_jumps ? c.jump_list() : Optional{}; + auto jump = collapse_jumps ? c.selections() : Optional{}; func(parser, c); // If the jump list got mutated, collapse all jumps into a single one from original selections - if (not transient and c.jump_list() != *original_jump_list) + if (collapse_jumps and c.jump_list() != *original_jump_list) { original_jump_list->push(std::move(*jump)); if (c.jump_list() != *original_jump_list) diff --git a/src/context.hh b/src/context.hh index f4562cf3f..dfbd855c6 100644 --- a/src/context.hh +++ b/src/context.hh @@ -159,10 +159,11 @@ private: struct ScopedEdition { ScopedEdition(Context& context) - : m_context(context), m_buffer(&context.buffer()) - { m_context.begin_edition(); } + : m_context{context}, + m_buffer{context.has_buffer() ? &context.buffer() : nullptr} + { if (m_buffer) m_context.begin_edition(); } - ~ScopedEdition() { m_context.end_edition(); } + ~ScopedEdition() { if (m_buffer) m_context.end_edition(); } Context& context() const { return m_context; } private: diff --git a/src/main.cc b/src/main.cc index 84cf162b0..8a7da2da2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -52,7 +52,8 @@ static const char* startup_info = " * faces are now scoped, set-face command takes an additional scope parameter\n" " * key is gone, use instead\n" " === Kakoune v2018.04.13 Released ===\n" -" * define-command -allow-override switch has been renamed -override\n"; +" * define-command -allow-override switch has been renamed -override\n" +" %sh{...} strings are not automatically reparsed anymore, use evaluate-commands %sh{...}\n"; struct startup_error : runtime_error {