From 55516af9d7cf5b28d4830e8eadd97302d5d9ddca Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 4 May 2012 04:25:09 +0000 Subject: [PATCH] remove {add,rm}grouphl, go back to a -group arg in {add,rm}hl more consistency, more shared code --- src/main.cc | 102 ++++++++++++++++++++++------------------------- src/rc/cpp.kak | 14 +++---- src/rc/git.kak | 12 +++--- src/rc/kakrc.kak | 14 +++---- 4 files changed, 68 insertions(+), 74 deletions(-) diff --git a/src/main.cc b/src/main.cc index 599ef62a..420bcb88 100644 --- a/src/main.cc +++ b/src/main.cc @@ -300,33 +300,26 @@ void add_highlighter(const CommandParameters& params, const Context& context) { if (params.size() < 1) throw wrong_argument_count(); - - try - { - HighlighterRegistry& registry = HighlighterRegistry::instance(); - HighlighterParameters highlighter_params(params.begin()+1, params.end()); - registry.add_highlighter_to_window(context.window(), params[0], - highlighter_params); - } - catch (runtime_error& err) - { - NCurses::print_status("error: " + err.description()); - } -} - -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().highlighters().get_group(params[0]); - HighlighterParameters highlighter_params(params.begin()+2, params.end()); - registry.add_highlighter_to_group(context.window(), group, - params[1], highlighter_params); + if (params[0] == "-group") + { + if (params.size() < 3) + throw wrong_argument_count(); + HighlighterParameters highlighter_params(params.begin()+3, params.end()); + HighlighterGroup& group = context.window().highlighters().get_group(params[1]); + 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); + } + } catch (runtime_error& err) { @@ -336,27 +329,30 @@ void add_group_highlighter(const CommandParameters& params, const Context& conte void rm_highlighter(const CommandParameters& params, const Context& context) { - if (params.size() != 1) + if (params.size() < 1) throw wrong_argument_count(); - - context.window().highlighters().remove(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().highlighters().get_group(params[0]); - group.remove(params[1]); + if (params[0] == "-group") + { + if (params.size() != 3) + throw wrong_argument_count(); + HighlighterGroup& group = context.window().highlighters().get_group(params[1]); + group.remove(params[2]); + } + else + { + if (params.size() != 1) + throw wrong_argument_count(); + context.window().highlighters().remove(params[0]); + } } catch (runtime_error& err) { NCurses::print_status("error: " + err.description()); } } + void add_filter(const CommandParameters& params, const Context& context) { if (params.size() < 1) @@ -931,33 +927,31 @@ int main(int argc, char* argv[]) })); command_manager.register_commands({ "ah", "addhl" }, add_highlighter, CommandManager::None, - PerArgumentCommandCompleter({ - std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2) - })); - command_manager.register_commands({ "agh", "addgrouphl" }, add_group_highlighter, - CommandManager::None, - PerArgumentCommandCompleter({ - [&](const String& prefix, size_t cursor_pos) - { return main_context.window().highlighters().complete_group_id(prefix, cursor_pos); }, - std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2) - })); + [&](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token) + { + Window& w = main_context.window(); + const String& arg = token_to_complete < params.size() ? + params[token_to_complete] : String(); + if (token_to_complete == 1 and params[0] == "-group") + return w.highlighters().complete_group_id(arg, pos_in_token); + else if (token_to_complete == 0 or token_to_complete == 2 and params[0] == "-group") + return highlighter_registry.complete_highlighter(arg, pos_in_token); + else + return CandidateList(); + }); command_manager.register_commands({ "rh", "rmhl" }, rm_highlighter, - CommandManager::None, - PerArgumentCommandCompleter({ - [&](const String& prefix, size_t cursor_pos) - { return main_context.window().highlighters().complete_group_id(prefix, cursor_pos); } - })); - command_manager.register_commands({ "rgh", "rmgrouphl" }, rm_group_highlighter, CommandManager::None, [&](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token) { Window& w = main_context.window(); const String& arg = token_to_complete < params.size() ? params[token_to_complete] : String(); - if (token_to_complete == 0) + if (token_to_complete == 1 and params[0] == "-group") return w.highlighters().complete_group_id(arg, pos_in_token); - else if (token_to_complete == 1) - return w.highlighters().get_group(params[0]).complete_id(arg, pos_in_token); + else if (token_to_complete == 2 and params[0] == "-group") + return w.highlighters().get_group(params[1]).complete_id(arg, pos_in_token); + else + return w.highlighters().complete_id(arg, pos_in_token); }); command_manager.register_commands({ "af", "addfilter" }, add_filter, CommandManager::None, diff --git a/src/rc/cpp.kak b/src/rc/cpp.kak index 140e36af..deb1ea5d 100644 --- a/src/rc/cpp.kak +++ b/src/rc/cpp.kak @@ -1,12 +1,12 @@ hook global WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) \ addhl group hlcpp; \ - addgrouphl hlcpp regex "\<(this|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|friend)\>" green default; \ - addgrouphl hlcpp regex "(?|\<-?\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|friend)\>" green default; \ + addhl -group hlcpp regex "(?d diff --git a/src/rc/git.kak b/src/rc/git.kak index 4d5603fe..daf8c6a0 100644 --- a/src/rc/git.kak +++ b/src/rc/git.kak @@ -1,12 +1,12 @@ hook global WinCreate .*COMMIT_EDITMSG \ addhl group hlgit; \ - addgrouphl hlgit regex "#[^\n]*\n" cyan default; \ - addgrouphl hlgit regex "\<(modified|deleted|new file):[^\n]*\n" magenta default; \ - addgrouphl hlgit regex "\<(modified|deleted|new file):" red default; + addhl -group hlgit regex "#[^\n]*\n" cyan default; \ + addhl -group hlgit regex "\<(modified|deleted|new file):[^\n]*\n" magenta default; \ + addhl -group hlgit regex "\<(modified|deleted|new file):" red default; hook global WinCreate .*git-rebase-todo \ addhl group hlgit; \ - addgrouphl hlgit regex "#[^\n]*\n" cyan default; \ - addgrouphl hlgit regex "^(pick|edit|reword|squash|fixup|exec|[persfx]) \w+" magenta default; \ - addgrouphl hlgit regex "^(pick|edit|reword|squash|fixup|exec|[persfx])" green default; + addhl -group hlgit regex "#[^\n]*\n" cyan default; \ + addhl -group hlgit regex "^(pick|edit|reword|squash|fixup|exec|[persfx]) \w+" magenta default; \ + addhl -group hlgit regex "^(pick|edit|reword|squash|fixup|exec|[persfx])" green default; diff --git a/src/rc/kakrc.kak b/src/rc/kakrc.kak index 5c258eb0..50c5616b 100644 --- a/src/rc/kakrc.kak +++ b/src/rc/kakrc.kak @@ -1,9 +1,9 @@ hook global WinCreate (.*/)?(kakrc|.*.kak) \ addhl group hlkakrc; \ - addgrouphl hlkakrc regex \<(hook|addhl|rmhl|addgrouphl|rmgrouphl|addfilter|rmfilter|exec|source|runtime|def|echo|edit)\> green default; \ - addgrouphl hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \ - addgrouphl hlkakrc regex (?<=\ green default; \ + addhl -group hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \ + addhl -group hlkakrc regex (?<=\