diff options
| -rw-r--r-- | main.c | 18 | ||||
| -rw-r--r-- | sam.c | 4 | ||||
| -rw-r--r-- | ui-terminal.c | 14 | ||||
| -rw-r--r-- | view.c | 112 | ||||
| -rw-r--r-- | view.h | 79 | ||||
| -rw-r--r-- | vis-cmds.c | 6 | ||||
| -rw-r--r-- | vis-lua.c | 26 | ||||
| -rw-r--r-- | vis-motions.c | 6 | ||||
| -rw-r--r-- | vis-operators.c | 4 | ||||
| -rw-r--r-- | vis-prompt.c | 2 | ||||
| -rw-r--r-- | vis-registers.c | 2 | ||||
| -rw-r--r-- | vis.c | 28 |
12 files changed, 108 insertions, 193 deletions
@@ -1348,7 +1348,7 @@ static const char *selections_align_indent(Vis *vis, const char *keys, const Arg static const char *selections_clear(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - if (view_selections_count(view) > 1) + if (view->selection_count > 1) view_selections_dispose_all(view); else view_selection_clear(view_selections_primary_get(view)); @@ -1356,7 +1356,7 @@ static const char *selections_clear(Vis *vis, const char *keys, const Arg *arg) } static Selection *selection_new(View *view, Filerange *r, bool isprimary) { - Text *txt = view_text(view); + Text *txt = view->text; size_t pos = text_char_prev(txt, r->end); Selection *s = view_selections_new(view, pos); if (!s) @@ -1378,7 +1378,7 @@ static const char *selections_match_next(Vis *vis, const char *keys, const Arg * static bool match_word; - if (view_selections_count(view) == 1) { + if (view->selection_count == 1) { Filerange word = text_object_word(txt, view_cursors_pos(s)); match_word = text_range_equal(&sel, &word); } @@ -1442,7 +1442,7 @@ static const char *selections_remove_column(Vis *vis, const char *keys, const Ar int column = VIS_COUNT_DEFAULT(vis->action.count, arg->i) - 1; if (column >= max) column = max - 1; - if (view_selections_count(view) == 1) { + if (view->selection_count == 1) { vis_keys_feed(vis, "<Escape>"); return keys; } @@ -1462,7 +1462,7 @@ static const char *selections_remove_column_except(Vis *vis, const char *keys, c int column = VIS_COUNT_DEFAULT(vis->action.count, arg->i) - 1; if (column >= max) column = max - 1; - if (view_selections_count(view) == 1) { + if (view->selection_count == 1) { vis_redraw(vis); return keys; } @@ -1483,7 +1483,7 @@ static const char *selections_remove_column_except(Vis *vis, const char *keys, c static const char *selections_navigate(Vis *vis, const char *keys, const Arg *arg) { View *view = vis_view(vis); - if (view_selections_count(view) == 1) + if (view->selection_count == 1) return wscroll(vis, keys, arg); Selection *s = view_selections_primary_get(view); VisCountIterator it = vis_count_iterator_get(vis, 1); @@ -1518,7 +1518,7 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg) Text *txt = vis_text(vis); View *view = vis_view(vis); int columns = view_selections_column_count(view); - int selections = columns == 1 ? view_selections_count(view) : columns; + int selections = columns == 1 ? view->selection_count : columns; int count = VIS_COUNT_DEFAULT(vis->action.count, 1); array_init_sized(&arr, sizeof(Rotate)); if (!array_reserve(&arr, selections)) @@ -1877,7 +1877,7 @@ static const char *undo(Vis *vis, const char *keys, const Arg *arg) { size_t pos = text_undo(vis_text(vis)); if (pos != EPOS) { View *view = vis_view(vis); - if (view_selections_count(view) == 1) + if (view->selection_count == 1) view_cursor_to(view, pos); /* redraw all windows in case some display the same file */ vis_draw(vis); @@ -1889,7 +1889,7 @@ static const char *redo(Vis *vis, const char *keys, const Arg *arg) { size_t pos = text_redo(vis_text(vis)); if (pos != EPOS) { View *view = vis_view(vis); - if (view_selections_count(view) == 1) + if (view->selection_count == 1) view_cursor_to(view, pos); /* redraw all windows in case some display the same file */ vis_draw(vis); @@ -1509,11 +1509,11 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Sel bool ret = true; View *view = win->view; Text *txt = win->file->text; - bool multiple_cursors = view_selections_count(view) > 1; + bool multiple_cursors = view->selection_count > 1; Selection *primary = view_selections_primary_get(view); if (vis->mode->visual) - count_init(cmd->cmd, view_selections_count(view)+1); + count_init(cmd->cmd, view->selection_count + 1); for (Selection *s = view_selections(view), *next; s && ret; s = next) { next = view_selections_next(s); diff --git a/ui-terminal.c b/ui-terminal.c index 09e618e..c26cdb0 100644 --- a/ui-terminal.c +++ b/ui-terminal.c @@ -243,7 +243,7 @@ static void ui_window_draw(UiWin *w) { UiTerm *ui = win->ui; View *view = win->win->view; int width = win->width, height = win->height; - const Line *line = view_lines_first(view); + const Line *line = view->topline; bool status = win->options & UI_OPTION_STATUSBAR; bool nu = win->options & UI_OPTION_LINE_NUMBERS_ABSOLUTE; bool rnu = win->options & UI_OPTION_LINE_NUMBERS_RELATIVE; @@ -254,14 +254,14 @@ static void ui_window_draw(UiWin *w) { win->sidebar_width = sidebar_width; } vis_window_draw(win->win); - line = view_lines_first(view); + line = view->topline; size_t prev_lineno = 0; Selection *sel = view_selections_primary_get(view); const Line *cursor_line = view_cursors_line_get(sel); size_t cursor_lineno = cursor_line->lineno; char buf[(sizeof(size_t) * CHAR_BIT + 2) / 3 + 1 + 1]; int x = win->x, y = win->y; - int view_width = view_width_get(view); + int view_width = view->width; Cell *cells = ui->cells + y * ui->width; if (x + sidebar_width + view_width > ui->width) view_width = ui->width - x - sidebar_width; @@ -400,7 +400,7 @@ static void ui_redraw(Ui *ui) { UiTerm *tui = (UiTerm*)ui; ui_term_backend_clear(tui); for (UiTermWin *win = tui->windows; win; win = win->next) - view_invalidate(win->win->view); + win->win->view->need_update = true; } static void ui_resize(Ui *ui) { @@ -457,8 +457,8 @@ static void ui_window_focus(UiWin *w) { if (new->options & UI_OPTION_STATUSBAR) new->ui->selwin = new; if (old) - view_invalidate(old->win->view); - view_invalidate(new->win->view); + old->win->view->need_update = true; + new->win->view->need_update = true; } static void ui_window_options_set(UiWin *w, enum UiOption options) { @@ -579,7 +579,7 @@ static UiWin *ui_window_new(Ui *ui, Win *w, enum UiOption options) { styles[UI_STYLE_STATUS].attr |= CELL_ATTR_REVERSE; styles[UI_STYLE_STATUS_FOCUSED].attr |= CELL_ATTR_REVERSE|CELL_ATTR_BOLD; styles[UI_STYLE_INFO].attr |= CELL_ATTR_BOLD; - view_ui(w->view, &win->uiwin); + w->view->ui = &win->uiwin; if (tui->windows) tui->windows->prev = win; @@ -13,19 +13,6 @@ #include "text-util.h" #include "util.h" -typedef struct { - char *symbol; -} SyntaxSymbol; - -enum { - SYNTAX_SYMBOL_SPACE, - SYNTAX_SYMBOL_TAB, - SYNTAX_SYMBOL_TAB_FILL, - SYNTAX_SYMBOL_EOL, - SYNTAX_SYMBOL_EOF, - SYNTAX_SYMBOL_LAST, -}; - /* A selection is made up of two marks named cursor and anchor. * While the anchor remains fixed the cursor mark follows cursor motions. * For a selection (indicated by []), the marks (^) are placed as follows: @@ -56,39 +43,6 @@ struct Selection { Selection *prev, *next; /* previous/next cursors ordered by location at creation time */ }; -struct View { - Text *text; /* underlying text management */ - char *textbuf; /* scratch buffer used for drawing */ - UiWin *ui; /* corresponding ui window */ - Cell cell_blank; /* used for empty/blank cells */ - int width, height; /* size of display area */ - size_t start, end; /* currently displayed area [start, end] in bytes from the start of the file */ - size_t start_last; /* previously used start of visible area, used to update the mark */ - Mark start_mark; /* mark to keep track of the start of the visible area */ - size_t lines_size; /* number of allocated bytes for lines (grows only) */ - Line *lines; /* view->height number of lines representing view content */ - Line *topline; /* top of the view, first line currently shown */ - Line *lastline; /* last currently used line, always <= bottomline */ - Line *bottomline; /* bottom of view, might be unused if lastline < bottomline */ - Selection *selection; /* primary selection, always placed within the visible viewport */ - Selection *selection_latest; /* most recently created cursor */ - Selection *selection_dead; /* primary cursor which was disposed, will be removed when another cursor is created */ - int selection_count; /* how many cursors do currently exist */ - Line *line; /* used while drawing view content, line where next char will be drawn */ - int col; /* used while drawing view content, column where next char will be drawn */ - const SyntaxSymbol *symbols[SYNTAX_SYMBOL_LAST]; /* symbols to use for white spaces etc */ - int tabwidth; /* how many spaces should be used to display a tab character */ - Selection *selections; /* all cursors currently active */ - int selection_generation; /* used to filter out newly created cursors during iteration */ - bool need_update; /* whether view has been redrawn */ - bool large_file; /* optimize for displaying large files */ - int colorcolumn; - char *breakat; /* characters which might cause a word wrap */ - int wrapcolumn; /* wrap lines at minimum of window width and wrapcolumn (if != 0) */ - int wrapcol; /* used while drawing view content, column where word wrap might happen */ - bool prevch_breakat; /* used while drawing view content, previous char is part of breakat */ -}; - static const SyntaxSymbol symbols_none[] = { [SYNTAX_SYMBOL_SPACE] = { " " }, [SYNTAX_SYMBOL_TAB] = { " " }, @@ -155,7 +109,7 @@ void window_status_update(Vis *vis, Win *win) { else if (count != VIS_COUNT_UNKNOWN) snprintf(right_parts[right_count++], sizeof(right_parts[0]), "%d", count); - int sel_count = view_selections_count(view); + int sel_count = view->selection_count; if (sel_count > 1) { Selection *s = view_selections_primary_get(view); int sel_number = view_selections_number(s) + 1; @@ -223,10 +177,6 @@ void view_tabwidth_set(View *view, int tabwidth) { view_draw(view); } -int view_tabwidth_get(View *view) { - return view->tabwidth; -} - /* reset internal view data structures (cell matrix, line offsets etc.) */ static void view_clear(View *view) { memset(view->lines, 0, view->lines_size); @@ -270,10 +220,6 @@ static void view_clear(View *view) { view->ui->style_set(view->ui, &view->cell_blank, UI_STYLE_DEFAULT); } -Filerange view_viewport_get(View *view) { - return (Filerange){ .start = view->start, .end = view->end }; -} - static int view_max_text_width(const View *view) { if (view->wrapcolumn > 0) return MIN(view->wrapcolumn, view->width); @@ -575,10 +521,6 @@ void view_draw(View *view) { view->need_update = true; } -void view_invalidate(View *view) { - view->need_update = true; -} - bool view_update(View *view) { if (!view->need_update) return false; @@ -621,14 +563,6 @@ bool view_resize(View *view, int width, int height) { return true; } -int view_height_get(View *view) { - return view->height; -} - -int view_width_get(View *view) { - return view->width; -} - void view_free(View *view) { if (!view) return; @@ -676,10 +610,6 @@ View *view_new(Text *text) { return view; } -void view_ui(View *view, UiWin* ui) { - view->ui = ui; -} - static size_t cursor_set(Selection *sel, Line *line, int col) { int row = 0; View *view = sel->view; @@ -955,14 +885,6 @@ size_t view_cursor_get(View *view) { return view_cursors_pos(view->selection); } -Line *view_lines_first(View *view) { - return view->topline; -} - -Line *view_lines_last(View *view) { - return view->lastline; -} - Line *view_cursors_line_get(Selection *sel) { return sel->line; } @@ -998,24 +920,6 @@ enum UiOption view_options_get(View *view) { return view->ui ? view->ui->options_get(view->ui) : 0; } -void view_colorcolumn_set(View *view, int col) { - if (col >= 0) - view->colorcolumn = col; -} - -int view_colorcolumn_get(View *view) { - return view->colorcolumn; -} - -void view_wrapcolumn_set(View *view, int col) { - if (col >= 0) - view->wrapcolumn = col; -} - -int view_wrapcolumn_get(View *view) { - return view->wrapcolumn; -} - bool view_breakat_set(View *view, const char *breakat) { char *copy = strdup(breakat); if (!copy) @@ -1025,10 +929,6 @@ bool view_breakat_set(View *view, const char *breakat) { return true; } -const char *view_breakat_get(View *view) { - return view->breakat; -} - size_t view_screenline_goto(View *view, int n) { size_t pos = view->start; for (Line *line = view->topline; --n > 0 && line != view->lastline; line = line->next) @@ -1108,10 +1008,6 @@ Selection *view_selections_new_force(View *view, size_t pos) { return selections_new(view, pos, true); } -int view_selections_count(View *view) { - return view->selection_count; -} - int view_selections_number(Selection *sel) { return sel->number; } @@ -1458,7 +1354,7 @@ void view_selections_set_all(View *view, Array *arr, bool anchored) { Array view_selections_get_all(View *view) { Array arr; array_init_sized(&arr, sizeof(Filerange)); - if (!array_reserve(&arr, view_selections_count(view))) + if (!array_reserve(&arr, view->selection_count)) return arr; for (Selection *s = view->selections; s; s = s->next) { Filerange r = view_selections_get(s); @@ -1490,10 +1386,6 @@ void view_selections_normalize(View *view) { view_selections_set(prev, &range_prev); } -Text *view_text(View *view) { - return view->text; -} - char *view_symbol_eof_get(View *view) { return view->symbols[SYNTAX_SYMBOL_EOF]->symbol; } @@ -4,20 +4,31 @@ #include <stddef.h> #include <stdbool.h> -typedef struct View View; typedef struct Selection Selection; -typedef struct Cell Cell; #include "text.h" #include "ui.h" #include "array.h" typedef struct { + char *symbol; +} SyntaxSymbol; + +enum { + SYNTAX_SYMBOL_SPACE, + SYNTAX_SYMBOL_TAB, + SYNTAX_SYMBOL_TAB_FILL, + SYNTAX_SYMBOL_EOL, + SYNTAX_SYMBOL_EOF, + SYNTAX_SYMBOL_LAST, +}; + +typedef struct { Mark anchor; Mark cursor; } SelectionRegion; -struct Cell { +typedef struct { char data[16]; /* utf8 encoded character displayed in this cell (might be more than one Unicode codepoint. might also not be the same as in the underlying text, for example tabs get expanded */ @@ -27,7 +38,7 @@ struct Cell { occupied by the same character have a length of 0. */ int width; /* display width i.e. number of columns occupied by this character */ CellStyle style; /* colors and attributes used to display this cell */ -}; +} Cell; typedef struct Line Line; struct Line { /* a line on the screen, *not* in the file */ @@ -38,14 +49,45 @@ struct Line { /* a line on the screen, *not* in the file */ Cell cells[]; /* win->width cells storing information about the displayed characters */ }; +typedef struct { + Text *text; /* underlying text management */ + char *textbuf; /* scratch buffer used for drawing */ + UiWin *ui; /* corresponding ui window */ + Cell cell_blank; /* used for empty/blank cells */ + int width, height; /* size of display area */ + size_t start, end; /* currently displayed area [start, end] in bytes from the start of the file */ + size_t start_last; /* previously used start of visible area, used to update the mark */ + Mark start_mark; /* mark to keep track of the start of the visible area */ + size_t lines_size; /* number of allocated bytes for lines (grows only) */ + Line *lines; /* view->height number of lines representing view content */ + Line *topline; /* top of the view, first line currently shown */ + Line *lastline; /* last currently used line, always <= bottomline */ + Line *bottomline; /* bottom of view, might be unused if lastline < bottomline */ + Selection *selection; /* primary selection, always placed within the visible viewport */ + Selection *selection_latest; /* most recently created cursor */ + Selection *selection_dead; /* primary cursor which was disposed, will be removed when another cursor is created */ + int selection_count; /* how many cursors do currently exist */ + Line *line; /* used while drawing view content, line where next char will be drawn */ + int col; /* used while drawing view content, column where next char will be drawn */ + const SyntaxSymbol *symbols[SYNTAX_SYMBOL_LAST]; /* symbols to use for white spaces etc */ + int tabwidth; /* how many spaces should be used to display a tab character */ + Selection *selections; /* all cursors currently active */ + int selection_generation; /* used to filter out newly created cursors during iteration */ + bool need_update; /* whether view has been redrawn */ + bool large_file; /* optimize for displaying large files */ + int colorcolumn; + char *breakat; /* characters which might cause a word wrap */ + int wrapcolumn; /* wrap lines at minimum of window width and wrapcolumn (if != 0) */ + int wrapcol; /* used while drawing view content, column where word wrap might happen */ + bool prevch_breakat; /* used while drawing view content, previous char is part of breakat */ +} View; + /** * @defgroup view_life * @{ */ View *view_new(Text*); void view_free(View*); -void view_ui(View*, UiWin*); -Text *view_text(View*); void view_reload(View*, Text*); /** * @} @@ -53,7 +95,7 @@ void view_reload(View*, Text*); * @{ */ /** Get the currently displayed text range. */ -Filerange view_viewport_get(View*); +#define VIEW_VIEWPORT_GET(v) (Filerange){ .start = v->start, .end = v->end } /** * Get window coordinate of text position. * @param pos The position to query. @@ -65,10 +107,6 @@ Filerange view_viewport_get(View*); bool view_coord_get(View*, size_t pos, Line **line, int *row, int *col); /** Get position at the start of the ``n``-th window line, counting from 1. */ size_t view_screenline_goto(View*, int n); -/** Get first screen line. */ -Line *view_lines_first(View*); -/** Get last non-empty screen line. */ -Line *view_lines_last(View*); size_t view_slide_up(View*, int lines); size_t view_slide_down(View*, int lines); size_t view_scroll_up(View*, int lines); @@ -87,14 +125,11 @@ void view_scroll_to(View*, size_t pos); * @{ */ bool view_resize(View*, int width, int height); -int view_height_get(View*); -int view_width_get(View*); /** * @} * @defgroup view_draw * @{ */ -void view_invalidate(View*); void view_draw(View*); bool view_update(View*); @@ -113,7 +148,7 @@ bool view_update(View*); Selection *view_selections_new(View*, size_t pos); /** * Create a new selection even if position is already covered by an - * existing selection. + * existing selection. * @rst * .. note:: This should only be used if the old selection is eventually * disposed. @@ -168,13 +203,6 @@ Selection *view_selections_prev(Selection*); /** Get immediate successor of selection. */ Selection *view_selections_next(Selection*); /** - * Get number of existing selections. - * @rst - * .. note:: Is always at least 1. - * @endrst - */ -int view_selections_count(View*); -/** * Get selection index. * @rst * .. note:: Is always in range ``[0, count-1]``. @@ -357,17 +385,10 @@ bool view_regions_save(View*, Filerange*, SelectionRegion*); */ void view_options_set(View*, enum UiOption options); enum UiOption view_options_get(View*); -void view_colorcolumn_set(View*, int col); -int view_colorcolumn_get(View*); -void view_wrapcolumn_set(View*, int col); -int view_wrapcolumn_get(View*); bool view_breakat_set(View*, const char *breakat); -const char *view_breakat_get(View*); /** Set how many spaces are used to display a tab `\t` character. */ void view_tabwidth_set(View*, int tabwidth); -/** Get how many spaces are used to display a tab `\t` character. */ -int view_tabwidth_get(View*); /** Define a display style. */ bool view_style_define(View*, enum UiStyle, const char *style); /** Apply a style to a text range. */ @@ -316,7 +316,8 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Select break; } case OPTION_COLOR_COLUMN: - view_colorcolumn_set(win->view, arg.i); + if (arg.i >= 0) + win->view->colorcolumn = arg.i; break; case OPTION_SAVE_METHOD: if (strcmp("auto", arg.s) == 0) { @@ -370,7 +371,8 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Select } break; case OPTION_WRAP_COLUMN: - view_wrapcolumn_set(win->view, arg.i); + if (arg.i >= 0) + win->view->wrapcolumn = arg.i; break; default: if (!opt->func) @@ -1766,10 +1766,10 @@ static int window_index(lua_State *L) { const char *key = lua_tostring(L, 2); if (strcmp(key, "viewport") == 0) { - Filerange b = view_viewport_get(win->view); + Filerange b = VIEW_VIEWPORT_GET(win->view); Filerange l; - l.start = view_lines_first(win->view)->lineno; - l.end = view_lines_last(win->view)->lineno; + l.start = win->view->topline->lineno; + l.end = win->view->lastline->lineno; lua_createtable(L, 0, 4); lua_pushstring(L, "bytes"); @@ -1779,10 +1779,10 @@ static int window_index(lua_State *L) { pushrange(L, &l); lua_settable(L, -3); lua_pushstring(L, "width"); - lua_pushunsigned(L, view_width_get(win->view)); + lua_pushunsigned(L, win->view->width); lua_settable(L, -3); lua_pushstring(L, "height"); - lua_pushunsigned(L, view_height_get(win->view)); + lua_pushunsigned(L, win->view->height); lua_settable(L, -3); return 1; } @@ -1832,7 +1832,7 @@ static int window_options_assign(Win *win, lua_State *L, const char *key, int ne if (lua_isstring(L, next)) view_breakat_set(win->view, lua_tostring(L, next)); } else if (strcmp(key, "colorcolumn") == 0 || strcmp(key, "cc") == 0) { - view_colorcolumn_set(win->view, luaL_checkint(L, next)); + win->view->colorcolumn = luaL_checkunsigned(L, next); } else if (strcmp(key, "cursorline") == 0 || strcmp(key, "cul") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_CURSOR_LINE; @@ -1882,7 +1882,7 @@ static int window_options_assign(Win *win, lua_State *L, const char *key, int ne flags &= ~UI_OPTION_STATUSBAR; view_options_set(win->view, flags); } else if (strcmp(key, "wrapcolumn") == 0 || strcmp(key, "wc") == 0) { - view_wrapcolumn_set(win->view, luaL_checkint(L, next)); + win->view->wrapcolumn = luaL_checkunsigned(L, next); } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) { view_tabwidth_set(win->view, luaL_checkint(L, next)); } else if (strcmp(key, "expandtab") == 0 || strcmp(key, "et") == 0) { @@ -2142,10 +2142,10 @@ static int window_options_index(lua_State *L) { if (lua_isstring(L, 2)) { const char *key = lua_tostring(L, 2); if (strcmp(key, "breakat") == 0 || strcmp(key, "brk") == 0) { - lua_pushstring(L, view_breakat_get(win->view)); + lua_pushstring(L, win->view->breakat); return 1; } else if (strcmp(key, "colorcolumn") == 0 || strcmp(key, "cc") == 0) { - lua_pushunsigned(L, view_colorcolumn_get(win->view)); + lua_pushunsigned(L, win->view->colorcolumn); return 1; } else if (strcmp(key, "cursorline") == 0 || strcmp(key, "cul") == 0) { lua_pushboolean(L, view_options_get(win->view) & UI_OPTION_CURSOR_LINE); @@ -2175,10 +2175,10 @@ static int window_options_index(lua_State *L) { lua_pushboolean(L, view_options_get(win->view) & UI_OPTION_STATUSBAR); return 1; } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) { - lua_pushinteger(L, view_tabwidth_get(win->view)); + lua_pushinteger(L, win->view->tabwidth); return 1; } else if (strcmp(key, "wrapcolumn") == 0 || strcmp(key, "wc") == 0) { - lua_pushunsigned(L, view_wrapcolumn_get(win->view)); + lua_pushunsigned(L, win->view->wrapcolumn); return 1; } } @@ -2203,7 +2203,7 @@ static const struct luaL_Reg window_option_funcs[] = { static int window_selections_index(lua_State *L) { View *view = obj_ref_check(L, 1, VIS_LUA_TYPE_SELECTIONS); size_t index = luaL_checkunsigned(L, 2); - size_t count = view_selections_count(view); + size_t count = view->selection_count; if (index == 0 || index > count) goto err; for (Selection *s = view_selections(view); s; s = view_selections_next(s)) { @@ -2219,7 +2219,7 @@ err: static int window_selections_len(lua_State *L) { View *view = obj_ref_check(L, 1, VIS_LUA_TYPE_SELECTIONS); - lua_pushunsigned(L, view_selections_count(view)); + lua_pushunsigned(L, view->selection_count); return 1; } diff --git a/vis-motions.c b/vis-motions.c index 430b51f..1d3f49a 100644 --- a/vis-motions.c +++ b/vis-motions.c @@ -193,13 +193,13 @@ static size_t view_lines_top(Vis *vis, View *view) { } static size_t view_lines_middle(Vis *vis, View *view) { - int h = view_height_get(view); + int h = view->height; return view_screenline_goto(view, h/2); } 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_DEFAULT(vis->action.count, 0)); + int h = view->height; + return view_screenline_goto(view, h - VIS_COUNT_DEFAULT(vis->action.count, 0)); } static size_t window_nop(Vis *vis, Win *win, size_t pos) { diff --git a/vis-operators.c b/vis-operators.c index 817480d..5ce64c4 100644 --- a/vis-operators.c +++ b/vis-operators.c @@ -102,7 +102,7 @@ static size_t op_put(Vis *vis, Text *txt, OperatorContext *c) { static size_t op_shift_right(Vis *vis, Text *txt, OperatorContext *c) { char spaces[9] = " "; - spaces[MIN(view_tabwidth_get(vis->win->view), LENGTH(spaces) - 1)] = '\0'; + spaces[MIN(vis->win->view->tabwidth, LENGTH(spaces) - 1)] = '\0'; const char *tab = vis->win->expandtab ? spaces : "\t"; size_t tablen = strlen(tab); size_t pos = text_line_begin(txt, c->range.end), prev_pos; @@ -127,7 +127,7 @@ static size_t op_shift_right(Vis *vis, Text *txt, OperatorContext *c) { static size_t op_shift_left(Vis *vis, Text *txt, OperatorContext *c) { size_t pos = text_line_begin(txt, c->range.end), prev_pos; - size_t tabwidth = view_tabwidth_get(vis->win->view), tablen; + size_t tabwidth = vis->win->view->tabwidth, tablen; size_t newpos = c->pos; /* if range ends at the begin of a line, skip line break */ diff --git a/vis-prompt.c b/vis-prompt.c index 1add11a..f265b10 100644 --- a/vis-prompt.c +++ b/vis-prompt.c @@ -114,7 +114,7 @@ static const char *prompt_enter(Vis *vis, const char *keys, const Arg *arg) { static const char *prompt_esc(Vis *vis, const char *keys, const Arg *arg) { Win *prompt = vis->win; - if (view_selections_count(prompt->view) > 1) { + if (prompt->view->selection_count > 1) { view_selections_dispose_all(prompt->view); } else { prompt_restore(prompt); diff --git a/vis-registers.c b/vis-registers.c index 1875da9..485284c 100644 --- a/vis-registers.c +++ b/vis-registers.c @@ -188,7 +188,7 @@ bool register_put_range(Vis *vis, Register *reg, Text *txt, Filerange *range) { size_t vis_register_count(Vis *vis, Register *reg) { if (reg->type == REGISTER_NUMBER) - return vis->win ? view_selections_count(vis->win->view) : 0; + return vis->win ? vis->win->view->selection_count : 0; return array_length(®->values); } @@ -218,15 +218,15 @@ static void window_free(Win *win) { static void window_draw_colorcolumn(Win *win) { View *view = win->view; - int cc = view_colorcolumn_get(view); + int cc = view->colorcolumn; if (cc <= 0) return; size_t lineno = 0; int line_cols = 0; /* Track the number of columns we've passed on each line */ bool line_cc_set = false; /* Has the colorcolumn attribute been set for this line yet */ - int width = view_width_get(view); + int width = view->width; - for (Line *l = view_lines_first(view); l; l = l->next) { + for (Line *l = view->topline; l; l = l->next) { if (l->lineno != lineno) { line_cols = 0; line_cc_set = false; @@ -254,13 +254,13 @@ static void window_draw_cursorline(Win *win) { return; if (vis->mode->visual || vis->win != win) return; - if (view_selections_count(view) > 1) + if (view->selection_count > 1) return; - int width = view_width_get(view); + int width = view->width; Selection *sel = view_selections_primary_get(view); size_t lineno = view_cursors_line_get(sel)->lineno; - for (Line *l = view_lines_first(view); l; l = l->next) { + for (Line *l = view->topline; l; l = l->next) { if (l->lineno == lineno) { for (int x = 0; x < width; x++) win->ui->style_set(win->ui, &l->cells[x], UI_STYLE_CURSOR_LINE); @@ -282,11 +282,11 @@ static void window_draw_selection(Win *win, Selection *cur) { if (!start_line && !end_line) return; if (!start_line) { - start_line = view_lines_first(view); + start_line = view->topline; start_col = 0; } if (!end_line) { - end_line = view_lines_last(view); + end_line = view->lastline; end_col = end_line->width; } for (Line *l = start_line; l != end_line->next; l = l->next) { @@ -302,7 +302,7 @@ static void window_draw_cursor_matching(Win *win, Selection *cur) { return; Line *line_match; int col_match; size_t pos = view_cursors_pos(cur); - Filerange limits = view_viewport_get(win->view); + Filerange limits = VIEW_VIEWPORT_GET(win->view); size_t pos_match = text_bracket_match_symbol(win->file->text, pos, "(){}[]\"'`", &limits); if (pos == pos_match) return; @@ -326,7 +326,7 @@ static void window_draw_cursor(Win *win, Selection *cur) { static void window_draw_selections(Win *win) { View *view = win->view; - Filerange viewport = view_viewport_get(view); + Filerange viewport = VIEW_VIEWPORT_GET(view); Selection *sel = view_selections_primary_get(view); for (Selection *s = view_selections_prev(sel); s; s = view_selections_prev(s)) { window_draw_selection(win, s); @@ -348,9 +348,9 @@ static void window_draw_selections(Win *win) { static void window_draw_eof(Win *win) { View *view = win->view; - if (view_width_get(view) == 0) + if (view->width == 0) return; - for (Line *l = view_lines_last(view)->next; l; l = l->next) { + for (Line *l = view->lastline->next; l; l = l->next) { strncpy(l->cells[0].data, view_symbol_eof_get(view), sizeof(l->cells[0].data)-1); win->ui->style_set(win->ui, &l->cells[0], UI_STYLE_EOF); } @@ -765,7 +765,7 @@ void vis_do(Vis *vis) { if (a->op == &vis_operators[VIS_OP_MODESWITCH]) count = 1; /* count should apply to inserted text not motion */ bool repeatable = a->op && !vis->macro_operator && !vis->win->parent; - bool multiple_cursors = view_selections_count(view) > 1; + bool multiple_cursors = view->selection_count > 1; bool linewise = !(a->type & CHARWISE) && ( a->type & LINEWISE || (a->movement && a->movement->type & LINEWISE) || @@ -1530,7 +1530,7 @@ void vis_insert_tab(Vis *vis) { return; } char spaces[9]; - int tabwidth = MIN(view_tabwidth_get(vis->win->view), LENGTH(spaces) - 1); + int tabwidth = MIN(vis->win->view->tabwidth, LENGTH(spaces) - 1); for (Selection *s = view_selections(win->view); s; s = view_selections_next(s)) { size_t pos = view_cursors_pos(s); int width = text_line_width_get(win->file->text, pos); |
