Skip to content

Commit

Permalink
vis: implement ga
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Nov 23, 2015
1 parent fafecae commit c4d675a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ static KeyBinding vis_mode_normal[] = {
{ "gv", ACTION(SELECTION_RESTORE) },
{ "m", ACTION(MARK_SET) },
{ "<F1>", ALIAS(":help<Enter>") },
{ "ga", ACTION(UNICODE_INFO) },
{ /* empty last element, array terminator */ },
};

Expand Down
31 changes: 31 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ static const char *wslide(Vis*, const char *keys, const Arg *arg);
static const char *call(Vis*, const char *keys, const Arg *arg);
/* call window function as indicated by arg->w */
static const char *window(Vis*, const char *keys, const Arg *arg);
/* show info about Unicode character at cursor position */
static const char *unicode_info(Vis*, const char *keys, const Arg *arg);

enum {
VIS_ACTION_EDITOR_SUSPEND,
Expand Down Expand Up @@ -261,6 +263,7 @@ enum {
VIS_ACTION_TEXT_OBJECT_LINE_INNER,
VIS_ACTION_MOTION_CHARWISE,
VIS_ACTION_MOTION_LINEWISE,
VIS_ACTION_UNICODE_INFO,
VIS_ACTION_NOP,
};

Expand Down Expand Up @@ -1040,6 +1043,11 @@ static KeyAction vis_action[] = {
"Force motion to be linewise",
motiontype, { .i = VIS_MOTIONTYPE_LINEWISE }
},
[VIS_ACTION_UNICODE_INFO] = {
"unicode-info",
"Show Unicode codepoint(s) of character under cursor",
unicode_info,
},
[VIS_ACTION_NOP] = {
"nop",
"Ignore key, do nothing",
Expand Down Expand Up @@ -1547,6 +1555,29 @@ static const char *insertmode(Vis *vis, const char *keys, const Arg *arg) {
return keys;
}

static const char *unicode_info(Vis *vis, const char *keys, const Arg *arg) {
View *view = vis_view(vis);
Text *txt = vis_text(vis);
size_t start = view_cursor_get(view);
size_t end = text_char_next(txt, start);
char data[end-start], *data_cur = data;
text_bytes_get(txt, start, end - start, data);
Iterator it = text_iterator_get(txt, start);
char info[255] = "", *info_cur = info;
for (size_t pos = start; it.pos < end; pos = it.pos) {
text_iterator_codepoint_next(&it, NULL);
size_t len = it.pos - pos;
wchar_t wc = 0xFFFD;
mbtowc(&wc, data_cur, len);
int width = wcwidth(wc);
info_cur += snprintf(info_cur, sizeof(info) - (info_cur - info) - 1,
"<%s%.*s> U+%04x ", width == 0 ? " " : "", len, data_cur, wc);
data_cur += len;
}
vis_info_show(vis, "%s", info);
return keys;
}

static Vis *vis;

static KeyBinding *default_bindings[] = {
Expand Down

0 comments on commit c4d675a

Please sign in to comment.