Skip to content

Commit

Permalink
Highlight ASCII control characters unambiguously
Browse files Browse the repository at this point in the history
Previously, all ASCII control characters would be shown as the replacement
character. This leads to a visual loss of information and ambiguities,
particularly when opening files that contain lots of control characters (or
binary files). Use the common circumflex notation, known from software such as
`cat -v` or vim, instead.

Fixes mawww#2936
  • Loading branch information
alois31 committed Sep 8, 2024
1 parent 642680a commit 1634f9d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/highlighters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,12 @@ void expand_unprintable(HighlightContext context, DisplayBuffer& display_buffer,
if (ByteCount pos(next - line_data); pos < atom_it->end().column)
atom_it = line.split(atom_it, {begin.line, pos});

atom_it->replace("");
if (cp < ' ')
atom_it->replace(format("^{}", (char)(cp + '@')));
else if (cp == 127)
atom_it->replace("^?");
else
atom_it->replace("");
atom_it->face = error;
break;
}
Expand Down

0 comments on commit 1634f9d

Please sign in to comment.