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