summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorWormHeamer2025-12-31 03:43:51 -0500
committerWormHeamer2025-12-31 03:43:51 -0500
commitd2a55a6e846644f16b2cd440ead8222ae5a3067e (patch)
tree199aa35621d73cefdc872cee748471f226f0a225 /main.c
parent79f562d94a908d3ebfc9ac68a577dbc70f12c450 (diff)
highlight trailing whitespace, allow count in gG
Diffstat (limited to 'main.c')
-rw-r--r--main.c49
1 files changed, 41 insertions, 8 deletions
diff --git a/main.c b/main.c
index 892dea6..9ab3a67 100644
--- a/main.c
+++ b/main.c
@@ -190,6 +190,12 @@ u32 move_par_down(Txt *t, u32 cur) {
return txt_ofs(next_par(txt_at(t, cur)));
}
+TxtLoc txt_at_line(Txt *t, u32 line) {
+ TxtLoc l = txt_start(t);
+ while (line-- > 1) l = next_line(l);
+ return l;
+}
+
typedef struct {
pid_t pid;
int from, to;
@@ -357,15 +363,24 @@ void draw(void *ctx) {
while (txt_before(start, end)) {
if (l.p == start.p && l.i == start.i) {
cur_found = 1;
- vui_curs_pos(x, y);
+ if (txt_chr(start) == '\t') {
+ vui_curs_pos(x + (-(x+1) & 7), y);
+ } else {
+ vui_curs_pos(x, y);
+ }
}
u32 c = txt_chr_next(&start);
if (c == '\n') {
x = lmarg;
y++;
- } else if (c == '\t') {
- x++;
- x += (-x & 7);
+ } else if (is_space(c)) {
+ VuiAttr a = txt_chr(start) == '\n' ? (FG_WHITE | BG_BLUE) : (FG_WHITE | BG_BLACK);
+ if (c == '\t') {
+ u32 n = 1 + (-(x+1) & 7);
+ while (n--) vui_chra(x++, y, ' ', a);
+ } else {
+ vui_chra(x++, y, ' ', a);
+ }
} else if (c) {
vui_chr(x++, y, c);
}
@@ -382,6 +397,12 @@ void draw(void *ctx) {
vui_printf(-1, -2, "e.scratch %.02f/%.02fk", used/1024.0, max/1024.0);*/
}
+TxtLoc logical_line_start(TxtLoc l) {
+ l = start_of_line(l);
+ while (txt_chr(l) == '\t') l = cnext(l);
+ return l;
+}
+
int motion(TxtLoc *lp, u32 c) {
TxtLoc l = *lp;
TxtLoc last_loc = l;
@@ -445,6 +466,8 @@ loop:
break;
case KEY_HOME:
case '^':
+ l = logical_line_start(l);
+ break;
case '0':
l = start_of_line(l);
break;
@@ -454,11 +477,21 @@ loop:
break;
case KEY_HOME | KEY_CTRL_BIT:
case 'g':
- l = txt_start(l.t);
+ if (e.count) {
+ l = txt_at_line(l.t, e.count);
+ e.count = 0;
+ } else {
+ l = txt_start(l.t);
+ }
break;
case KEY_END | KEY_CTRL_BIT:
case 'G':
- l = txt_end(l.t);
+ if (e.count) {
+ l = txt_at_line(l.t, e.count);
+ e.count = 0;
+ } else {
+ l = txt_end(l.t);
+ }
break;
case 'f': {
u32 k = vui_key();
@@ -649,7 +682,7 @@ int main(int argc, const char **argv) {
arena_reset(&e.scratch);
EditBuf *eb = &e.buf[e.bufi];
draw(NULL);
-
+
switch (e.mode) {
case MODE_NORMAL:
vui_curs_shape(VUI_CURS_BLOCK);
@@ -701,7 +734,7 @@ int main(int argc, const char **argv) {
} break;
case 'I':
e.mode = 1;
- eb->cur = start_of_line(eb->cur);
+ eb->cur = logical_line_start(eb->cur);
break;
case 'A':
e.mode = 1;