ref: 93781fc57a4c47ab2a417722b77e46df0d18604e
parent: a8d4fea6ef2b46865bfbaa416f0bf5db972d4374
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sun Feb 23 10:44:53 EST 2020
plan9: add undo/redo via command, allow two-char shorthands
--- a/orca.man
+++ b/orca.man
@@ -159,7 +159,11 @@
.B Ctrl+k
or with a
.B $
-operator.
+operator. All commands except
+.I undo
+and
+.I redo
+have a shorthand equivalent to their first two characters.
.PP
Any command can start with
.I ,
--- a/plan9.c
+++ b/plan9.c
@@ -438,12 +438,18 @@
}
static void
-command(char *s)
+nosnapshot(void)
{
+}
+
+static void
+command(char *s, void (*snapshot)(void))
+{
char *a;
int x, y;
if (s[0] == ',') {
+ snapshot();
cur = ZP;
sel = Rect(0, 0, field.width, field.height);
s++;
@@ -450,6 +456,8 @@
}
if (s[0] == '|' || s[0] == '>' || s[0] == '<') {
+ if (s[0] != '>')
+ snapshot();
shellpipe(s);
return;
}
@@ -457,19 +465,21 @@
if ((a = strchr(s, ':')) != nil || (a = strchr(s, ' ')) != nil)
*a++ = 0;
- if (strcmp(s, "play") == 0)
+ if (s[0] == 'p' && s[1] == 'l') /* play */
pause = false;
- else if (strcmp(s, "stop") == 0)
+ else if (s[0] == 's' && s[1] == 't') /* stop */
pause = true;
- else if (strcmp(s, "run") == 0)
+ else if (s[0] == 'r' && s[1] == 'u') /* run */
forward = true;
- else if (strcmp(s, "copy") == 0)
+ else if (s[0] == 'c' && s[1] == 'o') /* copy */
selcopy();
- else if (strcmp(s, "paste") == 0)
+ else if (s[0] == 'p' && s[1] == 'a') { /* paste */
+ snapshot();
selpaste();
- else if (strcmp(s, "erase") == 0)
+ } else if (s[0] == 'e' && s[1] == 'r') { /* erase */
+ snapshot();
selset('.');
- else if (strcmp(s, "print") == 0) {
+ } else if (s[0] == 'p' && s[1] == 'r') { /* print */
for (y = sel.min.y; y <= sel.max.y; y++) {
for (x = sel.min.x; x <= sel.max.x; x++)
putchar(field.buffer[x + y*field.width]);
@@ -479,24 +489,28 @@
} else if (a != nil) {
x = atoi(a);
- if (strcmp(s, "bpm") == 0)
+ if (s[0] == 'b' && s[1] == 'p') /* bpm */
apm = bpm = MAX(1, x);
- else if (strcmp(s, "apm") == 0)
+ else if (s[0] == 'a' && s[1] == 'p') /* apm */
apm = MAX(1, x);
- else if (strcmp(s, "frame") == 0)
+ else if (s[0] == 'f' && s[1] == 'r') /* frame */
tick = MAX(0, x);
- else if (strcmp(s, "skip") == 0)
+ else if (s[0] == 's' && s[1] == 'k') /* skip */
tick = MAX(0, tick+x);
- else if (strcmp(s, "rewind") == 0)
+ else if (s[0] == 'r' && s[1] == 'e') /* rewind */
tick = MAX(0, tick-x);
- else if (strcmp(s, "ip") == 0)
+ else if (s[0] == 'i' && s[1] == 'p') /* ip */
netdial(a, nil);
- else if (strcmp(s, "udp") == 0)
+ else if (s[0] == 'u' && s[1] == 'd') /* udp */
netdial(nil, a);
- else if (strcmp(s, "midi") == 0)
+ else if (s[0] == 'm' && s[1] == 'i') /* midi */
midiopen(a);
/* FIXME color, find, select, inject, write, time */
+ } else if (strcmp(s, "undo") == 0) {
+ undo();
+ } else if (strcmp(s, "redo") == 0) {
+ redo();
}
}
@@ -527,7 +541,7 @@
Oevent_cmd_string *c = &e->cmd_string;
memmove(tmp, c->chars, c->count);
tmp[c->count] = 0;
- command(tmp);
+ command(tmp, nosnapshot);
} else if (e->any.oevent_type = Oevent_type_udp_string) {
Oevent_udp_string *u = &e->udp_string;
if (udp >= 0)
@@ -969,13 +983,12 @@
if ((n = read(0, buf, sizeof(buf)-1)) <= 0)
break;
- snapshot();
for (i = 0; i < n; i++) {
if (buf[i] == '\r' || buf[i] == '\n' || buf[i] == 0) {
buf[i] = 0;
while (buf[i+1] == '\n')
i++;
- command(buf);
+ command(buf, snapshot);
n -= i;
memmove(buf, buf+i+1, n);
i = 0;
@@ -1462,9 +1475,8 @@
break;
case 0x0b: /* C-k */
tmp[0] = 0;
- snapshot();
if (enter("command:", tmp, sizeof(tmp), nil, &kctl, nil) > 0)
- command(tmp);
+ command(tmp, snapshot);
break;
case Kesc:
if (mode == Mslide || mode != Minsert)
@@ -1535,6 +1547,11 @@
break;
}
}
+
+ if (field.width != oldw)
+ w = field.width;
+ if (field.height != oldh)
+ h = field.height;
if (w != oldw || h != oldh) {
mbuf_reusable_ensure_size(&mscr, h, w);