diff options
author | spew <devnull@localhost> | 2018-08-01 11:14:59 -0400 |
---|---|---|
committer | spew <devnull@localhost> | 2018-08-01 11:14:59 -0400 |
commit | 4757debd0b5935dae94944c35c3cac74b14aa209 (patch) | |
tree | 950414554d5b67cce61a3c7809222a331d64a028 /sys/src/cmd/acme/text.c | |
parent | 2b619dc9669e34c7b110ce188a10d03849119c78 (diff) |
acme: add spacesindent mode
Diffstat (limited to 'sys/src/cmd/acme/text.c')
-rw-r--r-- | sys/src/cmd/acme/text.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/sys/src/cmd/acme/text.c b/sys/src/cmd/acme/text.c index 7380d0163..b96213a68 100644 --- a/sys/src/cmd/acme/text.c +++ b/sys/src/cmd/acme/text.c @@ -502,6 +502,27 @@ textreadc(Text *t, uint q) return r; } +static int +spacesindentbswidth(Text *t) +{ + uint q, col; + Rune r; + + col = textbswidth(t, 0x15); + q = t->q0; + while(q > 0){ + r = textreadc(t, q-1); + if(r != ' ') + break; + q--; + if(--col % t->tabstop == 0) + break; + } + if(t->q0 == q) + return 1; + return t->q0-q; +} + int textbswidth(Text *t, Rune c) { @@ -510,8 +531,11 @@ textbswidth(Text *t, Rune c) int skipping; /* there is known to be at least one character to erase */ - if(c == 0x08) /* ^H: erase character */ + if(c == 0x08){ /* ^H: erase character */ + if(t->what == Body && t->w->indent[SPACESINDENT]) + return spacesindentbswidth(t); return 1; + } q = t->q0; skipping = TRUE; while(q > 0){ @@ -775,8 +799,19 @@ texttype(Text *t, Rune r) for(i=0; i<t->file->ntext; i++) textfill(t->file->text[i]); return; + case '\t': + if(t->what == Body && t->w->indent[SPACESINDENT]){ + nnb = textbswidth(t, 0x15); + if(nnb == 1 && textreadc(t, t->q0-1) == '\n') + nnb = 0; + nnb = t->tabstop - nnb % t->tabstop; + rp = runemalloc(nnb); + for(nr = 0; nr < nnb; nr++) + rp[nr] = ' '; + } + break; case '\n': - if(t->what == Body && t->w->autoindent){ + if(t->what == Body && t->w->indent[AUTOINDENT]){ /* find beginning of previous line using backspace code */ nnb = textbswidth(t, 0x15); /* ^U case */ rp = runemalloc(nnb + 1); |