File tree 6 files changed +98
-3
lines changed
6 files changed +98
-3
lines changed Original file line number Diff line number Diff line change 1
1
Micro Vi
2
2
3
3
Similar commands to vi.
4
+
5
+ See uvi.1
Original file line number Diff line number Diff line change @@ -764,6 +764,66 @@ static void colon(const char *initial)
764
764
free (in );
765
765
}
766
766
767
+ void visual_inside (int include )
768
+ {
769
+ struct list * l ;
770
+ char * s ;
771
+ int i ;
772
+ int start_y ;
773
+ int bracket ;
774
+
775
+ /* TODO: number */
776
+
777
+ bracket = gui_getch (GETCH_COOKED );
778
+ l = buffer_getindex (buffers_current (), gui_y ());
779
+ s = l -> data ;
780
+
781
+ if (!isparen (bracket ))
782
+ /* TODO: iw, ip (paragraph), etc - swap to a motion? */
783
+ return ;
784
+
785
+ /* TODO: go forward if it's a close bracket, else go backward */
786
+
787
+ i = gui_x ();
788
+ start_y = gui_y ();
789
+ while (s [i ] != bracket ){
790
+ if (-- i < 0 ){
791
+ l = l -> prev ;
792
+ start_y -- ;
793
+ if (!l )
794
+ return ;
795
+ s = l -> data ;
796
+ i = strlen (s ) - 1 ;
797
+ }
798
+ }
799
+
800
+ /* s[i] is the bracket, do a motion_percent on it and visual() */
801
+ {
802
+ /* TODO: distinguish between vi{ and va{ */
803
+ struct motion m ;
804
+ struct bufferpos bp ;
805
+ struct screeninfo si ;
806
+ int x [2 ], y [2 ];
807
+
808
+ memset (& m , 0 , sizeof m );
809
+ m .motion = MOTION_PAREN_MATCH ;
810
+
811
+ si .top = gui_top ();
812
+ si .height = gui_max_y ();
813
+
814
+ x [0 ] = x [1 ] = i ;
815
+ y [0 ] = y [1 ] = start_y ;
816
+ bp .x = x + 1 ;
817
+ bp .y = y + 1 ;
818
+
819
+ if (motion_apply (& m , & bp , & si ))
820
+ return ;
821
+
822
+ /* highlight from {x,y][1] to {x,y}[0] */
823
+ visual_setpoints (x , y );
824
+ }
825
+ }
826
+
767
827
static int is_edit_char (int c )
768
828
{
769
829
switch (c ){
@@ -994,9 +1054,15 @@ void gui_run()
994
1054
flag = 1 ;
995
1055
case 'i' :
996
1056
case_i :
997
- insert (flag , 0 , 0 );
998
- buffer_changed = 1 ;
999
- SET_DOT ();
1057
+ if (visual_get () == VISUAL_NONE ){
1058
+ insert (flag , 0 , 0 );
1059
+ buffer_changed = 1 ;
1060
+ SET_DOT ();
1061
+ }else {
1062
+ /* ibracket */
1063
+ visual_inside (flag );
1064
+ view_changed = 1 ;
1065
+ }
1000
1066
break ;
1001
1067
case 'I' :
1002
1068
SET_MOTION (MOTION_LINE_START );
Original file line number Diff line number Diff line change @@ -10,6 +10,15 @@ static enum visual visual_state = VISUAL_NONE;
10
10
static struct range visual_cursor ;
11
11
static struct range visual_anchor ;
12
12
13
+ void visual_setpoints (int x [2 ], int y [2 ])
14
+ {
15
+ visual_cursor .start = y [0 ];
16
+ visual_cursor .end = x [0 ];
17
+ visual_anchor .start = y [1 ];
18
+ visual_anchor .end = x [1 ];
19
+ gui_move (visual_cursor .start , visual_cursor .end );
20
+ }
21
+
13
22
void visual_update (struct range * v )
14
23
{
15
24
v -> start = gui_y ();
Original file line number Diff line number Diff line change @@ -13,6 +13,8 @@ enum visual visual_get();
13
13
void visual_swap ();
14
14
void visual_join ();
15
15
16
+ void visual_setpoints (int x [2 ], int y [2 ]);
17
+
16
18
const struct range * visual_get_start ();
17
19
const struct range * visual_get_end ();
18
20
const struct range * visual_get_col_start ();
Original file line number Diff line number Diff line change @@ -24,6 +24,20 @@ int isfnamechar(int c)
24
24
return !isspace (c ) && !ispunct (c ) && c != '"' && c != '\'' ; /* TODO: ignore trailing punctuation */
25
25
}
26
26
27
+ int isparen (int c )
28
+ {
29
+ switch (c ){
30
+ case '{' :
31
+ case '(' :
32
+ case '[' :
33
+ case '}' :
34
+ case ')' :
35
+ case ']' :
36
+ return 1 ;
37
+ }
38
+ return 0 ;
39
+ }
40
+
27
41
char * chars_at (const char * line , int x , int (* cmp )(int ))
28
42
{
29
43
const char * wordstart , * wordend ;
Original file line number Diff line number Diff line change @@ -10,6 +10,8 @@ char **words_begin(struct list *, const char *);
10
10
11
11
int line_isspace (const char * s );
12
12
13
+ int isparen (int );
14
+
13
15
void str_escape (char * arg );
14
16
char * chr_expand (char * arg , char c , const char * rep );
15
17
char * str_expand (char * str , const char * grow_from , const char * grow_to );
You can’t perform that action at this time.
0 commit comments