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