diff options
| -rw-r--r-- | main.c | 66 | ||||
| -rw-r--r-- | view.c | 4 | ||||
| -rw-r--r-- | vis-lua.c | 10 | ||||
| -rw-r--r-- | vis-motions.c | 18 | ||||
| -rw-r--r-- | vis-operators.c | 2 | ||||
| -rw-r--r-- | vis.c | 34 | ||||
| -rw-r--r-- | vis.h | 20 |
7 files changed, 54 insertions, 100 deletions
@@ -1280,7 +1280,7 @@ static const char *selections_new(Vis *vis, const char *keys, const Arg *arg) { view_selections_anchor(sel_new, anchored); } } - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } @@ -1439,7 +1439,7 @@ static const char *selections_remove(Vis *vis, const char *keys, const Arg *arg) static const char *selections_remove_column(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); int max = view_selections_column_count(view); - int column = vis_count_get_default(vis, arg->i) - 1; + int column = VIS_COUNT_DEFAULT(vis->action.count, arg->i) - 1; if (column >= max) column = max - 1; if (view_selections_count(view) == 1) { @@ -1452,14 +1452,14 @@ static const char *selections_remove_column(Vis *vis, const char *keys, const Ar view_selections_dispose(s); } - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } static const char *selections_remove_column_except(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); int max = view_selections_column_count(view); - int column = vis_count_get_default(vis, arg->i) - 1; + int column = VIS_COUNT_DEFAULT(vis->action.count, arg->i) - 1; if (column >= max) column = max - 1; if (view_selections_count(view) == 1) { @@ -1477,7 +1477,7 @@ static const char *selections_remove_column_except(Vis *vis, const char *keys, c view_selections_dispose(sel); } - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } @@ -1502,7 +1502,7 @@ static const char *selections_navigate(Vis *vis, const char *keys, const Arg *ar } } view_selections_primary_set(s); - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } @@ -1519,7 +1519,7 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg) View *view = vis_view(vis); int columns = view_selections_column_count(view); int selections = columns == 1 ? view_selections_count(view) : columns; - int count = vis_count_get_default(vis, 1); + int count = VIS_COUNT_DEFAULT(vis->action.count, 1); array_init_sized(&arr, sizeof(Rotate)); if (!array_reserve(&arr, selections)) return keys; @@ -1569,7 +1569,7 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg) } array_release(&arr); - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } @@ -1595,7 +1595,7 @@ static const char *selections_trim(Vis *vis, const char *keys, const Arg *arg) { } static void selections_set(Vis *vis, View *view, Array *sel) { - enum VisMode mode = vis_mode_get(vis); + enum VisMode mode = vis->mode->id; bool anchored = mode == VIS_MODE_VISUAL || mode == VIS_MODE_VISUAL_LINE; view_selections_set_all(view, sel, anchored); if (!anchored) @@ -1603,7 +1603,7 @@ static void selections_set(Vis *vis, View *view, Array *sel) { } static const char *selections_save(Vis *vis, const char *keys, const Arg *arg) { - Win *win = vis_window(vis); + Win *win = vis->win; View *view = vis_view(vis); enum VisMark mark = vis_mark_used(vis); Array sel = view_selections_get_all(view); @@ -1614,7 +1614,7 @@ static const char *selections_save(Vis *vis, const char *keys, const Arg *arg) { } static const char *selections_restore(Vis *vis, const char *keys, const Arg *arg) { - Win *win = vis_window(vis); + Win *win = vis->win; View *view = vis_view(vis); enum VisMark mark = vis_mark_used(vis); Array sel = vis_mark_get(win, mark); @@ -1625,7 +1625,7 @@ static const char *selections_restore(Vis *vis, const char *keys, const Arg *arg } static const char *selections_union(Vis *vis, const char *keys, const Arg *arg) { - Win *win = vis_window(vis); + Win *win = vis->win; View *view = vis_view(vis); enum VisMark mark = vis_mark_used(vis); Array a = vis_mark_get(win, mark); @@ -1692,7 +1692,7 @@ static void intersect(Array *ret, Array *a, Array *b) { } static const char *selections_intersect(Vis *vis, const char *keys, const Arg *arg) { - Win *win = vis_window(vis); + Win *win = vis->win; View *view = vis_view(vis); enum VisMark mark = vis_mark_used(vis); Array a = vis_mark_get(win, mark); @@ -1745,7 +1745,7 @@ static const char *selections_complement(Vis *vis, const char *keys, const Arg * static const char *selections_minus(Vis *vis, const char *keys, const Arg *arg) { Text *txt = vis_text(vis); - Win *win = vis_window(vis); + Win *win = vis->win; View *view = vis_view(vis); enum VisMark mark = vis_mark_used(vis); Array a = view_selections_get_all(view); @@ -1788,25 +1788,25 @@ static const char *replace(Vis *vis, const char *keys, const Arg *arg) { return next; vis_operator(vis, VIS_OP_REPLACE, replacement); - if (vis_mode_get(vis) == VIS_MODE_OPERATOR_PENDING) + if (vis->mode->id == VIS_MODE_OPERATOR_PENDING) vis_motion(vis, VIS_MOVE_CHAR_NEXT); return next; } static const char *count(Vis *vis, const char *keys, const Arg *arg) { int digit = keys[-1] - '0'; - int count = vis_count_get_default(vis, 0); + int count = VIS_COUNT_DEFAULT(vis->action.count, 0); if (0 <= digit && digit <= 9) { if (digit == 0 && count == 0) vis_motion(vis, VIS_MOVE_LINE_BEGIN); else - vis_count_set(vis, count * 10 + digit); + vis->action.count = VIS_COUNT_NORMALIZE(count * 10 + digit); } return keys; } static const char *gotoline(Vis *vis, const char *keys, const Arg *arg) { - if (vis_count_get(vis) != VIS_COUNT_UNKNOWN) + if (vis->action.count != VIS_COUNT_UNKNOWN) vis_motion(vis, VIS_MOVE_LINE); else if (arg->i < 0) vis_motion(vis, VIS_MOVE_FILE_BEGIN); @@ -2032,7 +2032,7 @@ static const char *insert_verbatim(Vis *vis, const char *keys, const Arg *arg) { static const char *wscroll(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - int count = vis_count_get(vis); + int count = vis->action.count; switch (arg->i) { case -PAGE: view_scroll_page_up(view); @@ -2055,20 +2055,20 @@ static const char *wscroll(Vis *vis, const char *keys, const Arg *arg) { view_scroll_down(view, count); break; } - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } static const char *wslide(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - int count = vis_count_get(vis); + int count = vis->action.count; if (count == VIS_COUNT_UNKNOWN) count = arg->i < 0 ? -arg->i : arg->i; if (arg->i >= 0) view_slide_down(view, count); else view_slide_up(view, count); - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } @@ -2088,7 +2088,7 @@ static const char *openline(Vis *vis, const char *keys, const Arg *arg) { vis_motion(vis, VIS_MOVE_LINE_END); vis_keys_feed(vis, "<Enter>"); } else { - if (vis_get_autoindent(vis)) { + if (vis->autoindent) { vis_motion(vis, VIS_MOVE_LINE_START); vis_keys_feed(vis, "<vis-motion-line-start>"); } else { @@ -2101,30 +2101,30 @@ static const char *openline(Vis *vis, const char *keys, const Arg *arg) { } static const char *join(Vis *vis, const char *keys, const Arg *arg) { - bool normal = (vis_mode_get(vis) == VIS_MODE_NORMAL); + bool normal = (vis->mode->id == VIS_MODE_NORMAL); vis_operator(vis, VIS_OP_JOIN, arg->s); if (normal) { - int count = vis_count_get_default(vis, 0); - if (count) - vis_count_set(vis, count-1); + vis->action.count = VIS_COUNT_DEFAULT(vis->action.count, 0); + if (vis->action.count > 0) + vis->action.count -= 1; vis_motion(vis, VIS_MOVE_LINE_NEXT); } return keys; } static const char *normalmode_escape(Vis *vis, const char *keys, const Arg *arg) { - if (vis_count_get(vis) == VIS_COUNT_UNKNOWN) + if (vis->action.count == VIS_COUNT_UNKNOWN) selections_clear(vis, keys, arg); else - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } static const char *visualmode_escape(Vis *vis, const char *keys, const Arg *arg) { - if (vis_count_get(vis) == VIS_COUNT_UNKNOWN) + if (vis->action.count == VIS_COUNT_UNKNOWN) vis_mode_switch(vis, VIS_MODE_NORMAL); else - vis_count_set(vis, VIS_COUNT_UNKNOWN); + vis->action.count = VIS_COUNT_UNKNOWN; return keys; } @@ -2189,7 +2189,7 @@ err: } static const char *percent(Vis *vis, const char *keys, const Arg *arg) { - if (vis_count_get(vis) == VIS_COUNT_UNKNOWN) + if (vis->action.count == VIS_COUNT_UNKNOWN) vis_motion(vis, VIS_MOVE_BRACKET_MATCH); else vis_motion(vis, VIS_MOVE_PERCENT); @@ -2323,7 +2323,7 @@ int main(int argc, char *argv[]) { } } - if (!vis_window(vis) && !win_created) { + if (!vis->win && !win_created) { if (!vis_window_new(vis, NULL)) vis_die(vis, "Can not create empty buffer\n"); if (cmd) @@ -134,7 +134,7 @@ void window_status_update(Vis *vis, Win *win) { View *view = win->view; File *file = win->file; Text *txt = file->text; - int width = vis_window_width_get(win); + int width = win->ui->window_width(win->ui); enum UiOption options = view_options_get(view); bool focused = vis->win == win; const char *filename = file_name_get(file); @@ -148,7 +148,7 @@ void window_status_update(Vis *vis, Win *win) { text_modified(txt) ? " [+]" : "", vis_macro_recording(vis) ? " @": ""); - int count = vis_count_get(vis); + int count = vis->action.count; const char *keys = buffer_content0(&vis->input_queue); if (keys && keys[0]) snprintf(right_parts[right_count++], sizeof(right_parts[0]), "%s", keys); @@ -1384,7 +1384,7 @@ static int vis_index(lua_State *L) { } if (strcmp(key, "count") == 0) { - int count = vis_count_get(vis); + int count = vis->action.count; if (count == VIS_COUNT_UNKNOWN) lua_pushnil(L); else @@ -1467,7 +1467,7 @@ static int vis_newindex(lua_State *L) { count = VIS_COUNT_UNKNOWN; else count = luaL_checkunsigned(L, 3); - vis_count_set(vis, count); + vis->action.count = count; return 0; } @@ -1788,12 +1788,12 @@ static int window_index(lua_State *L) { } if (strcmp(key, "width") == 0) { - lua_pushunsigned(L, vis_window_width_get(win)); + lua_pushunsigned(L, win->ui->window_width(win->ui)); return 1; } if (strcmp(key, "height") == 0) { - lua_pushunsigned(L, vis_window_height_get(win)); + lua_pushunsigned(L, win->ui->window_height(win->ui)); return 1; } @@ -2050,7 +2050,7 @@ static int window_style_pos(lua_State *L) { static int window_status(lua_State *L) { Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW); char status[1024] = ""; - int width = vis_window_width_get(win); + int width = win->ui->window_width(win->ui); const char *left = luaL_checkstring(L, 2); const char *right = luaL_optstring(L, 3, ""); int left_width = text_string_width(left, strlen(left)); diff --git a/vis-motions.c b/vis-motions.c index 6178f5a..430b51f 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -69,7 +69,7 @@ static size_t common_word_next(Vis *vis, Text *txt, size_t pos, if (!text_iterator_byte_get(&it, &c)) return pos; const Movement *motion = NULL; - int count = vis_count_get_default(vis, 1); + int count = VIS_COUNT_DEFAULT(vis->action.count, 1); if (isspace((unsigned char)c)) { motion = &vis_motions[start_next]; } else if (!isboundary((unsigned char)c) && text_iterator_char_next(&it, &c) && isboundary((unsigned char)c)) { @@ -175,7 +175,7 @@ static size_t firstline(Text *txt, size_t pos) { } static size_t line(Vis *vis, Text *txt, size_t pos) { - int count = vis_count_get_default(vis, 1); + int count = VIS_COUNT_DEFAULT(vis->action.count, 1); return text_line_start(txt, text_pos_by_lineno(txt, count)); } @@ -185,11 +185,11 @@ static size_t lastline(Text *txt, size_t pos) { } static size_t column(Vis *vis, Text *txt, size_t pos) { - return text_line_offset(txt, pos, vis_count_get_default(vis, 0)); + return text_line_offset(txt, pos, VIS_COUNT_DEFAULT(vis->action.count, 0)); } static size_t view_lines_top(Vis *vis, View *view) { - return view_screenline_goto(view, vis_count_get_default(vis, 1)); + return view_screenline_goto(view, VIS_COUNT_DEFAULT(vis->action.count, 1)); } static size_t view_lines_middle(Vis *vis, View *view) { @@ -199,7 +199,7 @@ static size_t view_lines_middle(Vis *vis, View *view) { static size_t view_lines_bottom(Vis *vis, View *view) { int h = view_height_get(vis->win->view); - return view_screenline_goto(vis->win->view, h - vis_count_get_default(vis, 0)); + return view_screenline_goto(vis->win->view, h - VIS_COUNT_DEFAULT(vis->action.count, 0)); } static size_t window_nop(Vis *vis, Win *win, size_t pos) { @@ -233,25 +233,25 @@ static size_t bracket_match(Text *txt, size_t pos) { } static size_t percent(Vis *vis, Text *txt, size_t pos) { - int ratio = vis_count_get_default(vis, 0); + int ratio = VIS_COUNT_DEFAULT(vis->action.count, 0); if (ratio > 100) ratio = 100; return text_size(txt) * ratio / 100; } static size_t byte(Vis *vis, Text *txt, size_t pos) { - pos = vis_count_get_default(vis, 0); + pos = VIS_COUNT_DEFAULT(vis->action.count, 0); size_t max = text_size(txt); return pos <= max ? pos : max; } static size_t byte_left(Vis *vis, Text *txt, size_t pos) { - size_t off = vis_count_get_default(vis, 1); + size_t off = VIS_COUNT_DEFAULT(vis->action.count, 1); return off <= pos ? pos-off : 0; } static size_t byte_right(Vis *vis, Text *txt, size_t pos) { - size_t off = vis_count_get_default(vis, 1); + size_t off = VIS_COUNT_DEFAULT(vis->action.count, 1); size_t new = pos + off; size_t max = text_size(txt); return new <= max && new > pos ? new : max; diff --git a/vis-operators.c b/vis-operators.c index 0e4f8b4..817480d 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -272,7 +272,7 @@ bool vis_operator(Vis *vis, enum VisOperator id, ...) { } case VIS_OP_DELETE: { - enum VisMode mode = vis_mode_get(vis); + enum VisMode mode = vis->mode->id; enum VisRegister reg = vis_register_used(vis); if (reg == VIS_REG_DEFAULT && (mode == VIS_MODE_INSERT || mode == VIS_MODE_REPLACE)) vis_register(vis, VIS_REG_BLACKHOLE); @@ -481,14 +481,6 @@ void vis_window_prev(Vis *vis) { vis_window_focus(sel); } -int vis_window_width_get(const Win *win) { - return win->ui->window_width(win->ui); -} - -int vis_window_height_get(const Win *win) { - return win->ui->window_height(win->ui); -} - void vis_draw(Vis *vis) { for (Win *win = vis->windows; win; win = win->next) view_draw(win->view); @@ -1461,7 +1453,7 @@ bool vis_macro_replay(Vis *vis, enum VisRegister id) { Macro *macro = macro_get(vis, id); if (!macro || macro == vis->recording) return false; - int count = vis_count_get_default(vis, 1); + int count = VIS_COUNT_DEFAULT(vis->action.count, 1); vis_cancel(vis); for (int i = 0; i < count; i++) macro_replay(vis, macro); @@ -1502,25 +1494,11 @@ void vis_repeat(Vis *vis) { vis_file_snapshot(vis, win->file); } -int vis_count_get(Vis *vis) { - return vis->action.count; -} - -int vis_count_get_default(Vis *vis, int def) { - if (vis->action.count == VIS_COUNT_UNKNOWN) - return def; - return vis->action.count; -} - -void vis_count_set(Vis *vis, int count) { - vis->action.count = (count >= 0 ? count : VIS_COUNT_UNKNOWN); -} - VisCountIterator vis_count_iterator_get(Vis *vis, int def) { return (VisCountIterator) { .vis = vis, .iteration = 0, - .count = vis_count_get_default(vis, def), + .count = VIS_COUNT_DEFAULT(vis->action.count, def), }; } @@ -1928,11 +1906,3 @@ View *vis_view(Vis *vis) { Win *win = vis->win; return win ? win->view : NULL; } - -Win *vis_window(Vis *vis) { - return vis->win; -} - -bool vis_get_autoindent(const Vis *vis) { - return vis->autoindent; -} @@ -208,10 +208,6 @@ void vis_window_prev(Vis*); void vis_window_focus(Win*); /** Swap location of two windows. */ void vis_window_swap(Win*, Win*); -/** Query window width. */ -int vis_window_width_get(const Win*); -/** Query window height. */ -int vis_window_height_get(const Win*); /** * @} * @defgroup vis_info @@ -294,8 +290,6 @@ enum VisMode { * @endrst */ void vis_mode_switch(Vis*, enum VisMode); -/** Get currently active mode. */ -enum VisMode vis_mode_get(Vis*); /** Translate human readable mode name to constant. */ enum VisMode vis_mode_from(Vis*, const char *name); @@ -560,14 +554,8 @@ int vis_motion_register(Vis*, void *context, VisMotionFunction*); */ /** No count was specified. */ #define VIS_COUNT_UNKNOWN (-1) -/** Get count, might return `VIS_COUNT_UNKNOWN`. */ -int vis_count_get(Vis*); -/** Get count, if none was specified, return ``def``. */ -int vis_count_get_default(Vis*, int def); -/** Set a count. */ -void vis_count_set(Vis*, int count); -/** Set the tabwidth */ -void vis_tabwidth_set(Vis*, int tw); +#define VIS_COUNT_DEFAULT(count, def) ((count) == VIS_COUNT_UNKNOWN ? (def) : (count)) +#define VIS_COUNT_NORMALIZE(count) ((count) < 0 ? VIS_COUNT_UNKNOWN : (count)) /** Set the shell */ void vis_shell_set(Vis*, const char *new_shell); @@ -974,9 +962,5 @@ void vis_file_snapshot(Vis*, File*); /* TODO: expose proper API to iterate through files etc */ Text *vis_text(Vis*); View *vis_view(Vis*); -Win *vis_window(Vis*); - -/* Get value of autoindent */ -bool vis_get_autoindent(const Vis*); #endif |
