replace addhl -group with addgrouphl command, and add rmgrouphl

This commit is contained in:
Maxime Coste 2012-01-18 00:15:10 +00:00
parent ae8882b0de
commit cffdbcb689
3 changed files with 51 additions and 27 deletions

View File

@ -485,22 +485,29 @@ void add_highlighter(const CommandParameters& params, const Context& context)
try
{
HighlighterRegistry& registry = HighlighterRegistry::instance();
if (params[0] == "-group")
{
if (params.size() < 3)
throw wrong_argument_count();
HighlighterParameters highlighter_params(params.begin()+1, params.end());
registry.add_highlighter_to_window(context.window(), params[0],
highlighter_params);
}
catch (runtime_error& err)
{
print_status("error: " + err.description());
}
}
HighlighterGroup& group = context.window().get_highlighter_group(params[1]);
HighlighterParameters highlighter_params(params.begin()+3, params.end());
registry.add_highlighter_to_group(context.window(), group,
params[2], highlighter_params);
}
else
{
HighlighterParameters highlighter_params(params.begin()+1, params.end());
registry.add_highlighter_to_window(context.window(), params[0],
highlighter_params);
}
void add_group_highlighter(const CommandParameters& params, const Context& context)
{
if (params.size() < 2)
throw wrong_argument_count();
try
{
HighlighterRegistry& registry = HighlighterRegistry::instance();
HighlighterGroup& group = context.window().get_highlighter_group(params[0]);
HighlighterParameters highlighter_params(params.begin()+2, params.end());
registry.add_highlighter_to_group(context.window(), group,
params[1], highlighter_params);
}
catch (runtime_error& err)
{
@ -516,6 +523,21 @@ void rm_highlighter(const CommandParameters& params, const Context& context)
context.window().remove_highlighter(params[0]);
}
void rm_group_highlighter(const CommandParameters& params, const Context& context)
{
if (params.size() != 2)
throw wrong_argument_count();
try
{
HighlighterGroup& group = context.window().get_highlighter_group(params[0]);
group.remove_highlighter(params[1]);
}
catch (runtime_error& err)
{
print_status("error: " + err.description());
}
}
void add_filter(const CommandParameters& params, const Context& context)
{
if (params.size() < 1)
@ -944,12 +966,14 @@ int main(int argc, char* argv[])
PerArgumentCommandCompleter {
std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2)
});
command_manager.register_command(std::vector<std::string>{ "agh", "addgrouphl" }, add_group_highlighter);
command_manager.register_command(std::vector<std::string>{ "rh", "rmhl" }, rm_highlighter,
CommandManager::None,
PerArgumentCommandCompleter {
[&](const std::string& prefix, size_t cursor_pos)
{ return main_context.window().complete_highlighterid(prefix, cursor_pos); }
});
command_manager.register_command(std::vector<std::string>{ "rgh", "rmgrouphl" }, rm_group_highlighter);
command_manager.register_command(std::vector<std::string>{ "af", "addfilter" }, add_filter,
CommandManager::None,
PerArgumentCommandCompleter {

View File

@ -1,11 +1,11 @@
hook WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) \
addhl group hlcpp; \
addhl -group hlcpp regex "\<(true|false|NULL|nullptr)\>|\<-?\d+[fdiu]?|'((\\.)?|[^'\\])'" red default; \
addhl -group hlcpp regex "\<(void|int|char|unsigned|float|bool|size_t)\>" yellow default; \
addhl -group hlcpp regex "\<(while|for|if|else|do|switch|case|default|goto|break|continue|return|using|try|catch|throw)\>" blue default; \
addhl -group hlcpp regex "\<(const|auto|namespace|static|volatile|class|struct|enum|union|public|protected|private|template|typedef|virtual)\>" green default; \
addhl -group hlcpp regex "(?<!')\"(\\\"|[^\"])*\"" magenta default; \
addhl -group hlcpp regex "(\`|(?<=\n))\h*#\h*[^\n]*" magenta default; \
addhl -group hlcpp regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" cyan default; \
addgrouphl hlcpp regex "\<(true|false|NULL|nullptr)\>|\<-?\d+[fdiu]?|'((\\.)?|[^'\\])'" red default; \
addgrouphl hlcpp regex "\<(void|int|char|unsigned|float|bool|size_t)\>" yellow default; \
addgrouphl hlcpp regex "\<(while|for|if|else|do|switch|case|default|goto|break|continue|return|using|try|catch|throw)\>" blue default; \
addgrouphl hlcpp regex "\<(const|auto|namespace|static|volatile|class|struct|enum|union|public|protected|private|template|typedef|virtual)\>" green default; \
addgrouphl hlcpp regex "(?<!')\"(\\\"|[^\"])*\"" magenta default; \
addgrouphl hlcpp regex "(\`|(?<=\n))\h*#\h*[^\n]*" magenta default; \
addgrouphl hlcpp regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" cyan default; \
addfilter preserve_indent; \
addfilter cleanup_whitespaces

View File

@ -1,7 +1,7 @@
hook WinCreate (.*/)?(kakrc|.*.kak) \
addhl group hlkakrc; \
addhl -group hlkakrc regex \<(hook|addhl|rmhl|addfilter|rmfilter|exec|source|runtime)\> green default; \
addhl -group hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \
addhl -group hlkakrc regex (?<=\<hook)\h+\w+\h+\H+ magenta default; \
addhl -group hlkakrc regex (?<=\<hook)\h+\w+ cyan default; \
addhl -group hlkakrc regex (?<=\<regex)\h+\H+ magenta default
addgrouphl hlkakrc regex \<(hook|addhl|rmhl|addgrouphl|rmgrouphl|addfilter|rmfilter|exec|source|runtime)\> green default; \
addgrouphl hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \
addgrouphl hlkakrc regex (?<=\<hook)\h+\w+\h+\H+ magenta default; \
addgrouphl hlkakrc regex (?<=\<hook)\h+\w+ cyan default; \
addgrouphl hlkakrc regex (?<=\<regex)\h+\H+ magenta default