tled: word erase with ^W - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit f80a244199b5d2735fcdd0abd4664346ba51dd32
(DIR) parent 8f774acd2f6aa77052899ed737b8d34658601156
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Mon, 4 May 2015 12:39:21 +0430
led: word erase with ^W
Diffstat:
M led.c | 16 ++++++++++++++++
M uc.c | 9 +++++++++
M vi.c | 19 +++++--------------
M vi.h | 1 +
4 files changed, 31 insertions(+), 14 deletions(-)
---
(DIR) diff --git a/led.c b/led.c
t@@ -36,6 +36,18 @@ static int led_lastchar(char *s)
return r - s;
}
+static int led_lastword(char *s)
+{
+ char *r = *s ? uc_beg(s, strchr(s, '\0') - 1) : s;
+ int kind;
+ while (r > s && uc_isspace(r))
+ r = uc_beg(s, r - 1);
+ kind = r > s ? uc_kind(r) : 0;
+ while (r > s && uc_kind(uc_beg(s, r - 1)) == kind)
+ r = uc_beg(s, r - 1);
+ return r - s;
+}
+
static void led_printparts(char *pref, char *main, char *post)
{
struct sbuf *ln;
t@@ -87,6 +99,10 @@ static char *led_line(char *pref, char *post, int *key, char ***kmap)
case TERMCTRL('v'):
sbuf_chr(sb, term_read(-1));
break;
+ case TERMCTRL('w'):
+ if (sbuf_len(sb))
+ sbuf_cut(sb, led_lastword(sbuf_buf(sb)));
+ break;
default:
if (c == '\n' || c == TERMESC || c < 0)
break;
(DIR) diff --git a/uc.c b/uc.c
t@@ -118,6 +118,15 @@ int uc_isdigit(char *s)
return c <= 0x7f && isdigit(c);
}
+int uc_kind(char *c)
+{
+ if (uc_isspace(c))
+ return 0;
+ if (uc_isalpha(c) || uc_isdigit(c) || c[0] == '_')
+ return 1;
+ return 2;
+}
+
#define UC_R2L(ch) (((ch) & 0xff00) == 0x0600 || \
((ch) & 0xfffc) == 0x200c || \
((ch) & 0xff00) == 0xfb00 || \
(DIR) diff --git a/vi.c b/vi.c
t@@ -222,24 +222,15 @@ static int vi_motionln(int *row, int cmd, int pre1, int pre2)
return c;
}
-static int chkind(char *c)
-{
- if (uc_isspace(c))
- return 0;
- if (uc_isalpha(c) || uc_isdigit(c) || c[0] == '_')
- return 1;
- return 2;
-}
-
/* move to the last character of the word */
static int lbuf_wordlast(struct lbuf *lb, int *row, int *col, int kind, int dir)
{
- if (!kind || !(chkind(lbuf_chr(lb, *row, *col)) & kind))
+ if (!kind || !(uc_kind(lbuf_chr(lb, *row, *col)) & kind))
return 0;
- while (chkind(lbuf_chr(lb, *row, *col)) & kind)
+ while (uc_kind(lbuf_chr(lb, *row, *col)) & kind)
if (lbuf_next(lb, row, col, dir))
return 1;
- if (!(chkind(lbuf_chr(lb, *row, *col)) & kind))
+ if (!(uc_kind(lbuf_chr(lb, *row, *col)) & kind))
lbuf_next(lb, row, col, -dir);
return 0;
}
t@@ -247,7 +238,7 @@ static int lbuf_wordlast(struct lbuf *lb, int *row, int *col, int kind, int dir)
static int lbuf_wordbeg(struct lbuf *lb, int *row, int *col, int big, int dir)
{
int nl = 0;
- lbuf_wordlast(lb, row, col, big ? 3 : chkind(lbuf_chr(lb, *row, *col)), dir);
+ lbuf_wordlast(lb, row, col, big ? 3 : uc_kind(lbuf_chr(lb, *row, *col)), dir);
if (lbuf_next(lb, row, col, dir))
return 1;
while (uc_isspace(lbuf_chr(lb, *row, *col))) {
t@@ -276,7 +267,7 @@ static int lbuf_wordend(struct lbuf *lb, int *row, int *col, int big, int dir)
if (lbuf_next(lb, row, col, dir))
return 1;
}
- if (lbuf_wordlast(lb, row, col, big ? 3 : chkind(lbuf_chr(lb, *row, *col)), dir))
+ if (lbuf_wordlast(lb, row, col, big ? 3 : uc_kind(lbuf_chr(lb, *row, *col)), dir))
return 1;
return 0;
}
(DIR) diff --git a/vi.h b/vi.h
t@@ -58,6 +58,7 @@ int uc_isspace(char *s);
int uc_isprint(char *s);
int uc_isdigit(char *s);
int uc_isalpha(char *s);
+int uc_kind(char *c);
char **uc_chop(char *s, int *n);
char *uc_next(char *s);
char *uc_beg(char *beg, char *s);