Mercurial > vim
annotate src/ops.c @ 25315:cf45fde10bdb
Added tag v8.2.3194 for changeset 7e620652bd13fd4313bc3cb7d4d34ccd48166ec4
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 21 Jul 2021 19:15:04 +0200 |
parents | bd46322bea66 |
children | ac88cd21ae88 |
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, | |
23287
f2a70fca3485
patch 8.2.2189: cannot repeat a command that uses the small delete register
Bram Moolenaar <Bram@vim.org>
parents:
23281
diff
changeset
|
12 * op_change, op_yank, do_join |
7 | 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); |
7 | 20 |
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
|
21 // 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
|
22 #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
|
23 #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
|
24 |
7 | 25 /* |
26 * The names of operators. | |
27 * 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
|
28 * The third field holds OPF_ flags. |
7 | 29 */ |
30 static char opchars[][3] = | |
31 { | |
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
|
32 {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
|
33 {'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
|
34 {'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
|
35 {'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
|
36 {'<', 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
|
37 {'>', 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
|
38 {'!', 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
|
39 {'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
|
40 {'=', 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
|
41 {'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
|
42 {':', 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
|
43 {'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
|
44 {'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
|
45 {'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
|
46 {'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
|
47 {'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
|
48 {'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
|
49 {'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
|
50 {'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
|
51 {'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
|
52 {'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
|
53 {'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
|
54 {'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
|
55 {'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
|
56 {'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
|
57 {'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
|
58 {'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
|
59 {'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
|
60 {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
|
61 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB |
7 | 62 }; |
63 | |
64 /* | |
65 * Translate a command name into an operator type. | |
66 * Must only be called with a valid operator name! | |
67 */ | |
68 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
69 get_op_type(int char1, int char2) |
7 | 70 { |
71 int i; | |
72 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
73 if (char1 == 'r') // ignore second character |
7 | 74 return OP_REPLACE; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
75 if (char1 == '~') // when tilde is an operator |
7 | 76 return OP_TILDE; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
77 if (char1 == 'g' && char2 == Ctrl_A) // add |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
78 return OP_NR_ADD; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
79 if (char1 == 'g' && char2 == Ctrl_X) // subtract |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
80 return OP_NR_SUB; |
24866
f1121eb17e14
patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
81 if (char1 == 'z' && char2 == 'y') // OP_YANK |
f1121eb17e14
patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
82 return OP_YANK; |
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; | |
24768
7334bf933510
patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents:
24756
diff
changeset
|
87 if (i == (int)ARRAY_LENGTH(opchars) - 1) |
13072
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(); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
155 if (first_char == NUL) // empty line |
7 | 156 curwin->w_cursor.col = 0; |
157 else if (oap->block_mode) | |
158 shift_block(oap, amount); | |
159 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
160 // Move the line right if it doesn't start with '#', 'smartindent' |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
161 // isn't set or 'cindent' isn't set or '#' isn't in 'cino'. |
7 | 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 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
175 else if (curs_top) // put cursor on first line, for ">>" |
7 | 176 { |
177 curwin->w_cursor.lnum = oap->start.lnum; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
178 beginline(BL_SOL | BL_FIX); // shift_line() may have set cursor.col |
7 | 179 } |
180 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
181 --curwin->w_cursor.lnum; // put cursor on last line, for ":>" |
7 | 182 |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
183 #ifdef FEAT_FOLDING |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
184 // The cursor line is not in a closed fold |
10486
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); |
19665
b64343cbabc6
patch 8.2.0389: delayed redraw when shifting text from Insert mode
Bram Moolenaar <Bram@vim.org>
parents:
19477
diff
changeset
|
206 msg_attr_keep((char *)IObuff, 0, TRUE); |
7 | 207 } |
208 | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
209 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
210 { |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
211 // Set "'[" and "']" marks. |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
212 curbuf->b_op_start = oap->start; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
213 curbuf->b_op_end.lnum = oap->end.lnum; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
214 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
215 if (curbuf->b_op_end.col > 0) |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
216 --curbuf->b_op_end.col; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
217 } |
7 | 218 } |
219 | |
220 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
221 * 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
|
222 * leaves cursor on first blank in the line. |
7 | 223 */ |
224 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
225 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
226 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
227 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
228 int amount, |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
229 int call_changed_bytes) // call changed_bytes() |
7 | 230 { |
231 int count; | |
232 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
|
233 int sw_val = (int)get_sw_value_indent(curbuf); |
7 | 234 |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
235 count = get_indent(); // get current indent |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
236 |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
237 if (round) // round off indent |
7 | 238 { |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
239 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
|
240 j = count % sw_val; // extra spaces |
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
241 if (j && left) // first remove extra spaces |
7 | 242 --amount; |
243 if (left) | |
244 { | |
245 i -= amount; | |
246 if (i < 0) | |
247 i = 0; | |
248 } | |
249 else | |
250 i += amount; | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
251 count = i * sw_val; |
7 | 252 } |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
253 else // original vi indent |
7 | 254 { |
255 if (left) | |
256 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
257 count -= sw_val * amount; |
7 | 258 if (count < 0) |
259 count = 0; | |
260 } | |
261 else | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
262 count += sw_val * amount; |
7 | 263 } |
264 | |
18203
e0ec4cd7a865
patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
18164
diff
changeset
|
265 // Set new indent |
7 | 266 if (State & VREPLACE_FLAG) |
1516 | 267 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 268 else |
1516 | 269 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 270 } |
271 | |
272 /* | |
273 * Shift one line of the current block one shiftwidth right or left. | |
274 * Leaves cursor on first character in block. | |
275 */ | |
276 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
277 shift_block(oparg_T *oap, int amount) |
7 | 278 { |
279 int left = (oap->op_type == OP_LSHIFT); | |
280 int oldstate = State; | |
1839 | 281 int total; |
282 char_u *newp, *oldp; | |
7 | 283 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
|
284 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
|
285 int ts_val = (int)curbuf->b_p_ts; |
7 | 286 struct block_def bd; |
287 int incr; | |
1839 | 288 colnr_T ws_vcol; |
7 | 289 int i = 0, j = 0; |
290 int len; | |
291 #ifdef FEAT_RIGHTLEFT | |
292 int old_p_ri = p_ri; | |
293 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
294 p_ri = 0; // don't want revins in indent |
7 | 295 #endif |
296 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
297 State = INSERT; // don't want REPLACE for State |
7 | 298 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
299 if (bd.is_short) | |
300 return; | |
301 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
302 // 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
|
303 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
|
304 if ((total / sw_val) != amount) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
305 return; // multiplication overflow |
11997
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
306 |
7 | 307 oldp = ml_get_curline(); |
308 | |
309 if (!left) | |
310 { | |
311 /* | |
312 * 1. Get start vcol | |
313 * 2. Total ws vcols | |
314 * 3. Divvy into TABs & spp | |
315 * 4. Construct new string | |
316 */ | |
19195
2ef19eed524a
patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents:
19176
diff
changeset
|
317 total += bd.pre_whitesp; // all virtual WS up to & incl a split TAB |
7 | 318 ws_vcol = bd.start_vcol - bd.pre_whitesp; |
319 if (bd.startspaces) | |
320 { | |
321 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
322 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
323 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
324 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
325 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
326 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
327 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
328 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
329 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
330 } |
1995 | 331 else |
332 ++bd.textstart; | |
7 | 333 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
334 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 335 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
336 // TODO: is passing bd.textstart for start of the line OK? |
5995 | 337 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, |
338 (colnr_T)(bd.start_vcol)); | |
7 | 339 total += incr; |
340 bd.start_vcol += incr; | |
341 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
342 // OK, now total=all the VWS reqd, and textstart points at the 1st |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
343 // 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
|
344 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
345 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
|
346 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
|
347 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
|
348 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
349 j = total; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
350 #else |
7 | 351 if (!curbuf->b_p_et) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
352 i = ((ws_vcol % ts_val) + total) / ts_val; // number of tabs |
7 | 353 if (i) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
354 j = ((ws_vcol % ts_val) + total) % ts_val; // number of spp |
7 | 355 else |
356 j = total; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
357 #endif |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
358 // if we're splitting a TAB, allow for it |
7 | 359 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); |
360 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
|
361 newp = alloc(bd.textcol + i + j + len); |
7 | 362 if (newp == NULL) |
363 return; | |
364 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
365 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 366 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
367 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
368 // the end |
7 | 369 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); |
370 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
371 else // left |
7 | 372 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
373 colnr_T destination_col; // column to which text in block will |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
374 // be shifted |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
375 char_u *verbatim_copy_end; // end of the part of the line which is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
376 // copied verbatim |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
377 colnr_T verbatim_copy_width;// the (displayed) width of this part |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
378 // of line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
379 unsigned fill; // nr of spaces that replace a TAB |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
380 unsigned new_line_len; // the length of the line after the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
381 // block shift |
1839 | 382 size_t block_space_width; |
383 size_t shift_amount; | |
384 char_u *non_white = bd.textstart; | |
385 colnr_T non_white_col; | |
386 | |
387 /* | |
388 * Firstly, let's find the first non-whitespace character that is | |
389 * displayed after the block's start column and the character's column | |
390 * number. Also, let's calculate the width of all the whitespace | |
391 * characters that are displayed in the block and precede the searched | |
392 * non-whitespace character. | |
393 */ | |
394 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
395 // If "bd.startspaces" is set, "bd.textstart" points to the character, |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
396 // the part of which is displayed at the block's beginning. Let's start |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
397 // searching from the next character. |
1839 | 398 if (bd.startspaces) |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
399 MB_PTR_ADV(non_white); |
1839 | 400 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
401 // The character's column is in "bd.start_vcol". |
1839 | 402 non_white_col = bd.start_vcol; |
403 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
404 while (VIM_ISWHITE(*non_white)) |
7 | 405 { |
5995 | 406 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 407 non_white_col += incr; |
7 | 408 } |
1839 | 409 |
410 block_space_width = non_white_col - oap->start_vcol; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
411 // We will shift by "total" or "block_space_width", whichever is less. |
1860 | 412 shift_amount = (block_space_width < (size_t)total |
413 ? block_space_width : (size_t)total); | |
1839 | 414 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
415 // The column to which we will shift the text. |
1860 | 416 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 417 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
418 // Now let's find out how much of the beginning of the line we can |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
419 // reuse without modification. |
1839 | 420 verbatim_copy_end = bd.textstart; |
421 verbatim_copy_width = bd.start_vcol; | |
422 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
423 // If "bd.startspaces" is set, "bd.textstart" points to the character |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
424 // preceding the block. We have to subtract its width to obtain its |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
425 // column number. |
1839 | 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 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
432 // TODO: is passing verbatim_copy_end for start of the line OK? |
5995 | 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 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
441 // If "destination_col" is different from the width of the initial |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
442 // part of the line that will be copied, it means we encountered a tab |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
443 // character, which we will have to partly replace with spaces. |
1839 | 444 fill = destination_col - verbatim_copy_width; |
445 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
446 // The replacement line will consist of: |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
447 // - the beginning of the original line up to "verbatim_copy_end", |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
448 // - "fill" number of spaces, |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
449 // - the rest of the line, pointed to by non_white. |
1839 | 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 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
461 // replace the line |
7 | 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; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
483 int count = 0; // extra spaces to replace a cut TAB |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
484 int spaces = 0; // non-zero if cutting a TAB |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
485 colnr_T offset; // pointer along new line |
22282
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
22278
diff
changeset
|
486 colnr_T startcol; // column where insert starts |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
487 unsigned s_len; // STRLEN(s) |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
488 char_u *newp, *oldp; // new, old lines |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
489 linenr_T lnum; // loop var |
7 | 490 int oldstate = State; |
491 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
492 State = INSERT; // don't want REPLACE for State |
7 | 493 s_len = (unsigned)STRLEN(s); |
494 | |
495 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
496 { | |
497 block_prep(oap, bdp, lnum, TRUE); | |
498 if (bdp->is_short && b_insert) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
499 continue; // OP_INSERT, line ends before block start |
7 | 500 |
501 oldp = ml_get(lnum); | |
502 | |
503 if (b_insert) | |
504 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
505 ts_val = bdp->start_char_vcols; |
7 | 506 spaces = bdp->startspaces; |
507 if (spaces != 0) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
508 count = ts_val - 1; // we're cutting a TAB |
7 | 509 offset = bdp->textcol; |
510 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
511 else // append |
7 | 512 { |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
513 ts_val = bdp->end_char_vcols; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
514 if (!bdp->is_short) // spaces = padding after block |
7 | 515 { |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
516 spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); |
7 | 517 if (spaces != 0) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
518 count = ts_val - 1; // we're cutting a TAB |
7 | 519 offset = bdp->textcol + bdp->textlen - (spaces != 0); |
520 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
521 else // spaces = padding to block edge |
7 | 522 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
523 // if $ used, just append to EOL (ie spaces==0) |
7 | 524 if (!bdp->is_MAX) |
525 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
526 count = spaces; | |
527 offset = bdp->textcol + bdp->textlen; | |
528 } | |
529 } | |
530 | |
6140 | 531 if (has_mbyte && spaces > 0) |
532 { | |
6460 | 533 int off; |
534 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
535 // Avoid starting halfway a multi-byte character. |
6140 | 536 if (b_insert) |
537 { | |
6460 | 538 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 539 } |
540 else | |
541 { | |
6460 | 542 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 543 offset += off; |
544 } | |
6460 | 545 spaces -= off; |
546 count -= off; | |
6140 | 547 } |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
548 if (spaces < 0) // can happen when the cursor was moved |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
549 spaces = 0; |
6140 | 550 |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
551 newp = alloc(STRLEN(oldp) + s_len + count + 1); |
7 | 552 if (newp == NULL) |
553 continue; | |
554 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
555 // copy up to shifted part |
7 | 556 mch_memmove(newp, oldp, (size_t)(offset)); |
557 oldp += offset; | |
558 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
559 // insert pre-padding |
6929 | 560 vim_memset(newp + offset, ' ', (size_t)spaces); |
22282
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
22278
diff
changeset
|
561 startcol = offset + spaces; |
7 | 562 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
563 // copy the new text |
22282
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
22278
diff
changeset
|
564 mch_memmove(newp + startcol, s, (size_t)s_len); |
7 | 565 offset += s_len; |
566 | |
567 if (spaces && !bdp->is_short) | |
568 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
569 // 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
|
570 vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
571 // We're splitting a TAB, don't copy it. |
7 | 572 oldp++; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
573 // We allowed for that TAB, remember this now |
7 | 574 count++; |
575 } | |
576 | |
577 if (spaces > 0) | |
578 offset += count; | |
1622 | 579 STRMOVE(newp + offset, oldp); |
7 | 580 |
581 ml_replace(lnum, newp, FALSE); | |
582 | |
22282
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
22278
diff
changeset
|
583 if (b_insert) |
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
22278
diff
changeset
|
584 // correct any text properties |
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
22278
diff
changeset
|
585 inserted_bytes(lnum, startcol, s_len); |
5adb97bf0b32
patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents:
22278
diff
changeset
|
586 |
7 | 587 if (lnum == oap->end.lnum) |
588 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
589 // Set "']" mark to the end of the block instead of the end of |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
590 // the insert in the first line. |
7 | 591 curbuf->b_op_end.lnum = oap->end.lnum; |
592 curbuf->b_op_end.col = offset; | |
593 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
594 } // for all lnum |
7 | 595 |
596 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
597 | |
598 State = oldstate; | |
599 } | |
600 | |
601 /* | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
602 * Handle a delete operation. |
7 | 603 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
604 * Return FAIL if undo failed, OK otherwise. |
7 | 605 */ |
606 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
607 op_delete(oparg_T *oap) |
7 | 608 { |
609 int n; | |
610 linenr_T lnum; | |
611 char_u *ptr; | |
612 char_u *newp, *oldp; | |
613 struct block_def bd; | |
614 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
615 int did_yank = FALSE; | |
616 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
617 if (curbuf->b_ml.ml_flags & ML_EMPTY) // nothing to do |
7 | 618 return OK; |
619 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
620 // Nothing to delete, return here. Do prepare undo, for op_change(). |
7 | 621 if (oap->empty) |
622 return u_save_cursor(); | |
623 | |
624 if (!curbuf->b_p_ma) | |
625 { | |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
24866
diff
changeset
|
626 emsg(_(e_cannot_make_changes_modifiable_is_off)); |
7 | 627 return FAIL; |
628 } | |
629 | |
630 #ifdef FEAT_CLIPBOARD | |
631 adjust_clip_reg(&oap->regname); | |
632 #endif | |
633 | |
634 if (has_mbyte) | |
635 mb_adjust_opend(oap); | |
636 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
637 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
638 * 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
|
639 * 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
|
640 * 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
|
641 */ |
7 | 642 if ( oap->motion_type == MCHAR |
643 && !oap->is_VIsual | |
50 | 644 && !oap->block_mode |
7 | 645 && oap->line_count > 1 |
3254 | 646 && oap->motion_force == NUL |
7 | 647 && oap->op_type == OP_DELETE) |
648 { | |
2957 | 649 ptr = ml_get(oap->end.lnum) + oap->end.col; |
650 if (*ptr != NUL) | |
651 ptr += oap->inclusive; | |
7 | 652 ptr = skipwhite(ptr); |
653 if (*ptr == NUL && inindent(0)) | |
654 oap->motion_type = MLINE; | |
655 } | |
656 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
657 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
658 * 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
|
659 * 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
|
660 */ |
7 | 661 if ( oap->motion_type == MCHAR |
662 && oap->line_count == 1 | |
663 && oap->op_type == OP_DELETE | |
664 && *ml_get(oap->start.lnum) == NUL) | |
665 { | |
666 /* | |
446 | 667 * It's an error to operate on an empty region, when 'E' included in |
7 | 668 * 'cpoptions' (Vi compatible). |
669 */ | |
446 | 670 if (virtual_op) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
671 // Virtual editing: Nothing gets deleted, but we set the '[ and '] |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
672 // marks as if it happened. |
446 | 673 goto setmarks; |
7 | 674 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
675 beep_flush(); | |
676 return OK; | |
677 } | |
678 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
679 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
680 * 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
|
681 * 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
|
682 * 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
|
683 */ |
7 | 684 if (oap->regname != '_') |
685 { | |
686 if (oap->regname != 0) | |
687 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
688 // check for read-only register |
7 | 689 if (!valid_yank_reg(oap->regname, TRUE)) |
690 { | |
691 beep_flush(); | |
692 return OK; | |
693 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
694 get_yank_register(oap->regname, TRUE); // yank into specif'd reg. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
695 if (op_yank(oap, TRUE, FALSE) == OK) // yank without message |
7 | 696 did_yank = TRUE; |
697 } | |
698 | |
699 /* | |
700 * 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
|
701 * 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
|
702 * compatible) |
3782 | 703 * Use the register name from before adjust_clip_reg() may have |
704 * changed it. | |
7 | 705 */ |
15987
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
706 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
|
707 || oap->use_reg_one) |
7 | 708 { |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
709 shift_delete_registers(); |
7 | 710 if (op_yank(oap, TRUE, FALSE) == OK) |
711 did_yank = TRUE; | |
712 } | |
713 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
714 // Yank into small delete register when no named register specified |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
715 // and the delete is within one line. |
3468 | 716 if (( |
717 #ifdef FEAT_CLIPBOARD | |
3584 | 718 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
719 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 720 #endif |
721 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 722 && oap->line_count == 1) |
723 { | |
724 oap->regname = '-'; | |
725 get_yank_register(oap->regname, TRUE); | |
726 if (op_yank(oap, TRUE, FALSE) == OK) | |
727 did_yank = TRUE; | |
728 oap->regname = 0; | |
729 } | |
730 | |
731 /* | |
732 * If there's too much stuff to fit in the yank register, then get a | |
733 * confirmation before doing the delete. This is crude, but simple. | |
734 * And it avoids doing a delete of something we can't put back if we | |
735 * want. | |
736 */ | |
737 if (!did_yank) | |
738 { | |
739 int msg_silent_save = msg_silent; | |
740 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
741 msg_silent = 0; // must display the prompt |
7 | 742 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); |
743 msg_silent = msg_silent_save; | |
744 if (n != 'y') | |
745 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
746 emsg(_(e_abort)); |
7 | 747 return FAIL; |
748 } | |
749 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
750 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
751 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
752 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
|
753 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
|
754 #endif |
7 | 755 } |
756 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
757 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
758 * 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
|
759 */ |
7 | 760 if (oap->block_mode) |
761 { | |
762 if (u_save((linenr_T)(oap->start.lnum - 1), | |
763 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
764 return FAIL; | |
765 | |
766 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
767 { | |
768 block_prep(oap, &bd, lnum, TRUE); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
769 if (bd.textlen == 0) // nothing to delete |
7 | 770 continue; |
771 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
772 // Adjust cursor position for tab replaced by spaces and 'lbr'. |
7 | 773 if (lnum == curwin->w_cursor.lnum) |
774 { | |
775 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
776 curwin->w_cursor.coladd = 0; | |
777 } | |
778 | |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
779 // "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
|
780 // 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
|
781 // Thus the number of characters may increase! |
7 | 782 n = bd.textlen - bd.startspaces - bd.endspaces; |
783 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
|
784 newp = alloc(STRLEN(oldp) + 1 - n); |
7 | 785 if (newp == NULL) |
786 continue; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
787 // copy up to deleted part |
7 | 788 mch_memmove(newp, oldp, (size_t)bd.textcol); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
789 // insert spaces |
6929 | 790 vim_memset(newp + bd.textcol, ' ', |
7 | 791 (size_t)(bd.startspaces + bd.endspaces)); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
792 // copy the part after the deleted part |
7 | 793 oldp += bd.textcol + bd.textlen; |
1622 | 794 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
795 // replace the line |
7 | 796 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
|
797 |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
798 #ifdef FEAT_PROP_POPUP |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
799 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
|
800 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
|
801 #endif |
7 | 802 } |
803 | |
804 check_cursor_col(); | |
805 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
806 oap->end.lnum + 1, 0L); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
807 oap->line_count = 0; // no lines deleted |
7 | 808 } |
5735 | 809 else if (oap->motion_type == MLINE) |
7 | 810 { |
811 if (oap->op_type == OP_CHANGE) | |
812 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
813 // Delete the lines except the first one. Temporarily move the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
814 // cursor to the next line. Save the current line number, if the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
815 // last line is deleted it may be changed. |
7 | 816 if (oap->line_count > 1) |
817 { | |
818 lnum = curwin->w_cursor.lnum; | |
819 ++curwin->w_cursor.lnum; | |
820 del_lines((long)(oap->line_count - 1), TRUE); | |
821 curwin->w_cursor.lnum = lnum; | |
822 } | |
823 if (u_save_cursor() == FAIL) | |
824 return FAIL; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
825 if (curbuf->b_p_ai) // don't delete indent |
7 | 826 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
827 beginline(BL_WHITE); // cursor on first non-white |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
828 did_ai = TRUE; // delete the indent when ESC hit |
7 | 829 ai_col = curwin->w_cursor.col; |
830 } | |
831 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
832 beginline(0); // cursor in column 0 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
833 truncate_line(FALSE); // delete the rest of the line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
834 // leave cursor past last char in line |
7 | 835 if (oap->line_count > 1) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
836 u_clearline(); // "U" command not possible after "2cc" |
7 | 837 } |
838 else | |
839 { | |
840 del_lines(oap->line_count, TRUE); | |
841 beginline(BL_WHITE | BL_FIX); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
842 u_clearline(); // "U" command not possible after "dd" |
7 | 843 } |
844 } | |
845 else | |
846 { | |
847 if (virtual_op) | |
848 { | |
849 int endcol = 0; | |
850 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
851 // For virtualedit: break the tabs that are partly included. |
7 | 852 if (gchar_pos(&oap->start) == '\t') |
853 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
854 if (u_save_cursor() == FAIL) // save first line for undo |
7 | 855 return FAIL; |
856 if (oap->line_count == 1) | |
857 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
858 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
859 oap->start = curwin->w_cursor; | |
860 if (oap->line_count == 1) | |
861 { | |
862 coladvance(endcol); | |
863 oap->end.col = curwin->w_cursor.col; | |
864 oap->end.coladd = curwin->w_cursor.coladd; | |
865 curwin->w_cursor = oap->start; | |
866 } | |
867 } | |
868 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
869 // Break a tab only when it's included in the area. |
7 | 870 if (gchar_pos(&oap->end) == '\t' |
871 && (int)oap->end.coladd < oap->inclusive) | |
872 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
873 // save last line for undo |
7 | 874 if (u_save((linenr_T)(oap->end.lnum - 1), |
875 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
876 return FAIL; | |
877 curwin->w_cursor = oap->end; | |
878 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
879 oap->end = curwin->w_cursor; | |
880 curwin->w_cursor = oap->start; | |
881 } | |
18481
26256dcadd77
patch 8.1.2235: "C" with 'virtualedit' set does not include multi-byte char
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
882 if (has_mbyte) |
26256dcadd77
patch 8.1.2235: "C" with 'virtualedit' set does not include multi-byte char
Bram Moolenaar <Bram@vim.org>
parents:
18354
diff
changeset
|
883 mb_adjust_opend(oap); |
7 | 884 } |
885 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
886 if (oap->line_count == 1) // delete characters within one line |
7 | 887 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
888 if (u_save_cursor() == FAIL) // save line for undo |
7 | 889 return FAIL; |
890 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
891 // if 'cpoptions' contains '$', display '$' at end of change |
5735 | 892 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 893 && oap->op_type == OP_CHANGE |
894 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 895 && !oap->is_VIsual) |
7 | 896 display_dollar(oap->end.col - !oap->inclusive); |
897 | |
898 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
899 | |
900 if (virtual_op) | |
901 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
902 // fix up things for virtualedit-delete: |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
903 // break the tabs which are going to get in our way |
7 | 904 char_u *curline = ml_get_curline(); |
905 int len = (int)STRLEN(curline); | |
906 | |
907 if (oap->end.coladd != 0 | |
908 && (int)oap->end.col >= len - 1 | |
909 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
910 n++; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
911 // Delete at least one char (e.g, when on a control char). |
7 | 912 if (n == 0 && oap->start.coladd != oap->end.coladd) |
913 n = 1; | |
914 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
915 // When deleted a char in the line, reset coladd. |
7 | 916 if (gchar_cursor() != NUL) |
917 curwin->w_cursor.coladd = 0; | |
918 } | |
6826 | 919 (void)del_bytes((long)n, !virtual_op, |
920 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 921 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
922 else // delete characters between lines |
7 | 923 { |
924 pos_T curpos; | |
925 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
926 // save deleted and changed lines for undo |
7 | 927 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), |
928 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
929 return FAIL; | |
930 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
931 truncate_line(TRUE); // delete from cursor to end of line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
932 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
933 curpos = curwin->w_cursor; // remember curwin->w_cursor |
7 | 934 ++curwin->w_cursor.lnum; |
935 del_lines((long)(oap->line_count - 2), FALSE); | |
936 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
937 // delete from start of line until op_end |
2957 | 938 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 939 curwin->w_cursor.col = 0; |
940 (void)del_bytes((long)n, !virtual_op, | |
941 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
942 curwin->w_cursor = curpos; // restore curwin->w_cursor |
6826 | 943 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); |
7 | 944 } |
23241
87acfcf65a2e
patch 8.2.2166: auto format doesn't work when deleting text
Bram Moolenaar <Bram@vim.org>
parents:
22965
diff
changeset
|
945 auto_format(FALSE, TRUE); |
7 | 946 } |
947 | |
948 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
949 | |
446 | 950 setmarks: |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
951 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
7 | 952 { |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
953 if (oap->block_mode) |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
954 { |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
955 curbuf->b_op_end.lnum = oap->end.lnum; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
956 curbuf->b_op_end.col = oap->start.col; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
957 } |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
958 else |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
959 curbuf->b_op_end = oap->start; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
960 curbuf->b_op_start = oap->start; |
7 | 961 } |
962 | |
963 return OK; | |
964 } | |
965 | |
966 /* | |
967 * Adjust end of operating area for ending on a multi-byte character. | |
968 * Used for deletion. | |
969 */ | |
970 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
971 mb_adjust_opend(oparg_T *oap) |
7 | 972 { |
973 char_u *p; | |
974 | |
975 if (oap->inclusive) | |
976 { | |
977 p = ml_get(oap->end.lnum); | |
978 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
979 } | |
980 } | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
981 |
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
|
982 /* |
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
|
983 * 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
|
984 * 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
|
985 */ |
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
|
986 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
|
987 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
|
988 { |
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
|
989 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
|
990 |
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
|
991 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
|
992 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
|
993 State = n; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
994 // Backup to the replaced character. |
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
|
995 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
|
996 } |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
997 |
7 | 998 /* |
999 * Replace a whole area with one character. | |
1000 */ | |
1001 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1002 op_replace(oparg_T *oap, int c) |
7 | 1003 { |
1004 int n, numc; | |
1005 int num_chars; | |
1006 char_u *newp, *oldp; | |
1007 size_t oldlen; | |
1008 struct block_def bd; | |
5428 | 1009 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
|
1010 int had_ctrl_v_cr = FALSE; |
7 | 1011 |
1012 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1013 return OK; // nothing to do |
7 | 1014 |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1015 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
|
1016 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1017 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
|
1018 c = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1019 } |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1020 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
|
1021 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1022 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
|
1023 c = NL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
1024 } |
5428 | 1025 |
7 | 1026 if (has_mbyte) |
1027 mb_adjust_opend(oap); | |
1028 | |
1029 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1030 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1031 return FAIL; | |
1032 | |
1033 /* | |
1034 * block mode replace | |
1035 */ | |
1036 if (oap->block_mode) | |
1037 { | |
1038 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
1039 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
1040 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1041 curwin->w_cursor.col = 0; // make sure cursor position is valid |
7 | 1042 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
1043 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1044 continue; // nothing to replace |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1045 |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1046 // n == number of extra chars required |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1047 // If we split a TAB, it may be replaced by several characters. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1048 // Thus the number of characters may increase! |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1049 // If the range starts in virtual space, count the initial |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1050 // coladd offset as part of "startspaces" |
7 | 1051 if (virtual_op && bd.is_short && *bd.textstart == NUL) |
1052 { | |
1053 pos_T vpos; | |
1054 | |
1982 | 1055 vpos.lnum = curwin->w_cursor.lnum; |
7 | 1056 getvpos(&vpos, oap->start_vcol); |
1057 bd.startspaces += vpos.coladd; | |
1058 n = bd.startspaces; | |
1059 } | |
1060 else | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1061 // allow for pre spaces |
7 | 1062 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); |
1063 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1064 // allow for post spp |
7 | 1065 n += (bd.endspaces |
1066 && !bd.is_oneChar | |
1067 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1068 // Figure out how many characters to replace. |
7 | 1069 numc = oap->end_vcol - oap->start_vcol + 1; |
1070 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
1071 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
1072 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1073 // A double-wide character can be replaced only up to half the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1074 // times. |
7 | 1075 if ((*mb_char2cells)(c) > 1) |
1076 { | |
1077 if ((numc & 1) && !bd.is_short) | |
1078 { | |
1079 ++bd.endspaces; | |
1080 ++n; | |
1081 } | |
1082 numc = numc / 2; | |
1083 } | |
1084 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1085 // Compute bytes needed, move character count to num_chars. |
7 | 1086 num_chars = numc; |
1087 numc *= (*mb_char2len)(c); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1088 // oldlen includes textlen, so don't double count |
7 | 1089 n += numc - bd.textlen; |
1090 | |
1091 oldp = ml_get_curline(); | |
1092 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
|
1093 newp = alloc(oldlen + 1 + n); |
7 | 1094 if (newp == NULL) |
1095 continue; | |
1096 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1097 // copy up to deleted part |
7 | 1098 mch_memmove(newp, oldp, (size_t)bd.textcol); |
1099 oldp += bd.textcol + bd.textlen; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1100 // insert pre-spaces |
6929 | 1101 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1102 // insert replacement chars CHECK FOR ALLOCATED SPACE |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1103 // REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1104 // literally. |
5428 | 1105 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
7 | 1106 { |
5428 | 1107 if (has_mbyte) |
1108 { | |
1109 n = (int)STRLEN(newp); | |
1110 while (--num_chars >= 0) | |
1111 n += (*mb_char2bytes)(c, newp + n); | |
1112 } | |
1113 else | |
6929 | 1114 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 1115 if (!bd.is_short) |
1116 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1117 // insert post-spaces |
6929 | 1118 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1119 // copy the part after the changed part |
5428 | 1120 STRMOVE(newp + STRLEN(newp), oldp); |
1121 } | |
7 | 1122 } |
1123 else | |
1124 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1125 // 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
|
1126 after_p = alloc(oldlen + 1 + n - STRLEN(newp)); |
5428 | 1127 if (after_p != NULL) |
1128 STRMOVE(after_p, oldp); | |
7 | 1129 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1130 // replace the line |
7 | 1131 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
5428 | 1132 if (after_p != NULL) |
1133 { | |
1134 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
1135 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
1136 oap->end.lnum++; | |
1137 vim_free(after_p); | |
1138 } | |
7 | 1139 } |
1140 } | |
1141 else | |
1142 { | |
1143 /* | |
1144 * MCHAR and MLINE motion replace. | |
1145 */ | |
1146 if (oap->motion_type == MLINE) | |
1147 { | |
1148 oap->start.col = 0; | |
1149 curwin->w_cursor.col = 0; | |
1150 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1151 if (oap->end.col) | |
1152 --oap->end.col; | |
1153 } | |
1154 else if (!oap->inclusive) | |
1155 dec(&(oap->end)); | |
1156 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
1157 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 1158 { |
1159 n = gchar_cursor(); | |
1160 if (n != NUL) | |
1161 { | |
1162 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
1163 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1164 // This is slow, but it handles replacing a single-byte |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1165 // with a multi-byte and the other way around. |
4203 | 1166 if (curwin->w_cursor.lnum == oap->end.lnum) |
1167 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
|
1168 replace_character(c); |
7 | 1169 } |
1170 else | |
1171 { | |
1172 if (n == TAB) | |
1173 { | |
1174 int end_vcol = 0; | |
1175 | |
1176 if (curwin->w_cursor.lnum == oap->end.lnum) | |
1177 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1178 // oap->end has to be recalculated when |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1179 // the tab breaks |
7 | 1180 end_vcol = getviscol2(oap->end.col, |
1181 oap->end.coladd); | |
1182 } | |
1183 coladvance_force(getviscol()); | |
1184 if (curwin->w_cursor.lnum == oap->end.lnum) | |
1185 getvpos(&oap->end, end_vcol); | |
1186 } | |
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
|
1187 PBYTE(curwin->w_cursor, c); |
7 | 1188 } |
1189 } | |
1190 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
1191 { | |
1192 int virtcols = oap->end.coladd; | |
1193 | |
1194 if (curwin->w_cursor.lnum == oap->start.lnum | |
1195 && oap->start.col == oap->end.col && oap->start.coladd) | |
1196 virtcols -= oap->start.coladd; | |
1197 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1198 // oap->end has been trimmed so it's effectively inclusive; |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1199 // as a result an extra +1 must be counted so we don't |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1200 // trample the NUL byte. |
7 | 1201 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); |
1202 curwin->w_cursor.col -= (virtcols + 1); | |
1203 for (; virtcols >= 0; virtcols--) | |
1204 { | |
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
|
1205 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
|
1206 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
|
1207 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
|
1208 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
|
1209 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
|
1210 break; |
7 | 1211 } |
1212 } | |
1213 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1214 // Advance to next character, stop at the end of the file. |
7 | 1215 if (inc_cursor() == -1) |
1216 break; | |
1217 } | |
1218 } | |
1219 | |
1220 curwin->w_cursor = oap->start; | |
1221 check_cursor(); | |
1222 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
1223 | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
1224 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1225 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1226 // Set "'[" and "']" marks. |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1227 curbuf->b_op_start = oap->start; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1228 curbuf->b_op_end = oap->end; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1229 } |
7 | 1230 |
1231 return OK; | |
1232 } | |
1233 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
1234 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 1235 |
7 | 1236 /* |
1237 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
1238 */ | |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
1239 static void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1240 op_tilde(oparg_T *oap) |
7 | 1241 { |
1242 pos_T pos; | |
1243 struct block_def bd; | |
1528 | 1244 int did_change = FALSE; |
7 | 1245 |
1246 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1247 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1248 return; | |
1249 | |
1250 pos = oap->start; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1251 if (oap->block_mode) // Visual block mode |
7 | 1252 { |
1253 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
1254 { | |
1766 | 1255 int one_change; |
1256 | |
7 | 1257 block_prep(oap, &bd, pos.lnum, FALSE); |
1258 pos.col = bd.textcol; | |
1766 | 1259 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
1260 did_change |= one_change; | |
1525 | 1261 |
5735 | 1262 #ifdef FEAT_NETBEANS_INTG |
2210 | 1263 if (netbeans_active() && one_change) |
7 | 1264 { |
1265 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
1266 | |
33 | 1267 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
1268 (long)bd.textlen); | |
7 | 1269 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 1270 &ptr[bd.textcol], bd.textlen); |
7 | 1271 } |
5735 | 1272 #endif |
7 | 1273 } |
1274 if (did_change) | |
1275 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
1276 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1277 else // not block mode |
7 | 1278 { |
1279 if (oap->motion_type == MLINE) | |
1280 { | |
1281 oap->start.col = 0; | |
1282 pos.col = 0; | |
1283 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
1284 if (oap->end.col) | |
1285 --oap->end.col; | |
1286 } | |
1287 else if (!oap->inclusive) | |
1288 dec(&(oap->end)); | |
1289 | |
1528 | 1290 if (pos.lnum == oap->end.lnum) |
1291 did_change = swapchars(oap->op_type, &pos, | |
1292 oap->end.col - pos.col + 1); | |
1293 else | |
1294 for (;;) | |
1295 { | |
1296 did_change |= swapchars(oap->op_type, &pos, | |
1297 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
1298 (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
|
1299 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 1300 break; |
1301 } | |
7 | 1302 if (did_change) |
1303 { | |
1304 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
1305 0L); | |
1306 #ifdef FEAT_NETBEANS_INTG | |
2210 | 1307 if (netbeans_active() && did_change) |
7 | 1308 { |
1309 char_u *ptr; | |
1310 int count; | |
1311 | |
1312 pos = oap->start; | |
1313 while (pos.lnum < oap->end.lnum) | |
1314 { | |
1315 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 1316 count = (int)STRLEN(ptr) - pos.col; |
33 | 1317 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 1318 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 1319 &ptr[pos.col], count); |
7 | 1320 pos.col = 0; |
1321 pos.lnum++; | |
1322 } | |
1323 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
1324 count = oap->end.col - pos.col + 1; | |
33 | 1325 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 1326 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 1327 &ptr[pos.col], count); |
7 | 1328 } |
1329 #endif | |
1330 } | |
1331 } | |
1332 | |
1333 if (!did_change && oap->is_VIsual) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1334 // No change: need to remove the Visual selection |
7 | 1335 redraw_curbuf_later(INVERTED); |
1336 | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
1337 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1338 { |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1339 // Set '[ and '] marks. |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1340 curbuf->b_op_start = oap->start; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1341 curbuf->b_op_end = oap->end; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
1342 } |
7 | 1343 |
1344 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
|
1345 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
|
1346 oap->line_count), oap->line_count); |
7 | 1347 } |
1348 | |
1349 /* | |
1525 | 1350 * Invoke swapchar() on "length" bytes at position "pos". |
1351 * "pos" is advanced to just after the changed characters. | |
1352 * "length" is rounded up to include the whole last multi-byte character. | |
1353 * Also works correctly when the number of bytes changes. | |
1354 * Returns TRUE if some character was changed. | |
1355 */ | |
1356 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1357 swapchars(int op_type, pos_T *pos, int length) |
1525 | 1358 { |
1359 int todo; | |
1360 int did_change = 0; | |
1361 | |
1362 for (todo = length; todo > 0; --todo) | |
1363 { | |
1364 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1365 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1366 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1367 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1368 // we're counting bytes, not characters |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1369 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1370 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
1371 } |
1525 | 1372 did_change |= swapchar(op_type, pos); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1373 if (inc(pos) == -1) // at end of file |
1525 | 1374 break; |
1375 } | |
1376 return did_change; | |
1377 } | |
1378 | |
1379 /* | |
7 | 1380 * If op_type == OP_UPPER: make uppercase, |
1381 * if op_type == OP_LOWER: make lowercase, | |
1382 * if op_type == OP_ROT13: do rot13 encoding, | |
1383 * else swap case of character at 'pos' | |
1384 * returns TRUE when something actually changed. | |
1385 */ | |
1386 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1387 swapchar(int op_type, pos_T *pos) |
7 | 1388 { |
1389 int c; | |
1390 int nc; | |
1391 | |
1392 c = gchar_pos(pos); | |
1393 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1394 // Only do rot13 encoding for ASCII characters. |
7 | 1395 if (c >= 0x80 && op_type == OP_ROT13) |
1396 return FALSE; | |
1397 | |
1525 | 1398 if (op_type == OP_UPPER && c == 0xdf |
1399 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 1400 { |
1401 pos_T sp = curwin->w_cursor; | |
1402 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1403 // Special handling of German sharp s: change to "SS". |
493 | 1404 curwin->w_cursor = *pos; |
1405 del_char(FALSE); | |
1406 ins_char('S'); | |
1407 ins_char('S'); | |
1408 curwin->w_cursor = sp; | |
1409 inc(pos); | |
1410 } | |
1411 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1412 if (enc_dbcs != 0 && c >= 0x100) // No lower/uppercase letter |
7 | 1413 return FALSE; |
1414 nc = c; | |
1415 if (MB_ISLOWER(c)) | |
1416 { | |
1417 if (op_type == OP_ROT13) | |
1418 nc = ROT13(c, 'a'); | |
1419 else if (op_type != OP_LOWER) | |
1420 nc = MB_TOUPPER(c); | |
1421 } | |
1422 else if (MB_ISUPPER(c)) | |
1423 { | |
1424 if (op_type == OP_ROT13) | |
1425 nc = ROT13(c, 'A'); | |
1426 else if (op_type != OP_UPPER) | |
1427 nc = MB_TOLOWER(c); | |
1428 } | |
1429 if (nc != c) | |
1430 { | |
1431 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
1432 { | |
1433 pos_T sp = curwin->w_cursor; | |
1434 | |
1435 curwin->w_cursor = *pos; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1436 // don't use del_char(), it also removes composing chars |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
1437 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 1438 ins_char(nc); |
1439 curwin->w_cursor = sp; | |
1440 } | |
1441 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
|
1442 PBYTE(*pos, nc); |
7 | 1443 return TRUE; |
1444 } | |
1445 return FALSE; | |
1446 } | |
1447 | |
1448 /* | |
1449 * op_insert - Insert and append operators for Visual mode. | |
1450 */ | |
1451 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1452 op_insert(oparg_T *oap, long count1) |
7 | 1453 { |
1454 long ins_len, pre_textlen = 0; | |
1455 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
1456 colnr_T ind_pre = 0, ind_post; |
7 | 1457 struct block_def bd; |
1458 int i; | |
6579 | 1459 pos_T t1; |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1460 pos_T start_insert; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1461 // offset when cursor was moved in insert mode |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1462 int offset = 0; |
7 | 1463 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1464 // edit() changes this - record it for OP_APPEND |
7 | 1465 bd.is_MAX = (curwin->w_curswant == MAXCOL); |
1466 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1467 // vis block is still marked. Get rid of it now. |
7 | 1468 curwin->w_cursor.lnum = oap->start.lnum; |
1469 update_screen(INVERTED); | |
1470 | |
1471 if (oap->block_mode) | |
1472 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1473 // When 'virtualedit' is used, need to insert the extra spaces before |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1474 // doing block_prep(). When only "block" is used, virtual edit is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1475 // already disabled, but still need it when calling |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1476 // coladvance_force(). |
7 | 1477 if (curwin->w_cursor.coladd > 0) |
1478 { | |
1479 int old_ve_flags = ve_flags; | |
1480 | |
1481 ve_flags = VE_ALL; | |
1482 if (u_save_cursor() == FAIL) | |
1483 return; | |
1484 coladvance_force(oap->op_type == OP_APPEND | |
1485 ? oap->end_vcol + 1 : getviscol()); | |
1486 if (oap->op_type == OP_APPEND) | |
1487 --curwin->w_cursor.col; | |
1488 ve_flags = old_ve_flags; | |
1489 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1490 // Get the info about the block before entering the text |
7 | 1491 block_prep(oap, &bd, oap->start.lnum, TRUE); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1492 // Get indent information |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
1493 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 1494 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
|
1495 |
7 | 1496 if (oap->op_type == OP_APPEND) |
1497 firstline += bd.textlen; | |
1498 pre_textlen = (long)STRLEN(firstline); | |
1499 } | |
1500 | |
1501 if (oap->op_type == OP_APPEND) | |
1502 { | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
1503 if (oap->block_mode && curwin->w_cursor.coladd == 0) |
7 | 1504 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1505 // Move the cursor to the character right of the block. |
7 | 1506 curwin->w_set_curswant = TRUE; |
1507 while (*ml_get_cursor() != NUL | |
1508 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
1509 ++curwin->w_cursor.col; | |
1510 if (bd.is_short && !bd.is_MAX) | |
1511 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1512 // First line was too short, make it longer and adjust the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1513 // values in "bd". |
7 | 1514 if (u_save_cursor() == FAIL) |
1515 return; | |
1516 for (i = 0; i < bd.endspaces; ++i) | |
1517 ins_char(' '); | |
1518 bd.textlen += bd.endspaces; | |
1519 } | |
1520 } | |
1521 else | |
1522 { | |
1523 curwin->w_cursor = oap->end; | |
893 | 1524 check_cursor_col(); |
7 | 1525 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1526 // 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
|
1527 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 1528 && oap->start_vcol != oap->end_vcol) |
1529 inc_cursor(); | |
1530 } | |
1531 } | |
1532 | |
6579 | 1533 t1 = oap->start; |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1534 start_insert = curwin->w_cursor; |
10803
065da86ca6d2
patch 8.0.0291: Visual block insertion does not insert in all lines
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
1535 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 1536 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1537 // When a tab was inserted, and the characters in front of the tab |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1538 // have been converted to a tab as well, the column of the cursor |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1539 // might have actually been reduced, so need to adjust here. |
6579 | 1540 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
|
1541 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 1542 oap->start = curbuf->b_op_start_orig; |
1543 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1544 // If user has moved off this line, we don't know what to do, so do |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1545 // nothing. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1546 // Also don't repeat the insert when Insert mode ended with CTRL-C. |
1477 | 1547 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) |
7 | 1548 return; |
1549 | |
1550 if (oap->block_mode) | |
1551 { | |
1552 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
|
1553 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
|
1554 size_t len; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1555 int add; |
7 | 1556 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1557 // If indent kicked in, the firstline might have changed |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1558 // but only do that, if the indent actually increased. |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1559 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1560 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
|
1561 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1562 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1563 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
|
1564 did_indent = TRUE; |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1565 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
1566 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1567 // The user may have moved the cursor before inserting something, try |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1568 // to adjust the block for that. But only do it, if the difference |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1569 // does not come from indent kicking in. |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1570 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
|
1571 && !bd.is_MAX && !did_indent) |
5471 | 1572 { |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1573 int t = getviscol2(curbuf->b_op_start_orig.col, |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1574 curbuf->b_op_start_orig.coladd); |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1575 |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1576 if (!bd.is_MAX) |
5471 | 1577 { |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1578 if (oap->op_type == OP_INSERT |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1579 && oap->start.col + oap->start.coladd |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1580 != curbuf->b_op_start_orig.col |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1581 + curbuf->b_op_start_orig.coladd) |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1582 { |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1583 oap->start.col = curbuf->b_op_start_orig.col; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1584 pre_textlen -= t - oap->start_vcol; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1585 oap->start_vcol = t; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1586 } |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1587 else if (oap->op_type == OP_APPEND |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1588 && oap->end.col + oap->end.coladd |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1589 >= curbuf->b_op_start_orig.col |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1590 + curbuf->b_op_start_orig.coladd) |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1591 { |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1592 oap->start.col = curbuf->b_op_start_orig.col; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1593 // reset pre_textlen to the value of OP_INSERT |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1594 pre_textlen += bd.textlen; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1595 pre_textlen -= t - oap->start_vcol; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1596 oap->start_vcol = t; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1597 oap->op_type = OP_INSERT; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1598 } |
5471 | 1599 } |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1600 else if (bd.is_MAX && oap->op_type == OP_APPEND) |
5471 | 1601 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1602 // reset pre_textlen to the value of OP_INSERT |
5471 | 1603 pre_textlen += bd.textlen; |
6579 | 1604 pre_textlen -= t - oap->start_vcol; |
5471 | 1605 } |
1606 } | |
1607 | |
7 | 1608 /* |
1609 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 1610 * tabs. Get the starting column again and correct the length. |
7 | 1611 * Don't do this when "$" used, end-of-line will have changed. |
1612 */ | |
1613 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
1614 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
1615 { | |
1616 if (oap->op_type == OP_APPEND) | |
1617 { | |
1618 pre_textlen += bd2.textlen - bd.textlen; | |
1619 if (bd2.endspaces) | |
1620 --bd2.textlen; | |
1621 } | |
1622 bd.textcol = bd2.textcol; | |
1623 bd.textlen = bd2.textlen; | |
1624 } | |
1625 | |
1626 /* | |
1627 * Subsequent calls to ml_get() flush the firstline data - take a | |
1628 * copy of the required string. | |
1629 */ | |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1630 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
|
1631 len = STRLEN(firstline); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1632 add = bd.textcol; |
7 | 1633 if (oap->op_type == OP_APPEND) |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1634 { |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1635 add += bd.textlen; |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1636 // account for pressing cursor in insert mode when '$' was used |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1637 if (bd.is_MAX |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1638 && (start_insert.lnum == Insstart.lnum |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1639 && start_insert.col > Insstart.col)) |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1640 { |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1641 offset = (start_insert.col - Insstart.col); |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1642 add -= offset; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1643 if (oap->end_vcol > offset) |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1644 oap->end_vcol -= (offset + 1); |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1645 else |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1646 // moved outside of the visual block, what to do? |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1647 return; |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1648 } |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1649 } |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1650 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
|
1651 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
|
1652 else |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
1653 firstline += add; |
25072
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1654 if (pre_textlen >= 0 && (ins_len = |
bd46322bea66
patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1655 (long)STRLEN(firstline) - pre_textlen - offset) > 0) |
7 | 1656 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20822
diff
changeset
|
1657 ins_text = vim_strnsave(firstline, ins_len); |
7 | 1658 if (ins_text != NULL) |
1659 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1660 // block handled here |
7 | 1661 if (u_save(oap->start.lnum, |
1662 (linenr_T)(oap->end.lnum + 1)) == OK) | |
1663 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
1664 &bd); | |
1665 | |
1666 curwin->w_cursor.col = oap->start.col; | |
1667 check_cursor(); | |
1668 vim_free(ins_text); | |
1669 } | |
1670 } | |
1671 } | |
1672 } | |
1673 | |
1674 /* | |
1675 * op_change - handle a change operation | |
1676 * | |
1677 * return TRUE if edit() returns because of a CTRL-O command | |
1678 */ | |
1679 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1680 op_change(oparg_T *oap) |
7 | 1681 { |
1682 colnr_T l; | |
1683 int retval; | |
1684 long offset; | |
1685 linenr_T linenr; | |
1392 | 1686 long ins_len; |
1687 long pre_textlen = 0; | |
1688 long pre_indent = 0; | |
7 | 1689 char_u *firstline; |
1690 char_u *ins_text, *newp, *oldp; | |
1691 struct block_def bd; | |
1692 | |
1693 l = oap->start.col; | |
1694 if (oap->motion_type == MLINE) | |
1695 { | |
1696 l = 0; | |
1697 #ifdef FEAT_SMARTINDENT | |
1698 if (!p_paste && curbuf->b_p_si | |
1699 # ifdef FEAT_CINDENT | |
1700 && !curbuf->b_p_cin | |
1701 # endif | |
1702 ) | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1703 can_si = TRUE; // It's like opening a new line, do si |
7 | 1704 #endif |
1705 } | |
1706 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1707 // First delete the text in the region. In an empty buffer only need to |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1708 // save for undo |
7 | 1709 if (curbuf->b_ml.ml_flags & ML_EMPTY) |
1710 { | |
1711 if (u_save_cursor() == FAIL) | |
1712 return FALSE; | |
1713 } | |
1714 else if (op_delete(oap) == FAIL) | |
1715 return FALSE; | |
1716 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
1717 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 1718 && !virtual_op) |
1719 inc_cursor(); | |
1720 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1721 // check for still on same line (<CR> in inserted text meaningless) |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1722 // skip blank lines too |
7 | 1723 if (oap->block_mode) |
1724 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1725 // Add spaces before getting the current line length. |
7 | 1726 if (virtual_op && (curwin->w_cursor.coladd > 0 |
1727 || gchar_cursor() == NUL)) | |
1728 coladvance_force(getviscol()); | |
1392 | 1729 firstline = ml_get(oap->start.lnum); |
1730 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
|
1731 pre_indent = (long)getwhitecols(firstline); |
7 | 1732 bd.textcol = curwin->w_cursor.col; |
1733 } | |
1734 | |
1735 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
1736 if (oap->motion_type == MLINE) | |
1737 fix_indent(); | |
1738 #endif | |
1739 | |
1740 retval = edit(NUL, FALSE, (linenr_T)1); | |
1741 | |
1742 /* | |
39 | 1743 * In Visual block mode, handle copying the new text to all lines of the |
7 | 1744 * block. |
1477 | 1745 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 1746 */ |
1477 | 1747 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 1748 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1749 // Auto-indenting may have changed the indent. If the cursor was past |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1750 // the indent, exclude that indent change from the inserted text. |
7 | 1751 firstline = ml_get(oap->start.lnum); |
1403 | 1752 if (bd.textcol > (colnr_T)pre_indent) |
7 | 1753 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
1754 long new_indent = (long)getwhitecols(firstline); |
1392 | 1755 |
1756 pre_textlen += new_indent - pre_indent; | |
1757 bd.textcol += new_indent - pre_indent; | |
1758 } | |
1759 | |
1760 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
1761 if (ins_len > 0) | |
1762 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1763 // Subsequent calls to ml_get() flush the firstline data - take a |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1764 // 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
|
1765 if ((ins_text = alloc(ins_len + 1)) != NULL) |
7 | 1766 { |
419 | 1767 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 1768 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
1769 linenr++) | |
1770 { | |
1771 block_prep(oap, &bd, linenr, TRUE); | |
1772 if (!bd.is_short || virtual_op) | |
1773 { | |
1774 pos_T vpos; | |
1775 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1776 // If the block starts in virtual space, count the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1777 // initial coladd offset as part of "startspaces" |
7 | 1778 if (bd.is_short) |
1779 { | |
1982 | 1780 vpos.lnum = linenr; |
7 | 1781 (void)getvpos(&vpos, oap->start_vcol); |
1782 } | |
1783 else | |
1784 vpos.coladd = 0; | |
1785 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
|
1786 newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); |
7 | 1787 if (newp == NULL) |
1788 continue; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1789 // copy up to block start |
7 | 1790 mch_memmove(newp, oldp, (size_t)bd.textcol); |
1791 offset = bd.textcol; | |
6929 | 1792 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 1793 offset += vpos.coladd; |
1794 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
1795 offset += ins_len; | |
1796 oldp += bd.textcol; | |
1622 | 1797 STRMOVE(newp + offset, oldp); |
7 | 1798 ml_replace(linenr, newp, FALSE); |
1799 } | |
1800 } | |
1801 check_cursor(); | |
1802 | |
1803 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
1804 } | |
1805 vim_free(ins_text); | |
1806 } | |
1807 } | |
1808 | |
1809 return retval; | |
1810 } | |
1811 | |
1812 /* | |
844 | 1813 * When the cursor is on the NUL past the end of the line and it should not be |
1814 * there move it left. | |
1815 */ | |
1816 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1817 adjust_cursor_eol(void) |
844 | 1818 { |
1819 if (curwin->w_cursor.col > 0 | |
1820 && gchar_cursor() == NUL | |
773 | 1821 && (ve_flags & VE_ONEMORE) == 0 |
7 | 1822 && !(restart_edit || (State & INSERT))) |
1823 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1824 // Put the cursor on the last character in the line. |
555 | 1825 dec_cursor(); |
844 | 1826 |
7 | 1827 if (ve_flags == VE_ALL) |
557 | 1828 { |
1829 colnr_T scol, ecol; | |
1830 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1831 // Coladd is set to the width of the last character. |
557 | 1832 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); |
1833 curwin->w_cursor.coladd = ecol - scol + 1; | |
1834 } | |
7 | 1835 } |
1836 } | |
1837 | |
3562 | 1838 /* |
1839 * If "process" is TRUE and the line begins with a comment leader (possibly | |
1840 * after some white space), return a pointer to the text after it. Put a boolean | |
1841 * value indicating whether the line ends with an unclosed comment in | |
1842 * "is_comment". | |
1843 * line - line to be processed, | |
1844 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 1845 * comment, |
3562 | 1846 * include_space - whether to also skip space following the comment leader, |
1847 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 1848 * comment. |
3562 | 1849 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
1850 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1851 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1852 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1853 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1854 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1855 int *is_comment) |
3562 | 1856 { |
1857 char_u *comment_flags = NULL; | |
1858 int lead_len; | |
1859 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
1860 | |
1861 *is_comment = FALSE; | |
1862 if (leader_offset != -1) | |
1863 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1864 // Let's check whether the line ends with an unclosed comment. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1865 // If the last comment leader has COM_END in flags, there's no comment. |
3562 | 1866 while (*comment_flags) |
1867 { | |
1868 if (*comment_flags == COM_END | |
1869 || *comment_flags == ':') | |
1870 break; | |
1871 ++comment_flags; | |
1872 } | |
1873 if (*comment_flags != COM_END) | |
1874 *is_comment = TRUE; | |
1875 } | |
1876 | |
1877 if (process == FALSE) | |
1878 return line; | |
1879 | |
1880 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
1881 | |
1882 if (lead_len == 0) | |
1883 return line; | |
1884 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1885 // Find: |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1886 // - COM_END, |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1887 // - colon, |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1888 // whichever comes first. |
3562 | 1889 while (*comment_flags) |
1890 { | |
3580 | 1891 if (*comment_flags == COM_END |
3562 | 1892 || *comment_flags == ':') |
1893 break; | |
1894 ++comment_flags; | |
1895 } | |
1896 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1897 // If we found a colon, it means that we are not processing a line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1898 // starting with a closing part of a three-part comment. That's good, |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1899 // because we don't want to remove those as this would be annoying. |
3562 | 1900 if (*comment_flags == ':' || *comment_flags == NUL) |
1901 line += lead_len; | |
1902 | |
1903 return line; | |
1904 } | |
1905 | |
7 | 1906 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1907 * 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
|
1908 * When "save_undo" is TRUE save lines for undo first. |
5848 | 1909 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
1910 * leaders should not be removed. | |
1911 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
1912 * to set those marks. | |
7 | 1913 * |
1217 | 1914 * return FAIL for failure, OK otherwise |
7 | 1915 */ |
1916 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1917 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1918 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1919 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1920 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1921 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1922 int setmark) |
7 | 1923 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
1924 char_u *curr = NULL; |
2597 | 1925 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
|
1926 char_u *cend; |
7 | 1927 char_u *newp; |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
1928 size_t newp_len; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
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; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1932 int currsize = 0; // size of the current line |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
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; | |
18763
49b78d6465e5
patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents:
18619
diff
changeset
|
1941 #ifdef FEAT_PROP_POPUP |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
1942 int propcount = 0; // number of props over all joined lines |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
1943 int props_remaining; |
16678
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 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1950 // Allocate an array to store the number of spaces inserted before each |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1951 // line. We will use it to pre-compute the length of the new line and the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
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)); |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
1974 #ifdef FEAT_PROP_POPUP |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
1975 propcount += count_props((linenr_T) (curwin->w_cursor.lnum + t), t > 0); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
1976 #endif |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
1977 if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
5664 | 1978 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1979 // Set the '[ mark. |
5664 | 1980 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; |
1981 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
1982 } | |
3562 | 1983 if (remove_comments) |
1984 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1985 // We don't want to remove the comment leader if the |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
1986 // previous line is not a comment. |
3562 | 1987 if (t > 0 && prev_was_comment) |
1988 { | |
1989 | |
1990 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
1991 &prev_was_comment); | |
3576 | 1992 comments[t] = (int)(new_curr - curr); |
3562 | 1993 curr = new_curr; |
1994 } | |
1995 else | |
1996 curr = skip_comment(curr, FALSE, insert_space, | |
1997 &prev_was_comment); | |
1998 } | |
1999 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2000 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
|
2001 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2002 curr = skipwhite(curr); |
18599
9cbdd58eeeb2
patch 8.1.2293: join adds trailing space when second line is empty
Bram Moolenaar <Bram@vim.org>
parents:
18574
diff
changeset
|
2003 if (*curr != NUL && *curr != ')' |
18914
4c0b420e7327
patch 8.2.0018: :join does not add white space where it should
Bram Moolenaar <Bram@vim.org>
parents:
18882
diff
changeset
|
2004 && sumsize != 0 && endcurr1 != TAB |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2005 && (!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
|
2006 || (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
|
2007 && (!has_format_option(FO_MBYTE_JOIN2) |
20695
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20655
diff
changeset
|
2008 || (mb_ptr2char(curr) < 0x100 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20655
diff
changeset
|
2009 && !(enc_utf8 && utf_eat_space(endcurr1))) |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20655
diff
changeset
|
2010 || (endcurr1 < 0x100 |
cea8ae407452
patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents:
20655
diff
changeset
|
2011 && !(enc_utf8 && utf_eat_space(mb_ptr2char(curr))))) |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2012 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2013 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2014 // don't add a space if the line is ending in a space |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2015 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2016 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2017 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2018 ++spaces[t]; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2019 // extra space when 'joinspaces' set and line ends in '.' |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2020 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2021 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2022 || (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
|
2023 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2024 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2025 } |
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 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2028 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2029 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2030 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
|
2031 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2032 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2033 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2034 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2035 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
|
2036 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2037 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2038 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2039 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
|
2040 endcurr2 = (*mb_ptr2char)(cend); |
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 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2044 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2045 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2046 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2047 endcurr2 = *(curr + currsize - 2); |
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 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2051 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2052 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2053 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2054 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2055 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2056 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2057 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2058 // store the column position before last line |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2059 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
|
2060 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2061 // allocate the space for the new line |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2062 newp_len = sumsize + 1; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2063 #ifdef FEAT_PROP_POPUP |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2064 newp_len += propcount * sizeof(textprop_T); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2065 #endif |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2066 newp = alloc(newp_len); |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2067 if (newp == NULL) |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2068 { |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2069 ret = FAIL; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2070 goto theend; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
2071 } |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2072 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2073 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2074 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2075 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2076 * 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
|
2077 * 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
|
2078 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2079 * 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
|
2080 * 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
|
2081 * 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
|
2082 */ |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2083 #ifdef FEAT_PROP_POPUP |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2084 props_remaining = propcount; |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2085 #endif |
2294
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); |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2092 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2093 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2094 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2095 cend -= spaces[t]; |
6929 | 2096 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
|
2097 } |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2098 |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
2099 // 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
|
2100 // 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
|
2101 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
|
2102 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2103 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
|
2104 (long)(cend - newp - spaces_removed), spaces_removed); |
20583
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2105 #ifdef FEAT_PROP_POPUP |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2106 prepend_joined_props(newp + sumsize + 1, propcount, &props_remaining, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2107 curwin->w_cursor.lnum + t, t == count - 1, |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2108 (long)(cend - newp), spaces_removed); |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2109 #endif |
d067be761cd7
patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents:
20237
diff
changeset
|
2110 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2111 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2112 break; |
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 |
20655
707b21559848
patch 8.2.0881: compiler warning for argument type
Bram Moolenaar <Bram@vim.org>
parents:
20613
diff
changeset
|
2121 ml_replace_len(curwin->w_cursor.lnum, newp, (colnr_T)newp_len, TRUE, FALSE); |
7 | 2122 |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
2123 if (setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
5848 | 2124 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2125 // Set the '] mark. |
5848 | 2126 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
|
2127 curwin->w_buffer->b_op_end.col = (colnr_T)sumsize; |
5848 | 2128 } |
5664 | 2129 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2130 // Only report the change in the first line here, del_lines() will report |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2131 // the deleted line. |
7 | 2132 changed_lines(curwin->w_cursor.lnum, currsize, |
2133 curwin->w_cursor.lnum + 1, 0L); | |
2134 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2135 * Delete following lines. To do this we move the cursor there |
7 | 2136 * briefly, and then move it back. After del_lines() the cursor may |
2137 * have moved up (last line deleted), so the current lnum is kept in t. | |
2138 */ | |
2139 t = curwin->w_cursor.lnum; | |
2140 ++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
|
2141 del_lines(count - 1, FALSE); |
7 | 2142 curwin->w_cursor.lnum = t; |
2143 | |
2144 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2145 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2146 * 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
|
2147 * vim: use the column of the last join |
7 | 2148 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2149 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2150 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 2151 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2152 |
7 | 2153 curwin->w_cursor.coladd = 0; |
2154 curwin->w_set_curswant = TRUE; | |
2155 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2156 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2157 vim_free(spaces); |
3562 | 2158 if (remove_comments) |
2159 vim_free(comments); | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
2160 return ret; |
7 | 2161 } |
2162 | |
2163 /* | |
2164 * prepare a few things for block mode yank/delete/tilde | |
2165 * | |
2166 * for delete: | |
2167 * - textlen includes the first/last char to be (partly) deleted | |
2168 * - start/endspaces is the number of columns that are taken by the | |
2169 * first/last deleted char minus the number of columns that have to be | |
1839 | 2170 * deleted. |
2171 * for yank and tilde: | |
7 | 2172 * - textlen includes the first/last char to be wholly yanked |
2173 * - start/endspaces is the number of columns of the first/last yanked char | |
2174 * that are to be yanked. | |
2175 */ | |
18164
f57481564f2c
patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18100
diff
changeset
|
2176 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2177 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2178 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2179 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2180 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2181 int is_del) |
7 | 2182 { |
2183 int incr = 0; | |
2184 char_u *pend; | |
2185 char_u *pstart; | |
2186 char_u *line; | |
2187 char_u *prev_pstart; | |
2188 char_u *prev_pend; | |
19176
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2189 #ifdef FEAT_LINEBREAK |
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2190 int lbr_saved = curwin->w_p_lbr; |
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2191 |
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2192 // Avoid a problem with unwanted linebreaks in block mode. |
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2193 curwin->w_p_lbr = FALSE; |
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2194 #endif |
7 | 2195 bdp->startspaces = 0; |
2196 bdp->endspaces = 0; | |
2197 bdp->textlen = 0; | |
2198 bdp->start_vcol = 0; | |
2199 bdp->end_vcol = 0; | |
2200 bdp->is_short = FALSE; | |
2201 bdp->is_oneChar = FALSE; | |
2202 bdp->pre_whitesp = 0; | |
2203 bdp->pre_whitesp_c = 0; | |
2204 bdp->end_char_vcols = 0; | |
2205 bdp->start_char_vcols = 0; | |
2206 | |
2207 line = ml_get(lnum); | |
2208 pstart = line; | |
2209 prev_pstart = line; | |
2210 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
2211 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2212 // Count a tab for what it's worth (if list mode not on) |
5995 | 2213 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 2214 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
|
2215 if (VIM_ISWHITE(*pstart)) |
7 | 2216 { |
2217 bdp->pre_whitesp += incr; | |
2218 bdp->pre_whitesp_c++; | |
2219 } | |
2220 else | |
2221 { | |
2222 bdp->pre_whitesp = 0; | |
2223 bdp->pre_whitesp_c = 0; | |
2224 } | |
2225 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2226 MB_PTR_ADV(pstart); |
7 | 2227 } |
2228 bdp->start_char_vcols = incr; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2229 if (bdp->start_vcol < oap->start_vcol) // line too short |
7 | 2230 { |
2231 bdp->end_vcol = bdp->start_vcol; | |
2232 bdp->is_short = TRUE; | |
2233 if (!is_del || oap->op_type == OP_APPEND) | |
2234 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
2235 } | |
2236 else | |
2237 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2238 // notice: this converts partly selected Multibyte characters to |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2239 // spaces, too. |
7 | 2240 bdp->startspaces = bdp->start_vcol - oap->start_vcol; |
2241 if (is_del && bdp->startspaces) | |
2242 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
2243 pend = pstart; | |
2244 bdp->end_vcol = bdp->start_vcol; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2245 if (bdp->end_vcol > oap->end_vcol) // it's all in one character |
7 | 2246 { |
2247 bdp->is_oneChar = TRUE; | |
2248 if (oap->op_type == OP_INSERT) | |
2249 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
2250 else if (oap->op_type == OP_APPEND) | |
2251 { | |
2252 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
2253 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
2254 } | |
2255 else | |
2256 { | |
2257 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
2258 if (is_del && oap->op_type != OP_LSHIFT) | |
2259 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2260 // just putting the sum of those two into |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2261 // bdp->startspaces doesn't work for Visual replace, |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2262 // so we have to split the tab in two |
7 | 2263 bdp->startspaces = bdp->start_char_vcols |
2264 - (bdp->start_vcol - oap->start_vcol); | |
2265 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
2266 } | |
2267 } | |
2268 } | |
2269 else | |
2270 { | |
2271 prev_pend = pend; | |
2272 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
2273 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2274 // Count a tab for what it's worth (if list mode not on) |
7 | 2275 prev_pend = pend; |
6535 | 2276 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 2277 bdp->end_vcol += incr; |
2278 } | |
2279 if (bdp->end_vcol <= oap->end_vcol | |
2280 && (!is_del | |
2281 || oap->op_type == OP_APPEND | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2282 || oap->op_type == OP_REPLACE)) // line too short |
7 | 2283 { |
2284 bdp->is_short = TRUE; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2285 // Alternative: include spaces to fill up the block. |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2286 // Disadvantage: can lead to trailing spaces when the line is |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2287 // short where the text is put |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2288 // if (!is_del || oap->op_type == OP_APPEND) |
7 | 2289 if (oap->op_type == OP_APPEND || virtual_op) |
2290 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 2291 + oap->inclusive; |
7 | 2292 else |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2293 bdp->endspaces = 0; // replace doesn't add characters |
7 | 2294 } |
2295 else if (bdp->end_vcol > oap->end_vcol) | |
2296 { | |
2297 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
2298 if (!is_del && bdp->endspaces) | |
2299 { | |
2300 bdp->endspaces = incr - bdp->endspaces; | |
2301 if (pend != pstart) | |
2302 pend = prev_pend; | |
2303 } | |
2304 } | |
2305 } | |
2306 bdp->end_char_vcols = incr; | |
2307 if (is_del && bdp->startspaces) | |
2308 pstart = prev_pstart; | |
2309 bdp->textlen = (int)(pend - pstart); | |
2310 } | |
2311 bdp->textcol = (colnr_T) (pstart - line); | |
2312 bdp->textstart = pstart; | |
19176
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2313 #ifdef FEAT_LINEBREAK |
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2314 curwin->w_p_lbr = lbr_saved; |
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
2315 #endif |
7 | 2316 } |
2317 | |
2318 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2319 * Handle the add/subtract operator. |
7 | 2320 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2321 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2322 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2323 oparg_T *oap, |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2324 linenr_T Prenum1, // Amount of add/subtract |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2325 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
|
2326 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2327 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2328 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2329 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2330 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2331 |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2332 // 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
|
2333 // 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
|
2334 // 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
|
2335 #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
|
2336 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
|
2337 #endif |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2338 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2339 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2340 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2341 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2342 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
|
2343 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2344 #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
|
2345 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
|
2346 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2347 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2348 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2349 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
|
2350 #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
|
2351 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
|
2352 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2353 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2354 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
|
2355 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2356 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2357 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2358 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2359 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2360 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2361 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2362 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
|
2363 (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
|
2364 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2365 #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
|
2366 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
|
2367 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2368 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2369 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2370 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2371 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2372 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
|
2373 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2374 if (oap->block_mode) // Visual block mode |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2375 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2376 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
|
2377 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2378 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2379 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2380 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
|
2381 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2382 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2383 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2384 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
|
2385 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2386 else // oap->motion_type == MCHAR |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2387 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
2388 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
|
2389 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2390 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
|
2391 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2392 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
|
2393 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2394 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2395 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2396 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2397 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2398 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2399 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
|
2400 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2401 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2402 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
|
2403 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2404 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2405 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
|
2406 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2407 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2408 // Remember the start position of the first change. |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2409 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2410 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2411 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2412 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2413 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2414 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2415 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2416 { |
24756
ac7ad168caed
patch 8.2.2916: operators are not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
24665
diff
changeset
|
2417 char_u *ptr; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2418 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2419 netbeans_removed(curbuf, pos.lnum, pos.col, (long)length); |
24756
ac7ad168caed
patch 8.2.2916: operators are not fully tested
Bram Moolenaar <Bram@vim.org>
parents:
24665
diff
changeset
|
2420 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2421 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
|
2422 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2423 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2424 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2425 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2426 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2427 } |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2428 |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
2429 #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
|
2430 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
|
2431 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2432 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2433 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
|
2434 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2435 if (!change_cnt && oap->is_VIsual) |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2436 // No change: need to remove the Visual selection |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2437 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2438 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2439 // Set '[ mark if something changed. Keep the last end |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2440 // position from do_addsub(). |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
2441 if (change_cnt > 0 && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2442 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2443 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2444 if (change_cnt > p_report) |
19760
9daed26b788b
patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents:
19665
diff
changeset
|
2445 smsg(NGETTEXT("%d line changed", "%d lines changed", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2446 change_cnt), change_cnt); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2447 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2448 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2449 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2450 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2451 * 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
|
2452 * 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
|
2453 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2454 * 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
|
2455 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2456 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2457 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2458 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2459 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2460 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2461 linenr_T Prenum1) |
7 | 2462 { |
2463 int col; | |
2464 char_u *buf1; | |
2465 char_u buf2[NUMBUFLEN]; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2466 int pre; // 'X'/'x': hex; '0': octal; 'B'/'b': bin |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2467 static int hexupper = FALSE; // 0xABC |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2468 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2469 uvarnumber_T oldn; |
7 | 2470 char_u *ptr; |
2471 int c; | |
2472 int todel; | |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2473 int do_hex; |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2474 int do_oct; |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2475 int do_bin; |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2476 int do_alpha; |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2477 int do_unsigned; |
7 | 2478 int firstdigit; |
2479 int subtract; | |
6868 | 2480 int negative = FALSE; |
6891 | 2481 int was_positive = TRUE; |
6868 | 2482 int visual = VIsual_active; |
6921 | 2483 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2484 pos_T save_cursor = curwin->w_cursor; |
6927 | 2485 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
2486 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
2487 pos_T endpos; |
20822
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2488 colnr_T save_coladd = 0; |
7 | 2489 |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2490 do_hex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2491 do_oct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2492 do_bin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin" |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2493 do_alpha = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha" |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2494 do_unsigned = (vim_strchr(curbuf->b_p_nf, 'u') != NULL); // "Unsigned" |
7 | 2495 |
20822
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2496 if (virtual_active()) |
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2497 { |
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2498 save_coladd = pos->coladd; |
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2499 pos->coladd = 0; |
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2500 } |
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2501 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2502 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2503 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2504 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2505 |
20822
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2506 if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2507 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2508 |
7 | 2509 /* |
2510 * First check if we are on a hexadecimal number, after the "0x". | |
2511 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2512 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2513 { |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2514 if (do_bin) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2515 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
|
2516 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2517 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2518 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2519 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
|
2520 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2521 |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2522 if (do_hex) |
6868 | 2523 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
|
2524 { |
6868 | 2525 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2526 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2527 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
|
2528 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2529 |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2530 if ( do_bin |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2531 && do_hex |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2532 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2533 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2534 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2535 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2536 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2537 !(*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
|
2538 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2539 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2540 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2541 // In case of binary/hexadecimal pattern overlap match, rescan |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2542 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2543 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2544 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2545 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
|
2546 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2547 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2548 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2549 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
|
2550 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2551 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2552 |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2553 if (( do_hex |
6868 | 2554 && col > 0 |
2555 && (ptr[col] == 'X' | |
2556 || ptr[col] == 'x') | |
2557 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2558 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2559 !(*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
|
2560 && vim_isxdigit(ptr[col + 1])) || |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2561 ( do_bin |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2562 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2563 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2564 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
2565 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2566 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2567 !(*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
|
2568 && vim_isbdigit(ptr[col + 1]))) |
6868 | 2569 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2570 // Found hexadecimal or binary number, move to its start. |
7 | 2571 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2572 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2573 col -= (*mb_head_off)(ptr, ptr + col); |
6868 | 2574 } |
2575 else | |
7 | 2576 { |
6868 | 2577 /* |
2578 * Search forward and then backward to find the start of number. | |
2579 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2580 col = pos->col; |
6868 | 2581 |
2582 while (ptr[col] != NUL | |
2583 && !vim_isdigit(ptr[col]) | |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2584 && !(do_alpha && 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
|
2585 col += mb_ptr2len(ptr + col); |
6868 | 2586 |
2587 while (col > 0 | |
2588 && vim_isdigit(ptr[col - 1]) | |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2589 && !(do_alpha && ASCII_ISALPHA(ptr[col]))) |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2590 { |
6868 | 2591 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2592 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2593 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
|
2594 } |
6868 | 2595 } |
2596 } | |
2597 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2598 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2599 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2600 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2601 && !vim_isdigit(ptr[col]) |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2602 && !(do_alpha && ASCII_ISALPHA(ptr[col]))) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2603 { |
18251
c8a53c0daeed
patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents:
18219
diff
changeset
|
2604 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
|
2605 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2606 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2607 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2608 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2609 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2610 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2611 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2612 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2613 if (col > pos->col && ptr[col - 1] == '-' |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2614 && (!has_mbyte || !(*mb_head_off)(ptr, ptr + col - 1)) |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2615 && !do_unsigned) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2616 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2617 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2618 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2619 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2620 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2621 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2622 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2623 * 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
|
2624 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2625 firstdigit = ptr[col]; |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2626 if (!VIM_ISDIGIT(firstdigit) && !(do_alpha && ASCII_ISALPHA(firstdigit))) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2627 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2628 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2629 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2630 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2631 |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2632 if (do_alpha && ASCII_ISALPHA(firstdigit)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2633 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2634 // decrement or increment alphabetic character |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2635 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2636 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2637 if (CharOrd(firstdigit) < Prenum1) |
6927 | 2638 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2639 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2640 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2641 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2642 firstdigit = 'a'; |
6927 | 2643 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2644 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2645 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2646 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2647 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2648 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2649 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2650 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2651 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2652 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2653 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 2654 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2655 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2656 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2657 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2658 firstdigit = 'z'; |
6927 | 2659 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2660 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2661 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2662 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2663 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2664 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2665 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2666 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2667 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2668 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2669 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2670 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2671 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2672 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2673 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2674 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2675 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2676 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2677 { |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2678 pos_T save_pos; |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2679 int i; |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2680 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2681 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2682 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
2683 !(*mb_head_off)(ptr, ptr + col - 1)) |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2684 && !visual |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2685 && !do_unsigned) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2686 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2687 // negative number |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2688 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2689 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2690 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2691 // get the number value (unsigned) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2692 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2693 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
|
2694 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2695 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2696 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2697 vim_str2nr(ptr + col, &pre, &length, |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2698 0 + (do_bin ? STR2NR_BIN : 0) |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2699 + (do_oct ? STR2NR_OCT : 0) |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2700 + (do_hex ? 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
|
2701 NULL, &n, maxlen, FALSE); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2702 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2703 // ignore leading '-' for hex and octal and bin numbers |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2704 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2705 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2706 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2707 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2708 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2709 } |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2710 // add or subtract |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2711 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2712 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2713 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2714 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2715 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2716 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2717 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2718 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2719 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2720 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2721 n += (uvarnumber_T)Prenum1; |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2722 // handle wraparound for decimal numbers |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2723 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2724 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2725 if (subtract) |
6927 | 2726 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2727 if (n > oldn) |
6868 | 2728 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2729 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
|
2730 negative ^= TRUE; |
6868 | 2731 } |
7 | 2732 } |
2733 else | |
6868 | 2734 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2735 // add |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2736 if (n < oldn) |
6868 | 2737 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2738 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2739 negative ^= TRUE; |
6868 | 2740 } |
6927 | 2741 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2742 if (n == 0) |
6868 | 2743 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2744 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2745 |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2746 if (do_unsigned && negative) |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2747 { |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2748 if (subtract) |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2749 // sticking at zero. |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2750 n = (uvarnumber_T)0; |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2751 else |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2752 // sticking at 2^64 - 1. |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2753 n = (uvarnumber_T)(-1); |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2754 negative = FALSE; |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2755 } |
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2756 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2757 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
|
2758 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2759 // need to remove the '-' |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2760 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2761 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2762 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2763 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2764 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2765 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2766 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2767 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2768 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2769 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2770 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2771 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2772 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2773 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2774 * 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
|
2775 * 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
|
2776 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2777 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2778 --length; |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2779 |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2780 save_pos = curwin->w_cursor; |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2781 for (i = 0; i < todel; ++i) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2782 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2783 if (c < 0x100 && isalpha(c)) |
6868 | 2784 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2785 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2786 hexupper = TRUE; |
6868 | 2787 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2788 hexupper = FALSE; |
6891 | 2789 } |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2790 inc_cursor(); |
6868 | 2791 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2792 } |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2793 curwin->w_cursor = save_pos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2794 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2795 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2796 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2797 * 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
|
2798 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2799 */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
2800 buf1 = alloc(length + NUMBUFLEN); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2801 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2802 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2803 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
2804 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2805 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2806 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2807 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2808 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2809 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2810 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2811 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2812 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2813 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2814 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2815 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2816 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2817 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2818 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2819 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2820 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2821 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2822 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2823 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2824 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
|
2825 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2826 // leading zeros |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2827 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2828 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2829 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2830 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2831 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
|
2832 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2833 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2834 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2835 else if (pre == 0) |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
2836 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", (uvarnumber_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2837 else if (pre == '0') |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
2838 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", (uvarnumber_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2839 else if (pre && hexupper) |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
2840 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", (uvarnumber_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2841 else |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
2842 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", (uvarnumber_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2843 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2844 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2845 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2846 * 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
|
2847 * 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
|
2848 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2849 * 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
|
2850 */ |
20613
9edb439adbea
patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents:
20583
diff
changeset
|
2851 if (firstdigit == '0' && !(do_oct && pre == 0)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2852 while (length-- > 0) |
6868 | 2853 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2854 *ptr = NUL; |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2855 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2856 STRCAT(buf1, buf2); |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2857 |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2858 // Insert just after the first character to be removed, so that any |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2859 // text properties will be adjusted. Then delete the old number |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2860 // afterwards. |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2861 save_pos = curwin->w_cursor; |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2862 if (todel > 0) |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2863 inc_cursor(); |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2864 ins_str(buf1); // insert the new number |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2865 vim_free(buf1); |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2866 |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2867 // del_char() will also mark line needing displaying |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2868 if (todel > 0) |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2869 { |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2870 int bytes_after = (int)STRLEN(ml_get_curline()) |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2871 - curwin->w_cursor.col; |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2872 |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2873 // Delete the one character before the insert. |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2874 curwin->w_cursor = save_pos; |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2875 (void)del_char(FALSE); |
22290
9debc021e99e
patch 8.2.1694: compiler warning for loss if data
Bram Moolenaar <Bram@vim.org>
parents:
22282
diff
changeset
|
2876 curwin->w_cursor.col = (colnr_T)(STRLEN(ml_get_curline()) |
9debc021e99e
patch 8.2.1694: compiler warning for loss if data
Bram Moolenaar <Bram@vim.org>
parents:
22282
diff
changeset
|
2877 - bytes_after); |
22278
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2878 --todel; |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2879 } |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2880 while (todel-- > 0) |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2881 (void)del_char(FALSE); |
0416105e103b
patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2882 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2883 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2884 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
|
2885 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2886 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2887 |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
2888 if (did_change && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
2889 { |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2890 // set the '[ and '] marks |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
2891 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
2892 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
2893 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
|
2894 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
2895 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2896 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2897 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2898 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2899 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
2900 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
2901 curwin->w_set_curswant = TRUE; |
20822
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2902 else if (virtual_active()) |
8e5f991db3b4
patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents:
20695
diff
changeset
|
2903 curwin->w_cursor.coladd = save_coladd; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
2904 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
2905 return did_change; |
7 | 2906 } |
2907 | |
2908 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2909 clear_oparg(oparg_T *oap) |
7 | 2910 { |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19774
diff
changeset
|
2911 CLEAR_POINTER(oap); |
7 | 2912 } |
2913 | |
2914 /* | |
161 | 2915 * Count the number of bytes, characters and "words" in a line. |
7 | 2916 * |
2917 * "Words" are counted by looking for boundaries between non-space and | |
2918 * space characters. (it seems to produce results that match 'wc'.) | |
2919 * | |
161 | 2920 * Return value is byte count; word count for the line is added to "*wc". |
2921 * Char count is added to "*cc". | |
7 | 2922 * |
2923 * The function will only examine the first "limit" characters in the | |
2924 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
2925 * case, eol_size will be added to the character count to account for | |
2926 * the size of the EOL character. | |
2927 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2928 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2929 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2930 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2931 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2932 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2933 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2934 int eol_size) |
7 | 2935 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2936 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2937 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2938 varnumber_T chars = 0; |
7 | 2939 int is_word = 0; |
2940 | |
3626 | 2941 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 2942 { |
2943 if (is_word) | |
2944 { | |
2945 if (vim_isspace(line[i])) | |
2946 { | |
2947 words++; | |
2948 is_word = 0; | |
2949 } | |
2950 } | |
2951 else if (!vim_isspace(line[i])) | |
2952 is_word = 1; | |
161 | 2953 ++chars; |
474 | 2954 i += (*mb_ptr2len)(line + i); |
7 | 2955 } |
2956 | |
2957 if (is_word) | |
2958 words++; | |
2959 *wc += words; | |
2960 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
2961 // Add eol_size if the end of line was reached before hitting limit. |
2996 | 2962 if (i < limit && line[i] == NUL) |
161 | 2963 { |
7 | 2964 i += eol_size; |
161 | 2965 chars += eol_size; |
2966 } | |
2967 *cc += chars; | |
7 | 2968 return i; |
2969 } | |
2970 | |
2971 /* | |
2972 * Give some info about the position of the cursor (for "g CTRL-G"). | |
2973 * In Visual mode, give some info about the selected region. (In this case, | |
2974 * 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
|
2975 * When "dict" is not NULL store the info there instead of showing it. |
7 | 2976 */ |
2977 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2978 cursor_pos_info(dict_T *dict) |
7 | 2979 { |
2980 char_u *p; | |
274 | 2981 char_u buf1[50]; |
2982 char_u buf2[40]; | |
7 | 2983 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2984 varnumber_T byte_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2985 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2986 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2987 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2988 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2989 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2990 varnumber_T word_count_cursor = 0; |
7 | 2991 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
2992 varnumber_T last_check = 100000L; |
7 | 2993 long line_count_selected = 0; |
2994 pos_T min_pos, max_pos; | |
2995 oparg_T oparg; | |
2996 struct block_def bd; | |
2997 | |
2998 /* | |
2999 * Compute the length of the file in characters. | |
3000 */ | |
3001 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
3002 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3003 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3004 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3005 msg(_(no_lines_msg)); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3006 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3007 } |
7 | 3008 } |
3009 else | |
3010 { | |
3011 if (get_fileformat(curbuf) == EOL_DOS) | |
3012 eol_size = 2; | |
3013 else | |
3014 eol_size = 1; | |
3015 | |
3016 if (VIsual_active) | |
3017 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
3018 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 3019 { |
3020 min_pos = VIsual; | |
3021 max_pos = curwin->w_cursor; | |
3022 } | |
3023 else | |
3024 { | |
3025 min_pos = curwin->w_cursor; | |
3026 max_pos = VIsual; | |
3027 } | |
3028 if (*p_sel == 'e' && max_pos.col > 0) | |
3029 --max_pos.col; | |
3030 | |
3031 if (VIsual_mode == Ctrl_V) | |
3032 { | |
1866 | 3033 #ifdef FEAT_LINEBREAK |
3034 char_u * saved_sbr = p_sbr; | |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18481
diff
changeset
|
3035 char_u * saved_w_sbr = curwin->w_p_sbr; |
1866 | 3036 |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3037 // Make 'sbr' empty for a moment to get the correct size. |
1866 | 3038 p_sbr = empty_option; |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18481
diff
changeset
|
3039 curwin->w_p_sbr = empty_option; |
1866 | 3040 #endif |
7 | 3041 oparg.is_VIsual = 1; |
3042 oparg.block_mode = TRUE; | |
3043 oparg.op_type = OP_NOP; | |
3044 getvcols(curwin, &min_pos, &max_pos, | |
688 | 3045 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 3046 #ifdef FEAT_LINEBREAK |
3047 p_sbr = saved_sbr; | |
18574
8b0114ffde2b
patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents:
18481
diff
changeset
|
3048 curwin->w_p_sbr = saved_w_sbr; |
1866 | 3049 #endif |
688 | 3050 if (curwin->w_curswant == MAXCOL) |
3051 oparg.end_vcol = MAXCOL; | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3052 // Swap the start, end vcol if needed |
7 | 3053 if (oparg.end_vcol < oparg.start_vcol) |
3054 { | |
3055 oparg.end_vcol += oparg.start_vcol; | |
3056 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
3057 oparg.end_vcol -= oparg.start_vcol; | |
3058 } | |
3059 } | |
3060 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
3061 } | |
3062 | |
3063 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
3064 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3065 // Check for a CTRL-C every 100000 characters. |
161 | 3066 if (byte_count > last_check) |
7 | 3067 { |
3068 ui_breakcheck(); | |
3069 if (got_int) | |
3070 return; | |
161 | 3071 last_check = byte_count + 100000L; |
7 | 3072 } |
3073 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3074 // Do extra processing for VIsual mode. |
7 | 3075 if (VIsual_active |
3076 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
3077 { | |
45 | 3078 char_u *s = NULL; |
3079 long len = 0L; | |
3080 | |
7 | 3081 switch (VIsual_mode) |
3082 { | |
3083 case Ctrl_V: | |
3084 virtual_op = virtual_active(); | |
3085 block_prep(&oparg, &bd, lnum, 0); | |
3086 virtual_op = MAYBE; | |
45 | 3087 s = bd.textstart; |
3088 len = (long)bd.textlen; | |
7 | 3089 break; |
3090 case 'V': | |
45 | 3091 s = ml_get(lnum); |
3092 len = MAXCOL; | |
7 | 3093 break; |
3094 case 'v': | |
3095 { | |
3096 colnr_T start_col = (lnum == min_pos.lnum) | |
3097 ? min_pos.col : 0; | |
3098 colnr_T end_col = (lnum == max_pos.lnum) | |
3099 ? max_pos.col - start_col + 1 : MAXCOL; | |
3100 | |
45 | 3101 s = ml_get(lnum) + start_col; |
3102 len = end_col; | |
7 | 3103 } |
3104 break; | |
3105 } | |
45 | 3106 if (s != NULL) |
3107 { | |
161 | 3108 byte_count_cursor += line_count_info(s, &word_count_cursor, |
3109 &char_count_cursor, len, eol_size); | |
45 | 3110 if (lnum == curbuf->b_ml.ml_line_count |
3111 && !curbuf->b_p_eol | |
6933 | 3112 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 3113 && (long)STRLEN(s) < len) |
161 | 3114 byte_count_cursor -= eol_size; |
45 | 3115 } |
7 | 3116 } |
3117 else | |
3118 { | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3119 // In non-visual mode, check for the line the cursor is on |
7 | 3120 if (lnum == curwin->w_cursor.lnum) |
3121 { | |
3122 word_count_cursor += word_count; | |
161 | 3123 char_count_cursor += char_count; |
3124 byte_count_cursor = byte_count + | |
3125 line_count_info(ml_get(lnum), | |
3126 &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
|
3127 (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
|
3128 eol_size); |
7 | 3129 } |
3130 } | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3131 // Add to the running totals |
161 | 3132 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
|
3133 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3134 eol_size); |
7 | 3135 } |
3136 | |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3137 // Correction for when last line doesn't have an EOL. |
6933 | 3138 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 3139 byte_count -= eol_size; |
7 | 3140 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3141 if (dict == NULL) |
7 | 3142 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3143 if (VIsual_active) |
7 | 3144 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3145 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
|
3146 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3147 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
|
3148 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3149 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
|
3150 (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
|
3151 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3152 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3153 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3154 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3155 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
|
3156 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3157 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3158 _("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
|
3159 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3160 (long)curbuf->b_ml.ml_line_count, |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3161 (varnumber_T)word_count_cursor, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3162 (varnumber_T)word_count, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3163 (varnumber_T)byte_count_cursor, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3164 (varnumber_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3165 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3166 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3167 _("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
|
3168 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3169 (long)curbuf->b_ml.ml_line_count, |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3170 (varnumber_T)word_count_cursor, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3171 (varnumber_T)word_count, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3172 (varnumber_T)char_count_cursor, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3173 (varnumber_T)char_count, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3174 (varnumber_T)byte_count_cursor, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3175 (varnumber_T)byte_count); |
7 | 3176 } |
3177 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3178 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3179 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3180 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3181 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
|
3182 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3183 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
|
3184 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3185 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3186 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
|
3187 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3188 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3189 _("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
|
3190 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3191 (long)curwin->w_cursor.lnum, |
7 | 3192 (long)curbuf->b_ml.ml_line_count, |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3193 (varnumber_T)word_count_cursor, (varnumber_T)word_count, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3194 (varnumber_T)byte_count_cursor, (varnumber_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3195 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3196 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
3197 _("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
|
3198 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3199 (long)curwin->w_cursor.lnum, |
161 | 3200 (long)curbuf->b_ml.ml_line_count, |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3201 (varnumber_T)word_count_cursor, (varnumber_T)word_count, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3202 (varnumber_T)char_count_cursor, (varnumber_T)char_count, |
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3203 (varnumber_T)byte_count_cursor, (varnumber_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3204 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3205 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3206 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3207 bom_count = bomb_size(); |
18062
0b351691071c
patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
17797
diff
changeset
|
3208 if (dict == NULL && bom_count > 0) |
19005
53088656f5ed
patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents:
18914
diff
changeset
|
3209 { |
53088656f5ed
patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents:
18914
diff
changeset
|
3210 size_t len = STRLEN(IObuff); |
53088656f5ed
patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents:
18914
diff
changeset
|
3211 |
53088656f5ed
patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents:
18914
diff
changeset
|
3212 vim_snprintf((char *)IObuff + len, IOSIZE - len, |
19477
2bb0e80fcd32
patch 8.2.0296: mixing up "long long" and __int64 may cause problems
Bram Moolenaar <Bram@vim.org>
parents:
19195
diff
changeset
|
3213 _("(+%lld for BOM)"), (varnumber_T)bom_count); |
19005
53088656f5ed
patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents:
18914
diff
changeset
|
3214 } |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3215 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3216 { |
18062
0b351691071c
patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
17797
diff
changeset
|
3217 // 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
|
3218 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3219 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
|
3220 msg((char *)IObuff); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3221 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3222 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3223 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
3224 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3225 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
3226 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3227 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
|
3228 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
|
3229 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
|
3230 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
|
3231 byte_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3232 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
|
3233 char_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
3234 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
|
3235 word_count_cursor); |
7 | 3236 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
3237 #endif |
7 | 3238 } |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3239 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3240 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3241 * 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
|
3242 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3243 static void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3244 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
|
3245 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3246 stuffcharReadbuff(':'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3247 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
|
3248 stuffReadbuff((char_u *)"'<,'>"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3249 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3250 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3251 // 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
|
3252 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
|
3253 stuffcharReadbuff('.'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3254 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3255 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
|
3256 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
|
3257 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3258 stuffcharReadbuff(','); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3259 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
|
3260 stuffcharReadbuff('.'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3261 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
|
3262 stuffcharReadbuff('$'); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3263 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
|
3264 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3265 stuffReadbuff((char_u *)".+"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3266 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
|
3267 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3268 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3269 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
|
3270 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3271 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3272 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
|
3273 stuffReadbuff((char_u *)"!"); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3274 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
|
3275 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3276 #ifndef FEAT_CINDENT |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3277 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
|
3278 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
|
3279 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3280 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3281 stuffReadbuff(get_equalprg()); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3282 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
|
3283 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3284 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
|
3285 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3286 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
|
3287 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
|
3288 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
|
3289 stuffReadbuff(p_fp); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3290 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3291 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
|
3292 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
|
3293 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3294 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3295 // 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
|
3296 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3297 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3298 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3299 * 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
|
3300 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3301 static void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3302 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
|
3303 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3304 #ifdef FEAT_EVAL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3305 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
|
3306 int save_virtual_op = virtual_op; |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
3307 pos_T orig_start = curbuf->b_op_start; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
3308 pos_T orig_end = curbuf->b_op_end; |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3309 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3310 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
|
3311 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
|
3312 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3313 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3314 // 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
|
3315 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
|
3316 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
|
3317 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
|
3318 // 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
|
3319 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
|
3320 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3321 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
|
3322 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
|
3323 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
|
3324 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
|
3325 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
|
3326 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3327 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
|
3328 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
|
3329 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3330 // 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
|
3331 // function. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3332 virtual_op = MAYBE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3333 |
23281
5b4db8035d1d
patch 8.2.2186: Vim9: error when using 'opfunc'
Bram Moolenaar <Bram@vim.org>
parents:
23241
diff
changeset
|
3334 (void)call_func_noret(p_opfunc, 1, argv); |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3335 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3336 virtual_op = save_virtual_op; |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
22290
diff
changeset
|
3337 if (cmdmod.cmod_flags & CMOD_LOCKMARKS) |
18619
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
3338 { |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
3339 curbuf->b_op_start = orig_start; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
3340 curbuf->b_op_end = orig_end; |
788d76db02ac
patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents:
18599
diff
changeset
|
3341 } |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3342 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3343 #else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3344 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
|
3345 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3346 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3347 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3348 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3349 * 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
|
3350 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3351 static void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3352 get_op_vcol( |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3353 oparg_T *oap, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3354 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
|
3355 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
|
3356 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3357 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
|
3358 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3359 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
|
3360 || (!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
|
3361 return; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3362 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3363 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
|
3364 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3365 // 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
|
3366 if (has_mbyte) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3367 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
|
3368 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3369 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
|
3370 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3371 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
|
3372 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3373 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
|
3374 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3375 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
|
3376 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
|
3377 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
|
3378 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3379 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
|
3380 && 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
|
3381 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
|
3382 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3383 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
|
3384 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3385 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3386 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3387 // 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
|
3388 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
|
3389 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3390 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
|
3391 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
|
3392 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
|
3393 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
|
3394 ++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
|
3395 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3396 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
|
3397 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
|
3398 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
|
3399 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3400 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3401 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
|
3402 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
|
3403 // 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
|
3404 // 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
|
3405 // |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3406 // (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
|
3407 // positions) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3408 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
|
3409 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
|
3410 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
|
3411 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3412 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
|
3413 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
|
3414 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
|
3415 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3416 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3417 /* |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3418 * 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
|
3419 * "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
|
3420 */ |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3421 void |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3422 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
|
3423 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3424 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
|
3425 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
|
3426 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
|
3427 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
|
3428 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3429 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
|
3430 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3431 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3432 // 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
|
3433 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
|
3434 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
|
3435 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
|
3436 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
|
3437 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
|
3438 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
|
3439 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3440 #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
|
3441 // 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
|
3442 // 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
|
3443 // 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
|
3444 // 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
|
3445 // 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
|
3446 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
|
3447 && 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
|
3448 && !gui_yank |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3449 && VIsual_active |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3450 && !redo_VIsual_busy |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3451 && oap->regname == 0) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3452 clip_auto_select(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3453 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3454 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
|
3455 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3456 // 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
|
3457 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
|
3458 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3459 // 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
|
3460 // for the clipboard. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3461 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
|
3462 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3463 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3464 // 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
|
3465 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
|
3466 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
|
3467 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
|
3468 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3469 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
|
3470 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
|
3471 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
|
3472 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
|
3473 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3474 // 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
|
3475 // 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
|
3476 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
|
3477 oap->inclusive = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3478 // 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
|
3479 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
|
3480 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
|
3481 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
|
3482 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3483 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
|
3484 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3485 // 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
|
3486 if (!VIsual_active) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3487 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3488 VIsual_active = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3489 VIsual = oap->start; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3490 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3491 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
|
3492 VIsual_select = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3493 VIsual_reselect = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3494 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3495 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3496 // 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
|
3497 // 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
|
3498 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
|
3499 && ((!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
|
3500 // Also redo Operator-pending Visual mode mappings |
22916
1fe53aae3ba0
patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3501 || (VIsual_active |
1fe53aae3ba0
patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3502 && (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND) |
1fe53aae3ba0
patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3503 && oap->op_type != OP_COLON)) |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3504 && cap->cmdchar != 'D' |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3505 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3506 && 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
|
3507 && 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
|
3508 && 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
|
3509 && 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
|
3510 && 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
|
3511 && 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
|
3512 && 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
|
3513 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3514 ) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3515 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3516 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
|
3517 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
|
3518 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
|
3519 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
|
3520 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3521 // 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
|
3522 // 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
|
3523 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
|
3524 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
|
3525 AppendToRedobuff(NL_STR); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3526 } |
22862
6d50182e7e24
patch 8.2.1978: making a mapping work in all modes is complicated
Bram Moolenaar <Bram@vim.org>
parents:
22699
diff
changeset
|
3527 else if (cap->cmdchar == ':' || cap->cmdchar == K_COMMAND) |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3528 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3529 // 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
|
3530 // "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
|
3531 // 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
|
3532 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
|
3533 ResetRedobuff(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3534 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3535 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3536 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
|
3537 AppendToRedobuff(NL_STR); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3538 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
|
3539 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3540 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3541 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3542 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3543 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
|
3544 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3545 // 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
|
3546 // 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
|
3547 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
|
3548 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
|
3549 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
|
3550 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
|
3551 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
|
3552 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
|
3553 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3554 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
|
3555 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3556 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
|
3557 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3558 validate_virtcol(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3559 curwin->w_curswant = |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3560 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
|
3561 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3562 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3563 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
|
3564 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3565 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3566 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3567 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
|
3568 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3569 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
|
3570 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3571 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
|
3572 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
|
3573 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
|
3574 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3575 cap->count1 = 1; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3576 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3577 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
|
3578 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3579 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3580 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3581 // 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
|
3582 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
|
3583 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
|
3584 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
|
3585 restore_visual_mode(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3586 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
|
3587 # ifdef FEAT_EVAL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3588 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
|
3589 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3590 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3591 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3592 // 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
|
3593 // characterwise selection. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3594 // 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
|
3595 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
|
3596 && 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
|
3597 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3598 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
|
3599 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3600 VIsual.col = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3601 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
|
3602 (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
|
3603 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3604 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3605 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3606 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
|
3607 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
|
3608 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3609 VIsual_mode = 'v'; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3610 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3611 // 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
|
3612 // charwise selections. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3613 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
|
3614 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
|
3615 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3616 oap->start = VIsual; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3617 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
|
3618 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3619 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
|
3620 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
|
3621 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3622 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3623 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3624 // 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
|
3625 // 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
|
3626 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
|
3627 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3628 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3629 // 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
|
3630 if (!VIsual_active) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3631 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3632 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
|
3633 oap->start.col = 0; |
18882
f9e41ffd3539
patch 8.2.0002: "dj" only deletes first line of closed fold
Bram Moolenaar <Bram@vim.org>
parents:
18808
diff
changeset
|
3634 if ((curwin->w_cursor.col > 0 || oap->inclusive |
f9e41ffd3539
patch 8.2.0002: "dj" only deletes first line of closed fold
Bram Moolenaar <Bram@vim.org>
parents:
18808
diff
changeset
|
3635 || oap->motion_type == MLINE) |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3636 && 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
|
3637 &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
|
3638 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
|
3639 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3640 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3641 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
|
3642 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
|
3643 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3644 // 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
|
3645 // 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
|
3646 // automatically. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3647 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
|
3648 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3649 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3650 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3651 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3652 // 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
|
3653 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
|
3654 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3655 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
|
3656 NULL)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3657 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
|
3658 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
|
3659 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
|
3660 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3661 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3662 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
|
3663 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
|
3664 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3665 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3666 // 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
|
3667 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
|
3668 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
|
3669 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3670 // 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
|
3671 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
|
3672 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3673 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
|
3674 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3675 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
|
3676 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3677 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
|
3678 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3679 // 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
|
3680 // 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
|
3681 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
|
3682 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
|
3683 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
|
3684 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3685 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3686 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
|
3687 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
|
3688 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
|
3689 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
|
3690 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3691 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
|
3692 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
|
3693 &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
|
3694 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
|
3695 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3696 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3697 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
|
3698 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3699 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
|
3700 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3701 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3702 // 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
|
3703 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
|
3704 && 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
|
3705 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3706 && 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
|
3707 && 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
|
3708 && 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
|
3709 && 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
|
3710 && 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
|
3711 && 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
|
3712 && 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
|
3713 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3714 && 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
|
3715 ) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3716 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3717 // 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
|
3718 // 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
|
3719 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
|
3720 || cap->nchar == 'N')) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3721 prep_redo(oap->regname, cap->count0, |
18808
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3722 get_op_char(oap->op_type), |
7982f65d8f54
patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18763
diff
changeset
|
3723 get_extra_op_char(oap->op_type), |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3724 oap->motion_force, cap->cmdchar, cap->nchar); |
22916
1fe53aae3ba0
patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Bram Moolenaar <Bram@vim.org>
parents:
22862
diff
changeset
|
3725 else if (cap->cmdchar != ':' && cap->cmdchar != K_COMMAND) |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3726 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3727 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
|
3728 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3729 // 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
|
3730 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
|
3731 nchar = CAR; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3732 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
|
3733 nchar = NL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3734 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
|
3735 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
|
3736 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
|
3737 nchar); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3738 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3739 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
|
3740 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3741 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
|
3742 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
|
3743 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
|
3744 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
|
3745 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
|
3746 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3747 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3748 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3749 // 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
|
3750 // 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
|
3751 // 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
|
3752 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
|
3753 oap->inclusive = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3754 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
|
3755 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
|
3756 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3757 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3758 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
|
3759 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
|
3760 && (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
|
3761 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3762 oap->inclusive = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3763 // 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
|
3764 // 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
|
3765 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
|
3766 && !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
|
3767 && 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
|
3768 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3769 ++oap->end.lnum; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3770 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
|
3771 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
|
3772 ++oap->line_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3773 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3774 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3775 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3776 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3777 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
|
3778 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3779 // 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
|
3780 // 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
|
3781 // 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
|
3782 // 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
|
3783 // part. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3784 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3785 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3786 VIsual_active = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3787 setmouse(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3788 mouse_dragging = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3789 may_clear_cmdline(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3790 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
|
3791 || 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
|
3792 || 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
|
3793 || 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
|
3794 && 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
|
3795 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3796 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3797 // 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
|
3798 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
|
3799 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3800 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
|
3801 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3802 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3803 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3804 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3805 // 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
|
3806 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
|
3807 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3808 int l; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3809 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3810 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
|
3811 if (l > 1) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3812 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
|
3813 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3814 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
|
3815 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3816 // 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
|
3817 // 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
|
3818 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
|
3819 && (!oap->inclusive |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3820 || (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
|
3821 && 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
|
3822 && 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
|
3823 && !(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
|
3824 // 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
|
3825 // 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
|
3826 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
|
3827 && 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
|
3828 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3829 // 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
|
3830 // '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
|
3831 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
|
3832 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3833 || 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
|
3834 #endif |
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 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3837 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3838 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
|
3839 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3840 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
|
3841 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3842 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3843 // 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
|
3844 // 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
|
3845 // 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
|
3846 // 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
|
3847 // (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
|
3848 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
|
3849 && oap->inclusive == FALSE |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3850 && !(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
|
3851 && 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
|
3852 && (!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
|
3853 && !oap->block_mode |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3854 && 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
|
3855 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3856 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
|
3857 --oap->line_count; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3858 --oap->end.lnum; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3859 if (inindent(0)) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3860 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
|
3861 else |
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 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
|
3864 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
|
3865 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3866 --oap->end.col; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3867 oap->inclusive = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3868 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3869 } |
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 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3872 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
|
3873 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3874 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
|
3875 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3876 case OP_LSHIFT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3877 case OP_RSHIFT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3878 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
|
3879 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
|
3880 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3881 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3882 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
|
3883 case OP_JOIN: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3884 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
|
3885 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
|
3886 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
|
3887 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
|
3888 beep_flush(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3889 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3890 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3891 (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
|
3892 TRUE, TRUE, TRUE); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3893 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
|
3894 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3895 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3896 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3897 case OP_DELETE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3898 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
|
3899 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
|
3900 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3901 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
|
3902 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3903 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3904 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3905 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3906 (void)op_delete(oap); |
22965
473a1413d09b
patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3907 // save cursor line for undo if it wasn't saved yet |
473a1413d09b
patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3908 if (oap->motion_type == MLINE && has_format_option(FO_AUTO) |
473a1413d09b
patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3909 && u_save_cursor() == OK) |
473a1413d09b
patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents:
22916
diff
changeset
|
3910 auto_format(FALSE, TRUE); |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3911 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3912 break; |
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 case OP_YANK: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3915 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
|
3916 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3917 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3918 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3919 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
|
3920 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3921 } |
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 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3924 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3925 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3926 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
|
3927 #endif |
24866
f1121eb17e14
patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents:
24768
diff
changeset
|
3928 oap->excl_tr_ws = cap->cmdchar == 'z'; |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3929 (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
|
3930 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3931 check_cursor_col(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3932 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3933 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3934 case OP_CHANGE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3935 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
|
3936 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
|
3937 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3938 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
|
3939 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3940 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3941 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3942 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3943 // 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
|
3944 // 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
|
3945 // 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
|
3946 // '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
|
3947 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
|
3948 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
|
3949 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3950 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
|
3951 restart_edit = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3952 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3953 // 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
|
3954 // before. |
19176
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
3955 curwin->w_p_lbr = lbr_saved; |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3956 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3957 // 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
|
3958 finish_op = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3959 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
|
3960 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
|
3961 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
|
3962 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
|
3963 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3964 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3965 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3966 case OP_FILTER: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3967 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
|
3968 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
|
3969 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3970 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
|
3971 // FALLTHROUGH |
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 case OP_INDENT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3974 case OP_COLON: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3975 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3976 #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
|
3977 // 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
|
3978 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
|
3979 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3980 # ifdef FEAT_LISP |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3981 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
|
3982 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3983 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
|
3984 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3985 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3986 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3987 # ifdef FEAT_CINDENT |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3988 op_reindent(oap, |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3989 # ifdef FEAT_EVAL |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3990 *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
|
3991 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3992 get_c_indent); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3993 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3994 # endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3995 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3996 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3997 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3998 op_colon(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
3999 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4000 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4001 case OP_TILDE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4002 case OP_UPPER: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4003 case OP_LOWER: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4004 case OP_ROT13: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4005 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
|
4006 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4007 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
|
4008 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4009 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4010 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4011 op_tilde(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4012 check_cursor_col(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4013 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4014 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4015 case OP_FORMAT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4016 #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
|
4017 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
|
4018 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
|
4019 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4020 #endif |
24665
661d15592d3c
patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents:
23287
diff
changeset
|
4021 { |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4022 if (*p_fp != NUL || *curbuf->b_p_fp != NUL) |
24665
661d15592d3c
patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents:
23287
diff
changeset
|
4023 op_colon(oap); // use external command |
661d15592d3c
patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents:
23287
diff
changeset
|
4024 else |
661d15592d3c
patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents:
23287
diff
changeset
|
4025 op_format(oap, FALSE); // use internal function |
661d15592d3c
patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents:
23287
diff
changeset
|
4026 } |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4027 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4028 case OP_FORMAT2: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4029 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
|
4030 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4031 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4032 case OP_FUNCTION: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4033 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4034 // 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
|
4035 // before. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4036 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
|
4037 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4038 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
|
4039 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4040 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4041 case OP_INSERT: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4042 case OP_APPEND: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4043 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
|
4044 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
|
4045 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4046 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
|
4047 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4048 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4049 else |
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 // 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
|
4052 // 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
|
4053 // 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
|
4054 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
|
4055 restart_edit = 0; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4056 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4057 // 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
|
4058 // before. |
19176
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
4059 curwin->w_p_lbr = lbr_saved; |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4060 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4061 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
|
4062 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4063 // 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
|
4064 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
|
4065 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4066 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4067 // 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
|
4068 // the lines. |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4069 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
|
4070 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4071 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
|
4072 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
|
4073 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4074 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
|
4075 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4076 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4077 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4078 case OP_REPLACE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4079 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
|
4080 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
|
4081 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4082 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
|
4083 CancelRedo(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4084 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4085 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4086 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4087 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4088 // 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
|
4089 // before. |
19176
be81baeb69f8
patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents:
19005
diff
changeset
|
4090 curwin->w_p_lbr = lbr_saved; |
18219
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4091 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4092 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
|
4093 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4094 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4095 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4096 #ifdef FEAT_FOLDING |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4097 case OP_FOLD: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4098 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
|
4099 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
|
4100 break; |
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 case OP_FOLDOPEN: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4103 case OP_FOLDOPENREC: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4104 case OP_FOLDCLOSE: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4105 case OP_FOLDCLOSEREC: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4106 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
|
4107 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
|
4108 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
|
4109 || 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
|
4110 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
|
4111 || 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
|
4112 oap->is_VIsual); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4113 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4114 |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4115 case OP_FOLDDEL: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4116 case OP_FOLDDELREC: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4117 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
|
4118 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
|
4119 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
|
4120 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4121 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4122 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
|
4123 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
|
4124 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
|
4125 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4126 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
|
4127 CancelRedo(); |
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 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4130 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4131 VIsual_active = TRUE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4132 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4133 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
|
4134 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4135 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
|
4136 VIsual_active = FALSE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4137 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4138 check_cursor_col(); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4139 break; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4140 default: |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4141 clearopbeep(oap); |
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 virtual_op = MAYBE; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4144 if (!gui_yank) |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4145 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4146 // 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
|
4147 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
|
4148 && (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
|
4149 || 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
|
4150 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4151 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4152 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
|
4153 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4154 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
|
4155 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4156 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4157 else |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4158 { |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4159 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
|
4160 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4161 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
|
4162 clearop(oap); |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4163 motion_force = NUL; |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4164 } |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4165 #ifdef FEAT_LINEBREAK |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4166 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
|
4167 #endif |
5d67f207f7c3
patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18203
diff
changeset
|
4168 } |