aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2014-09-04 22:22:39 +0200
committerMarc André Tanner <mat@brain-dump.org>2014-09-04 22:22:39 +0200
commit33812921a2294637e4635d5b8426fc47f69a05a5 (patch)
treefea0b77a032b80b0211fb9a7110ee01ef2aa3955
parent3bfd0792b7116eacd5f9c46070b6fee236d4b956 (diff)
downloadvis-33812921a2294637e4635d5b8426fc47f69a05a5.tar.gz
vis-33812921a2294637e4635d5b8426fc47f69a05a5.tar.xz
Implement movement to a given line
-rw-r--r--config.def.h12
-rw-r--r--main.c10
-rw-r--r--vis.c6
-rw-r--r--vis.h1
4 files changed, 11 insertions, 18 deletions
diff --git a/config.def.h b/config.def.h
index 190b1b4..1a5c3e3 100644
--- a/config.def.h
+++ b/config.def.h
@@ -92,6 +92,14 @@ static size_t till_left(const Arg *arg) {
return text_char_next(vis->win->text, to_left(arg));
}
+static size_t line(const Arg *arg) {
+ if (action.count == 0)
+ return text_size(vis->win->text);
+ size_t pos = text_pos_by_lineno(vis->win->text, action.count);
+ action.count = 0;
+ return pos;
+}
+
static Operator ops[] = {
[OP_DELETE] = { op_delete, false },
[OP_CHANGE] = { op_change, false },
@@ -106,6 +114,7 @@ enum {
MOVE_LINE_START,
MOVE_LINE_FINISH,
MOVE_LINE_END,
+ MOVE_LINE,
MOVE_CHAR_PREV,
MOVE_CHAR_NEXT,
MOVE_WORD_START_PREV,
@@ -134,6 +143,7 @@ static Movement moves[] = {
[MOVE_LINE_START] = { .txt = text_line_start, .type = LINEWISE },
[MOVE_LINE_FINISH] = { .txt = text_line_finish, .type = LINEWISE },
[MOVE_LINE_END] = { .txt = text_line_end, .type = LINEWISE },
+ [MOVE_LINE] = { .cmd = line, .type = LINEWISE },
[MOVE_CHAR_PREV] = { .win = window_char_prev },
[MOVE_CHAR_NEXT] = { .win = window_char_next },
[MOVE_WORD_START_PREV] = { .txt = text_word_start_prev, .type = CHARWISE },
@@ -454,7 +464,7 @@ static KeyBinding vis_movements[] = {
{ { NONE('(') }, movement, { .i = MOVE_SENTENCE_PREV } },
{ { NONE(')') }, movement, { .i = MOVE_SENTENCE_NEXT } },
{ { NONE('g'), NONE('g') }, movement, { .i = MOVE_FILE_BEGIN } },
- { { NONE('G') }, movement, { .i = MOVE_FILE_END } },
+ { { NONE('G') }, movement, { .i = MOVE_LINE } },
{ { NONE('f') }, movement_key, { .i = MOVE_RIGHT_TO } },
{ { NONE('F') }, movement_key, { .i = MOVE_LEFT_TO } },
{ { NONE('t') }, movement_key, { .i = MOVE_RIGHT_TILL } },
diff --git a/main.c b/main.c
index 68bcb0c..d1c0b07 100644
--- a/main.c
+++ b/main.c
@@ -21,8 +21,6 @@ int ESCDELAY;
static Key getkey(void);
static void cursor(const Arg *arg);
static void call(const Arg *arg);
-static void insert(const Arg *arg);
-static void line(const Arg *arg);
static void find_forward(const Arg *arg);
static void find_backward(const Arg *arg);
@@ -38,10 +36,6 @@ static void call(const Arg *arg) {
arg->f(vis);
}
-static void line(const Arg *arg) {
- vis_line_goto(vis, arg->i);
-}
-
static void find_forward(const Arg *arg) {
vis_search(vis, arg->s, 1);
}
@@ -50,10 +44,6 @@ static void find_backward(const Arg *arg) {
vis_search(vis, arg->s, -1);
}
-static void insert(const Arg *arg) {
- //vis_insert(vis, arg->s, strlen(arg->s));
-}
-
typedef struct Screen Screen;
static struct Screen {
int w, h;
diff --git a/vis.c b/vis.c
index 68928e8..c06f30c 100644
--- a/vis.c
+++ b/vis.c
@@ -42,12 +42,6 @@ void vis_statusbar_set(Vis *vis, vis_statusbar_t statusbar) {
vis->statusbar = statusbar;
}
-size_t vis_line_goto(Vis *vis, size_t lineno) {
- size_t pos = text_pos_by_lineno(vis->win->text, lineno);
- window_cursor_to(vis->win->win, pos);
- return pos;
-}
-
static void vis_search_forward(Vis *vis, Regex *regex) {
VisWin *win = vis->win;
int pos = window_cursor_get(win->win) + 1;
diff --git a/vis.h b/vis.h
index fec25f1..c3f81c3 100644
--- a/vis.h
+++ b/vis.h
@@ -175,7 +175,6 @@ bool vis_syntax_load(Vis*, Syntax *syntaxes, Color *colors);
void vis_syntax_unload(Vis*);
void vis_search(Vis *ed, const char *regex, int direction);
-size_t vis_line_goto(Vis *vis, size_t lineno);
bool vis_window_new(Vis *vis, const char *filename);
void vis_window_split(Vis *ed, const char *filename);