Skip to content

Commit

Permalink
vis: implement g8
Browse files Browse the repository at this point in the history
Shows hex values up to the next UTF-8 encoded character.
  • Loading branch information
martanne committed Dec 21, 2016
1 parent 6aeb589 commit 0109dfc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ static const KeyBinding bindings_normal[] = {
{ "<Escape>", ACTION(CURSORS_REMOVE_ALL) },
{ "<F1>", ALIAS(":help<Enter>") },
{ "ga", ACTION(UNICODE_INFO) },
{ "g8", ACTION(UTF8_INFO) },
{ "g,", ACTION(CHANGELIST_NEXT) },
{ "g;", ACTION(CHANGELIST_PREV) },
{ "g-", ACTION(EARLIER) },
Expand Down
19 changes: 15 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ enum {
VIS_ACTION_MOTION_CHARWISE,
VIS_ACTION_MOTION_LINEWISE,
VIS_ACTION_UNICODE_INFO,
VIS_ACTION_UTF8_INFO,
VIS_ACTION_NUMBER_INCREMENT,
VIS_ACTION_NUMBER_DECREMENT,
VIS_ACTION_OPEN_FILE_UNDER_CURSOR,
Expand Down Expand Up @@ -1198,7 +1199,12 @@ static const KeyAction vis_action[] = {
[VIS_ACTION_UNICODE_INFO] = {
"unicode-info",
"Show Unicode codepoint(s) of character under cursor",
unicode_info,
unicode_info, { .i = VIS_ACTION_UNICODE_INFO }
},
[VIS_ACTION_UTF8_INFO] = {
"utf8-info",
"Show UTF-8 encoded codepoint(s) of character under cursor",
unicode_info, { .i = VIS_ACTION_UTF8_INFO }
},
[VIS_ACTION_NUMBER_INCREMENT] = {
"number-increment",
Expand Down Expand Up @@ -2004,10 +2010,15 @@ static const char *unicode_info(Vis *vis, const char *keys, const Arg *arg) {
combining = (wc != L'\0' && wcwidth(wc) == 0);
unsigned char ch = *codepoint;
if (ch < 128 && !isprint(ch))
buffer_appendf(&info, "<^%c>", ch == 127 ? '?' : ch + 64);
buffer_appendf(&info, "<^%c> ", ch == 127 ? '?' : ch + 64);
else
buffer_appendf(&info, "<%s%.*s>", combining ? " " : "", (int)len, codepoint);
buffer_appendf(&info, " U+%04x ", wc);
buffer_appendf(&info, "<%s%.*s> ", combining ? " " : "", (int)len, codepoint);
if (arg->i == VIS_ACTION_UNICODE_INFO) {
buffer_appendf(&info, "U+%04x ", wc);
} else {
for (size_t i = 0; i < len; i++)
buffer_appendf(&info, "%02x ", (uint8_t)codepoint[i]);
}
codepoint += len;
}
vis_info_show(vis, "%s", buffer_content0(&info));
Expand Down

0 comments on commit 0109dfc

Please sign in to comment.