Skip to content

Commit

Permalink
view: rename view_cursors_next
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jun 15, 2017
1 parent 88ae50f commit 9e0c192
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 30 deletions.
24 changes: 12 additions & 12 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,7 @@ static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) {
cursor = view_cursors(view);
break;
case INT_MAX:
for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c))
for (Cursor *c = view_cursors(view); c; c = view_selections_next(c))
cursor = c;
break;
default:
Expand All @@ -1272,7 +1272,7 @@ static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) {
if (arg->i == -1)
cursor_new = view_selections_prev(cursor);
else if (arg->i == +1)
cursor_new = view_cursors_next(cursor);
cursor_new = view_selections_next(cursor);
}
if (cursor_new)
view_selections_primary_set(cursor_new);
Expand All @@ -1285,12 +1285,12 @@ static const char *cursors_align(Vis *vis, const char *keys, const Arg *arg) {
View *view = vis_view(vis);
Text *txt = vis_text(vis);
int mincol = INT_MAX;
for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(view); c; c = view_selections_next(c)) {
int col = view_cursors_cell_get(c);
if (col >= 0 && col < mincol)
mincol = col;
}
for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(view); c; c = view_selections_next(c)) {
if (view_cursors_cell_set(c, mincol) == -1) {
size_t pos = view_cursors_pos(c);
size_t col = text_line_width_set(txt, pos, mincol);
Expand Down Expand Up @@ -1355,7 +1355,7 @@ static const char *cursors_clear(Vis *vis, const char *keys, const Arg *arg) {
static const char *cursors_select(Vis *vis, const char *keys, const Arg *arg) {
Text *txt = vis_text(vis);
View *view = vis_view(vis);
for (Cursor *cursor = view_cursors(view); cursor; cursor = view_cursors_next(cursor)) {
for (Cursor *cursor = view_cursors(view); cursor; cursor = view_selections_next(cursor)) {
Filerange word = text_object_word(txt, view_cursors_pos(cursor));
if (text_range_valid(&word))
view_selections_set(cursor, &word);
Expand Down Expand Up @@ -1450,7 +1450,7 @@ static const char *cursors_remove_column_except(Vis *vis, const char *keys, cons
Cursor *cur = view_cursors(view);
Cursor *col = view_cursors_column(view, column);
for (Cursor *next; cur; cur = next) {
next = view_cursors_next(cur);
next = view_selections_next(cur);
if (cur == col)
col = view_cursors_column_next(col, column);
else
Expand All @@ -1469,14 +1469,14 @@ static const char *cursors_navigate(Vis *vis, const char *keys, const Arg *arg)
VisCountIterator it = vis_count_iterator_get(vis, 1);
while (vis_count_iterator_next(&it)) {
if (arg->i > 0) {
c = view_cursors_next(c);
c = view_selections_next(c);
if (!c)
c = view_cursors(view);
} else {
c = view_selections_prev(c);
if (!c) {
c = view_cursors(view);
for (Cursor *n = c; n; n = view_cursors_next(n))
for (Cursor *n = c; n; n = view_selections_next(n))
c = n;
}
}
Expand Down Expand Up @@ -1506,7 +1506,7 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg)
size_t line = 0;

for (Cursor *c = view_cursors(view), *next; c; c = next) {
next = view_cursors_next(c);
next = view_selections_next(c);
size_t line_next = 0;

Filerange sel = view_selections_get(c);
Expand Down Expand Up @@ -1557,7 +1557,7 @@ static const char *selections_trim(Vis *vis, const char *keys, const Arg *arg) {
Text *txt = vis_text(vis);
View *view = vis_view(vis);
for (Cursor *c = view_cursors(view), *next; c; c = next) {
next = view_cursors_next(c);
next = view_selections_next(c);
Filerange sel = view_selections_get(c);
if (!text_range_valid(&sel))
continue;
Expand Down Expand Up @@ -1660,15 +1660,15 @@ static const char *textobj(Vis *vis, const char *keys, const Arg *arg) {
}

static const char *selection_end(Vis *vis, const char *keys, const Arg *arg) {
for (Cursor *c = view_cursors(vis_view(vis)); c; c = view_cursors_next(c))
for (Cursor *c = view_cursors(vis_view(vis)); c; c = view_selections_next(c))
view_selections_flip(c);
return keys;
}

static const char *selection_restore(Vis *vis, const char *keys, const Arg *arg) {
Text *txt = vis_text(vis);
View *view = vis_view(vis);
for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c))
for (Cursor *c = view_cursors(view); c; c = view_selections_next(c))
view_selections_restore(c);
Filerange sel = view_selection_get(view);
if (text_range_is_linewise(txt, &sel))
Expand Down
8 changes: 4 additions & 4 deletions sam.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ enum SamError sam_cmd(Vis *vis, const char *s) {
view_cursor_to(vis->win->view, primary_pos);
view_selections_primary_set(view_cursors(vis->win->view));
bool completed = true;
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_selections_next(c)) {
if (view_selection_anchored(c)) {
completed = false;
break;
Expand Down Expand Up @@ -1444,7 +1444,7 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
count_init(cmd->cmd, view_cursors_count(view)+1);

for (Cursor *c = view_cursors(view), *next; c && ret; c = next) {
next = view_cursors_next(c);
next = view_selections_next(c);
size_t pos = view_cursors_pos(c);
if (vis->mode->visual) {
sel = view_selections_get(c);
Expand Down Expand Up @@ -1562,7 +1562,7 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs

bool visual = vis->mode->visual;

for (Cursor *c = view_cursors(win->view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(win->view); c; c = view_selections_next(c)) {
Filerange range = visual ? view_selections_get(c) : *r;
ssize_t written = text_write_range(text, &range, file->fd);
if (written == -1 || (size_t)written != text_range_size(&range)) {
Expand Down Expand Up @@ -1614,7 +1614,7 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs
bool failure = false;
bool visual = vis->mode->visual;

for (Cursor *c = view_cursors(win->view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(win->view); c; c = view_selections_next(c)) {
Filerange range = visual ? view_selections_get(c) : *r;
ssize_t written = text_save_write_range(ctx, &range);
failure = (written == -1 || (size_t)written != text_range_size(&range));
Expand Down
2 changes: 1 addition & 1 deletion view.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ Cursor *view_selections_prev(Cursor *c) {
return NULL;
}

Cursor *view_cursors_next(Cursor *c) {
Cursor *view_selections_next(Cursor *c) {
View *view = c->view;
for (c = c->next; c; c = c->next) {
if (c->generation != view->cursor_generation)
Expand Down
2 changes: 1 addition & 1 deletion view.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ Cursor *view_cursors(View*);
/** Get immediate predecessor of selection. */
Cursor *view_selections_prev(Cursor*);
/** Get immediate successor of selection. */
Cursor *view_cursors_next(Cursor*);
Cursor *view_selections_next(Cursor*);
/**
* Get number of existing selections.
* @rst
Expand Down
4 changes: 2 additions & 2 deletions vis-lua.c
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ static int window_cursors_iterator_next(lua_State *L) {
Cursor *cur = obj_lightref_new(L, *handle, VIS_LUA_TYPE_CURSOR);
if (!cur)
return 0;
*handle = view_cursors_next(cur);
*handle = view_selections_next(cur);
return 1;
}

Expand Down Expand Up @@ -1730,7 +1730,7 @@ static int window_cursors_index(lua_State *L) {
size_t count = view_cursors_count(view);
if (index == 0 || index > count)
goto err;
for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(view); c; c = view_selections_next(c)) {
if (!--index) {
obj_lightref_new(L, c, VIS_LUA_TYPE_CURSOR);
return 1;
Expand Down
6 changes: 3 additions & 3 deletions vis-modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static void vis_mode_normal_enter(Vis *vis, Mode *old) {
return;
if (vis->autoindent && strcmp(vis->key_prev, "<Enter>") == 0) {
Text *txt = vis->win->file->text;
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_selections_next(c)) {
size_t pos = view_cursors_pos(c);
size_t start = text_line_start(txt, pos);
size_t end = text_line_end(txt, pos);
Expand Down Expand Up @@ -185,14 +185,14 @@ static void vis_mode_operator_input(Vis *vis, const char *str, size_t len) {

static void vis_mode_visual_enter(Vis *vis, Mode *old) {
if (!old->visual) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c))
for (Cursor *c = view_cursors(vis->win->view); c; c = view_selections_next(c))
view_selections_anchor(c);
}
}

static void vis_mode_visual_line_enter(Vis *vis, Mode *old) {
if (!old->visual) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c))
for (Cursor *c = view_cursors(vis->win->view); c; c = view_selections_next(c))
view_selections_anchor(c);
}
if (!vis->action.op)
Expand Down
14 changes: 7 additions & 7 deletions vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void window_selection_save(Win *win) {
file->marks[VIS_MARK_SELECTION_START] = text_mark_set(file->text, sel.start);
file->marks[VIS_MARK_SELECTION_END] = text_mark_set(file->text, sel.end);
if (!vis->action.op) {
for (Selection *s = view_cursors(win->view); s; s = view_cursors_next(s))
for (Selection *s = view_cursors(win->view); s; s = view_selections_next(s))
view_selections_save(s);
}
}
Expand Down Expand Up @@ -412,7 +412,7 @@ static void window_draw_cursors(Win *win) {
}
window_draw_selection(win->view, cursor, &style_selection);
window_draw_cursor(win, cursor, multiple_cursors ? &style_cursor_primary : &style_cursor, &style_selection);
for (Cursor *c = view_cursors_next(cursor); c; c = view_cursors_next(c)) {
for (Cursor *c = view_selections_next(cursor); c; c = view_selections_next(c)) {
window_draw_selection(win->view, c, &style_selection);
size_t pos = view_cursors_pos(c);
if (pos > viewport.end)
Expand Down Expand Up @@ -754,7 +754,7 @@ void vis_insert(Vis *vis, size_t pos, const char *data, size_t len) {
}

void vis_insert_key(Vis *vis, const char *data, size_t len) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_selections_next(c)) {
size_t pos = view_cursors_pos(c);
vis_insert(vis, pos, data, len);
view_cursors_scroll_to(c, pos + len);
Expand All @@ -773,7 +773,7 @@ void vis_replace(Vis *vis, size_t pos, const char *data, size_t len) {
}

void vis_replace_key(Vis *vis, const char *data, size_t len) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_selections_next(c)) {
size_t pos = view_cursors_pos(c);
vis_replace(vis, pos, data, len);
view_cursors_scroll_to(c, pos + len);
Expand Down Expand Up @@ -848,7 +848,7 @@ void vis_do(Vis *vis) {
if (vis->interrupted)
break;

next = view_cursors_next(cursor);
next = view_selections_next(cursor);

size_t pos = view_cursors_pos(cursor);
if (pos == EPOS) {
Expand Down Expand Up @@ -1578,7 +1578,7 @@ void vis_insert_tab(Vis *vis) {
}
char spaces[9];
int tabwidth = MIN(vis->tabwidth, LENGTH(spaces) - 1);
for (Cursor *c = view_cursors(vis->win->view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(vis->win->view); c; c = view_selections_next(c)) {
size_t pos = view_cursors_pos(c);
int width = text_line_width_get(vis->win->file->text, pos);
int count = tabwidth - (width % tabwidth);
Expand Down Expand Up @@ -1633,7 +1633,7 @@ void vis_insert_nl(Vis *vis) {
Win *win = vis->win;
View *view = win->view;
Text *txt = win->file->text;
for (Cursor *c = view_cursors(view); c; c = view_cursors_next(c)) {
for (Cursor *c = view_cursors(view); c; c = view_selections_next(c)) {
size_t pos = view_cursors_pos(c);
size_t newpos = vis_text_insert_nl(vis, txt, pos);
/* This is a bit of a hack to fix cursor positioning when
Expand Down

0 comments on commit 9e0c192

Please sign in to comment.