New feature: echo -to-file and %file{…} expansion



Following a request from @alexherbo2, @mawww just added a bidirectional way to exchange Kakoune data through the file-system:

  • echo -to-file [foo]
  • %file{foo}

One example used in the test is:
:echo -to-file commands 'foo bar'<ret>:execute-keys i %file{commands} <lt>esc><ret>

Are there any plugins in the current ecosystem that could benefit, be simplified, from this new pattern?

Could this new feature open new perspectives for the creation of future plugins which have been blocked by some limitations like the size of env vars in %sh{} expansion or other factors? (like a undo-tree plugin)


I’m going to look how I can simplify code of fzf.kak with it


I consider those features experimental, I am really interested in making sure they are actually usefull to simplify existing scripts and general comunication with external tools, so please post any feedback you have on them.


Oh this looks interesting, gotta dig thru my plugins to see where it could be applied.


A typo here. Should be % instead of $


Thanks, fixed


@mawww In a sense yep, but the feature does not preserve the arg-list.

Example – Restore the copy register from a file:

echo -to-file reg-dquote %reg(dquote)
set-register dquote %file(reg-dquote)

I need it in order to implement a feature which has been suggested and completed by @losnappas and @andreyorst:

define-command fzf-yanks %{
  connect %{
    trap "rm $copy" EXIT
    eval "set -- $(get opt yank_ring_history)"
    printf '%s\0' "$@" |
    fzf --read0 --preview 'printf %s {}' > "$copy"
    if test -s "$copy"; then
      send "set-register dquote %file($copy)"

Other than that, I successfully simplified the the way to get a value from a client.


How about this to preserve the arg-list ?

evaluate-commands set-register dquote %file(reg-dquote)

For a more fool proof version, my idea is to extend echo with a way to specify how separate arguments should be joined together. Currently it joins them using spaces, but it could make sense to support quoted joining.


I like it.