From cffdbcb6891d0c6a27d9486cf58415708ef96ad2 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 18 Jan 2012 00:15:10 +0000 Subject: [PATCH] replace addhl -group with addgrouphl command, and add rmgrouphl --- src/main.cc | 54 ++++++++++++++++++++++++++++++++++-------------- src/rc/cpp.kak | 14 ++++++------- src/rc/kakrc.kak | 10 ++++----- 3 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/main.cc b/src/main.cc index 1cd671bc..ff9e54f0 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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{ "agh", "addgrouphl" }, add_group_highlighter); command_manager.register_command(std::vector{ "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{ "rgh", "rmgrouphl" }, rm_group_highlighter); command_manager.register_command(std::vector{ "af", "addfilter" }, add_filter, CommandManager::None, PerArgumentCommandCompleter { diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index 6838fd51..f25c73dc 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -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 "(?|\<-?\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 "(? green default; \ - addhl -group hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \ - addhl -group hlkakrc regex (?<=\ green default; \ + addgrouphl hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \ + addgrouphl hlkakrc regex (?<=\