CommandManager: rework command parser
a new type of strings is supported inspired by the ruby strings. %<delimiter>content<delimiter>, if opening delimiter is one of ([{<, then closing delimiter is the matching )]}> and balanced delimiters in the string needs not to be escaped, else the closing delimiter is the same as the opening one. shell expansion is available through %sh<delimiter>command<delimiter> syntax. Command flags have been removed, as these strings provide proper nesting support, so now, you can for example do: def command %{ echo %sh{ ls } }
This commit is contained in:
parent
ac2676cbcf
commit
36070dd429
|
@ -17,60 +17,110 @@ bool CommandManager::command_defined(const String& command_name) const
|
||||||
|
|
||||||
void CommandManager::register_command(const String& command_name,
|
void CommandManager::register_command(const String& command_name,
|
||||||
Command command,
|
Command command,
|
||||||
unsigned flags,
|
|
||||||
const CommandCompleter& completer)
|
const CommandCompleter& completer)
|
||||||
{
|
{
|
||||||
m_commands[command_name] = CommandDescriptor { command, flags, completer };
|
m_commands[command_name] = CommandDescriptor { command, completer };
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandManager::register_commands(const memoryview<String>& command_names,
|
void CommandManager::register_commands(const memoryview<String>& command_names,
|
||||||
Command command,
|
Command command,
|
||||||
unsigned flags,
|
|
||||||
const CommandCompleter& completer)
|
const CommandCompleter& completer)
|
||||||
{
|
{
|
||||||
for (auto command_name : command_names)
|
for (auto command_name : command_names)
|
||||||
register_command(command_name, command, flags, completer);
|
register_command(command_name, command, completer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_blank(char c)
|
static bool is_horizontal_blank(char c)
|
||||||
{
|
{
|
||||||
return c == ' ' or c == '\t' or c == '\n';
|
return c == ' ' or c == '\t';
|
||||||
}
|
}
|
||||||
|
|
||||||
using TokenList = std::vector<Token>;
|
using TokenList = std::vector<Token>;
|
||||||
using TokenPosList = std::vector<std::pair<size_t, size_t>>;
|
using TokenPosList = std::vector<std::pair<size_t, size_t>>;
|
||||||
|
|
||||||
|
static bool is_command_separator(Character c)
|
||||||
|
{
|
||||||
|
return c == ';' or c == '\n';
|
||||||
|
}
|
||||||
|
|
||||||
static TokenList parse(const String& line,
|
static TokenList parse(const String& line,
|
||||||
TokenPosList* opt_token_pos_info = NULL)
|
TokenPosList* opt_token_pos_info = NULL)
|
||||||
{
|
{
|
||||||
TokenList result;
|
TokenList result;
|
||||||
|
|
||||||
|
size_t length = line.length();
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
while (pos < line.length())
|
while (pos < length)
|
||||||
{
|
{
|
||||||
while(is_blank(line[pos]) and pos != line.length())
|
while (pos != length)
|
||||||
|
{
|
||||||
|
if (is_horizontal_blank(line[pos]))
|
||||||
++pos;
|
++pos;
|
||||||
|
else if (line[pos] == '\\' and pos+1 < length and line[pos+1] == '\n')
|
||||||
|
pos += 2;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
size_t token_start = pos;
|
size_t token_start = pos;
|
||||||
|
|
||||||
Token::Type type = Token::Type::Raw;
|
Token::Type type = Token::Type::Raw;
|
||||||
if (line[pos] == '"' or line[pos] == '\'' or line[pos] == '`')
|
if (line[pos] == '"' or line[pos] == '\'')
|
||||||
{
|
{
|
||||||
char delimiter = line[pos];
|
char delimiter = line[pos];
|
||||||
|
|
||||||
if (delimiter == '`')
|
|
||||||
type = Token::Type::ShellExpand;
|
|
||||||
|
|
||||||
token_start = ++pos;
|
token_start = ++pos;
|
||||||
|
|
||||||
while ((line[pos] != delimiter or line[pos-1] == '\\') and
|
while ((line[pos] != delimiter or line[pos-1] == '\\') and
|
||||||
pos != line.length())
|
pos != length)
|
||||||
++pos;
|
++pos;
|
||||||
|
}
|
||||||
|
else if (line[pos] == '%')
|
||||||
|
{
|
||||||
|
size_t type_start = ++pos;
|
||||||
|
while (isalpha(line[pos]))
|
||||||
|
++pos;
|
||||||
|
String type_name = line.substr(type_start, pos - type_start);
|
||||||
|
|
||||||
|
if (type_name == "sh")
|
||||||
|
type = Token::Type::ShellExpand;
|
||||||
|
|
||||||
|
static const std::unordered_map<Character, Character> matching_delimiters = {
|
||||||
|
{ '(', ')' }, { '[', ']' }, { '{', '}' }, { '<', '>' }
|
||||||
|
};
|
||||||
|
|
||||||
|
Character opening_delimiter = line[pos];
|
||||||
|
token_start = ++pos;
|
||||||
|
|
||||||
|
auto delim_it = matching_delimiters.find(opening_delimiter);
|
||||||
|
if (delim_it != matching_delimiters.end())
|
||||||
|
{
|
||||||
|
Character closing_delimiter = delim_it->second;
|
||||||
|
int level = 0;
|
||||||
|
while (pos != length)
|
||||||
|
{
|
||||||
|
if (line[pos-1] != '\\' and line[pos] == opening_delimiter)
|
||||||
|
++level;
|
||||||
|
if (line[pos-1] != '\\' and line[pos] == closing_delimiter)
|
||||||
|
{
|
||||||
|
if (level > 0)
|
||||||
|
--level;
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
while (not is_blank(line[pos]) and pos != line.length() and
|
{
|
||||||
(line[pos] != ';' or line[pos-1] == '\\'))
|
while ((line[pos] != opening_delimiter or line[pos-1] == '\\') and
|
||||||
|
pos != length)
|
||||||
|
++pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
while (pos != length and not is_horizontal_blank(line[pos]) and
|
||||||
|
(not is_command_separator(line[pos]) or line[pos-1] == '\\'))
|
||||||
++pos;
|
++pos;
|
||||||
|
|
||||||
if (token_start != pos)
|
if (token_start != pos)
|
||||||
|
@ -80,7 +130,7 @@ static TokenList parse(const String& line,
|
||||||
result.push_back({type, line.substr(token_start, pos - token_start)});
|
result.push_back({type, line.substr(token_start, pos - token_start)});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line[pos] == ';')
|
if (is_command_separator(line[pos]))
|
||||||
{
|
{
|
||||||
if (opt_token_pos_info)
|
if (opt_token_pos_info)
|
||||||
opt_token_pos_info->push_back({pos, pos+1});
|
opt_token_pos_info->push_back({pos, pos+1});
|
||||||
|
@ -140,13 +190,6 @@ void CommandManager::execute(const CommandParameters& params,
|
||||||
if (command_it == m_commands.end())
|
if (command_it == m_commands.end())
|
||||||
throw command_not_found(begin->content());
|
throw command_not_found(begin->content());
|
||||||
|
|
||||||
if (command_it->second.flags & IgnoreSemiColons)
|
|
||||||
end = params.end();
|
|
||||||
|
|
||||||
if (command_it->second.flags & DeferredShellEval)
|
|
||||||
command_it->second.command(CommandParameters(begin + 1, end), context);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
TokenList expanded_tokens;
|
TokenList expanded_tokens;
|
||||||
for (auto param = begin+1; param != end; ++param)
|
for (auto param = begin+1; param != end; ++param)
|
||||||
{
|
{
|
||||||
|
@ -158,7 +201,6 @@ void CommandManager::execute(const CommandParameters& params,
|
||||||
}
|
}
|
||||||
command_it->second.command(expanded_tokens, context);
|
command_it->second.command(expanded_tokens, context);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (end == params.end())
|
if (end == params.end())
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -72,13 +72,6 @@ private:
|
||||||
class CommandManager : public Singleton<CommandManager>
|
class CommandManager : public Singleton<CommandManager>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Flags
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
IgnoreSemiColons = 1,
|
|
||||||
DeferredShellEval = 2,
|
|
||||||
};
|
|
||||||
|
|
||||||
void execute(const String& command_line, const Context& context,
|
void execute(const String& command_line, const Context& context,
|
||||||
const EnvVarMap& env_vars = EnvVarMap());
|
const EnvVarMap& env_vars = EnvVarMap());
|
||||||
void execute(const CommandParameters& params, const Context& context,
|
void execute(const CommandParameters& params, const Context& context,
|
||||||
|
@ -90,19 +83,16 @@ public:
|
||||||
|
|
||||||
void register_command(const String& command_name,
|
void register_command(const String& command_name,
|
||||||
Command command,
|
Command command,
|
||||||
unsigned flags = None,
|
|
||||||
const CommandCompleter& completer = CommandCompleter());
|
const CommandCompleter& completer = CommandCompleter());
|
||||||
|
|
||||||
void register_commands(const memoryview<String>& command_names,
|
void register_commands(const memoryview<String>& command_names,
|
||||||
Command command,
|
Command command,
|
||||||
unsigned flags = None,
|
|
||||||
const CommandCompleter& completer = CommandCompleter());
|
const CommandCompleter& completer = CommandCompleter());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct CommandDescriptor
|
struct CommandDescriptor
|
||||||
{
|
{
|
||||||
Command command;
|
Command command;
|
||||||
unsigned flags;
|
|
||||||
CommandCompleter completer;
|
CommandCompleter completer;
|
||||||
};
|
};
|
||||||
std::unordered_map<String, CommandDescriptor> m_commands;
|
std::unordered_map<String, CommandDescriptor> m_commands;
|
||||||
|
|
131
src/commands.cc
131
src/commands.cc
|
@ -440,16 +440,16 @@ void rm_filter(const CommandParameters& params, const Context& context)
|
||||||
|
|
||||||
void add_hook(const CommandParameters& params, const Context& context)
|
void add_hook(const CommandParameters& params, const Context& context)
|
||||||
{
|
{
|
||||||
if (params.size() < 4)
|
if (params.size() != 4)
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
|
||||||
|
// copy so that the lambda gets a copy as well
|
||||||
String regex = params[2].content();
|
String regex = params[2].content();
|
||||||
std::vector<Token> hook_params(params.begin()+3, params.end());
|
String command = params[3].content();
|
||||||
|
|
||||||
auto hook_func = [=](const String& param, const Context& context) {
|
auto hook_func = [=](const String& param, const Context& context) {
|
||||||
if (boost::regex_match(param.begin(), param.end(),
|
if (boost::regex_match(param.begin(), param.end(),
|
||||||
Regex(regex.begin(), regex.end())))
|
Regex(regex.begin(), regex.end())))
|
||||||
CommandManager::instance().execute(hook_params, context);
|
CommandManager::instance().execute(command, context);
|
||||||
};
|
};
|
||||||
|
|
||||||
const String& scope = params[0].content();
|
const String& scope = params[0].content();
|
||||||
|
@ -484,7 +484,7 @@ void define_command(const CommandParameters& params, const Context& context)
|
||||||
{ "allow-override", false },
|
{ "allow-override", false },
|
||||||
{ "shell-completion", true } });
|
{ "shell-completion", true } });
|
||||||
|
|
||||||
if (parser.positional_count() < 2)
|
if (parser.positional_count() != 2)
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
|
||||||
auto begin = parser.begin();
|
auto begin = parser.begin();
|
||||||
|
@ -494,30 +494,21 @@ void define_command(const CommandParameters& params, const Context& context)
|
||||||
not parser.has_option("allow-override"))
|
not parser.has_option("allow-override"))
|
||||||
throw runtime_error("command '" + cmd_name + "' already defined");
|
throw runtime_error("command '" + cmd_name + "' already defined");
|
||||||
|
|
||||||
std::vector<Token> cmd_params(++begin, parser.end());
|
String commands = parser[1].content();
|
||||||
Command cmd;
|
Command cmd;
|
||||||
if (parser.has_option("env-params"))
|
if (parser.has_option("env-params"))
|
||||||
{
|
{
|
||||||
cmd = [=](const CommandParameters& params, const Context& context) {
|
cmd = [=](const CommandParameters& params, const Context& context) {
|
||||||
CommandManager::instance().execute(cmd_params, context,
|
CommandManager::instance().execute(commands, context,
|
||||||
params_to_env_var_map(params));
|
params_to_env_var_map(params));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (parser.has_option("append-params"))
|
|
||||||
{
|
|
||||||
cmd = [=](const CommandParameters& params, const Context& context) {
|
|
||||||
std::vector<Token> merged_params = cmd_params;
|
|
||||||
for (auto& param : params)
|
|
||||||
merged_params.push_back(param);
|
|
||||||
CommandManager::instance().execute(merged_params, context);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cmd = [=](const CommandParameters& params, const Context& context) {
|
cmd = [=](const CommandParameters& params, const Context& context) {
|
||||||
if (not params.empty())
|
if (not params.empty())
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
CommandManager::instance().execute(cmd_params, context);
|
CommandManager::instance().execute(commands, context);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -533,9 +524,7 @@ void define_command(const CommandParameters& params, const Context& context)
|
||||||
String output = ShellManager::instance().eval(shell_cmd, context, vars);
|
String output = ShellManager::instance().eval(shell_cmd, context, vars);
|
||||||
return split(output, '\n');
|
return split(output, '\n');
|
||||||
};
|
};
|
||||||
CommandManager::instance().register_command(cmd_name, cmd,
|
CommandManager::instance().register_command(cmd_name, cmd, completer);
|
||||||
CommandManager::None,
|
|
||||||
completer);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CommandManager::instance().register_command(cmd_name, cmd);
|
CommandManager::instance().register_command(cmd_name, cmd);
|
||||||
|
@ -556,61 +545,7 @@ void exec_commands_in_file(const CommandParameters& params,
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
|
||||||
String file_content = read_file(parse_filename(params[0].content()));
|
String file_content = read_file(parse_filename(params[0].content()));
|
||||||
CommandManager& cmd_manager = CommandManager::instance();
|
CommandManager::instance().execute(file_content, context);
|
||||||
|
|
||||||
size_t pos = 0;
|
|
||||||
size_t length = file_content.length();
|
|
||||||
bool cat_with_previous = false;
|
|
||||||
String command_line;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
if (not cat_with_previous)
|
|
||||||
command_line = String();
|
|
||||||
|
|
||||||
size_t end_pos = pos;
|
|
||||||
|
|
||||||
while (file_content[end_pos] != '\n' and end_pos != length)
|
|
||||||
{
|
|
||||||
if (file_content[end_pos] == '"' or file_content[end_pos] == '\'' or
|
|
||||||
file_content[end_pos] == '`')
|
|
||||||
{
|
|
||||||
char delimiter = file_content[end_pos];
|
|
||||||
++end_pos;
|
|
||||||
while ((file_content[end_pos] != delimiter or
|
|
||||||
file_content[end_pos-1] == '\\') and end_pos != length)
|
|
||||||
++end_pos;
|
|
||||||
|
|
||||||
if (end_pos == length)
|
|
||||||
throw(String("unterminated '") + delimiter + "' string");
|
|
||||||
|
|
||||||
++end_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (end_pos != length)
|
|
||||||
++end_pos;
|
|
||||||
}
|
|
||||||
if (end_pos != pos and end_pos != length and
|
|
||||||
file_content[end_pos - 1] == '\\')
|
|
||||||
{
|
|
||||||
command_line += file_content.substr(pos, end_pos - pos - 1);
|
|
||||||
cat_with_previous = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
command_line += file_content.substr(pos, end_pos - pos);
|
|
||||||
cmd_manager.execute(command_line, context);
|
|
||||||
cat_with_previous = false;
|
|
||||||
}
|
|
||||||
if (end_pos == length)
|
|
||||||
{
|
|
||||||
if (cat_with_previous)
|
|
||||||
throw runtime_error("while executing commands in \"" +
|
|
||||||
params[0].content() +
|
|
||||||
"\": last command not complete");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pos = end_pos + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void exec_commands_in_runtime_file(const CommandParameters& params,
|
void exec_commands_in_runtime_file(const CommandParameters& params,
|
||||||
|
@ -803,24 +738,19 @@ void menu(const CommandParameters& params,
|
||||||
void try_catch(const CommandParameters& params,
|
void try_catch(const CommandParameters& params,
|
||||||
const Context& context)
|
const Context& context)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
if (params.size() != 3)
|
||||||
for (; i < params.size(); ++i)
|
|
||||||
{
|
|
||||||
if (params[i].content() == "catch")
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == 0 or i == params.size())
|
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
if (params[1].content() != "catch")
|
||||||
|
throw runtime_error("try needs a catch");
|
||||||
|
|
||||||
CommandManager& command_manager = CommandManager::instance();
|
CommandManager& command_manager = CommandManager::instance();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
command_manager.execute(params.subrange(0, i), context);
|
command_manager.execute(params[0].content(), context);
|
||||||
}
|
}
|
||||||
catch (Kakoune::runtime_error& e)
|
catch (Kakoune::runtime_error& e)
|
||||||
{
|
{
|
||||||
command_manager.execute(params.subrange(i+1, params.size() - i - 1), context);
|
command_manager.execute(params[2].content(), context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,12 +761,9 @@ void register_commands()
|
||||||
CommandManager& cm = CommandManager::instance();
|
CommandManager& cm = CommandManager::instance();
|
||||||
|
|
||||||
PerArgumentCommandCompleter filename_completer({ complete_filename });
|
PerArgumentCommandCompleter filename_completer({ complete_filename });
|
||||||
cm.register_commands({ "e", "edit" }, edit<false>,
|
cm.register_commands({ "e", "edit" }, edit<false>, filename_completer);
|
||||||
CommandManager::None, filename_completer);
|
cm.register_commands({ "e!", "edit!" }, edit<true>, filename_completer);
|
||||||
cm.register_commands({ "e!", "edit!" }, edit<true>,
|
cm.register_commands({ "w", "write" }, write_buffer, filename_completer);
|
||||||
CommandManager::None, filename_completer);
|
|
||||||
cm.register_commands({ "w", "write" }, write_buffer,
|
|
||||||
CommandManager::None, filename_completer);
|
|
||||||
cm.register_commands({ "q", "quit" }, quit<false>);
|
cm.register_commands({ "q", "quit" }, quit<false>);
|
||||||
cm.register_commands({ "q!", "quit!" }, quit<true>);
|
cm.register_commands({ "q!", "quit!" }, quit<true>);
|
||||||
cm.register_command("wq", write_and_quit<false>);
|
cm.register_command("wq", write_and_quit<false>);
|
||||||
|
@ -846,13 +773,10 @@ void register_commands()
|
||||||
[](const String& prefix, size_t cursor_pos)
|
[](const String& prefix, size_t cursor_pos)
|
||||||
{ return BufferManager::instance().complete_buffername(prefix, cursor_pos); }
|
{ return BufferManager::instance().complete_buffername(prefix, cursor_pos); }
|
||||||
});
|
});
|
||||||
cm.register_commands({ "b", "buffer" }, show_buffer,
|
cm.register_commands({ "b", "buffer" }, show_buffer, buffer_completer);
|
||||||
CommandManager::None, buffer_completer);
|
cm.register_commands({ "db", "delbuf" }, delete_buffer, buffer_completer);
|
||||||
cm.register_commands({ "db", "delbuf" }, delete_buffer,
|
|
||||||
CommandManager::None, buffer_completer);
|
|
||||||
|
|
||||||
cm.register_commands({ "ah", "addhl" }, add_highlighter,
|
cm.register_commands({ "ah", "addhl" }, add_highlighter,
|
||||||
CommandManager::None,
|
|
||||||
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
||||||
{
|
{
|
||||||
Window& w = main_context.window();
|
Window& w = main_context.window();
|
||||||
|
@ -866,7 +790,6 @@ void register_commands()
|
||||||
return CandidateList();
|
return CandidateList();
|
||||||
});
|
});
|
||||||
cm.register_commands({ "rh", "rmhl" }, rm_highlighter,
|
cm.register_commands({ "rh", "rmhl" }, rm_highlighter,
|
||||||
CommandManager::None,
|
|
||||||
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
||||||
{
|
{
|
||||||
Window& w = main_context.window();
|
Window& w = main_context.window();
|
||||||
|
@ -880,7 +803,6 @@ void register_commands()
|
||||||
return w.highlighters().complete_id(arg, pos_in_token);
|
return w.highlighters().complete_id(arg, pos_in_token);
|
||||||
});
|
});
|
||||||
cm.register_commands({ "af", "addfilter" }, add_filter,
|
cm.register_commands({ "af", "addfilter" }, add_filter,
|
||||||
CommandManager::None,
|
|
||||||
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
||||||
{
|
{
|
||||||
Window& w = main_context.window();
|
Window& w = main_context.window();
|
||||||
|
@ -894,7 +816,6 @@ void register_commands()
|
||||||
return CandidateList();
|
return CandidateList();
|
||||||
});
|
});
|
||||||
cm.register_commands({ "rf", "rmfilter" }, rm_filter,
|
cm.register_commands({ "rf", "rmfilter" }, rm_filter,
|
||||||
CommandManager::None,
|
|
||||||
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
[](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
||||||
{
|
{
|
||||||
Window& w = main_context.window();
|
Window& w = main_context.window();
|
||||||
|
@ -908,24 +829,22 @@ void register_commands()
|
||||||
return w.filters().complete_id(arg, pos_in_token);
|
return w.filters().complete_id(arg, pos_in_token);
|
||||||
});
|
});
|
||||||
|
|
||||||
cm.register_command("hook", add_hook, CommandManager::IgnoreSemiColons | CommandManager::DeferredShellEval);
|
cm.register_command("hook", add_hook);
|
||||||
|
|
||||||
cm.register_command("source", exec_commands_in_file,
|
cm.register_command("source", exec_commands_in_file, filename_completer);
|
||||||
CommandManager::None, filename_completer);
|
|
||||||
cm.register_command("runtime", exec_commands_in_runtime_file);
|
cm.register_command("runtime", exec_commands_in_runtime_file);
|
||||||
|
|
||||||
cm.register_command("exec", exec_string);
|
cm.register_command("exec", exec_string);
|
||||||
cm.register_command("eval", eval_string);
|
cm.register_command("eval", eval_string);
|
||||||
cm.register_command("menu", menu);
|
cm.register_command("menu", menu);
|
||||||
cm.register_command("try", try_catch, CommandManager::IgnoreSemiColons | CommandManager::DeferredShellEval);
|
cm.register_command("try", try_catch);
|
||||||
|
|
||||||
cm.register_command("def", define_command, CommandManager::IgnoreSemiColons | CommandManager::DeferredShellEval);
|
cm.register_command("def", define_command);
|
||||||
cm.register_command("echo", echo_message);
|
cm.register_command("echo", echo_message);
|
||||||
|
|
||||||
cm.register_commands({ "setg", "setglobal" },
|
cm.register_commands({ "setg", "setglobal" },
|
||||||
[](const CommandParameters& params, const Context& context)
|
[](const CommandParameters& params, const Context& context)
|
||||||
{ set_option(GlobalOptionManager::instance(), params, context); },
|
{ set_option(GlobalOptionManager::instance(), params, context); },
|
||||||
CommandManager::None,
|
|
||||||
PerArgumentCommandCompleter({
|
PerArgumentCommandCompleter({
|
||||||
[](const String& prefix, size_t cursor_pos)
|
[](const String& prefix, size_t cursor_pos)
|
||||||
{ return GlobalOptionManager::instance().complete_option_name(prefix, cursor_pos); }
|
{ return GlobalOptionManager::instance().complete_option_name(prefix, cursor_pos); }
|
||||||
|
@ -933,7 +852,6 @@ void register_commands()
|
||||||
cm.register_commands({ "setb", "setbuffer" },
|
cm.register_commands({ "setb", "setbuffer" },
|
||||||
[](const CommandParameters& params, const Context& context)
|
[](const CommandParameters& params, const Context& context)
|
||||||
{ set_option(context.buffer().option_manager(), params, context); },
|
{ set_option(context.buffer().option_manager(), params, context); },
|
||||||
CommandManager::None,
|
|
||||||
PerArgumentCommandCompleter({
|
PerArgumentCommandCompleter({
|
||||||
[](const String& prefix, size_t cursor_pos)
|
[](const String& prefix, size_t cursor_pos)
|
||||||
{ return main_context.buffer().option_manager().complete_option_name(prefix, cursor_pos); }
|
{ return main_context.buffer().option_manager().complete_option_name(prefix, cursor_pos); }
|
||||||
|
@ -941,7 +859,6 @@ void register_commands()
|
||||||
cm.register_commands({ "setw", "setwindow" },
|
cm.register_commands({ "setw", "setwindow" },
|
||||||
[](const CommandParameters& params, const Context& context)
|
[](const CommandParameters& params, const Context& context)
|
||||||
{ set_option(context.window().option_manager(), params, context); },
|
{ set_option(context.window().option_manager(), params, context); },
|
||||||
CommandManager::None,
|
|
||||||
PerArgumentCommandCompleter({
|
PerArgumentCommandCompleter({
|
||||||
[](const String& prefix, size_t cursor_pos)
|
[](const String& prefix, size_t cursor_pos)
|
||||||
{ return main_context.window().option_manager().complete_option_name(prefix, cursor_pos); }
|
{ return main_context.window().option_manager().complete_option_name(prefix, cursor_pos); }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
hook global WinCreate .* addhl regex \h+(?=\n) default red
|
hook global WinCreate .* %{ addhl regex \h+(?=\n) default red }
|
||||||
hook global WinCreate .* addhl number_lines
|
hook global WinCreate .* %{ addhl number_lines }
|
||||||
|
|
||||||
runtime rc/cpp.kak
|
runtime rc/cpp.kak
|
||||||
runtime rc/kakrc.kak
|
runtime rc/kakrc.kak
|
||||||
|
|
|
@ -1,29 +1,33 @@
|
||||||
hook global BufCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) \
|
hook global BufCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) %{
|
||||||
setb filetype cpp
|
setb filetype cpp
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=cpp \
|
hook global WinSetOption filetype=cpp %{
|
||||||
addhl group cpp-highlight; \
|
addhl group cpp-highlight;
|
||||||
addhl -group cpp-highlight regex "\<(this|true|false|NULL|nullptr|)\>|\<-?\d+[fdiu]?|'((\\.)?|[^'\\])'" red default; \
|
addhl -group cpp-highlight regex "\<(this|true|false|NULL|nullptr|)\>|\<-?\d+[fdiu]?|'((\\.)?|[^'\\])'" red default;
|
||||||
addhl -group cpp-highlight regex "\<(void|int|char|unsigned|float|bool|size_t)\>" yellow default; \
|
addhl -group cpp-highlight regex "\<(void|int|char|unsigned|float|bool|size_t)\>" yellow default;
|
||||||
addhl -group cpp-highlight regex "\<(while|for|if|else|do|switch|case|default|goto|break|continue|return|using|try|catch|throw|new|delete|and|or|not)\>" blue default; \
|
addhl -group cpp-highlight regex "\<(while|for|if|else|do|switch|case|default|goto|break|continue|return|using|try|catch|throw|new|delete|and|or|not)\>" blue default;
|
||||||
addhl -group cpp-highlight regex "\<(const|auto|namespace|inline|static|volatile|class|struct|enum|union|public|protected|private|template|typedef|virtual|friend|extern|typename)\>" green default; \
|
addhl -group cpp-highlight regex "\<(const|auto|namespace|inline|static|volatile|class|struct|enum|union|public|protected|private|template|typedef|virtual|friend|extern|typename)\>" green default;
|
||||||
addhl -group cpp-highlight regex "(?<!')\"(\\\"|[^\"])*\"" magenta default; \
|
addhl -group cpp-highlight regex "(?<!')\"(\\\"|[^\"])*\"" magenta default;
|
||||||
addhl -group cpp-highlight regex "(\`|(?<=\n))\h*#\h*[^\n]*" magenta default; \
|
addhl -group cpp-highlight regex "(\`|(?<=\n))\h*#\h*[^\n]*" magenta default;
|
||||||
addhl -group cpp-highlight regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" cyan default; \
|
addhl -group cpp-highlight regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" cyan default;
|
||||||
addfilter group cpp-filters; \
|
addfilter group cpp-filters;
|
||||||
addfilter -group cpp-filters preserve_indent; \
|
addfilter -group cpp-filters preserve_indent;
|
||||||
addfilter -group cpp-filters cleanup_whitespaces; \
|
addfilter -group cpp-filters cleanup_whitespaces;
|
||||||
hook window InsertEnd .* exec xs\h+(?=\n)<ret>d
|
hook window InsertEnd .* %{ exec xs\h+(?=\n)<ret>d }
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=(?!cpp).* \
|
hook global WinSetOption filetype=(?!cpp).* %{
|
||||||
rmhl cpp-highlight; \
|
rmhl cpp-highlight;
|
||||||
rmfilter cpp-filters
|
rmfilter cpp-filters
|
||||||
|
}
|
||||||
|
|
||||||
hook global BufNew .*\.(h|hh|hpp|hxx|H) \
|
hook global BufNew .*\.(h|hh|hpp|hxx|H) %{
|
||||||
exec ggi<c-r>%<ret><esc>ggxs\.<ret>c_<esc><space>A_INCLUDED<esc>xyppI#ifndef<space><esc>jI#define<space><esc>jI#endif<space>//<space><esc>O<esc>
|
exec ggi<c-r>%<ret><esc>ggxs\.<ret>c_<esc><space>A_INCLUDED<esc>xyppI#ifndef<space><esc>jI#define<space><esc>jI#endif<space>//<space><esc>O<esc>
|
||||||
|
}
|
||||||
|
|
||||||
def alt edit \
|
def alt %{ edit %sh{
|
||||||
`case ${kak_bufname} in
|
case ${kak_bufname} in
|
||||||
*.c) echo ${kak_bufname/%c/h} ;;
|
*.c) echo ${kak_bufname/%c/h} ;;
|
||||||
*.cc) echo ${kak_bufname/%cc/hh} ;;
|
*.cc) echo ${kak_bufname/%cc/hh} ;;
|
||||||
*.cpp) echo ${kak_bufname/%cpp/hpp} ;;
|
*.cpp) echo ${kak_bufname/%cpp/hpp} ;;
|
||||||
|
@ -34,4 +38,5 @@ def alt edit \
|
||||||
*.hpp) echo ${kak_bufname/%hpp/cpp} ;;
|
*.hpp) echo ${kak_bufname/%hpp/cpp} ;;
|
||||||
*.hxx) echo ${kak_bufname/%hxx/cxx} ;;
|
*.hxx) echo ${kak_bufname/%hxx/cxx} ;;
|
||||||
*.H) echo ${kak_bufname/%H/C} ;;
|
*.H) echo ${kak_bufname/%H/C} ;;
|
||||||
esac`
|
esac
|
||||||
|
}}
|
|
@ -1,11 +1,14 @@
|
||||||
hook global BufCreate .*\.(diff|patch) \
|
hook global BufCreate .*\.(diff|patch) %{
|
||||||
setb filetype diff
|
setb filetype diff
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=diff \
|
hook global WinSetOption filetype=diff %{
|
||||||
addhl group diff-highlight; \
|
addhl group diff-highlight
|
||||||
addhl -group diff-highlight regex "^\+[^\n]*\n" green default; \
|
addhl -group diff-highlight regex "^\+[^\n]*\n" green default
|
||||||
addhl -group diff-highlight regex "^-[^\n]*\n" red default; \
|
addhl -group diff-highlight regex "^-[^\n]*\n" red default
|
||||||
addhl -group diff-highlight regex "^@@[^\n]*@@" cyan default;
|
addhl -group diff-highlight regex "^@@[^\n]*@@" cyan default
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=(?!diff).* \
|
hook global WinSetOption filetype=(?!diff).* %{
|
||||||
rmhl diff-highlight
|
rmhl diff-highlight
|
||||||
|
}
|
||||||
|
|
|
@ -1,23 +1,29 @@
|
||||||
hook global BufCreate .*COMMIT_EDITMSG \
|
hook global BufCreate .*COMMIT_EDITMSG %{
|
||||||
setb filetype git-commit
|
setb filetype git-commit
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=git-commit \
|
hook global WinSetOption filetype=git-commit %{
|
||||||
addhl group git-commit-highlight; \
|
addhl group git-commit-highlight
|
||||||
addhl -group git-commit-highlight regex "#[^\n]*\n" cyan default; \
|
addhl -group git-commit-highlight regex "#[^\n]*\n" cyan default
|
||||||
addhl -group git-commit-highlight regex "\<(modified|deleted|new file):[^\n]*\n" magenta default; \
|
addhl -group git-commit-highlight regex "\<(modified|deleted|new file):[^\n]*\n" magenta default
|
||||||
addhl -group git-commit-highlight regex "\<(modified|deleted|new file):" red default;
|
addhl -group git-commit-highlight regex "\<(modified|deleted|new file):" red default
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=(?!git-commit).* \
|
hook global WinSetOption filetype=(?!git-commit).* %{
|
||||||
rmhl git-commit-highlight
|
rmhl git-commit-highlight
|
||||||
|
}
|
||||||
|
|
||||||
hook global BufCreate .*git-rebase-todo \
|
hook global BufCreate .*git-rebase-todo %{
|
||||||
setb filetype git-rebase
|
setb filetype git-rebase
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=git-rebase \
|
hook global WinSetOption filetype=git-rebase %{
|
||||||
addhl group git-rebase-highlight; \
|
addhl group git-rebase-highlight
|
||||||
addhl -group git-rebase-highlight regex "#[^\n]*\n" cyan default; \
|
addhl -group git-rebase-highlight regex "#[^\n]*\n" cyan default
|
||||||
addhl -group git-rebase-highlight regex "^(pick|edit|reword|squash|fixup|exec|[persfx]) \w+" magenta default; \
|
addhl -group git-rebase-highlight regex "^(pick|edit|reword|squash|fixup|exec|[persfx]) \w+" magenta default
|
||||||
addhl -group git-rebase-highlight regex "^(pick|edit|reword|squash|fixup|exec|[persfx])" green default;
|
addhl -group git-rebase-highlight regex "^(pick|edit|reword|squash|fixup|exec|[persfx])" green default
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=(?!git-rebase).* \
|
hook global WinSetOption filetype=(?!git-rebase).* %{
|
||||||
rmhl git-rebase-highlight
|
rmhl git-rebase-highlight
|
||||||
|
}
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
def -env-params \
|
def -env-params \
|
||||||
-shell-completion 'global -c ${kak_param0}' \
|
-shell-completion %{ global -c ${kak_param0} } \
|
||||||
tag eval \
|
tag %{ eval %sh{
|
||||||
`if [[ ${kak_param0} != "" ]]; then
|
if [[ ${kak_param0} != "" ]]; then
|
||||||
tagname=${kak_param0}
|
tagname=${kak_param0}
|
||||||
else
|
else
|
||||||
tagname=${kak_selection}
|
tagname=${kak_selection}
|
||||||
fi
|
fi
|
||||||
params=$(global --result grep ${tagname} | sed "s/\([^:]*\):\([0-9]*\):\(.*\)/'\1:\2 \3' 'edit \1 \2; try exec \"20k41Xs\\\\Q\3<ret>\" catch echo \"could not find [\3] near \1:\2\"; exec \2g'/")
|
params=$(global --result grep ${tagname} | sed "s/\([^:]*\):\([0-9]*\):\(.*\)/'\1:\2 \3' 'edit \1 \2; try %{ exec \"20k41Xs\\\\Q\3<ret>\" } catch %{ echo \"could not find [\3] near \1:\2\"; exec \2g }'/")
|
||||||
if [[ ${params} != "" ]]; then
|
if [[ ${params} != "" ]]; then
|
||||||
echo "menu -auto-single $params"
|
echo "menu -auto-single ${params//$'\n'/ }"
|
||||||
else
|
else
|
||||||
echo echo tag ${tagname} not found
|
echo echo tag ${tagname} not found
|
||||||
fi`
|
fi
|
||||||
|
}}
|
||||||
|
|
|
@ -1,17 +1,20 @@
|
||||||
hook global BufCreate (.*/)?(kakrc|.*.kak) \
|
hook global BufCreate (.*/)?(kakrc|.*.kak) %{
|
||||||
setb filetype kak
|
setb filetype kak
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=kak \
|
hook global WinSetOption filetype=kak %{
|
||||||
addhl group kak-highlight; \
|
addhl group kak-highlight
|
||||||
addhl -group kak-highlight regex \<(hook|addhl|rmhl|addfilter|rmfilter|exec|source|runtime|def|echo|edit|set[gbw])\> green default; \
|
addhl -group kak-highlight regex \<(hook|addhl|rmhl|addfilter|rmfilter|exec|source|runtime|def|echo|edit|set[gbw])\> green default
|
||||||
addhl -group kak-highlight regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \
|
addhl -group kak-highlight regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default
|
||||||
addhl -group kak-highlight regex (?<=\<hook)(\h+\w+){2}\h+\H+ magenta default; \
|
addhl -group kak-highlight regex (?<=\<hook)(\h+\w+){2}\h+\H+ magenta default
|
||||||
addhl -group kak-highlight regex (?<=\<hook)(\h+\w+){2} cyan default; \
|
addhl -group kak-highlight regex (?<=\<hook)(\h+\w+){2} cyan default
|
||||||
addhl -group kak-highlight regex (?<=\<hook)(\h+\w+) red default; \
|
addhl -group kak-highlight regex (?<=\<hook)(\h+\w+) red default
|
||||||
addhl -group kak-highlight regex (?<=\<hook)(\h+(global|buffer|window)) blue default; \
|
addhl -group kak-highlight regex (?<=\<hook)(\h+(global|buffer|window)) blue default
|
||||||
addhl -group kak-highlight regex (?<=\<regex)\h+\S+ magenta default; \
|
addhl -group kak-highlight regex (?<=\<regex)\h+\S+ magenta default
|
||||||
addhl -group kak-highlight regex (?<=\<set[gbw])\h+\S+\h+\S+ magenta default; \
|
addhl -group kak-highlight regex (?<=\<set[gbw])\h+\S+\h+\S+ magenta default
|
||||||
addhl -group kak-highlight regex (?<=\<set[gbw])\h+\S+ red default
|
addhl -group kak-highlight regex (?<=\<set[gbw])\h+\S+ red default
|
||||||
|
}
|
||||||
|
|
||||||
hook global WinSetOption filetype=(?!kak).* \
|
hook global WinSetOption filetype=(?!kak).* %{
|
||||||
rmhl kak-highlight
|
rmhl kak-highlight
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user