tvi: hll option to highlight current line - neatvi - [fork] simple vi-type edit… | |
git clone git://src.adamsgaard.dk/neatvi | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit 4cb1cd3990fc9abf27d4c796825b7e080e1e8aea | |
parent a4917ea76e33803c53332bc622d870b36c7371c9 | |
Author: Ali Gholami Rudi <[email protected]> | |
Date: Sun, 19 Jan 2020 20:15:34 +0330 | |
vi: hll option to highlight current line | |
Diffstat: | |
M README | 2 ++ | |
M conf.c | 6 ++++++ | |
M conf.h | 5 ++++- | |
M ex.c | 2 ++ | |
M syn.c | 8 ++++++++ | |
M vi.c | 18 +++++++++++++++--- | |
M vi.h | 3 +++ | |
7 files changed, 40 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/README b/README | |
t@@ -60,6 +60,8 @@ order | |
hl, highlight | |
If set (default), text will be highlighted based on syntax | |
highlighting rules in conf.h. | |
+hll, highlightline | |
+ If set, highlight current line. | |
ai, autoindent | |
As in vi(1). | |
aw, autowrite | |
diff --git a/conf.c b/conf.c | |
t@@ -75,6 +75,12 @@ int conf_highlight_revdir(int *att) | |
return 0; | |
} | |
+int conf_highlight_line(int *att) | |
+{ | |
+ *att = SYN_LINE; | |
+ return 0; | |
+} | |
+ | |
char **conf_kmap(int id) | |
{ | |
return kmaps[id]; | |
diff --git a/conf.h b/conf.h | |
t@@ -81,8 +81,11 @@ static struct highlight { | |
{"---", {8 | SYN_BD}, "^.*$"}, | |
}; | |
+/* how to hightlight current line (hll option) */ | |
+#define SYN_LINE (SYN_BGMK(11)) | |
+ | |
/* how to hightlight text in the reverse direction */ | |
-#define SYN_REVDIR (SYN_BGMK(255)) | |
+#define SYN_REVDIR (SYN_BGMK(7)) | |
/* right-to-left characters (used only in dircontexts[] and dirmarks[]) */ | |
#define CR2L "ءآأؤإئابةتثجحخدذرزسشصضطظ�… | |
diff --git a/ex.c b/ex.c | |
t@@ -15,6 +15,7 @@ int xai = 1; /* autoindent option */ | |
int xic = 1; /* ignorecase option */ | |
int xaw; /* autowrite option */ | |
int xhl = 1; /* syntax highlight option */ | |
+int xhll; /* highlight current line */ | |
int xled = 1; /* use the line editor */ | |
int xtd = +1; /* current text direction */ | |
int xshape = 1; /* perform letter shaping */ | |
t@@ -860,6 +861,7 @@ static struct option { | |
{"shape", "shape", &xshape}, | |
{"order", "xorder", &xorder}, | |
{"hl", "highlight", &xhl}, | |
+ {"hll", "highlightline", &xhll}, | |
}; | |
static char *cutword(char *s, char *d) | |
diff --git a/syn.c b/syn.c | |
t@@ -12,6 +12,7 @@ static struct ftmap { | |
} ftmap[NFTS]; | |
static struct rset *syn_ftrs; | |
+static int syn_ctx; | |
static struct rset *syn_find(char *ft) | |
{ | |
t@@ -29,6 +30,11 @@ int syn_merge(int old, int new) | |
return ((old | new) & SYN_FLG) | (bg << 8) | fg; | |
} | |
+void syn_context(int att) | |
+{ | |
+ syn_ctx = att; | |
+} | |
+ | |
int *syn_highlight(char *ft, char *s) | |
{ | |
int subs[16 * 2]; | |
t@@ -41,6 +47,8 @@ int *syn_highlight(char *ft, char *s) | |
memset(att, 0, n * sizeof(att[0])); | |
if (!rs) | |
return att; | |
+ for (i = 0; i < n; i++) | |
+ att[i] = syn_ctx; | |
while ((hl = rset_find(rs, s + sidx, LEN(subs) / 2, subs, flg)) >= 0) { | |
int grp = 0; | |
int cend = 1; | |
diff --git a/vi.c b/vi.c | |
t@@ -53,7 +53,13 @@ static void vi_drawmsg(void) | |
static void vi_drawrow(int row) | |
{ | |
char *s = lbuf_get(xb, row); | |
+ if (xhll && row == xrow) { | |
+ int hll; | |
+ conf_highlight_line(&hll); | |
+ syn_context(hll); | |
+ } | |
led_print(s ? s : (row ? "~" : ""), row - xtop, ex_filetype()); | |
+ syn_context(0); | |
} | |
/* redraw the screen */ | |
t@@ -1326,10 +1332,16 @@ static void vi(void) | |
if (xcol < xleft) | |
xleft = xcol < xcols ? 0 : xcol - xcols / 2; | |
vi_wait(); | |
- if (mod || xleft != oleft) | |
+ if (mod || xleft != oleft) { | |
vi_drawagain(xcol, mod == 2 && xleft == oleft && xrow … | |
- else if (xtop != otop) | |
- vi_drawupdate(xcol, otop); | |
+ } else { | |
+ if (xtop != otop) | |
+ vi_drawupdate(xcol, otop); | |
+ if (xhll && xrow != orow && orow >= xtop && orow < xto… | |
+ vi_drawrow(orow); | |
+ if (xhll && xrow != orow) | |
+ vi_drawrow(xrow); | |
+ } | |
if (vi_msg[0]) | |
vi_drawmsg(); | |
term_pos(xrow - xtop, led_pos(lbuf_get(xb, xrow), | |
diff --git a/vi.h b/vi.h | |
t@@ -173,6 +173,7 @@ int cmd_exec(char *cmd); | |
int *syn_highlight(char *ft, char *s); | |
char *syn_filetype(char *path); | |
+void syn_context(int att); | |
int syn_merge(int old, int new); | |
void syn_init(void); | |
void syn_done(void); | |
t@@ -184,6 +185,7 @@ int conf_placeholder(int idx, char **s, char **d, int *wid… | |
int conf_highlight(int idx, char **ft, int **att, char **pat, int *end); | |
int conf_filetype(int idx, char **ft, char **pat); | |
int conf_highlight_revdir(int *att); | |
+int conf_highlight_line(int *att); | |
char **conf_kmap(int id); | |
int conf_kmapfind(char *name); | |
char *conf_digraph(int c1, int c2); | |
t@@ -202,5 +204,6 @@ extern int xtd; | |
extern int xshape; | |
extern int xorder; | |
extern int xhl; | |
+extern int xhll; | |
extern int xkmap; | |
extern int xkmap_alt; |