Skip to content

Commit 22b476f

Browse files
committed
remove SwitchesOnlyOnStart, better code style
- use `and` instead of && - better name for var instead of ruler_provided - else if and { on newline
1 parent a6669af commit 22b476f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/highlighters.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,22 +524,22 @@ const HighlighterDesc column_desc = {
524524
"Highlight the column <column> with <face>",
525525
{
526526
{ { "ruler", { ArgCompleter{}, "replace empty or whitespace cells with the given character. When provided, <face> is not applied to non-empty cells" } } },
527-
ParameterDesc::Flags::SwitchesOnlyAtStart, 2, 2
527+
ParameterDesc::Flags::None, 2, 2
528528
},
529529
};
530530
UniquePtr<Highlighter> create_column_highlighter(HighlighterParameters params, Highlighter*)
531531
{
532532
ParametersParser parser{params, column_desc.params};
533533

534534
auto positionals = parser.positionals_from(0);
535-
auto ruler = parser.get_switch("ruler");
536-
if (ruler.value_or(" ").char_length() > 1)
537-
throw runtime_error("-ruler expects a single character");
538535

539-
auto ruler_provided = static_cast<bool>(ruler);
536+
auto ruler = parser.get_switch("ruler");
537+
bool highlight_non_blank = static_cast<bool>(ruler);
540538
auto col_char = ruler.value_or(" ").str();
539+
if (col_char.char_length() > 1)
540+
throw runtime_error("-ruler expects a single character");
541541

542-
auto func = [col_expr=positionals[0], facespec=parse_face(positionals[1]), ruler_provided, col_char]
542+
auto func = [col_expr=positionals[0], facespec=parse_face(positionals[1]), highlight_non_blank, col_char]
543543
(HighlightContext context, DisplayBuffer& display_buffer, BufferRange)
544544
{
545545
ColumnCount column = -1;
@@ -574,9 +574,10 @@ UniquePtr<Highlighter> create_column_highlighter(HighlighterParameters params, H
574574
atom_it = ++line.split(atom_it, remaining_col);
575575
if (atom_it->length() > 1)
576576
atom_it = line.split(atom_it, 1_col);
577-
if (!ruler_provided)
577+
if (!highlight_non_blank)
578578
atom_it->face = merge_faces(atom_it->face, face);
579-
if (ruler_provided && is_blank(atom_it->content()[0])) {
579+
else if (is_blank(atom_it->content()[0]))
580+
{
580581
atom_it->replace(col_char);
581582
atom_it->face = merge_faces(atom_it->face, face);
582583
}

0 commit comments

Comments
 (0)