From 1a1db1cb3aa2afad849ac9619e524086ec306df8 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 4 May 2015 17:12:51 +0100 Subject: [PATCH] {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 --- rc/grep.kak | 2 +- rc/make.kak | 2 +- src/highlighters.cc | 31 +++++++++++++++---------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/rc/grep.kak b/rc/grep.kak index 76a1f7c1..1ef9d98c 100644 --- a/rc/grep.kak +++ b/rc/grep.kak @@ -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 jump } diff --git a/rc/make.kak b/rc/make.kak index ef25cee1..7de757c9 100644 --- a/rc/make.kak +++ b/rc/make.kak @@ -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 diff --git a/src/highlighters.cc b/src/highlighters.cc index 4323f674..839ab4b6 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -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(); // verify option type now auto func = [=](const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange) { - int line = context.options()[option_name].get(); - highlight_range(display_buffer, {line-1, 0}, {line, 0}, false, - apply_face(get_face(facespec))); + 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(); // verify option type now auto func = [=](const Context& context, HighlightFlags flags, DisplayBuffer& display_buffer, BufferRange) { - const CharCount column = context.options()[option_name].get() - 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