aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c152
-rw-r--r--sam.c220
-rw-r--r--ui-terminal.c4
-rw-r--r--view.c589
-rw-r--r--view.h73
-rw-r--r--vis-cmds.c42
-rw-r--r--vis-core.h2
-rw-r--r--vis-lua.c72
-rw-r--r--vis-modes.c14
-rw-r--r--vis-prompt.c4
-rw-r--r--vis-registers.c2
-rw-r--r--vis.c90
-rw-r--r--vis.h2
13 files changed, 631 insertions, 635 deletions
diff --git a/main.c b/main.c
index edd0428..3f73b6e 100644
--- a/main.c
+++ b/main.c
@@ -1244,38 +1244,38 @@ static const char *cursors_new(Vis *vis, const char *keys, const Arg *arg) {
View *view = vis_view(vis);
VisCountIterator it = vis_count_iterator_get(vis, 1);
while (vis_count_iterator_next(&it)) {
- Cursor *cursor = NULL;
+ Selection *sel = NULL;
switch (arg->i) {
case -1:
case +1:
- cursor = view_selections_primary_get(view);
+ sel = view_selections_primary_get(view);
break;
case INT_MIN:
- cursor = view_selections(view);
+ sel = view_selections(view);
break;
case INT_MAX:
- for (Cursor *c = view_selections(view); c; c = view_selections_next(c))
- cursor = c;
+ for (Selection *s = view_selections(view); s; s = view_selections_next(s))
+ sel = s;
break;
default:
return keys;
}
- size_t oldpos = view_cursors_pos(cursor);
+ size_t oldpos = view_cursors_pos(sel);
if (arg->i > 0)
- view_line_down(cursor);
+ view_line_down(sel);
else if (arg->i < 0)
- view_line_up(cursor);
- size_t newpos = view_cursors_pos(cursor);
- view_cursors_to(cursor, oldpos);
- Cursor *cursor_new = view_selections_new(view, newpos);
- if (!cursor_new) {
+ view_line_up(sel);
+ size_t newpos = view_cursors_pos(sel);
+ view_cursors_to(sel, oldpos);
+ Selection *sel_new = view_selections_new(view, newpos);
+ if (!sel_new) {
if (arg->i == -1)
- cursor_new = view_selections_prev(cursor);
+ sel_new = view_selections_prev(sel);
else if (arg->i == +1)
- cursor_new = view_selections_next(cursor);
+ sel_new = view_selections_next(sel);
}
- if (cursor_new)
- view_selections_primary_set(cursor_new);
+ if (sel_new)
+ view_selections_primary_set(sel_new);
}
vis_count_set(vis, VIS_COUNT_UNKNOWN);
return keys;
@@ -1285,16 +1285,16 @@ 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_selections(view); c; c = view_selections_next(c)) {
- int col = view_cursors_cell_get(c);
+ for (Selection *s = view_selections(view); s; s = view_selections_next(s)) {
+ int col = view_cursors_cell_get(s);
if (col >= 0 && col < mincol)
mincol = col;
}
- for (Cursor *c = view_selections(view); c; c = view_selections_next(c)) {
- if (view_cursors_cell_set(c, mincol) == -1) {
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections(view); s; s = view_selections_next(s)) {
+ if (view_cursors_cell_set(s, mincol) == -1) {
+ size_t pos = view_cursors_pos(s);
size_t col = text_line_width_set(txt, pos, mincol);
- view_cursors_to(c, col);
+ view_cursors_to(s, col);
}
}
return keys;
@@ -1308,8 +1308,8 @@ static const char *cursors_align_indent(Vis *vis, const char *keys, const Arg *a
for (int i = 0; i < columns; i++) {
int mincol = INT_MAX, maxcol = 0;
- for (Cursor *c = view_selections_column(view, i); c; c = view_selections_column_next(c, i)) {
- Filerange sel = view_selections_get(c);
+ for (Selection *s = view_selections_column(view, i); s; s = view_selections_column_next(s, i)) {
+ Filerange sel = view_selections_get(s);
size_t pos = left_align ? sel.start : sel.end;
int col = text_line_width_get(txt, pos);
if (col < mincol)
@@ -1324,8 +1324,8 @@ static const char *cursors_align_indent(Vis *vis, const char *keys, const Arg *a
return keys;
memset(buf, ' ', len);
- for (Cursor *c = view_selections_column(view, i); c; c = view_selections_column_next(c, i)) {
- Filerange sel = view_selections_get(c);
+ for (Selection *s = view_selections_column(view, i); s; s = view_selections_column_next(s, i)) {
+ Filerange sel = view_selections_get(s);
size_t pos = left_align ? sel.start : sel.end;
size_t ipos = sel.start;
int col = text_line_width_get(txt, pos);
@@ -1355,10 +1355,10 @@ 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_selections(view); cursor; cursor = view_selections_next(cursor)) {
- Filerange word = text_object_word(txt, view_cursors_pos(cursor));
+ for (Selection *s = view_selections(view); s; s = view_selections_next(s)) {
+ Filerange word = text_object_word(txt, view_cursors_pos(s));
if (text_range_valid(&word))
- view_selections_set(cursor, &word);
+ view_selections_set(s, &word);
}
vis_mode_switch(vis, VIS_MODE_VISUAL);
return keys;
@@ -1367,8 +1367,8 @@ static const char *cursors_select(Vis *vis, const char *keys, const Arg *arg) {
static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *arg) {
Text *txt = vis_text(vis);
View *view = vis_view(vis);
- Cursor *cursor = view_selections_primary_get(view);
- Filerange sel = view_selections_get(cursor);
+ Selection *s = view_selections_primary_get(view);
+ Filerange sel = view_selections_get(s);
if (!text_range_valid(&sel))
return keys;
@@ -1378,9 +1378,9 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar
Filerange word = text_object_word_find_next(txt, sel.end, buf);
if (text_range_valid(&word)) {
size_t pos = text_char_prev(txt, word.end);
- if ((cursor = view_selections_new(view, pos))) {
- view_selections_set(cursor, &word);
- view_selections_primary_set(cursor);
+ if ((s = view_selections_new(view, pos))) {
+ view_selections_set(s, &word);
+ view_selections_primary_set(s);
goto out;
}
}
@@ -1390,9 +1390,9 @@ static const char *cursors_select_next(Vis *vis, const char *keys, const Arg *ar
if (!text_range_valid(&word))
goto out;
size_t pos = text_char_prev(txt, word.end);
- if ((cursor = view_selections_new(view, pos))) {
- view_selections_set(cursor, &word);
- view_selections_primary_set(cursor);
+ if ((s = view_selections_new(view, pos))) {
+ view_selections_set(s, &word);
+ view_selections_primary_set(s);
}
out:
@@ -1402,10 +1402,10 @@ out:
static const char *cursors_select_skip(Vis *vis, const char *keys, const Arg *arg) {
View *view = vis_view(vis);
- Cursor *cursor = view_selections_primary_get(view);
+ Selection *sel = view_selections_primary_get(view);
keys = cursors_select_next(vis, keys, arg);
- if (cursor != view_selections_primary_get(view))
- view_selections_dispose(cursor);
+ if (sel != view_selections_primary_get(view))
+ view_selections_dispose(sel);
return keys;
}
@@ -1427,9 +1427,9 @@ static const char *cursors_remove_column(Vis *vis, const char *keys, const Arg *
return keys;
}
- for (Cursor *c = view_selections_column(view, column), *next; c; c = next) {
- next = view_selections_column_next(c, column);
- view_selections_dispose(c);
+ for (Selection *s = view_selections_column(view, column), *next; s; s = next) {
+ next = view_selections_column_next(s, column);
+ view_selections_dispose(s);
}
vis_count_set(vis, VIS_COUNT_UNKNOWN);
@@ -1447,14 +1447,14 @@ static const char *cursors_remove_column_except(Vis *vis, const char *keys, cons
return keys;
}
- Cursor *cur = view_selections(view);
- Cursor *col = view_selections_column(view, column);
- for (Cursor *next; cur; cur = next) {
- next = view_selections_next(cur);
- if (cur == col)
+ Selection *sel = view_selections(view);
+ Selection *col = view_selections_column(view, column);
+ for (Selection *next; sel; sel = next) {
+ next = view_selections_next(sel);
+ if (sel == col)
col = view_selections_column_next(col, column);
else
- view_selections_dispose(cur);
+ view_selections_dispose(sel);
}
vis_count_set(vis, VIS_COUNT_UNKNOWN);
@@ -1465,23 +1465,23 @@ static const char *cursors_navigate(Vis *vis, const char *keys, const Arg *arg)
View *view = vis_view(vis);
if (view_selections_count(view) == 1)
return wscroll(vis, keys, arg);
- Cursor *c = view_selections_primary_get(view);
+ Selection *s = view_selections_primary_get(view);
VisCountIterator it = vis_count_iterator_get(vis, 1);
while (vis_count_iterator_next(&it)) {
if (arg->i > 0) {
- c = view_selections_next(c);
- if (!c)
- c = view_selections(view);
+ s = view_selections_next(s);
+ if (!s)
+ s = view_selections(view);
} else {
- c = view_selections_prev(c);
- if (!c) {
- c = view_selections(view);
- for (Cursor *n = c; n; n = view_selections_next(n))
- c = n;
+ s = view_selections_prev(s);
+ if (!s) {
+ s = view_selections(view);
+ for (Selection *n = s; n; n = view_selections_next(n))
+ s = n;
}
}
}
- view_selections_primary_set(c);
+ view_selections_primary_set(s);
vis_count_set(vis, VIS_COUNT_UNKNOWN);
return keys;
}
@@ -1489,7 +1489,7 @@ static const char *cursors_navigate(Vis *vis, const char *keys, const Arg *arg)
static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg) {
typedef struct {
- Cursor *cursor;
+ Selection *sel;
char *data;
size_t len;
} Rotate;
@@ -1505,13 +1505,13 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg)
return keys;
size_t line = 0;
- for (Cursor *c = view_selections(view), *next; c; c = next) {
- next = view_selections_next(c);
+ for (Selection *s = view_selections(view), *next; s; s = next) {
+ next = view_selections_next(s);
size_t line_next = 0;
- Filerange sel = view_selections_get(c);
+ Filerange sel = view_selections_get(s);
Rotate rot;
- rot.cursor = c;
+ rot.sel = s;
rot.len = text_range_size(&sel);
if ((rot.data = malloc(rot.len)))
rot.len = text_bytes_get(txt, sel.start, rot.len, rot.data);
@@ -1520,7 +1520,7 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg)
array_add(&arr, &rot);
if (!line)
- line = text_lineno_by_pos(txt, view_cursors_pos(c));
+ line = text_lineno_by_pos(txt, view_cursors_pos(s));
if (next)
line_next = text_lineno_by_pos(txt, view_cursors_pos(next));
if (!next || (columns > 1 && line != line_next)) {
@@ -1532,7 +1532,7 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg)
Rotate *newrot = array_get(&arr, j);
if (!oldrot || !newrot || oldrot == newrot)
continue;
- Filerange newsel = view_selections_get(newrot->cursor);
+ Filerange newsel = view_selections_get(newrot->sel);
if (!text_range_valid(&newsel))
continue;
if (!text_delete_range(txt, &newsel))
@@ -1540,7 +1540,7 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg)
if (!text_insert(txt, newsel.start, oldrot->data, oldrot->len))
continue;
newsel.end = newsel.start + oldrot->len;
- view_selections_set(newrot->cursor, &newsel);
+ view_selections_set(newrot->sel, &newsel);
free(oldrot->data);
}
array_clear(&arr);
@@ -1556,9 +1556,9 @@ static const char *selections_rotate(Vis *vis, const char *keys, const Arg *arg)
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_selections(view), *next; c; c = next) {
- next = view_selections_next(c);
- Filerange sel = view_selections_get(c);
+ for (Selection *s = view_selections(view), *next; s; s = next) {
+ next = view_selections_next(s);
+ Filerange sel = view_selections_get(s);
if (!text_range_valid(&sel))
continue;
for (char b; sel.start < sel.end && text_byte_get(txt, sel.end-1, &b)
@@ -1566,8 +1566,8 @@ static const char *selections_trim(Vis *vis, const char *keys, const Arg *arg) {
for (char b; sel.start <= sel.end && text_byte_get(txt, sel.start, &b)
&& isspace((unsigned char)b); sel.start++);
if (sel.start < sel.end) {
- view_selections_set(c, &sel);
- } else if (!view_selections_dispose(c)) {
+ view_selections_set(s, &sel);
+ } else if (!view_selections_dispose(s)) {
vis_mode_switch(vis, VIS_MODE_NORMAL);
}
}
@@ -1660,16 +1660,16 @@ 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_selections(vis_view(vis)); c; c = view_selections_next(c))
- view_selections_flip(c);
+ for (Selection *s = view_selections(vis_view(vis)); s; s = view_selections_next(s))
+ view_selections_flip(s);
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_selections(view); c; c = view_selections_next(c))
- view_selections_restore(c);
+ for (Selection *s = view_selections(view); s; s = view_selections_next(s))
+ view_selections_restore(s);
Filerange sel = view_selection_get(view);
if (text_range_is_linewise(txt, &sel))
vis_mode_switch(vis, VIS_MODE_VISUAL_LINE);
diff --git a/sam.c b/sam.c
index 42a81df..6d6da1c 100644
--- a/sam.c
+++ b/sam.c
@@ -45,7 +45,7 @@ struct Change {
TRANSCRIPT_CHANGE = TRANSCRIPT_INSERT|TRANSCRIPT_DELETE,
} type;
Win *win; /* window in which changed file is being displayed */
- Cursor *cursor; /* cursor associated with this change, might be NULL */
+ Selection *cursor; /* cursor associated with this change, might be NULL */
Filerange range; /* inserts are denoted by zero sized range (same start/end) */
const char *data; /* will be free(3)-ed after transcript has been processed */
size_t len; /* size in bytes of the chunk pointed to by data */
@@ -102,44 +102,44 @@ struct CommandDef {
CMD_DESTRUCTIVE = 1 << 17, /* command potentially destroys window */
} flags;
const char *defcmd; /* name of a default target command */
- bool (*func)(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*); /* command implementation */
+ bool (*func)(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*); /* command implementation */
};
/* sam commands */
-static bool cmd_insert(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_append(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_change(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_delete(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_guard(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_extract(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_select(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_print(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_files(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_pipein(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_pipeout(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_filter(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_launch(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_substitute(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_write(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_read(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_edit(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_quit(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_cd(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
+static bool cmd_insert(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_append(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_change(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_delete(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_guard(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_extract(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_select(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_print(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_files(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_pipein(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_pipeout(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_filter(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_launch(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_substitute(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_write(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_read(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_edit(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_quit(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_cd(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
/* vi(m) commands */
-static bool cmd_set(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_open(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_qall(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_split(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_vsplit(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_new(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_vnew(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_wq(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_earlier_later(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_help(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_map(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_unmap(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_langmap(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
-static bool cmd_user(Vis*, Win*, Command*, const char *argv[], Cursor*, Filerange*);
+static bool cmd_set(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_open(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_qall(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_split(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_vsplit(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_new(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_vnew(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_wq(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_earlier_later(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_help(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_map(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_unmap(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_langmap(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
+static bool cmd_user(Vis*, Win*, Command*, const char *argv[], Selection*, Filerange*);
static const CommandDef cmds[] = {
// name help
@@ -419,7 +419,7 @@ static void change_free(Change *c) {
free(c);
}
-static Change *change_new(Transcript *t, enum ChangeType type, Filerange *range, Win *win, Cursor *cur) {
+static Change *change_new(Transcript *t, enum ChangeType type, Filerange *range, Win *win, Selection *sel) {
if (!text_range_valid(range))
return NULL;
Change **prev, *next;
@@ -442,7 +442,7 @@ static Change *change_new(Transcript *t, enum ChangeType type, Filerange *range,
if (new) {
new->type = type;
new->range = *range;
- new->cursor = cur;
+ new->cursor = sel;
new->win = win;
new->next = next;
*prev = new;
@@ -468,9 +468,9 @@ static void sam_transcript_free(Transcript *t) {
}
}
-static bool sam_insert(Win *win, Cursor *cur, size_t pos, const char *data, size_t len) {
+static bool sam_insert(Win *win, Selection *sel, size_t pos, const char *data, size_t len) {
Filerange range = text_range_new(pos, pos);
- Change *c = change_new(&win->file->transcript, TRANSCRIPT_INSERT, &range, win, cur);
+ Change *c = change_new(&win->file->transcript, TRANSCRIPT_INSERT, &range, win, sel);
if (c) {
c->data = data;
c->len = len;
@@ -478,12 +478,12 @@ static bool sam_insert(Win *win, Cursor *cur, size_t pos, const char *data, size
return c;
}
-static bool sam_delete(Win *win, Cursor *cur, Filerange *range) {
- return change_new(&win->file->transcript, TRANSCRIPT_DELETE, range, win, cur);
+static bool sam_delete(Win *win, Selection *sel, Filerange *range) {
+ return change_new(&win->file->transcript, TRANSCRIPT_DELETE, range, win, sel);
}
-static bool sam_change(Win *win, Cursor *cur, Filerange *range, const char *data, size_t len) {
- Change *c = change_new(&win->file->transcript, TRANSCRIPT_CHANGE, range, win, cur);
+static bool sam_change(Win *win, Selection *sel, Filerange *range, const char *data, size_t len) {
+ Change *c = change_new(&win->file->transcript, TRANSCRIPT_CHANGE, range, win, sel);
if (c) {
c->data = data;
c->len = len;
@@ -1084,7 +1084,7 @@ static bool count_evaluate(Command *cmd) {
return count->start <= cmd->iteration && cmd->iteration <= count->end;
}
-static bool sam_execute(Vis *vis, Win *win, Command *cmd, Cursor *cur, Filerange *range) {
+static bool sam_execute(Vis *vis, Win *win, Command *cmd, Selection *sel, Filerange *range) {
bool ret = true;
if (cmd->address && win)
*range = address_evaluate(cmd->address, win->file, range, 0);
@@ -1095,11 +1095,11 @@ static bool sam_execute(Vis *vis, Win *win, Command *cmd, Cursor *cur, Filerange
{
for (Command *c = cmd->cmd; c && ret; c = c->next)
ret &= sam_execute(vis, win, c, NULL, range);
- view_selections_dispose_force(cur);
+ view_selections_dispose_force(sel);
break;
}
default:
- ret = cmd->cmddef->func(vis, win, cmd, cmd->argv, cur, range);
+ ret = cmd->cmddef->func(vis, win, cmd, cmd->argv, sel, range);
break;
}
return ret;
@@ -1221,7 +1221,7 @@ enum SamError sam_cmd(Vis *vis, const char *s) {
view_cursors_to(c->cursor, sel.end);
}
} else if (visual) {
- Cursor *cursor = view_selections_new(c->win->view, sel.start);
+ Selection *cursor = view_selections_new(c->win->view, sel.start);
if (cursor) {
view_selections_set(cursor, &sel);
view_selections_anchor(cursor);
@@ -1238,8 +1238,8 @@ enum SamError sam_cmd(Vis *vis, const char *s) {
view_cursor_to(vis->win->view, primary_pos);
view_selections_primary_set(view_selections(vis->win->view));
bool completed = true;
- for (Cursor *c = view_selections(vis->win->view); c; c = view_selections_next(c)) {
- if (view_selections_anchored(c)) {
+ for (Selection *s = view_selections(vis->win->view); s; s = view_selections_next(s)) {
+ if (view_selections_anchored(s)) {
completed = false;
break;
}
@@ -1288,58 +1288,58 @@ out:
return buf;
}
-static bool cmd_insert(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_insert(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
Buffer buf = text(vis, argv[1]);
size_t len = buffer_length(&buf);
char *data = buffer_move(&buf);
- bool ret = sam_insert(win, cur, range->start, data, len);
+ bool ret = sam_insert(win, sel, range->start, data, len);
if (!ret)
free(data);
return ret;
}
-static bool cmd_append(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_append(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
Buffer buf = text(vis, argv[1]);
size_t len = buffer_length(&buf);
char *data = buffer_move(&buf);
- bool ret = sam_insert(win, cur, range->end, data, len);
+ bool ret = sam_insert(win, sel, range->end, data, len);
if (!ret)
free(data);
return ret;
}
-static bool cmd_change(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_change(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
Buffer buf = text(vis, argv[1]);
size_t len = buffer_length(&buf);
char *data = buffer_move(&buf);
- bool ret = sam_change(win, cur, range, data, len);
+ bool ret = sam_change(win, sel, range, data, len);
if (!ret)
free(data);
return ret;
}
-static bool cmd_delete(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
- return win && sam_delete(win, cur, range);
+static bool cmd_delete(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
+ return win && sam_delete(win, sel, range);
}
-static bool cmd_guard(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_guard(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
bool match = !cmd->regex || !text_search_range_forward(win->file->text, range->start,
text_range_size(range), cmd->regex, 0, NULL, 0);
if ((count_evaluate(cmd) && match) ^ (argv[0][0] == 'v'))
- return sam_execute(vis, win, cmd->cmd, cur, range);
- view_selections_dispose_force(cur);
+ return sam_execute(vis, win, cmd->cmd, sel, range);
+ view_selections_dispose_force(sel);
return true;
}
-static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range, bool simulate) {
+static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range, bool simulate) {
bool ret = true;
int count = 0;
Text *txt = win->file->text;
@@ -1416,38 +1416,38 @@ static int extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor
}
if (!simulate)
- view_selections_dispose_force(cur);
+ view_selections_dispose_force(sel);
return simulate ? count : ret;
}
-static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_extract(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
int matches = 0;
if (count_negative(cmd->cmd))
- matches = extract(vis, win, cmd, argv, cur, range, true);
+ matches = extract(vis, win, cmd, argv, sel, range, true);
count_init(cmd->cmd, matches+1);
- return extract(vis, win, cmd, argv, cur, range, false);
+ return extract(vis, win, cmd, argv, sel, range, false);
}
-static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
- Filerange sel = text_range_empty();
+static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
+ Filerange r = text_range_empty();
if (!win)
- return sam_execute(vis, NULL, cmd->cmd, NULL, &sel);
+ return sam_execute(vis, NULL, cmd->cmd, NULL, &r);
bool ret = true;
View *view = win->view;
Text *txt = win->file->text;
bool multiple_cursors = view_selections_count(view) > 1;
- Cursor *primary = view_selections_primary_get(view);
+ Selection *primary = view_selections_primary_get(view);
if (vis->mode->visual)
count_init(cmd->cmd, view_selections_count(view)+1);
- for (Cursor *c = view_selections(view), *next; c && ret; c = next) {
- next = view_selections_next(c);
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections(view), *next; s && ret; s = next) {
+ next = view_selections_next(s);
+ size_t pos = view_cursors_pos(s);
if (vis->mode->visual) {
- sel = view_selections_get(c);
+ r = view_selections_get(s);
} else if (cmd->cmd->address) {
/* convert a single line range to a goto line motion */
if (!multiple_cursors && cmd->cmd->cmddef->func == cmd_print) {
@@ -1463,24 +1463,24 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
break;
}
}
- sel = text_range_new(pos, pos);
+ r = text_range_new(pos, pos);
} else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_POS) {
- sel = text_range_new(pos, pos);
+ r = text_range_new(pos, pos);
} else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_LINE) {
- sel = text_object_line(txt, pos);
+ r = text_object_line(txt, pos);
} else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_AFTER) {
size_t next_line = text_line_next(txt, pos);
- sel = text_range_new(next_line, next_line);
+ r = text_range_new(next_line, next_line);
} else if (cmd->cmd->cmddef->flags & CMD_ADDRESS_ALL) {
- sel = text_range_new(0, text_size(txt));
+ r = text_range_new(0, text_size(txt));
} else if (!multiple_cursors && (cmd->cmd->cmddef->flags & CMD_ADDRESS_ALL_1CURSOR)) {
- sel = text_range_new(0, text_size(txt));
+ r = text_range_new(0, text_size(txt));
} else {
- sel = text_range_new(pos, text_char_next(txt, pos));
+ r = text_range_new(pos, text_char_next(txt, pos));
}
- if (!text_range_valid(&sel))
- sel = text_range_new(0, 0);
- ret &= sam_execute(vis, win, cmd->cmd, c, &sel);
+ if (!text_range_valid(&r))
+ r = text_range_new(0, 0);
+ ret &= sam_execute(vis, win, cmd->cmd, s, &r);
if (cmd->cmd->cmddef->flags & CMD_ONCE)
break;
}
@@ -1490,7 +1490,7 @@ static bool cmd_select(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
return ret;
}
-static bool cmd_print(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_print(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win || !text_range_valid(range))
return false;
View *view = win->view;
@@ -1498,22 +1498,22 @@ static bool cmd_print(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs
size_t pos = range->end;
if (range->start != range->end)
pos = text_char_prev(txt, pos);
- if (cur)
- view_cursors_to(cur, pos);
+ if (sel)
+ view_cursors_to(sel, pos);
else
- cur = view_selections_new_force(view, pos);
- if (cur) {
+ sel = view_selections_new_force(view, pos);
+ if (sel) {
if (range->start != range->end) {
- view_selections_set(cur, range);
- view_selections_anchor(cur);
+ view_selections_set(sel, range);
+ view_selections_anchor(sel);
} else {
- view_selection_clear(cur);
+ view_selection_clear(sel);
}
}
- return cur != NULL;
+ return sel != NULL;
}
-static bool cmd_files(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_files(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
bool ret = true;
for (Win *win = vis->windows; win; win = win->next) {
if (win->file->internal)
@@ -1528,12 +1528,12 @@ static bool cmd_files(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs
return ret;
}
-static bool cmd_substitute(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_substitute(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
vis_info_show(vis, "Use :x/pattern/ c/replacement/ instead");
return false;
}
-static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *r) {
+static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *r) {
if (!win)
return false;
@@ -1562,8 +1562,8 @@ static bool cmd_write(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs
bool visual = vis->mode->visual;
- for (Cursor *c = view_selections(win->view); c; c = view_selections_next(c)) {
- Filerange range = visual ? view_selections_get(c) : *r;
+ for (Selection *s = view_selections(win->view); s; s = view_selections_next(s)) {
+ Filerange range = visual ? view_selections_get(s) : *r;
ssize_t written = text_write_range(text, &range, file->fd);
if (written == -1 || (size_t)written != text_range_size(&range)) {
vis_info_show(vis, "Can not write to stdout");
@@ -1614,8 +1614,8 @@ 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_selections(win->view); c; c = view_selections_next(c)) {
- Filerange range = visual ? view_selections_get(c) : *r;
+ for (Selection *s = view_selections(win->view); s; s = view_selections_next(s)) {
+ Filerange range = visual ? view_selections_get(s) : *r;
ssize_t written = text_save_write_range(ctx, &range);
failure = (written == -1 || (size_t)written != text_range_size(&range));
if (failure) {
@@ -1646,7 +1646,7 @@ static ssize_t read_buffer(void *context, char *data, size_t len) {
return len;
}
-static bool cmd_filter(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_filter(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
@@ -1661,7 +1661,7 @@ static bool cmd_filter(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
} else if (status == 0) {
size_t len = buffer_length(&bufout);
char *data = buffer_move(&bufout);
- if (!sam_change(win, cur, range, data, len))
+ if (!sam_change(win, sel, range, data, len))
free(data);
} else {
vis_info_show(vis, "Command failed %s", buffer_content0(&buferr));
@@ -1673,22 +1673,22 @@ static bool cmd_filter(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
return !vis->interrupted && status == 0;
}
-static bool cmd_launch(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
- Filerange invalid = text_range_new(cur ? view_cursors_pos(cur) : range->start, EPOS);
- return cmd_filter(vis, win, cmd, argv, cur, &invalid);
+static bool cmd_launch(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
+ Filerange invalid = text_range_new(sel ? view_cursors_pos(sel) : range->start, EPOS);
+ return cmd_filter(vis, win, cmd, argv, sel, &invalid);
}
-static bool cmd_pipein(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_pipein(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
Filerange filter_range = text_range_new(range->end, range->end);
- bool ret = cmd_filter(vis, win, cmd, argv, cur, &filter_range);
+ bool ret = cmd_filter(vis, win, cmd, argv, sel, &filter_range);
if (ret)
ret = sam_delete(win, NULL, range);
return ret;
}
-static bool cmd_pipeout(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_pipeout(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
Buffer buferr;
@@ -1696,8 +1696,8 @@ static bool cmd_pipeout(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu
int status = vis_pipe(vis, win->file, range, (const char*[]){ argv[1], NULL }, NULL, NULL, &buferr, read_buffer);
- if (status == 0 && cur)
- view_cursors_to(cur, range->start);
+ if (status == 0 && sel)
+ view_cursors_to(sel, range->start);
if (vis->interrupted)
vis_info_show(vis, "Command cancelled");
@@ -1709,7 +1709,7 @@ static bool cmd_pipeout(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu
return !vis->interrupted && status == 0;
}
-static bool cmd_cd(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_cd(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
const char *dir = argv[1];
if (!dir)
dir = getenv("HOME");
diff --git a/ui-terminal.c b/ui-terminal.c
index 6ba3164..69a6f29 100644
--- a/ui-terminal.c
+++ b/ui-terminal.c
@@ -247,8 +247,8 @@ static void ui_window_draw(UiWin *w) {
vis_window_draw(win->win);
line = view_lines_first(view);
size_t prev_lineno = 0;
- Cursor *cursor = view_selections_primary_get(view);
- const Line *cursor_line = view_cursors_line_get(cursor);
+ 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[sidebar_width+1];
int x = win->x, y = win->y;
diff --git a/view.c b/view.c
index be74b62..262bdde 100644
--- a/view.c
+++ b/view.c
@@ -43,27 +43,24 @@ typedef struct {
Mark cursor;
} SelectionRegion;
-struct Cursor { /* cursor position */
- Mark cursor; /* other selection endpoint where it changes */
- Mark anchor; /* position where the selection was created */
- bool anchored; /* whether anchor remains fixed */
- size_t pos; /* in bytes from the start of the file */
- int row, col; /* in terms of zero based screen coordinates */
- int lastcol; /* remembered column used when moving across lines */
- Line *line; /* screen line on which cursor currently resides */
- int generation; /* used to filter out newly created cursors during iteration */
- int number; /* how many cursors are located before this one */
+struct Selection {
+ Mark cursor; /* other selection endpoint where it changes */
+ Mark anchor; /* position where the selection was created */
+ bool anchored; /* whether anchor remains fixed */
+ size_t pos; /* in bytes from the start of the file */
+ int row, col; /* in terms of zero based screen coordinates */
+ int lastcol; /* remembered column used when moving across lines */
+ Line *line; /* screen line on which cursor currently resides */
+ int generation; /* used to filter out newly created cursors during iteration */
+ int number; /* how many cursors are located before this one */
SelectionRegion region; /* saved selection region */
- View *view; /* associated view to which this cursor belongs */
- Cursor *prev, *next;/* previous/next cursors ordered by location at creation time */
+ View *view; /* associated view to which this cursor belongs */
+ Selection *prev, *next; /* previous/next cursors ordered by location at creation time */
};
-/* Viewable area, showing part of a file. Keeps track of cursors and selections.
- * At all times there exists at least one cursor, which is placed in the visible viewport.
- * Additional cursors can be created and positioned anywhere in the file. */
struct View {
Text *text; /* underlying text management */
- UiWin *ui;
+ 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 */
@@ -74,16 +71,16 @@ struct View {
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 */
- Cursor *cursor; /* main cursor, always placed within the visible viewport */
- Cursor *cursor_latest; /* most recently created cursor */
- Cursor *cursor_dead;/* main cursor which was disposed, will be removed when another cursor is created */
- int cursor_count; /* how many cursors do currently exist */
+ 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 */
- Cursor *cursors; /* all cursors currently active */
- int cursor_generation; /* used to filter out newly created cursors during iteration */
+ 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;
@@ -115,9 +112,9 @@ static bool view_viewport_down(View *view, int n);
static void view_clear(View *view);
static bool view_addch(View *view, Cell *cell);
-static void view_cursors_free(Cursor *c);
+static void selection_free(Selection*);
/* set/move current cursor position to a given (line, column) pair */
-static size_t cursor_set(Cursor *cursor, Line *line, int col);
+static size_t cursor_set(Selection*, Line *line, int col);
void view_tabwidth_set(View *view, int tabwidth) {
view->tabwidth = tabwidth;
@@ -263,24 +260,24 @@ static bool view_addch(View *view, Cell *cell) {
}
}
-static void cursor_to(Cursor *c, size_t pos) {
- Text *txt = c->view->text;
- c->cursor = text_mark_set(txt, pos);
- if (!c->anchored)
- c->anchor = c->cursor;
- if (pos != c->pos)
- c->lastcol = 0;
- c->pos = pos;
- if (!view_coord_get(c->view, pos, &c->line, &c->row, &c->col)) {
- if (c->view->cursor == c) {
- c->line = c->view->topline;
- c->row = 0;
- c->col = 0;
+static void cursor_to(Selection *s, size_t pos) {
+ Text *txt = s->view->text;
+ s->cursor = text_mark_set(txt, pos);
+ if (!s->anchored)
+ s->anchor = s->cursor;
+ if (pos != s->pos)
+ s->lastcol = 0;
+ s->pos = pos;
+ if (!view_coord_get(s->view, pos, &s->line, &s->row, &s->col)) {
+ if (s->view->selection == s) {
+ s->line = s->view->topline;
+ s->row = 0;
+ s->col = 0;
}
return;
}
// TODO: minimize number of redraws
- view_draw(c->view);
+ view_draw(s->view);
}
bool view_coord_get(View *view, size_t pos, Line **retline, int *retrow, int *retcol) {
@@ -324,7 +321,7 @@ bool view_coord_get(View *view, size_t pos, Line **retline, int *retrow, int *re
/* move the cursor to the character at pos bytes from the begining of the file.
* if pos is not in the current viewport, redraw the view to make it visible */
void view_cursor_to(View *view, size_t pos) {
- view_cursors_to(view->cursor, pos);
+ view_cursors_to(view->selection, pos);
}
/* redraw the complete with data starting from view->start bytes into the file.
@@ -422,13 +419,13 @@ void view_draw(View *view) {
}
/* resync position of cursors within visible area */
- for (Cursor *c = view->cursors; c; c = c->next) {
- size_t pos = view_cursors_pos(c);
- if (!view_coord_get(view, pos, &c->line, &c->row, &c->col) &&
- c == view->cursor) {
- c->line = view->topline;
- c->row = 0;
- c->col = 0;
+ for (Selection *s = view->selections; s; s = s->next) {
+ size_t pos = view_cursors_pos(s);
+ if (!view_coord_get(view, pos, &s->line, &s->row, &s->col) &&
+ s == view->selection) {
+ s->line = view->topline;
+ s->row = 0;
+ s->col = 0;
}
}
@@ -485,8 +482,8 @@ int view_width_get(View *view) {
void view_free(View *view) {
if (!view)
return;
- while (view->cursors)
- view_cursors_free(view->cursors);
+ while (view->selections)
+ selection_free(view->selections);
free(view->lines);
free(view);
}
@@ -531,13 +528,13 @@ void view_ui(View *view, UiWin* ui) {
view->ui = ui;
}
-static size_t cursor_set(Cursor *cursor, Line *line, int col) {
+static size_t cursor_set(Selection *sel, Line *line, int col) {
int row = 0;
- View *view = cursor->view;
+ View *view = sel->view;
size_t pos = view->start;
/* get row number and file offset at start of the given line */
- for (Line *cur = view->topline; cur && cur != line; cur = cur->next) {
- pos += cur->len;
+ for (Line *l = view->topline; l && l != line; l = l->next) {
+ pos += l->len;
row++;
}
@@ -548,11 +545,11 @@ static size_t cursor_set(Cursor *cursor, Line *line, int col) {
for (int i = 0; i < col; i++)
pos += line->cells[i].len;
- cursor->col = col;
- cursor->row = row;
- cursor->line = line;
+ sel->col = col;
+ sel->row = row;
+ sel->line = line;
- cursor_to(cursor, pos);
+ cursor_to(sel, pos);
return pos;
}
@@ -600,19 +597,19 @@ static bool view_viewport_up(View *view, int n) {
}
void view_redraw_top(View *view) {
- Line *line = view->cursor->line;
+ Line *line = view->selection->line;
for (Line *cur = view->topline; cur && cur != line; cur = cur->next)
view->start += cur->len;
view_draw(view);
- view_cursor_to(view, view->cursor->pos);
+ view_cursor_to(view, view->selection->pos);
}
void view_redraw_center(View *view) {
int center = view->height / 2;
- size_t pos = view->cursor->pos;
+ size_t pos = view->selection->pos;
for (int i = 0; i < 2; i++) {
int linenr = 0;
- Line *line = view->cursor->line;
+ Line *line = view->selection->line;
for (Line *cur = view->topline; cur && cur != line; cur = cur->next)
linenr++;
if (linenr < center) {
@@ -630,81 +627,81 @@ void view_redraw_center(View *view) {
}
void view_redraw_bottom(View *view) {
- Line *line = view->cursor->line;
+ Line *line = view->selection->line;
if (line == view->lastline)
return;
- size_t pos = view->cursor->pos;
+ size_t pos = view->selection->pos;
view_viewport_up(view, view->height);
while (pos >= view->end && view_viewport_down(view, 1));
- cursor_to(view->cursor, pos);
+ cursor_to(view->selection, pos);
}
size_t view_slide_up(View *view, int lines) {
- Cursor *cursor = view->cursor;
+ Selection *sel = view->selection;
if (view_viewport_down(view, lines)) {
- if (cursor->line == view->topline)
- cursor_set(cursor, view->topline, cursor->col);
+ if (sel->line == view->topline)
+ cursor_set(sel, view->topline, sel->col);
else
- view_cursor_to(view, cursor->pos);
+ view_cursor_to(view, sel->pos);
} else {
- view_screenline_down(cursor);
+ view_screenline_down(sel);
}
- return cursor->pos;
+ return sel->pos;
}
size_t view_slide_down(View *view, int lines) {
- Cursor *cursor = view->cursor;
- bool lastline = cursor->line == view->lastline;
- size_t col = cursor->col;
+ Selection *sel = view->selection;
+ bool lastline = sel->line == view->lastline;
+ size_t col = sel->col;
if (view_viewport_up(view, lines)) {
if (lastline)
- cursor_set(cursor, view->lastline, col);
+ cursor_set(sel, view->lastline, col);
else
- view_cursor_to(view, cursor->pos);
+ view_cursor_to(view, sel->pos);
} else {
- view_screenline_up(cursor);
+ view_screenline_up(sel);
}
- return cursor->pos;
+ return sel->pos;
}
size_t view_scroll_up(View *view, int lines) {
- Cursor *cursor = view->cursor;
+ Selection *sel = view->selection;
if (view_viewport_up(view, lines)) {
- Line *line = cursor->line < view->lastline ? cursor->line : view->lastline;
- cursor_set(cursor, line, view->cursor->col);
+ Line *line = sel->line < view->lastline ? sel->line : view->lastline;
+ cursor_set(sel, line, view->selection->col);
} else {
view_cursor_to(view, 0);
}
- return cursor->pos;
+ return sel->pos;
}
size_t view_scroll_page_up(View *view) {
- Cursor *cursor = view->cursor;
+ Selection *sel = view->selection;
if (view->start == 0) {
view_cursor_to(view, 0);
} else {
view_cursor_to(view, view->start-1);
view_redraw_bottom(view);
- view_screenline_begin(cursor);
+ view_screenline_begin(sel);
}
- return cursor->pos;
+ return sel->pos;
}
size_t view_scroll_page_down(View *view) {
view_scroll_down(view, view->height);
- return view_screenline_begin(view->cursor);
+ return view_screenline_begin(view->selection);
}
size_t view_scroll_halfpage_up(View *view) {
- Cursor *cursor = view->cursor;
+ Selection *sel = view->selection;
if (view->start == 0) {
view_cursor_to(view, 0);
} else {
view_cursor_to(view, view->start-1);
view_redraw_center(view);
- view_screenline_begin(cursor);
+ view_screenline_begin(sel);
}
- return cursor->pos;
+ return sel->pos;
}
size_t view_scroll_halfpage_down(View *view) {
@@ -712,101 +709,101 @@ size_t view_scroll_halfpage_down(View *view) {
size_t pos = view_scroll_down(view, view->height/2);
if (pos < text_size(view->text))
view_cursor_to(view, end);
- return view->cursor->pos;
+ return view->selection->pos;
}
size_t view_scroll_down(View *view, int lines) {
- Cursor *cursor = view->cursor;
+ Selection *sel = view->selection;
if (view_viewport_down(view, lines)) {
- Line *line = cursor->line > view->topline ? cursor->line : view->topline;
- cursor_set(cursor, line, cursor->col);
+ Line *line = sel->line > view->topline ? sel->line : view->topline;
+ cursor_set(sel, line, sel->col);
} else {
view_cursor_to(view, text_size(view->text));
}
- return cursor->pos;
+ return sel->pos;
}
-size_t view_line_up(Cursor *cursor) {
- View *view = cursor->view;
- int lastcol = cursor->lastcol;
+size_t view_line_up(Selection *sel) {
+ View *view = sel->view;
+ int lastcol = sel->lastcol;
if (!lastcol)
- lastcol = cursor->col;
- size_t pos = text_line_up(cursor->view->text, cursor->pos);
- bool offscreen = view->cursor == cursor && pos < view->start;
- view_cursors_to(cursor, pos);
+ lastcol = sel->col;
+ size_t pos = text_line_up(sel->view->text, sel->pos);
+ bool offscreen = view->selection == sel && pos < view->start;
+ view_cursors_to(sel, pos);
if (offscreen)
view_redraw_top(view);
- if (cursor->line)
- cursor_set(cursor, cursor->line, lastcol);
- cursor->lastcol = lastcol;
- return cursor->pos;
+ if (sel->line)
+ cursor_set(sel, sel->line, lastcol);
+ sel->lastcol = lastcol;
+ return sel->pos;
}
-size_t view_line_down(Cursor *cursor) {
- View *view = cursor->view;
- int lastcol = cursor->lastcol;
+size_t view_line_down(Selection *sel) {
+ View *view = sel->view;
+ int lastcol = sel->lastcol;
if (!lastcol)
- lastcol = cursor->col;
- size_t pos = text_line_down(cursor->view->text, cursor->pos);
- bool offscreen = view->cursor == cursor && pos > view->end;
- view_cursors_to(cursor, pos);
+ lastcol = sel->col;
+ size_t pos = text_line_down(sel->view->text, sel->pos);
+ bool offscreen = view->selection == sel && pos > view->end;
+ view_cursors_to(sel, pos);
if (offscreen)
view_redraw_bottom(view);
- if (cursor->line)
- cursor_set(cursor, cursor->line, lastcol);
- cursor->lastcol = lastcol;
- return cursor->pos;
+ if (sel->line)
+ cursor_set(sel, sel->line, lastcol);
+ sel->lastcol = lastcol;
+ return sel->pos;
}
-size_t view_screenline_up(Cursor *cursor) {
- if (!cursor->line)
- return view_line_up(cursor);
- int lastcol = cursor->lastcol;
+size_t view_screenline_up(Selection *sel) {
+ if (!sel->line)
+ return view_line_up(sel);
+ int lastcol = sel->lastcol;
if (!lastcol)
- lastcol = cursor->col;
- if (!cursor->line->prev)
- view_scroll_up(cursor->view, 1);
- if (cursor->line->prev)
- cursor_set(cursor, cursor->line->prev, lastcol);
- cursor->lastcol = lastcol;
- return cursor->pos;
-}
-
-size_t view_screenline_down(Cursor *cursor) {
- if (!cursor->line)
- return view_line_down(cursor);
- int lastcol = cursor->lastcol;
+ lastcol = sel->col;
+ if (!sel->line->prev)
+ view_scroll_up(sel->view, 1);
+ if (sel->line->prev)
+ cursor_set(sel, sel->line->prev, lastcol);
+ sel->lastcol = lastcol;
+ return sel->pos;
+}
+
+size_t view_screenline_down(Selection *sel) {
+ if (!sel->line)
+ return view_line_down(sel);
+ int lastcol = sel->lastcol;
if (!lastcol)
- lastcol = cursor->col;
- if (!cursor->line->next && cursor->line == cursor->view->bottomline)
- view_scroll_down(cursor->view, 1);
- if (cursor->line->next)
- cursor_set(cursor, cursor->line->next, lastcol);
- cursor->lastcol = lastcol;
- return cursor->pos;
+ lastcol = sel->col;
+ if (!sel->line->next && sel->line == sel->view->bottomline)
+ view_scroll_down(sel->view, 1);
+ if (sel->line->next)
+ cursor_set(sel, sel->line->next, lastcol);
+ sel->lastcol = lastcol;
+ return sel->pos;
}
-size_t view_screenline_begin(Cursor *cursor) {
- if (!cursor->line)
- return cursor->pos;
- return cursor_set(cursor, cursor->line, 0);
+size_t view_screenline_begin(Selection *sel) {
+ if (!sel->line)
+ return sel->pos;
+ return cursor_set(sel, sel->line, 0);
}
-size_t view_screenline_middle(Cursor *cursor) {
- if (!cursor->line)
- return cursor->pos;
- return cursor_set(cursor, cursor->line, cursor->line->width / 2);
+size_t view_screenline_middle(Selection *sel) {
+ if (!sel->line)
+ return sel->pos;
+ return cursor_set(sel, sel->line, sel->line->width / 2);
}
-size_t view_screenline_end(Cursor *cursor) {
- if (!cursor->line)
- return cursor->pos;
- int col = cursor->line->width - 1;
- return cursor_set(cursor, cursor->line, col >= 0 ? col : 0);
+size_t view_screenline_end(Selection *sel) {
+ if (!sel->line)
+ return sel->pos;
+ int col = sel->line->width - 1;
+ return cursor_set(sel, sel->line, col >= 0 ? col : 0);
}
size_t view_cursor_get(View *view) {
- return view_cursors_pos(view->cursor);
+ return view_cursors_pos(view->selection);
}
Line *view_lines_first(View *view) {
@@ -817,12 +814,12 @@ Line *view_lines_last(View *view) {
return view->lastline;
}
-Line *view_cursors_line_get(Cursor *c) {
- return c->line;
+Line *view_cursors_line_get(Selection *sel) {
+ return sel->line;
}
void view_scroll_to(View *view, size_t pos) {
- view_cursors_scroll_to(view->cursor, pos);
+ view_cursors_scroll_to(view->selection, pos);
}
void view_options_set(View *view, enum UiOption options) {
@@ -867,22 +864,22 @@ size_t view_screenline_goto(View *view, int n) {
return pos;
}
-static Cursor *cursors_new(View *view, size_t pos, bool force) {
- Cursor *c = calloc(1, sizeof(*c));
- if (!c)
+static Selection *selections_new(View *view, size_t pos, bool force) {
+ Selection *s = calloc(1, sizeof(*s));
+ if (!s)
return NULL;
- c->view = view;
- c->generation = view->cursor_generation;
- if (!view->cursors) {
- view->cursor = c;
- view->cursor_latest = c;
- view->cursors = c;
- view->cursor_count = 1;
- return c;
+ s->view = view;
+ s->generation = view->selection_generation;
+ if (!view->selections) {
+ view->selection = s;
+ view->selection_latest = s;
+ view->selections = s;
+ view->selection_count = 1;
+ return s;
}
- Cursor *prev = NULL, *next = NULL;
- Cursor *latest = view->cursor_latest ? view->cursor_latest : view->cursor;
+ Selection *prev = NULL, *next = NULL;
+ Selection *latest = view->selection_latest ? view->selection_latest : view->selection;
size_t cur = view_cursors_pos(latest);
if (pos == cur) {
prev = latest;
@@ -906,51 +903,51 @@ static Cursor *cursors_new(View *view, size_t pos, bool force) {
if (pos == cur && !force)
goto err;
- for (Cursor *after = next; after; after = after->next)
+ for (Selection *after = next; after; after = after->next)
after->number++;
- c->prev = prev;
- c->next = next;
+ s->prev = prev;
+ s->next = next;
if (next)
- next->prev = c;
+ next->prev = s;
if (prev) {
- prev->next = c;
- c->number = prev->number + 1;
+ prev->next = s;
+ s->number = prev->number + 1;
} else {
- view->cursors = c;
+ view->selections = s;
}
- view->cursor_latest = c;
- view->cursor_count++;
- view_selections_dispose(view->cursor_dead);
- view_cursors_to(c, pos);
- return c;
+ view->selection_latest = s;
+ view->selection_count++;
+ view_selections_dispose(view->selection_dead);
+ view_cursors_to(s, pos);
+ return s;
err:
- free(c);
+ free(s);
return NULL;
}
-Cursor *view_selections_new(View *view, size_t pos) {
- return cursors_new(view, pos, false);
+Selection *view_selections_new(View *view, size_t pos) {
+ return selections_new(view, pos, false);
}
-Cursor *view_selections_new_force(View *view, size_t pos) {
- return cursors_new(view, pos, true);
+Selection *view_selections_new_force(View *view, size_t pos) {
+ return selections_new(view, pos, true);
}
int view_selections_count(View *view) {
- return view->cursor_count;
+ return view->selection_count;
}
-int view_selections_number(Cursor *c) {
- return c->number;
+int view_selections_number(Selection *sel) {
+ return sel->number;
}
int view_selections_column_count(View *view) {
Text *txt = view->text;
int cpl_max = 0, cpl = 0; /* cursors per line */
size_t line_prev = 0;
- for (Cursor *c = view->cursors; c; c = c->next) {
- size_t pos = view_cursors_pos(c);
+ for (Selection *sel = view->selections; sel; sel = sel->next) {
+ size_t pos = view_cursors_pos(sel);
size_t line = text_lineno_by_pos(txt, pos);
if (line == line_prev)
cpl++;
@@ -963,20 +960,20 @@ int view_selections_column_count(View *view) {
return cpl_max;
}
-static Cursor *cursors_column_next(View *view, Cursor *c, int column) {
+static Selection *selections_column_next(View *view, Selection *sel, int column) {
size_t line_cur = 0;
int column_cur = 0;
Text *txt = view->text;
- if (c) {
- size_t pos = view_cursors_pos(c);
+ if (sel) {
+ size_t pos = view_cursors_pos(sel);
line_cur = text_lineno_by_pos(txt, pos);
column_cur = INT_MIN;
} else {
- c = view->cursors;
+ sel = view->selections;
}
- for (; c; c = c->next) {
- size_t pos = view_cursors_pos(c);
+ for (; sel; sel = sel->next) {
+ size_t pos = view_cursors_pos(sel);
size_t line = text_lineno_by_pos(txt, pos);
if (line != line_cur) {
line_cur = line;
@@ -985,147 +982,147 @@ static Cursor *cursors_column_next(View *view, Cursor *c, int column) {
column_cur++;
}
if (column == column_cur)
- return c;
+ return sel;
}
return NULL;
}
-Cursor *view_selections_column(View *view, int column) {
- return cursors_column_next(view, NULL, column);
+Selection *view_selections_column(View *view, int column) {
+ return selections_column_next(view, NULL, column);
}
-Cursor *view_selections_column_next(Cursor *c, int column) {
- return cursors_column_next(c->view, c, column);
+Selection *view_selections_column_next(Selection *sel, int column) {
+ return selections_column_next(sel->view, sel, column);
}
-static void view_cursors_free(Cursor *c) {
- if (!c)
+static void selection_free(Selection *s) {
+ if (!s)
return;
- for (Cursor *after = c->next; after; after = after->next)
+ for (Selection *after = s->next; after; after = after->next)
after->number--;
- if (c->prev)
- c->prev->next = c->next;
- if (c->next)
- c->next->prev = c->prev;
- if (c->view->cursors == c)
- c->view->cursors = c->next;
- if (c->view->cursor == c)
- c->view->cursor = c->next ? c->next : c->prev;
- if (c->view->cursor_dead == c)
- c->view->cursor_dead = NULL;
- if (c->view->cursor_latest == c)
- c->view->cursor_latest = c->prev ? c->prev : c->next;
- c->view->cursor_count--;
- free(c);
-}
-
-bool view_selections_dispose(Cursor *c) {
- if (!c)
+ if (s->prev)
+ s->prev->next = s->next;
+ if (s->next)
+ s->next->prev = s->prev;
+ if (s->view->selections == s)
+ s->view->selections = s->next;
+ if (s->view->selection == s)
+ s->view->selection = s->next ? s->next : s->prev;
+ if (s->view->selection_dead == s)
+ s->view->selection_dead = NULL;
+ if (s->view->selection_latest == s)
+ s->view->selection_latest = s->prev ? s->prev : s->next;
+ s->view->selection_count--;
+ free(s);
+}
+
+bool view_selections_dispose(Selection *sel) {
+ if (!sel)
return true;
- View *view = c->view;
- if (!view->cursors || !view->cursors->next)
+ View *view = sel->view;
+ if (!view->selections || !view->selections->next)
return false;
- view_cursors_free(c);
- view_selections_primary_set(view->cursor);
+ selection_free(sel);
+ view_selections_primary_set(view->selection);
return true;
}
-bool view_selections_dispose_force(Cursor *c) {
- if (view_selections_dispose(c))
+bool view_selections_dispose_force(Selection *sel) {
+ if (view_selections_dispose(sel))
return true;
- View *view = c->view;
- if (view->cursor_dead)
+ View *view = sel->view;
+ if (view->selection_dead)
return false;
- view_selection_clear(c);
- view->cursor_dead = c;
+ view_selection_clear(sel);
+ view->selection_dead = sel;
return true;
}
-Cursor *view_selection_disposed(View *view) {
- Cursor *c = view->cursor_dead;
- view->cursor_dead = NULL;
- return c;
+Selection *view_selection_disposed(View *view) {
+ Selection *sel = view->selection_dead;
+ view->selection_dead = NULL;
+ return sel;
}
-Cursor *view_selections(View *view) {
- view->cursor_generation++;
- return view->cursors;
+Selection *view_selections(View *view) {
+ view->selection_generation++;
+ return view->selections;
}
-Cursor *view_selections_primary_get(View *view) {
- view->cursor_generation++;
- return view->cursor;
+Selection *view_selections_primary_get(View *view) {
+ view->selection_generation++;
+ return view->selection;
}
-void view_selections_primary_set(Cursor *c) {
- if (!c)
+void view_selections_primary_set(Selection *s) {
+ if (!s)
return;
- c->view->cursor = c;
+ s->view->selection = s;
}
-Cursor *view_selections_prev(Cursor *c) {
- View *view = c->view;
- for (c = c->prev; c; c = c->prev) {
- if (c->generation != view->cursor_generation)
- return c;
+Selection *view_selections_prev(Selection *s) {
+ View *view = s->view;
+ for (s = s->prev; s; s = s->prev) {
+ if (s->generation != view->selection_generation)
+ return s;
}
- view->cursor_generation++;
+ view->selection_generation++;
return NULL;
}
-Cursor *view_selections_next(Cursor *c) {
- View *view = c->view;
- for (c = c->next; c; c = c->next) {
- if (c->generation != view->cursor_generation)
- return c;
+Selection *view_selections_next(Selection *s) {
+ View *view = s->view;
+ for (s = s->next; s; s = s->next) {
+ if (s->generation != view->selection_generation)
+ return s;
}
- view->cursor_generation++;
+ view->selection_generation++;
return NULL;
}
-size_t view_cursors_pos(Cursor *c) {
- return text_mark_get(c->view->text, c->cursor);
+size_t view_cursors_pos(Selection *s) {
+ return text_mark_get(s->view->text, s->cursor);
}
-size_t view_cursors_line(Cursor *c) {
- size_t pos = view_cursors_pos(c);
- return text_lineno_by_pos(c->view->text, pos);
+size_t view_cursors_line(Selection *s) {
+ size_t pos = view_cursors_pos(s);
+ return text_lineno_by_pos(s->view->text, pos);
}
-size_t view_cursors_col(Cursor *c) {
- size_t pos = view_cursors_pos(c);
- return text_line_char_get(c->view->text, pos) + 1;
+size_t view_cursors_col(Selection *s) {
+ size_t pos = view_cursors_pos(s);
+ return text_line_char_get(s->view->text, pos) + 1;
}
-int view_cursors_cell_get(Cursor *c) {
- return c->line ? c->col : -1;
+int view_cursors_cell_get(Selection *s) {
+ return s->line ? s->col : -1;
}
-int view_cursors_cell_set(Cursor *c, int cell) {
- if (!c->line || cell < 0)
+int view_cursors_cell_set(Selection *s, int cell) {
+ if (!s->line || cell < 0)
return -1;
- cursor_set(c, c->line, cell);
- return c->col;
+ cursor_set(s, s->line, cell);
+ return s->col;
}
-void view_cursors_scroll_to(Cursor *c, size_t pos) {
- View *view = c->view;
- if (view->cursor == c) {
+void view_cursors_scroll_to(Selection *s, size_t pos) {
+ View *view = s->view;
+ if (view->selection == s) {
view_draw(view);
while (pos < view->start && view_viewport_up(view, 1));
while (pos > view->end && view_viewport_down(view, 1));
}
- view_cursors_to(c, pos);
+ view_cursors_to(s, pos);
}
-void view_cursors_to(Cursor *c, size_t pos) {
- View *view = c->view;
+void view_cursors_to(Selection *s, size_t pos) {
+ View *view = s->view;
if (pos == EPOS)
return;
size_t size = text_size(view->text);
if (pos > size)
pos = size;
- if (c->view->cursor == c) {
+ if (s->view->selection == s) {
/* make sure we redraw changes to the very first character of the window */
if (view->start == pos)
view->start_last = 0;
@@ -1151,27 +1148,27 @@ void view_cursors_to(Cursor *c, size_t pos) {
}
}
- cursor_to(c, pos);
+ cursor_to(s, pos);
}
-void view_cursors_place(Cursor *c, size_t line, size_t col) {
- Text *txt = c->view->text;
+void view_cursors_place(Selection *s, size_t line, size_t col) {
+ Text *txt = s->view->text;
size_t pos = text_pos_by_lineno(txt, line);
pos = text_line_char_set(txt, pos, col > 0 ? col-1 : col);
- view_cursors_to(c, pos);
+ view_cursors_to(s, pos);
}
-void view_selections_anchor(Cursor *c) {
- c->anchored = true;
+void view_selections_anchor(Selection *s) {
+ s->anchored = true;
}
-void view_selection_clear(Cursor *c) {
- c->anchored = false;
- c->anchor = c->cursor;
- c->view->need_update = true;
+void view_selection_clear(Selection *s) {
+ s->anchored = false;
+ s->anchor = s->cursor;
+ s->view->need_update = true;
}
-void view_selections_flip(Cursor *s) {
+void view_selections_flip(Selection *s) {
Mark temp = s->anchor;
s->anchor = s->cursor;
s->cursor = temp;
@@ -1183,22 +1180,22 @@ bool view_selections_anchored(Selection *s) {
}
void view_selections_clear_all(View *view) {
- for (Cursor *c = view->cursors; c; c = c->next)
- view_selection_clear(c);
+ for (Selection *s = view->selections; s; s = s->next)
+ view_selection_clear(s);
view_draw(view);
}
void view_selections_dispose_all(View *view) {
- for (Cursor *c = view->cursors, *next; c; c = next) {
- next = c->next;
- if (c != view->cursor)
- view_cursors_free(c);
+ for (Selection *s = view->selections, *next; s; s = next) {
+ next = s->next;
+ if (s != view->selection)
+ selection_free(s);
}
view_draw(view);
}
Filerange view_selection_get(View *view) {
- return view_selections_get(view->cursor);
+ return view_selections_get(view->selection);
}
Filerange view_selections_get(Selection *s) {
diff --git a/view.h b/view.h
index 2a3f15c..e5f4c7f 100644
--- a/view.h
+++ b/view.h
@@ -5,8 +5,7 @@
#include <stdbool.h>
typedef struct View View;
-typedef struct Cursor Cursor;
-typedef Cursor Selection;
+typedef struct Selection Selection;
#include "text.h"
#include "ui.h"
@@ -104,7 +103,7 @@ bool view_update(View*);
* .. warning:: Fails if position is already covered by a selection.
* @endrst
*/
-Cursor *view_selections_new(View*, size_t pos);
+Selection *view_selections_new(View*, size_t pos);
/**
* Create a new selection even if position is already covered by an
* existing selection.
@@ -113,14 +112,14 @@ Cursor *view_selections_new(View*, size_t pos);
* disposed.
* @endrst
*/
-Cursor *view_selections_new_force(View*, size_t pos);
+Selection *view_selections_new_force(View*, size_t pos);
/**
* Dispose an existing selection.
* @rst
* .. warning:: Not applicaple for the last existing selection.
* @endrst
*/
-bool view_selections_dispose(Cursor*);
+bool view_selections_dispose(Selection*);
/**
* Forcefully dispose an existing selection.
*
@@ -128,14 +127,14 @@ bool view_selections_dispose(Cursor*);
* marked for destruction. As soon as a new selection is created this one
* will be disposed.
*/
-bool view_selections_dispose_force(Cursor*);
+bool view_selections_dispose_force(Selection*);
/**
* Query state of primary selection.
*
* If the primary selection was marked for destruction, return it and
* clear descruction flag.
*/
-Cursor *view_selection_disposed(View*);
+Selection *view_selection_disposed(View*);
/** Dispose all but the primary selection. */
void view_selections_dispose_all(View*);
/**
@@ -143,14 +142,14 @@ void view_selections_dispose_all(View*);
* @defgroup view_navigate
* @{
*/
-Cursor *view_selections_primary_get(View*);
-void view_selections_primary_set(Cursor*);
+Selection *view_selections_primary_get(View*);
+void view_selections_primary_set(Selection*);
/** Get first selection. */
-Cursor *view_selections(View*);
+Selection *view_selections(View*);
/** Get immediate predecessor of selection. */
-Cursor *view_selections_prev(Cursor*);
+Selection *view_selections_prev(Selection*);
/** Get immediate successor of selection. */
-Cursor *view_selections_next(Cursor*);
+Selection *view_selections_next(Selection*);
/**
* Get number of existing selections.
* @rst
@@ -166,35 +165,35 @@ int view_selections_count(View*);
* to remain the same.
* @endrst
*/
-int view_selections_number(Cursor*);
+int view_selections_number(Selection*);
/** Get maximal number of selections on a single line. */
int view_selections_column_count(View*);
/**
* Starting from the start of the text, get the `column`-th selection on a line.
* @param column The zero based column index.
*/
-Cursor *view_selections_column(View*, int column);
+Selection *view_selections_column(View*, int column);
/**
* Get the next `column`-th selection on a line.
* @param column The zero based column index.
*/
-Cursor *view_selections_column_next(Cursor*, int column);
+Selection *view_selections_column_next(Selection*, int column);
/**
* @}
* @defgroup view_cover
* @{
*/
/** Get an inclusive range of the selection cover. */
-Filerange view_selections_get(Cursor*);
+Filerange view_selections_get(Selection*);
/** Set selection cover. Updates both cursor and anchor. */
-void view_selections_set(Cursor*, const Filerange*);
+void view_selections_set(Selection*, const Filerange*);
/**
* Reduce selection to character currently covered by the cursor.
* @rst
* .. note:: Sets selection to non-anchored mode.
* @endrst
*/
-void view_selection_clear(Cursor*);
+void view_selection_clear(Selection*);
/** Reduce *all* currently active selections. */
void view_selections_clear_all(View*);
/**
@@ -203,7 +202,7 @@ void view_selections_clear_all(View*);
* .. note:: Has no effect on singleton selections.
* @endrst
*/
-void view_selections_flip(Cursor*);
+void view_selections_flip(Selection*);
/**
* @}
* @defgroup view_anchor
@@ -213,9 +212,9 @@ void view_selections_flip(Cursor*);
* Anchor selection.
* Further updates will only update the cursor, the anchor will remain fixed.
*/
-void view_selections_anchor(Cursor*);
+void view_selections_anchor(Selection*);
/** Check whether selection is anchored. */
-bool view_selections_anchored(Cursor*);
+bool view_selections_anchored(Selection*);
/** Get position of selection cursor. */
/**
* @}
@@ -223,9 +222,9 @@ bool view_selections_anchored(Cursor*);
* @{
*/
/** Get position of selection cursor. */
-size_t view_cursors_pos(Cursor*);
+size_t view_cursors_pos(Selection*);
/** Get 1-based line number of selection cursor. */
-size_t view_cursors_line(Cursor*);
+size_t view_cursors_line(Selection*);
/**
* Get 1-based column of selection cursor.
* @rst
@@ -233,21 +232,21 @@ size_t view_cursors_line(Cursor*);
* position.
* @endrst
*/
-size_t view_cursors_col(Cursor*);
+size_t view_cursors_col(Selection*);
/**
* Get screen line of selection cursor.
* @rst
* .. warning: Is `NULL` for non-visible selections.
* @endrst
*/
-Line *view_cursors_line_get(Cursor*);
+Line *view_cursors_line_get(Selection*);
/**
* Get zero based index of screen cell on which selection cursor currently resides.
* @rst
* .. warning:: Returns `-1` if the selection cursor is currently not visible.
* @endrst
*/
-int view_cursors_cell_get(Cursor*);
+int view_cursors_cell_get(Selection*);
/**
* @}
* @defgroup view_place
@@ -262,7 +261,7 @@ int view_cursors_cell_get(Cursor*);
* cursor will be changed while the anchor remains fixed.
* @endrst
*/
-void view_cursors_to(Cursor*, size_t pos);
+void view_cursors_to(Selection*, size_t pos);
/**
* Adjusts window viewport until the requested position becomes visible.
* @rst
@@ -272,7 +271,7 @@ void view_cursors_to(Cursor*, size_t pos);
* short distances between current cursor position and destination.
* @endrst
*/
-void view_cursors_scroll_to(Cursor*, size_t pos);
+void view_cursors_scroll_to(Selection*, size_t pos);
/**
* Place cursor on given (line, column) pair.
* @param line the 1-based line number
@@ -282,26 +281,26 @@ void view_cursors_scroll_to(Cursor*, size_t pos);
* `view_selection_to`.
* @endrst
*/
-void view_cursors_place(Cursor*, size_t line, size_t col);
+void view_cursors_place(Selection*, size_t line, size_t col);
/**
* Place selection cursor on zero based window cell index.
* @rst
* .. warning:: Fails if the selection cursor is currently not visible.
* @endrst
*/
-int view_cursors_cell_set(Cursor*, int cell);
+int view_cursors_cell_set(Selection*, int cell);
/**
* @}
* @defgroup view_motions
* @{
*/
-size_t view_line_down(Cursor*);
-size_t view_line_up(Cursor*);
-size_t view_screenline_down(Cursor*);
-size_t view_screenline_up(Cursor*);
-size_t view_screenline_begin(Cursor*);
-size_t view_screenline_middle(Cursor*);
-size_t view_screenline_end(Cursor*);
+size_t view_line_down(Selection*);
+size_t view_line_up(Selection*);
+size_t view_screenline_down(Selection*);
+size_t view_screenline_up(Selection*);
+size_t view_screenline_begin(Selection*);
+size_t view_screenline_middle(Selection*);
+size_t view_screenline_end(Selection*);
/**
* @}
* @defgroup view_primary
diff --git a/vis-cmds.c b/vis-cmds.c
index ec70231..5c3925b 100644
--- a/vis-cmds.c
+++ b/vis-cmds.c
@@ -120,9 +120,9 @@ bool vis_option_unregister(Vis *vis, const char *name) {
return true;
}
-static bool cmd_user(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_user(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
CmdUser *user = map_get(vis->usercmds, argv[0]);
- return user && user->func(vis, win, user->data, cmd->flags == '!', argv, cur, range);
+ return user && user->func(vis, win, user->data, cmd->flags == '!', argv, sel, range);
}
static void windows_arrange(Vis *vis, enum UiLayout layout) {
@@ -155,7 +155,7 @@ static bool parse_bool(const char *s, bool *outval) {
return false;
}
-static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!argv[1] || !argv[1][0] || argv[3]) {
vis_info_show(vis, "Expecting: set option [value]");
@@ -405,7 +405,7 @@ static bool openfiles(Vis *vis, const char **files) {
return true;
}
-static bool cmd_open(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_open(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!argv[1])
return vis_window_new(vis, NULL);
return openfiles(vis, &argv[1]);
@@ -415,7 +415,7 @@ static void info_unsaved_changes(Vis *vis) {
vis_info_show(vis, "No write since last change (add ! to override)");
}
-static bool cmd_edit(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_edit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (argv[2]) {
vis_info_show(vis, "Only 1 filename allowed");
return false;
@@ -445,7 +445,7 @@ static bool cmd_edit(Vis *vis, Win *win, Command *cmd, const char *argv[], Curso
return vis->win != oldwin;
}
-static bool cmd_read(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_read(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
bool ret = false;
const size_t first_file = 3;
const char *args[MAX_ARGV] = { argv[0], "cat", "--" };
@@ -456,7 +456,7 @@ static bool cmd_read(Vis *vis, Win *win, Command *cmd, const char *argv[], Curso
goto err;
}
args[LENGTH(args)-1] = NULL;
- ret = cmd_pipein(vis, win, cmd, args, cur, range);
+ ret = cmd_pipein(vis, win, cmd, args, sel, range);
err:
for (size_t i = first_file; i < LENGTH(args); i++)
free((char*)args[i]);
@@ -471,7 +471,7 @@ static bool has_windows(Vis *vis) {
return false;
}
-static bool cmd_quit(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_quit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (cmd->flags != '!' && !vis_window_closable(win)) {
info_unsaved_changes(vis);
return false;
@@ -482,7 +482,7 @@ static bool cmd_quit(Vis *vis, Win *win, Command *cmd, const char *argv[], Curso
return true;
}
-static bool cmd_qall(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_qall(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
for (Win *next, *win = vis->windows; win; win = next) {
next = win->next;
if (!win->file->internal && (!text_modified(win->file->text) || cmd->flags == '!'))
@@ -497,7 +497,7 @@ static bool cmd_qall(Vis *vis, Win *win, Command *cmd, const char *argv[], Curso
}
}
-static bool cmd_split(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_split(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
enum UiOption options = view_options_get(win->view);
@@ -510,7 +510,7 @@ static bool cmd_split(Vis *vis, Win *win, Command *cmd, const char *argv[], Curs
return ret;
}
-static bool cmd_vsplit(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_vsplit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
enum UiOption options = view_options_get(win->view);
@@ -523,27 +523,27 @@ static bool cmd_vsplit(Vis *vis, Win *win, Command *cmd, const char *argv[], Cur
return ret;
}
-static bool cmd_new(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_new(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
windows_arrange(vis, UI_LAYOUT_HORIZONTAL);
return vis_window_new(vis, NULL);
}
-static bool cmd_vnew(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_vnew(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
windows_arrange(vis, UI_LAYOUT_VERTICAL);
return vis_window_new(vis, NULL);
}
-static bool cmd_wq(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_wq(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
File *file = win->file;
bool unmodified = file->fd == -1 && !file->name && !text_modified(file->text);
- if (unmodified || cmd_write(vis, win, cmd, argv, cur, range))
- return cmd_quit(vis, win, cmd, argv, cur, range);
+ if (unmodified || cmd_write(vis, win, cmd, argv, sel, range))
+ return cmd_quit(vis, win, cmd, argv, sel, range);
return false;
}
-static bool cmd_earlier_later(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_earlier_later(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!win)
return false;
Text *txt = win->file->text;
@@ -719,7 +719,7 @@ static void print_symbolic_keys(Vis *vis, Text *txt) {
}
}
-static bool cmd_help(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_help(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
if (!vis_window_new(vis, NULL))
return false;
@@ -816,7 +816,7 @@ static bool cmd_help(Vis *vis, Win *win, Command *cmd, const char *argv[], Curso
return true;
}
-static bool cmd_langmap(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_langmap(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
const char *nonlatin = argv[1];
const char *latin = argv[2];
bool mapped = true;
@@ -847,7 +847,7 @@ static bool cmd_langmap(Vis *vis, Win *win, Command *cmd, const char *argv[], Cu
return mapped;
}
-static bool cmd_map(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_map(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
bool mapped = false;
bool local = strstr(argv[0], "-") != NULL;
enum VisMode mode = vis_mode_from(vis, argv[1]);
@@ -882,7 +882,7 @@ err:
return mapped;
}
-static bool cmd_unmap(Vis *vis, Win *win, Command *cmd, const char *argv[], Cursor *cur, Filerange *range) {
+static bool cmd_unmap(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) {
bool unmapped = false;
bool local = strstr(argv[0], "-") != NULL;
enum VisMode mode = vis_mode_from(vis, argv[1]);
diff --git a/vis-core.h b/vis-core.h
index 1ffb980..d043207 100644
--- a/vis-core.h
+++ b/vis-core.h
@@ -72,7 +72,7 @@ typedef struct {
typedef struct { /* Motion implementation, takes a cursor postion and returns a new one */
/* TODO: merge types / use union to save space */
- size_t (*cur)(Cursor*);
+ size_t (*cur)(Selection*);
size_t (*txt)(Text*, size_t pos);
size_t (*file)(Vis*, File*, size_t pos);
size_t (*vis)(Vis*, Text*, size_t pos);
diff --git a/vis-lua.c b/vis-lua.c
index f70a356..d5cfa98 100644
--- a/vis-lua.c
+++ b/vis-lua.c
@@ -81,8 +81,8 @@ static void window_status_update(Vis *vis, Win *win) {
int cursor_count = view_selections_count(view);
if (cursor_count > 1) {
- Cursor *c = view_selections_primary_get(view);
- int cursor_number = view_selections_number(c) + 1;
+ Selection *s = view_selections_primary_get(view);
+ int cursor_number = view_selections_number(s) + 1;
snprintf(right_parts[right_count], sizeof(right_parts[right_count])-1,
"%d/%d", cursor_number, cursor_count);
right_count++;
@@ -100,9 +100,9 @@ static void window_status_update(Vis *vis, Win *win) {
right_count++;
if (!(options & UI_OPTION_LARGE_FILE)) {
- Cursor *cur = view_selections_primary_get(win->view);
- size_t line = view_cursors_line(cur);
- size_t col = view_cursors_col(cur);
+ Selection *sel = view_selections_primary_get(win->view);
+ size_t line = view_cursors_line(sel);
+ size_t col = view_cursors_col(sel);
if (col > UI_LARGE_FILE_LINE_SIZE) {
options |= UI_OPTION_LARGE_FILE;
view_options_set(win->view, options);
@@ -1192,7 +1192,7 @@ static int option_unregister(lua_State *L) {
return 1;
}
-static bool command_lua(Vis *vis, Win *win, void *data, bool force, const char *argv[], Cursor *cur, Filerange *range) {
+static bool command_lua(Vis *vis, Win *win, void *data, bool force, const char *argv[], Selection *sel, Filerange *range) {
lua_State *L = vis->lua;
if (!L || !func_ref_get(L, data))
return false;
@@ -1205,9 +1205,9 @@ static bool command_lua(Vis *vis, Win *win, void *data, bool force, const char *
lua_pushboolean(L, force);
if (!obj_ref_new(L, win, VIS_LUA_TYPE_WINDOW))
return false;
- if (!cur)
- cur = view_selections_primary_get(win->view);
- if (!obj_lightref_new(L, cur, VIS_LUA_TYPE_CURSOR))
+ if (!sel)
+ sel = view_selections_primary_get(win->view);
+ if (!obj_lightref_new(L, sel, VIS_LUA_TYPE_CURSOR))
return false;
pushrange(L, range);
if (pcall(vis, L, 5, 1) != 0)
@@ -1574,8 +1574,8 @@ static int window_index(lua_State *L) {
}
if (strcmp(key, "cursor") == 0) {
- Cursor *cur = view_selections_primary_get(win->view);
- obj_lightref_new(L, cur, VIS_LUA_TYPE_CURSOR);
+ Selection *sel = view_selections_primary_get(win->view);
+ obj_lightref_new(L, sel, VIS_LUA_TYPE_CURSOR);
return 1;
}
@@ -1589,13 +1589,13 @@ static int window_index(lua_State *L) {
}
static int window_cursors_iterator_next(lua_State *L) {
- Cursor **handle = lua_touserdata(L, lua_upvalueindex(1));
+ Selection **handle = lua_touserdata(L, lua_upvalueindex(1));
if (!*handle)
return 0;
- Cursor *cur = obj_lightref_new(L, *handle, VIS_LUA_TYPE_CURSOR);
- if (!cur)
+ Selection *sel = obj_lightref_new(L, *handle, VIS_LUA_TYPE_CURSOR);
+ if (!sel)
return 0;
- *handle = view_selections_next(cur);
+ *handle = view_selections_next(sel);
return 1;
}
@@ -1606,7 +1606,7 @@ static int window_cursors_iterator_next(lua_State *L) {
*/
static int window_cursors_iterator(lua_State *L) {
Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW);
- Cursor **handle = lua_newuserdata(L, sizeof *handle);
+ Selection **handle = lua_newuserdata(L, sizeof *handle);
*handle = view_selections(win->view);
lua_pushcclosure(L, window_cursors_iterator_next, 1);
return 1;
@@ -1730,9 +1730,9 @@ static int window_cursors_index(lua_State *L) {
size_t count = view_selections_count(view);
if (index == 0 || index > count)
goto err;
- for (Cursor *c = view_selections(view); c; c = view_selections_next(c)) {
+ for (Selection *s = view_selections(view); s; s = view_selections_next(s)) {
if (!--index) {
- obj_lightref_new(L, c, VIS_LUA_TYPE_CURSOR);
+ obj_lightref_new(L, s, VIS_LUA_TYPE_CURSOR);
return 1;
}
}
@@ -1835,8 +1835,8 @@ static const struct luaL_Reg window_cursors_funcs[] = {
* @tfield Range selection the selection or `nil` if not in visual mode
*/
static int window_cursor_index(lua_State *L) {
- Cursor *cur = obj_lightref_check(L, 1, VIS_LUA_TYPE_CURSOR);
- if (!cur) {
+ Selection *sel = obj_lightref_check(L, 1, VIS_LUA_TYPE_CURSOR);
+ if (!sel) {
lua_pushnil(L);
return 1;
}
@@ -1844,28 +1844,28 @@ static int window_cursor_index(lua_State *L) {
if (lua_isstring(L, 2)) {
const char *key = lua_tostring(L, 2);
if (strcmp(key, "pos") == 0) {
- pushpos(L, view_cursors_pos(cur));
+ pushpos(L, view_cursors_pos(sel));
return 1;
}
if (strcmp(key, "line") == 0) {
- lua_pushunsigned(L, view_cursors_line(cur));
+ lua_pushunsigned(L, view_cursors_line(sel));
return 1;
}
if (strcmp(key, "col") == 0) {
- lua_pushunsigned(L, view_cursors_col(cur));
+ lua_pushunsigned(L, view_cursors_col(sel));
return 1;
}
if (strcmp(key, "number") == 0) {
- lua_pushunsigned(L, view_selections_number(cur)+1);
+ lua_pushunsigned(L, view_selections_number(sel)+1);
return 1;
}
if (strcmp(key, "selection") == 0) {
- Filerange sel = view_selections_get(cur);
- pushrange(L, &sel);
+ Filerange range = view_selections_get(sel);
+ pushrange(L, &range);
return 1;
}
}
@@ -1874,23 +1874,23 @@ static int window_cursor_index(lua_State *L) {
}
static int window_cursor_newindex(lua_State *L) {
- Cursor *cur = obj_lightref_check(L, 1, VIS_LUA_TYPE_CURSOR);
- if (!cur)
+ Selection *sel = obj_lightref_check(L, 1, VIS_LUA_TYPE_CURSOR);
+ if (!sel)
return 0;
if (lua_isstring(L, 2)) {
const char *key = lua_tostring(L, 2);
if (strcmp(key, "pos") == 0) {
size_t pos = checkpos(L, 3);
- view_cursors_to(cur, pos);
+ view_cursors_to(sel, pos);
return 0;
}
if (strcmp(key, "selection") == 0) {
- Filerange sel = getrange(L, 3);
- if (text_range_valid(&sel))
- view_selections_set(cur, &sel);
+ Filerange range = getrange(L, 3);
+ if (text_range_valid(&range))
+ view_selections_set(sel, &range);
else
- view_selection_clear(cur);
+ view_selection_clear(sel);
return 0;
}
}
@@ -1904,11 +1904,11 @@ static int window_cursor_newindex(lua_State *L) {
* @tparam int col the 1-based column number
*/
static int window_cursor_to(lua_State *L) {
- Cursor *cur = obj_lightref_check(L, 1, VIS_LUA_TYPE_CURSOR);
- if (cur) {
+ Selection *sel = obj_lightref_check(L, 1, VIS_LUA_TYPE_CURSOR);
+ if (sel) {
size_t line = checkpos(L, 2);
size_t col = checkpos(L, 3);
- view_cursors_place(cur, line, col);
+ view_cursors_place(sel, line, col);
}
return 0;
}
diff --git a/vis-modes.c b/vis-modes.c
index c396b4a..6fd05b7 100644
--- a/vis-modes.c
+++ b/vis-modes.c
@@ -145,8 +145,8 @@ 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_selections(vis->win->view); c; c = view_selections_next(c)) {
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections(vis->win->view); s; s = view_selections_next(s)) {
+ size_t pos = view_cursors_pos(s);
size_t start = text_line_start(txt, pos);
size_t end = text_line_end(txt, pos);
if (start == pos && start == end) {
@@ -154,7 +154,7 @@ static void vis_mode_normal_enter(Vis *vis, Mode *old) {
size_t len = start - begin;
if (len) {
text_delete(txt, begin, len);
- view_cursors_to(c, pos-len);
+ view_cursors_to(s, pos-len);
}
}
}
@@ -185,15 +185,15 @@ 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_selections(vis->win->view); c; c = view_selections_next(c))
- view_selections_anchor(c);
+ for (Selection *s = view_selections(vis->win->view); s; s = view_selections_next(s))
+ view_selections_anchor(s);
}
}
static void vis_mode_visual_line_enter(Vis *vis, Mode *old) {
if (!old->visual) {
- for (Cursor *c = view_selections(vis->win->view); c; c = view_selections_next(c))
- view_selections_anchor(c);
+ for (Selection *s = view_selections(vis->win->view); s; s = view_selections_next(s))
+ view_selections_anchor(s);
}
if (!vis->action.op)
vis_motion(vis, VIS_MOVE_NOP);
diff --git a/vis-prompt.c b/vis-prompt.c
index 30334b7..0eea81f 100644
--- a/vis-prompt.c
+++ b/vis-prompt.c
@@ -169,8 +169,8 @@ void vis_prompt_show(Vis *vis, const char *title) {
window_selection_save(active);
Text *txt = prompt->file->text;
text_appendf(txt, "%s\n", title);
- Cursor *cursor = view_selections_primary_get(prompt->view);
- view_cursors_scroll_to(cursor, text_size(txt)-1);
+ Selection *sel = view_selections_primary_get(prompt->view);
+ view_cursors_scroll_to(sel, text_size(txt)-1);
prompt->parent = active;
prompt->parent_mode = vis->mode;
vis_window_mode_map(prompt, VIS_MODE_NORMAL, true, "<Enter>", &prompt_enter_binding);
diff --git a/vis-registers.c b/vis-registers.c
index 55aab11..aae7fdc 100644
--- a/vis-registers.c
+++ b/vis-registers.c
@@ -258,5 +258,5 @@ const RegisterDef vis_registers[] = {
[VIS_REG_SEARCH] = { '/', VIS_HELP("Last search pattern") },
[VIS_REG_COMMAND] = { ':', VIS_HELP("Last :-command") },
[VIS_REG_SHELL] = { '!', VIS_HELP("Last shell command given to either <, >, |, or !") },
- [VIS_REG_NUMBER] = { '#', VIS_HELP("Cursor number") },
+ [VIS_REG_NUMBER] = { '#', VIS_HELP("Register number") },
};
diff --git a/vis.c b/vis.c
index ff89afc..1ba6ff2 100644
--- a/vis.c
+++ b/vis.c
@@ -316,8 +316,8 @@ static void window_draw_cursorline(Win *win) {
int width = view_width_get(view);
CellStyle style = win->ui->style_get(win->ui, UI_STYLE_CURSOR_LINE);
- Cursor *cursor = view_selections_primary_get(view);
- size_t lineno = view_cursors_line_get(cursor)->lineno;
+ 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) {
if (l->lineno == lineno) {
for (int x = 0; x < width; x++) {
@@ -330,7 +330,7 @@ static void window_draw_cursorline(Win *win) {
}
}
-static void window_draw_selection(View *view, Cursor *cur, CellStyle *style) {
+static void window_draw_selection(View *view, Selection *cur, CellStyle *style) {
Filerange sel = view_selections_get(cur);
if (!text_range_valid(&sel))
return;
@@ -364,7 +364,7 @@ static void window_draw_selection(View *view, Cursor *cur, CellStyle *style) {
}
}
-static void window_draw_cursor_matching(Win *win, Cursor *cur, CellStyle *style) {
+static void window_draw_cursor_matching(Win *win, Selection *cur, CellStyle *style) {
if (win->vis->mode->visual)
return;
Line *line_match; int col_match;
@@ -383,7 +383,7 @@ static void window_draw_cursor_matching(Win *win, Cursor *cur, CellStyle *style)
}
}
-static void window_draw_cursor(Win *win, Cursor *cur, CellStyle *style, CellStyle *sel_style) {
+static void window_draw_cursor(Win *win, Selection *cur, CellStyle *style, CellStyle *sel_style) {
if (win->vis->win != win)
return;
Line *line = view_cursors_line_get(cur);
@@ -399,25 +399,25 @@ static void window_draw_cursors(Win *win) {
View *view = win->view;
Filerange viewport = view_viewport_get(view);
bool multiple_cursors = view_selections_count(view) > 1;
- Cursor *cursor = view_selections_primary_get(view);
+ Selection *sel = view_selections_primary_get(view);
CellStyle style_cursor = win->ui->style_get(win->ui, UI_STYLE_CURSOR);
CellStyle style_cursor_primary = win->ui->style_get(win->ui, UI_STYLE_CURSOR_PRIMARY);
CellStyle style_selection = win->ui->style_get(win->ui, UI_STYLE_SELECTION);
- for (Cursor *c = view_selections_prev(cursor); c; c = view_selections_prev(c)) {
- window_draw_selection(win->view, c, &style_selection);
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections_prev(sel); s; s = view_selections_prev(s)) {
+ window_draw_selection(win->view, s, &style_selection);
+ size_t pos = view_cursors_pos(s);
if (pos < viewport.start)
break;
- window_draw_cursor(win, c, &style_cursor, &style_selection);
+ window_draw_cursor(win, s, &style_cursor, &style_selection);
}
- 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_selections_next(cursor); c; c = view_selections_next(c)) {
- window_draw_selection(win->view, c, &style_selection);
- size_t pos = view_cursors_pos(c);
+ window_draw_selection(win->view, sel, &style_selection);
+ window_draw_cursor(win, sel, multiple_cursors ? &style_cursor_primary : &style_cursor, &style_selection);
+ for (Selection *s = view_selections_next(sel); s; s = view_selections_next(s)) {
+ window_draw_selection(win->view, s, &style_selection);
+ size_t pos = view_cursors_pos(s);
if (pos > viewport.end)
break;
- window_draw_cursor(win, c, &style_cursor, &style_selection);
+ window_draw_cursor(win, s, &style_cursor, &style_selection);
}
}
@@ -754,10 +754,10 @@ 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_selections(vis->win->view); c; c = view_selections_next(c)) {
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections(vis->win->view); s; s = view_selections_next(s)) {
+ size_t pos = view_cursors_pos(s);
vis_insert(vis, pos, data, len);
- view_cursors_scroll_to(c, pos + len);
+ view_cursors_scroll_to(s, pos + len);
}
}
@@ -773,10 +773,10 @@ 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_selections(vis->win->view); c; c = view_selections_next(c)) {
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections(vis->win->view); s; s = view_selections_next(s)) {
+ size_t pos = view_cursors_pos(s);
vis_replace(vis, pos, data, len);
- view_cursors_scroll_to(c, pos + len);
+ view_cursors_scroll_to(s, pos + len);
}
}
@@ -844,16 +844,16 @@ void vis_do(Vis *vis) {
if (a->op == &vis_operators[VIS_OP_PUT_AFTER] && multiple_cursors && vis_register_count(vis, reg) == 1)
reg_slot = 0;
- for (Cursor *cursor = view_selections(view), *next; cursor; cursor = next) {
+ for (Selection *sel = view_selections(view), *next; sel; sel = next) {
if (vis->interrupted)
break;
- next = view_selections_next(cursor);
+ next = view_selections_next(sel);
- size_t pos = view_cursors_pos(cursor);
+ size_t pos = view_cursors_pos(sel);
if (pos == EPOS) {
- if (!view_selections_dispose(cursor))
- view_cursors_to(cursor, 0);
+ if (!view_selections_dispose(sel))
+ view_cursors_to(sel, 0);
continue;
}
@@ -863,7 +863,7 @@ void vis_do(Vis *vis) {
.newpos = EPOS,
.range = text_range_empty(),
.reg = reg,
- .reg_slot = reg_slot == EPOS ? (size_t)view_selections_number(cursor) : reg_slot,
+ .reg_slot = reg_slot == EPOS ? (size_t)view_selections_number(sel) : reg_slot,
.linewise = linewise,
.arg = &a->arg,
.context = a->op ? a->op->context : NULL,
@@ -879,7 +879,7 @@ void vis_do(Vis *vis) {
if (a->movement->txt)
pos = a->movement->txt(txt, pos);
else if (a->movement->cur)
- pos = a->movement->cur(cursor);
+ pos = a->movement->cur(sel);
else if (a->movement->file)
pos = a->movement->file(vis, file, pos);
else if (a->movement->vis)
@@ -912,11 +912,11 @@ void vis_do(Vis *vis) {
if (!a->op) {
if (a->movement->type & CHARWISE)
- view_cursors_scroll_to(cursor, pos);
+ view_cursors_scroll_to(sel, pos);
else
- view_cursors_to(cursor, pos);
+ view_cursors_to(sel, pos);
if (vis->mode->visual)
- c.range = view_selections_get(cursor);
+ c.range = view_selections_get(sel);
if (a->movement->type & JUMP)
window_jumplist_add(win, pos);
else
@@ -928,7 +928,7 @@ void vis_do(Vis *vis) {
}
} else if (a->textobj) {
if (vis->mode->visual)
- c.range = view_selections_get(cursor);
+ c.range = view_selections_get(sel);
else
c.range.start = c.range.end = pos;
for (int i = 0; i < count; i++) {
@@ -964,7 +964,7 @@ void vis_do(Vis *vis) {
}
}
} else if (vis->mode->visual) {
- c.range = view_selections_get(cursor);
+ c.range = view_selections_get(sel);
if (!text_range_valid(&c.range))
c.range.start = c.range.end = pos;
}
@@ -972,16 +972,16 @@ void vis_do(Vis *vis) {
if (linewise && vis->mode != &vis_modes[VIS_MODE_VISUAL])
c.range = text_range_linewise(txt, &c.range);
if (vis->mode->visual)
- view_selections_set(cursor, &c.range);
+ view_selections_set(sel, &c.range);
if (a->op) {
size_t pos = a->op->func(vis, txt, &c);
if (pos == EPOS) {
- view_selections_dispose(cursor);
+ view_selections_dispose(sel);
} else if (pos <= text_size(txt)) {
if (vis->mode->visual)
- view_selections_save(cursor);
- view_cursors_to(cursor, pos);
+ view_selections_save(sel);
+ view_cursors_to(sel, pos);
}
}
}
@@ -1578,15 +1578,15 @@ void vis_insert_tab(Vis *vis) {
}
char spaces[9];
int tabwidth = MIN(vis->tabwidth, LENGTH(spaces) - 1);
- for (Cursor *c = view_selections(vis->win->view); c; c = view_selections_next(c)) {
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections(vis->win->view); s; s = view_selections_next(s)) {
+ size_t pos = view_cursors_pos(s);
int width = text_line_width_get(vis->win->file->text, pos);
int count = tabwidth - (width % tabwidth);
for (int i = 0; i < count; i++)
spaces[i] = ' ';
spaces[count] = '\0';
vis_insert(vis, pos, spaces, count);
- view_cursors_scroll_to(c, pos + count);
+ view_cursors_scroll_to(s, pos + count);
}
}
@@ -1633,16 +1633,16 @@ void vis_insert_nl(Vis *vis) {
Win *win = vis->win;
View *view = win->view;
Text *txt = win->file->text;
- for (Cursor *c = view_selections(view); c; c = view_selections_next(c)) {
- size_t pos = view_cursors_pos(c);
+ for (Selection *s = view_selections(view); s; s = view_selections_next(s)) {
+ size_t pos = view_cursors_pos(s);
size_t newpos = vis_text_insert_nl(vis, txt, pos);
/* This is a bit of a hack to fix cursor positioning when
* inserting a new line at the start of the view port.
* It has the effect of reseting the mark used by the view
* code to keep track of the start of the visible region.
*/
- view_cursors_to(c, pos);
- view_cursors_to(c, newpos);
+ view_cursors_to(s, pos);
+ view_cursors_to(s, newpos);
}
vis_window_invalidate(win);
}
diff --git a/vis.h b/vis.h
index b35458e..a4f1d46 100644
--- a/vis.h
+++ b/vis.h
@@ -789,7 +789,7 @@ bool vis_cmd(Vis*, const char *cmd);
/** Command handler function. */
typedef bool (VisCommandFunction)(Vis*, Win*, void *data, bool force,
- const char *argv[], Cursor*, Filerange*);
+ const char *argv[], Selection*, Filerange*);
/**
* Register new ``:``-command.
* @param name The command name.