forked from n-t-roff/sc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vi.c
3578 lines (3341 loc) · 120 KB
/
vi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* SC A Spreadsheet Calculator
* One line vi emulation
*
* updated by Charlie Gordon: June, 2021
*
* $Revision: 9.1 $
*/
#include <sys/wait.h>
#include <signal.h>
#if defined REGCOMP
#include <regex.h>
#elif defined RE_COMP
extern char *re_comp(char *s);
extern char *re_exec(char *s);
#elif defined REGCMP
char *regcmp();
char *regex();
#else
#endif
#include "sc.h"
static inline int iswordchar(char c) { return isalnumchar(c) || c == '_'; }
static void write_line(sheet_t *sp, int c);
static void append_line(void);
static void back_hist(void);
static int back_line(int arg);
static int back_word(int arg, int big_word);
static void back_space(void);
static void change_case(int arg);
static void col_0(void);
static void cr_line(sheet_t *sp, int action);
static void del_in_line(int arg, int back_null);
static void del_to_end(void);
static void ins_string(sheet_t *sp, const char *s);
static void ins_in_line(sheet_t *sp, int c);
static void doabbrev(sheet_t *sp);
static void dogoto(sheet_t *sp);
static void dotab(sheet_t *sp);
static void dotcmd(sheet_t *sp);
static void doshell(sheet_t *sp);
static int find_char(sheet_t *sp, int start, int arg, int dir);
static void find_char2(sheet_t *sp, int arg, int dir);
static void forw_hist(void);
static int forw_line(int arg, int stop_null);
static int forw_word(int arg, int end_word, int big_word, int stop_null);
static int istart;
static void last_col(void);
static void match_paren(void);
static void rep_char(sheet_t *sp);
static void replace_in_line(int c);
static void replace_mode(void);
static void restore_it(void);
static void savedot(int c);
static void save_hist(void);
static void search_again(sc_bool_t reverse);
static void search_hist(void);
static void search_mode(char sind);
static void stop_edit(sheet_t *sp);
static int to_char(sheet_t *sp, int start, int arg, int dir);
static void u_save(int c);
static void yank_cmd(sheet_t *sp, int delete, int change);
static void yank_chars(int first, int last, int delete);
static int get_motion(sheet_t *sp, int change);
static int vigetch(sheet_t *sp);
static void colshow_op(sheet_t *sp);
static void rowshow_op(sheet_t *sp);
static int setmark(sheet_t *sp, int c); /* convert and set the mark and return index or complain and return -1 */
static int checkmark(int c); /* convert mark char to index or complain and return -1 */
static void markcell(sheet_t *sp);
static void dotick(sheet_t *sp, int tick);
static int get_rcqual(sheet_t *sp, int ch);
static void formatcol(sheet_t *sp, int arg);
static void edit_mode(void);
static void insert_mode(void);
static void toggle_navigate_mode(void);
static void startshow(sheet_t *sp);
static void showdr(sheet_t *sp);
static void list_all(sheet_t *sp);
static void mouse_set_pos(void);
static int mouse_sel_cell(sheet_t *sp);
/* used in update() in screen.c */
char line[FBUFLEN];
int linelim = -1; /* position in line for writing and parsing */
static int linelen = 0;
static int uarg = 1; /* universal numeric prefix argument */
static char *completethis = NULL;
static int search_dir; /* Search direction: forward = 0; back = 1 */
/* values for mode below */
#define INSERT_MODE 0 /* Insert mode */
#define EDIT_MODE 1 /* Edit mode */
#define REP_MODE 2 /* Replace mode */
#define SEARCH_MODE 3 /* Get arguments for '/' command */
#define NAVIGATE_MODE 4 /* Navigate the spreadsheet while editing a line */
#define DOTLEN 200
static int mode = INSERT_MODE;
static int help_topic = HELP_INTRO;
static SCXMEM string_t *history[HISTLEN + 1];
static int histp = 0;
static int lasthist = 0;
static int endhist = -1;
static int histsessionstart = 0;
static int histsessionnew = 0;
#if defined REGCOMP
static regex_t preg;
static regex_t *last_search = NULL;
static int errcode;
#elif defined RE_COMP
#elif defined REGCMP
static char *last_search = NULL; /* allocated with malloc() */
#else
static SCXMEM string_t *last_search = NULL;
#endif
static char undo_line[FBUFLEN];
static int undo_len;
static int undo_lim;
static char dotb[DOTLEN];
static int doti = 0;
static int do_dot = 0;
static int nosavedot = 1;
static int dotarg = 1;
static char putbuf[FBUFLEN];
static int findfunc = '\0';
static int findchar = 1;
static int finddir = 0;
static int numeric_field = 0; /* Started the line editing with a number */
static int cellassign;
int set_line(const char *fmt, ...) {
size_t len;
va_list ap;
va_start(ap, fmt);
// Prevent warning: format string is not a string literal [-Werror,-Wformat-nonliteral]
len = ((int (*)(char *, size_t, const char *, va_list))vsnprintf)
(line, sizeof line, fmt, ap);
va_end(ap);
if (len >= sizeof line)
len = strlen(line);
return linelim = linelen = len;
}
static void init_line(void) {
line[0] = '\0';
linelim = linelen = 0;
}
void vi_interaction(sheet_t *sp) {
int inloop = 1;
int c, ch2;
int narg;
int edistate = -1;
int nedistate;
int running;
int anychanged = FALSE;
char *ext;
struct ent *p;
buf_t buf;
sp->modflg = 0;
if (linelim < 0)
cellassign = 0;
uarg = 1;
while (inloop) {
running = 1;
while (running) {
sp = sht;
nedistate = -1;
narg = 1;
if (edistate < 0 && linelim < 0 && sp->autocalc && (changed || FullUpdate)) {
EvalAll(sp);
if (changed) /* if EvalAll changed or was before */
anychanged = TRUE;
changed = 0;
} else { /* any cells change? */
if (changed)
anychanged = TRUE;
//changed = 0; // XXX: should clear changed
}
update(sp, anychanged);
anychanged = FALSE;
#ifndef SYSV3 /* HP/Ux 3.1 this may not be wanted */
screen_refresh(); /* 5.3 does a refresh in getch */
#endif
c = nmgetch_savepos(1);
seenerr = 0;
showneed = 0; /* reset after each update */
showexpr = 0;
shownote = 0;
if (ISCTL(c) || c == DEL || c == SC_KEY_END || c == SC_KEY_BACKSPACE) {
switch (c) {
#ifdef SIGTSTP
case ctl('z'):
screen_deraw(1);
kill(0, SIGTSTP); /* Nail process group */
/* the pc stops here */
screen_goraw();
break;
#endif
case ctl('r'):
showneed = 1;
FALLTHROUGH;
case ctl('l'):
FullUpdate++;
screen_rebuild();
break;
case ctl('x'):
FullUpdate++;
showexpr = 1;
screen_rebuild();
break;
case ctl('b'):
if (emacs_bindings)
backcol(sp, uarg);
else
backpage(sp, uarg);
break;
case ctl('c'):
running = 0;
break;
case SC_KEY_END:
case ctl('e'):
if (linelim < 0 || mode_ind == 'v') {
switch (c = nmgetch(1)) {
case SC_KEY_UP:
case ctl('p'):
case 'k': doend(sp, -1, 0); break;
case SC_KEY_DOWN:
case ctl('n'):
case 'j': doend(sp, 1, 0); break;
case SC_KEY_LEFT:
case SC_KEY_BACKSPACE:
case ctl('h'):
case 'h': doend(sp, 0, -1); break;
case SC_KEY_RIGHT:
case ' ':
case ctl('i'):
case 'l': doend(sp, 0, 1); break;
case ctl('e'):
case ctl('y'):
while (c == ctl('e') || c == ctl('y')) {
int x = uarg;
while (uarg) {
if (c == ctl('e')) {
scroll_down(sp);
} else {
// XXX: Passing x seems incorrect
scroll_up(sp, x);
}
uarg--;
}
FullUpdate++;
update(sp, 0);
uarg = 1;
c = nmgetch(0);
}
nmungetch(c);
break;
case ESC:
case ctl('g'):
break;
default:
error("Invalid ^E command");
break;
}
} else {
write_line(sp, ctl('e'));
}
break;
case ctl('y'):
while (c == ctl('e') || c == ctl('y')) {
int x = uarg;
while (uarg) {
if (c == ctl('e')) {
scroll_down(sp);
} else {
// XXX: Passing x seems incorrect
scroll_up(sp, x);
}
uarg--;
}
FullUpdate++;
update(sp, 0);
uarg = 1;
c = nmgetch(0);
}
nmungetch(c);
break;
case ctl('f'):
if (emacs_bindings)
forwcol(sp, uarg);
else
forwpage(sp, uarg);
break;
case ctl('g'):
sp->showrange = 0;
linelim = -1;
screen_clear_line(1);
break;
case ESC: /* ctl('[') */
write_line(sp, ESC);
break;
case ctl('d'):
write_line(sp, ctl('d'));
break;
case SC_KEY_BACKSPACE:
case DEL:
case ctl('h'):
if (linelim < 0) /* not editing */
backcol(sp, uarg); /* treat like ^B */
else
write_line(sp, ctl('h'));
break;
case ctl('i'): /* tab */
if (linelim < 0) /* not editing */
forwcol(sp, uarg);
else
write_line(sp, ctl('i'));
break;
case ctl('m'):
case ctl('j'):
write_line(sp, ctl('m'));
break;
case ctl('n'):
if (numeric_field) {
// XXX: should avoid global variable hacking
c = sp->craction;
sp->craction = 0;
write_line(sp, ctl('m'));
sp->craction = c;
numeric_field = 0;
}
if (linelim < 0)
forwrow(sp, uarg);
else
write_line(sp, ctl('n'));
break;
case ctl('p'):
if (numeric_field) {
// XXX: should avoid global variable hacking
c = sp->craction;
sp->craction = 0;
write_line(sp, ctl('m'));
sp->craction = c;
numeric_field = 0;
}
if (linelim < 0)
backrow(sp, uarg);
else
write_line(sp, ctl('p'));
break;
case ctl('q'):
if (emacs_bindings) {
// XXX: just a test for function keys
error("Quote: ");
for (;;) {
c = nmgetch(1);
if (c == ctl('q') || c == ctl('m'))
break;
error("Quote: %d (%#x)\n", c, c);
}
break;
}
break; /* ignore flow control */
case ctl('s'):
if (emacs_bindings) {
// XXX: search
break;
}
break; /* ignore flow control */
case ctl('t'):
error("Toggle: a:auto,c:cell,e:ext funcs,n:numeric,p:protection,t:top,"
#ifndef NOCRYPT
"x:encrypt,"
#endif
"$:pre-scale,<MORE>");
if (braille) screen_move(1, 0);
screen_refresh();
switch (nmgetch(1)) {
case 'a': case 'A':
case 'm': case 'M':
sp->autocalc ^= 1;
error("Automatic recalculation %s.",
sp->autocalc ? "enabled" : "disabled");
break;
case 'b':
braille ^= 1;
error("Braille enhancement %s.",
braille ? "enabled" : "disabled");
--sp->modflg; /* negate the sp->modflg++ */
break;
case 'c':
repaint_cursor(sp, -showcell);
showcell = !showcell;
repaint_cursor(sp, showcell);
error("Cell highlighting %s.",
showcell ? "enabled" : "disabled");
--sp->modflg; /* negate the sp->modflg++ */
break;
case 'C':
sc_setcolor(!color);
error("Color %s.", color ? "enabled" : "disabled");
break;
case 'e':
sp->extfunc = !sp->extfunc;
error("External functions %s.",
sp->extfunc? "enabled" : "disabled");
break;
case 'E':
sp->colorerr = !sp->colorerr;
error("Color changing of cells with errors %s.",
sp->colorerr ? "enabled" : "disabled");
break;
case 'i': case 'I':
sp->autoinsert = !sp->autoinsert;
error("Autoinsert %s.",
sp->autoinsert? "enabled" : "disabled");
break;
case 'l': case 'L':
autolabel = !autolabel;
error("Autolabel %s.",
autolabel ? "enabled" : "disabled");
break;
case 'p':
sp->protect = !sp->protect;
error("Protect mode %s.",
sp->protect ? "enabled" : "disabled");
break;
case 'n':
sp->numeric = !sp->numeric;
error("Numeric input %s.",
sp->numeric ? "enabled" : "disabled");
break;
case 'N':
sp->colorneg = !sp->colorneg;
error("Color changing of negative numbers %s.",
sp->colorneg ? "enabled" : "disabled");
break;
case 'o': case 'O':
sp->optimize ^= 1;
error("%s expressions upon entry.",
sp->optimize ? "Optimize" : "Do not optimize");
break;
case 'r': case 'R':
error("Which direction after return key?");
switch (nmgetch(1)) {
case ctl('m'):
sp->craction = 0;
error("No action after new line");
break;
case 'j':
case ctl('n'):
case SC_KEY_DOWN:
sp->craction = CRROWS;
error("Down row after new line");
break;
case 'l':
case ' ':
case SC_KEY_RIGHT:
sp->craction = CRCOLS;
error("Right column after new line");
break;
case ESC:
case ctl('g'):
break;
default:
error("Not a valid direction");
}
break;
case 's':
sp->cslop ^= 1;
error("Color slop %s.",
sp->cslop ? "enabled" : "disabled");
break;
case 't': case 'T':
sp->showtop = !sp->showtop;
error("Top line %s.",
sp->showtop ? "enabled" : "disabled");
break;
case 'v':
emacs_bindings = !emacs_bindings;
error("Emacs %s.",
emacs_bindings ? "enabled" : "disabled");
break;
case 'w': case 'W':
sp->autowrap = !sp->autowrap;
error("Autowrap %s.",
sp->autowrap? "enabled" : "disabled");
break;
case 'x': case 'X':
#ifdef NOCRYPT
error("Encryption not available.");
#else
Crypt = !Crypt;
error("Encryption %s.", Crypt ? "enabled" : "disabled");
#endif
break;
case 'z': case 'Z':
sp->rowlimit = sp->currow;
sp->collimit = sp->curcol;
error("Row and column limits set");
break;
case '$':
if (sp->prescale == 1.0) {
error("Prescale enabled.");
sp->prescale = 0.01;
} else {
sp->prescale = 1.0;
error("Prescale disabled.");
}
break;
case ESC:
case ctl('g'):
--sp->modflg; /* negate the sp->modflg++ */
break;
default:
error("Invalid toggle command");
--sp->modflg; /* negate the sp->modflg++ */
}
FullUpdate++;
sp->modflg++;
break;
case ctl('u'):
narg = uarg * 4;
nedistate = 1;
break;
case ctl('v'): /* switch to navigate mode, or if already *
* in navigate mode, insert variable name */
if (linelim >= 0)
write_line(sp, ctl('v'));
else
if (emacs_bindings)
forwpage(sp, uarg);
break;
case ctl('w'): /* insert variable expression */
if (linelim >= 0) {
buf_init2(buf, line, sizeof line, linelen);
p = getcell(sp, sp->currow, sp->curcol);
/* decompile expression into line array */
// XXX: insert expression instead of appending?
// XXX: should pass sp->currow, sp->curcol as the cell reference
if (p && p->expr)
decompile_expr(sp, buf, p->expr, 0, 0, DCP_DEFAULT);
linelim = linelen = buf->len;
}
break;
case ctl('a'):
if (emacs_bindings) {
// XXX: goto beginning of row.
// repeated: goto A0
break;
}
if (linelim >= 0) {
write_line(sp, c);
} else {
remember(sp, 0);
// XXX: update strow/stcol?
sp->currow = 0;
sp->curcol = 0;
remember(sp, 1);
FullUpdate++;
}
break;
case '\035': /* ^] */
if (linelim >= 0)
write_line(sp, c);
break;
default:
error("No such command (^%c)", c + 0100);
break;
} /* End of the control char switch stmt */
} else
if (ISBYTE(c) && isdigit(c) &&
((!sp->numeric && linelim < 0) ||
(linelim >= 0 && (mode_ind == 'e' || mode_ind == 'v')) ||
edistate >= 0))
{
/* we got a leading number */
if (edistate != 0) {
/* First char of the count */
if (c == '0') { /* just a '0' goes to left col */
if (linelim >= 0)
write_line(sp, c);
else
leftlimit(sp);
} else {
nedistate = 0;
narg = c - '0';
}
} else {
/* Succeeding count chars */
nedistate = 0;
narg = uarg * 10 + (c - '0');
}
} else
if (c == SC_KEY_F(1) && sempty(sp->fkey[c - SC_KEY_F0])) {
#if 0
screen_deraw(1);
system("man sc");
screen_goraw();
screen_erase();
#else
help(help_topic);
#endif
} else
if (linelim >= 0) {
/* Editing line */
switch (c) {
case ')':
case ',':
if (sp->showrange)
showdr(sp);
break;
default:
break;
}
write_line(sp, c);
} else
if (c >= SC_KEY_F0 && c <= SC_KEY_F(FKEYS-1)) {
/* a function key was pressed */
if (!sempty(sp->fkey[c - SC_KEY_F0])) {
int i;
pstrcpy(line, sizeof line, s2c(sp->fkey[c - SC_KEY_F0]));
for (i = 0; line[i]; i++) {
// XXX: string should have been unescaped already
if (line[i] == '\\' && line[i+1] == '"') {
strsplice(line, sizeof line, i, 1, NULL, 0);
/* i++ will skip the '"' */
} else
if (line[i] == '$' && line[i+1] == '$') {
const char *s = cell_addr(sp, cellref_current(sp));
size_t len = strlen(s);
strsplice(line, sizeof line, i, 2, s, len);
/* i++ will skip the replacement string */
i += len - 1;
}
}
linelen = i;
linelim = 0;
insert_mode();
write_line(sp, ctl('m'));
}
} else {
/* switch on a normal command character */
switch (c) {
case '/':
if (linelim >= 0)
write_line(sp, c);
else
lotus_menu();
break;
case ':':
if (linelim >= 0)
write_line(sp, c);
break; /* Be nice to vi users */
case '@':
EvalAll(sp);
changed = 0; // XXX: questionable
anychanged = TRUE;
break;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '.':
if (!locked_cell(sp, sp->currow, sp->curcol)) {
set_line("let %s = %c", cell_addr(sp, cellref_current(sp)), c);
setmark(sp, '0');
numeric_field = 1;
cellassign = 1;
insert_mode();
}
break;
case '+':
case '-':
if (!locked_cell(sp, sp->currow, sp->curcol)) {
p = getcell(sp, sp->currow, sp->curcol);
if (!sp->numeric && p && p->type == SC_NUMBER) {
/* increment/decrement numeric cell by uarg */
if (c == '+')
p->v += (double)uarg;
else
p->v -= (double)uarg;
FullUpdate++;
sp->modflg++;
continue;
}
/* copy cell contents into line array */
buf_init(buf, line, sizeof line);
// XXX: the conversion should be localized
linelim = linelen = edit_cell(sp, buf, sp->currow, sp->curcol,
p, 0, 0, DCP_DEFAULT, 0);
setmark(sp, '0');
numeric_field = 1;
cellassign = 1;
insert_mode();
if (c == '-' || (p && p->flags == SC_NUMBER) || (p && p->expr))
write_line(sp, c);
else
write_line(sp, ctl('v'));
}
break;
case '=':
if (!locked_cell(sp, sp->currow, sp->curcol)) {
set_line("let %s = ", cell_addr(sp, cellref_current(sp)));
setmark(sp, '0');
cellassign = 1;
insert_mode();
}
break;
case '!':
doshell(sp);
break;
/*
* Range commands:
*/
case 'r':
error("Range: x:erase v:value c:copy f:fill d:def l:lock U:unlock S:show u:undef F:fmt");
if (braille) screen_move(1, 0);
screen_refresh();
switch (c = nmgetch(1)) {
case 'l':
set_line("lock [range] ");
insert_mode();
startshow(sp);
break;
case 'U':
set_line("unlock [range] ");
insert_mode();
startshow(sp);
break;
case 'c':
set_line("copy [dest_range src_range] ");
insert_mode();
startshow(sp);
break;
case 'm':
set_line("move [destination src_range] %s ", cell_addr(sp, cellref_current(sp)));
insert_mode();
write_line(sp, ctl('v'));
break;
case 'x':
set_line("erase [range] ");
insert_mode();
startshow(sp);
break;
case 'y':
set_line("yank [range] ");
insert_mode();
startshow(sp);
break;
case 'v':
set_line("value [range] ");
insert_mode();
startshow(sp);
break;
case 'f':
set_line("fill [range start inc] ");
insert_mode();
startshow(sp);
break;
case 'd':
set_line("define [string range] \"");
insert_mode();
break;
case 'u':
set_line("undefine [range] ");
insert_mode();
break;
case 'r':
error("frame (top/bottom/left/right/all/unframe)");
if (braille) screen_move(1, 0);
screen_refresh();
switch (c = nmgetch(1)) {
case 't':
set_line("frametop [<outrange> rows] ");
insert_mode();
break;
case 'b':
set_line("framebottom [<outrange> rows] ");
insert_mode();
break;
case 'l':
set_line("frameleft [<outrange> cols] ");
insert_mode();
break;
case 'r':
set_line("frameright [<outrange> cols] ");
insert_mode();
break;
case 'a':
set_line("frame [<outrange> inrange] ");
insert_mode();
startshow(sp);
break;
case 'u':
set_line("unframe [<range>] ");
insert_mode();
startshow(sp);
break;
case ESC:
case ctl('g'):
linelim = -1;
break;
default:
error("Invalid frame command");
linelim = -1;
break;
}
break;
case 's':
set_line("sort [range \"criteria\"] ");
insert_mode();
startshow(sp);
break;
case 'C':
set_line("color [range color#] ");
insert_mode();
startshow(sp);
break;
case 'S':
list_all(sp);
break;
case 'F':
set_line("fmt [range \"format\"] ");
insert_mode();
startshow(sp);
break;
case '{':
set_line("leftjustify [range] ");
insert_mode();
startshow(sp);
break;
case '}':
set_line("rightjustify [range] ");
cellassign = 1;
insert_mode();
startshow(sp);
break;
case '|':
set_line("center [range] ");
cellassign = 1;
insert_mode();
startshow(sp);
break;
case ESC:
case ctl('g'):
break;
default:
error("Invalid region command");
break;
}
break;
case '~':
set_line("abbrev \"");
insert_mode();
break;
case '"':
error("Select buffer (a-z or 0-9):");
c = nmgetch(1);
if (c == ESC || c == ctl('g')) {
break;
} else {
select_register(c);
}
break;
/*
* Row/column commands:
*/
case SC_KEY_IC:
case 'i':
case 'o':
case 'a':
case 'd':
case 'y':
case 'p':
case 'v':
case 's':
case 'Z':
{
if (!(ch2 = get_rcqual(sp, c))) {
error("Invalid row/column command");
break;
}
if (ch2 == ESC || ch2 == ctl('g'))
break;
switch (c) {
case 'i':
if (ch2 == 'r') insert_rows(sp, cellref_current(sp), uarg, 0);
else insert_cols(sp, cellref_current(sp), uarg, 0);
break;
case 'o':
if (ch2 == 'r') sp->currow += insert_rows(sp, cellref_current(sp), uarg, 1);
else sp->curcol += insert_cols(sp, cellref_current(sp), uarg, 1);
break;
case 'a':
if (ch2 == 'r') while (uarg --> 0 && dup_row(sp, cellref_current(sp)))
sp->currow++;
else while (uarg --> 0 && dup_col(sp, cellref_current(sp)))
sp->curcol++;
break;
case 'd':
if (ch2 == 'r') delete_rows(sp, sp->currow, sp->currow + uarg - 1);
else delete_cols(sp, sp->curcol, sp->curcol + uarg - 1);
break;
case 'y':
if (ch2 == 'r') yank_rows(sp, sp->currow, sp->currow + uarg - 1);
else yank_cols(sp, sp->curcol, sp->curcol + uarg - 1);
break;
case 'p':
if (ch2 == '.') {
// XXX: should handle uarg
set_line("pullcopy [range] ");
insert_mode();
startshow(sp);
break;
}
cmd_pullcells(sp, ch2, uarg);
break;
/*
* turn an area starting at sp->currow/sp->curcol into
* constants vs expressions - non reversible
*/
case 'v':
// XXX: 'v.' should get a range for the "value" cmd
if (ch2 == 'r') {
int c1 = 0, c2 = sp->maxcol;
struct frange *fr;
if ((fr = frange_get_current(sp))) {
c1 = fr->orr.left.col;
c2 = fr->orr.right.col;
}
valueize_area(sp, rangeref(sp->currow, c1, sp->currow + uarg - 1, c2));
} else {
valueize_area(sp, rangeref(0, sp->curcol, sp->maxrow, sp->curcol + uarg - 1));
}
break;
case 'Z':
switch (ch2) {
case 'r': hiderows(sp, sp->currow, sp->currow + uarg - 1); break;
case 'c': hidecols(sp, sp->curcol, sp->curcol + uarg - 1); break;