all repos — acme @ 110ffde5158b065084a7d8a161c7fb2d5ec45ea1

fork of the acme editor from plan9port - keybinds, tweaks, config.h, etc

added tabs to spaces code from mkhl
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iQIzBAABCAAdFiEEkFh6dA+k/6CXFXU4O3+8IhROY5gFAl+0I+EACgkQO3+8IhRO
Y5gu/A/+P4c3fIuALUHouvU8UV8+ckQfqwwLnPmZNqd5QTJDGhBu8dotwi/s/m5m
YBfdrhyDM9QGVLBJuFuL1PLL6/cNoZHh72Va2mL4+GKw2w79kYBzQ+xzL5EVaJkd
+UMZqq50Woh4BId62fEL2Ap4IF4/wVI7OZuFDY7zys4xWpqDZxheVUOVWO6OeqYX
h1Uu6kE/8F9Z+RFEaQT8E3aB8zthGP9Ez13zn0H9bYIdJe6pIrDCbnScurvtL3qb
x7T68xiLrDe6xCZqlGDT5QHY6oTInp89IdcY/DfHQkkM6yf0hQ32rEeV7PQp76HQ
+gK+Vwo4St+9sKUUO/rkYnru/BABoc2lk8BrtkgI48bCmWcfejjp8e4EaZB+KUYB
+LScF1BJsUyoEAu5wruSi+VdOT6mPgpX0aFfzjfwW1oPjmXrq7Uwfcg54RqojzQA
ab6VN4yQzJwttXTGSwS9PzHYkCPe10zpakNYq2lzGGdSnibDWzmHI0laHVDQoxbB
XaH1m2jaWr/g+DMNNsoI1yVCTb1oIeUdRB6X7pQV6ONje/3reNNENAffX1eCklBB
ep861SEh/QRx3r8e5aJ7K51sTAYEcjdJR+jX8Sgb1A6hqrh6MqGtzFUajEDKAY7o
2fB9vcmEWi24Upxv/eD23E7WBBGLC8H0H6IPx9y48wMPUUcxoWI=
=vQzx
-----END PGP SIGNATURE-----
commit

110ffde5158b065084a7d8a161c7fb2d5ec45ea1

parent

770f1906a3fd1f3bb53dbf7ed787bfc707868cda

7 files changed, 170 insertions(+), 108 deletions(-)

jump to
M acme.cacme.c

@@ -78,7 +78,7 @@ _threaddebuglevel = ~0;

} break; case 'a': - globalautoindent = TRUE; + globalindent[AUTOINDENT] = TRUE; break; case 'b': bartflag = TRUE;

@@ -101,6 +101,9 @@ fontnames[1] = ARGF();

if(fontnames[1] == nil) goto Usage; break; + case 'i': + globalindent[SPACESINDENT] = TRUE; + break; case 'l': loadfile = ARGF(); if(loadfile == nil)

@@ -121,7 +124,7 @@ goto Usage;

break; default: Usage: - fprint(2, "usage: acme -a -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n"); + fprint(2, "usage: acme -aib -c ncol -f fontname -F fixedwidthfontname -l loadfile -W winsize\n"); threadexitsall("usage"); }ARGEND

@@ -968,69 +971,69 @@ };

Cursor2 boxcursor2 = { {-15, -15}, - {0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xC0, 0x03, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xF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, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0x00, 0x00, 0xFC, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x3F, 0xFF, 0xFF, 0xFC, - 0x00, 0x00, 0x00, 0x00, + {0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0x00, 0x00, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x3F, 0xFF, 0xFF, 0xFC, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} };

@@ -1047,7 +1050,7 @@ tagcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x1F9B92FF);

tagcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x797979FF); tagcols[TEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x797979FF); tagcols[HTEXT] = display->black; - + /* Blue */ textcols[BACK] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x000F19FF); textcols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x1F9B92FF);

@@ -1055,7 +1058,7 @@ textcols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x93A1A1FF);

textcols[TEXT] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0x93A1A1FF); textcols[HTEXT] = display->black; } - + r = Rect(0, 0, Scrollwid+ButtonBorder, font->height+1); if(button && eqrect(r, button->r)) return;
M dat.hdat.h

@@ -229,6 +229,14 @@ void textsetselect(Text*, uint, uint);

void textshow(Text*, uint, uint, int); void texttype(Text*, Rune); + +enum +{ + SPACESINDENT = 0, + AUTOINDENT, + NINDENT, +}; + struct Window { QLock lk;

@@ -240,7 +248,7 @@ uchar isdir;

uchar isscratch; uchar filemenu; uchar dirty; - uchar autoindent; + uchar indent[NINDENT]; uchar showdel; int id; Range addr;

@@ -552,7 +560,7 @@ extern char wdir[]; /* must use extern because no dimension given */

int editing; int erroutfd; int messagesize; /* negotiated in 9P version setup */ -int globalautoindent; +int globalindent[NINDENT]; int dodollarsigns; char* mtpt;
M exec.cexec.c

@@ -92,6 +92,7 @@ static Rune LRedo[] = { 'R', 'e', 'd', 'o', 0 };

static Rune LSend[] = { 'S', 'e', 'n', 'd', 0 }; static Rune LSnarf[] = { 'S', 'n', 'a', 'r', 'f', 0 }; static Rune LSort[] = { 'S', 'o', 'r', 't', 0 }; +static Rune LSpaces[] = { 'S', 'p', 'a', 'c', 'e', 's', 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 };

@@ -109,7 +110,7 @@ { LFont, fontx, FALSE, XXX, XXX },

{ LGet, get, FALSE, TRUE, XXX }, { LID, id, FALSE, XXX, XXX }, { LIncl, incl, FALSE, XXX, XXX }, - { LIndent, indent, FALSE, XXX, XXX }, + { LIndent, indent, FALSE, AUTOINDENT, XXX }, { LKill, xkill, FALSE, XXX, XXX }, { LLoad, dump, FALSE, FALSE, XXX }, { LLocal, local, FALSE, XXX, XXX },

@@ -123,6 +124,7 @@ { LRedo, undo, FALSE, FALSE, XXX },

{ LSend, sendx, TRUE, XXX, XXX }, { LSnarf, cut, FALSE, TRUE, FALSE }, { LSort, sort, FALSE, XXX, XXX }, + { LSpaces, indent, FALSE, SPACESINDENT, XXX }, { LTab, tab, FALSE, XXX, XXX }, { LUndo, undo, FALSE, TRUE, XXX }, { LZerox, zeroxx, FALSE, XXX, XXX },

@@ -911,7 +913,7 @@ if(name == nil){

warning(nil, "no file name\n"); return; } - if(w->autoindent) + if(w->indent[NINDENT]) trimspaces(et); namer = bytetorune(name, &nname); putfile(f, 0, f->b.nc, namer, nname);

@@ -1383,66 +1385,75 @@

static Rune LON[] = { 'O', 'N', 0 }; static Rune LOFF[] = { 'O', 'F', 'F', 0 }; static Rune Lon[] = { 'o', 'n', 0 }; +static Rune Loff[] = { 'o', 'f', 'f', 0 }; enum { IGlobal = -2, IError = -1, - Ion = 0, - Ioff = 1 }; static int -indentval(Rune *s, int n) +indentval(Rune *s, int n, int type) { + static char *strs[] = { + [SPACESINDENT] = "Spaces", + [AUTOINDENT] = "Indent", + }; + if(n < 2) return IError; if(runestrncmp(s, LON, n) == 0){ - globalautoindent = TRUE; - warning(nil, "Indent ON\n"); + globalindent[type] = TRUE; + warning(nil, "%s ON\n", strs[type]); return IGlobal; } if(runestrncmp(s, LOFF, n) == 0){ - globalautoindent = FALSE; - warning(nil, "Indent OFF\n"); + globalindent[type] = FALSE; + warning(nil, "%s OFF\n", strs[type]); return IGlobal; } - return runestrncmp(s, Lon, n) == 0; + if(runestrncmp(s, Lon, n) == 0) + return TRUE; + if(runestrncmp(s, Loff, n) == 0) + return FALSE; + return IError; } static void fixindent(Window *w, void *arg) { - USED(arg); - w->autoindent = globalautoindent; + int t; + + t = (int)arg; + w->indent[t] = globalindent[t]; } void -indent(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) +indent(Text *et, Text* _0, Text *argt, int type, int _1, Rune *arg, int narg) { Rune *a, *r; Window *w; - int na, len, autoindent; + int na, len, ival; USED(_0); USED(_1); - USED(_2); w = nil; if(et!=nil && et->w!=nil) w = et->w; - autoindent = IError; + ival = IError; getarg(argt, FALSE, TRUE, &r, &len); if(r!=nil && len>0) - autoindent = indentval(r, len); + ival = indentval(r, len, type); else{ a = findbl(arg, narg, &na); if(a != arg) - autoindent = indentval(arg, narg-na); + ival = indentval(arg, narg-na, type); } - if(autoindent == IGlobal) - allwindows(fixindent, nil); - else if(w != nil && autoindent >= 0) - w->autoindent = autoindent; + if(ival == IGlobal) + allwindows(fixindent, (void*)type); + else if(w != nil && ival >= 0) + w->indent[type] = ival; } void
M look.clook.c

@@ -799,9 +799,11 @@ rp = runemalloc(n);

runemove(rp, ow->incl[i], n); winaddincl(w, rp, n); } - w->autoindent = ow->autoindent; + for(i=0; i < NINDENT; i++) + w->indent[i] = ow->indent[i]; }else - w->autoindent = globalautoindent; + for(i=0; i < NINDENT; i++) + w->indent[i] = globalindent[i]; xfidlog(w, "new"); } if(e->a1 == e->a0)
M text.ctext.c

@@ -532,6 +532,27 @@ bufread(&t->file->b, q, &r, 1);

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) {

@@ -540,8 +561,11 @@ Rune r;

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){

@@ -910,8 +934,19 @@ for(i=0; i<t->file->ntext; i++)

textfill(t->file->text[i]); t->iq1 = t->q0; 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->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);
M util.cutil.c

@@ -107,7 +107,8 @@ r = runemalloc(n);

runemove(r, incl[i], n); winaddincl(w, r, n); } - w->autoindent = globalautoindent; + for(i=0; i<NINDENT; i++) + w->indent[i] = globalindent[i]; return w; }

@@ -132,7 +133,7 @@ return w;

} /* - * Incoming window should be locked. + * Incoming window should be locked. * It will be unlocked and returned window * will be locked in its place. */

@@ -189,7 +190,7 @@ void

addwarningtext(Mntdir *md, Rune *r, int nr) { Warning *warn; - + for(warn = warnings; warn; warn=warn->next){ if(warn->md == md){ bufinsert(&warn->buf, warn->buf.nc, r, nr);
M wind.cwind.c

@@ -21,7 +21,7 @@ Rectangle r1, br;

File *f; Reffont *rf; Rune *rp; - int nc; + int nc, i; w->tag.w = w; w->taglines = 1;

@@ -80,10 +80,12 @@ br.max.y = br.min.y + Dy(button->r);

draw(screen, br, button, nil, button->r.min); w->filemenu = TRUE; w->maxlines = w->body.fr.maxlines; - w->autoindent = globalautoindent; + for(i=0; i<NINDENT; i++) + w->indent[i] = globalindent[i]; if(clone){ w->dirty = clone->dirty; - w->autoindent = clone->autoindent; + for(i=0; i<NINDENT; i++) + w->indent[i] = clone->indent[i]; textsetselect(&w->body, clone->body.q0, clone->body.q1); winsettag(w); }

@@ -97,7 +99,7 @@ windrawbutton(Window *w)

{ Image *b; Rectangle br; - + b = button; if(!w->isdir && !w->isscratch && (w->body.file->mod || w->body.ncache)) b = modbutton;

@@ -112,7 +114,7 @@ delrunepos(Window *w)

{ int n; Rune rune; - + for(n=0; n<w->tag.file->b.nc; n++) { bufread(&w->tag.file->b, n, &rune, 1); if(rune == ' ')

@@ -128,7 +130,7 @@ void

movetodel(Window *w) { int n; - + n = delrunepos(w); if(n < 0) return;

@@ -153,7 +155,7 @@ w->tag.fr.noredraw = 1;

textresize(&w->tag, r, TRUE); w->tag.fr.noredraw = 0; w->tagsafe = FALSE; - + if(!w->tagexpand) { /* use just as many lines as needed to show the Del */ n = delrunepos(w);

@@ -162,7 +164,7 @@ return 1;

p = subpt(frptofchar(&w->tag.fr, n), w->tag.fr.r.min); return 1 + p.y / w->tag.fr.font->height; } - + /* can't use more than we have */ if(w->tag.fr.nlines >= w->tag.fr.maxlines) return w->tag.fr.maxlines;

@@ -224,7 +226,7 @@ p.y = w->tag.all.max.y+3;

moveto(mousectl, p); } } - + /* If needed, resize & redraw body. */ r1 = r; r1.min.y = y;

@@ -293,7 +295,7 @@

void winmousebut(Window *w) { - moveto(mousectl, addpt(w->tag.scrollr.min, + moveto(mousectl, addpt(w->tag.scrollr.min, divpt(Pt(Dx(w->tag.scrollr), font->height), 2))); }

@@ -672,7 +674,7 @@ {

sprint(buf, "%11d %11d %11d %11d %11d ", w->id, w->tag.file->b.nc, w->body.file->b.nc, w->isdir, w->dirty); if(fonts) - return smprint("%s%11d %q %11d ", buf, Dx(w->body.fr.r), + return smprint("%s%11d %q %11d ", buf, Dx(w->body.fr.r), w->body.reffont->f->name, w->body.fr.maxtab); return buf; }