Introduction
Introduction Statistics Contact Development Disclaimer Help
tvi: join command - neatvi - [fork] simple vi-type editor with UTF-8 support
git clone git://src.adamsgaard.dk/neatvi
Log
Files
Refs
README
---
commit 1dc67eff887a162e76d774b367ab3648e5876e17
parent e73bb547ae0e1e53e3841978ea84b3f855d3c805
Author: Ali Gholami Rudi <[email protected]>
Date: Thu, 7 May 2015 17:43:29 +0430
vi: join command
Diffstat:
M vi.c | 45 +++++++++++++++++++++++++++++…
1 file changed, 45 insertions(+), 0 deletions(-)
---
diff --git a/vi.c b/vi.c
t@@ -515,6 +515,47 @@ static void vc_put(int cmd, int cnt)
}
+static int join_spaces(char *prev, char *next)
+{
+ int prevlen = strlen(prev);
+ if (!prev[0])
+ return 0;
+ if (prev[prevlen - 1] == ' ' || next[0] == ')')
+ return 0;
+ return prev[prevlen - 1] == '.' ? 2 : 1;
+}
+
+static void vc_join(int arg)
+{
+ struct sbuf *sb;
+ int cnt = arg <= 1 ? 2 : arg;
+ int beg = xrow;
+ int end = xrow + cnt;
+ int off = 0;
+ int i;
+ if (!lbuf_get(xb, beg) || !lbuf_get(xb, end - 1))
+ return;
+ sb = sbuf_make();
+ for (i = beg; i < end; i++) {
+ char *ln = lbuf_get(xb, i);
+ char *lnend = strchr(ln, '\n');
+ int spaces;
+ if (i > beg)
+ while (ln[0] == ' ' || ln[0] == '\t')
+ ln++;
+ spaces = i > beg ? join_spaces(sbuf_buf(sb), ln) : 0;
+ off = uc_slen(sbuf_buf(sb));
+ while (spaces--)
+ sbuf_chr(sb, ' ');
+ sbuf_mem(sb, ln, lnend - ln);
+ }
+ sbuf_chr(sb, '\n');
+ lbuf_rm(xb, beg, end);
+ lbuf_put(xb, beg, sbuf_buf(sb));
+ xcol = ren_pos(sbuf_buf(sb), off);
+ sbuf_free(sb);
+}
+
static void vi(void)
{
int mark;
t@@ -587,6 +628,10 @@ static void vi(void)
vc_insert(c);
redraw = 1;
break;
+ case 'J':
+ vc_join(pre1);
+ redraw = 1;
+ break;
case 'm':
if ((mark = vi_read()) > 0 && isalpha(mark))
lbuf_mark(xb, mark, xrow);
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.