Add support for %file{...} expansions
This should make the use case exposed in #2836 implementable.
This commit is contained in:
parent
744778be30
commit
41f19f8dc9
|
@ -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
|
Kakoune uses a shell command, such as the `|`, `!` or `$` normal mode commands
|
||||||
(See <<keys#,`:doc keys`>>).
|
(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
|
== Value expansions
|
||||||
|
|
||||||
Expansions with the type `val` give access to Kakoune internal data that is
|
Expansions with the type `val` give access to Kakoune internal data that is
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "buffer_utils.hh"
|
#include "buffer_utils.hh"
|
||||||
#include "context.hh"
|
#include "context.hh"
|
||||||
#include "flags.hh"
|
#include "flags.hh"
|
||||||
|
#include "file.hh"
|
||||||
#include "optional.hh"
|
#include "optional.hh"
|
||||||
#include "option_types.hh"
|
#include "option_types.hh"
|
||||||
#include "ranges.hh"
|
#include "ranges.hh"
|
||||||
|
@ -168,6 +169,8 @@ Token::Type token_type(StringView type_name, bool throw_on_invalid)
|
||||||
return Token::Type::ValExpand;
|
return Token::Type::ValExpand;
|
||||||
else if (type_name == "arg")
|
else if (type_name == "arg")
|
||||||
return Token::Type::ArgExpand;
|
return Token::Type::ArgExpand;
|
||||||
|
else if (type_name == "file")
|
||||||
|
return Token::Type::FileExpand;
|
||||||
else if (throw_on_invalid)
|
else if (throw_on_invalid)
|
||||||
throw parse_error{format("unknown expand '{}'", type_name)};
|
throw parse_error{format("unknown expand '{}'", type_name)};
|
||||||
else
|
else
|
||||||
|
@ -327,6 +330,8 @@ expand_token(const Token& token, const Context& context, const ShellContext& she
|
||||||
throw runtime_error("invalid argument index");
|
throw runtime_error("invalid argument index");
|
||||||
return {arg < params.size() ? params[arg] : String{}};
|
return {arg < params.size() ? params[arg] : String{}};
|
||||||
}
|
}
|
||||||
|
case Token::Type::FileExpand:
|
||||||
|
return {read_file(content)};
|
||||||
case Token::Type::RawEval:
|
case Token::Type::RawEval:
|
||||||
return {expand(content, context, shell_context)};
|
return {expand(content, context, shell_context)};
|
||||||
case Token::Type::Raw:
|
case Token::Type::Raw:
|
||||||
|
|
|
@ -51,6 +51,7 @@ struct Token
|
||||||
OptionExpand,
|
OptionExpand,
|
||||||
ValExpand,
|
ValExpand,
|
||||||
ArgExpand,
|
ArgExpand,
|
||||||
|
FileExpand,
|
||||||
CommandSeparator
|
CommandSeparator
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
1
test/compose/file-expansion/cmd
Normal file
1
test/compose/file-expansion/cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
:echo -to-file commands 'foo bar'<ret>:execute-keys i %file{commands} <lt>esc><ret>
|
1
test/compose/file-expansion/in
Normal file
1
test/compose/file-expansion/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
test/compose/file-expansion/out
Normal file
1
test/compose/file-expansion/out
Normal file
|
@ -0,0 +1 @@
|
||||||
|
foo bar
|
Loading…
Reference in New Issue
Block a user