remove {add,rm}grouphl, go back to a -group arg in {add,rm}hl
more consistency, more shared code
This commit is contained in:
parent
7158aa00b7
commit
55516af9d7
96
src/main.cc
96
src/main.cc
|
@ -300,33 +300,26 @@ void add_highlighter(const CommandParameters& params, const Context& context)
|
||||||
{
|
{
|
||||||
if (params.size() < 1)
|
if (params.size() < 1)
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HighlighterRegistry& registry = HighlighterRegistry::instance();
|
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[0] == "-group")
|
||||||
{
|
{
|
||||||
if (params.size() < 2)
|
if (params.size() < 3)
|
||||||
throw wrong_argument_count();
|
throw wrong_argument_count();
|
||||||
|
HighlighterParameters highlighter_params(params.begin()+3, params.end());
|
||||||
try
|
HighlighterGroup& group = context.window().highlighters().get_group(params[1]);
|
||||||
{
|
|
||||||
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,
|
registry.add_highlighter_to_group(context.window(), group,
|
||||||
params[1], highlighter_params);
|
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)
|
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)
|
void rm_highlighter(const CommandParameters& params, const Context& context)
|
||||||
{
|
{
|
||||||
if (params.size() != 1)
|
if (params.size() < 1)
|
||||||
throw wrong_argument_count();
|
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
|
try
|
||||||
{
|
{
|
||||||
HighlighterGroup& group = context.window().highlighters().get_group(params[0]);
|
if (params[0] == "-group")
|
||||||
group.remove(params[1]);
|
{
|
||||||
|
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)
|
catch (runtime_error& err)
|
||||||
{
|
{
|
||||||
NCurses::print_status("error: " + err.description());
|
NCurses::print_status("error: " + err.description());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void add_filter(const CommandParameters& params, const Context& context)
|
void add_filter(const CommandParameters& params, const Context& context)
|
||||||
{
|
{
|
||||||
if (params.size() < 1)
|
if (params.size() < 1)
|
||||||
|
@ -931,33 +927,31 @@ int main(int argc, char* argv[])
|
||||||
}));
|
}));
|
||||||
command_manager.register_commands({ "ah", "addhl" }, add_highlighter,
|
command_manager.register_commands({ "ah", "addhl" }, add_highlighter,
|
||||||
CommandManager::None,
|
CommandManager::None,
|
||||||
PerArgumentCommandCompleter({
|
[&](const CommandParameters& params, size_t token_to_complete, size_t pos_in_token)
|
||||||
std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2)
|
{
|
||||||
}));
|
Window& w = main_context.window();
|
||||||
command_manager.register_commands({ "agh", "addgrouphl" }, add_group_highlighter,
|
const String& arg = token_to_complete < params.size() ?
|
||||||
CommandManager::None,
|
params[token_to_complete] : String();
|
||||||
PerArgumentCommandCompleter({
|
if (token_to_complete == 1 and params[0] == "-group")
|
||||||
[&](const String& prefix, size_t cursor_pos)
|
return w.highlighters().complete_group_id(arg, pos_in_token);
|
||||||
{ return main_context.window().highlighters().complete_group_id(prefix, cursor_pos); },
|
else if (token_to_complete == 0 or token_to_complete == 2 and params[0] == "-group")
|
||||||
std::bind(&HighlighterRegistry::complete_highlighter, &highlighter_registry, _1, _2)
|
return highlighter_registry.complete_highlighter(arg, pos_in_token);
|
||||||
}));
|
else
|
||||||
|
return CandidateList();
|
||||||
|
});
|
||||||
command_manager.register_commands({ "rh", "rmhl" }, rm_highlighter,
|
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,
|
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();
|
||||||
const String& arg = token_to_complete < params.size() ?
|
const String& arg = token_to_complete < params.size() ?
|
||||||
params[token_to_complete] : String();
|
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);
|
return w.highlighters().complete_group_id(arg, pos_in_token);
|
||||||
else if (token_to_complete == 1)
|
else if (token_to_complete == 2 and params[0] == "-group")
|
||||||
return w.highlighters().get_group(params[0]).complete_id(arg, pos_in_token);
|
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,
|
command_manager.register_commands({ "af", "addfilter" }, add_filter,
|
||||||
CommandManager::None,
|
CommandManager::None,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
hook global WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) \
|
hook global WinCreate .*\.(c|cc|cpp|cxx|C|h|hh|hpp|hxx|H) \
|
||||||
addhl group hlcpp; \
|
addhl group hlcpp; \
|
||||||
addgrouphl hlcpp regex "\<(this|true|false|NULL|nullptr)\>|\<-?\d+[fdiu]?|'((\\.)?|[^'\\])'" red default; \
|
addhl -group hlcpp regex "\<(this|true|false|NULL|nullptr)\>|\<-?\d+[fdiu]?|'((\\.)?|[^'\\])'" red default; \
|
||||||
addgrouphl hlcpp regex "\<(void|int|char|unsigned|float|bool|size_t)\>" yellow default; \
|
addhl -group 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; \
|
addhl -group 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; \
|
addhl -group hlcpp regex "\<(const|auto|namespace|static|volatile|class|struct|enum|union|public|protected|private|template|typedef|virtual|friend)\>" green default; \
|
||||||
addgrouphl hlcpp regex "(?<!')\"(\\\"|[^\"])*\"" magenta default; \
|
addhl -group hlcpp regex "(?<!')\"(\\\"|[^\"])*\"" magenta default; \
|
||||||
addgrouphl hlcpp regex "(\`|(?<=\n))\h*#\h*[^\n]*" magenta default; \
|
addhl -group hlcpp regex "(\`|(?<=\n))\h*#\h*[^\n]*" magenta default; \
|
||||||
addgrouphl hlcpp regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" cyan default; \
|
addhl -group hlcpp regex "(//[^\n]*\n)|(/\*.*?(\*/|\'))" cyan default; \
|
||||||
addfilter preserve_indent; \
|
addfilter preserve_indent; \
|
||||||
addfilter cleanup_whitespaces; \
|
addfilter cleanup_whitespaces; \
|
||||||
hook window InsertEnd .* exec xs\h+(?=\n)<ret>d
|
hook window InsertEnd .* exec xs\h+(?=\n)<ret>d
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
hook global WinCreate .*COMMIT_EDITMSG \
|
hook global WinCreate .*COMMIT_EDITMSG \
|
||||||
addhl group hlgit; \
|
addhl group hlgit; \
|
||||||
addgrouphl hlgit regex "#[^\n]*\n" cyan default; \
|
addhl -group hlgit regex "#[^\n]*\n" cyan default; \
|
||||||
addgrouphl hlgit regex "\<(modified|deleted|new file):[^\n]*\n" magenta default; \
|
addhl -group hlgit regex "\<(modified|deleted|new file):[^\n]*\n" magenta default; \
|
||||||
addgrouphl hlgit regex "\<(modified|deleted|new file):" red default;
|
addhl -group hlgit regex "\<(modified|deleted|new file):" red default;
|
||||||
|
|
||||||
hook global WinCreate .*git-rebase-todo \
|
hook global WinCreate .*git-rebase-todo \
|
||||||
addhl group hlgit; \
|
addhl group hlgit; \
|
||||||
addgrouphl hlgit regex "#[^\n]*\n" cyan default; \
|
addhl -group hlgit regex "#[^\n]*\n" cyan default; \
|
||||||
addgrouphl hlgit regex "^(pick|edit|reword|squash|fixup|exec|[persfx]) \w+" magenta default; \
|
addhl -group 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 "^(pick|edit|reword|squash|fixup|exec|[persfx])" green default;
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
hook global WinCreate (.*/)?(kakrc|.*.kak) \
|
hook global WinCreate (.*/)?(kakrc|.*.kak) \
|
||||||
addhl group hlkakrc; \
|
addhl group hlkakrc; \
|
||||||
addgrouphl hlkakrc regex \<(hook|addhl|rmhl|addgrouphl|rmgrouphl|addfilter|rmfilter|exec|source|runtime|def|echo|edit)\> green default; \
|
addhl -group hlkakrc regex \<(hook|addhl|rmhl|addfilter|rmfilter|exec|source|runtime|def|echo|edit)\> green default; \
|
||||||
addgrouphl hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \
|
addhl -group hlkakrc regex \<(default|black|red|green|yellow|blue|magenta|cyan|white)\> yellow default; \
|
||||||
addgrouphl hlkakrc regex (?<=\<hook)(\h+\w+){2}\h+\H+ magenta default; \
|
addhl -group hlkakrc regex (?<=\<hook)(\h+\w+){2}\h+\H+ magenta default; \
|
||||||
addgrouphl hlkakrc regex (?<=\<hook)(\h+\w+){2} cyan default; \
|
addhl -group hlkakrc regex (?<=\<hook)(\h+\w+){2} cyan default; \
|
||||||
addgrouphl hlkakrc regex (?<=\<hook)(\h+\w+) red default; \
|
addhl -group hlkakrc regex (?<=\<hook)(\h+\w+) red default; \
|
||||||
addgrouphl hlkakrc regex (?<=\<hook)(\h+(global|window)) blue default; \
|
addhl -group hlkakrc regex (?<=\<hook)(\h+(global|window)) blue default; \
|
||||||
addgrouphl hlkakrc regex (?<=\<regex)\h+\H+ magenta default
|
addhl -group hlkakrc regex (?<=\<regex)\h+\H+ magenta default
|
||||||
|
|
Loading…
Reference in New Issue
Block a user