1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-11-23 15:23:29 +03:00

Add support for %file{...} expansions

This should make the use case exposed in #2836 implementable.
This commit is contained in:
Maxime Coste 2019-04-07 09:43:40 +10:00
parent 744778be30
commit 41f19f8dc9
6 changed files with 14 additions and 0 deletions

View File

@ -167,6 +167,11 @@ TIP: These environment variables are also available in other contexts where
Kakoune uses a shell command, such as the `|`, `!` or `$` normal mode commands
(See <<keys#,`:doc keys`>>).
== File expansions
Expansions with the type `file` will expand to the content of the filename
given in argument as read from the host filesystem.
== Value expansions
Expansions with the type `val` give access to Kakoune internal data that is

View File

@ -5,6 +5,7 @@
#include "buffer_utils.hh"
#include "context.hh"
#include "flags.hh"
#include "file.hh"
#include "optional.hh"
#include "option_types.hh"
#include "ranges.hh"
@ -168,6 +169,8 @@ Token::Type token_type(StringView type_name, bool throw_on_invalid)
return Token::Type::ValExpand;
else if (type_name == "arg")
return Token::Type::ArgExpand;
else if (type_name == "file")
return Token::Type::FileExpand;
else if (throw_on_invalid)
throw parse_error{format("unknown expand '{}'", type_name)};
else
@ -327,6 +330,8 @@ expand_token(const Token& token, const Context& context, const ShellContext& she
throw runtime_error("invalid argument index");
return {arg < params.size() ? params[arg] : String{}};
}
case Token::Type::FileExpand:
return {read_file(content)};
case Token::Type::RawEval:
return {expand(content, context, shell_context)};
case Token::Type::Raw:

View File

@ -51,6 +51,7 @@ struct Token
OptionExpand,
ValExpand,
ArgExpand,
FileExpand,
CommandSeparator
};

View File

@ -0,0 +1 @@
:echo -to-file commands 'foo bar'<ret>:execute-keys i %file{commands} <lt>esc><ret>

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
foo bar