Mercurial > vim
annotate src/ops.c @ 18354:9f51d0cef8da v8.1.2171
patch 8.1.2171: mouse support not always available
Commit: https://github.com/vim/vim/commit/a1cb1d1dce14dd005797590721f1bcd0e7c3b35f
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 17 23:00:07 2019 +0200
patch 8.1.2171: mouse support not always available
Problem: Mouse support not always available.
Solution: Enable mouse support also in tiny version. Do not define
FEAT_MOUSE_XTERM on MS-Windows (didn't really work).
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 17 Oct 2019 23:15:04 +0200 |
parents | fe5afdc03bd2 |
children | 26256dcadd77 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9834
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, | |
12 * op_change, op_yank, do_put, do_join | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
17 static void shift_block(oparg_T *oap, int amount); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
18 static void mb_adjust_opend(oparg_T *oap); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
19 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
20 static int ends_in_white(linenr_T lnum); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
21 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 22 |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
23 // Flags for third item in "opchars". |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
24 #define OPF_LINES 1 // operator always works on lines |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
25 #define OPF_CHANGE 2 // operator changes text |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
26 |
7 | 27 /* |
28 * The names of operators. | |
29 * IMPORTANT: Index must correspond with defines in vim.h!!! | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
30 * The third field holds OPF_ flags. |
7 | 31 */ |
32 static char opchars[][3] = | |
33 { | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
34 {NUL, NUL, 0}, // OP_NOP |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
35 {'d', NUL, OPF_CHANGE}, // OP_DELETE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
36 {'y', NUL, 0}, // OP_YANK |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
37 {'c', NUL, OPF_CHANGE}, // OP_CHANGE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
38 {'<', NUL, OPF_LINES | OPF_CHANGE}, // OP_LSHIFT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
39 {'>', NUL, OPF_LINES | OPF_CHANGE}, // OP_RSHIFT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
40 {'!', NUL, OPF_LINES | OPF_CHANGE}, // OP_FILTER |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
41 {'g', '~', OPF_CHANGE}, // OP_TILDE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
42 {'=', NUL, OPF_LINES | OPF_CHANGE}, // OP_INDENT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
43 {'g', 'q', OPF_LINES | OPF_CHANGE}, // OP_FORMAT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
44 {':', NUL, OPF_LINES}, // OP_COLON |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
45 {'g', 'U', OPF_CHANGE}, // OP_UPPER |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
46 {'g', 'u', OPF_CHANGE}, // OP_LOWER |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
47 {'J', NUL, OPF_LINES | OPF_CHANGE}, // DO_JOIN |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
48 {'g', 'J', OPF_LINES | OPF_CHANGE}, // DO_JOIN_NS |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
49 {'g', '?', OPF_CHANGE}, // OP_ROT13 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
50 {'r', NUL, OPF_CHANGE}, // OP_REPLACE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
51 {'I', NUL, OPF_CHANGE}, // OP_INSERT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
52 {'A', NUL, OPF_CHANGE}, // OP_APPEND |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
53 {'z', 'f', OPF_LINES}, // OP_FOLD |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
54 {'z', 'o', OPF_LINES}, // OP_FOLDOPEN |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
55 {'z', 'O', OPF_LINES}, // OP_FOLDOPENREC |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
56 {'z', 'c', OPF_LINES}, // OP_FOLDCLOSE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
57 {'z', 'C', OPF_LINES}, // OP_FOLDCLOSEREC |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
58 {'z', 'd', OPF_LINES}, // OP_FOLDDEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
59 {'z', 'D', OPF_LINES}, // OP_FOLDDELREC |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
60 {'g', 'w', OPF_LINES | OPF_CHANGE}, // OP_FORMAT2 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
61 {'g', '@', OPF_CHANGE}, // OP_FUNCTION |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
62 {Ctrl_A, NUL, OPF_CHANGE}, // OP_NR_ADD |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
63 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB |
7 | 64 }; |
65 | |
66 /* | |
67 * Translate a command name into an operator type. | |
68 * Must only be called with a valid operator name! | |
69 */ | |
70 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
71 get_op_type(int char1, int char2) |
7 | 72 { |
73 int i; | |
74 | |
75 if (char1 == 'r') /* ignore second character */ | |
76 return OP_REPLACE; | |
77 if (char1 == '~') /* when tilde is an operator */ | |
78 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
79 if (char1 == 'g' && char2 == Ctrl_A) /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
80 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
81 if (char1 == 'g' && char2 == Ctrl_X) /* subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
82 return OP_NR_SUB; |
7 | 83 for (i = 0; ; ++i) |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
84 { |
7 | 85 if (opchars[i][0] == char1 && opchars[i][1] == char2) |
86 break; | |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
87 if (i == (int)(sizeof(opchars) / sizeof(char [3]) - 1)) |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
88 { |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
89 internal_error("get_op_type()"); |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
90 break; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
91 } |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
92 } |
7 | 93 return i; |
94 } | |
95 | |
96 /* | |
97 * Return TRUE if operator "op" always works on whole lines. | |
98 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
99 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
100 op_on_lines(int op) |
7 | 101 { |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
102 return opchars[op][2] & OPF_LINES; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
103 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
104 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
105 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
106 /* |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
107 * Return TRUE if operator "op" changes text. |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
108 */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
109 int |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
110 op_is_change(int op) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
111 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
112 return opchars[op][2] & OPF_CHANGE; |
7 | 113 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
114 #endif |
7 | 115 |
116 /* | |
117 * Get first operator command character. | |
118 * Returns 'g' or 'z' if there is another command character. | |
119 */ | |
120 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
121 get_op_char(int optype) |
7 | 122 { |
123 return opchars[optype][0]; | |
124 } | |
125 | |
126 /* | |
127 * Get second operator command character. | |
128 */ | |
129 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
130 get_extra_op_char(int optype) |
7 | 131 { |
132 return opchars[optype][1]; | |
133 } | |
134 | |
135 /* | |
136 * op_shift - handle a shift operation | |
137 */ | |
138 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
139 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 140 { |
141 long i; | |
142 int first_char; | |
143 int block_col = 0; | |
144 | |
145 if (u_save((linenr_T)(oap->start.lnum - 1), | |
146 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
147 return; | |
148 | |
149 if (oap->block_mode) | |
150 block_col = curwin->w_cursor.col; | |
151 | |
152 for (i = oap->line_count; --i >= 0; ) | |
153 { | |
154 first_char = *ml_get_curline(); | |
155 if (first_char == NUL) /* empty line */ | |
156 curwin->w_cursor.col = 0; | |
157 else if (oap->block_mode) | |
158 shift_block(oap, amount); | |
159 else | |
160 /* Move the line right if it doesn't start with '#', 'smartindent' | |
161 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
162 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
163 if (first_char != '#' || !preprocs_left()) | |
164 #endif | |
1516 | 165 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 166 ++curwin->w_cursor.lnum; |
167 } | |
168 | |
169 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
170 if (oap->block_mode) | |
171 { | |
172 curwin->w_cursor.lnum = oap->start.lnum; | |
173 curwin->w_cursor.col = block_col; | |
174 } | |
5735 | 175 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 176 { |
177 curwin->w_cursor.lnum = oap->start.lnum; | |
178 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
179 } | |
180 else | |
181 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
182 | |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
183 #ifdef FEAT_FOLDING |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
184 /* The cursor line is not in a closed fold */ |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
185 foldOpenCursor(); |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
186 #endif |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
187 |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
188 |
7 | 189 if (oap->line_count > p_report) |
190 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
191 char *op; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
192 char *msg_line_single; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
193 char *msg_line_plural; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
194 |
7 | 195 if (oap->op_type == OP_RSHIFT) |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
196 op = ">"; |
7 | 197 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
198 op = "<"; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
199 msg_line_single = NGETTEXT("%ld line %sed %d time", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
200 "%ld line %sed %d times", amount); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
201 msg_line_plural = NGETTEXT("%ld lines %sed %d time", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
202 "%ld lines %sed %d times", amount); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
203 vim_snprintf((char *)IObuff, IOSIZE, |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
204 NGETTEXT(msg_line_single, msg_line_plural, oap->line_count), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
205 oap->line_count, op, amount); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
206 msg((char *)IObuff); |
7 | 207 } |
208 | |
209 /* | |
210 * Set "'[" and "']" marks. | |
211 */ | |
212 curbuf->b_op_start = oap->start; | |
213 curbuf->b_op_end.lnum = oap->end.lnum; | |
214 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
215 if (curbuf->b_op_end.col > 0) | |
216 --curbuf->b_op_end.col; | |
217 } | |
218 | |
219 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
220 * Shift the current line one shiftwidth left (if left != 0) or right |
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
221 * leaves cursor on first blank in the line. |
7 | 222 */ |
223 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
224 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
225 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
226 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
227 int amount, |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
228 int call_changed_bytes) // call changed_bytes() |
7 | 229 { |
230 int count; | |
231 int i, j; | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
232 int sw_val = (int)get_sw_value_indent(curbuf); |
7 | 233 |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
234 count = get_indent(); // get current indent |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
235 |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
236 if (round) // round off indent |
7 | 237 { |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
238 i = count / sw_val; // number of 'shiftwidth' rounded down |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
239 j = count % sw_val; // extra spaces |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
240 if (j && left) // first remove extra spaces |
7 | 241 --amount; |
242 if (left) | |
243 { | |
244 i -= amount; | |
245 if (i < 0) | |
246 i = 0; | |
247 } | |
248 else | |
249 i += amount; | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
250 count = i * sw_val; |
7 | 251 } |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
252 else // original vi indent |
7 | 253 { |
254 if (left) | |
255 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
256 count -= sw_val * amount; |
7 | 257 if (count < 0) |
258 count = 0; | |
259 } | |
260 else | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
261 count += sw_val * amount; |
7 | 262 } |
263 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
264 // Set new indent |
7 | 265 if (State & VREPLACE_FLAG) |
1516 | 266 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 267 else |
1516 | 268 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 269 } |
270 | |
271 /* | |
272 * Shift one line of the current block one shiftwidth right or left. | |
273 * Leaves cursor on first character in block. | |
274 */ | |
275 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
276 shift_block(oparg_T *oap, int amount) |
7 | 277 { |
278 int left = (oap->op_type == OP_LSHIFT); | |
279 int oldstate = State; | |
1839 | 280 int total; |
281 char_u *newp, *oldp; | |
7 | 282 int oldcol = curwin->w_cursor.col; |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
283 int sw_val = (int)get_sw_value_indent(curbuf); |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
284 int ts_val = (int)curbuf->b_p_ts; |
7 | 285 struct block_def bd; |
286 int incr; | |
1839 | 287 colnr_T ws_vcol; |
7 | 288 int i = 0, j = 0; |
289 int len; | |
290 #ifdef FEAT_RIGHTLEFT | |
291 int old_p_ri = p_ri; | |
292 | |
4352 | 293 p_ri = 0; /* don't want revins in indent */ |
7 | 294 #endif |
295 | |
296 State = INSERT; /* don't want REPLACE for State */ | |
297 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
298 if (bd.is_short) | |
299 return; | |
300 | |
301 /* total is number of screen columns to be inserted/removed */ | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
302 total = (int)((unsigned)amount * (unsigned)sw_val); |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
303 if ((total / sw_val) != amount) |
11997
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
304 return; /* multiplication overflow */ |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
305 |
7 | 306 oldp = ml_get_curline(); |
307 | |
308 if (!left) | |
309 { | |
310 /* | |
311 * 1. Get start vcol | |
312 * 2. Total ws vcols | |
313 * 3. Divvy into TABs & spp | |
314 * 4. Construct new string | |
315 */ | |
316 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
317 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
318 if (bd.startspaces) | |
319 { | |
320 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
321 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
322 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
323 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
324 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
325 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
326 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
327 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
328 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
329 } |
1995 | 330 else |
331 ++bd.textstart; | |
7 | 332 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
333 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 334 { |
5995 | 335 /* TODO: is passing bd.textstart for start of the line OK? */ |
336 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
337 (colnr_T)(bd.start_vcol)); | |
7 | 338 total += incr; |
339 bd.start_vcol += incr; | |
340 } | |
341 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
342 * non-ws char in the block. */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
343 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
344 if (!curbuf->b_p_et) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
345 tabstop_fromto(ws_vcol, ws_vcol + total, |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
346 ts_val, curbuf->b_p_vts_array, &i, &j); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
347 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
348 j = total; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
349 #else |
7 | 350 if (!curbuf->b_p_et) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
351 i = ((ws_vcol % ts_val) + total) / ts_val; /* number of tabs */ |
7 | 352 if (i) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
353 j = ((ws_vcol % ts_val) + total) % ts_val; /* number of spp */ |
7 | 354 else |
355 j = total; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
356 #endif |
7 | 357 /* if we're splitting a TAB, allow for it */ |
358 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
359 len = (int)STRLEN(bd.textstart) + 1; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
360 newp = alloc(bd.textcol + i + j + len); |
7 | 361 if (newp == NULL) |
362 return; | |
363 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
364 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 365 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
366 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 367 /* the end */ |
368 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
369 } | |
370 else /* left */ | |
371 { | |
1839 | 372 colnr_T destination_col; /* column to which text in block will |
373 be shifted */ | |
374 char_u *verbatim_copy_end; /* end of the part of the line which is | |
375 copied verbatim */ | |
376 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
377 of line */ | |
378 unsigned fill; /* nr of spaces that replace a TAB */ | |
379 unsigned new_line_len; /* the length of the line after the | |
380 block shift */ | |
381 size_t block_space_width; | |
382 size_t shift_amount; | |
383 char_u *non_white = bd.textstart; | |
384 colnr_T non_white_col; | |
385 | |
386 /* | |
387 * Firstly, let's find the first non-whitespace character that is | |
388 * displayed after the block's start column and the character's column | |
389 * number. Also, let's calculate the width of all the whitespace | |
390 * characters that are displayed in the block and precede the searched | |
391 * non-whitespace character. | |
392 */ | |
393 | |
394 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
395 * the part of which is displayed at the block's beginning. Let's start | |
396 * searching from the next character. */ | |
397 if (bd.startspaces) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
398 MB_PTR_ADV(non_white); |
1839 | 399 |
400 /* The character's column is in "bd.start_vcol". */ | |
401 non_white_col = bd.start_vcol; | |
402 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
403 while (VIM_ISWHITE(*non_white)) |
7 | 404 { |
5995 | 405 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 406 non_white_col += incr; |
7 | 407 } |
1839 | 408 |
409 block_space_width = non_white_col - oap->start_vcol; | |
410 /* We will shift by "total" or "block_space_width", whichever is less. | |
411 */ | |
1860 | 412 shift_amount = (block_space_width < (size_t)total |
413 ? block_space_width : (size_t)total); | |
1839 | 414 |
415 /* The column to which we will shift the text. */ | |
1860 | 416 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 417 |
418 /* Now let's find out how much of the beginning of the line we can | |
419 * reuse without modification. */ | |
420 verbatim_copy_end = bd.textstart; | |
421 verbatim_copy_width = bd.start_vcol; | |
422 | |
423 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
424 * preceding the block. We have to subtract its width to obtain its | |
425 * column number. */ | |
426 if (bd.startspaces) | |
427 verbatim_copy_width -= bd.start_char_vcols; | |
428 while (verbatim_copy_width < destination_col) | |
7 | 429 { |
5995 | 430 char_u *line = verbatim_copy_end; |
431 | |
432 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
433 incr = lbr_chartabsize(line, verbatim_copy_end, | |
434 verbatim_copy_width); | |
1839 | 435 if (verbatim_copy_width + incr > destination_col) |
436 break; | |
437 verbatim_copy_width += incr; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
438 MB_PTR_ADV(verbatim_copy_end); |
7 | 439 } |
440 | |
1839 | 441 /* If "destination_col" is different from the width of the initial |
442 * part of the line that will be copied, it means we encountered a tab | |
443 * character, which we will have to partly replace with spaces. */ | |
444 fill = destination_col - verbatim_copy_width; | |
445 | |
446 /* The replacement line will consist of: | |
447 * - the beginning of the original line up to "verbatim_copy_end", | |
448 * - "fill" number of spaces, | |
449 * - the rest of the line, pointed to by non_white. */ | |
450 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
451 + fill | |
452 + (unsigned)STRLEN(non_white) + 1; | |
453 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
454 newp = alloc(new_line_len); |
7 | 455 if (newp == NULL) |
456 return; | |
1839 | 457 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 458 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 459 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 460 } |
461 /* replace the line */ | |
462 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
463 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
464 State = oldstate; | |
465 curwin->w_cursor.col = oldcol; | |
466 #ifdef FEAT_RIGHTLEFT | |
467 p_ri = old_p_ri; | |
468 #endif | |
469 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
470 |
7 | 471 /* |
472 * Insert string "s" (b_insert ? before : after) block :AKelly | |
473 * Caller must prepare for undo. | |
474 */ | |
475 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
476 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
477 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
478 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
479 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
480 struct block_def *bdp) |
7 | 481 { |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
482 int ts_val; |
7 | 483 int count = 0; /* extra spaces to replace a cut TAB */ |
484 int spaces = 0; /* non-zero if cutting a TAB */ | |
485 colnr_T offset; /* pointer along new line */ | |
486 unsigned s_len; /* STRLEN(s) */ | |
487 char_u *newp, *oldp; /* new, old lines */ | |
488 linenr_T lnum; /* loop var */ | |
489 int oldstate = State; | |
490 | |
491 State = INSERT; /* don't want REPLACE for State */ | |
492 s_len = (unsigned)STRLEN(s); | |
493 | |
494 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
495 { | |
496 block_prep(oap, bdp, lnum, TRUE); | |
497 if (bdp->is_short && b_insert) | |
498 continue; /* OP_INSERT, line ends before block start */ | |
499 | |
500 oldp = ml_get(lnum); | |
501 | |
502 if (b_insert) | |
503 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
504 ts_val = bdp->start_char_vcols; |
7 | 505 spaces = bdp->startspaces; |
506 if (spaces != 0) | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
507 count = ts_val - 1; /* we're cutting a TAB */ |
7 | 508 offset = bdp->textcol; |
509 } | |
510 else /* append */ | |
511 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
512 ts_val = bdp->end_char_vcols; |
7 | 513 if (!bdp->is_short) /* spaces = padding after block */ |
514 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
515 spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); |
7 | 516 if (spaces != 0) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
517 count = ts_val - 1; /* we're cutting a TAB */ |
7 | 518 offset = bdp->textcol + bdp->textlen - (spaces != 0); |
519 } | |
520 else /* spaces = padding to block edge */ | |
521 { | |
522 /* if $ used, just append to EOL (ie spaces==0) */ | |
523 if (!bdp->is_MAX) | |
524 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
525 count = spaces; | |
526 offset = bdp->textcol + bdp->textlen; | |
527 } | |
528 } | |
529 | |
6140 | 530 if (has_mbyte && spaces > 0) |
531 { | |
6460 | 532 int off; |
533 | |
6140 | 534 /* Avoid starting halfway a multi-byte character. */ |
535 if (b_insert) | |
536 { | |
6460 | 537 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 538 } |
539 else | |
540 { | |
6460 | 541 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 542 offset += off; |
543 } | |
6460 | 544 spaces -= off; |
545 count -= off; | |
6140 | 546 } |
547 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
548 newp = alloc(STRLEN(oldp) + s_len + count + 1); |
7 | 549 if (newp == NULL) |
550 continue; | |
551 | |
552 /* copy up to shifted part */ | |
553 mch_memmove(newp, oldp, (size_t)(offset)); | |
554 oldp += offset; | |
555 | |
556 /* insert pre-padding */ | |
6929 | 557 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 558 |
559 /* copy the new text */ | |
560 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
561 offset += s_len; | |
562 | |
563 if (spaces && !bdp->is_short) | |
564 { | |
565 /* insert post-padding */ | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
566 vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); |
7 | 567 /* We're splitting a TAB, don't copy it. */ |
568 oldp++; | |
569 /* We allowed for that TAB, remember this now */ | |
570 count++; | |
571 } | |
572 | |
573 if (spaces > 0) | |
574 offset += count; | |
1622 | 575 STRMOVE(newp + offset, oldp); |
7 | 576 |
577 ml_replace(lnum, newp, FALSE); | |
578 | |
579 if (lnum == oap->end.lnum) | |
580 { | |
581 /* Set "']" mark to the end of the block instead of the end of | |
582 * the insert in the first line. */ | |
583 curbuf->b_op_end.lnum = oap->end.lnum; | |
584 curbuf->b_op_end.col = offset; | |
585 } | |
586 } /* for all lnum */ | |
587 | |
588 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
589 | |
590 State = oldstate; | |
591 } | |
592 | |
593 /* | |
594 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
595 * literally ("literally" TRUE) or interpret is as typed characters. | |
596 */ | |
18164
f57481564f2c
patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18100
diff
changeset
|
597 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
598 stuffescaped(char_u *arg, int literally) |
7 | 599 { |
600 int c; | |
601 char_u *start; | |
602 | |
603 while (*arg != NUL) | |
604 { | |
605 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
606 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
607 * is TRUE. */ | |
608 start = arg; | |
609 while ((*arg >= ' ' | |
610 #ifndef EBCDIC | |
611 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
612 #endif | |
613 ) | |
614 || (*arg == K_SPECIAL && !literally)) | |
615 ++arg; | |
616 if (arg > start) | |
617 stuffReadbuffLen(start, (long)(arg - start)); | |
618 | |
619 /* stuff a single special character */ | |
620 if (*arg != NUL) | |
621 { | |
622 if (has_mbyte) | |
2446
348f64c129df
Fixed: CTRL-R in Insert mode doesn't insert composing characters.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
623 c = mb_cptr2char_adv(&arg); |
7 | 624 else |
625 c = *arg++; | |
626 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
627 stuffcharReadbuff(Ctrl_V); | |
628 stuffcharReadbuff(c); | |
629 } | |
630 } | |
631 } | |
632 | |
633 /* | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
634 * Handle a delete operation. |
7 | 635 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
636 * Return FAIL if undo failed, OK otherwise. |
7 | 637 */ |
638 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
639 op_delete(oparg_T *oap) |
7 | 640 { |
641 int n; | |
642 linenr_T lnum; | |
643 char_u *ptr; | |
644 char_u *newp, *oldp; | |
645 struct block_def bd; | |
646 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
647 int did_yank = FALSE; | |
648 | |
649 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
650 return OK; | |
651 | |
652 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
653 if (oap->empty) | |
654 return u_save_cursor(); | |
655 | |
656 if (!curbuf->b_p_ma) | |
657 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
658 emsg(_(e_modifiable)); |
7 | 659 return FAIL; |
660 } | |
661 | |
662 #ifdef FEAT_CLIPBOARD | |
663 adjust_clip_reg(&oap->regname); | |
664 #endif | |
665 | |
666 if (has_mbyte) | |
667 mb_adjust_opend(oap); | |
668 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
669 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
670 * Imitate the strange Vi behaviour: If the delete spans more than one |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
671 * line and motion_type == MCHAR and the result is a blank line, make the |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
672 * delete linewise. Don't do this for the change command or Visual mode. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
673 */ |
7 | 674 if ( oap->motion_type == MCHAR |
675 && !oap->is_VIsual | |
50 | 676 && !oap->block_mode |
7 | 677 && oap->line_count > 1 |
3254 | 678 && oap->motion_force == NUL |
7 | 679 && oap->op_type == OP_DELETE) |
680 { | |
2957 | 681 ptr = ml_get(oap->end.lnum) + oap->end.col; |
682 if (*ptr != NUL) | |
683 ptr += oap->inclusive; | |
7 | 684 ptr = skipwhite(ptr); |
685 if (*ptr == NUL && inindent(0)) | |
686 oap->motion_type = MLINE; | |
687 } | |
688 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
689 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
690 * Check for trying to delete (e.g. "D") in an empty line. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
691 * Note: For the change operator it is ok. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
692 */ |
7 | 693 if ( oap->motion_type == MCHAR |
694 && oap->line_count == 1 | |
695 && oap->op_type == OP_DELETE | |
696 && *ml_get(oap->start.lnum) == NUL) | |
697 { | |
698 /* | |
446 | 699 * It's an error to operate on an empty region, when 'E' included in |
7 | 700 * 'cpoptions' (Vi compatible). |
701 */ | |
446 | 702 if (virtual_op) |
703 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
704 * marks as if it happened. */ | |
705 goto setmarks; | |
7 | 706 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
707 beep_flush(); | |
708 return OK; | |
709 } | |
710 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
711 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
712 * Do a yank of whatever we're about to delete. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
713 * If a yank register was specified, put the deleted text into that |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
714 * register. For the black hole register '_' don't yank anything. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
715 */ |
7 | 716 if (oap->regname != '_') |
717 { | |
718 if (oap->regname != 0) | |
719 { | |
720 /* check for read-only register */ | |
721 if (!valid_yank_reg(oap->regname, TRUE)) | |
722 { | |
723 beep_flush(); | |
724 return OK; | |
725 } | |
726 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
727 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
728 did_yank = TRUE; | |
729 } | |
730 | |
731 /* | |
732 * Put deleted text into register 1 and shift number registers if the | |
15987
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
733 * delete contains a line break, or when using a specific operator (Vi |
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
734 * compatible) |
3782 | 735 * Use the register name from before adjust_clip_reg() may have |
736 * changed it. | |
7 | 737 */ |
15987
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
738 if (oap->motion_type == MLINE || oap->line_count > 1 |
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
739 || oap->use_reg_one) |
7 | 740 { |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
741 shift_delete_registers(); |
7 | 742 if (op_yank(oap, TRUE, FALSE) == OK) |
743 did_yank = TRUE; | |
744 } | |
745 | |
3468 | 746 /* Yank into small delete register when no named register specified |
747 * and the delete is within one line. */ | |
748 if (( | |
749 #ifdef FEAT_CLIPBOARD | |
3584 | 750 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
751 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 752 #endif |
753 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 754 && oap->line_count == 1) |
755 { | |
756 oap->regname = '-'; | |
757 get_yank_register(oap->regname, TRUE); | |
758 if (op_yank(oap, TRUE, FALSE) == OK) | |
759 did_yank = TRUE; | |
760 oap->regname = 0; | |
761 } | |
762 | |
763 /* | |
764 * If there's too much stuff to fit in the yank register, then get a | |
765 * confirmation before doing the delete. This is crude, but simple. | |
766 * And it avoids doing a delete of something we can't put back if we | |
767 * want. | |
768 */ | |
769 if (!did_yank) | |
770 { | |
771 int msg_silent_save = msg_silent; | |
772 | |
773 msg_silent = 0; /* must display the prompt */ | |
774 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
775 msg_silent = msg_silent_save; | |
776 if (n != 'y') | |
777 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
778 emsg(_(e_abort)); |
7 | 779 return FAIL; |
780 } | |
781 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
782 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
783 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
784 if (did_yank && has_textyankpost()) |
18164
f57481564f2c
patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18100
diff
changeset
|
785 yank_do_autocmd(oap, get_y_current()); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
786 #endif |
7 | 787 } |
788 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
789 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
790 * block mode delete |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
791 */ |
7 | 792 if (oap->block_mode) |
793 { | |
794 if (u_save((linenr_T)(oap->start.lnum - 1), | |
795 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
796 return FAIL; | |
797 | |
798 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
799 { | |
800 block_prep(oap, &bd, lnum, TRUE); | |
801 if (bd.textlen == 0) /* nothing to delete */ | |
802 continue; | |
803 | |
804 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
805 if (lnum == curwin->w_cursor.lnum) | |
806 { | |
807 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
808 curwin->w_cursor.coladd = 0; | |
809 } | |
810 | |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
811 // "n" == number of chars deleted |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
812 // If we delete a TAB, it may be replaced by several characters. |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
813 // Thus the number of characters may increase! |
7 | 814 n = bd.textlen - bd.startspaces - bd.endspaces; |
815 oldp = ml_get(lnum); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
816 newp = alloc(STRLEN(oldp) + 1 - n); |
7 | 817 if (newp == NULL) |
818 continue; | |
819 /* copy up to deleted part */ | |
820 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
821 /* insert spaces */ | |
6929 | 822 vim_memset(newp + bd.textcol, ' ', |
7 | 823 (size_t)(bd.startspaces + bd.endspaces)); |
824 /* copy the part after the deleted part */ | |
825 oldp += bd.textcol + bd.textlen; | |
1622 | 826 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 827 /* replace the line */ |
828 ml_replace(lnum, newp, FALSE); | |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
829 |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
830 #ifdef FEAT_TEXT_PROP |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
831 if (curbuf->b_has_textprop && n != 0) |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
832 adjust_prop_columns(lnum, bd.textcol, -n, 0); |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
833 #endif |
7 | 834 } |
835 | |
836 check_cursor_col(); | |
837 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
838 oap->end.lnum + 1, 0L); | |
839 oap->line_count = 0; /* no lines deleted */ | |
840 } | |
5735 | 841 else if (oap->motion_type == MLINE) |
7 | 842 { |
843 if (oap->op_type == OP_CHANGE) | |
844 { | |
845 /* Delete the lines except the first one. Temporarily move the | |
846 * cursor to the next line. Save the current line number, if the | |
847 * last line is deleted it may be changed. | |
848 */ | |
849 if (oap->line_count > 1) | |
850 { | |
851 lnum = curwin->w_cursor.lnum; | |
852 ++curwin->w_cursor.lnum; | |
853 del_lines((long)(oap->line_count - 1), TRUE); | |
854 curwin->w_cursor.lnum = lnum; | |
855 } | |
856 if (u_save_cursor() == FAIL) | |
857 return FAIL; | |
858 if (curbuf->b_p_ai) /* don't delete indent */ | |
859 { | |
860 beginline(BL_WHITE); /* cursor on first non-white */ | |
861 did_ai = TRUE; /* delete the indent when ESC hit */ | |
862 ai_col = curwin->w_cursor.col; | |
863 } | |
864 else | |
865 beginline(0); /* cursor in column 0 */ | |
866 truncate_line(FALSE); /* delete the rest of the line */ | |
867 /* leave cursor past last char in line */ | |
868 if (oap->line_count > 1) | |
869 u_clearline(); /* "U" command not possible after "2cc" */ | |
870 } | |
871 else | |
872 { | |
873 del_lines(oap->line_count, TRUE); | |
874 beginline(BL_WHITE | BL_FIX); | |
875 u_clearline(); /* "U" command not possible after "dd" */ | |
876 } | |
877 } | |
878 else | |
879 { | |
880 if (virtual_op) | |
881 { | |
882 int endcol = 0; | |
883 | |
884 /* For virtualedit: break the tabs that are partly included. */ | |
885 if (gchar_pos(&oap->start) == '\t') | |
886 { | |
887 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
888 return FAIL; | |
889 if (oap->line_count == 1) | |
890 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
891 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
892 oap->start = curwin->w_cursor; | |
893 if (oap->line_count == 1) | |
894 { | |
895 coladvance(endcol); | |
896 oap->end.col = curwin->w_cursor.col; | |
897 oap->end.coladd = curwin->w_cursor.coladd; | |
898 curwin->w_cursor = oap->start; | |
899 } | |
900 } | |
901 | |
902 /* Break a tab only when it's included in the area. */ | |
903 if (gchar_pos(&oap->end) == '\t' | |
904 && (int)oap->end.coladd < oap->inclusive) | |
905 { | |
906 /* save last line for undo */ | |
907 if (u_save((linenr_T)(oap->end.lnum - 1), | |
908 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
909 return FAIL; | |
910 curwin->w_cursor = oap->end; | |
911 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
912 oap->end = curwin->w_cursor; | |
913 curwin->w_cursor = oap->start; | |
914 } | |
915 } | |
916 | |
917 if (oap->line_count == 1) /* delete characters within one line */ | |
918 { | |
919 if (u_save_cursor() == FAIL) /* save line for undo */ | |
920 return FAIL; | |
921 | |
922 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 923 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 924 && oap->op_type == OP_CHANGE |
925 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 926 && !oap->is_VIsual) |
7 | 927 display_dollar(oap->end.col - !oap->inclusive); |
928 | |
929 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
930 | |
931 if (virtual_op) | |
932 { | |
933 /* fix up things for virtualedit-delete: | |
934 * break the tabs which are going to get in our way | |
935 */ | |
936 char_u *curline = ml_get_curline(); | |
937 int len = (int)STRLEN(curline); | |
938 | |
939 if (oap->end.coladd != 0 | |
940 && (int)oap->end.col >= len - 1 | |
941 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
942 n++; | |
943 /* Delete at least one char (e.g, when on a control char). */ | |
944 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
945 n = 1; | |
946 | |
947 /* When deleted a char in the line, reset coladd. */ | |
948 if (gchar_cursor() != NUL) | |
949 curwin->w_cursor.coladd = 0; | |
950 } | |
6826 | 951 (void)del_bytes((long)n, !virtual_op, |
952 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 953 } |
954 else /* delete characters between lines */ | |
955 { | |
956 pos_T curpos; | |
957 | |
958 /* save deleted and changed lines for undo */ | |
959 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
960 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
961 return FAIL; | |
962 | |
963 truncate_line(TRUE); /* delete from cursor to end of line */ | |
964 | |
965 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
966 ++curwin->w_cursor.lnum; | |
967 del_lines((long)(oap->line_count - 2), FALSE); | |
968 | |
6826 | 969 /* delete from start of line until op_end */ |
2957 | 970 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 971 curwin->w_cursor.col = 0; |
972 (void)del_bytes((long)n, !virtual_op, | |
973 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
974 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
975 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 976 } |
977 } | |
978 | |
979 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
980 | |
446 | 981 setmarks: |
7 | 982 if (oap->block_mode) |
983 { | |
984 curbuf->b_op_end.lnum = oap->end.lnum; | |
985 curbuf->b_op_end.col = oap->start.col; | |
986 } | |
987 else | |
988 curbuf->b_op_end = oap->start; | |
989 curbuf->b_op_start = oap->start; | |
990 | |
991 return OK; | |
992 } | |
993 | |
994 /* | |
995 * Adjust end of operating area for ending on a multi-byte character. | |
996 * Used for deletion. | |
997 */ | |
998 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
999 mb_adjust_opend(oparg_T *oap) |
7 | 1000 { |
1001 char_u *p; | |
1002 | |
1003 if (oap->inclusive) | |
1004 { | |
1005 p = ml_get(oap->end.lnum); | |
1006 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
1007 } | |
1008 } | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
1009 |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1010 /* |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1011 * Replace the character under the cursor with "c". |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1012 * This takes care of multi-byte characters. |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1013 */ |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1014 static void |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1015 replace_character(int c) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1016 { |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1017 int n = State; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1018 |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1019 State = REPLACE; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1020 ins_char(c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1021 State = n; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1022 /* Backup to the replaced character. */ |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1023 dec_cursor(); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1024 } |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
1025 |
7 | 1026 /* |
1027 * Replace a whole area with one character. | |
1028 */ | |
1029 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1030 op_replace(oparg_T *oap, int c) |
7 | 1031 { |
1032 int n, numc; | |
1033 int num_chars; | |
1034 char_u *newp, *oldp; | |
1035 size_t oldlen; | |
1036 struct block_def bd; | |
5428 | 1037 char_u *after_p = NULL; |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1038 int had_ctrl_v_cr = FALSE; |
7 | 1039 |
1040 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
1041 return OK; /* nothing to do */ | |
1042 | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1043 if (c == REPLACE_CR_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1044 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1045 had_ctrl_v_cr = TRUE; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1046 c = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1047 } |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1048 else if (c == REPLACE_NL_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1049 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1050 had_ctrl_v_cr = TRUE; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1051 c = NL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1052 } |
5428 | 1053 |
7 | 1054 if (has_mbyte) |
1055 mb_adjust_opend(oap); | |
1056 | |
1057 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1058 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1059 return FAIL; | |
1060 | |
1061 /* | |
1062 * block mode replace | |
1063 */ | |
1064 if (oap->block_mode) | |
1065 { | |
1066 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
1067 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
1068 { | |
1982 | 1069 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 1070 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
1071 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
1072 continue; /* nothing to replace */ | |
1073 | |
1074 /* n == number of extra chars required | |
1075 * If we split a TAB, it may be replaced by several characters. | |
1076 * Thus the number of characters may increase! | |
1077 */ | |
1078 /* If the range starts in virtual space, count the initial | |
1079 * coladd offset as part of "startspaces" */ | |
1080 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
1081 { | |
1082 pos_T vpos; | |
1083 | |
1982 | 1084 vpos.lnum = curwin->w_cursor.lnum; |
7 | 1085 getvpos(&vpos, oap->start_vcol); |
1086 bd.startspaces += vpos.coladd; | |
1087 n = bd.startspaces; | |
1088 } | |
1089 else | |
1090 /* allow for pre spaces */ | |
1091 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
1092 | |
1093 /* allow for post spp */ | |
1094 n += (bd.endspaces | |
1095 && !bd.is_oneChar | |
1096 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
1097 /* Figure out how many characters to replace. */ | |
1098 numc = oap->end_vcol - oap->start_vcol + 1; | |
1099 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
1100 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
1101 | |
1102 /* A double-wide character can be replaced only up to half the | |
1103 * times. */ | |
1104 if ((*mb_char2cells)(c) > 1) | |
1105 { | |
1106 if ((numc & 1) && !bd.is_short) | |
1107 { | |
1108 ++bd.endspaces; | |
1109 ++n; | |
1110 } | |
1111 numc = numc / 2; | |
1112 } | |
1113 | |
1114 /* Compute bytes needed, move character count to num_chars. */ | |
1115 num_chars = numc; | |
1116 numc *= (*mb_char2len)(c); | |
1117 /* oldlen includes textlen, so don't double count */ | |
1118 n += numc - bd.textlen; | |
1119 | |
1120 oldp = ml_get_curline(); | |
1121 oldlen = STRLEN(oldp); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1122 newp = alloc(oldlen + 1 + n); |
7 | 1123 if (newp == NULL) |
1124 continue; | |
1125 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
1126 /* copy up to deleted part */ | |
1127 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1128 oldp += bd.textcol + bd.textlen; | |
1129 /* insert pre-spaces */ | |
6929 | 1130 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 1131 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1132 /* REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1133 * literally. */ |
5428 | 1134 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
7 | 1135 { |
5428 | 1136 if (has_mbyte) |
1137 { | |
1138 n = (int)STRLEN(newp); | |
1139 while (--num_chars >= 0) | |
1140 n += (*mb_char2bytes)(c, newp + n); | |
1141 } | |
1142 else | |
6929 | 1143 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 1144 if (!bd.is_short) |
1145 { | |
1146 /* insert post-spaces */ | |
6929 | 1147 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 1148 /* copy the part after the changed part */ |
1149 STRMOVE(newp + STRLEN(newp), oldp); | |
1150 } | |
7 | 1151 } |
1152 else | |
1153 { | |
5428 | 1154 /* Replacing with \r or \n means splitting the line. */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1155 after_p = alloc(oldlen + 1 + n - STRLEN(newp)); |
5428 | 1156 if (after_p != NULL) |
1157 STRMOVE(after_p, oldp); | |
7 | 1158 } |
1159 /* replace the line */ | |
1160 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 1161 if (after_p != NULL) |
1162 { | |
1163 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
1164 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
1165 oap->end.lnum++; | |
1166 vim_free(after_p); | |
1167 } | |
7 | 1168 } |
1169 } | |
1170 else | |
1171 { | |
1172 /* | |
1173 * MCHAR and MLINE motion replace. | |
1174 */ | |
1175 if (oap->motion_type == MLINE) | |
1176 { | |
1177 oap->start.col = 0; | |
1178 curwin->w_cursor.col = 0; | |
1179 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1180 if (oap->end.col) | |
1181 --oap->end.col; | |
1182 } | |
1183 else if (!oap->inclusive) | |
1184 dec(&(oap->end)); | |
1185 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
1186 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 1187 { |
1188 n = gchar_cursor(); | |
1189 if (n != NUL) | |
1190 { | |
1191 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
1192 { | |
1193 /* This is slow, but it handles replacing a single-byte | |
1194 * with a multi-byte and the other way around. */ | |
4203 | 1195 if (curwin->w_cursor.lnum == oap->end.lnum) |
1196 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1197 replace_character(c); |
7 | 1198 } |
1199 else | |
1200 { | |
1201 if (n == TAB) | |
1202 { | |
1203 int end_vcol = 0; | |
1204 | |
1205 if (curwin->w_cursor.lnum == oap->end.lnum) | |
1206 { | |
1207 /* oap->end has to be recalculated when | |
1208 * the tab breaks */ | |
1209 end_vcol = getviscol2(oap->end.col, | |
1210 oap->end.coladd); | |
1211 } | |
1212 coladvance_force(getviscol()); | |
1213 if (curwin->w_cursor.lnum == oap->end.lnum) | |
1214 getvpos(&oap->end, end_vcol); | |
1215 } | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1216 PBYTE(curwin->w_cursor, c); |
7 | 1217 } |
1218 } | |
1219 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
1220 { | |
1221 int virtcols = oap->end.coladd; | |
1222 | |
1223 if (curwin->w_cursor.lnum == oap->start.lnum | |
1224 && oap->start.col == oap->end.col && oap->start.coladd) | |
1225 virtcols -= oap->start.coladd; | |
1226 | |
1227 /* oap->end has been trimmed so it's effectively inclusive; | |
1228 * as a result an extra +1 must be counted so we don't | |
1229 * trample the NUL byte. */ | |
1230 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
1231 curwin->w_cursor.col -= (virtcols + 1); | |
1232 for (; virtcols >= 0; virtcols--) | |
1233 { | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1234 if ((*mb_char2len)(c) > 1) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1235 replace_character(c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1236 else |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1237 PBYTE(curwin->w_cursor, c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1238 if (inc(&curwin->w_cursor) == -1) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1239 break; |
7 | 1240 } |
1241 } | |
1242 | |
1243 /* Advance to next character, stop at the end of the file. */ | |
1244 if (inc_cursor() == -1) | |
1245 break; | |
1246 } | |
1247 } | |
1248 | |
1249 curwin->w_cursor = oap->start; | |
1250 check_cursor(); | |
1251 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
1252 | |
1253 /* Set "'[" and "']" marks. */ | |
1254 curbuf->b_op_start = oap->start; | |
1255 curbuf->b_op_end = oap->end; | |
1256 | |
1257 return OK; | |
1258 } | |
1259 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
1260 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 1261 |
7 | 1262 /* |
1263 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
1264 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1265 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1266 op_tilde(oparg_T *oap) |
7 | 1267 { |
1268 pos_T pos; | |
1269 struct block_def bd; | |
1528 | 1270 int did_change = FALSE; |
7 | 1271 |
1272 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1273 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1274 return; | |
1275 | |
1276 pos = oap->start; | |
1277 if (oap->block_mode) /* Visual block mode */ | |
1278 { | |
1279 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
1280 { | |
1766 | 1281 int one_change; |
1282 | |
7 | 1283 block_prep(oap, &bd, pos.lnum, FALSE); |
1284 pos.col = bd.textcol; | |
1766 | 1285 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
1286 did_change |= one_change; | |
1525 | 1287 |
5735 | 1288 #ifdef FEAT_NETBEANS_INTG |
2210 | 1289 if (netbeans_active() && one_change) |
7 | 1290 { |
1291 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
1292 | |
33 | 1293 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
1294 (long)bd.textlen); | |
7 | 1295 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 1296 &ptr[bd.textcol], bd.textlen); |
7 | 1297 } |
5735 | 1298 #endif |
7 | 1299 } |
1300 if (did_change) | |
1301 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
1302 } | |
1303 else /* not block mode */ | |
1304 { | |
1305 if (oap->motion_type == MLINE) | |
1306 { | |
1307 oap->start.col = 0; | |
1308 pos.col = 0; | |
1309 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1310 if (oap->end.col) | |
1311 --oap->end.col; | |
1312 } | |
1313 else if (!oap->inclusive) | |
1314 dec(&(oap->end)); | |
1315 | |
1528 | 1316 if (pos.lnum == oap->end.lnum) |
1317 did_change = swapchars(oap->op_type, &pos, | |
1318 oap->end.col - pos.col + 1); | |
1319 else | |
1320 for (;;) | |
1321 { | |
1322 did_change |= swapchars(oap->op_type, &pos, | |
1323 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
1324 (int)STRLEN(ml_get_pos(&pos))); | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
1325 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 1326 break; |
1327 } | |
7 | 1328 if (did_change) |
1329 { | |
1330 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
1331 0L); | |
1332 #ifdef FEAT_NETBEANS_INTG | |
2210 | 1333 if (netbeans_active() && did_change) |
7 | 1334 { |
1335 char_u *ptr; | |
1336 int count; | |
1337 | |
1338 pos = oap->start; | |
1339 while (pos.lnum < oap->end.lnum) | |
1340 { | |
1341 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 1342 count = (int)STRLEN(ptr) - pos.col; |
33 | 1343 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 1344 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 1345 &ptr[pos.col], count); |
7 | 1346 pos.col = 0; |
1347 pos.lnum++; | |
1348 } | |
1349 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
1350 count = oap->end.col - pos.col + 1; | |
33 | 1351 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 1352 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 1353 &ptr[pos.col], count); |
7 | 1354 } |
1355 #endif | |
1356 } | |
1357 } | |
1358 | |
1359 if (!did_change && oap->is_VIsual) | |
1360 /* No change: need to remove the Visual selection */ | |
1361 redraw_curbuf_later(INVERTED); | |
1362 | |
1363 /* | |
1364 * Set '[ and '] marks. | |
1365 */ | |
1366 curbuf->b_op_start = oap->start; | |
1367 curbuf->b_op_end = oap->end; | |
1368 | |
1369 if (oap->line_count > p_report) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1370 smsg(NGETTEXT("%ld line changed", "%ld lines changed", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
1371 oap->line_count), oap->line_count); |
7 | 1372 } |
1373 | |
1374 /* | |
1525 | 1375 * Invoke swapchar() on "length" bytes at position "pos". |
1376 * "pos" is advanced to just after the changed characters. | |
1377 * "length" is rounded up to include the whole last multi-byte character. | |
1378 * Also works correctly when the number of bytes changes. | |
1379 * Returns TRUE if some character was changed. | |
1380 */ | |
1381 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1382 swapchars(int op_type, pos_T *pos, int length) |
1525 | 1383 { |
1384 int todo; | |
1385 int did_change = 0; | |
1386 | |
1387 for (todo = length; todo > 0; --todo) | |
1388 { | |
1389 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1390 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1391 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1392 |
1525 | 1393 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1394 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1395 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1396 } |
1525 | 1397 did_change |= swapchar(op_type, pos); |
1398 if (inc(pos) == -1) /* at end of file */ | |
1399 break; | |
1400 } | |
1401 return did_change; | |
1402 } | |
1403 | |
1404 /* | |
7 | 1405 * If op_type == OP_UPPER: make uppercase, |
1406 * if op_type == OP_LOWER: make lowercase, | |
1407 * if op_type == OP_ROT13: do rot13 encoding, | |
1408 * else swap case of character at 'pos' | |
1409 * returns TRUE when something actually changed. | |
1410 */ | |
1411 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1412 swapchar(int op_type, pos_T *pos) |
7 | 1413 { |
1414 int c; | |
1415 int nc; | |
1416 | |
1417 c = gchar_pos(pos); | |
1418 | |
1419 /* Only do rot13 encoding for ASCII characters. */ | |
1420 if (c >= 0x80 && op_type == OP_ROT13) | |
1421 return FALSE; | |
1422 | |
1525 | 1423 if (op_type == OP_UPPER && c == 0xdf |
1424 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 1425 { |
1426 pos_T sp = curwin->w_cursor; | |
1427 | |
1428 /* Special handling of German sharp s: change to "SS". */ | |
1429 curwin->w_cursor = *pos; | |
1430 del_char(FALSE); | |
1431 ins_char('S'); | |
1432 ins_char('S'); | |
1433 curwin->w_cursor = sp; | |
1434 inc(pos); | |
1435 } | |
1436 | |
7 | 1437 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
1438 return FALSE; | |
1439 nc = c; | |
1440 if (MB_ISLOWER(c)) | |
1441 { | |
1442 if (op_type == OP_ROT13) | |
1443 nc = ROT13(c, 'a'); | |
1444 else if (op_type != OP_LOWER) | |
1445 nc = MB_TOUPPER(c); | |
1446 } | |
1447 else if (MB_ISUPPER(c)) | |
1448 { | |
1449 if (op_type == OP_ROT13) | |
1450 nc = ROT13(c, 'A'); | |
1451 else if (op_type != OP_UPPER) | |
1452 nc = MB_TOLOWER(c); | |
1453 } | |
1454 if (nc != c) | |
1455 { | |
1456 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
1457 { | |
1458 pos_T sp = curwin->w_cursor; | |
1459 | |
1460 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
1461 /* don't use del_char(), it also removes composing chars */ |
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
1462 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 1463 ins_char(nc); |
1464 curwin->w_cursor = sp; | |
1465 } | |
1466 else | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
1467 PBYTE(*pos, nc); |
7 | 1468 return TRUE; |
1469 } | |
1470 return FALSE; | |
1471 } | |
1472 | |
1473 /* | |
1474 * op_insert - Insert and append operators for Visual mode. | |
1475 */ | |
1476 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1477 op_insert(oparg_T *oap, long count1) |
7 | 1478 { |
1479 long ins_len, pre_textlen = 0; | |
1480 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
1481 colnr_T ind_pre = 0, ind_post; |
7 | 1482 struct block_def bd; |
1483 int i; | |
6579 | 1484 pos_T t1; |
7 | 1485 |
1486 /* edit() changes this - record it for OP_APPEND */ | |
1487 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
1488 | |
1489 /* vis block is still marked. Get rid of it now. */ | |
1490 curwin->w_cursor.lnum = oap->start.lnum; | |
1491 update_screen(INVERTED); | |
1492 | |
1493 if (oap->block_mode) | |
1494 { | |
1495 /* When 'virtualedit' is used, need to insert the extra spaces before | |
1496 * doing block_prep(). When only "block" is used, virtual edit is | |
1497 * already disabled, but still need it when calling | |
1498 * coladvance_force(). */ | |
1499 if (curwin->w_cursor.coladd > 0) | |
1500 { | |
1501 int old_ve_flags = ve_flags; | |
1502 | |
1503 ve_flags = VE_ALL; | |
1504 if (u_save_cursor() == FAIL) | |
1505 return; | |
1506 coladvance_force(oap->op_type == OP_APPEND | |
1507 ? oap->end_vcol + 1 : getviscol()); | |
1508 if (oap->op_type == OP_APPEND) | |
1509 --curwin->w_cursor.col; | |
1510 ve_flags = old_ve_flags; | |
1511 } | |
1512 /* Get the info about the block before entering the text */ | |
1513 block_prep(oap, &bd, oap->start.lnum, TRUE); | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
1514 /* Get indent information */ |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
1515 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 1516 firstline = ml_get(oap->start.lnum) + bd.textcol; |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
1517 |
7 | 1518 if (oap->op_type == OP_APPEND) |
1519 firstline += bd.textlen; | |
1520 pre_textlen = (long)STRLEN(firstline); | |
1521 } | |
1522 | |
1523 if (oap->op_type == OP_APPEND) | |
1524 { | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1525 if (oap->block_mode && curwin->w_cursor.coladd == 0) |
7 | 1526 { |
1527 /* Move the cursor to the character right of the block. */ | |
1528 curwin->w_set_curswant = TRUE; | |
1529 while (*ml_get_cursor() != NUL | |
1530 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
1531 ++curwin->w_cursor.col; | |
1532 if (bd.is_short && !bd.is_MAX) | |
1533 { | |
1534 /* First line was too short, make it longer and adjust the | |
1535 * values in "bd". */ | |
1536 if (u_save_cursor() == FAIL) | |
1537 return; | |
1538 for (i = 0; i < bd.endspaces; ++i) | |
1539 ins_char(' '); | |
1540 bd.textlen += bd.endspaces; | |
1541 } | |
1542 } | |
1543 else | |
1544 { | |
1545 curwin->w_cursor = oap->end; | |
893 | 1546 check_cursor_col(); |
7 | 1547 |
1548 /* Works just like an 'i'nsert on the next character. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
1549 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 1550 && oap->start_vcol != oap->end_vcol) |
1551 inc_cursor(); | |
1552 } | |
1553 } | |
1554 | |
6579 | 1555 t1 = oap->start; |
10803
065da86ca6d2
patch 8.0.0291: Visual block insertion does not insert in all lines
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
1556 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 1557 |
6579 | 1558 /* When a tab was inserted, and the characters in front of the tab |
1559 * have been converted to a tab as well, the column of the cursor | |
1560 * might have actually been reduced, so need to adjust here. */ | |
1561 if (t1.lnum == curbuf->b_op_start_orig.lnum | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
1562 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 1563 oap->start = curbuf->b_op_start_orig; |
1564 | |
1477 | 1565 /* If user has moved off this line, we don't know what to do, so do |
1566 * nothing. | |
1567 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
1568 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 1569 return; |
1570 | |
1571 if (oap->block_mode) | |
1572 { | |
1573 struct block_def bd2; | |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1574 int did_indent = FALSE; |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1575 size_t len; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1576 int add; |
7 | 1577 |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1578 /* If indent kicked in, the firstline might have changed |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1579 * but only do that, if the indent actually increased. */ |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1580 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1581 if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1582 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1583 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1584 bd.start_vcol += ind_post - ind_pre; |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1585 did_indent = TRUE; |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1586 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1587 |
5471 | 1588 /* The user may have moved the cursor before inserting something, try |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1589 * to adjust the block for that. But only do it, if the difference |
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1590 * does not come from indent kicking in. */ |
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1591 if (oap->start.lnum == curbuf->b_op_start_orig.lnum |
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1592 && !bd.is_MAX && !did_indent) |
5471 | 1593 { |
1594 if (oap->op_type == OP_INSERT | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1595 && oap->start.col + oap->start.coladd |
5730 | 1596 != curbuf->b_op_start_orig.col |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1597 + curbuf->b_op_start_orig.coladd) |
5471 | 1598 { |
6579 | 1599 int t = getviscol2(curbuf->b_op_start_orig.col, |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1600 curbuf->b_op_start_orig.coladd); |
5680 | 1601 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 1602 pre_textlen -= t - oap->start_vcol; |
1603 oap->start_vcol = t; | |
5471 | 1604 } |
1605 else if (oap->op_type == OP_APPEND | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1606 && oap->end.col + oap->end.coladd |
5730 | 1607 >= curbuf->b_op_start_orig.col |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1608 + curbuf->b_op_start_orig.coladd) |
5471 | 1609 { |
6579 | 1610 int t = getviscol2(curbuf->b_op_start_orig.col, |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1611 curbuf->b_op_start_orig.coladd); |
5680 | 1612 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 1613 /* reset pre_textlen to the value of OP_INSERT */ |
1614 pre_textlen += bd.textlen; | |
6579 | 1615 pre_textlen -= t - oap->start_vcol; |
1616 oap->start_vcol = t; | |
5471 | 1617 oap->op_type = OP_INSERT; |
1618 } | |
1619 } | |
1620 | |
7 | 1621 /* |
1622 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 1623 * tabs. Get the starting column again and correct the length. |
7 | 1624 * Don't do this when "$" used, end-of-line will have changed. |
1625 */ | |
1626 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
1627 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
1628 { | |
1629 if (oap->op_type == OP_APPEND) | |
1630 { | |
1631 pre_textlen += bd2.textlen - bd.textlen; | |
1632 if (bd2.endspaces) | |
1633 --bd2.textlen; | |
1634 } | |
1635 bd.textcol = bd2.textcol; | |
1636 bd.textlen = bd2.textlen; | |
1637 } | |
1638 | |
1639 /* | |
1640 * Subsequent calls to ml_get() flush the firstline data - take a | |
1641 * copy of the required string. | |
1642 */ | |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1643 firstline = ml_get(oap->start.lnum); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1644 len = STRLEN(firstline); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1645 add = bd.textcol; |
7 | 1646 if (oap->op_type == OP_APPEND) |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1647 add += bd.textlen; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1648 if ((size_t)add > len) |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1649 firstline += len; // short line, point to the NUL |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1650 else |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1651 firstline += add; |
3421 | 1652 if (pre_textlen >= 0 |
1653 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 1654 { |
1655 ins_text = vim_strnsave(firstline, (int)ins_len); | |
1656 if (ins_text != NULL) | |
1657 { | |
1658 /* block handled here */ | |
1659 if (u_save(oap->start.lnum, | |
1660 (linenr_T)(oap->end.lnum + 1)) == OK) | |
1661 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
1662 &bd); | |
1663 | |
1664 curwin->w_cursor.col = oap->start.col; | |
1665 check_cursor(); | |
1666 vim_free(ins_text); | |
1667 } | |
1668 } | |
1669 } | |
1670 } | |
1671 | |
1672 /* | |
1673 * op_change - handle a change operation | |
1674 * | |
1675 * return TRUE if edit() returns because of a CTRL-O command | |
1676 */ | |
1677 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1678 op_change(oparg_T *oap) |
7 | 1679 { |
1680 colnr_T l; | |
1681 int retval; | |
1682 long offset; | |
1683 linenr_T linenr; | |
1392 | 1684 long ins_len; |
1685 long pre_textlen = 0; | |
1686 long pre_indent = 0; | |
7 | 1687 char_u *firstline; |
1688 char_u *ins_text, *newp, *oldp; | |
1689 struct block_def bd; | |
1690 | |
1691 l = oap->start.col; | |
1692 if (oap->motion_type == MLINE) | |
1693 { | |
1694 l = 0; | |
1695 #ifdef FEAT_SMARTINDENT | |
1696 if (!p_paste && curbuf->b_p_si | |
1697 # ifdef FEAT_CINDENT | |
1698 && !curbuf->b_p_cin | |
1699 # endif | |
1700 ) | |
1701 can_si = TRUE; /* It's like opening a new line, do si */ | |
1702 #endif | |
1703 } | |
1704 | |
1705 /* First delete the text in the region. In an empty buffer only need to | |
1706 * save for undo */ | |
1707 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
1708 { | |
1709 if (u_save_cursor() == FAIL) | |
1710 return FALSE; | |
1711 } | |
1712 else if (op_delete(oap) == FAIL) | |
1713 return FALSE; | |
1714 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
1715 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 1716 && !virtual_op) |
1717 inc_cursor(); | |
1718 | |
1719 /* check for still on same line (<CR> in inserted text meaningless) */ | |
1720 /* skip blank lines too */ | |
1721 if (oap->block_mode) | |
1722 { | |
1723 /* Add spaces before getting the current line length. */ | |
1724 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
1725 || gchar_cursor() == NUL)) | |
1726 coladvance_force(getviscol()); | |
1392 | 1727 firstline = ml_get(oap->start.lnum); |
1728 pre_textlen = (long)STRLEN(firstline); | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
1729 pre_indent = (long)getwhitecols(firstline); |
7 | 1730 bd.textcol = curwin->w_cursor.col; |
1731 } | |
1732 | |
1733 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1734 if (oap->motion_type == MLINE) | |
1735 fix_indent(); | |
1736 #endif | |
1737 | |
1738 retval = edit(NUL, FALSE, (linenr_T)1); | |
1739 | |
1740 /* | |
39 | 1741 * In Visual block mode, handle copying the new text to all lines of the |
7 | 1742 * block. |
1477 | 1743 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 1744 */ |
1477 | 1745 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 1746 { |
1392 | 1747 /* Auto-indenting may have changed the indent. If the cursor was past |
1748 * the indent, exclude that indent change from the inserted text. */ | |
7 | 1749 firstline = ml_get(oap->start.lnum); |
1403 | 1750 if (bd.textcol > (colnr_T)pre_indent) |
7 | 1751 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
1752 long new_indent = (long)getwhitecols(firstline); |
1392 | 1753 |
1754 pre_textlen += new_indent - pre_indent; | |
1755 bd.textcol += new_indent - pre_indent; | |
1756 } | |
1757 | |
1758 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
1759 if (ins_len > 0) | |
1760 { | |
1761 /* Subsequent calls to ml_get() flush the firstline data - take a | |
1762 * copy of the inserted text. */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1763 if ((ins_text = alloc(ins_len + 1)) != NULL) |
7 | 1764 { |
419 | 1765 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 1766 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
1767 linenr++) | |
1768 { | |
1769 block_prep(oap, &bd, linenr, TRUE); | |
1770 if (!bd.is_short || virtual_op) | |
1771 { | |
1772 pos_T vpos; | |
1773 | |
1774 /* If the block starts in virtual space, count the | |
1775 * initial coladd offset as part of "startspaces" */ | |
1776 if (bd.is_short) | |
1777 { | |
1982 | 1778 vpos.lnum = linenr; |
7 | 1779 (void)getvpos(&vpos, oap->start_vcol); |
1780 } | |
1781 else | |
1782 vpos.coladd = 0; | |
1783 oldp = ml_get(linenr); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1784 newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); |
7 | 1785 if (newp == NULL) |
1786 continue; | |
1787 /* copy up to block start */ | |
1788 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1789 offset = bd.textcol; | |
6929 | 1790 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 1791 offset += vpos.coladd; |
1792 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
1793 offset += ins_len; | |
1794 oldp += bd.textcol; | |
1622 | 1795 STRMOVE(newp + offset, oldp); |
7 | 1796 ml_replace(linenr, newp, FALSE); |
1797 } | |
1798 } | |
1799 check_cursor(); | |
1800 | |
1801 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
1802 } | |
1803 vim_free(ins_text); | |
1804 } | |
1805 } | |
1806 | |
1807 return retval; | |
1808 } | |
1809 | |
1810 /* | |
844 | 1811 * When the cursor is on the NUL past the end of the line and it should not be |
1812 * there move it left. | |
1813 */ | |
1814 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1815 adjust_cursor_eol(void) |
844 | 1816 { |
1817 if (curwin->w_cursor.col > 0 | |
1818 && gchar_cursor() == NUL | |
773 | 1819 && (ve_flags & VE_ONEMORE) == 0 |
7 | 1820 && !(restart_edit || (State & INSERT))) |
1821 { | |
557 | 1822 /* Put the cursor on the last character in the line. */ |
555 | 1823 dec_cursor(); |
844 | 1824 |
7 | 1825 if (ve_flags == VE_ALL) |
557 | 1826 { |
1827 colnr_T scol, ecol; | |
1828 | |
1829 /* Coladd is set to the width of the last character. */ | |
1830 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
1831 curwin->w_cursor.coladd = ecol - scol + 1; | |
1832 } | |
7 | 1833 } |
1834 } | |
1835 | |
3562 | 1836 /* |
1837 * If "process" is TRUE and the line begins with a comment leader (possibly | |
1838 * after some white space), return a pointer to the text after it. Put a boolean | |
1839 * value indicating whether the line ends with an unclosed comment in | |
1840 * "is_comment". | |
1841 * line - line to be processed, | |
1842 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 1843 * comment, |
3562 | 1844 * include_space - whether to also skip space following the comment leader, |
1845 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 1846 * comment. |
3562 | 1847 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1848 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1849 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1850 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1851 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1852 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1853 int *is_comment) |
3562 | 1854 { |
1855 char_u *comment_flags = NULL; | |
1856 int lead_len; | |
1857 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
1858 | |
1859 *is_comment = FALSE; | |
1860 if (leader_offset != -1) | |
1861 { | |
1862 /* Let's check whether the line ends with an unclosed comment. | |
1863 * If the last comment leader has COM_END in flags, there's no comment. | |
1864 */ | |
1865 while (*comment_flags) | |
1866 { | |
1867 if (*comment_flags == COM_END | |
1868 || *comment_flags == ':') | |
1869 break; | |
1870 ++comment_flags; | |
1871 } | |
1872 if (*comment_flags != COM_END) | |
1873 *is_comment = TRUE; | |
1874 } | |
1875 | |
1876 if (process == FALSE) | |
1877 return line; | |
1878 | |
1879 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
1880 | |
1881 if (lead_len == 0) | |
1882 return line; | |
1883 | |
1884 /* Find: | |
1885 * - COM_END, | |
1886 * - colon, | |
1887 * whichever comes first. | |
1888 */ | |
1889 while (*comment_flags) | |
1890 { | |
3580 | 1891 if (*comment_flags == COM_END |
3562 | 1892 || *comment_flags == ':') |
1893 break; | |
1894 ++comment_flags; | |
1895 } | |
1896 | |
1897 /* If we found a colon, it means that we are not processing a line | |
3580 | 1898 * starting with a closing part of a three-part comment. That's good, |
1899 * because we don't want to remove those as this would be annoying. | |
3562 | 1900 */ |
1901 if (*comment_flags == ':' || *comment_flags == NUL) | |
1902 line += lead_len; | |
1903 | |
1904 return line; | |
1905 } | |
1906 | |
7 | 1907 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1908 * Join 'count' lines (minimal 2) at cursor position. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1909 * When "save_undo" is TRUE save lines for undo first. |
5848 | 1910 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
1911 * leaders should not be removed. | |
1912 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
1913 * to set those marks. | |
7 | 1914 * |
1217 | 1915 * return FAIL for failure, OK otherwise |
7 | 1916 */ |
1917 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1918 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1919 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1920 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1921 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1922 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1923 int setmark) |
7 | 1924 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1925 char_u *curr = NULL; |
2597 | 1926 char_u *curr_start = NULL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1927 char_u *cend; |
7 | 1928 char_u *newp; |
2597 | 1929 char_u *spaces; /* number of spaces inserted before a line */ |
2310
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
1930 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
1931 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1932 int currsize = 0; /* size of the current line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1933 int sumsize = 0; /* size of the long new line */ |
7 | 1934 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1935 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1936 int ret = OK; |
3574 | 1937 int *comments = NULL; |
3562 | 1938 int remove_comments = (use_formatoptions == TRUE) |
1939 && has_format_option(FO_REMOVE_COMS); | |
1940 int prev_was_comment; | |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1941 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1942 textprop_T **prop_lines = NULL; |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1943 int *prop_lengths = NULL; |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1944 #endif |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1945 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1946 if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1), |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1947 (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1948 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1949 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1950 /* Allocate an array to store the number of spaces inserted before each |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1951 * line. We will use it to pre-compute the length of the new line and the |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1952 * proper placement of each original line in the new one. */ |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1953 spaces = lalloc_clear(count, TRUE); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1954 if (spaces == NULL) |
7 | 1955 return FAIL; |
3562 | 1956 if (remove_comments) |
1957 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1958 comments = lalloc_clear(count * sizeof(int), TRUE); |
3562 | 1959 if (comments == NULL) |
1960 { | |
1961 vim_free(spaces); | |
1962 return FAIL; | |
1963 } | |
1964 } | |
7 | 1965 |
1966 /* | |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1967 * Don't move anything yet, just compute the final line length |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1968 * and setup the array of space strings lengths |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1969 * This loops forward over the joined lines. |
7 | 1970 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1971 for (t = 0; t < count; ++t) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1972 { |
2597 | 1973 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 1974 if (t == 0 && setmark) |
5664 | 1975 { |
1976 /* Set the '[ mark. */ | |
1977 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
1978 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
1979 } | |
3562 | 1980 if (remove_comments) |
1981 { | |
1982 /* We don't want to remove the comment leader if the | |
1983 * previous line is not a comment. */ | |
1984 if (t > 0 && prev_was_comment) | |
1985 { | |
1986 | |
1987 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
1988 &prev_was_comment); | |
3576 | 1989 comments[t] = (int)(new_curr - curr); |
3562 | 1990 curr = new_curr; |
1991 } | |
1992 else | |
1993 curr = skip_comment(curr, FALSE, insert_space, | |
1994 &prev_was_comment); | |
1995 } | |
1996 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1997 if (insert_space && t > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1998 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1999 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2000 if (*curr != ')' && currsize != 0 && endcurr1 != TAB |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2001 && (!has_format_option(FO_MBYTE_JOIN) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2002 || (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2003 && (!has_format_option(FO_MBYTE_JOIN2) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2004 || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2005 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2006 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2007 /* don't add a space if the line is ending in a space */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2008 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2009 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2010 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2011 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2012 /* extra space when 'joinspaces' set and line ends in '.' */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2013 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2014 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2015 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2016 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2017 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2018 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2019 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2020 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2021 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2022 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2023 if (insert_space && currsize > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2024 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2025 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2026 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2027 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2028 MB_PTR_BACK(curr, cend); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2029 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2030 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2031 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2032 MB_PTR_BACK(curr, cend); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2033 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2034 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2035 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2036 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2037 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2038 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2039 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2040 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2041 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2042 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2043 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2044 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2045 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2046 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2047 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2048 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2049 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2050 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2051 /* store the column position before last line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2052 col = sumsize - currsize - spaces[count - 1]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2053 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2054 /* allocate the space for the new line */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
2055 newp = alloc(sumsize + 1); |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2056 if (newp == NULL) |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2057 { |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2058 ret = FAIL; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2059 goto theend; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2060 } |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2061 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2062 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2063 |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2064 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2065 // We need to move properties of the lines that are going to be deleted to |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2066 // the new long one. |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2067 if (curbuf->b_has_textprop && !text_prop_frozen) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2068 { |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2069 // Allocate an array to copy the text properties of joined lines into. |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2070 // And another array to store the number of properties in each line. |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2071 prop_lines = ALLOC_CLEAR_MULT(textprop_T *, count - 1); |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
2072 prop_lengths = ALLOC_CLEAR_MULT(int, count - 1); |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2073 if (prop_lengths == NULL) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2074 VIM_CLEAR(prop_lines); |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2075 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2076 #endif |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2077 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2078 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2079 * Move affected lines to the new long one. |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2080 * This loops backwards over the joined lines, including the original line. |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2081 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2082 * Move marks from each deleted line to the joined line, adjusting the |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2083 * column. This is not Vi compatible, but Vi deletes the marks, thus that |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2084 * should not really be a problem. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2085 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2086 for (t = count - 1; ; --t) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2087 { |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2088 int spaces_removed; |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2089 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2090 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2091 mch_memmove(cend, curr, (size_t)currsize); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2092 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2093 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2094 cend -= spaces[t]; |
6929 | 2095 vim_memset(cend, ' ', (size_t)(spaces[t])); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2096 } |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2097 |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2098 // If deleting more spaces than adding, the cursor moves no more than |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2099 // what is added if it is inside these spaces. |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2100 spaces_removed = (curr - curr_start) - spaces[t]; |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2101 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2102 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2103 (long)(cend - newp - spaces_removed), spaces_removed); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2104 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2105 break; |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2106 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2107 if (prop_lines != NULL) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2108 adjust_props_for_join(curwin->w_cursor.lnum + t, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2109 prop_lines + t - 1, prop_lengths + t - 1, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2110 (long)(cend - newp - spaces_removed), spaces_removed); |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2111 #endif |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2112 |
2597 | 2113 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 2114 if (remove_comments) |
2115 curr += comments[t - 1]; | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2116 if (insert_space && t > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2117 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2118 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2119 } |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2120 |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2121 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2122 if (prop_lines != NULL) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2123 join_prop_lines(curwin->w_cursor.lnum, newp, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2124 prop_lines, prop_lengths, count); |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2125 else |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2126 #endif |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
2127 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
7 | 2128 |
5848 | 2129 if (setmark) |
2130 { | |
2131 /* Set the '] mark. */ | |
2132 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
16680
c263acbbd961
patch 8.1.1342: using freed memory when joining line with text property
Bram Moolenaar <Bram@vim.org>
parents:
16678
diff
changeset
|
2133 curwin->w_buffer->b_op_end.col = (colnr_T)sumsize; |
5848 | 2134 } |
5664 | 2135 |
7 | 2136 /* Only report the change in the first line here, del_lines() will report |
2137 * the deleted line. */ | |
2138 changed_lines(curwin->w_cursor.lnum, currsize, | |
2139 curwin->w_cursor.lnum + 1, 0L); | |
2140 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2141 * Delete following lines. To do this we move the cursor there |
7 | 2142 * briefly, and then move it back. After del_lines() the cursor may |
2143 * have moved up (last line deleted), so the current lnum is kept in t. | |
2144 */ | |
2145 t = curwin->w_cursor.lnum; | |
2146 ++curwin->w_cursor.lnum; | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2147 del_lines(count - 1, FALSE); |
7 | 2148 curwin->w_cursor.lnum = t; |
2149 | |
2150 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2151 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2152 * Vi compatible: use the column of the first join |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2310
diff
changeset
|
2153 * vim: use the column of the last join |
7 | 2154 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2155 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2156 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 2157 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2158 |
7 | 2159 curwin->w_cursor.coladd = 0; |
2160 curwin->w_set_curswant = TRUE; | |
2161 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2162 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2163 vim_free(spaces); |
3562 | 2164 if (remove_comments) |
2165 vim_free(comments); | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2166 return ret; |
7 | 2167 } |
2168 | |
2169 /* | |
2170 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
2171 * the first line. White-space is ignored. Note that the whole of | |
2172 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
2173 */ | |
2174 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2175 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2176 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2177 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2178 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2179 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2180 char_u *leader2_flags) |
7 | 2181 { |
2182 int idx1 = 0, idx2 = 0; | |
2183 char_u *p; | |
2184 char_u *line1; | |
2185 char_u *line2; | |
2186 | |
2187 if (leader1_len == 0) | |
2188 return (leader2_len == 0); | |
2189 | |
2190 /* | |
2191 * If first leader has 'f' flag, the lines can be joined only if the | |
2192 * second line does not have a leader. | |
2193 * If first leader has 'e' flag, the lines can never be joined. | |
2194 * If fist leader has 's' flag, the lines can only be joined if there is | |
2195 * some text after it and the second line has the 'm' flag. | |
2196 */ | |
2197 if (leader1_flags != NULL) | |
2198 { | |
2199 for (p = leader1_flags; *p && *p != ':'; ++p) | |
2200 { | |
2201 if (*p == COM_FIRST) | |
2202 return (leader2_len == 0); | |
2203 if (*p == COM_END) | |
2204 return FALSE; | |
2205 if (*p == COM_START) | |
2206 { | |
2207 if (*(ml_get(lnum) + leader1_len) == NUL) | |
2208 return FALSE; | |
2209 if (leader2_flags == NULL || leader2_len == 0) | |
2210 return FALSE; | |
2211 for (p = leader2_flags; *p && *p != ':'; ++p) | |
2212 if (*p == COM_MIDDLE) | |
2213 return TRUE; | |
2214 return FALSE; | |
2215 } | |
2216 } | |
2217 } | |
2218 | |
2219 /* | |
2220 * Get current line and next line, compare the leaders. | |
2221 * The first line has to be saved, only one line can be locked at a time. | |
2222 */ | |
2223 line1 = vim_strsave(ml_get(lnum)); | |
2224 if (line1 != NULL) | |
2225 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2226 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 2227 ; |
2228 line2 = ml_get(lnum + 1); | |
2229 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
2230 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2231 if (!VIM_ISWHITE(line2[idx2])) |
7 | 2232 { |
2233 if (line1[idx1++] != line2[idx2]) | |
2234 break; | |
2235 } | |
2236 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2237 while (VIM_ISWHITE(line1[idx1])) |
7 | 2238 ++idx1; |
2239 } | |
2240 vim_free(line1); | |
2241 } | |
2242 return (idx2 == leader2_len && idx1 == leader1_len); | |
2243 } | |
2244 | |
2245 /* | |
3252 | 2246 * Implementation of the format operator 'gq'. |
7 | 2247 */ |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
2248 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2249 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2250 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2251 int keep_cursor) /* keep cursor on same text char */ |
7 | 2252 { |
2253 long old_line_count = curbuf->b_ml.ml_line_count; | |
2254 | |
2255 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
2256 * can put it back there. */ | |
2257 curwin->w_cursor = oap->cursor_start; | |
2258 | |
2259 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2260 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2261 return; | |
2262 curwin->w_cursor = oap->start; | |
2263 | |
2264 if (oap->is_VIsual) | |
2265 /* When there is no change: need to remove the Visual selection */ | |
2266 redraw_curbuf_later(INVERTED); | |
2267 | |
2268 /* Set '[ mark at the start of the formatted area */ | |
2269 curbuf->b_op_start = oap->start; | |
2270 | |
2271 /* For "gw" remember the cursor position and put it back below (adjusted | |
2272 * for joined and split lines). */ | |
2273 if (keep_cursor) | |
2274 saved_cursor = oap->cursor_start; | |
2275 | |
1563 | 2276 format_lines(oap->line_count, keep_cursor); |
7 | 2277 |
2278 /* | |
2279 * Leave the cursor at the first non-blank of the last formatted line. | |
2280 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
2281 * line, so "." will do the next lines. | |
2282 */ | |
2283 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2284 ++curwin->w_cursor.lnum; | |
2285 beginline(BL_WHITE | BL_FIX); | |
2286 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
2287 msgmore(old_line_count); | |
2288 | |
2289 /* put '] mark on the end of the formatted area */ | |
2290 curbuf->b_op_end = curwin->w_cursor; | |
2291 | |
2292 if (keep_cursor) | |
2293 { | |
2294 curwin->w_cursor = saved_cursor; | |
2295 saved_cursor.lnum = 0; | |
2296 } | |
2297 | |
2298 if (oap->is_VIsual) | |
2299 { | |
2300 win_T *wp; | |
2301 | |
2302 FOR_ALL_WINDOWS(wp) | |
2303 { | |
2304 if (wp->w_old_cursor_lnum != 0) | |
2305 { | |
2306 /* When lines have been inserted or deleted, adjust the end of | |
2307 * the Visual area to be redrawn. */ | |
2308 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
2309 wp->w_old_cursor_lnum += old_line_count; | |
2310 else | |
2311 wp->w_old_visual_lnum += old_line_count; | |
2312 } | |
2313 } | |
2314 } | |
2315 } | |
2316 | |
667 | 2317 #if defined(FEAT_EVAL) || defined(PROTO) |
2318 /* | |
2319 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
2320 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
2321 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2322 op_formatexpr(oparg_T *oap) |
667 | 2323 { |
2324 if (oap->is_VIsual) | |
2325 /* When there is no change: need to remove the Visual selection */ | |
2326 redraw_curbuf_later(INVERTED); | |
2327 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2328 if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2329 /* As documented: when 'formatexpr' returns non-zero fall back to |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2330 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
2331 op_format(oap, FALSE); |
667 | 2332 } |
2333 | |
2334 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2335 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2336 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2337 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2338 int c) /* character to be inserted */ |
667 | 2339 { |
681 | 2340 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
2341 OPT_LOCAL); | |
667 | 2342 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2343 char_u *fex; |
667 | 2344 |
2345 /* | |
2346 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 2347 * Set v:char to the character to be inserted (can be NUL). |
667 | 2348 */ |
2349 set_vim_var_nr(VV_LNUM, lnum); | |
2350 set_vim_var_nr(VV_COUNT, count); | |
1969 | 2351 set_vim_var_char(c); |
844 | 2352 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2353 /* Make a copy, the option could be changed while calling it. */ |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2354 fex = vim_strsave(curbuf->b_p_fex); |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2355 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2356 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2357 |
667 | 2358 /* |
2359 * Evaluate the function. | |
2360 */ | |
2361 if (use_sandbox) | |
2362 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2363 r = (int)eval_to_number(fex); |
667 | 2364 if (use_sandbox) |
2365 --sandbox; | |
844 | 2366 |
2367 set_vim_var_string(VV_CHAR, NULL, -1); | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2368 vim_free(fex); |
844 | 2369 |
667 | 2370 return r; |
2371 } | |
2372 #endif | |
2373 | |
7 | 2374 /* |
2375 * Format "line_count" lines, starting at the cursor position. | |
2376 * When "line_count" is negative, format until the end of the paragraph. | |
2377 * Lines after the cursor line are saved for undo, caller must have saved the | |
2378 * first line. | |
2379 */ | |
2380 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2381 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2382 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2383 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 2384 { |
2385 int max_len; | |
2386 int is_not_par; /* current line not part of parag. */ | |
2387 int next_is_not_par; /* next line not part of paragraph */ | |
2388 int is_end_par; /* at end of paragraph */ | |
2389 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
2390 int next_is_start_par = FALSE; | |
2391 int leader_len = 0; /* leader len of current line */ | |
2392 int next_leader_len; /* leader len of next line */ | |
2393 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
2394 char_u *next_leader_flags; /* flags for leader of next line */ | |
2395 int do_comments; /* format comments */ | |
3584 | 2396 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 2397 int advance = TRUE; |
3584 | 2398 int second_indent = -1; /* indent for second line (comment |
2399 * aware) */ | |
7 | 2400 int do_second_indent; |
2401 int do_number_indent; | |
2402 int do_trail_white; | |
2403 int first_par_line = TRUE; | |
2404 int smd_save; | |
2405 long count; | |
2406 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
2407 int force_format = FALSE; | |
2408 int old_State = State; | |
2409 | |
2410 /* length of a line to force formatting: 3 * 'tw' */ | |
2411 max_len = comp_textwidth(TRUE) * 3; | |
2412 | |
2413 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
2414 do_comments = has_format_option(FO_Q_COMS); | |
2415 do_second_indent = has_format_option(FO_Q_SECOND); | |
2416 do_number_indent = has_format_option(FO_Q_NUMBER); | |
2417 do_trail_white = has_format_option(FO_WHITE_PAR); | |
2418 | |
2419 /* | |
2420 * Get info about the previous and current line. | |
2421 */ | |
2422 if (curwin->w_cursor.lnum > 1) | |
2423 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2424 , &leader_len, &leader_flags, do_comments); |
7 | 2425 else |
2426 is_not_par = TRUE; | |
2427 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2428 , &next_leader_len, &next_leader_flags, do_comments); |
7 | 2429 is_end_par = (is_not_par || next_is_not_par); |
2430 if (!is_end_par && do_trail_white) | |
2431 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
2432 | |
2433 curwin->w_cursor.lnum--; | |
2434 for (count = line_count; count != 0 && !got_int; --count) | |
2435 { | |
2436 /* | |
2437 * Advance to next paragraph. | |
2438 */ | |
2439 if (advance) | |
2440 { | |
2441 curwin->w_cursor.lnum++; | |
2442 prev_is_end_par = is_end_par; | |
2443 is_not_par = next_is_not_par; | |
2444 leader_len = next_leader_len; | |
2445 leader_flags = next_leader_flags; | |
2446 } | |
2447 | |
2448 /* | |
2449 * The last line to be formatted. | |
2450 */ | |
2451 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
2452 { | |
2453 next_is_not_par = TRUE; | |
2454 next_leader_len = 0; | |
2455 next_leader_flags = NULL; | |
2456 } | |
2457 else | |
2458 { | |
2459 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2460 , &next_leader_len, &next_leader_flags, do_comments); |
7 | 2461 if (do_number_indent) |
2462 next_is_start_par = | |
2463 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
2464 } | |
2465 advance = TRUE; | |
2466 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
2467 if (!is_end_par && do_trail_white) | |
2468 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
2469 | |
2470 /* | |
2471 * Skip lines that are not in a paragraph. | |
2472 */ | |
2473 if (is_not_par) | |
2474 { | |
2475 if (line_count < 0) | |
2476 break; | |
2477 } | |
2478 else | |
2479 { | |
2480 /* | |
2481 * For the first line of a paragraph, check indent of second line. | |
2482 * Don't do this for comments and empty lines. | |
2483 */ | |
2484 if (first_par_line | |
2485 && (do_second_indent || do_number_indent) | |
2486 && prev_is_end_par | |
3584 | 2487 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
2488 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2489 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 2490 { |
2491 if (leader_len == 0 && next_leader_len == 0) | |
2492 { | |
2493 /* no comment found */ | |
2494 second_indent = | |
2495 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
2496 } | |
2497 else | |
2498 { | |
2499 second_indent = next_leader_len; | |
2500 do_comments_list = 1; | |
2501 } | |
2502 } | |
7 | 2503 else if (do_number_indent) |
3584 | 2504 { |
2505 if (leader_len == 0 && next_leader_len == 0) | |
2506 { | |
2507 /* no comment found */ | |
2508 second_indent = | |
2509 get_number_indent(curwin->w_cursor.lnum); | |
2510 } | |
2511 else | |
2512 { | |
2513 /* get_number_indent() is now "comment aware"... */ | |
2514 second_indent = | |
2515 get_number_indent(curwin->w_cursor.lnum); | |
2516 do_comments_list = 1; | |
2517 } | |
2518 } | |
7 | 2519 } |
2520 | |
2521 /* | |
2522 * When the comment leader changes, it's the end of the paragraph. | |
2523 */ | |
2524 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
2525 || !same_leader(curwin->w_cursor.lnum, | |
2526 leader_len, leader_flags, | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2527 next_leader_len, next_leader_flags)) |
7 | 2528 is_end_par = TRUE; |
2529 | |
2530 /* | |
2531 * If we have got to the end of a paragraph, or the line is | |
2532 * getting long, format it. | |
2533 */ | |
2534 if (is_end_par || force_format) | |
2535 { | |
2536 if (need_set_indent) | |
2537 /* replace indent in first line with minimal number of | |
2538 * tabs and spaces, according to current options */ | |
2539 (void)set_indent(get_indent(), SIN_CHANGED); | |
2540 | |
2541 /* put cursor on last non-space */ | |
2542 State = NORMAL; /* don't go past end-of-line */ | |
2543 coladvance((colnr_T)MAXCOL); | |
2544 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
2545 dec_cursor(); | |
2546 | |
2547 /* do the formatting, without 'showmode' */ | |
2548 State = INSERT; /* for open_line() */ | |
2549 smd_save = p_smd; | |
2550 p_smd = FALSE; | |
2551 insertchar(NUL, INSCHAR_FORMAT | |
2552 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 2553 + (do_comments && do_comments_list |
2554 ? INSCHAR_COM_LIST : 0) | |
1563 | 2555 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 2556 State = old_State; |
2557 p_smd = smd_save; | |
2558 second_indent = -1; | |
2559 /* at end of par.: need to set indent of next par. */ | |
2560 need_set_indent = is_end_par; | |
2561 if (is_end_par) | |
2562 { | |
2563 /* When called with a negative line count, break at the | |
2564 * end of the paragraph. */ | |
2565 if (line_count < 0) | |
2566 break; | |
2567 first_par_line = TRUE; | |
2568 } | |
2569 force_format = FALSE; | |
2570 } | |
2571 | |
2572 /* | |
2573 * When still in same paragraph, join the lines together. But | |
5403 | 2574 * first delete the leader from the second line. |
7 | 2575 */ |
2576 if (!is_end_par) | |
2577 { | |
2578 advance = FALSE; | |
2579 curwin->w_cursor.lnum++; | |
2580 curwin->w_cursor.col = 0; | |
2581 if (line_count < 0 && u_save_cursor() == FAIL) | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2582 break; |
7 | 2583 if (next_leader_len > 0) |
5403 | 2584 { |
2585 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 2586 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2587 (long)-next_leader_len, 0); |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2588 } |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2589 else if (second_indent > 0) // the "leader" for FO_Q_SECOND |
5403 | 2590 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2591 int indent = getwhitecols_curline(); |
5403 | 2592 |
2593 if (indent > 0) | |
2594 { | |
2595 (void)del_bytes(indent, FALSE, FALSE); | |
2596 mark_col_adjust(curwin->w_cursor.lnum, | |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2597 (colnr_T)0, 0L, (long)-indent, 0); |
5415 | 2598 } |
5403 | 2599 } |
7 | 2600 curwin->w_cursor.lnum--; |
5848 | 2601 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 2602 { |
2603 beep_flush(); | |
2604 break; | |
2605 } | |
2606 first_par_line = FALSE; | |
2607 /* If the line is getting long, format it next time */ | |
2608 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
2609 force_format = TRUE; | |
2610 else | |
2611 force_format = FALSE; | |
2612 } | |
2613 } | |
2614 line_breakcheck(); | |
2615 } | |
2616 } | |
2617 | |
2618 /* | |
2619 * Return TRUE if line "lnum" ends in a white character. | |
2620 */ | |
2621 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2622 ends_in_white(linenr_T lnum) |
7 | 2623 { |
2624 char_u *s = ml_get(lnum); | |
2625 size_t l; | |
2626 | |
2627 if (*s == NUL) | |
2628 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2629 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 2630 * invocation may call function multiple times". */ |
2631 l = STRLEN(s) - 1; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2632 return VIM_ISWHITE(s[l]); |
7 | 2633 } |
2634 | |
2635 /* | |
2636 * Blank lines, and lines containing only the comment leader, are left | |
2637 * untouched by the formatting. The function returns TRUE in this | |
2638 * case. It also returns TRUE when a line starts with the end of a comment | |
2639 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
2640 * previous line. A new paragraph starts after a blank line, or when the | |
2641 * comment leader changes -- webb. | |
2642 */ | |
2643 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2644 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2645 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2646 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2647 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2648 int do_comments) |
7 | 2649 { |
2650 char_u *flags = NULL; /* init for GCC */ | |
2651 char_u *ptr; | |
2652 | |
2653 ptr = ml_get(lnum); | |
2654 if (do_comments) | |
3562 | 2655 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 2656 else |
2657 *leader_len = 0; | |
2658 | |
2659 if (*leader_len > 0) | |
2660 { | |
2661 /* | |
2662 * Search for 'e' flag in comment leader flags. | |
2663 */ | |
2664 flags = *leader_flags; | |
2665 while (*flags && *flags != ':' && *flags != COM_END) | |
2666 ++flags; | |
2667 } | |
2668 | |
2669 return (*skipwhite(ptr + *leader_len) == NUL | |
2670 || (*leader_len > 0 && *flags == COM_END) | |
2671 || startPS(lnum, NUL, FALSE)); | |
2672 } | |
2673 | |
2674 /* | |
2675 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
2676 * previous line is in the same paragraph. Used for auto-formatting. | |
2677 */ | |
2678 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2679 paragraph_start(linenr_T lnum) |
7 | 2680 { |
2681 char_u *p; | |
2682 int leader_len = 0; /* leader len of current line */ | |
2683 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
2684 int next_leader_len; /* leader len of next line */ | |
2685 char_u *next_leader_flags; /* flags for leader of next line */ | |
2686 int do_comments; /* format comments */ | |
2687 | |
2688 if (lnum <= 1) | |
2689 return TRUE; /* start of the file */ | |
2690 | |
2691 p = ml_get(lnum - 1); | |
2692 if (*p == NUL) | |
2693 return TRUE; /* after empty line */ | |
2694 | |
2695 do_comments = has_format_option(FO_Q_COMS); | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2696 if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments)) |
7 | 2697 return TRUE; /* after non-paragraph line */ |
2698 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
2699 if (fmt_check_par(lnum, &next_leader_len, &next_leader_flags, do_comments)) |
7 | 2700 return TRUE; /* "lnum" is not a paragraph line */ |
2701 | |
2702 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
2703 return TRUE; /* missing trailing space in previous line. */ | |
2704 | |
2705 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
2706 return TRUE; /* numbered item starts in "lnum". */ | |
2707 | |
2708 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
2709 next_leader_len, next_leader_flags)) | |
2710 return TRUE; /* change of comment leader. */ | |
2711 | |
2712 return FALSE; | |
2713 } | |
2714 | |
2715 /* | |
2716 * prepare a few things for block mode yank/delete/tilde | |
2717 * | |
2718 * for delete: | |
2719 * - textlen includes the first/last char to be (partly) deleted | |
2720 * - start/endspaces is the number of columns that are taken by the | |
2721 * first/last deleted char minus the number of columns that have to be | |
1839 | 2722 * deleted. |
2723 * for yank and tilde: | |
7 | 2724 * - textlen includes the first/last char to be wholly yanked |
2725 * - start/endspaces is the number of columns of the first/last yanked char | |
2726 * that are to be yanked. | |
2727 */ | |
18164
f57481564f2c
patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18100
diff
changeset
|
2728 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2729 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2730 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2731 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2732 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2733 int is_del) |
7 | 2734 { |
2735 int incr = 0; | |
2736 char_u *pend; | |
2737 char_u *pstart; | |
2738 char_u *line; | |
2739 char_u *prev_pstart; | |
2740 char_u *prev_pend; | |
2741 | |
2742 bdp->startspaces = 0; | |
2743 bdp->endspaces = 0; | |
2744 bdp->textlen = 0; | |
2745 bdp->start_vcol = 0; | |
2746 bdp->end_vcol = 0; | |
2747 bdp->is_short = FALSE; | |
2748 bdp->is_oneChar = FALSE; | |
2749 bdp->pre_whitesp = 0; | |
2750 bdp->pre_whitesp_c = 0; | |
2751 bdp->end_char_vcols = 0; | |
2752 bdp->start_char_vcols = 0; | |
2753 | |
2754 line = ml_get(lnum); | |
2755 pstart = line; | |
2756 prev_pstart = line; | |
2757 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
2758 { | |
2759 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 2760 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 2761 bdp->start_vcol += incr; |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
2762 if (VIM_ISWHITE(*pstart)) |
7 | 2763 { |
2764 bdp->pre_whitesp += incr; | |
2765 bdp->pre_whitesp_c++; | |
2766 } | |
2767 else | |
2768 { | |
2769 bdp->pre_whitesp = 0; | |
2770 bdp->pre_whitesp_c = 0; | |
2771 } | |
2772 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2773 MB_PTR_ADV(pstart); |
7 | 2774 } |
2775 bdp->start_char_vcols = incr; | |
2776 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
2777 { | |
2778 bdp->end_vcol = bdp->start_vcol; | |
2779 bdp->is_short = TRUE; | |
2780 if (!is_del || oap->op_type == OP_APPEND) | |
2781 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
2782 } | |
2783 else | |
2784 { | |
2785 /* notice: this converts partly selected Multibyte characters to | |
2786 * spaces, too. */ | |
2787 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
2788 if (is_del && bdp->startspaces) | |
2789 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
2790 pend = pstart; | |
2791 bdp->end_vcol = bdp->start_vcol; | |
2792 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
2793 { | |
2794 bdp->is_oneChar = TRUE; | |
2795 if (oap->op_type == OP_INSERT) | |
2796 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
2797 else if (oap->op_type == OP_APPEND) | |
2798 { | |
2799 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
2800 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
2801 } | |
2802 else | |
2803 { | |
2804 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
2805 if (is_del && oap->op_type != OP_LSHIFT) | |
2806 { | |
2807 /* just putting the sum of those two into | |
2808 * bdp->startspaces doesn't work for Visual replace, | |
2809 * so we have to split the tab in two */ | |
2810 bdp->startspaces = bdp->start_char_vcols | |
2811 - (bdp->start_vcol - oap->start_vcol); | |
2812 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
2813 } | |
2814 } | |
2815 } | |
2816 else | |
2817 { | |
2818 prev_pend = pend; | |
2819 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
2820 { | |
2821 /* Count a tab for what it's worth (if list mode not on) */ | |
2822 prev_pend = pend; | |
6535 | 2823 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 2824 bdp->end_vcol += incr; |
2825 } | |
2826 if (bdp->end_vcol <= oap->end_vcol | |
2827 && (!is_del | |
2828 || oap->op_type == OP_APPEND | |
2829 || oap->op_type == OP_REPLACE)) /* line too short */ | |
2830 { | |
2831 bdp->is_short = TRUE; | |
2832 /* Alternative: include spaces to fill up the block. | |
2833 * Disadvantage: can lead to trailing spaces when the line is | |
2834 * short where the text is put */ | |
2835 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
2836 if (oap->op_type == OP_APPEND || virtual_op) | |
2837 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 2838 + oap->inclusive; |
7 | 2839 else |
2840 bdp->endspaces = 0; /* replace doesn't add characters */ | |
2841 } | |
2842 else if (bdp->end_vcol > oap->end_vcol) | |
2843 { | |
2844 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
2845 if (!is_del && bdp->endspaces) | |
2846 { | |
2847 bdp->endspaces = incr - bdp->endspaces; | |
2848 if (pend != pstart) | |
2849 pend = prev_pend; | |
2850 } | |
2851 } | |
2852 } | |
2853 bdp->end_char_vcols = incr; | |
2854 if (is_del && bdp->startspaces) | |
2855 pstart = prev_pstart; | |
2856 bdp->textlen = (int)(pend - pstart); | |
2857 } | |
2858 bdp->textcol = (colnr_T) (pstart - line); | |
2859 bdp->textstart = pstart; | |
2860 } | |
2861 | |
2862 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2863 * Handle the add/subtract operator. |
7 | 2864 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2865 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2866 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2867 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2868 linenr_T Prenum1, /* Amount of add/subtract */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2869 int g_cmd) /* was g<c-a>/g<c-x> */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2870 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2871 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2872 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2873 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2874 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2875 |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2876 // do_addsub() might trigger re-evaluation of 'foldexpr' halfway, when the |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
2877 // buffer is not completely updated yet. Postpone updating folds until before |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2878 // the call to changed_lines(). |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2879 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2880 disable_fold_update++; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2881 #endif |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2882 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2883 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2884 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2885 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2886 if (u_save_cursor() == FAIL) |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2887 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2888 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2889 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2890 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2891 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2892 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2893 change_cnt = do_addsub(oap->op_type, &pos, 0, amount); |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2894 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2895 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2896 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2897 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2898 changed_lines(pos.lnum, 0, pos.lnum + 1, 0L); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2899 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2900 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2901 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2902 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2903 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2904 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2905 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2906 if (u_save((linenr_T)(oap->start.lnum - 1), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2907 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2908 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2909 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2910 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2911 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2912 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2913 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2914 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2915 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2916 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2917 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2918 if (oap->block_mode) /* Visual block mode */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2919 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2920 block_prep(oap, &bd, pos.lnum, FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2921 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2922 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2923 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2924 else if (oap->motion_type == MLINE) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2925 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2926 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2927 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2928 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2929 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2930 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2931 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
2932 if (pos.lnum == oap->start.lnum && !oap->inclusive) |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2933 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2934 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2935 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2936 if (pos.lnum == oap->start.lnum) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2937 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2938 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2939 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2940 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2941 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2942 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2943 length = (int)STRLEN(ml_get(oap->end.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2944 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2945 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2946 length = oap->end.col - pos.col + 1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2947 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2948 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2949 one_change = do_addsub(oap->op_type, &pos, length, amount); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2950 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2951 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2952 /* Remember the start position of the first change. */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2953 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2954 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2955 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2956 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2957 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2958 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2959 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2960 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2961 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2962 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2963 netbeans_removed(curbuf, pos.lnum, pos.col, (long)length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2964 netbeans_inserted(curbuf, pos.lnum, pos.col, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2965 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2966 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2967 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2968 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2969 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2970 } |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2971 |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2972 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2973 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2974 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2975 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2976 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2977 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2978 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2979 /* No change: need to remove the Visual selection */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2980 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2981 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2982 /* Set '[ mark if something changed. Keep the last end |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2983 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2984 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2985 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2986 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2987 if (change_cnt > p_report) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
2988 smsg(NGETTEXT("%ld line changed", "%ld lines changed", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2989 change_cnt), change_cnt); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2990 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2991 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2992 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2993 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2994 * Add or subtract 'Prenum1' from a number in a line |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2995 * op_type is OP_NR_ADD or OP_NR_SUB |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2996 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2997 * Returns TRUE if some character was changed. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2998 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2999 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3000 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3001 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3002 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3003 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3004 linenr_T Prenum1) |
7 | 3005 { |
3006 int col; | |
3007 char_u *buf1; | |
3008 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3009 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 3010 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3011 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3012 uvarnumber_T oldn; |
7 | 3013 char_u *ptr; |
3014 int c; | |
3015 int todel; | |
3016 int dohex; | |
3017 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3018 int dobin; |
7 | 3019 int doalp; |
3020 int firstdigit; | |
3021 int subtract; | |
6868 | 3022 int negative = FALSE; |
6891 | 3023 int was_positive = TRUE; |
6868 | 3024 int visual = VIsual_active; |
6921 | 3025 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
3026 pos_T save_cursor = curwin->w_cursor; |
6927 | 3027 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3028 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3029 pos_T endpos; |
7 | 3030 |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
3031 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
3032 dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
3033 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin" |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
3034 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha" |
7 | 3035 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3036 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3037 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3038 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3039 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3040 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3041 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3042 |
7 | 3043 /* |
3044 * First check if we are on a hexadecimal number, after the "0x". | |
3045 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3046 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3047 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3048 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3049 while (col > 0 && vim_isbdigit(ptr[col])) |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3050 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3051 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3052 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3053 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3054 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3055 |
6868 | 3056 if (dohex) |
3057 while (col > 0 && vim_isxdigit(ptr[col])) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3058 { |
6868 | 3059 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3060 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3061 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3062 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3063 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3064 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3065 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3066 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3067 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3068 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3069 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3070 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3071 !(*mb_head_off)(ptr, ptr + col - 1)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3072 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3073 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3074 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3075 /* In case of binary/hexadecimal pattern overlap match, rescan */ |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3076 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3077 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3078 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3079 while (col > 0 && vim_isdigit(ptr[col])) |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3080 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3081 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3082 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3083 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3084 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3085 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3086 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3087 if (( dohex |
6868 | 3088 && col > 0 |
3089 && (ptr[col] == 'X' | |
3090 || ptr[col] == 'x') | |
3091 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3092 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3093 !(*mb_head_off)(ptr, ptr + col - 1)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3094 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3095 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3096 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3097 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3098 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3099 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3100 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3101 !(*mb_head_off)(ptr, ptr + col - 1)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3102 && vim_isbdigit(ptr[col + 1]))) |
6868 | 3103 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
3104 /* Found hexadecimal or binary number, move to its start. */ |
7 | 3105 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3106 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3107 col -= (*mb_head_off)(ptr, ptr + col); |
6868 | 3108 } |
3109 else | |
7 | 3110 { |
6868 | 3111 /* |
3112 * Search forward and then backward to find the start of number. | |
3113 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3114 col = pos->col; |
6868 | 3115 |
3116 while (ptr[col] != NUL | |
3117 && !vim_isdigit(ptr[col]) | |
3118 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
3119 col += mb_ptr2len(ptr + col); |
6868 | 3120 |
3121 while (col > 0 | |
3122 && vim_isdigit(ptr[col - 1]) | |
3123 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3124 { |
6868 | 3125 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3126 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3127 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3128 } |
6868 | 3129 } |
3130 } | |
3131 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3132 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3133 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3134 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3135 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3136 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3137 { |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
3138 int mb_len = mb_ptr2len(ptr + col); |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3139 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3140 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3141 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3142 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3143 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3144 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3145 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3146 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3147 if (col > pos->col && ptr[col - 1] == '-' |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3148 && (!has_mbyte || !(*mb_head_off)(ptr, ptr + col - 1))) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3149 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3150 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3151 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3152 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3153 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3154 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3155 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3156 * If a number was found, and saving for undo works, replace the number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3157 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3158 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3159 if (!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3160 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3161 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3162 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3163 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3164 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3165 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3166 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3167 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3168 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3169 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3170 if (CharOrd(firstdigit) < Prenum1) |
6927 | 3171 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3172 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3173 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3174 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3175 firstdigit = 'a'; |
6927 | 3176 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3177 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3178 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3179 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3180 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3181 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3182 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3183 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3184 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3185 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3186 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 3187 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3188 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3189 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3190 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3191 firstdigit = 'z'; |
6927 | 3192 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3193 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3194 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3195 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3196 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3197 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3198 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3199 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3200 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3201 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3202 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3203 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3204 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3205 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3206 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3207 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3208 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3209 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3210 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3211 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3212 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3213 !(*mb_head_off)(ptr, ptr + col - 1)) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
3214 && !visual) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3215 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3216 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3217 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3218 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3219 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3220 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3221 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3222 maxlen = (curbuf->b_visual.vi_curswant == MAXCOL |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3223 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3224 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3225 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3226 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3227 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3228 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3229 + (dohex ? STR2NR_HEX : 0), |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
3230 NULL, &n, maxlen, FALSE); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3231 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3232 /* ignore leading '-' for hex and octal and bin numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3233 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3234 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3235 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3236 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3237 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3238 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3239 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3240 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3241 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3242 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3243 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3244 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3245 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3246 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3247 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3248 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3249 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3250 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3251 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3252 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3253 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3254 if (subtract) |
6927 | 3255 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3256 if (n > oldn) |
6868 | 3257 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3258 n = 1 + (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3259 negative ^= TRUE; |
6868 | 3260 } |
7 | 3261 } |
3262 else | |
6868 | 3263 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3264 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3265 if (n < oldn) |
6868 | 3266 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3267 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3268 negative ^= TRUE; |
6868 | 3269 } |
6927 | 3270 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3271 if (n == 0) |
6868 | 3272 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3273 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3274 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3275 if (visual && !was_positive && !negative && col > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3276 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3277 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3278 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3279 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3280 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3281 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3282 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3283 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3284 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3285 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3286 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3287 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3288 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3289 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3290 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3291 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3292 * Don't include the '-' in the length, only the length of the |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3293 * part after it is kept the same. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3294 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3295 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3296 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3297 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3298 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3299 if (c < 0x100 && isalpha(c)) |
6868 | 3300 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3301 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3302 hexupper = TRUE; |
6868 | 3303 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3304 hexupper = FALSE; |
6891 | 3305 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3306 /* del_char() will mark line needing displaying */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3307 (void)del_char(FALSE); |
6868 | 3308 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3309 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3310 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3311 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3312 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3313 * When there are many leading zeros it could be very long. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3314 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3315 */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
3316 buf1 = alloc(length + NUMBUFLEN); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3317 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3318 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3319 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
3320 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3321 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3322 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3323 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3324 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3325 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3326 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3327 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3328 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3329 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3330 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3331 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3332 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3333 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3334 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3335 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3336 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3337 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3338 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3339 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3340 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3341 int bits = sizeof(uvarnumber_T) * 8; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3342 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3343 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3344 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3345 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3346 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3347 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3348 buf2[i++] = ((n >> (bit - 1)) & 0x1) ? '1' : '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3349 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3350 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3351 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3352 else if (pre == 0) |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
3353 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3354 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3355 else if (pre == '0') |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
3356 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3357 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3358 else if (pre && hexupper) |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
3359 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3360 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3361 else |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
3362 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3363 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3364 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3365 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3366 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3367 * Adjust number of zeros to the new number of digits, so the |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3368 * total length of the number remains the same. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3369 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3370 * the result may look like an octal number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3371 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3372 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3373 while (length-- > 0) |
6868 | 3374 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3375 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3376 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3377 ins_str(buf1); /* insert the new number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3378 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3379 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3380 if (did_change && curwin->w_cursor.col) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3381 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3382 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3383 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3384 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3385 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3386 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3387 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3388 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3389 if (curbuf->b_op_end.col > 0) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3390 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
3391 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3392 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
3393 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
3394 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
3395 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
3396 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
3397 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
3398 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
3399 return did_change; |
7 | 3400 } |
3401 | |
3402 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
3403 /* | |
3404 * SELECTION / PRIMARY ('*') | |
3405 * | |
3406 * Text selection stuff that uses the GUI selection register '*'. When using a | |
3407 * GUI this may be text from another window, otherwise it is the last text we | |
3408 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
3409 * button performs the paste, otherwise you will need to do <"*p>. " | |
3410 * If not under X, it is synonymous with the clipboard register '+'. | |
3411 * | |
3412 * X CLIPBOARD ('+') | |
3413 * | |
3414 * Text selection stuff that uses the GUI clipboard register '+'. | |
3415 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
3416 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
3417 * otherwise you will need to do <"+p>. " | |
3418 * If not under X, it is synonymous with the selection register '*'. | |
3419 */ | |
3420 | |
3421 /* | |
3422 * Routine to export any final X selection we had to the environment | |
11065
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3423 * so that the text is still available after Vim has exited. X selections |
7 | 3424 * only exist while the owning application exists, so we write to the |
3425 * permanent (while X runs) store CUT_BUFFER0. | |
3426 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
3427 * 'permanent' of the two), otherwise the PRIMARY one. | |
3428 * For now, use a hard-coded sanity limit of 1Mb of data. | |
3429 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
3430 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 3431 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3432 x11_export_final_selection(void) |
7 | 3433 { |
3434 Display *dpy; | |
3435 char_u *str = NULL; | |
3436 long_u len = 0; | |
3437 int motion_type = -1; | |
3438 | |
3439 # ifdef FEAT_GUI | |
3440 if (gui.in_use) | |
3441 dpy = X_DISPLAY; | |
3442 else | |
3443 # endif | |
3444 # ifdef FEAT_XCLIPBOARD | |
3445 dpy = xterm_dpy; | |
3446 # else | |
3447 return; | |
3448 # endif | |
3449 | |
3450 /* Get selection to export */ | |
3451 if (clip_plus.owned) | |
3452 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
3453 else if (clip_star.owned) | |
3454 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
3455 | |
3456 /* Check it's OK */ | |
3457 if (dpy != NULL && str != NULL && motion_type >= 0 | |
3458 && len < 1024*1024 && len > 0) | |
3459 { | |
4201 | 3460 int ok = TRUE; |
3461 | |
1924 | 3462 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
3463 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
3464 * encoding conversion usually doesn't work, so keep the text as-is. | |
3465 */ | |
3466 if (has_mbyte) | |
3467 { | |
3468 vimconv_T vc; | |
3469 | |
3470 vc.vc_type = CONV_NONE; | |
3471 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
3472 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
3473 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
3474 char_u *conv_str; |
2007 | 3475 |
4201 | 3476 vc.vc_fail = TRUE; |
2007 | 3477 conv_str = string_convert(&vc, str, &intlen); |
3478 len = intlen; | |
1924 | 3479 if (conv_str != NULL) |
3480 { | |
3481 vim_free(str); | |
3482 str = conv_str; | |
3483 } | |
4201 | 3484 else |
3485 { | |
3486 ok = FALSE; | |
3487 } | |
1924 | 3488 convert_setup(&vc, NULL, NULL); |
3489 } | |
4201 | 3490 else |
3491 { | |
3492 ok = FALSE; | |
3493 } | |
1924 | 3494 } |
4201 | 3495 |
3496 /* Do not store the string if conversion failed. Better to use any | |
3497 * other selection than garbled text. */ | |
3498 if (ok) | |
3499 { | |
3500 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
3501 XFlush(dpy); | |
3502 } | |
7 | 3503 } |
3504 | |
3505 vim_free(str); | |
3506 } | |
3507 #endif | |
3508 #endif /* FEAT_CLIPBOARD || PROTO */ | |
3509 | |
3510 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3511 clear_oparg(oparg_T *oap) |
7 | 3512 { |
3513 vim_memset(oap, 0, sizeof(oparg_T)); | |
3514 } | |
3515 | |
3516 /* | |
161 | 3517 * Count the number of bytes, characters and "words" in a line. |
7 | 3518 * |
3519 * "Words" are counted by looking for boundaries between non-space and | |
3520 * space characters. (it seems to produce results that match 'wc'.) | |
3521 * | |
161 | 3522 * Return value is byte count; word count for the line is added to "*wc". |
3523 * Char count is added to "*cc". | |
7 | 3524 * |
3525 * The function will only examine the first "limit" characters in the | |
3526 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
3527 * case, eol_size will be added to the character count to account for | |
3528 * the size of the EOL character. | |
3529 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3530 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3531 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3532 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3533 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3534 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3535 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3536 int eol_size) |
7 | 3537 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3538 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3539 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3540 varnumber_T chars = 0; |
7 | 3541 int is_word = 0; |
3542 | |
3626 | 3543 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 3544 { |
3545 if (is_word) | |
3546 { | |
3547 if (vim_isspace(line[i])) | |
3548 { | |
3549 words++; | |
3550 is_word = 0; | |
3551 } | |
3552 } | |
3553 else if (!vim_isspace(line[i])) | |
3554 is_word = 1; | |
161 | 3555 ++chars; |
474 | 3556 i += (*mb_ptr2len)(line + i); |
7 | 3557 } |
3558 | |
3559 if (is_word) | |
3560 words++; | |
3561 *wc += words; | |
3562 | |
3563 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 3564 if (i < limit && line[i] == NUL) |
161 | 3565 { |
7 | 3566 i += eol_size; |
161 | 3567 chars += eol_size; |
3568 } | |
3569 *cc += chars; | |
7 | 3570 return i; |
3571 } | |
3572 | |
3573 /* | |
3574 * Give some info about the position of the cursor (for "g CTRL-G"). | |
3575 * In Visual mode, give some info about the selected region. (In this case, | |
3576 * the *_count_cursor variables store running totals for the selection.) | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3577 * When "dict" is not NULL store the info there instead of showing it. |
7 | 3578 */ |
3579 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3580 cursor_pos_info(dict_T *dict) |
7 | 3581 { |
3582 char_u *p; | |
274 | 3583 char_u buf1[50]; |
3584 char_u buf2[40]; | |
7 | 3585 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3586 varnumber_T byte_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3587 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3588 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3589 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3590 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3591 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3592 varnumber_T word_count_cursor = 0; |
7 | 3593 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3594 varnumber_T last_check = 100000L; |
7 | 3595 long line_count_selected = 0; |
3596 pos_T min_pos, max_pos; | |
3597 oparg_T oparg; | |
3598 struct block_def bd; | |
3599 | |
3600 /* | |
3601 * Compute the length of the file in characters. | |
3602 */ | |
3603 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
3604 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3605 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3606 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3607 msg(_(no_lines_msg)); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3608 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3609 } |
7 | 3610 } |
3611 else | |
3612 { | |
3613 if (get_fileformat(curbuf) == EOL_DOS) | |
3614 eol_size = 2; | |
3615 else | |
3616 eol_size = 1; | |
3617 | |
3618 if (VIsual_active) | |
3619 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
3620 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 3621 { |
3622 min_pos = VIsual; | |
3623 max_pos = curwin->w_cursor; | |
3624 } | |
3625 else | |
3626 { | |
3627 min_pos = curwin->w_cursor; | |
3628 max_pos = VIsual; | |
3629 } | |
3630 if (*p_sel == 'e' && max_pos.col > 0) | |
3631 --max_pos.col; | |
3632 | |
3633 if (VIsual_mode == Ctrl_V) | |
3634 { | |
1866 | 3635 #ifdef FEAT_LINEBREAK |
3636 char_u * saved_sbr = p_sbr; | |
3637 | |
3638 /* Make 'sbr' empty for a moment to get the correct size. */ | |
3639 p_sbr = empty_option; | |
3640 #endif | |
7 | 3641 oparg.is_VIsual = 1; |
3642 oparg.block_mode = TRUE; | |
3643 oparg.op_type = OP_NOP; | |
3644 getvcols(curwin, &min_pos, &max_pos, | |
688 | 3645 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 3646 #ifdef FEAT_LINEBREAK |
3647 p_sbr = saved_sbr; | |
3648 #endif | |
688 | 3649 if (curwin->w_curswant == MAXCOL) |
3650 oparg.end_vcol = MAXCOL; | |
7 | 3651 /* Swap the start, end vcol if needed */ |
3652 if (oparg.end_vcol < oparg.start_vcol) | |
3653 { | |
3654 oparg.end_vcol += oparg.start_vcol; | |
3655 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
3656 oparg.end_vcol -= oparg.start_vcol; | |
3657 } | |
3658 } | |
3659 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
3660 } | |
3661 | |
3662 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
3663 { | |
3664 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 3665 if (byte_count > last_check) |
7 | 3666 { |
3667 ui_breakcheck(); | |
3668 if (got_int) | |
3669 return; | |
161 | 3670 last_check = byte_count + 100000L; |
7 | 3671 } |
3672 | |
3673 /* Do extra processing for VIsual mode. */ | |
3674 if (VIsual_active | |
3675 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
3676 { | |
45 | 3677 char_u *s = NULL; |
3678 long len = 0L; | |
3679 | |
7 | 3680 switch (VIsual_mode) |
3681 { | |
3682 case Ctrl_V: | |
3683 virtual_op = virtual_active(); | |
3684 block_prep(&oparg, &bd, lnum, 0); | |
3685 virtual_op = MAYBE; | |
45 | 3686 s = bd.textstart; |
3687 len = (long)bd.textlen; | |
7 | 3688 break; |
3689 case 'V': | |
45 | 3690 s = ml_get(lnum); |
3691 len = MAXCOL; | |
7 | 3692 break; |
3693 case 'v': | |
3694 { | |
3695 colnr_T start_col = (lnum == min_pos.lnum) | |
3696 ? min_pos.col : 0; | |
3697 colnr_T end_col = (lnum == max_pos.lnum) | |
3698 ? max_pos.col - start_col + 1 : MAXCOL; | |
3699 | |
45 | 3700 s = ml_get(lnum) + start_col; |
3701 len = end_col; | |
7 | 3702 } |
3703 break; | |
3704 } | |
45 | 3705 if (s != NULL) |
3706 { | |
161 | 3707 byte_count_cursor += line_count_info(s, &word_count_cursor, |
3708 &char_count_cursor, len, eol_size); | |
45 | 3709 if (lnum == curbuf->b_ml.ml_line_count |
3710 && !curbuf->b_p_eol | |
6933 | 3711 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 3712 && (long)STRLEN(s) < len) |
161 | 3713 byte_count_cursor -= eol_size; |
45 | 3714 } |
7 | 3715 } |
3716 else | |
3717 { | |
3718 /* In non-visual mode, check for the line the cursor is on */ | |
3719 if (lnum == curwin->w_cursor.lnum) | |
3720 { | |
3721 word_count_cursor += word_count; | |
161 | 3722 char_count_cursor += char_count; |
3723 byte_count_cursor = byte_count + | |
3724 line_count_info(ml_get(lnum), | |
3725 &word_count_cursor, &char_count_cursor, | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3726 (varnumber_T)(curwin->w_cursor.col + 1), |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3727 eol_size); |
7 | 3728 } |
3729 } | |
3730 /* Add to the running totals */ | |
161 | 3731 byte_count += line_count_info(ml_get(lnum), &word_count, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3732 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3733 eol_size); |
7 | 3734 } |
3735 | |
3736 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 3737 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 3738 byte_count -= eol_size; |
7 | 3739 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3740 if (dict == NULL) |
7 | 3741 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3742 if (VIsual_active) |
7 | 3743 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3744 if (VIsual_mode == Ctrl_V && curwin->w_curswant < MAXCOL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3745 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3746 getvcols(curwin, &min_pos, &max_pos, &min_pos.col, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3747 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3748 vim_snprintf((char *)buf1, sizeof(buf1), _("%ld Cols; "), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3749 (long)(oparg.end_vcol - oparg.start_vcol + 1)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3750 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3751 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3752 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3753 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3754 if (char_count_cursor == byte_count_cursor |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3755 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3756 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3757 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Bytes"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3758 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3759 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3760 (long_long_T)word_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3761 (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3762 (long_long_T)byte_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3763 (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3764 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3765 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3766 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Chars; %lld of %lld Bytes"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3767 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3768 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3769 (long_long_T)word_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3770 (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3771 (long_long_T)char_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3772 (long_long_T)char_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3773 (long_long_T)byte_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3774 (long_long_T)byte_count); |
7 | 3775 } |
3776 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3777 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3778 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3779 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3780 col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3781 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3782 col_print(buf2, sizeof(buf2), (int)STRLEN(p), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3783 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3784 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3785 if (char_count_cursor == byte_count_cursor |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3786 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3787 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3788 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Byte %lld of %lld"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3789 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3790 (long)curwin->w_cursor.lnum, |
7 | 3791 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3792 (long_long_T)word_count_cursor, (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3793 (long_long_T)byte_count_cursor, (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3794 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3795 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3796 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Char %lld of %lld; Byte %lld of %lld"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3797 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3798 (long)curwin->w_cursor.lnum, |
161 | 3799 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3800 (long_long_T)word_count_cursor, (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3801 (long_long_T)char_count_cursor, (long_long_T)char_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3802 (long_long_T)byte_count_cursor, (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3803 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3804 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3805 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3806 bom_count = bomb_size(); |
18062
0b351691071c
patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
17797
diff
changeset
|
3807 if (dict == NULL && bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
3808 vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE, |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3809 _("(+%lld for BOM)"), (long_long_T)bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3810 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3811 { |
18062
0b351691071c
patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
17797
diff
changeset
|
3812 // Don't shorten this message, the user asked for it. |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3813 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3814 p_shm = (char_u *)""; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3815 msg((char *)IObuff); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3816 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3817 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3818 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
3819 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3820 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3821 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3822 dict_add_number(dict, "words", word_count); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3823 dict_add_number(dict, "chars", char_count); |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3824 dict_add_number(dict, "bytes", byte_count + bom_count); |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3825 dict_add_number(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3826 byte_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3827 dict_add_number(dict, VIsual_active ? "visual_chars" : "cursor_chars", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3828 char_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3829 dict_add_number(dict, VIsual_active ? "visual_words" : "cursor_words", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3830 word_count_cursor); |
7 | 3831 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
3832 #endif |
7 | 3833 } |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3834 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3835 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3836 * Handle indent and format operators and visual mode ":". |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3837 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3838 static void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3839 op_colon(oparg_T *oap) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3840 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3841 stuffcharReadbuff(':'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3842 if (oap->is_VIsual) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3843 stuffReadbuff((char_u *)"'<,'>"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3844 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3845 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3846 // Make the range look nice, so it can be repeated. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3847 if (oap->start.lnum == curwin->w_cursor.lnum) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3848 stuffcharReadbuff('.'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3849 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3850 stuffnumReadbuff((long)oap->start.lnum); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3851 if (oap->end.lnum != oap->start.lnum) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3852 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3853 stuffcharReadbuff(','); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3854 if (oap->end.lnum == curwin->w_cursor.lnum) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3855 stuffcharReadbuff('.'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3856 else if (oap->end.lnum == curbuf->b_ml.ml_line_count) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3857 stuffcharReadbuff('$'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3858 else if (oap->start.lnum == curwin->w_cursor.lnum) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3859 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3860 stuffReadbuff((char_u *)".+"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3861 stuffnumReadbuff((long)oap->line_count - 1); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3862 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3863 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3864 stuffnumReadbuff((long)oap->end.lnum); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3865 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3866 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3867 if (oap->op_type != OP_COLON) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3868 stuffReadbuff((char_u *)"!"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3869 if (oap->op_type == OP_INDENT) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3870 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3871 #ifndef FEAT_CINDENT |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3872 if (*get_equalprg() == NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3873 stuffReadbuff((char_u *)"indent"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3874 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3875 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3876 stuffReadbuff(get_equalprg()); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3877 stuffReadbuff((char_u *)"\n"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3878 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3879 else if (oap->op_type == OP_FORMAT) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3880 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3881 if (*curbuf->b_p_fp != NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3882 stuffReadbuff(curbuf->b_p_fp); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3883 else if (*p_fp != NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3884 stuffReadbuff(p_fp); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3885 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3886 stuffReadbuff((char_u *)"fmt"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3887 stuffReadbuff((char_u *)"\n']"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3888 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3889 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3890 // do_cmdline() does the rest |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3891 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3892 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3893 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3894 * Handle the "g@" operator: call 'operatorfunc'. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3895 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3896 static void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3897 op_function(oparg_T *oap UNUSED) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3898 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3899 #ifdef FEAT_EVAL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3900 typval_T argv[2]; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3901 int save_virtual_op = virtual_op; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3902 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3903 if (*p_opfunc == NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3904 emsg(_("E774: 'operatorfunc' is empty")); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3905 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3906 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3907 // Set '[ and '] marks to text to be operated on. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3908 curbuf->b_op_start = oap->start; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3909 curbuf->b_op_end = oap->end; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3910 if (oap->motion_type != MLINE && !oap->inclusive) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3911 // Exclude the end position. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3912 decl(&curbuf->b_op_end); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3913 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3914 argv[0].v_type = VAR_STRING; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3915 if (oap->block_mode) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3916 argv[0].vval.v_string = (char_u *)"block"; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3917 else if (oap->motion_type == MLINE) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3918 argv[0].vval.v_string = (char_u *)"line"; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3919 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3920 argv[0].vval.v_string = (char_u *)"char"; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3921 argv[1].v_type = VAR_UNKNOWN; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3922 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3923 // Reset virtual_op so that 'virtualedit' can be changed in the |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3924 // function. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3925 virtual_op = MAYBE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3926 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3927 (void)call_func_retnr(p_opfunc, 1, argv); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3928 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3929 virtual_op = save_virtual_op; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3930 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3931 #else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3932 emsg(_("E775: Eval feature not available")); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3933 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3934 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3935 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3936 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3937 * Calculate start/end virtual columns for operating in block mode. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3938 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3939 static void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3940 get_op_vcol( |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3941 oparg_T *oap, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3942 colnr_T redo_VIsual_vcol, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3943 int initial) // when TRUE adjust position for 'selectmode' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3944 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3945 colnr_T start, end; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3946 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3947 if (VIsual_mode != Ctrl_V |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3948 || (!initial && oap->end.col < curwin->w_width)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3949 return; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3950 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3951 oap->block_mode = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3952 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3953 // prevent from moving onto a trail byte |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3954 if (has_mbyte) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3955 mb_adjustpos(curwin->w_buffer, &oap->end); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3956 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3957 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3958 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3959 if (!redo_VIsual_busy) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3960 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3961 getvvcol(curwin, &(oap->end), &start, NULL, &end); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3962 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3963 if (start < oap->start_vcol) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3964 oap->start_vcol = start; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3965 if (end > oap->end_vcol) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3966 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3967 if (initial && *p_sel == 'e' && start >= 1 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3968 && start - 1 >= oap->end_vcol) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3969 oap->end_vcol = start - 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3970 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3971 oap->end_vcol = end; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3972 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3973 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3974 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3975 // if '$' was used, get oap->end_vcol from longest line |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3976 if (curwin->w_curswant == MAXCOL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3977 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3978 curwin->w_cursor.col = MAXCOL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3979 oap->end_vcol = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3980 for (curwin->w_cursor.lnum = oap->start.lnum; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3981 curwin->w_cursor.lnum <= oap->end.lnum; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3982 ++curwin->w_cursor.lnum) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3983 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3984 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3985 if (end > oap->end_vcol) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3986 oap->end_vcol = end; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3987 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3988 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3989 else if (redo_VIsual_busy) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3990 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3991 // Correct oap->end.col and oap->start.col to be the |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3992 // upper-left and lower-right corner of the block area. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3993 // |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3994 // (Actually, this does convert column positions into character |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3995 // positions) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3996 curwin->w_cursor.lnum = oap->end.lnum; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3997 coladvance(oap->end_vcol); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3998 oap->end = curwin->w_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3999 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4000 curwin->w_cursor = oap->start; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4001 coladvance(oap->start_vcol); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4002 oap->start = curwin->w_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4003 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4004 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4005 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4006 * Handle an operator after Visual mode or when the movement is finished. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4007 * "gui_yank" is true when yanking text for the clipboard. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4008 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4009 void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4010 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4011 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4012 oparg_T *oap = cap->oap; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4013 pos_T old_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4014 int empty_region_error; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4015 int restart_edit_save; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4016 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4017 int lbr_saved = curwin->w_p_lbr; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4018 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4019 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4020 // The visual area is remembered for redo |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4021 static int redo_VIsual_mode = NUL; // 'v', 'V', or Ctrl-V |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4022 static linenr_T redo_VIsual_line_count; // number of lines |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4023 static colnr_T redo_VIsual_vcol; // number of cols or end column |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4024 static long redo_VIsual_count; // count for Visual operator |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4025 static int redo_VIsual_arg; // extra argument |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4026 int include_line_break = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4027 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4028 #if defined(FEAT_CLIPBOARD) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4029 // Yank the visual area into the GUI selection register before we operate |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4030 // on it and lose it forever. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4031 // Don't do it if a specific register was specified, so that ""x"*P works. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4032 // This could call do_pending_operator() recursively, but that's OK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4033 // because gui_yank will be TRUE for the nested call. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4034 if ((clip_star.available || clip_plus.available) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4035 && oap->op_type != OP_NOP |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4036 && !gui_yank |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4037 && VIsual_active |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4038 && !redo_VIsual_busy |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4039 && oap->regname == 0) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4040 clip_auto_select(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4041 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4042 old_cursor = curwin->w_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4043 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4044 // If an operation is pending, handle it... |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4045 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4046 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4047 // Yank can be redone when 'y' is in 'cpoptions', but not when yanking |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4048 // for the clipboard. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4049 int redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4050 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4051 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4052 // Avoid a problem with unwanted linebreaks in block mode. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4053 if (curwin->w_p_lbr) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4054 curwin->w_valid &= ~VALID_VIRTCOL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4055 curwin->w_p_lbr = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4056 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4057 oap->is_VIsual = VIsual_active; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4058 if (oap->motion_force == 'V') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4059 oap->motion_type = MLINE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4060 else if (oap->motion_force == 'v') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4061 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4062 // If the motion was linewise, "inclusive" will not have been set. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4063 // Use "exclusive" to be consistent. Makes "dvj" work nice. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4064 if (oap->motion_type == MLINE) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4065 oap->inclusive = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4066 // If the motion already was characterwise, toggle "inclusive" |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4067 else if (oap->motion_type == MCHAR) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4068 oap->inclusive = !oap->inclusive; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4069 oap->motion_type = MCHAR; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4070 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4071 else if (oap->motion_force == Ctrl_V) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4072 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4073 // Change line- or characterwise motion into Visual block mode. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4074 if (!VIsual_active) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4075 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4076 VIsual_active = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4077 VIsual = oap->start; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4078 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4079 VIsual_mode = Ctrl_V; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4080 VIsual_select = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4081 VIsual_reselect = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4082 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4083 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4084 // Only redo yank when 'y' flag is in 'cpoptions'. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4085 // Never redo "zf" (define fold). |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4086 if ((redo_yank || oap->op_type != OP_YANK) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4087 && ((!VIsual_active || oap->motion_force) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4088 // Also redo Operator-pending Visual mode mappings |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4089 || (VIsual_active && cap->cmdchar == ':' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4090 && oap->op_type != OP_COLON)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4091 && cap->cmdchar != 'D' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4092 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4093 && oap->op_type != OP_FOLD |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4094 && oap->op_type != OP_FOLDOPEN |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4095 && oap->op_type != OP_FOLDOPENREC |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4096 && oap->op_type != OP_FOLDCLOSE |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4097 && oap->op_type != OP_FOLDCLOSEREC |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4098 && oap->op_type != OP_FOLDDEL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4099 && oap->op_type != OP_FOLDDELREC |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4100 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4101 ) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4102 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4103 prep_redo(oap->regname, cap->count0, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4104 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4105 oap->motion_force, cap->cmdchar, cap->nchar); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4106 if (cap->cmdchar == '/' || cap->cmdchar == '?') // was a search |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4107 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4108 // If 'cpoptions' does not contain 'r', insert the search |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4109 // pattern to really repeat the same command. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4110 if (vim_strchr(p_cpo, CPO_REDO) == NULL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4111 AppendToRedobuffLit(cap->searchbuf, -1); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4112 AppendToRedobuff(NL_STR); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4113 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4114 else if (cap->cmdchar == ':') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4115 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4116 // do_cmdline() has stored the first typed line in |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4117 // "repeat_cmdline". When several lines are typed repeating |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4118 // won't be possible. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4119 if (repeat_cmdline == NULL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4120 ResetRedobuff(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4121 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4122 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4123 AppendToRedobuffLit(repeat_cmdline, -1); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4124 AppendToRedobuff(NL_STR); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4125 VIM_CLEAR(repeat_cmdline); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4126 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4127 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4128 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4129 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4130 if (redo_VIsual_busy) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4131 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4132 // Redo of an operation on a Visual area. Use the same size from |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4133 // redo_VIsual_line_count and redo_VIsual_vcol. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4134 oap->start = curwin->w_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4135 curwin->w_cursor.lnum += redo_VIsual_line_count - 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4136 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4137 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4138 VIsual_mode = redo_VIsual_mode; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4139 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4140 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4141 if (VIsual_mode == 'v') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4142 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4143 if (redo_VIsual_line_count <= 1) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4144 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4145 validate_virtcol(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4146 curwin->w_curswant = |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4147 curwin->w_virtcol + redo_VIsual_vcol - 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4148 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4149 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4150 curwin->w_curswant = redo_VIsual_vcol; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4151 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4152 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4153 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4154 curwin->w_curswant = MAXCOL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4155 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4156 coladvance(curwin->w_curswant); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4157 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4158 cap->count0 = redo_VIsual_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4159 if (redo_VIsual_count != 0) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4160 cap->count1 = redo_VIsual_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4161 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4162 cap->count1 = 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4163 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4164 else if (VIsual_active) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4165 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4166 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4167 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4168 // Save the current VIsual area for '< and '> marks, and "gv" |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4169 curbuf->b_visual.vi_start = VIsual; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4170 curbuf->b_visual.vi_end = curwin->w_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4171 curbuf->b_visual.vi_mode = VIsual_mode; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4172 restore_visual_mode(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4173 curbuf->b_visual.vi_curswant = curwin->w_curswant; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4174 # ifdef FEAT_EVAL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4175 curbuf->b_visual_mode_eval = VIsual_mode; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4176 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4177 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4178 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4179 // In Select mode, a linewise selection is operated upon like a |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4180 // characterwise selection. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4181 // Special case: gH<Del> deletes the last line. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4182 if (VIsual_select && VIsual_mode == 'V' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4183 && cap->oap->op_type != OP_DELETE) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4184 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4185 if (LT_POS(VIsual, curwin->w_cursor)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4186 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4187 VIsual.col = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4188 curwin->w_cursor.col = |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4189 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum)); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4190 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4191 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4192 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4193 curwin->w_cursor.col = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4194 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum)); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4195 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4196 VIsual_mode = 'v'; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4197 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4198 // If 'selection' is "exclusive", backup one character for |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4199 // charwise selections. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4200 else if (VIsual_mode == 'v') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4201 include_line_break = unadjust_for_sel(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4202 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4203 oap->start = VIsual; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4204 if (VIsual_mode == 'V') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4205 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4206 oap->start.col = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4207 oap->start.coladd = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4208 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4209 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4210 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4211 // Set oap->start to the first position of the operated text, oap->end |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4212 // to the end of the operated text. w_cursor is equal to oap->start. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4213 if (LT_POS(oap->start, curwin->w_cursor)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4214 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4215 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4216 // Include folded lines completely. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4217 if (!VIsual_active) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4218 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4219 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4220 oap->start.col = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4221 if ((curwin->w_cursor.col > 0 || oap->inclusive) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4222 && hasFolding(curwin->w_cursor.lnum, NULL, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4223 &curwin->w_cursor.lnum)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4224 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline()); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4225 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4226 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4227 oap->end = curwin->w_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4228 curwin->w_cursor = oap->start; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4229 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4230 // w_virtcol may have been updated; if the cursor goes back to its |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4231 // previous position w_virtcol becomes invalid and isn't updated |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4232 // automatically. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4233 curwin->w_valid &= ~VALID_VIRTCOL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4234 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4235 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4236 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4237 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4238 // Include folded lines completely. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4239 if (!VIsual_active && oap->motion_type == MLINE) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4240 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4241 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4242 NULL)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4243 curwin->w_cursor.col = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4244 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4245 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum)); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4246 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4247 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4248 oap->end = oap->start; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4249 oap->start = curwin->w_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4250 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4251 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4252 // Just in case lines were deleted that make the position invalid. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4253 check_pos(curwin->w_buffer, &oap->end); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4254 oap->line_count = oap->end.lnum - oap->start.lnum + 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4255 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4256 // Set "virtual_op" before resetting VIsual_active. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4257 virtual_op = virtual_active(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4258 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4259 if (VIsual_active || redo_VIsual_busy) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4260 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4261 get_op_vcol(oap, redo_VIsual_vcol, TRUE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4262 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4263 if (!redo_VIsual_busy && !gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4264 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4265 // Prepare to reselect and redo Visual: this is based on the |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4266 // size of the Visual text |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4267 resel_VIsual_mode = VIsual_mode; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4268 if (curwin->w_curswant == MAXCOL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4269 resel_VIsual_vcol = MAXCOL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4270 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4271 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4272 if (VIsual_mode != Ctrl_V) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4273 getvvcol(curwin, &(oap->end), |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4274 NULL, NULL, &oap->end_vcol); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4275 if (VIsual_mode == Ctrl_V || oap->line_count <= 1) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4276 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4277 if (VIsual_mode != Ctrl_V) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4278 getvvcol(curwin, &(oap->start), |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4279 &oap->start_vcol, NULL, NULL); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4280 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4281 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4282 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4283 resel_VIsual_vcol = oap->end_vcol; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4284 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4285 resel_VIsual_line_count = oap->line_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4286 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4287 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4288 // can't redo yank (unless 'y' is in 'cpoptions') and ":" |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4289 if ((redo_yank || oap->op_type != OP_YANK) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4290 && oap->op_type != OP_COLON |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4291 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4292 && oap->op_type != OP_FOLD |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4293 && oap->op_type != OP_FOLDOPEN |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4294 && oap->op_type != OP_FOLDOPENREC |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4295 && oap->op_type != OP_FOLDCLOSE |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4296 && oap->op_type != OP_FOLDCLOSEREC |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4297 && oap->op_type != OP_FOLDDEL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4298 && oap->op_type != OP_FOLDDELREC |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4299 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4300 && oap->motion_force == NUL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4301 ) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4302 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4303 // Prepare for redoing. Only use the nchar field for "r", |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4304 // otherwise it might be the second char of the operator. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4305 if (cap->cmdchar == 'g' && (cap->nchar == 'n' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4306 || cap->nchar == 'N')) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4307 prep_redo(oap->regname, cap->count0, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4308 get_op_char(oap->op_type), get_extra_op_char(oap->op_type), |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4309 oap->motion_force, cap->cmdchar, cap->nchar); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4310 else if (cap->cmdchar != ':') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4311 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4312 int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4313 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4314 // reverse what nv_replace() did |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4315 if (nchar == REPLACE_CR_NCHAR) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4316 nchar = CAR; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4317 else if (nchar == REPLACE_NL_NCHAR) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4318 nchar = NL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4319 prep_redo(oap->regname, 0L, NUL, 'v', |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4320 get_op_char(oap->op_type), |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4321 get_extra_op_char(oap->op_type), |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4322 nchar); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4323 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4324 if (!redo_VIsual_busy) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4325 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4326 redo_VIsual_mode = resel_VIsual_mode; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4327 redo_VIsual_vcol = resel_VIsual_vcol; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4328 redo_VIsual_line_count = resel_VIsual_line_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4329 redo_VIsual_count = cap->count0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4330 redo_VIsual_arg = cap->arg; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4331 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4332 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4333 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4334 // oap->inclusive defaults to TRUE. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4335 // If oap->end is on a NUL (empty line) oap->inclusive becomes |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4336 // FALSE. This makes "d}P" and "v}dP" work the same. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4337 if (oap->motion_force == NUL || oap->motion_type == MLINE) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4338 oap->inclusive = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4339 if (VIsual_mode == 'V') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4340 oap->motion_type = MLINE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4341 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4342 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4343 oap->motion_type = MCHAR; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4344 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4345 && (include_line_break || !virtual_op)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4346 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4347 oap->inclusive = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4348 // Try to include the newline, unless it's an operator |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4349 // that works on lines only. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4350 if (*p_sel != 'o' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4351 && !op_on_lines(oap->op_type) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4352 && oap->end.lnum < curbuf->b_ml.ml_line_count) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4353 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4354 ++oap->end.lnum; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4355 oap->end.col = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4356 oap->end.coladd = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4357 ++oap->line_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4358 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4359 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4360 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4361 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4362 redo_VIsual_busy = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4363 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4364 // Switch Visual off now, so screen updating does |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4365 // not show inverted text when the screen is redrawn. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4366 // With OP_YANK and sometimes with OP_COLON and OP_FILTER there is |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4367 // no screen redraw, so it is done here to remove the inverted |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4368 // part. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4369 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4370 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4371 VIsual_active = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4372 setmouse(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4373 mouse_dragging = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4374 may_clear_cmdline(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4375 if ((oap->op_type == OP_YANK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4376 || oap->op_type == OP_COLON |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4377 || oap->op_type == OP_FUNCTION |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4378 || oap->op_type == OP_FILTER) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4379 && oap->motion_force == NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4380 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4381 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4382 // make sure redrawing is correct |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4383 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4384 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4385 redraw_curbuf_later(INVERTED); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4386 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4387 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4388 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4389 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4390 // Include the trailing byte of a multi-byte char. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4391 if (has_mbyte && oap->inclusive) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4392 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4393 int l; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4394 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4395 l = (*mb_ptr2len)(ml_get_pos(&oap->end)); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4396 if (l > 1) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4397 oap->end.col += l - 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4398 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4399 curwin->w_set_curswant = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4400 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4401 // oap->empty is set when start and end are the same. The inclusive |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4402 // flag affects this too, unless yanking and the end is on a NUL. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4403 oap->empty = (oap->motion_type == MCHAR |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4404 && (!oap->inclusive |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4405 || (oap->op_type == OP_YANK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4406 && gchar_pos(&oap->end) == NUL)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4407 && EQUAL_POS(oap->start, oap->end) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4408 && !(virtual_op && oap->start.coladd != oap->end.coladd)); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4409 // For delete, change and yank, it's an error to operate on an |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4410 // empty region, when 'E' included in 'cpoptions' (Vi compatible). |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4411 empty_region_error = (oap->empty |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4412 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4413 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4414 // Force a redraw when operating on an empty Visual region, when |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4415 // 'modifiable is off or creating a fold. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4416 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4417 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4418 || oap->op_type == OP_FOLD |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4419 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4420 )) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4421 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4422 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4423 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4424 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4425 redraw_curbuf_later(INVERTED); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4426 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4427 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4428 // If the end of an operator is in column one while oap->motion_type |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4429 // is MCHAR and oap->inclusive is FALSE, we put op_end after the last |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4430 // character in the previous line. If op_start is on or before the |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4431 // first non-blank in the line, the operator becomes linewise |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4432 // (strange, but that's the way vi does it). |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4433 if ( oap->motion_type == MCHAR |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4434 && oap->inclusive == FALSE |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4435 && !(cap->retval & CA_NO_ADJ_OP_END) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4436 && oap->end.col == 0 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4437 && (!oap->is_VIsual || *p_sel == 'o') |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4438 && !oap->block_mode |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4439 && oap->line_count > 1) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4440 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4441 oap->end_adjusted = TRUE; // remember that we did this |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4442 --oap->line_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4443 --oap->end.lnum; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4444 if (inindent(0)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4445 oap->motion_type = MLINE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4446 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4447 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4448 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4449 if (oap->end.col) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4450 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4451 --oap->end.col; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4452 oap->inclusive = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4453 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4454 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4455 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4456 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4457 oap->end_adjusted = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4458 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4459 switch (oap->op_type) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4460 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4461 case OP_LSHIFT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4462 case OP_RSHIFT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4463 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4464 auto_format(FALSE, TRUE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4465 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4466 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4467 case OP_JOIN_NS: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4468 case OP_JOIN: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4469 if (oap->line_count < 2) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4470 oap->line_count = 2; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4471 if (curwin->w_cursor.lnum + oap->line_count - 1 > |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4472 curbuf->b_ml.ml_line_count) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4473 beep_flush(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4474 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4475 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4476 (void)do_join(oap->line_count, oap->op_type == OP_JOIN, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4477 TRUE, TRUE, TRUE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4478 auto_format(FALSE, TRUE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4479 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4480 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4481 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4482 case OP_DELETE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4483 VIsual_reselect = FALSE; // don't reselect now |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4484 if (empty_region_error) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4485 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4486 vim_beep(BO_OPER); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4487 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4488 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4489 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4490 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4491 (void)op_delete(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4492 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4493 u_save_cursor(); // cursor line wasn't saved yet |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4494 auto_format(FALSE, TRUE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4495 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4496 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4497 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4498 case OP_YANK: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4499 if (empty_region_error) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4500 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4501 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4502 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4503 vim_beep(BO_OPER); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4504 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4505 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4506 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4507 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4508 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4509 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4510 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4511 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4512 (void)op_yank(oap, FALSE, !gui_yank); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4513 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4514 check_cursor_col(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4515 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4516 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4517 case OP_CHANGE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4518 VIsual_reselect = FALSE; // don't reselect now |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4519 if (empty_region_error) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4520 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4521 vim_beep(BO_OPER); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4522 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4523 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4524 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4525 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4526 // This is a new edit command, not a restart. Need to |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4527 // remember it to make 'insertmode' work with mappings for |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4528 // Visual mode. But do this only once and not when typed and |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4529 // 'insertmode' isn't set. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4530 if (p_im || !KeyTyped) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4531 restart_edit_save = restart_edit; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4532 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4533 restart_edit_save = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4534 restart_edit = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4535 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4536 // Restore linebreak, so that when the user edits it looks as |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4537 // before. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4538 if (curwin->w_p_lbr != lbr_saved) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4539 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4540 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4541 get_op_vcol(oap, redo_VIsual_mode, FALSE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4542 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4543 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4544 // Reset finish_op now, don't want it set inside edit(). |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4545 finish_op = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4546 if (op_change(oap)) // will call edit() |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4547 cap->retval |= CA_COMMAND_BUSY; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4548 if (restart_edit == 0) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4549 restart_edit = restart_edit_save; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4550 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4551 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4552 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4553 case OP_FILTER: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4554 if (vim_strchr(p_cpo, CPO_FILTER) != NULL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4555 AppendToRedobuff((char_u *)"!\r"); // use any last used !cmd |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4556 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4557 bangredo = TRUE; // do_bang() will put cmd in redo buffer |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4558 // FALLTHROUGH |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4559 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4560 case OP_INDENT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4561 case OP_COLON: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4562 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4563 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4564 // If 'equalprg' is empty, do the indenting internally. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4565 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4566 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4567 # ifdef FEAT_LISP |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4568 if (curbuf->b_p_lisp) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4569 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4570 op_reindent(oap, get_lisp_indent); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4571 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4572 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4573 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4574 # ifdef FEAT_CINDENT |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4575 op_reindent(oap, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4576 # ifdef FEAT_EVAL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4577 *curbuf->b_p_inde != NUL ? get_expr_indent : |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4578 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4579 get_c_indent); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4580 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4581 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4582 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4583 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4584 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4585 op_colon(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4586 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4587 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4588 case OP_TILDE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4589 case OP_UPPER: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4590 case OP_LOWER: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4591 case OP_ROT13: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4592 if (empty_region_error) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4593 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4594 vim_beep(BO_OPER); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4595 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4596 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4597 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4598 op_tilde(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4599 check_cursor_col(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4600 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4601 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4602 case OP_FORMAT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4603 #if defined(FEAT_EVAL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4604 if (*curbuf->b_p_fex != NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4605 op_formatexpr(oap); // use expression |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4606 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4607 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4608 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4609 op_colon(oap); // use external command |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4610 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4611 op_format(oap, FALSE); // use internal function |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4612 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4613 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4614 case OP_FORMAT2: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4615 op_format(oap, TRUE); // use internal function |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4616 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4617 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4618 case OP_FUNCTION: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4619 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4620 // Restore linebreak, so that when the user edits it looks as |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4621 // before. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4622 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4623 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4624 op_function(oap); // call 'operatorfunc' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4625 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4626 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4627 case OP_INSERT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4628 case OP_APPEND: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4629 VIsual_reselect = FALSE; // don't reselect now |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4630 if (empty_region_error) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4631 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4632 vim_beep(BO_OPER); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4633 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4634 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4635 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4636 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4637 // This is a new edit command, not a restart. Need to |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4638 // remember it to make 'insertmode' work with mappings for |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4639 // Visual mode. But do this only once. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4640 restart_edit_save = restart_edit; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4641 restart_edit = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4642 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4643 // Restore linebreak, so that when the user edits it looks as |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4644 // before. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4645 if (curwin->w_p_lbr != lbr_saved) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4646 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4647 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4648 get_op_vcol(oap, redo_VIsual_mode, FALSE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4649 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4650 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4651 op_insert(oap, cap->count1); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4652 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4653 // Reset linebreak, so that formatting works correctly. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4654 curwin->w_p_lbr = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4655 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4656 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4657 // TODO: when inserting in several lines, should format all |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4658 // the lines. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4659 auto_format(FALSE, TRUE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4660 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4661 if (restart_edit == 0) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4662 restart_edit = restart_edit_save; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4663 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4664 cap->retval |= CA_COMMAND_BUSY; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4665 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4666 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4667 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4668 case OP_REPLACE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4669 VIsual_reselect = FALSE; // don't reselect now |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4670 if (empty_region_error) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4671 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4672 vim_beep(BO_OPER); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4673 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4674 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4675 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4676 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4677 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4678 // Restore linebreak, so that when the user edits it looks as |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4679 // before. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4680 if (curwin->w_p_lbr != lbr_saved) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4681 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4682 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4683 get_op_vcol(oap, redo_VIsual_mode, FALSE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4684 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4685 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4686 op_replace(oap, cap->nchar); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4687 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4688 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4689 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4690 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4691 case OP_FOLD: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4692 VIsual_reselect = FALSE; // don't reselect now |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4693 foldCreate(oap->start.lnum, oap->end.lnum); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4694 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4695 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4696 case OP_FOLDOPEN: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4697 case OP_FOLDOPENREC: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4698 case OP_FOLDCLOSE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4699 case OP_FOLDCLOSEREC: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4700 VIsual_reselect = FALSE; // don't reselect now |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4701 opFoldRange(oap->start.lnum, oap->end.lnum, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4702 oap->op_type == OP_FOLDOPEN |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4703 || oap->op_type == OP_FOLDOPENREC, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4704 oap->op_type == OP_FOLDOPENREC |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4705 || oap->op_type == OP_FOLDCLOSEREC, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4706 oap->is_VIsual); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4707 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4708 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4709 case OP_FOLDDEL: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4710 case OP_FOLDDELREC: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4711 VIsual_reselect = FALSE; // don't reselect now |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4712 deleteFold(oap->start.lnum, oap->end.lnum, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4713 oap->op_type == OP_FOLDDELREC, oap->is_VIsual); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4714 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4715 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4716 case OP_NR_ADD: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4717 case OP_NR_SUB: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4718 if (empty_region_error) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4719 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4720 vim_beep(BO_OPER); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4721 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4722 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4723 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4724 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4725 VIsual_active = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4726 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4727 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4728 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4729 op_addsub(oap, cap->count1, redo_VIsual_arg); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4730 VIsual_active = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4731 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4732 check_cursor_col(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4733 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4734 default: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4735 clearopbeep(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4736 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4737 virtual_op = MAYBE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4738 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4739 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4740 // if 'sol' not set, go back to old column for some commands |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4741 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4742 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4743 || oap->op_type == OP_DELETE)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4744 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4745 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4746 curwin->w_p_lbr = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4747 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4748 coladvance(curwin->w_curswant = old_col); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4749 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4750 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4751 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4752 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4753 curwin->w_cursor = old_cursor; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4754 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4755 oap->block_mode = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4756 clearop(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4757 motion_force = NUL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4758 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4759 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4760 curwin->w_p_lbr = lbr_saved; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4761 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4762 } |