1919#include " utf8.hh"
2020#include " utf8_iterator.hh"
2121#include " window.hh"
22+ #include " unicode.hh"
2223
2324#include < cstdio>
2425#include < limits>
@@ -519,16 +520,26 @@ UniquePtr<Highlighter> create_line_highlighter(HighlighterParameters params, Hig
519520}
520521
521522const HighlighterDesc column_desc = {
522- " Parameters: <value string> <face>\n "
523- " Highlight the column given by evaluating <value string> with <face>" ,
524- {}
523+ " Parameters: [-ruler <character>] <column> <face>\n "
524+ " Highlight the column <column> with <face>" ,
525+ {
526+ { { " ruler" , { ArgCompleter{}, " replace empty or whitespace cells with the given character. When provided, <face> is not applied to non-empty cells" } } },
527+ ParameterDesc::Flags::None, 2 , 2
528+ },
525529};
526530UniquePtr<Highlighter> create_column_highlighter (HighlighterParameters params, Highlighter*)
527531{
528- if (params.size () != 2 )
529- throw runtime_error (" wrong parameter count" );
532+ ParametersParser parser{params, column_desc.params };
533+
534+ auto positionals = parser.positionals_from (0 );
530535
531- auto func = [col_expr=params[0 ], facespec=parse_face (params[1 ])]
536+ auto ruler = parser.get_switch (" ruler" );
537+ bool highlight_non_blank = not (bool )ruler;
538+ auto col_char = ruler.value_or (" " ).str ();
539+ if (col_char.char_length () > 1 )
540+ throw runtime_error (" -ruler expects a single character" );
541+
542+ auto func = [col_expr=positionals[0 ], facespec=parse_face (positionals[1 ]), highlight_non_blank, col_char]
532543 (HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
533544 {
534545 ColumnCount column = -1 ;
@@ -563,7 +574,13 @@ UniquePtr<Highlighter> create_column_highlighter(HighlighterParameters params, H
563574 atom_it = ++line.split (atom_it, remaining_col);
564575 if (atom_it->length () > 1 )
565576 atom_it = line.split (atom_it, 1_col);
566- atom_it->face = merge_faces (atom_it->face , face);
577+ if (highlight_non_blank)
578+ atom_it->face = merge_faces (atom_it->face , face);
579+ else if (is_blank (atom_it->content ()[0 ]))
580+ {
581+ atom_it->replace (col_char);
582+ atom_it->face = merge_faces (atom_it->face , face);
583+ }
567584 found = true ;
568585 break ;
569586 }
@@ -574,7 +591,7 @@ UniquePtr<Highlighter> create_column_highlighter(HighlighterParameters params, H
574591
575592 if (remaining_col > 0 )
576593 line.push_back ({String{' ' , remaining_col}, Face{}});
577- line.push_back ({" " , face});
594+ line.push_back ({col_char , face});
578595 }
579596 };
580597
0 commit comments