{line,column}_option highlighters use an expanded string instead of an option name
That allows access to non option values, such as cursor_column or cursor_line with :addhl line '%val{cursor_line}' default,rgb:404040 Fixes #38
This commit is contained in:
parent
cfdf03ab31
commit
1a1db1cb3a
|
@ -26,7 +26,7 @@ def -shell-params -file-completion \
|
|||
hook global WinSetOption filetype=grep %{
|
||||
addhl group grep
|
||||
addhl -group grep regex "^((?:\w:)?[^:]+):(\d+):(\d+)?" 1:cyan 2:green 3:green
|
||||
addhl -group grep line_option _grep_current_line default+b
|
||||
addhl -group grep line %{%opt{_grep_current_line}} default+b
|
||||
hook buffer -group grep-hooks NormalKey <c-m> jump
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ def -shell-params make %{ %sh{
|
|||
|
||||
addhl -group / group make
|
||||
addhl -group /make regex "^((?:\w:)?[^:\n]+):(\d+):(?:(\d+):)?\h+(?:((?:fatal )?error)|(warning)|(note)|(required from(?: here)?))?.*?$" 1:cyan 2:green 3:green 4:red 5:yellow 6:blue 7:yellow
|
||||
addhl -group /make line_option _make_current_error_line default+b
|
||||
addhl -group /make line %{%opt{_make_current_error_line}} default+b
|
||||
|
||||
hook global WinSetOption filetype=make %{
|
||||
addhl ref make
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "buffer_utils.hh"
|
||||
#include "context.hh"
|
||||
#include "containers.hh"
|
||||
#include "command_manager.hh"
|
||||
#include "display_buffer.hh"
|
||||
#include "face_registry.hh"
|
||||
#include "highlighter_group.hh"
|
||||
|
@ -491,7 +492,7 @@ HighlighterAndId create_regex_option_highlighter(HighlighterParameters params)
|
|||
return {"hloption_" + option_name, make_dynamic_regex_highlighter(get_regex, get_face)};
|
||||
}
|
||||
|
||||
HighlighterAndId create_line_option_highlighter(HighlighterParameters params)
|
||||
HighlighterAndId create_line_highlighter(HighlighterParameters params)
|
||||
{
|
||||
if (params.size() != 2)
|
||||
throw runtime_error("wrong parameter count");
|
||||
|
@ -500,20 +501,19 @@ HighlighterAndId create_line_option_highlighter(HighlighterParameters params)
|
|||
String option_name = params[0];
|
||||
|
||||
get_face(facespec); // validate facespec
|
||||
GlobalScope::instance().options()[option_name].get<int>(); // verify option type now
|
||||
|
||||
auto func = [=](const Context& context, HighlightFlags flags,
|
||||
DisplayBuffer& display_buffer, BufferRange)
|
||||
{
|
||||
int line = context.options()[option_name].get<int>();
|
||||
highlight_range(display_buffer, {line-1, 0}, {line, 0}, false,
|
||||
if (auto line = str_to_int_ifp(expand(option_name, context, {}, EnvVarMap{})))
|
||||
highlight_range(display_buffer, {*line-1, 0}, {*line, 0}, false,
|
||||
apply_face(get_face(facespec)));
|
||||
};
|
||||
|
||||
return {"hlline_" + params[0], make_simple_highlighter(std::move(func))};
|
||||
}
|
||||
|
||||
HighlighterAndId create_column_option_highlighter(HighlighterParameters params)
|
||||
HighlighterAndId create_column_highlighter(HighlighterParameters params)
|
||||
{
|
||||
if (params.size() != 2)
|
||||
throw runtime_error("wrong parameter count");
|
||||
|
@ -522,12 +522,11 @@ HighlighterAndId create_column_option_highlighter(HighlighterParameters params)
|
|||
String option_name = params[0];
|
||||
|
||||
get_face(facespec); // validate facespec
|
||||
GlobalScope::instance().options()[option_name].get<int>(); // verify option type now
|
||||
|
||||
auto func = [=](const Context& context, HighlightFlags flags,
|
||||
DisplayBuffer& display_buffer, BufferRange)
|
||||
{
|
||||
const CharCount column = context.options()[option_name].get<int>() - 1;
|
||||
const CharCount column = str_to_int_ifp(expand(option_name, context, {}, EnvVarMap{})).value_or(0) - 1;
|
||||
if (column < 0)
|
||||
return;
|
||||
|
||||
|
@ -1341,15 +1340,15 @@ void register_highlighters()
|
|||
"Display flags specified in the line-flag-list option <option name>\n"
|
||||
"A line-flag is written: <line>|<fg color>|<text>, the list is : separated" } });
|
||||
registry.append({
|
||||
"line_option",
|
||||
{ create_line_option_highlighter,
|
||||
"Parameters: <option name> <face>\n"
|
||||
"Highlight the line stored in <option name> with <face>" } });
|
||||
"line",
|
||||
{ create_line_highlighter,
|
||||
"Parameters: <value string> <face>\n"
|
||||
"Highlight the line given by evaluating <value string> with <face>" } });
|
||||
registry.append({
|
||||
"column_option",
|
||||
{ create_column_option_highlighter,
|
||||
"Parameters: <option name> <face>\n"
|
||||
"Highlight the column stored in <option name> with <face>" } });
|
||||
"column",
|
||||
{ create_column_highlighter,
|
||||
"Parameters: <value string> <face>\n"
|
||||
"Highlight the column given by evaluating <value string> with <face>" } });
|
||||
registry.append({
|
||||
"ref",
|
||||
{ create_reference_highlighter,
|
||||
|
|
Loading…
Reference in New Issue
Block a user