Introduction
Introduction Statistics Contact Development Disclaimer Help
tvi: mark columns - neatvi - [fork] simple vi-type editor with UTF-8 support
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit 680585a37f36abc36eb00a7bd1a98459c0628012
parent 901e0cd396e087f435fa96b51196d01d0f94ca18
Author: Ali Gholami Rudi <[email protected]>
Date: Tue, 2 Jun 2015 23:28:58 +0430
vi: mark columns
Diffstat:
M ex.c | 4 ++--
M lbuf.c | 15 +++++++++++----
M vi.c | 31 +++++++++++++++++++++++------…
M vi.h | 4 ++--
4 files changed, 38 insertions(+), 16 deletions(-)
---
diff --git a/ex.c b/ex.c
t@@ -118,7 +118,7 @@ static int ex_lineno(char *num)
if (num[0] == '+')
n = xrow + (num[1] ? ex_lineno(num + 1) : 1);
if (num[0] == '\'')
- n = lbuf_markpos(xb, num[1]);
+ lbuf_markpos(xb, num[1], &n, NULL);
if (num[0] == '/' && num[1])
n = ex_search(num);
if (num[0] == '?' && num[1])
t@@ -393,7 +393,7 @@ static void ec_mark(char *ec)
ex_loc(ec, loc);
if (ex_region(loc, &beg, &end))
return;
- lbuf_mark(xb, arg[0], end - 1);
+ lbuf_mark(xb, arg[0], end - 1, 0);
}
static char *readuntil(char **src, int delim)
diff --git a/lbuf.c b/lbuf.c
t@@ -16,7 +16,8 @@ struct lopt {
/* line buffers */
struct lbuf {
- int mark[32]; /* buffer marks */
+ int mark[32]; /* mark lines */
+ int mark_off[32]; /* mark line offsets */
struct lopt hist[128]; /* buffer history */
int undo; /* current index into hist[] */
int useq; /* current operation sequence */
t@@ -177,14 +178,20 @@ int lbuf_len(struct lbuf *lb)
return lb->ln_n;
}
-void lbuf_mark(struct lbuf *lbuf, int mark, int pos)
+void lbuf_mark(struct lbuf *lbuf, int mark, int pos, int off)
{
lbuf->mark[MARK(mark)] = pos;
+ lbuf->mark_off[MARK(mark)] = off;
}
-int lbuf_markpos(struct lbuf *lbuf, int mark)
+int lbuf_markpos(struct lbuf *lbuf, int mark, int *pos, int *off)
{
- return lbuf->mark[MARK(mark)];
+ if (lbuf->mark[MARK(mark)] < 0)
+ return 1;
+ *pos = lbuf->mark[MARK(mark)];
+ if (off)
+ *off = lbuf->mark_off[MARK(mark)];
+ return 0;
}
static struct lopt *lbuf_lopt(struct lbuf *lb, int i)
diff --git a/vi.c b/vi.c
t@@ -218,7 +218,7 @@ static int vi_motionln(int *row, int cmd)
{
int cnt = (vi_arg1 ? vi_arg1 : 1) * (vi_arg2 ? vi_arg2 : 1);
int c = vi_read();
- int mark;
+ int mark, mark_row, mark_off;
switch (c) {
case '\n':
case '+':
t@@ -231,11 +231,13 @@ static int vi_motionln(int *row, int cmd)
*row = MIN(*row + cnt - 1, lbuf_len(xb) - 1);
break;
case '\'':
- if ((mark = vi_read()) <= 0 || (!isalpha(mark) && mark != '\''…
+ if ((mark = vi_read()) <= 0)
+ return -1;
+ if (!islower(mark) && !strchr("'`", mark))
return -1;
- if (lbuf_markpos(xb, mark) < 0)
+ if (lbuf_markpos(xb, mark, &mark_row, &mark_off))
return -1;
- *row = lbuf_markpos(xb, mark);
+ *row = mark_row;
break;
case 'j':
*row = MIN(*row + cnt, lbuf_len(xb) - 1);
t@@ -303,6 +305,7 @@ static int vi_motion(int *row, int *off)
int cnt = (vi_arg1 ? vi_arg1 : 1) * (vi_arg2 ? vi_arg2 : 1);
char *ln = lbuf_get(xb, *row);
int dir = dir_context(ln ? ln : "");
+ int mark, mark_row, mark_off;
char *cs;
int mv;
int i;
t@@ -461,6 +464,16 @@ static int vi_motion(int *row, int *off)
if (vi_nextoff(xb, -1, row, off))
break;
break;
+ case '`':
+ if ((mark = vi_read()) <= 0)
+ return -1;
+ if (!islower(mark) && !strchr("'`", mark))
+ return -1;
+ if (lbuf_markpos(xb, mark, &mark_row, &mark_off))
+ return -1;
+ *row = mark_row;
+ *off = mark_off;
+ break;
default:
vi_back(mv);
return 0;
t@@ -958,8 +971,10 @@ static void vi(void)
vi_ybuf = vi_yankbuf();
mv = vi_motion(&nrow, &noff);
if (mv > 0) {
- if (strchr("\'GHML/?{}[]nN", mv))
- lbuf_mark(xb, '\'', xrow);
+ if (strchr("\'`GHML/?{}[]nN", mv)) {
+ lbuf_mark(xb, '\'', xrow, xoff);
+ lbuf_mark(xb, '`', xrow, xoff);
+ }
xrow = nrow;
if (noff < 0 && !strchr("jk", mv))
noff = lbuf_indents(xb, xrow);
t@@ -1052,8 +1067,8 @@ static void vi(void)
redraw = 1;
break;
case 'm':
- if ((mark = vi_read()) > 0 && isalpha(mark))
- lbuf_mark(xb, mark, xrow);
+ if ((mark = vi_read()) > 0 && islower(mark))
+ lbuf_mark(xb, mark, xrow, xoff);
break;
case 'p':
case 'P':
diff --git a/vi.h b/vi.h
t@@ -15,8 +15,8 @@ char *lbuf_cp(struct lbuf *lbuf, int beg, int end);
void lbuf_put(struct lbuf *lbuf, int pos, char *s);
char *lbuf_get(struct lbuf *lbuf, int pos);
int lbuf_len(struct lbuf *lbuf);
-void lbuf_mark(struct lbuf *lbuf, int mark, int pos);
-int lbuf_markpos(struct lbuf *lbuf, int mark);
+void lbuf_mark(struct lbuf *lbuf, int mark, int pos, int off);
+int lbuf_markpos(struct lbuf *lbuf, int mark, int *pos, int *off);
void lbuf_undo(struct lbuf *lbuf);
void lbuf_redo(struct lbuf *lbuf);
void lbuf_undomark(struct lbuf *lbuf);
You are viewing proxied material from mx1.adamsgaard.dk. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.