-
Notifications
You must be signed in to change notification settings - Fork 26
/
vi.c
1979 lines (1804 loc) · 60 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
/* vi.c */
/* Copyright 1995 by Steve Kirkendall */
#include "elvis.h"
#ifdef FEATURE_RCSID
char id_vi[] = "$Id: vi.c,v 2.96 2004/03/07 21:38:21 steve Exp $";
#endif
#if USE_PROTOTYPES
static RESULT parse(_CHAR_ key, void *info);
static ELVCURSOR shape(WINDOW win);
# ifdef FEATURE_TEXTOBJ
static long indentation(WINDOW win, long line);
static RESULT vixmlobj(WINDOW win, VIINFO *vinf, MARKBUF *from, MARKBUF *to);
# endif
#endif
/* This is a list of operator commands. Note that 'g' commands are denoted by
* setting the 8th bit of the character, so \365 is gu, \325 is gU, \376 is g~,
* and \275 is g=.
*/
#define OPERATORS "cdy<=>!\275\365\325\376"
/* This is a list of letters and control characters that can be used as the
* 2nd key in a text object's name. In addition to the characters listed here,
* elvis always allows any punctuation character to be used -- as a field
* delimiter if nothing else.
*/
#define TEXTOBJECTS "BLSWXblpstwx\n"
/* These variables store the command which <.> is supposed to repeat.
* If the command is supposed to switch to input mode, then those
* commands will be smart enough to behave differently when executed
* for the <.> command. They'll paste from the "Elvis previous input"
* buffer.
*/
VIINFO dotcmd; /* the command itself, already parsed */
ELVBOOL dotviz; /* was the dotcmd used as a visible operator? */
long dotlines;/* number of lines for visible operator, or 0L if char/rect */
/* These are the "when" conditions in the array below */
#define WHEN_SEL 0x0001 /* legal while text is selected */
#define WHEN_ONCE 0x0002 /* legal during ^O */
#define WHEN_OPEN 0x0004 /* legal in "open" mode */
#define WHEN_HIST 0x0008 /* legal in "history" buffers */
#define WHEN_MOVE 0x0010 /* legal as target of an operator */
#define WHEN_ANY 0x001f /* all of the above */
#define WHEN_NEVER 0x0000 /* none of the above */
#define WHEN_MORE 0x0020 /* legal as part of a "more" invocation */
#define WHEN_EMPTY 0x0040 /* legal when buffer is empty */
#define WHEN_SEL_ONCE (WHEN_SEL|WHEN_ONCE)
#define WHEN_ONCE_OPEN (WHEN_ONCE|WHEN_OPEN)
#define WHEN_ONCE_OPEN_HIST (WHEN_ONCE|WHEN_OPEN|WHEN_HIST)
#define WHEN_SEL_ONCE_OPEN_HIST (WHEN_SEL|WHEN_ONCE|WHEN_OPEN|WHEN_HIST)
#define WHEN_SEL_ONCE_OPEN (WHEN_SEL|WHEN_ONCE|WHEN_OPEN)
#define WHEN_SEL_ONCE_MOVE (WHEN_SEL|WHEN_ONCE|WHEN_MOVE)
#define WHEN_SEL_ONCE_OPEN_MOVE (WHEN_SEL|WHEN_ONCE|WHEN_OPEN|WHEN_MOVE)
#define WHEN_SEL_ONCE_HIST_MOVE (WHEN_SEL|WHEN_ONCE|WHEN_HIST|WHEN_MOVE)
#define WHEN_OPEN_HIST (WHEN_OPEN|WHEN_HIST)
/* This array describes each command */
static struct
{
RESULT (*func) P_((WINDOW win, VIINFO *vinf));
unsigned short when; /* when command is legal */
unsigned short tweak; /* misc features */
char *helptopic; /* label in "elvisvi.html" */
}
vikeys[] =
{
/* NUL not defined */ { NULL, WHEN_NEVER, TWEAK_NONE, "nul" },
/* ^A search for word */ { m_search, WHEN_ANY, TWEAK_MARK },
/* ^B page backward */ { m_scroll, WHEN_SEL_ONCE, TWEAK_FRONT },
/* ^C not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* ^D scroll dn 1/2page */ { m_scroll, WHEN_SEL_ONCE_OPEN, TWEAK_FIXCOL },
/* ^E scroll up */ { m_scroll, WHEN_SEL_ONCE, TWEAK_FIXCOL },
/* ^F page forward */ { m_scroll, WHEN_SEL_ONCE, TWEAK_FRONT },
/* ^G show file status */ { m_absolute, WHEN_SEL_ONCE_OPEN|WHEN_EMPTY, TWEAK_NONE },
/* ^H move left, like h */ { m_left, WHEN_ANY, TWEAK_NONE },
/* ^I move to next tag */ { m_tag, WHEN_ONCE_OPEN, TWEAK_NONE },
/* ^J move down */ { m_updown, WHEN_ANY, TWEAK_IGNCOL_INCL_LINE },
/* ^K find misspelled */ { m_spell, WHEN_NEVER, TWEAK_NONE },
/* ^L redraw screen */ { v_expose, WHEN_SEL_ONCE|WHEN_EMPTY, TWEAK_NONE },
/* ^M mv front next ln */ { m_updown, WHEN_ANY, TWEAK_FRONT_INCL_LINE },
/* ^N move down */ { m_updown, WHEN_ANY, TWEAK_IGNCOL_INCL_LINE },
/* ^O ignored */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* ^P move up */ { m_updown, WHEN_ANY, TWEAK_IGNCOL_INCL_LINE },
/* ^Q not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* ^R redo change */ { v_undo, WHEN_ONCE_OPEN|WHEN_EMPTY, TWEAK_NONE },
/* ^S not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* ^T pop tagstack */ { v_tag, WHEN_OPEN|WHEN_EMPTY, TWEAK_NONE },
/* ^U scroll up 1/2page */ { m_scroll, WHEN_SEL_ONCE_OPEN, TWEAK_FIXCOL },
/* ^V start visible */ { v_visible, WHEN_SEL_ONCE, TWEAK_LINE },
/* ^W window operations */ { v_window, WHEN_SEL_ONCE_OPEN_HIST|WHEN_EMPTY,TWEAK_NONE },
/* ^X move to phys col */ { m_column, WHEN_SEL_ONCE_OPEN_HIST|WHEN_MOVE,TWEAK_IGNCOL_MARK },
/* ^Y scroll down */ { m_scroll, WHEN_SEL_ONCE, TWEAK_FIXCOL },
/* ^Z stop process */ { v_notex, WHEN_ANY, TWEAK_NONE },
/* ESC end visible mark */ { v_visible, WHEN_SEL, TWEAK_NONE, "^obra" },
/* ^\ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE, "^bksl" },
/* ^] keyword is tag */ { v_tag, WHEN_ONCE_OPEN, TWEAK_NONE, "^cbra" },
/* ^^ previous file */ { v_notex, WHEN_ONCE_OPEN|WHEN_EMPTY, TWEAK_FRONT },
/* ^_ move to row */ { NULL, WHEN_SEL_ONCE, TWEAK_FIXCOL_INCL },
/* SPC move right,like l */ { m_right, WHEN_ANY, TWEAK_NONE, "l" },
/* ! run thru filter */ { NULL, WHEN_NEVER, TWEAK_FRONT_LINE_DOT_OPER_UNDO, "bang" },
/* " select cut buffer */ { NULL, 0,/* This is handled by the command parser */0, "quote" },
/* # increment number */ { v_number, WHEN_ONCE_OPEN_HIST, TWEAK_DOT_UNDO, "hash" },
/* $ move to rear */ { m_column, WHEN_ANY, TWEAK_IGNCOL_INCL, "dollar"},
/* % move to match */ { m_absolute, WHEN_ANY, TWEAK_INCL, "pct" },
/* & repeat subst */ { v_notex, WHEN_NEVER, TWEAK_FIXCOL_INCL_LINE_DOT_UNDO, "amp"},
/* ' move to a mark */ { m_mark, WHEN_SEL_ONCE_OPEN_MOVE, TWEAK_FRONT_INCL_MARK_LINE, "apost"},
/* ( mv back sentence */ { m_bsentence, WHEN_ANY, TWEAK_NONE, "open" },
/* ) mv fwd sentence */ { m_fsentence, WHEN_ANY, TWEAK_NONE, "close" },
/* * errlist */ { v_notex, WHEN_OPEN|WHEN_EMPTY, TWEAK_FRONT, },
/* + mv front next ln */ { m_updown, WHEN_ANY, TWEAK_FRONT_INCL_LINE, },
/* , reverse [fFtT] cmd*/ { m_csearch, WHEN_ANY, TWEAK_INCL, "comma" },
/* - mv front prev ln */ { m_updown, WHEN_ANY, TWEAK_FRONT_INCL_LINE },
/* . special... */ { NULL, 0,/* This is handled by the command parser */0, "stop" },
/* / forward search */ { m_search, WHEN_ANY|WHEN_MORE, TWEAK_MARK, "slash" },
/* 0 part of count? */ { m_column, WHEN_ANY, TWEAK_IGNCOL_MARK },
/* 1 part of count */ { NULL /* This is handled by the command parser */ },
/* 2 part of count */ { NULL /* This is handled by the command parser */ },
/* 3 part of count */ { NULL /* This is handled by the command parser */ },
/* 4 part of count */ { NULL /* This is handled by the command parser */ },
/* 5 part of count */ { NULL /* This is handled by the command parser */ },
/* 6 part of count */ { NULL /* This is handled by the command parser */ },
/* 7 part of count */ { NULL /* This is handled by the command parser */ },
/* 8 part of count */ { NULL /* This is handled by the command parser */ },
/* 9 part of count */ { NULL /* This is handled by the command parser */ },
/* : run single EX cmd */ { v_ex, WHEN_SEL_ONCE_OPEN_HIST|WHEN_EMPTY, TWEAK_NONE, "colon" },
/* ; repeat [fFtT] cmd */ { m_csearch, WHEN_ANY, TWEAK_INCL, "semi" },
/* < shift text left */ { NULL, WHEN_OPEN, TWEAK_FRONT_LINE_DOT_OPER_UNDO,"lt"},
/* = preset filter */ { NULL, WHEN_OPEN, TWEAK_DOT_OPER_UNDO },
/* > shift text right */ { NULL, WHEN_OPEN, TWEAK_FRONT_LINE_DOT_OPER_UNDO,"gt"},
/* ? backward search */ { m_search, WHEN_ANY|WHEN_MORE, TWEAK_MARK, "quest" },
/* @ execute a cutbuf */ { v_at, WHEN_SEL_ONCE_OPEN_HIST|WHEN_EMPTY,TWEAK_NONE, "at" },
/* A append at EOL */ { v_input, WHEN_ONCE_OPEN_HIST|WHEN_EMPTY|WHEN_MORE, TWEAK_DOT_UNDO },
/* B move back Word */ { m_bigword, WHEN_ANY, TWEAK_NONE },
/* C change to EOL */ { v_notop, WHEN_OPEN, TWEAK_DOT_UNDO },
/* D delete to EOL */ { v_notop, WHEN_OPEN, TWEAK_DOT_UNDO },
/* E move end of Word */ { m_bigword, WHEN_ANY, TWEAK_INCL },
/* F move bk to char */ { m_csearch, WHEN_ANY, TWEAK_INCL },
/* G move to line # */ { m_absolute, WHEN_ANY, TWEAK_FRONT_INCL_MARK_LINE },
/* H move to row */ { m_scrnrel, WHEN_SEL_ONCE_MOVE, TWEAK_FRONT_INCL_LINE },
/* I insert at front */ { v_input, WHEN_ONCE_OPEN_HIST|WHEN_EMPTY|WHEN_MORE, TWEAK_DOT_UNDO },
/* J join lines */ { v_notex, WHEN_ONCE_OPEN, TWEAK_DOT_UNDO },
/* K look up keyword */ { v_notex, WHEN_OPEN, TWEAK_NONE },
/* L move to last row */ { m_scrnrel, WHEN_SEL_ONCE_MOVE, TWEAK_FRONT_INCL_LINE },
/* M move to mid row */ { m_scrnrel, WHEN_SEL_ONCE_MOVE, TWEAK_FRONT_INCL_LINE },
/* N reverse prev srch */ { m_search, WHEN_ANY, TWEAK_MARK },
/* O insert above line */ { v_input, WHEN_ONCE_OPEN_HIST|WHEN_EMPTY|WHEN_MORE, TWEAK_DOT_UNDO },
/* P paste before */ { v_paste, WHEN_ONCE_OPEN_HIST|WHEN_EMPTY, TWEAK_DOT_UNDO },
/* Q quit to EX mode */ { v_ex, WHEN_OPEN|WHEN_EMPTY, TWEAK_NONE },
/* R overtype */ { v_input, WHEN_ONCE_OPEN_HIST|WHEN_MORE, TWEAK_DOT_UNDO },
/* S change line */ { v_notop, WHEN_OPEN, TWEAK_DOT_UNDO },
/* T move bk to char */ { m_csearch, WHEN_ANY, TWEAK_INCL },
/* U undo whole line */ { v_undo, WHEN_OPEN_HIST|WHEN_EMPTY, TWEAK_FRONT_UNDO },
/* V start visible */ { v_visible, WHEN_SEL_ONCE_OPEN, TWEAK_LINE },
/* W move forward Word */ { m_bigword, WHEN_ANY, TWEAK_NONE },
/* X delete to left */ { v_delchar, WHEN_ONCE_OPEN_HIST, TWEAK_DOT_UNDO },
/* Y yank text */ { v_notop, WHEN_OPEN, TWEAK_NONE },
/* Z save file & exit */ { v_quit, WHEN_ONCE_OPEN|WHEN_EMPTY, TWEAK_NONE },
/* [ move back section */ { m_bsection, WHEN_ANY, TWEAK_MARK, "obra" },
/* \ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE, "bksl" },
/* ] move fwd section */ { m_fsection, WHEN_ANY, TWEAK_MARK, "cbra" },
/* ^ move to front */ { m_front, WHEN_ANY, TWEAK_NONE },
/* _ current line */ { m_updown, WHEN_ANY, TWEAK_FRONT_INCL_LINE },
/* ` move to mark */ { m_mark, WHEN_SEL_ONCE_OPEN_MOVE, TWEAK_MARK, "grave" },
/* a append at cursor */ { v_input, WHEN_OPEN_HIST|WHEN_EMPTY|WHEN_MORE, TWEAK_DOT_UNDO },
/* b move back word */ { m_word, WHEN_ANY, TWEAK_NONE },
/* c change text */ { NULL, WHEN_OPEN, TWEAK_DOT_OPER_UNDO },
/* d delete op */ { NULL, WHEN_OPEN, TWEAK_DOT_OPER_UNDO },
/* e move end word */ { m_word, WHEN_ANY, TWEAK_INCL },
/* f move fwd for char */ { m_csearch, WHEN_ANY, TWEAK_INCL },
/* g command prefix */ { NULL /* This is handled by the command parser */ },
/* h move left */ { m_left, WHEN_ANY, TWEAK_NONE },
/* i insert at cursor */ { v_input, WHEN_ONCE_OPEN_HIST|WHEN_EMPTY|WHEN_MORE, TWEAK_DOT_UNDO|TWEAK_IGNCOL },
/* j move down */ { m_updown, WHEN_ANY, TWEAK_IGNCOL_INCL_LINE },
/* k move up */ { m_updown, WHEN_ANY, TWEAK_IGNCOL_INCL_LINE },
/* l move right */ { m_right, WHEN_ANY, TWEAK_NONE },
/* m define a mark */ { v_setmark, WHEN_ONCE_OPEN|WHEN_OPEN, TWEAK_NONE },
/* n repeat prev srch */ { m_search, WHEN_ANY, TWEAK_MARK },
/* o insert below line */ { v_input, WHEN_OPEN_HIST|WHEN_EMPTY|WHEN_MORE, TWEAK_DOT_UNDO },
/* p paste after */ { v_paste, WHEN_ONCE_OPEN_HIST, TWEAK_DOT_UNDO },
/* q not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* r replace chars */ { v_delchar, WHEN_ONCE_OPEN_HIST, TWEAK_DOT_UNDO },
/* s subst N chars */ { v_notop, WHEN_OPEN, TWEAK_DOT_UNDO },
/* t move fwd to char */ { m_csearch, WHEN_ANY, TWEAK_INCL },
/* u undo */ { v_undo, WHEN_ONCE_OPEN|WHEN_EMPTY, TWEAK_NONE },
/* v start visible */ { v_visible, WHEN_SEL_ONCE_OPEN, TWEAK_NONE },
/* w move fwd word */ { m_word, WHEN_ANY, TWEAK_NONE },
/* x delete character */ { v_delchar, WHEN_ONCE_OPEN_HIST, TWEAK_DOT_UNDO },
/* y yank text */ { NULL, WHEN_OPEN, TWEAK_OPER },
/* z adjust scrn row */ { m_z, WHEN_SEL_ONCE, TWEAK_FIXCOL },
/* { back paragraph */ { m_bsection, WHEN_ANY, TWEAK_NONE, "ocur" },
/* | move to column */ { m_column, WHEN_ANY, TWEAK_IGNCOL_MARK, "bar" },
/* } fwd paragraph */ { m_fsection, WHEN_ANY, TWEAK_NONE, "ccur" },
/* ~ upper/lowercase */ { v_delchar, WHEN_ONCE_OPEN_HIST, TWEAK_DOT_UNDO },
/* DEL not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/****************************************************************************************************************/
/* gNUL not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^A not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^B not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^C not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^D not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^E not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^F not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^G not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^H not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^I move to prev tag */ { m_tag, WHEN_ONCE_OPEN, TWEAK_NONE },
/* g^J not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^K not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^L not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^M not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^N not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^O not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^P not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^Q not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^R not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^S not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^T not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^U not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^V opposite sel end */ { v_visible, WHEN_SEL, TWEAK_FIXCOL },
/* g^W not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^X not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^Y not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^Z not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gESC not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^\ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^] not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^^ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^_ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gSPC not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g! not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g" not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g# not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g$ move to row rear */ { m_g, WHEN_ANY, TWEAK_IGNCOL_INCL },
/* g% opposite sel end */ { v_visible, WHEN_SEL, TWEAK_FIXCOL },
/* g& not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g' not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g( not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g) not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g* not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g+ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g, not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g- not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g. not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g/ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g0 not defined */ { m_g, WHEN_ANY, TWEAK_IGNCOL_MARK },
/* g1 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g2 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g3 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g4 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g5 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g6 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g7 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g8 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g9 not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g: not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g; not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g< not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g= replace char op */ { NULL, WHEN_OPEN, TWEAK_DOT_OPER_UNDO },
/* g> not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g? not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g@ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gA not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gB not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gC not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gD find global def */ { m_search, WHEN_ANY, TWEAK_MARK },
/* gE not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gF not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gG not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gH not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gI insert at front */ { v_input, WHEN_ONCE_OPEN_HIST|WHEN_EMPTY|WHEN_MORE, TWEAK_DOT_UNDO },
/* gJ join lines */ { v_notex, WHEN_ONCE_OPEN, TWEAK_DOT_UNDO },
/* gK not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gL not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gM not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gN not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gO not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gP not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gQ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gR not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gS not defined */ { m_endspell, WHEN_ANY, TWEAK_INCL },
/* gT not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gU make uppercase op */ { NULL, WHEN_OPEN, TWEAK_DOT_OPER_UNDO },
/* gV not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gW not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gX not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gY not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gZ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g[ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g\ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g] not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g^ move to row front */ { m_g, WHEN_ANY, TWEAK_NONE },
/* g_ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g` not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* ga not defined */ { v_ascii, WHEN_ONCE_OPEN, TWEAK_NONE },
/* gb not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gc not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gd find local def */ { m_search, WHEN_ANY, TWEAK_MARK },
/* ge not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gf not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gg not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gh not defined */ { m_g, WHEN_ANY, TWEAK_NONE },
/* gi not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gj not defined */ { m_gupdown, WHEN_ANY, TWEAK_IGNCOL_INCL_LINE },
/* gk not defined */ { m_gupdown, WHEN_ANY, TWEAK_IGNCOL_INCL_LINE },
/* gl not defined */ { m_g, WHEN_ANY, TWEAK_NONE },
/* gm not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gn not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* go not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gp not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gq not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gr not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gs find misspelled */ { m_spell, WHEN_NEVER, TWEAK_NONE },
/* gt not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gu make lowercase op */ { NULL, WHEN_OPEN, TWEAK_DOT_OPER_UNDO },
/* gv not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gw not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gx not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gy not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* gz not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g{ not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g| not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g} not defined */ { NULL, WHEN_NEVER, TWEAK_NONE },
/* g~ toggle case op */ { NULL, WHEN_OPEN, TWEAK_DOT_OPER_UNDO },
/* gDEL not defined */ { NULL, WHEN_NEVER, TWEAK_NONE }
};
#ifdef FEATURE_TEXTOBJ
/* Return the indentation width (number of columns, after expanding tabs) for
* a given line number. For empty lines, return -1. This is used for the 'L'
* indentation blocks.
*/
static long indentation(win, line)
WINDOW win; /* buffer */
long line; /* line number */
{
long width;
BUFFER buf = markbuffer(win->cursor);
MARKBUF m;
CHAR *cp;
/* start counting from the beginning of the line */
scanalloc(&cp, marktmp(m, buf, lowline(bufbufinfo(buf), line)));
width = 0;
/* count the spaces and tabs */
while (*cp && *cp != '\n' && elvspace(*cp))
{
if (*cp == ' ')
width++;
else if (*cp == '\t')
width += opt_totab(o_tabstop(buf), width);
scannext(&cp);
}
/* if empty line, then width = -1 */
if (!cp || *cp == '\n'
#ifdef DISPLAY_SYNTAX
|| *cp == dmspreprocessor(win)
#endif
)
width = -1;
/* clean up, and return the width */
scanfree(&cp);
return width;
}
/* Find the endpoints for an XML object, delimited by <tag>...</tag> pairs.
* This function should only be called from the vitextobj() function.
*/
static RESULT vixmlobj(win, vinf, from, to)
WINDOW win; /* window where the command is to be run */
VIINFO *vinf; /* identifies the type of text object */
MARKBUF *from; /* output: move this mark to top of affected text */
MARKBUF *to; /* output: move this mark to bottom of affected text */
{
CHAR *scan, *intag;
CHAR prev;
CHAR *name = NULL, *inname;
int nest;
ELVBOOL slash;
MARKBUF middle;
static struct xmlstack_s
{
struct xmlstack_s *next;
CHAR *name;
} *stack = NULL, *st;
DEFAULT(1);
/* start scanning at cursor */
scanalloc(&scan, win->cursor);
/* Adjust the scanning point. If in a </tag> then we want to start
* at its "<". If in a <tag> then we want to start after the "<".
* Otherwise it doesn't matter much, so go back to the cursor position.
*/
while (scan && *scan != '<' && scanprev(&scan) && *scan != '>')
{
}
if (!scan || *scan != '<')
scanseek(&scan, win->cursor);
else if (scannext(&scan) && *scan == '/')
scanprev(&scan);
/* scan forward for the count'th unmatched "</". This is tricky!
* Not all XML tags come in pairs, so we can't simply count tags with
* and without slashes. We must push <tag> names onto a stack, and
* pop them when we get a </tag>. To handle unpaired tags, </tag>
* should always pop back to the matching name; or, if there is no
* name, then the match must be before the cursor so WE'RE IN THAT
* TAG PAIR! THAT'S ONE OF THE TAGS WE SHOULD COUNT!
*/
for (prev = *scan, nest = vinf->count; nest > 0; prev = *scan)
{
/* we scan pairs of characters -- one in "prev" and one at
* "*scan". We already have "prev", but now we need to
* increment the scan pointer.
*/
if (!scannext(&scan))
goto Fail;
/* Is this the start of a tag? */
if (prev == '<')
{
/* Remember the location of the "<". If this turns out
* to be the ending tag for an ix object, we'll need it.
*/
*to = *scanmark(&scan);
to->offset--;
middle = *to;
/* detect a slash */
slash = (ELVBOOL)(*scan == '/');
if (slash)
if (!scannext(&scan)) goto Fail ;
/* collect chars of the name */
assert(name == NULL);
for (;
scan && (elvalnum(*scan) ||
*scan == ':' ||
(*scan == '-' && prev != '-'));
scannext(&scan))
{
buildCHAR(&name, vinf->key2 == 'X' ? elvtolower(*scan) : *scan);
prev = *scan;
}
if (scan && *scan == '-')
{
scanprev(&scan);
name[CHARlen(name) - 1] = '\0';
}
if (!scan || !name)
goto Fail;
/* if slash, pop to match. If no match decrement nest*/
if (slash)
{
/* pop any tags that don't nest properly */
while (stack && CHARcmp(stack->name, name))
{
st = stack;
stack = st->next;
safefree(st->name);
safefree(st);
}
/* did we find a match? */
if (stack)
{
/* pop the match too. */
st = stack;
stack = st->next;
safefree(st->name);
safefree(st);
/* free the name */
safefree(name);
name = NULL;
}
else /* must extend back past the cursor */
{
nest--;
/* free the name, unless this is
* the tag we want.
*/
if (nest > 0)
{
safefree(name);
name = NULL;
}
}
}
else /* push onto stack */
{
st = (struct xmlstack_s *)safealloc(1, sizeof *st);
st->name = name;
st->next = stack;
stack = st;
name = NULL;
}
}
}
/* if "ax" object, remember where it ends to help find the right end */
if (vinf->command == 'a')
*to = *scanmark(&scan);
/* Scan backward for the starting tag, skipping over nested pairs.
* This is easier than the search for the ending tag, because now we
* only need to worry about nested pairs of THAT PARTICULAR TAG NAME.
*/
scanseek(&scan, &middle);
for (nest = 1; scan && nest > 0; )
{
if (!scanprev(&scan))
goto Fail;
if (*scan != '<')
continue;
/* we're at the start of a tag. See if it's a starter or not */
scandup(&intag, &scan);
scannext(&intag);
slash = (ELVBOOL)(*intag == '/');
if (slash)
scannext(&intag);
/* does the name match? */
inname = name;
if (vinf->key2 == 'X')
while (*inname && *inname++ == elvtolower(*intag))
scannext(&intag);
else
while (*inname && *inname++ == *intag)
scannext(&intag);
/* !!! Note: the following if() statement isn't quite right.
* It doesn't handle - correctly. Consequently </tag> may
* be paired up with <tag-long-name>, provided there is no
* </tag-long-name> between them.
*/
if (!*inname && (!intag || !(elvalnum(*intag)||*intag == ':')))
{
/* yes, the name matches -- adjust nest */
if (slash)
nest++;
else
nest--;
}
scanfree(&intag);
}
/* now we can compute the endpoints */
if (vinf->command == 'i')
{
/* skip to the end of the starting tag */
while (*scan != '>')
if (!scannext(&scan)) goto Fail;
/* this is probably the start of the inner tag */
*from = *scanmark(&scan);
from->offset++;
/* skip any spaces and tabs */
do
{
if (!scannext(&scan)) goto Fail;
} while (*scan == ' ' || *scan == '\t');
/* if we hit a newline, then starting point is after newline */
if (*scan == '\n')
{
scannext(&scan);
*from = *scanmark(&scan);
}
/* Go back to the "<" of the ending tag. This is probably the
* end of the inner tag.
*/
scanseek(&scan, to);
/* skip backward past any spaces and tabs */
while (scanprev(&scan) && (*scan == ' ' || *scan == '\t'))
{
}
/* if we hit a newline, then that's the real end of the object*/
if (scan && *scan == '\n')
{
*to = *scanmark(&scan);
to->offset++;
}
}
else /* vinf->command == 'a' */
{
/* The "<" of the start tag is the start of the object */
*from = *scanmark(&scan);
/* go back to the ending tag */
scanseek(&scan, to);
/* scan forward for the ">" at the end of that tag */
while (*scan != '>')
if (!scannext(&scan)) goto Fail;
/* This is the end of the object */
*to = *scanmark(&scan);
to->offset++;
}
/* if the endpoints would be the same, then fail */
if (from->offset >= to->offset)
goto Fail;
/* success! */
safefree(name);
scanfree(&scan);
return RESULT_COMPLETE;
Fail:
if (name)
safefree(name);
scanfree(&scan);
while (stack)
{
st = stack;
stack = st->next;
safefree(st->name);
safefree(st);
}
return RESULT_ERROR;
}
/* Find the endpoints of a text object. The "from" and "to" parameters should
* pointers to MARKBUF structures -- not dynamically allocated MARKs! Returns
* RESULT_COMPLETE normally, RESULT_MORE if only the "from" end could be found,
* or RESULT_ERROR if neither end could be found or the text object is not
* understood.
*/
RESULT vitextobj(win, vinf, from, to)
WINDOW win; /* window where the command is to be run */
VIINFO *vinf; /* identifies the type of text object */
MARKBUF *from; /* output: move this mark to top of affected text */
MARKBUF *to; /* output: move this mark to bottom of affected text */
{
CHAR *oldmatchchar;
RESULT result = RESULT_COMPLETE;
BUFFER buf;
CHAR *scan;
long count;
VIINFO cmd; /* simulated command, to find characters */
CHAR fromkey;/* keystroke used to find top of object */
CHAR tokey; /* keystroke used to find top of next object */
CHAR opposite;/* for block delimiters, this is the other delimiter */
CHAR prev; /* previously scanned character */
MARKBUF tmp;
long cursoff;
long ln, fromln, in, nextin;
/* if the buffer is empty, then there can't be any text object */
buf = markbuffer(win->cursor);
if (o_buflines(buf) == 0L)
return RESULT_ERROR;
/* temporarily change matchchar to a hardcoded value so we can handle
* blocks in a consistent way.
*/
oldmatchchar = o_matchchar;
o_matchchar = toCHAR("{}[]()<>");
/* change b, B, or l to the equivelent block or field delimiter */
if (vinf->key2 == 'b')
vinf->key2 = '(';
else if (vinf->key2 == 'B')
vinf->key2 = '{';
else if (vinf->key2 == 'l')
vinf->key2 = '\n';
else if (vinf->key2 == 't')
vinf->key2 = '\t';
/* if block delimiter, then find its opposite */
for (scan = o_matchchar, opposite = '\0'; !opposite && *scan; scan += 2)
if (scan[0] == vinf->key2)
opposite = scan[1];
else if (scan[1] == vinf->key2)
opposite = scan[0];
/* for now, assume we won't need fromkey/tokey */
fromkey = tokey = '\0';
/* "from" and "to" buffers are in the window's buffer */
from->buffer = to->buffer = buf;
/* the default count is always 1, for all types of text object */
DEFAULT(1);
/* handle each type of object separately */
switch (vinf->key2)
{
case '{':
case '[':
case '(':
case '<':
case '%':
/* search backward for nth character */
scanalloc(&scan, win->cursor);
if (vinf->key2 != '%')
{
for (count = vinf->count, prev = ' '; ; )
{
if (*scan == vinf->key2)
count--;
else if (*scan == '\n' && prev == vinf->key2)
break;
prev = *scan;
if (count == 0 || !scanprev(&scan))
break;
if (*scan == opposite)
count++;
}
}
else /* % */
{
for (count = vinf->count, prev = ' '; ; )
{
if (*scan=='(' || *scan=='{' || *scan=='[')
count--;
else if (*scan == '\n' &&
(prev=='(' || prev=='{' || prev=='['))
break;
prev = *scan;
if (count == 0 || !scanprev(&scan))
break;
if (*scan==')' || *scan=='}' || *scan==']')
count++;
}
}
if (count > 0L)
{
/* oops, there was no such character */
result = RESULT_ERROR;
scanfree(&scan);
goto Error;
}
/* This is the top of the object */
from->offset = markoffset(scanmark(&scan));
scanfree(&scan);
cursoff = markoffset(win->cursor);
marksetoffset(win->cursor, from->offset);
/* find the matching character by simulating a % command */
cmd.command = '%';
cmd.count = 0L;
result = m_absolute(win, &cmd);
if (result != RESULT_COMPLETE)
{
result = RESULT_MORE;
marksetoffset(win->cursor, cursoff);
goto Error;
}
/* the cursor is now at the bottom of the object */
to->offset = markoffset(win->cursor);
/* include delimiter chars if 'a', exclude if 'i' */
if (vinf->command == 'a')
to->offset++;
else
{
markaddoffset(from, 1L);
if (scanchar(from) == '\n')
markaddoffset(from, 1L);
do
{
markaddoffset(to, -1L);
} while (elvspace(scanchar(to)));
markaddoffset(to, 1L);
}
break;
case '}':
case ']':
case ')':
case '>':
/* search forward for nth character */
scanalloc(&scan, win->cursor);
scanprev(&scan);
for (count = vinf->count; count > 0L && scannext(&scan); )
if (*scan == vinf->key2)
count--;
else if (*scan == opposite)
count++;
if (count > 0L)
{
/* oops, there was no such character */
result = RESULT_ERROR;
scanfree(&scan);
goto Error;
}
/* This is the bottom of the object */
to->offset = markoffset(scanmark(&scan));
scanfree(&scan);
marksetoffset(win->cursor, to->offset);
/* find the matching character by simulating a % command */
cmd.command = '%';
cmd.count = 0L;
result = m_absolute(win, &cmd);
if (result != RESULT_COMPLETE)
goto Error;
/* the cursor is now at the bottom of the object */
from->offset = markoffset(win->cursor);
/* include delimiter chars if 'a', exclude if 'i' */
if (vinf->command == 'a')
to->offset++;
else
{
markaddoffset(from, 1L);
if (scanchar(from) == '\n')
markaddoffset(from, 1L);
do
{
markaddoffset(to, -1L);
} while (elvspace(scanchar(to)));
markaddoffset(to, 1L);
}
break;
case 'L':
fromln = markline(win->cursor);
in = indentation(win, fromln);
count = vinf->count;
/* if this line is blank, then scan forward and backward for
* the nearest nonblank lines. Use the one with more
* indentation.
*/
if (in < 0L)
{
/* scan backward for a non-blank line */
for (ln = fromln, nextin = -1L; nextin < 0 && --ln > 0;)
nextin = indentation(win, ln);
/* scan forward for a non-blank line */
for (; in < 0 && ++fromln < o_buflines(buf); )
in = indentation(win, fromln);
/* choose the one with more indentation. If the entire
* file consists of blank lines, then this will leave
* fromln=0, in=-1L, which will cause the next loop to
* detect a failure condition.
*/
if (nextin > in)
fromln = ln, in = nextin;
}
/* search backward for n'th line with a smaller indent */
for (ln = fromln - 1; ln >= 1 && in > 0 && count > 0; ln--)
{
nextin = indentation(win, ln);
if (nextin >= 0 && nextin < in)
{
in = nextin;
count--;
if (in == 0 || count == 0)
break;
}
}
if (count > 1 || (count == 1 && in == 0))
{
result = RESULT_ERROR;
goto Error;
}
/* we went one line too far -- range starts one line down */
marksetline(from, ln + 1);
/* search forward past lines with more indentation */
for (ln = fromln + 1; ln < o_buflines(buf); ln++)
{
nextin = indentation(win, ln);
if (nextin >= 0 && nextin <= in)
break;
}
/* ln is now either past the end of the buffer, or on the line
* after the end of the indentation block. Either way, that's
* the end of the block.
*/
marksetline(to, ln);
/* the 'i' version leaves off the whitespace */
if (vinf->command == 'i')
{
/* trim the leading space */
for (scanalloc(&scan, from);
*scan && elvspace(*scan);
scannext(&scan))
{
}
if (scan)
marksetoffset(from, markoffset(scanmark(&scan)));
scanfree(&scan);
/* trim the trailing space */
markaddoffset(to, -1L);
for (scanalloc(&scan, to);
*scan && elvspace(*scan);
scanprev(&scan))
{
}
if (scan)
marksetoffset(to, markoffset(scanmark(&scan)) + 1);
scanfree(&scan);
}
break;
case 'w':
fromkey = 'b';
tokey = 'w';
break;
case 'W':
fromkey = 'B';
tokey = 'W';
break;
case 's':
fromkey = '(';
tokey = ')';
break;
case 'S':
fromkey = '[';
tokey = ']';
break;
case 'p':
fromkey = '{';
tokey = '}';
break;
case 'x':
case 'X':
o_matchchar = oldmatchchar;
return vixmlobj(win, vinf, from, to);
default:
if (elvalnum(vinf->key2))
{
/* bogus letter */
result = RESULT_ERROR;
goto Error;
}
/* Other characters can be used as delimiters though... */
/* search backward for character */
scanalloc(&scan, win->cursor);
for (count = vinf->count; count && scanprev(&scan); )
{
if (*scan == vinf->key2 || *scan == '\n')
count--;
}
if (!scan && count > 1)
{
/* oops, there was no such character */
result = RESULT_ERROR;
scanfree(&scan);
goto Error;
}
/* This is the top of the object */
if (scan)
{
opposite = *scan;
marksetoffset(from, markoffset(scanmark(&scan)));
}
else
{
marksetoffset(from, 0L);
scanseek(&scan, from);
opposite = '\0';
}
/* search forward the matching character */