tled: use --- filetype for ex prompt and messages - neatvi - [fork] simple vi-t… | |
git clone git://src.adamsgaard.dk/neatvi | |
Log | |
Files | |
Refs | |
README | |
--- | |
commit cfdf0cf8c3281f83a091d9c36a887154e0bdfd6e | |
parent cfb5f5f6170fa3c66566a81ce2a4d17c60c563aa | |
Author: Ali Gholami Rudi <[email protected]> | |
Date: Thu, 31 Oct 2019 19:29:34 +0330 | |
led: use --- filetype for ex prompt and messages | |
Diffstat: | |
M led.c | 30 ++++++++++++++++-------------- | |
M vi.c | 14 +++++++------- | |
M vi.h | 8 ++++---- | |
3 files changed, 27 insertions(+), 25 deletions(-) | |
--- | |
diff --git a/led.c b/led.c | |
t@@ -78,7 +78,7 @@ static char *led_render(char *s0, int cbeg, int cend, char *… | |
for (j = 0; j < curwid; j++) | |
off[led_posctx(ctx, pos[i] + j, cbeg, cend)] =… | |
} | |
- att = syn_highlight(syn, s0); | |
+ att = syn_highlight(xhl ? syn : "", s0); | |
led_markrev(n, chrs, pos, att); | |
out = sbuf_make(); | |
i = cbeg; | |
t@@ -111,9 +111,9 @@ static char *led_render(char *s0, int cbeg, int cend, char… | |
} | |
/* print a line on the screen */ | |
-void led_print(char *s, int row) | |
+void led_print(char *s, int row, char *syn) | |
{ | |
- char *r = led_render(s, xleft, xleft + xcols, ex_filetype()); | |
+ char *r = led_render(s, xleft, xleft + xcols, syn); | |
term_pos(row, 0); | |
term_kill(); | |
term_str(r); | |
t@@ -129,10 +129,10 @@ static int td_set(int td) | |
} | |
/* print a line on the screen; for ex messages */ | |
-void led_printmsg(char *s, int row) | |
+void led_printmsg(char *s, int row, char *syn) | |
{ | |
int td = td_set(+2); | |
- char *r = led_render(s, xleft, xleft + xcols, xhl ? "---" : ""); | |
+ char *r = led_render(s, xleft, xleft + xcols, syn); | |
td_set(td); | |
term_pos(row, 0); | |
term_kill(); | |
t@@ -160,7 +160,8 @@ static int led_lastword(char *s) | |
return r - s; | |
} | |
-static void led_printparts(char *ai, char *pref, char *main, char *post, int k… | |
+static void led_printparts(char *ai, char *pref, char *main, | |
+ char *post, int kmap, char *syn) | |
{ | |
struct sbuf *ln; | |
int off, pos; | |
t@@ -186,7 +187,7 @@ static void led_printparts(char *ai, char *pref, char *mai… | |
xleft = pos - xcols / 2; | |
if (pos < xleft) | |
xleft = pos < xcols ? 0 : pos - xcols / 2; | |
- led_print(sbuf_buf(ln), -1); | |
+ led_print(sbuf_buf(ln), -1, syn); | |
term_pos(-1, led_pos(sbuf_buf(ln), pos + idir)); | |
sbuf_free(ln); | |
term_commit(); | |
t@@ -244,7 +245,8 @@ char *led_read(int *kmap) | |
} | |
/* read a line from the terminal */ | |
-static char *led_line(char *pref, char *post, char *ai, int ai_max, int *key, … | |
+static char *led_line(char *pref, char *post, char *ai, | |
+ int ai_max, int *key, int *kmap, char *syn) | |
{ | |
struct sbuf *sb; | |
int ai_len = strlen(ai); | |
t@@ -256,7 +258,7 @@ static char *led_line(char *pref, char *post, char *ai, in… | |
if (!post) | |
post = ""; | |
while (1) { | |
- led_printparts(ai, pref, sbuf_buf(sb), post, *kmap); | |
+ led_printparts(ai, pref, sbuf_buf(sb), post, *kmap, syn); | |
c = term_read(); | |
switch (c) { | |
case TK_CTL('f'): | |
t@@ -304,11 +306,11 @@ static char *led_line(char *pref, char *post, char *ai, … | |
} | |
/* read an ex command */ | |
-char *led_prompt(char *pref, char *post, int *kmap) | |
+char *led_prompt(char *pref, char *post, int *kmap, char *syn) | |
{ | |
int key; | |
int td = td_set(+2); | |
- char *s = led_line(pref, post, "", 0, &key, kmap); | |
+ char *s = led_line(pref, post, "", 0, &key, kmap, syn); | |
td_set(td); | |
if (key == '\n') { | |
struct sbuf *sb = sbuf_make(); | |
t@@ -325,7 +327,7 @@ char *led_prompt(char *pref, char *post, int *kmap) | |
} | |
/* read visual command input */ | |
-char *led_input(char *pref, char *post, int *kmap) | |
+char *led_input(char *pref, char *post, int *kmap, char *syn) | |
{ | |
struct sbuf *sb = sbuf_make(); | |
char ai[128]; | |
t@@ -336,7 +338,7 @@ char *led_input(char *pref, char *post, int *kmap) | |
ai[n++] = *pref++; | |
ai[n] = '\0'; | |
while (1) { | |
- char *ln = led_line(pref, post, ai, ai_max, &key, kmap); | |
+ char *ln = led_line(pref, post, ai, ai_max, &key, kmap, syn); | |
int ln_sp = 0; /* number of initial spaces in ln */ | |
while (ln[ln_sp] && (ln[ln_sp] == ' ' || ln[ln_sp] == '\t')) | |
ln_sp++; | |
t@@ -349,7 +351,7 @@ char *led_input(char *pref, char *post, int *kmap) | |
if (key == '\n') | |
sbuf_chr(sb, '\n'); | |
led_printparts(ai, pref ? pref : "", uc_lastline(ln), | |
- key == '\n' ? "" : post, *kmap); | |
+ key == '\n' ? "" : post, *kmap, syn); | |
if (key == '\n') | |
term_chr('\n'); | |
if (!pref || !pref[0]) { /* updating autoindent */ | |
diff --git a/vi.c b/vi.c | |
t@@ -45,7 +45,7 @@ static void vi_drawmsg(void) | |
{ | |
int oleft = xleft; | |
xleft = 0; | |
- led_printmsg(vi_msg, xrows); | |
+ led_printmsg(vi_msg, xrows, "---"); | |
vi_msg[0] = '\0'; | |
xleft = oleft; | |
} | |
t@@ -53,7 +53,7 @@ static void vi_drawmsg(void) | |
static void vi_drawrow(int row) | |
{ | |
char *s = lbuf_get(xb, row); | |
- led_print(s ? s : (row ? "~" : ""), row - xtop); | |
+ led_print(s ? s : (row ? "~" : ""), row - xtop, ex_filetype()); | |
} | |
/* redraw the screen */ | |
t@@ -126,7 +126,7 @@ static char *vi_prompt(char *msg, int *kmap) | |
char *r, *s; | |
term_pos(xrows, led_pos(msg, 0)); | |
term_kill(); | |
- s = led_prompt(msg, "", kmap); | |
+ s = led_prompt(msg, "", kmap, "---"); | |
if (!s) | |
return NULL; | |
r = uc_dup(strlen(s) >= strlen(msg) ? s + strlen(msg) : s); | |
t@@ -141,7 +141,7 @@ char *ex_read(char *msg) | |
char c; | |
if (xled) { | |
int oleft = xleft; | |
- char *s = led_prompt(msg, "", &xkmap); | |
+ char *s = led_prompt(msg, "", &xkmap, "---"); | |
xleft = oleft; | |
if (s) | |
term_chr('\n'); | |
t@@ -163,7 +163,7 @@ void ex_show(char *msg) | |
if (xvis) { | |
snprintf(vi_msg, sizeof(vi_msg), "%s", msg); | |
} else if (xled) { | |
- led_print(msg, -1); | |
+ led_print(msg, -1, "---"); | |
term_chr('\n'); | |
} else { | |
printf("%s", msg); | |
t@@ -178,7 +178,7 @@ void ex_print(char *line) | |
if (line) | |
snprintf(vi_msg, sizeof(vi_msg), "%s", line); | |
if (line) | |
- led_print(line, -1); | |
+ led_print(line, -1, ""); | |
term_chr('\n'); | |
} else { | |
if (line) | |
t@@ -657,7 +657,7 @@ static int charcount(char *text, char *post) | |
static char *vi_input(char *pref, char *post, int *row, int *off) | |
{ | |
- char *rep = led_input(pref, post, &xkmap); | |
+ char *rep = led_input(pref, post, &xkmap, ex_filetype()); | |
if (!rep) | |
return NULL; | |
*row = linecount(rep) - 1; | |
diff --git a/vi.h b/vi.h | |
t@@ -130,11 +130,11 @@ char *term_cmd(int *n); | |
#define TK_ESC (TK_CTL('[')) | |
/* line-oriented input and output */ | |
-char *led_prompt(char *pref, char *post, int *kmap); | |
-char *led_input(char *pref, char *post, int *kmap); | |
+char *led_prompt(char *pref, char *post, int *kmap, char *syn); | |
+char *led_input(char *pref, char *post, int *kmap, char *syn); | |
+void led_print(char *msg, int row, char *syn); | |
+void led_printmsg(char *s, int row, char *syn); | |
char *led_read(int *kmap); | |
-void led_print(char *msg, int row); | |
-void led_printmsg(char *s, int row); | |
int led_pos(char *s, int pos); | |
/* ex commands */ |