From c60b2b2a0dc502e61ab7d80b3ef5d0aa8b37690b Mon Sep 17 00:00:00 2001 From: binarycat Date: Thu, 5 Aug 2021 12:48:08 -0400 Subject: [PATCH] spaceindent --- acme.c | 5 ++++- dat.h | 2 ++ exec.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++----- text.c | 7 +++++++ wind.c | 1 + 5 files changed, 64 insertions(+), 6 deletions(-) diff --git a/acme.c b/acme.c index d001a2a..d0c1772 100644 --- a/acme.c +++ b/acme.c @@ -114,6 +114,9 @@ threadmain(int argc, char *argv[]) case 'r': swapscrollbuttons = TRUE; break; + case 's': + globalspaceindent = TRUE; + break; case 'W': winsize = ARGF(); if(winsize == nil) @@ -121,7 +124,7 @@ threadmain(int argc, char *argv[]) break; default: Usage: - fprint(2, "usage: acme -a -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n"); + fprint(2, "usage: acme -as -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n"); threadexitsall("usage"); }ARGEND diff --git a/dat.h b/dat.h index 8a81c97..90a3794 100644 --- a/dat.h +++ b/dat.h @@ -241,6 +241,7 @@ struct Window uchar filemenu; uchar dirty; uchar autoindent; + uchar spaceindent; uchar showdel; int id; Range addr; @@ -553,6 +554,7 @@ int editing; int erroutfd; int messagesize; /* negotiated in 9P version setup */ int globalautoindent; +int globalspaceindent; int dodollarsigns; char* mtpt; diff --git a/exec.c b/exec.c index be7936a..547e988 100644 --- a/exec.c +++ b/exec.c @@ -55,6 +55,7 @@ void sendx(Text*, Text*, Text*, int, int, Rune*, int); void sort(Text*, Text*, Text*, int, int, Rune*, int); void tab(Text*, Text*, Text*, int, int, Rune*, int); void zeroxx(Text*, Text*, Text*, int, int, Rune*, int); +void spaceindent(Text*, Text*, Text*, int, int, Rune*, int); typedef struct Exectab Exectab; struct Exectab @@ -95,6 +96,8 @@ static Rune LSort[] = { 'S', 'o', 'r', 't', 0 }; static Rune LTab[] = { 'T', 'a', 'b', 0 }; static Rune LUndo[] = { 'U', 'n', 'd', 'o', 0 }; static Rune LZerox[] = { 'Z', 'e', 'r', 'o', 'x', 0 }; +static Rune LSpaceindent[] = { 'S', 'p', 'a', 'c', 'e', 'i', 'n', 'd', 'e', 'n', 't', 0 }; + Exectab exectab[] = { { LAbort, doabort, FALSE, XXX, XXX, }, @@ -110,6 +113,7 @@ Exectab exectab[] = { { LID, id, FALSE, XXX, XXX }, { LIncl, incl, FALSE, XXX, XXX }, { LIndent, indent, FALSE, XXX, XXX }, + { LSpaceindent, spaceindent, FALSE, XXX, XXX }, { LKill, xkill, FALSE, XXX, XXX }, { LLoad, dump, FALSE, FALSE, XXX }, { LLocal, local, FALSE, XXX, XXX }, @@ -1395,29 +1399,37 @@ enum { Ioff = 1 }; + + static int -indentval(Rune *s, int n) +onoffval(Rune *s, int n, int *global) { if(n < 2) return IError; if(runestrncmp(s, LON, n) == 0){ - globalautoindent = TRUE; - warning(nil, "Indent ON\n"); + *global = TRUE; + //warning(nil, "Indent ON\n"); return IGlobal; } if(runestrncmp(s, LOFF, n) == 0){ - globalautoindent = FALSE; - warning(nil, "Indent OFF\n"); + *global = FALSE; + //warning(nil, "Indent OFF\n"); return IGlobal; } return runestrncmp(s, Lon, n) == 0; } +static int +indentval(Rune *s, int n) { + return onoffval(s, n, &globalautoindent); +} + static void fixindent(Window *w, void *arg) { USED(arg); w->autoindent = globalautoindent; + w->spaceindent = globalspaceindent; } void @@ -1426,6 +1438,8 @@ indent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) Rune *a, *r; Window *w; int na, len, autoindent; + + USED(_0); USED(_1); @@ -1449,6 +1463,37 @@ indent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) w->autoindent = autoindent; } +void +spaceindent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) +{ + Rune *a, *r; + Window *w; + int na, len, spindent; + + + + USED(_0); + USED(_1); + USED(_2); + + w = nil; + if(et!=nil && et->w!=nil) + w = et->w; + spindent = IError; + getarg(argt, FALSE, TRUE, &r, &len); + if(r!=nil && len>0) + spindent = onoffval(r, len, &globalspaceindent); + else{ /* I'm not really sure what this does */ + a = findbl(arg, narg, &na); + if(a != arg) + spindent = onoffval(arg, narg-na, &globalspaceindent); + } + if(spindent == IGlobal) + allwindows(fixindent, nil); + else if(w != nil && spindent >= 0) + w->spaceindent = spindent; +} + void tab(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) { diff --git a/text.c b/text.c index 09422dd..01730e0 100644 --- a/text.c +++ b/text.c @@ -902,6 +902,13 @@ texttype(Text *t, Rune r) } } break; /* fall through to normal code */ + case '\t': + if(t->w->spaceindent){ + for(i=0; iw->body.tabstop; i++) + texttype(t, ' '); + return; + } + break; } /* otherwise ordinary character; just insert, typically in caches of all texts */ for(i=0; ifile->ntext; i++){ diff --git a/wind.c b/wind.c index 0cba592..abeacf0 100644 --- a/wind.c +++ b/wind.c @@ -81,6 +81,7 @@ wininit(Window *w, Window *clone, Rectangle r) w->filemenu = TRUE; w->maxlines = w->body.fr.maxlines; w->autoindent = globalautoindent; + w->spaceindent = globalspaceindent; if(clone){ w->dirty = clone->dirty; w->autoindent = clone->autoindent; -- 2.25.1