diff options
-rw-r--r-- | src/cmd/acme/dat.h | 1 | ||||
-rw-r--r-- | src/cmd/acme/exec.c | 25 | ||||
-rw-r--r-- | src/cmd/acme/text.c | 67 | ||||
-rw-r--r-- | src/cmd/acme/wind.c | 3 | ||||
-rw-r--r-- | src/cmd/devdraw/cocoa-screen.m | 4 |
5 files changed, 90 insertions, 10 deletions
diff --git a/src/cmd/acme/dat.h b/src/cmd/acme/dat.h index df1a6422..74107a11 100644 --- a/src/cmd/acme/dat.h +++ b/src/cmd/acme/dat.h @@ -268,6 +268,7 @@ struct Window int utflastqid; int utflastboff; int utflastq; + uchar tabexpand; /* expand tab char with space*body.tabstop */ int tagsafe; /* taglines is correct */ int tagexpand; int taglines; diff --git a/src/cmd/acme/exec.c b/src/cmd/acme/exec.c index 2a259533..b46d7792 100644 --- a/src/cmd/acme/exec.c +++ b/src/cmd/acme/exec.c @@ -53,6 +53,7 @@ void putall(Text*, Text*, Text*, int, int, Rune*, int); 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 tabexpand(Text*, Text*, Text*, int, int, Rune*, int); void zeroxx(Text*, Text*, Text*, int, int, Rune*, int); typedef struct Exectab Exectab; @@ -92,6 +93,7 @@ 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 LTab[] = { 'T', 'a', 'b', 0 }; +static Rune LTabexpand[] = { 'T', 'a', 'b', 'e', 'x', 'p', 'a', 'n', 'd', 0 }; static Rune LUndo[] = { 'U', 'n', 'd', 'o', 0 }; static Rune LZerox[] = { 'Z', 'e', 'r', 'o', 'x', 0 }; @@ -123,6 +125,7 @@ Exectab exectab[] = { { LSnarf, cut, FALSE, TRUE, FALSE }, { LSort, sort, FALSE, XXX, XXX }, { LTab, tab, FALSE, XXX, XXX }, + { LTabexpand, tabexpand, FALSE, XXX, XXX }, { LUndo, undo, FALSE, TRUE, XXX }, { LZerox, zeroxx, FALSE, XXX, XXX }, { nil, 0, 0, 0, 0 } @@ -1359,6 +1362,28 @@ tab(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) } void +tabexpand(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg) +{ + Window *w; + + USED(_0); + USED(_1); + USED(_2); + + if(et==nil || et->w==nil) + return; + w = et->w; + + if(w->tabexpand){ + w->tabexpand = FALSE; + warning(nil, "%.*S: Tabexpand OFF\n", w->body.file->nname, w->body.file->name); + }else{ + w->tabexpand = TRUE; + warning(nil, "%.*S: Tabexpand ON\n", w->body.file->nname, w->body.file->name); + } +} + +void runproc(void *argvp) { /* args: */ diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c index c53694c6..e82a3a30 100644 --- a/src/cmd/acme/text.c +++ b/src/cmd/acme/text.c @@ -681,10 +681,19 @@ texttype(Text *t, Rune r) textshow(t, t->q1+1, t->q1+1, TRUE); return; case Kdown: - if(t->what == Tag) - goto Tagdown; - n = t->fr.maxlines/3; - goto case_Down; + typecommit(t); + q0 = t->q0; + nnb = 0; + if(q0>0 && textreadc(t, q0-1)!='\n') + nnb = textbswidth(t, 0x15); + while(q0<t->file->b.nc && textreadc(t, q0)!='\n') + q0++; + if (q0+1 <= t->file->b.nc) + q0++; + while(q0<t->file->b.nc && textreadc(t, q0)!='\n' && nnb--) + q0++; + textshow(t, q0, q0, TRUE); + return; case Kscrollonedown: if(t->what == Tag) goto Tagdown; @@ -699,10 +708,25 @@ texttype(Text *t, Rune r) textsetorigin(t, q0, TRUE); return; case Kup: - if(t->what == Tag) - goto Tagup; - n = t->fr.maxlines/3; - goto case_Up; + typecommit(t); + q0 = t->q0; + nnb = 0; + n = 0; + if(q0>0 && textreadc(t, q0-1)!='\n') + nnb = textbswidth(t, 0x15); + q0 -= nnb; + if (q0>0) + q0--; + while (q0>0 && textreadc(t, q0-1)!='\n') + if (q0 == 0) + break; + else { + q0--; + n++; + } + q0 += (nnb > n) ? n : nnb; + textshow(t, q0, q0, TRUE); + return; case Kscrolloneup: if(t->what == Tag) goto Tagup; @@ -734,17 +758,38 @@ texttype(Text *t, Rune r) } else textshow(t, t->file->b.nc, t->file->b.nc, FALSE); return; + case 0x09: /* ^I (TAB) */ + if(t->what!=Body) + break; + if(t->w->tabexpand == TRUE){ + for(i=0; i < t->w->body.tabstop; i++){ + texttype(t, ' '); + } + return; + }else + break; /* fall through to normal code */ case 0x01: /* ^A: beginning of line */ typecommit(t); /* go to where ^U would erase, if not already at BOL */ nnb = 0; if(t->q0>0 && textreadc(t, t->q0-1)!='\n') nnb = textbswidth(t, 0x15); + /* if already at beginning, wrap backwards to previous line if possible */ + if (nnb == 0 && t->q0>0) { + textshow(t, t->q0-1, t->q0-1, TRUE); + return; + } textshow(t, t->q0-nnb, t->q0-nnb, TRUE); return; case 0x05: /* ^E: end of line */ typecommit(t); q0 = t->q0; + /* if already at end, wrap forward to the next line if possible */ + if (q0<t->file->b.nc && textreadc(t, q0) == '\n') { + q0++; + textshow(t, q0, q0, TRUE); + return; + } while(q0<t->file->b.nc && textreadc(t, q0)!='\n') q0++; textshow(t, q0, q0, TRUE); @@ -760,7 +805,11 @@ texttype(Text *t, Rune r) case Kcmd+'Z': /* %-shift-Z: redo */ typecommit(t); undo(t, nil, nil, FALSE, 0, nil, 0); - return; + return; + case Kcmd+'s': /* %S: save/put file */ + typecommit(t); + put(&t->w->body, nil, nil, XXX, XXX, nil, 0); + return; Tagdown: /* expand tag to show all text */ diff --git a/src/cmd/acme/wind.c b/src/cmd/acme/wind.c index 712eb1dc..d255d00b 100644 --- a/src/cmd/acme/wind.c +++ b/src/cmd/acme/wind.c @@ -80,9 +80,12 @@ wininit(Window *w, Window *clone, Rectangle r) w->filemenu = TRUE; w->maxlines = w->body.fr.maxlines; w->autoindent = globalautoindent; + w->tabexpand = FALSE; if(clone){ w->dirty = clone->dirty; w->autoindent = clone->autoindent; + w->tabexpand = clone->tabexpand; + w->body.tabstop = clone->body.tabstop; textsetselect(&w->body, clone->body.q0, clone->body.q1); winsettag(w); } diff --git a/src/cmd/devdraw/cocoa-screen.m b/src/cmd/devdraw/cocoa-screen.m index e7296e44..8e141904 100644 --- a/src/cmd/devdraw/cocoa-screen.m +++ b/src/cmd/devdraw/cocoa-screen.m @@ -62,7 +62,7 @@ AUTOFRAMEWORK(Cocoa) int usegestures = 0; int useliveresizing = 0; -int useoldfullscreen = 0; +int useoldfullscreen = 1; int usebigarrow = 0; static void setprocname(const char*); @@ -927,6 +927,8 @@ getkeyboard(NSEvent *e) case NSFlagsChanged: if(in.mbuttons || in.kbuttons){ in.kbuttons = 0; + if(m & NSControlKeyMask) + in.kbuttons |= 1; if(m & NSAlternateKeyMask) in.kbuttons |= 2; if(m & NSCommandKeyMask) |