annotate src/ops.c @ 29247:5f314b2ed494 v8.2.5142

patch 8.2.5142: startup test fails if there is a status bar Commit: https://github.com/vim/vim/commit/fa04eae5a5b9394079bde2d37ce6f9f8a5567d48 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 21 14:38:40 2022 +0100 patch 8.2.5142: startup test fails if there is a status bar Problem: Startup test fails if there is a status bar at the top of the screen. (Ernie Rael) Solution: Use a larger vertical offset in the test.
author Bram Moolenaar <Bram@vim.org>
date Tue, 21 Jun 2022 18:45:07 +0200
parents 6cdf55afaae9
children fba9e366ced4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 * ops.c: implementation of various operators: op_shift, op_delete, op_tilde,
23287
f2a70fca3485 patch 8.2.2189: cannot repeat a command that uses the small delete register
Bram Moolenaar <Bram@vim.org>
parents: 23281
diff changeset
12 * op_change, op_yank, do_join
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 #include "vim.h"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7576
diff changeset
17 static void shift_block(oparg_T *oap, int amount);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7576
diff changeset
18 static void mb_adjust_opend(oparg_T *oap);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7576
diff changeset
19 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
21 // Flags for third item in "opchars".
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
22 #define OPF_LINES 1 // operator always works on lines
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
23 #define OPF_CHANGE 2 // operator changes text
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
24
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 * The names of operators.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 * IMPORTANT: Index must correspond with defines in vim.h!!!
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
28 * The third field holds OPF_ flags.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 static char opchars[][3] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 {
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
32 {NUL, NUL, 0}, // OP_NOP
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
33 {'d', NUL, OPF_CHANGE}, // OP_DELETE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
34 {'y', NUL, 0}, // OP_YANK
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
35 {'c', NUL, OPF_CHANGE}, // OP_CHANGE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
36 {'<', NUL, OPF_LINES | OPF_CHANGE}, // OP_LSHIFT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
37 {'>', NUL, OPF_LINES | OPF_CHANGE}, // OP_RSHIFT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
38 {'!', NUL, OPF_LINES | OPF_CHANGE}, // OP_FILTER
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
39 {'g', '~', OPF_CHANGE}, // OP_TILDE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
40 {'=', NUL, OPF_LINES | OPF_CHANGE}, // OP_INDENT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
41 {'g', 'q', OPF_LINES | OPF_CHANGE}, // OP_FORMAT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
42 {':', NUL, OPF_LINES}, // OP_COLON
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
43 {'g', 'U', OPF_CHANGE}, // OP_UPPER
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
44 {'g', 'u', OPF_CHANGE}, // OP_LOWER
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
45 {'J', NUL, OPF_LINES | OPF_CHANGE}, // DO_JOIN
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
46 {'g', 'J', OPF_LINES | OPF_CHANGE}, // DO_JOIN_NS
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
47 {'g', '?', OPF_CHANGE}, // OP_ROT13
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
48 {'r', NUL, OPF_CHANGE}, // OP_REPLACE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
49 {'I', NUL, OPF_CHANGE}, // OP_INSERT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
50 {'A', NUL, OPF_CHANGE}, // OP_APPEND
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
51 {'z', 'f', OPF_LINES}, // OP_FOLD
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
52 {'z', 'o', OPF_LINES}, // OP_FOLDOPEN
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
53 {'z', 'O', OPF_LINES}, // OP_FOLDOPENREC
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
54 {'z', 'c', OPF_LINES}, // OP_FOLDCLOSE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
55 {'z', 'C', OPF_LINES}, // OP_FOLDCLOSEREC
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
56 {'z', 'd', OPF_LINES}, // OP_FOLDDEL
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
57 {'z', 'D', OPF_LINES}, // OP_FOLDDELREC
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
58 {'g', 'w', OPF_LINES | OPF_CHANGE}, // OP_FORMAT2
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
59 {'g', '@', OPF_CHANGE}, // OP_FUNCTION
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
60 {Ctrl_A, NUL, OPF_CHANGE}, // OP_NR_ADD
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
61 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 * Translate a command name into an operator type.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 * Must only be called with a valid operator name!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
69 get_op_type(int char1, int char2)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
73 if (char1 == 'r') // ignore second character
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 return OP_REPLACE;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
75 if (char1 == '~') // when tilde is an operator
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 return OP_TILDE;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
77 if (char1 == 'g' && char2 == Ctrl_A) // add
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
78 return OP_NR_ADD;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
79 if (char1 == 'g' && char2 == Ctrl_X) // subtract
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
80 return OP_NR_SUB;
24866
f1121eb17e14 patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
81 if (char1 == 'z' && char2 == 'y') // OP_YANK
f1121eb17e14 patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
82 return OP_YANK;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 for (i = 0; ; ++i)
13072
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
84 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 if (opchars[i][0] == char1 && opchars[i][1] == char2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 break;
24768
7334bf933510 patch 8.2.2922: computing array length is done in various ways
Bram Moolenaar <Bram@vim.org>
parents: 24756
diff changeset
87 if (i == (int)ARRAY_LENGTH(opchars) - 1)
13072
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
88 {
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
89 internal_error("get_op_type()");
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
90 break;
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
91 }
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
92 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 * Return TRUE if operator "op" always works on whole lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 */
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
99 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
100 op_on_lines(int op)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 {
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
102 return opchars[op][2] & OPF_LINES;
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
103 }
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
104
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
105 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO)
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
106 /*
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
107 * Return TRUE if operator "op" changes text.
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
108 */
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
109 int
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
110 op_is_change(int op)
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
111 {
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
112 return opchars[op][2] & OPF_CHANGE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113 }
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
114 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
117 * Get first operator command character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118 * Returns 'g' or 'z' if there is another command character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
121 get_op_char(int optype)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 return opchars[optype][0];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 * Get second operator command character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
130 get_extra_op_char(int optype)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 return opchars[optype][1];
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 * op_shift - handle a shift operation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
139 op_shift(oparg_T *oap, int curs_top, int amount)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 long i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 int first_char;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 int block_col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 block_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 for (i = oap->line_count; --i >= 0; )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 first_char = *ml_get_curline();
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
155 if (first_char == NUL) // empty line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 else if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 shift_block(oap, amount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 else
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
160 // Move the line right if it doesn't start with '#', 'smartindent'
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
161 // isn't set or 'cindent' isn't set or '#' isn't in 'cino'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 if (first_char != '#' || !preprocs_left())
28942
6cdf55afaae9 patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents: 28869
diff changeset
163 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 curwin->w_cursor.lnum = oap->start.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 curwin->w_cursor.col = block_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
173 else if (curs_top) // put cursor on first line, for ">>"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 curwin->w_cursor.lnum = oap->start.lnum;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
176 beginline(BL_SOL | BL_FIX); // shift_line() may have set cursor.col
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 else
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
179 --curwin->w_cursor.lnum; // put cursor on last line, for ":>"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180
10486
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
181 #ifdef FEAT_FOLDING
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
182 // The cursor line is not in a closed fold
10486
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
183 foldOpenCursor();
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
184 #endif
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
185
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
186
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 if (oap->line_count > p_report)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 {
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
189 char *op;
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
190 char *msg_line_single;
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
191 char *msg_line_plural;
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
192
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 if (oap->op_type == OP_RSHIFT)
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
194 op = ">";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 else
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
196 op = "<";
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
197 msg_line_single = NGETTEXT("%ld line %sed %d time",
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
198 "%ld line %sed %d times", amount);
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
199 msg_line_plural = NGETTEXT("%ld lines %sed %d time",
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
200 "%ld lines %sed %d times", amount);
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
201 vim_snprintf((char *)IObuff, IOSIZE,
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
202 NGETTEXT(msg_line_single, msg_line_plural, oap->line_count),
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
203 oap->line_count, op, amount);
19665
b64343cbabc6 patch 8.2.0389: delayed redraw when shifting text from Insert mode
Bram Moolenaar <Bram@vim.org>
parents: 19477
diff changeset
204 msg_attr_keep((char *)IObuff, 0, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
207 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
208 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
209 // Set "'[" and "']" marks.
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
210 curbuf->b_op_start = oap->start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
211 curbuf->b_op_end.lnum = oap->end.lnum;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
212 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
213 if (curbuf->b_op_end.col > 0)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
214 --curbuf->b_op_end.col;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
215 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 /*
15422
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
219 * Shift the current line one shiftwidth left (if left != 0) or right
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
220 * leaves cursor on first blank in the line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
223 shift_line(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
224 int left,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
225 int round,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
226 int amount,
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
227 int call_changed_bytes) // call changed_bytes()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 int i, j;
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
231 int sw_val = (int)get_sw_value_indent(curbuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
233 count = get_indent(); // get current indent
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
234
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
235 if (round) // round off indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 {
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
237 i = count / sw_val; // number of 'shiftwidth' rounded down
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
238 j = count % sw_val; // extra spaces
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
239 if (j && left) // first remove extra spaces
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 --amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 if (left)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 i -= amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 if (i < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 i += amount;
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
249 count = i * sw_val;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 }
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
251 else // original vi indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 if (left)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 {
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
255 count -= sw_val * amount;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 if (count < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 else
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
260 count += sw_val * amount;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
263 // Set new indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 if (State & VREPLACE_FLAG)
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1477
diff changeset
265 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 else
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1477
diff changeset
267 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 * Shift one line of the current block one shiftwidth right or left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 * Leaves cursor on first character in block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
275 shift_block(oparg_T *oap, int amount)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 int left = (oap->op_type == OP_LSHIFT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 int oldstate = State;
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
279 int total;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
280 char_u *newp, *oldp;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 int oldcol = curwin->w_cursor.col;
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
282 int sw_val = (int)get_sw_value_indent(curbuf);
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
283 int ts_val = (int)curbuf->b_p_ts;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 int incr;
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
286 colnr_T ws_vcol;
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
287 int added;
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
288 unsigned new_line_len; // the length of the line after the
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
289 // block shift
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 int old_p_ri = p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
293 p_ri = 0; // don't want revins in indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
296 State = MODE_INSERT; // don't want MODE_REPLACE for State
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 if (bd.is_short)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
301 // total is number of screen columns to be inserted/removed
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
302 total = (int)((unsigned)amount * (unsigned)sw_val);
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
303 if ((total / sw_val) != amount)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
304 return; // multiplication overflow
11997
66b677c77467 patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents: 11688
diff changeset
305
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306 oldp = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308 if (!left)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 {
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
310 int tabs = 0, spaces = 0;
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
311
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 * 1. Get start vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 * 2. Total ws vcols
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 * 3. Divvy into TABs & spp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 * 4. Construct new string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 */
19195
2ef19eed524a patch 8.2.0156: various typos in source files and tests
Bram Moolenaar <Bram@vim.org>
parents: 19176
diff changeset
318 total += bd.pre_whitesp; // all virtual WS up to & incl a split TAB
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 ws_vcol = bd.start_vcol - bd.pre_whitesp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 if (bd.startspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322 if (has_mbyte)
8399
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
323 {
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
324 if ((*mb_ptr2len)(bd.textstart) == 1)
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
325 ++bd.textstart;
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
326 else
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
327 {
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
328 ws_vcol = 0;
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
329 bd.startspaces = 0;
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
330 }
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
331 }
1995
92809ecb9a47 updated for version 7.2-292
vimboss
parents: 1982
diff changeset
332 else
92809ecb9a47 updated for version 7.2-292
vimboss
parents: 1982
diff changeset
333 ++bd.textstart;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 }
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
335 for ( ; VIM_ISWHITE(*bd.textstart); )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
337 // TODO: is passing bd.textstart for start of the line OK?
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
338 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, bd.start_vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339 total += incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 bd.start_vcol += incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
342 // OK, now total=all the VWS reqd, and textstart points at the 1st
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
343 // non-ws char in the block.
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
344 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
345 if (!curbuf->b_p_et)
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
346 tabstop_fromto(ws_vcol, ws_vcol + total,
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
347 ts_val, curbuf->b_p_vts_array, &tabs, &spaces);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
348 else
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
349 spaces = total;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
350 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 if (!curbuf->b_p_et)
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
352 tabs = ((ws_vcol % ts_val) + total) / ts_val; // number of tabs
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
353 if (tabs > 0)
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
354 spaces = ((ws_vcol % ts_val) + total) % ts_val; // number of spp
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 else
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
356 spaces = total;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
357 #endif
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
358 // if we're splitting a TAB, allow for it
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0);
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
360
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
361 new_line_len = bd.textcol + tabs + spaces + (int)STRLEN(bd.textstart);
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
362 newp = alloc(new_line_len + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 mch_memmove(newp, oldp, (size_t)bd.textcol);
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
366 vim_memset(newp + bd.textcol, TAB, (size_t)tabs);
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
367 vim_memset(newp + bd.textcol + tabs, ' ', (size_t)spaces);
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
368 // Note that STRMOVE() copies the trailing NUL.
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
369 STRMOVE(newp + bd.textcol + tabs + spaces, bd.textstart);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
371 else // left
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
373 colnr_T destination_col; // column to which text in block will
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
374 // be shifted
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
375 char_u *verbatim_copy_end; // end of the part of the line which is
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
376 // copied verbatim
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
377 colnr_T verbatim_copy_width;// the (displayed) width of this part
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
378 // of line
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
379 unsigned fill; // nr of spaces that replace a TAB
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
380 size_t block_space_width;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
381 size_t shift_amount;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
382 char_u *non_white = bd.textstart;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
383 colnr_T non_white_col;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
384
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
385 /*
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
386 * Firstly, let's find the first non-whitespace character that is
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
387 * displayed after the block's start column and the character's column
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
388 * number. Also, let's calculate the width of all the whitespace
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
389 * characters that are displayed in the block and precede the searched
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
390 * non-whitespace character.
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
391 */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
392
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
393 // If "bd.startspaces" is set, "bd.textstart" points to the character,
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
394 // the part of which is displayed at the block's beginning. Let's start
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
395 // searching from the next character.
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
396 if (bd.startspaces)
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
397 MB_PTR_ADV(non_white);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
398
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
399 // The character's column is in "bd.start_vcol".
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
400 non_white_col = bd.start_vcol;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
401
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
402 while (VIM_ISWHITE(*non_white))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
404 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
405 non_white_col += incr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
406 }
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
407
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
408 block_space_width = non_white_col - oap->start_vcol;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
409 // We will shift by "total" or "block_space_width", whichever is less.
1860
f765f9c139de updated for version 7.2-158
vimboss
parents: 1839
diff changeset
410 shift_amount = (block_space_width < (size_t)total
f765f9c139de updated for version 7.2-158
vimboss
parents: 1839
diff changeset
411 ? block_space_width : (size_t)total);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
412
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
413 // The column to which we will shift the text.
1860
f765f9c139de updated for version 7.2-158
vimboss
parents: 1839
diff changeset
414 destination_col = (colnr_T)(non_white_col - shift_amount);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
415
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
416 // Now let's find out how much of the beginning of the line we can
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
417 // reuse without modification.
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
418 verbatim_copy_end = bd.textstart;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
419 verbatim_copy_width = bd.start_vcol;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
420
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
421 // If "bd.startspaces" is set, "bd.textstart" points to the character
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
422 // preceding the block. We have to subtract its width to obtain its
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
423 // column number.
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
424 if (bd.startspaces)
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
425 verbatim_copy_width -= bd.start_char_vcols;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
426 while (verbatim_copy_width < destination_col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
428 char_u *line = verbatim_copy_end;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
429
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
430 // TODO: is passing verbatim_copy_end for start of the line OK?
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
431 incr = lbr_chartabsize(line, verbatim_copy_end,
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
432 verbatim_copy_width);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
433 if (verbatim_copy_width + incr > destination_col)
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
434 break;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
435 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
436 MB_PTR_ADV(verbatim_copy_end);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
439 // If "destination_col" is different from the width of the initial
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
440 // part of the line that will be copied, it means we encountered a tab
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
441 // character, which we will have to partly replace with spaces.
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
442 fill = destination_col - verbatim_copy_width;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
443
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
444 // The replacement line will consist of:
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
445 // - the beginning of the original line up to "verbatim_copy_end",
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
446 // - "fill" number of spaces,
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
447 // - the rest of the line, pointed to by non_white.
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
448 new_line_len = (unsigned)(verbatim_copy_end - oldp)
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
449 + fill
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
450 + (unsigned)STRLEN(non_white);
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
451
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
452 newp = alloc(new_line_len + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 return;
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
455 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp));
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
456 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill);
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
457 // Note that STRMOVE() copies the trailing NUL.
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
458 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
460 // replace the line
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
461 added = new_line_len - (int)STRLEN(oldp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 ml_replace(curwin->w_cursor.lnum, newp, FALSE);
28854
647d7f439622 patch 8.2.4950: text properties position wrong after shifting text
Bram Moolenaar <Bram@vim.org>
parents: 28809
diff changeset
463 inserted_bytes(curwin->w_cursor.lnum, bd.textcol, added);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 State = oldstate;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 curwin->w_cursor.col = oldcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 p_ri = old_p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 }
15422
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
470
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 * Insert string "s" (b_insert ? before : after) block :AKelly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 * Caller must prepare for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
476 block_insert(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
477 oparg_T *oap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
478 char_u *s,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
479 int b_insert,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
480 struct block_def *bdp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 {
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
482 int ts_val;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
483 int count = 0; // extra spaces to replace a cut TAB
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
484 int spaces = 0; // non-zero if cutting a TAB
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
485 colnr_T offset; // pointer along new line
22282
5adb97bf0b32 patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents: 22278
diff changeset
486 colnr_T startcol; // column where insert starts
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
487 unsigned s_len; // STRLEN(s)
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
488 char_u *newp, *oldp; // new, old lines
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
489 linenr_T lnum; // loop var
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 int oldstate = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
492 State = MODE_INSERT; // don't want MODE_REPLACE for State
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 s_len = (unsigned)STRLEN(s);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 block_prep(oap, bdp, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 if (bdp->is_short && b_insert)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
499 continue; // OP_INSERT, line ends before block start
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 oldp = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 if (b_insert)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
504 {
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
505 ts_val = bdp->start_char_vcols;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 spaces = bdp->startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 if (spaces != 0)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
508 count = ts_val - 1; // we're cutting a TAB
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 offset = bdp->textcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
511 else // append
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 {
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
513 ts_val = bdp->end_char_vcols;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
514 if (!bdp->is_short) // spaces = padding after block
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515 {
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
516 spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 if (spaces != 0)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
518 count = ts_val - 1; // we're cutting a TAB
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 offset = bdp->textcol + bdp->textlen - (spaces != 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
521 else // spaces = padding to block edge
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
523 // if $ used, just append to EOL (ie spaces==0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 if (!bdp->is_MAX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 spaces = (oap->end_vcol - bdp->end_vcol) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 count = spaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 offset = bdp->textcol + bdp->textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530
6140
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
531 if (has_mbyte && spaces > 0)
27245
776db9e02b61 patch 8.2.4151: reading beyond the end of a line
Bram Moolenaar <Bram@vim.org>
parents: 27183
diff changeset
532 // avoid copying part of a multi-byte character
776db9e02b61 patch 8.2.4151: reading beyond the end of a line
Bram Moolenaar <Bram@vim.org>
parents: 27183
diff changeset
533 offset -= (*mb_head_off)(oldp, oldp + offset);
776db9e02b61 patch 8.2.4151: reading beyond the end of a line
Bram Moolenaar <Bram@vim.org>
parents: 27183
diff changeset
534
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
535 if (spaces < 0) // can happen when the cursor was moved
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
536 spaces = 0;
6140
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
537
27183
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
538 // Make sure the allocated size matches what is actually copied below.
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
539 newp = alloc(STRLEN(oldp) + spaces + s_len
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
540 + (spaces > 0 && !bdp->is_short ? ts_val - spaces : 0)
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
541 + count + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
542 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
543 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
544
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
545 // copy up to shifted part
27183
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
546 mch_memmove(newp, oldp, (size_t)offset);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
547 oldp += offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
548
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
549 // insert pre-padding
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
550 vim_memset(newp + offset, ' ', (size_t)spaces);
22282
5adb97bf0b32 patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents: 22278
diff changeset
551 startcol = offset + spaces;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
553 // copy the new text
22282
5adb97bf0b32 patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents: 22278
diff changeset
554 mch_memmove(newp + startcol, s, (size_t)s_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 offset += s_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556
27183
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
557 if (spaces > 0 && !bdp->is_short)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
558 {
27183
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
559 if (*oldp == TAB)
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
560 {
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
561 // insert post-padding
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
562 vim_memset(newp + offset + spaces, ' ',
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
563 (size_t)(ts_val - spaces));
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
564 // we're splitting a TAB, don't copy it
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
565 oldp++;
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
566 // We allowed for that TAB, remember this now
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
567 count++;
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
568 }
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
569 else
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
570 // Not a TAB, no extra spaces
be5e01f3ee3b patch 8.2.4120: block insert goes over the end of the line
Bram Moolenaar <Bram@vim.org>
parents: 27140
diff changeset
571 count = spaces;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
572 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
573
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
574 if (spaces > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
575 offset += count;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1563
diff changeset
576 STRMOVE(newp + offset, oldp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
577
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
578 ml_replace(lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
579
22282
5adb97bf0b32 patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents: 22278
diff changeset
580 if (b_insert)
5adb97bf0b32 patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents: 22278
diff changeset
581 // correct any text properties
5adb97bf0b32 patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents: 22278
diff changeset
582 inserted_bytes(lnum, startcol, s_len);
5adb97bf0b32 patch 8.2.1690: text properties not adjusted for "I" in Visual block mode
Bram Moolenaar <Bram@vim.org>
parents: 22278
diff changeset
583
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 if (lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
586 // Set "']" mark to the end of the block instead of the end of
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
587 // the insert in the first line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588 curbuf->b_op_end.lnum = oap->end.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 curbuf->b_op_end.col = offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
591 } // for all lnum
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 State = oldstate;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
598 /*
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
599 * Handle a delete operation.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 *
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
601 * Return FAIL if undo failed, OK otherwise.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
604 op_delete(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 char_u *newp, *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 linenr_T old_lcount = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 int did_yank = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
614 if (curbuf->b_ml.ml_flags & ML_EMPTY) // nothing to do
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
617 // Nothing to delete, return here. Do prepare undo, for op_change().
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 if (oap->empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619 return u_save_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 if (!curbuf->b_p_ma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 {
25064
8f2262c72178 patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 24866
diff changeset
623 emsg(_(e_cannot_make_changes_modifiable_is_off));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
624 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626
27263
93d4ee1e6113 patch 8.2.4160: cannot change the register used for Select mode delete
Bram Moolenaar <Bram@vim.org>
parents: 27245
diff changeset
627 if (VIsual_select && oap->is_VIsual)
93d4ee1e6113 patch 8.2.4160: cannot change the register used for Select mode delete
Bram Moolenaar <Bram@vim.org>
parents: 27245
diff changeset
628 // use register given with CTRL_R, defaults to zero
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28773
diff changeset
629 oap->regname = VIsual_select_reg;
27263
93d4ee1e6113 patch 8.2.4160: cannot change the register used for Select mode delete
Bram Moolenaar <Bram@vim.org>
parents: 27245
diff changeset
630
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 #ifdef FEAT_CLIPBOARD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 adjust_clip_reg(&oap->regname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
635 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 mb_adjust_opend(oap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
637
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
638 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
639 * 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
640 * 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
641 * 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
642 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 if ( oap->motion_type == MCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 && !oap->is_VIsual
50
90188be4861f updated for version 7.0028
vimboss
parents: 45
diff changeset
645 && !oap->block_mode
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 && oap->line_count > 1
3254
2f075595590f updated for version 7.3.396
Bram Moolenaar <bram@vim.org>
parents: 3252
diff changeset
647 && oap->motion_force == NUL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 && oap->op_type == OP_DELETE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649 {
2957
fe6ad3fd8532 updated for version 7.3.251
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
650 ptr = ml_get(oap->end.lnum) + oap->end.col;
fe6ad3fd8532 updated for version 7.3.251
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
651 if (*ptr != NUL)
fe6ad3fd8532 updated for version 7.3.251
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
652 ptr += oap->inclusive;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 if (*ptr == NUL && inindent(0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 oap->motion_type = MLINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
658 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
659 * 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
660 * 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
661 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662 if ( oap->motion_type == MCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 && oap->line_count == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 && oap->op_type == OP_DELETE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 && *ml_get(oap->start.lnum) == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 /*
446
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
668 * It's an error to operate on an empty region, when 'E' included in
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669 * 'cpoptions' (Vi compatible).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
670 */
446
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
671 if (virtual_op)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
672 // Virtual editing: Nothing gets deleted, but we set the '[ and ']
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
673 // marks as if it happened.
446
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
674 goto setmarks;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
677 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
679
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
680 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
681 * 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
682 * 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
683 * 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
684 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 if (oap->regname != '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 if (oap->regname != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
689 // check for read-only register
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
690 if (!valid_yank_reg(oap->regname, TRUE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
691 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
692 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
693 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
695 get_yank_register(oap->regname, TRUE); // yank into specif'd reg.
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
696 if (op_yank(oap, TRUE, FALSE) == OK) // yank without message
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 did_yank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 }
25808
b1440083f0da patch 8.2.3439: deleted lines go to wrong yank register
Bram Moolenaar <Bram@vim.org>
parents: 25666
diff changeset
699 else
b1440083f0da patch 8.2.3439: deleted lines go to wrong yank register
Bram Moolenaar <Bram@vim.org>
parents: 25666
diff changeset
700 reset_y_append(); // not appending to unnamed register
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
701
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
703 * 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
704 * 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
705 * compatible)
3782
063765c3cebb updated for version 7.3.649
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
706 * Use the register name from before adjust_clip_reg() may have
063765c3cebb updated for version 7.3.649
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
707 * changed it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 */
15987
29de75f53b1a patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
709 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
710 || oap->use_reg_one)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711 {
10827
e366b968bf08 patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents: 10803
diff changeset
712 shift_delete_registers();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
713 if (op_yank(oap, TRUE, FALSE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
714 did_yank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
715 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
716
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
717 // Yank into small delete register when no named register specified
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
718 // and the delete is within one line.
3468
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
719 if ((
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
720 #ifdef FEAT_CLIPBOARD
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
721 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') ||
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
722 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') ||
3468
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
723 #endif
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
724 oap->regname == 0) && oap->motion_type != MLINE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 && oap->line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 oap->regname = '-';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 get_yank_register(oap->regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 if (op_yank(oap, TRUE, FALSE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 did_yank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731 oap->regname = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
734 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
735 * If there's too much stuff to fit in the yank register, then get a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
736 * confirmation before doing the delete. This is crude, but simple.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
737 * And it avoids doing a delete of something we can't put back if we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 * want.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
739 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
740 if (!did_yank)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
742 int msg_silent_save = msg_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
744 msg_silent = 0; // must display the prompt
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746 msg_silent = msg_silent_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
747 if (n != 'y')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
748 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26581
diff changeset
749 emsg(_(e_command_aborted));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
750 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
751 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
752 }
13037
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 12996
diff changeset
753
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13254
diff changeset
754 #if defined(FEAT_EVAL)
13037
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 12996
diff changeset
755 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
756 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
757 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
760 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
761 * 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
762 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
766 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
768
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 block_prep(oap, &bd, lnum, TRUE);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
772 if (bd.textlen == 0) // nothing to delete
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
775 // Adjust cursor position for tab replaced by spaces and 'lbr'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 if (lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 curwin->w_cursor.col = bd.textcol + bd.startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
779 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16680
diff changeset
782 // "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
783 // 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
784 // Thus the number of characters may increase!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
785 n = bd.textlen - bd.startspaces - bd.endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
786 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
787 newp = alloc(STRLEN(oldp) + 1 - n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789 continue;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
790 // copy up to deleted part
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
791 mch_memmove(newp, oldp, (size_t)bd.textcol);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
792 // insert spaces
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
793 vim_memset(newp + bd.textcol, ' ',
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 (size_t)(bd.startspaces + bd.endspaces));
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
795 // copy the part after the deleted part
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 oldp += bd.textcol + bd.textlen;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1563
diff changeset
797 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
798 // replace the line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 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
800
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
801 #ifdef FEAT_PROP_POPUP
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16680
diff changeset
802 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
803 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
804 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 check_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 oap->end.lnum + 1, 0L);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
810 oap->line_count = 0; // no lines deleted
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811 }
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
812 else if (oap->motion_type == MLINE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
813 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
814 if (oap->op_type == OP_CHANGE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
816 // Delete the lines except the first one. Temporarily move the
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
817 // cursor to the next line. Save the current line number, if the
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
818 // last line is deleted it may be changed.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 if (oap->line_count > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
823 del_lines((long)(oap->line_count - 1), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
827 return FAIL;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
828 if (curbuf->b_p_ai) // don't delete indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
830 beginline(BL_WHITE); // cursor on first non-white
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
831 did_ai = TRUE; // delete the indent when ESC hit
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
832 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
833 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
834 else
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
835 beginline(0); // cursor in column 0
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
836 truncate_line(FALSE); // delete the rest of the line
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
837 // leave cursor past last char in line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 if (oap->line_count > 1)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
839 u_clearline(); // "U" command not possible after "2cc"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
842 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 del_lines(oap->line_count, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 beginline(BL_WHITE | BL_FIX);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
845 u_clearline(); // "U" command not possible after "dd"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 if (virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 int endcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
854 // For virtualedit: break the tabs that are partly included.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 if (gchar_pos(&oap->start) == '\t')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
857 if (u_save_cursor() == FAIL) // save first line for undo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
858 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
859 if (oap->line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 endcol = getviscol2(oap->end.col, oap->end.coladd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 coladvance_force(getviscol2(oap->start.col, oap->start.coladd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 oap->start = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 if (oap->line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 coladvance(endcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 oap->end.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 oap->end.coladd = curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 curwin->w_cursor = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
872 // Break a tab only when it's included in the area.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 if (gchar_pos(&oap->end) == '\t'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 && (int)oap->end.coladd < oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
876 // save last line for undo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 if (u_save((linenr_T)(oap->end.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 curwin->w_cursor = oap->end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 coladvance_force(getviscol2(oap->end.col, oap->end.coladd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 oap->end = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 curwin->w_cursor = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884 }
18481
26256dcadd77 patch 8.1.2235: "C" with 'virtualedit' set does not include multi-byte char
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
885 if (has_mbyte)
26256dcadd77 patch 8.1.2235: "C" with 'virtualedit' set does not include multi-byte char
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
886 mb_adjust_opend(oap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
889 if (oap->line_count == 1) // delete characters within one line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
891 if (u_save_cursor() == FAIL) // save line for undo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
894 // if 'cpoptions' contains '$', display '$' at end of change
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
895 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 && oap->op_type == OP_CHANGE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 && oap->end.lnum == curwin->w_cursor.lnum
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
898 && !oap->is_VIsual)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 display_dollar(oap->end.col - !oap->inclusive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 n = oap->end.col - oap->start.col + 1 - !oap->inclusive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 if (virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
905 // fix up things for virtualedit-delete:
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
906 // break the tabs which are going to get in our way
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 char_u *curline = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 int len = (int)STRLEN(curline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 if (oap->end.coladd != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 && (int)oap->end.col >= len - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 && !(oap->start.coladd && (int)oap->end.col >= len - 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 n++;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
914 // Delete at least one char (e.g, when on a control char).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 if (n == 0 && oap->start.coladd != oap->end.coladd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
916 n = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
917
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
918 // When deleted a char in the line, reset coladd.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919 if (gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 }
6826
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
922 (void)del_bytes((long)n, !virtual_op,
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
923 oap->op_type == OP_DELETE && !oap->is_VIsual);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
925 else // delete characters between lines
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
926 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 pos_T curpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
929 // save deleted and changed lines for undo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
934 truncate_line(TRUE); // delete from cursor to end of line
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
935
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
936 curpos = curwin->w_cursor; // remember curwin->w_cursor
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 del_lines((long)(oap->line_count - 2), FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
940 // delete from start of line until op_end
2957
fe6ad3fd8532 updated for version 7.3.251
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
941 n = (oap->end.col + 1 - !oap->inclusive);
6826
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
942 curwin->w_cursor.col = 0;
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
943 (void)del_bytes((long)n, !virtual_op,
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
944 oap->op_type == OP_DELETE && !oap->is_VIsual);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
945 curwin->w_cursor = curpos; // restore curwin->w_cursor
6826
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
946 (void)do_join(2, FALSE, FALSE, FALSE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 }
25666
649d3e9c5914 patch 8.2.3369: auto formatting after "cw" leaves cursor in wrong spot
Bram Moolenaar <Bram@vim.org>
parents: 25487
diff changeset
948 if (oap->op_type == OP_DELETE)
649d3e9c5914 patch 8.2.3369: auto formatting after "cw" leaves cursor in wrong spot
Bram Moolenaar <Bram@vim.org>
parents: 25487
diff changeset
949 auto_format(FALSE, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 msgmore(curbuf->b_ml.ml_line_count - old_lcount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953
446
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
954 setmarks:
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
955 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 {
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
957 if (oap->block_mode)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
958 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
959 curbuf->b_op_end.lnum = oap->end.lnum;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
960 curbuf->b_op_end.col = oap->start.col;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
961 }
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
962 else
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
963 curbuf->b_op_end = oap->start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
964 curbuf->b_op_start = oap->start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971 * Adjust end of operating area for ending on a multi-byte character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
972 * Used for deletion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
973 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
974 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
975 mb_adjust_opend(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
976 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
977 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
978
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 if (oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981 p = ml_get(oap->end.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 oap->end.col += mb_tail_off(p, p + oap->end.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
984 }
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
985
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
986 /*
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
987 * Replace 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
988 * 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
989 */
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
990 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
991 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
992 {
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
993 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
994
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
995 State = MODE_REPLACE;
14216
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
996 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
997 State = n;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
998 // Backup to the replaced character.
14216
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
999 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
1000 }
15422
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
1001
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 * Replace a whole area with one character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1005 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1006 op_replace(oparg_T *oap, int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008 int n, numc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 int num_chars;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 char_u *newp, *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 size_t oldlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 struct block_def bd;
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1013 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
1014 int had_ctrl_v_cr = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1015
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1016 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1017 return OK; // nothing to do
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1018
13202
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1019 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
1020 {
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1021 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
1022 c = CAR;
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1023 }
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1024 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
1025 {
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1026 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
1027 c = NL;
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1028 }
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1029
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1030 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1031 mb_adjust_opend(oap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1036
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 * block mode replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 bd.is_MAX = (curwin->w_curswant == MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1043 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1044 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1045 curwin->w_cursor.col = 0; // make sure cursor position is valid
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX))
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1048 continue; // nothing to replace
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1049
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1050 // n == number of extra chars required
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1051 // If we split a TAB, it may be replaced by several characters.
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1052 // Thus the number of characters may increase!
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1053 // If the range starts in virtual space, count the initial
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1054 // coladd offset as part of "startspaces"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1055 if (virtual_op && bd.is_short && *bd.textstart == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1056 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1057 pos_T vpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1058
1982
b1b09b68d706 updated for version 7.2-279
vimboss
parents: 1969
diff changeset
1059 vpos.lnum = curwin->w_cursor.lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 getvpos(&vpos, oap->start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 bd.startspaces += vpos.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062 n = bd.startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 else
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1065 // allow for pre spaces
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1068 // allow for post spp
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 n += (bd.endspaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 && !bd.is_oneChar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1072 // Figure out how many characters to replace.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 numc = oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 if (bd.is_short && (!virtual_op || bd.is_MAX))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1075 numc -= (oap->end_vcol - bd.end_vcol) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1077 // A double-wide character can be replaced only up to half the
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1078 // times.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079 if ((*mb_char2cells)(c) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 if ((numc & 1) && !bd.is_short)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 ++bd.endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 numc = numc / 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1089 // Compute bytes needed, move character count to num_chars.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1090 num_chars = numc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 numc *= (*mb_char2len)(c);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1092 // oldlen includes textlen, so don't double count
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 n += numc - bd.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 oldp = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 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
1097 newp = alloc(oldlen + 1 + n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n));
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1101 // copy up to deleted part
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 mch_memmove(newp, oldp, (size_t)bd.textcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 oldp += bd.textcol + bd.textlen;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1104 // insert pre-spaces
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1105 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1106 // insert replacement chars CHECK FOR ALLOCATED SPACE
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1107 // REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1108 // literally.
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1109 if (had_ctrl_v_cr || (c != '\r' && c != '\n'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 {
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1111 if (has_mbyte)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1112 {
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1113 n = (int)STRLEN(newp);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1114 while (--num_chars >= 0)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1115 n += (*mb_char2bytes)(c, newp + n);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1116 }
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1117 else
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1118 vim_memset(newp + STRLEN(newp), c, (size_t)numc);
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1119 if (!bd.is_short)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1120 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1121 // insert post-spaces
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1122 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1123 // copy the part after the changed part
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1124 STRMOVE(newp + STRLEN(newp), oldp);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1125 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1128 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1129 // 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
1130 after_p = alloc(oldlen + 1 + n - STRLEN(newp));
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1131 if (after_p != NULL)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1132 STRMOVE(after_p, oldp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1134 // replace the line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 ml_replace(curwin->w_cursor.lnum, newp, FALSE);
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1136 if (after_p != NULL)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1137 {
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1138 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1139 appended_lines_mark(curwin->w_cursor.lnum, 1L);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1140 oap->end.lnum++;
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1141 vim_free(after_p);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1142 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1143 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1144 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1145 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1146 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1147 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1148 * MCHAR and MLINE motion replace.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1149 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1150 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1151 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1152 oap->start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1153 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1154 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1155 if (oap->end.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1156 --oap->end.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 else if (!oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 dec(&(oap->end));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1160
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11065
diff changeset
1161 while (LTOREQ_POS(curwin->w_cursor, oap->end))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1162 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1163 n = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 if (n != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 {
26581
8da90cdcec68 patch 8.2.3820: "vrc" does not replace composing characters
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1166 int new_byte_len = (*mb_char2len)(c);
8da90cdcec68 patch 8.2.3820: "vrc" does not replace composing characters
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1167 int old_byte_len = mb_ptr2len(ml_get_cursor());
8da90cdcec68 patch 8.2.3820: "vrc" does not replace composing characters
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1168
8da90cdcec68 patch 8.2.3820: "vrc" does not replace composing characters
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1169 if (new_byte_len > 1 || old_byte_len > 1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1170 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1171 // This is slow, but it handles replacing a single-byte
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1172 // with a multi-byte and the other way around.
4203
eea32254940f updated for version 7.3.853
Bram Moolenaar <bram@vim.org>
parents: 4201
diff changeset
1173 if (curwin->w_cursor.lnum == oap->end.lnum)
26581
8da90cdcec68 patch 8.2.3820: "vrc" does not replace composing characters
Bram Moolenaar <Bram@vim.org>
parents: 26518
diff changeset
1174 oap->end.col += new_byte_len - old_byte_len;
14216
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1175 replace_character(c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 if (n == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 int end_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 if (curwin->w_cursor.lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1185 // oap->end has to be recalculated when
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1186 // the tab breaks
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 end_vcol = getviscol2(oap->end.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 oap->end.coladd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 coladvance_force(getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191 if (curwin->w_cursor.lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1192 getvpos(&oap->end, end_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 }
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
1194 PBYTE(curwin->w_cursor, c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 int virtcols = oap->end.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1201 if (curwin->w_cursor.lnum == oap->start.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1202 && oap->start.col == oap->end.col && oap->start.coladd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1203 virtcols -= oap->start.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1205 // oap->end has been trimmed so it's effectively inclusive;
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1206 // as a result an extra +1 must be counted so we don't
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1207 // trample the NUL byte.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 curwin->w_cursor.col -= (virtcols + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210 for (; virtcols >= 0; virtcols--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 {
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28773
diff changeset
1212 if ((*mb_char2len)(c) > 1)
14216
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1213 replace_character(c);
28809
d0241e74bfdb patch 8.2.4928: various white space and cosmetic mistakes
Bram Moolenaar <Bram@vim.org>
parents: 28773
diff changeset
1214 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
1215 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
1216 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
1217 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1221 // Advance to next character, stop at the end of the file.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1222 if (inc_cursor() == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 curwin->w_cursor = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
1231 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1232 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1233 // Set "'[" and "']" marks.
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1234 curbuf->b_op_start = oap->start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1235 curbuf->b_op_end = oap->end;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1236 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1240
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7576
diff changeset
1241 static int swapchars(int op_type, pos_T *pos, int length);
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1242
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1243 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1244 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1245 */
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
1246 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1247 op_tilde(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 struct block_def bd;
1528
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1251 int did_change = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 pos = oap->start;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1258 if (oap->block_mode) // Visual block mode
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1259 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1260 for (; pos.lnum <= oap->end.lnum; ++pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1261 {
1766
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1262 int one_change;
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1263
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1264 block_prep(oap, &bd, pos.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265 pos.col = bd.textcol;
1766
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1266 one_change = swapchars(oap->op_type, &pos, bd.textlen);
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1267 did_change |= one_change;
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1268
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
1269 #ifdef FEAT_NETBEANS_INTG
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1270 if (netbeans_active() && one_change)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1274 netbeans_removed(curbuf, pos.lnum, bd.textcol,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1275 (long)bd.textlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 netbeans_inserted(curbuf, pos.lnum, bd.textcol,
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1277 &ptr[bd.textcol], bd.textlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 }
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
1279 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 if (did_change)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1284 else // not block mode
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 oap->start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1290 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1291 if (oap->end.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 --oap->end.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1294 else if (!oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1295 dec(&(oap->end));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1296
1528
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1297 if (pos.lnum == oap->end.lnum)
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1298 did_change = swapchars(oap->op_type, &pos,
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1299 oap->end.col - pos.col + 1);
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1300 else
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1301 for (;;)
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1302 {
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1303 did_change |= swapchars(oap->op_type, &pos,
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1304 pos.lnum == oap->end.lnum ? oap->end.col + 1:
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1305 (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
1306 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1)
1528
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1307 break;
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1308 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1309 if (did_change)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1310 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 #ifdef FEAT_NETBEANS_INTG
28169
bef82285dda0 patch 8.2.4610: some conditions are always true
Bram Moolenaar <Bram@vim.org>
parents: 27724
diff changeset
1314 if (netbeans_active())
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 pos = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 while (pos.lnum < oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 777
diff changeset
1323 count = (int)STRLEN(ptr) - pos.col;
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1324 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1325 netbeans_inserted(curbuf, pos.lnum, pos.col,
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1326 &ptr[pos.col], count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1327 pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1328 pos.lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1329 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1330 ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1331 count = oap->end.col - pos.col + 1;
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1332 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1333 netbeans_inserted(curbuf, pos.lnum, pos.col,
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1334 &ptr[pos.col], count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1335 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1336 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 if (!did_change && oap->is_VIsual)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1341 // No change: need to remove the Visual selection
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1342 redraw_curbuf_later(INVERTED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
1344 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1345 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1346 // Set '[ and '] marks.
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1347 curbuf->b_op_start = oap->start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1348 curbuf->b_op_end = oap->end;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1349 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1351 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
1352 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
1353 oap->line_count), oap->line_count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1354 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 /*
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1357 * Invoke swapchar() on "length" bytes at position "pos".
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1358 * "pos" is advanced to just after the changed characters.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1359 * "length" is rounded up to include the whole last multi-byte character.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1360 * Also works correctly when the number of bytes changes.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1361 * Returns TRUE if some character was changed.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1362 */
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1363 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1364 swapchars(int op_type, pos_T *pos, int length)
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1365 {
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1366 int todo;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1367 int did_change = 0;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1368
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1369 for (todo = length; todo > 0; --todo)
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1370 {
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1371 if (has_mbyte)
5288
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1372 {
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1373 int len = (*mb_ptr2len)(ml_get_pos(pos));
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1374
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1375 // we're counting bytes, not characters
5288
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1376 if (len > 0)
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1377 todo -= len - 1;
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1378 }
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1379 did_change |= swapchar(op_type, pos);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1380 if (inc(pos) == -1) // at end of file
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1381 break;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1382 }
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1383 return did_change;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1384 }
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1385
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1386 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1387 * If op_type == OP_UPPER: make uppercase,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1388 * if op_type == OP_LOWER: make lowercase,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1389 * if op_type == OP_ROT13: do rot13 encoding,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1390 * else swap case of character at 'pos'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1391 * returns TRUE when something actually changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1392 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1393 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1394 swapchar(int op_type, pos_T *pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1395 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1396 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1397 int nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1399 c = gchar_pos(pos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1400
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1401 // Only do rot13 encoding for ASCII characters.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1402 if (c >= 0x80 && op_type == OP_ROT13)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1403 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1404
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1405 if (op_type == OP_UPPER && c == 0xdf
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1406 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0))
493
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1407 {
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1408 pos_T sp = curwin->w_cursor;
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1409
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1410 // Special handling of German sharp s: change to "SS".
493
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1411 curwin->w_cursor = *pos;
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1412 del_char(FALSE);
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1413 ins_char('S');
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1414 ins_char('S');
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1415 curwin->w_cursor = sp;
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1416 inc(pos);
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1417 }
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1418
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1419 if (enc_dbcs != 0 && c >= 0x100) // No lower/uppercase letter
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 nc = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1422 if (MB_ISLOWER(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 if (op_type == OP_ROT13)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 nc = ROT13(c, 'a');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426 else if (op_type != OP_LOWER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 nc = MB_TOUPPER(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 else if (MB_ISUPPER(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 if (op_type == OP_ROT13)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432 nc = ROT13(c, 'A');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1433 else if (op_type != OP_UPPER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1434 nc = MB_TOLOWER(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1435 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1436 if (nc != c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1437 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1438 if (enc_utf8 && (c >= 0x80 || nc >= 0x80))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1439 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1440 pos_T sp = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1441
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1442 curwin->w_cursor = *pos;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1443 // don't use del_char(), it also removes composing chars
2451
0b8612c2814d Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents: 2446
diff changeset
1444 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1445 ins_char(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1446 curwin->w_cursor = sp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 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
1449 PBYTE(*pos, nc);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 * op_insert - Insert and append operators for Visual mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1459 op_insert(oparg_T *oap, long count1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 long ins_len, pre_textlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 char_u *firstline, *ins_text;
26313
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1463 colnr_T ind_pre_col = 0, ind_post_col;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1464 int ind_pre_vcol = 0, ind_post_vcol = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 int i;
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1467 pos_T t1;
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1468 pos_T start_insert;
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1469 // offset when cursor was moved in insert mode
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1470 int offset = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1471
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1472 // edit() changes this - record it for OP_APPEND
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 bd.is_MAX = (curwin->w_curswant == MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1475 // vis block is still marked. Get rid of it now.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 curwin->w_cursor.lnum = oap->start.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1477 update_screen(INVERTED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1481 // When 'virtualedit' is used, need to insert the extra spaces before
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1482 // doing block_prep(). When only "block" is used, virtual edit is
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1483 // already disabled, but still need it when calling
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1484 // coladvance_force().
25380
ac88cd21ae88 patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents: 25072
diff changeset
1485 // coladvance_force() uses get_ve_flags() to get the 'virtualedit'
25487
c26ff3203b43 patch 8.2.3280: 'virtualedit' local to buffer is not the best solution
Bram Moolenaar <Bram@vim.org>
parents: 25380
diff changeset
1486 // state for the current window. To override that state, we need to
c26ff3203b43 patch 8.2.3280: 'virtualedit' local to buffer is not the best solution
Bram Moolenaar <Bram@vim.org>
parents: 25380
diff changeset
1487 // set the window-local value of ve_flags rather than the global value.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 if (curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 {
25487
c26ff3203b43 patch 8.2.3280: 'virtualedit' local to buffer is not the best solution
Bram Moolenaar <Bram@vim.org>
parents: 25380
diff changeset
1490 int old_ve_flags = curwin->w_ve_flags;
25380
ac88cd21ae88 patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents: 25072
diff changeset
1491
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 return;
25380
ac88cd21ae88 patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents: 25072
diff changeset
1494
25487
c26ff3203b43 patch 8.2.3280: 'virtualedit' local to buffer is not the best solution
Bram Moolenaar <Bram@vim.org>
parents: 25380
diff changeset
1495 curwin->w_ve_flags = VE_ALL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 coladvance_force(oap->op_type == OP_APPEND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 ? oap->end_vcol + 1 : getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 --curwin->w_cursor.col;
25487
c26ff3203b43 patch 8.2.3280: 'virtualedit' local to buffer is not the best solution
Bram Moolenaar <Bram@vim.org>
parents: 25380
diff changeset
1500 curwin->w_ve_flags = old_ve_flags;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1502 // Get the info about the block before entering the text
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 block_prep(oap, &bd, oap->start.lnum, TRUE);
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1504 // Get indent information
26313
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1505 ind_pre_col = (colnr_T)getwhitecols_curline();
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1506 ind_pre_vcol = get_indent();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 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
1508
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 firstline += bd.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 pre_textlen = (long)STRLEN(firstline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 {
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1516 if (oap->block_mode && curwin->w_cursor.coladd == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1518 // Move the cursor to the character right of the block.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 while (*ml_get_cursor() != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 && (curwin->w_cursor.col < bd.textcol + bd.textlen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 if (bd.is_short && !bd.is_MAX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1524 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1525 // First line was too short, make it longer and adjust the
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1526 // values in "bd".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1527 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 for (i = 0; i < bd.endspaces; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 bd.textlen += bd.endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1535 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 curwin->w_cursor = oap->end;
893
bf7803d0f5b9 updated for version 7.0-019
vimboss
parents: 856
diff changeset
1537 check_cursor_col();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1539 // 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
1540 if (!LINEEMPTY(curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 && oap->start_vcol != oap->end_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1546 t1 = oap->start;
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1547 start_insert = curwin->w_cursor;
10803
065da86ca6d2 patch 8.0.0291: Visual block insertion does not insert in all lines
Christian Brabandt <cb@256bit.org>
parents: 10785
diff changeset
1548 (void)edit(NUL, FALSE, (linenr_T)count1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1550 // When a tab was inserted, and the characters in front of the tab
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1551 // have been converted to a tab as well, the column of the cursor
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1552 // might have actually been reduced, so need to adjust here.
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1553 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
1554 && LT_POS(curbuf->b_op_start_orig, t1))
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1555 oap->start = curbuf->b_op_start_orig;
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1556
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1557 // If user has moved off this line, we don't know what to do, so do
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1558 // nothing.
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1559 // Also don't repeat the insert when Insert mode ended with CTRL-C.
1477
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1560 if (curwin->w_cursor.lnum != oap->start.lnum || got_int)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1565 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
1566 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
1567 size_t len;
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1568 int add;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1569
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1570 // If indent kicked in, the firstline might have changed
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1571 // but only do that, if the indent actually increased.
26313
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1572 ind_post_col = (colnr_T)getwhitecols_curline();
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1573 if (curbuf->b_op_start.col > ind_pre_col && ind_post_col > ind_pre_col)
12327
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1574 {
26313
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1575 bd.textcol += ind_post_col - ind_pre_col;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1576 ind_post_vcol = get_indent();
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1577 bd.start_vcol += ind_post_vcol - ind_pre_vcol;
13620
4faf77b96432 patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents: 13614
diff changeset
1578 did_indent = TRUE;
12327
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1579 }
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1580
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1581 // The user may have moved the cursor before inserting something, try
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1582 // to adjust the block for that. But only do it, if the difference
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1583 // does not come from indent kicking in.
13620
4faf77b96432 patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents: 13614
diff changeset
1584 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
1585 && !bd.is_MAX && !did_indent)
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1586 {
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1587 int t = getviscol2(curbuf->b_op_start_orig.col,
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1588 curbuf->b_op_start_orig.coladd);
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1589
27724
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1590 if (oap->op_type == OP_INSERT
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1591 && oap->start.col + oap->start.coladd
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1592 != curbuf->b_op_start_orig.col
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1593 + curbuf->b_op_start_orig.coladd)
27724
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1594 {
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1595 oap->start.col = curbuf->b_op_start_orig.col;
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1596 pre_textlen -= t - oap->start_vcol;
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1597 oap->start_vcol = t;
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1598 }
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1599 else if (oap->op_type == OP_APPEND
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1600 && oap->start.col + oap->start.coladd
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1601 >= curbuf->b_op_start_orig.col
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1602 + curbuf->b_op_start_orig.coladd)
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1603 {
27724
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1604 oap->start.col = curbuf->b_op_start_orig.col;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1605 // reset pre_textlen to the value of OP_INSERT
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1606 pre_textlen += bd.textlen;
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1607 pre_textlen -= t - oap->start_vcol;
27724
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1608 oap->start_vcol = t;
2261ef91b850 patch 8.2.4388: dead code in op_insert()
Bram Moolenaar <Bram@vim.org>
parents: 27521
diff changeset
1609 oap->op_type = OP_INSERT;
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1610 }
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1611 }
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1612
26313
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1613 // Spaces and tabs in the indent may have changed to other spaces and
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1614 // tabs. Get the starting column again and correct the length.
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1615 // Don't do this when "$" used, end-of-line will have changed.
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1616 //
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1617 // if indent was added and the inserted text was after the indent,
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1618 // correct the selection for the new indent.
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1619 if (did_indent && bd.textcol - ind_post_col > 0)
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1620 {
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1621 oap->start.col += ind_post_col - ind_pre_col;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1622 oap->start_vcol += ind_post_vcol - ind_pre_vcol;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1623 oap->end.col += ind_post_col - ind_pre_col;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1624 oap->end_vcol += ind_post_vcol - ind_pre_vcol;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1625 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1626 block_prep(oap, &bd2, oap->start.lnum, TRUE);
26313
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1627 if (did_indent && bd.textcol - ind_post_col > 0)
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1628 {
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1629 // undo for where "oap" is used below
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1630 oap->start.col -= ind_post_col - ind_pre_col;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1631 oap->start_vcol -= ind_post_vcol - ind_pre_vcol;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1632 oap->end.col -= ind_post_col - ind_pre_col;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1633 oap->end_vcol -= ind_post_vcol - ind_pre_vcol;
74e706afae3f patch 8.2.3687: blockwise insert does not handle autoindent properly
Bram Moolenaar <Bram@vim.org>
parents: 26307
diff changeset
1634 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 if (!bd.is_MAX || bd2.textlen < bd.textlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 pre_textlen += bd2.textlen - bd.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 if (bd2.endspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 --bd2.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 bd.textcol = bd2.textcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 bd.textlen = bd2.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648 * Subsequent calls to ml_get() flush the firstline data - take a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 * copy of the required string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 */
13814
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1651 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
1652 len = STRLEN(firstline);
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1653 add = bd.textcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1654 if (oap->op_type == OP_APPEND)
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1655 {
13814
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1656 add += bd.textlen;
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1657 // account for pressing cursor in insert mode when '$' was used
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1658 if (bd.is_MAX
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1659 && (start_insert.lnum == Insstart.lnum
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1660 && start_insert.col > Insstart.col))
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1661 {
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1662 offset = (start_insert.col - Insstart.col);
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1663 add -= offset;
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1664 if (oap->end_vcol > offset)
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1665 oap->end_vcol -= (offset + 1);
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1666 else
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1667 // moved outside of the visual block, what to do?
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1668 return;
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1669 }
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1670 }
13814
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1671 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
1672 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
1673 else
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1674 firstline += add;
25072
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1675 if (pre_textlen >= 0 && (ins_len =
bd46322bea66 patch 8.2.3073: when cursor is move for block append wrong text is inserted
Bram Moolenaar <Bram@vim.org>
parents: 25064
diff changeset
1676 (long)STRLEN(firstline) - pre_textlen - offset) > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 {
20830
9064044fd4f6 patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents: 20822
diff changeset
1678 ins_text = vim_strnsave(firstline, ins_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 if (ins_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1681 // block handled here
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 if (u_save(oap->start.lnum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 (linenr_T)(oap->end.lnum + 1)) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 block_insert(oap, ins_text, (oap->op_type == OP_INSERT),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 &bd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 curwin->w_cursor.col = oap->start.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1688 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 vim_free(ins_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1694
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1695 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1696 * op_change - handle a change operation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 * return TRUE if edit() returns because of a CTRL-O command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1701 op_change(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 colnr_T l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 long offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 linenr_T linenr;
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1707 long ins_len;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1708 long pre_textlen = 0;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1709 long pre_indent = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 char_u *firstline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 char_u *ins_text, *newp, *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714 l = oap->start.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 l = 0;
28856
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 28854
diff changeset
1718 can_si = may_do_si(); // Like opening a new line, do smart indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1721 // First delete the text in the region. In an empty buffer only need to
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1722 // save for undo
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 if (curbuf->b_ml.ml_flags & ML_EMPTY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1725 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728 else if (op_delete(oap) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11065
diff changeset
1731 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 && !virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1735 // check for still on same line (<CR> in inserted text meaningless)
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1736 // skip blank lines too
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1737 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1738 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1739 // Add spaces before getting the current line length.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 if (virtual_op && (curwin->w_cursor.coladd > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 || gchar_cursor() == NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742 coladvance_force(getviscol());
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1743 firstline = ml_get(oap->start.lnum);
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1744 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
1745 pre_indent = (long)getwhitecols(firstline);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 bd.textcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 fix_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1752 retval = edit(NUL, FALSE, (linenr_T)1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1753
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 /*
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
1755 * In Visual block mode, handle copying the new text to all lines of the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 * block.
1477
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1757 * Don't repeat the insert when Insert mode ended with CTRL-C.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1758 */
1477
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1759 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1760 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1761 // Auto-indenting may have changed the indent. If the cursor was past
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1762 // the indent, exclude that indent change from the inserted text.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1763 firstline = ml_get(oap->start.lnum);
1403
871231399cf5 updated for version 7.1-118
vimboss
parents: 1392
diff changeset
1764 if (bd.textcol > (colnr_T)pre_indent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1765 {
12323
4dba3e4f3b01 patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents: 11997
diff changeset
1766 long new_indent = (long)getwhitecols(firstline);
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1767
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1768 pre_textlen += new_indent - pre_indent;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1769 bd.textcol += new_indent - pre_indent;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1770 }
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1771
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1772 ins_len = (long)STRLEN(firstline) - pre_textlen;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1773 if (ins_len > 0)
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1774 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1775 // Subsequent calls to ml_get() flush the firstline data - take a
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1776 // 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
1777 if ((ins_text = alloc(ins_len + 1)) != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 356
diff changeset
1779 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 linenr++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783 block_prep(oap, &bd, linenr, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 if (!bd.is_short || virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 pos_T vpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1788 // If the block starts in virtual space, count the
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1789 // initial coladd offset as part of "startspaces"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 if (bd.is_short)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 {
1982
b1b09b68d706 updated for version 7.2-279
vimboss
parents: 1969
diff changeset
1792 vpos.lnum = linenr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 (void)getvpos(&vpos, oap->start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1794 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 vpos.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 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
1798 newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1800 continue;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1801 // copy up to block start
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 mch_memmove(newp, oldp, (size_t)bd.textcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 offset = bd.textcol;
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1804 vim_memset(newp + offset, ' ', (size_t)vpos.coladd);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1805 offset += vpos.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 mch_memmove(newp + offset, ins_text, (size_t)ins_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 offset += ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 oldp += bd.textcol;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1563
diff changeset
1809 STRMOVE(newp + offset, oldp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810 ml_replace(linenr, newp, FALSE);
28869
6a4edacbd178 patch 8.2.4957: text properties in a wrong position after a block change
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1811 #ifdef FEAT_PROP_POPUP
6a4edacbd178 patch 8.2.4957: text properties in a wrong position after a block change
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1812 // Shift the properties for linenr as edit() would do.
6a4edacbd178 patch 8.2.4957: text properties in a wrong position after a block change
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1813 if (curbuf->b_has_textprop)
6a4edacbd178 patch 8.2.4957: text properties in a wrong position after a block change
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1814 adjust_prop_columns(linenr, bd.textcol,
6a4edacbd178 patch 8.2.4957: text properties in a wrong position after a block change
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1815 vpos.coladd + ins_len, 0);
6a4edacbd178 patch 8.2.4957: text properties in a wrong position after a block change
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
1816 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1821 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1822 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1823 vim_free(ins_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1824 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1825 }
25666
649d3e9c5914 patch 8.2.3369: auto formatting after "cw" leaves cursor in wrong spot
Bram Moolenaar <Bram@vim.org>
parents: 25487
diff changeset
1826 auto_format(FALSE, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1827
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1828 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1829 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 /*
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1832 * When the cursor is on the NUL past the end of the line and it should not be
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1833 * there move it left.
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1834 */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1835 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1836 adjust_cursor_eol(void)
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1837 {
25380
ac88cd21ae88 patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents: 25072
diff changeset
1838 unsigned int cur_ve_flags = get_ve_flags();
ac88cd21ae88 patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents: 25072
diff changeset
1839
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1840 if (curwin->w_cursor.col > 0
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1841 && gchar_cursor() == NUL
25380
ac88cd21ae88 patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents: 25072
diff changeset
1842 && (cur_ve_flags & VE_ONEMORE) == 0
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28169
diff changeset
1843 && !(restart_edit || (State & MODE_INSERT)))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1845 // Put the cursor on the last character in the line.
555
a5efb97bc104 updated for version 7.0157
vimboss
parents: 530
diff changeset
1846 dec_cursor();
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1847
25380
ac88cd21ae88 patch 8.2.3227: 'virtualedit' can only be set globally
Bram Moolenaar <Bram@vim.org>
parents: 25072
diff changeset
1848 if (cur_ve_flags == VE_ALL)
557
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1849 {
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1850 colnr_T scol, ecol;
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1851
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1852 // Coladd is set to the width of the last character.
557
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1853 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1854 curwin->w_cursor.coladd = ecol - scol + 1;
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1855 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1857 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1858
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1859 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1860 * If "process" is TRUE and the line begins with a comment leader (possibly
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1861 * after some white space), return a pointer to the text after it. Put a boolean
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1862 * value indicating whether the line ends with an unclosed comment in
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1863 * "is_comment".
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1864 * line - line to be processed,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1865 * process - if FALSE, will only check whether the line ends with an unclosed
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
1866 * comment,
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1867 * include_space - whether to also skip space following the comment leader,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1868 * is_comment - will indicate whether the current line ends with an unclosed
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
1869 * comment.
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1870 */
11131
8d9ecf09183a patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
1871 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1872 skip_comment(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1873 char_u *line,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1874 int process,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1875 int include_space,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1876 int *is_comment)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1877 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1878 char_u *comment_flags = NULL;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1879 int lead_len;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1880 int leader_offset = get_last_leader_offset(line, &comment_flags);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1881
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1882 *is_comment = FALSE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1883 if (leader_offset != -1)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1884 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1885 // Let's check whether the line ends with an unclosed comment.
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1886 // If the last comment leader has COM_END in flags, there's no comment.
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1887 while (*comment_flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1888 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1889 if (*comment_flags == COM_END
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1890 || *comment_flags == ':')
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1891 break;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1892 ++comment_flags;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1893 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1894 if (*comment_flags != COM_END)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1895 *is_comment = TRUE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1896 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1897
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1898 if (process == FALSE)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1899 return line;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1900
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1901 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1902
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1903 if (lead_len == 0)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1904 return line;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1905
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1906 // Find:
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1907 // - COM_END,
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1908 // - colon,
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1909 // whichever comes first.
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1910 while (*comment_flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1911 {
3580
297771eff080 updated for version 7.3.550
Bram Moolenaar <bram@vim.org>
parents: 3576
diff changeset
1912 if (*comment_flags == COM_END
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1913 || *comment_flags == ':')
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1914 break;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1915 ++comment_flags;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1916 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1917
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1918 // If we found a colon, it means that we are not processing a line
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1919 // starting with a closing part of a three-part comment. That's good,
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1920 // because we don't want to remove those as this would be annoying.
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1921 if (*comment_flags == ':' || *comment_flags == NUL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1922 line += lead_len;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1923
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1924 return line;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1925 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1926
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 /*
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1928 * 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
1929 * When "save_undo" is TRUE save lines for undo first.
5848
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
1930 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
1931 * leaders should not be removed.
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
1932 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
1933 * to set those marks.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 *
1217
82274b284600 updated for version 7.1b
vimboss
parents: 1157
diff changeset
1935 * return FAIL for failure, OK otherwise
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1936 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1937 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1938 do_join(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1939 long count,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1940 int insert_space,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1941 int save_undo,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1942 int use_formatoptions UNUSED,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1943 int setmark)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 {
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1945 char_u *curr = NULL;
2597
c3b5d3fe9404 updated for version 7.3.020
Bram Moolenaar <bram@vim.org>
parents: 2451
diff changeset
1946 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
1947 char_u *cend;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1948 char_u *newp;
20583
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
1949 size_t newp_len;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1950 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
1951 int endcurr1 = NUL;
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2298
diff changeset
1952 int endcurr2 = NUL;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1953 int currsize = 0; // size of the current line
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1954 int sumsize = 0; // size of the long new line
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1955 linenr_T t;
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1956 colnr_T col = 0;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1957 int ret = OK;
3574
4f4db5d661c4 updated for version 7.3.547
Bram Moolenaar <bram@vim.org>
parents: 3562
diff changeset
1958 int *comments = NULL;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1959 int remove_comments = (use_formatoptions == TRUE)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1960 && has_format_option(FO_REMOVE_COMS);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1961 int prev_was_comment;
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
1962 #ifdef FEAT_PROP_POPUP
20583
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
1963 int propcount = 0; // number of props over all joined lines
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
1964 int props_remaining;
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1965 #endif
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1966
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1967 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
1968 (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
1969 return FAIL;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1970
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1971 // Allocate an array to store the number of spaces inserted before each
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1972 // line. We will use it to pre-compute the length of the new line and the
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
1973 // 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
1974 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
1975 if (spaces == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 return FAIL;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1977 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1978 {
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
1979 comments = lalloc_clear(count * sizeof(int), TRUE);
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1980 if (comments == NULL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1981 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1982 vim_free(spaces);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1983 return FAIL;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1984 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1985 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1986
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1987 /*
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1988 * 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
1989 * 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
1990 * This loops forward over the joined lines.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1991 */
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1992 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
1993 {
2597
c3b5d3fe9404 updated for version 7.3.020
Bram Moolenaar <bram@vim.org>
parents: 2451
diff changeset
1994 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
20583
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
1995 #ifdef FEAT_PROP_POPUP
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
1996 propcount += count_props((linenr_T) (curwin->w_cursor.lnum + t), t > 0);
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
1997 #endif
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
1998 if (t == 0 && setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
5664
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
1999 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2000 // Set the '[ mark.
5664
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
2001 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum;
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
2002 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr);
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
2003 }
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2004 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2005 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2006 // We don't want to remove the comment leader if the
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2007 // previous line is not a comment.
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2008 if (t > 0 && prev_was_comment)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2009 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2010
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2011 char_u *new_curr = skip_comment(curr, TRUE, insert_space,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2012 &prev_was_comment);
3576
8625e38066db updated for version 7.3.548
Bram Moolenaar <bram@vim.org>
parents: 3574
diff changeset
2013 comments[t] = (int)(new_curr - curr);
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2014 curr = new_curr;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2015 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2016 else
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2017 curr = skip_comment(curr, FALSE, insert_space,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2018 &prev_was_comment);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2019 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2020
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2021 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
2022 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2023 curr = skipwhite(curr);
18599
9cbdd58eeeb2 patch 8.1.2293: join adds trailing space when second line is empty
Bram Moolenaar <Bram@vim.org>
parents: 18574
diff changeset
2024 if (*curr != NUL && *curr != ')'
18914
4c0b420e7327 patch 8.2.0018: :join does not add white space where it should
Bram Moolenaar <Bram@vim.org>
parents: 18882
diff changeset
2025 && sumsize != 0 && endcurr1 != TAB
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2026 && (!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
2027 || (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
2028 && (!has_format_option(FO_MBYTE_JOIN2)
20695
cea8ae407452 patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents: 20655
diff changeset
2029 || (mb_ptr2char(curr) < 0x100
cea8ae407452 patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents: 20655
diff changeset
2030 && !(enc_utf8 && utf_eat_space(endcurr1)))
cea8ae407452 patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents: 20655
diff changeset
2031 || (endcurr1 < 0x100
cea8ae407452 patch 8.2.0901: formatting CJK text isn't optimal
Bram Moolenaar <Bram@vim.org>
parents: 20655
diff changeset
2032 && !(enc_utf8 && utf_eat_space(mb_ptr2char(curr)))))
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2033 )
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2034 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2035 // don't add a space if the line is ending in a space
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2036 if (endcurr1 == ' ')
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2037 endcurr1 = endcurr2;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2038 else
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2039 ++spaces[t];
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2040 // extra space when 'joinspaces' set and line ends in '.'
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2041 if ( p_js
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2042 && (endcurr1 == '.'
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2043 || (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
2044 && (endcurr1 == '?' || endcurr1 == '!'))))
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2045 ++spaces[t];
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2046 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2047 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2048 currsize = (int)STRLEN(curr);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2049 sumsize += currsize + spaces[t];
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2050 endcurr1 = endcurr2 = NUL;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2051 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
2052 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2053 if (has_mbyte)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2054 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2055 cend = curr + currsize;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2056 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
2057 endcurr1 = (*mb_ptr2char)(cend);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2058 if (cend > curr)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2059 {
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2060 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
2061 endcurr2 = (*mb_ptr2char)(cend);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2062 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2063 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2064 else
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2065 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2066 endcurr1 = *(curr + currsize - 1);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2067 if (currsize > 1)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2068 endcurr2 = *(curr + currsize - 2);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2069 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2070 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2071 line_breakcheck();
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2072 if (got_int)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2073 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2074 ret = FAIL;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2075 goto theend;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2076 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2077 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2078
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2079 // store the column position before last line
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2080 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
2081
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2082 // allocate the space for the new line
20583
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2083 newp_len = sumsize + 1;
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2084 #ifdef FEAT_PROP_POPUP
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2085 newp_len += propcount * sizeof(textprop_T);
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2086 #endif
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2087 newp = alloc(newp_len);
17797
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2088 if (newp == NULL)
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2089 {
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2090 ret = FAIL;
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2091 goto theend;
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2092 }
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2093 cend = newp + sumsize;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2094 *cend = 0;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2095
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2096 /*
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2097 * 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
2098 * 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
2099 *
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2100 * 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
2101 * 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
2102 * 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
2103 */
20583
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2104 #ifdef FEAT_PROP_POPUP
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2105 props_remaining = propcount;
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2106 #endif
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2107 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
2108 {
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2109 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
2110
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2111 cend -= currsize;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2112 mch_memmove(cend, curr, (size_t)currsize);
20583
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2113
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2114 if (spaces[t] > 0)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2115 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2116 cend -= spaces[t];
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
2117 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
2118 }
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2119
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2120 // 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
2121 // 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
2122 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
2123
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
2124 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, -t,
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2125 (long)(cend - newp - spaces_removed), spaces_removed);
20583
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2126 #ifdef FEAT_PROP_POPUP
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2127 prepend_joined_props(newp + sumsize + 1, propcount, &props_remaining,
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2128 curwin->w_cursor.lnum + t, t == count - 1,
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2129 (long)(cend - newp), spaces_removed);
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2130 #endif
d067be761cd7 patch 8.2.0845: text properties crossing lines not handled correctly
Bram Moolenaar <Bram@vim.org>
parents: 20237
diff changeset
2131
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2132 if (t == 0)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2133 break;
2597
c3b5d3fe9404 updated for version 7.3.020
Bram Moolenaar <bram@vim.org>
parents: 2451
diff changeset
2134 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1));
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2135 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2136 curr += comments[t - 1];
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2137 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
2138 curr = skipwhite(curr);
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 }
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2141
20655
707b21559848 patch 8.2.0881: compiler warning for argument type
Bram Moolenaar <Bram@vim.org>
parents: 20613
diff changeset
2142 ml_replace_len(curwin->w_cursor.lnum, newp, (colnr_T)newp_len, TRUE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2143
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
2144 if (setmark && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
5848
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
2145 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2146 // Set the '] mark.
5848
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
2147 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
2148 curwin->w_buffer->b_op_end.col = (colnr_T)sumsize;
5848
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
2149 }
5664
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
2150
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2151 // Only report the change in the first line here, del_lines() will report
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2152 // the deleted line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 changed_lines(curwin->w_cursor.lnum, currsize,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 curwin->w_cursor.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 /*
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2156 * Delete following lines. To do this we move the cursor there
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 * briefly, and then move it back. After del_lines() the cursor may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2158 * have moved up (last line deleted), so the current lnum is kept in t.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160 t = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 ++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
2162 del_lines(count - 1, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2163 curwin->w_cursor.lnum = t;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2164
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2165 /*
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2166 * Set the cursor column:
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2167 * 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
2168 * vim: use the column of the last join
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2169 */
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2170 curwin->w_cursor.col =
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2171 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172 check_cursor_col();
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2173
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2174 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2175 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2176
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2177 theend:
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2178 vim_free(spaces);
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2179 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2180 vim_free(comments);
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2181 return ret;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 * prepare a few things for block mode yank/delete/tilde
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2186 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2187 * for delete:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2188 * - textlen includes the first/last char to be (partly) deleted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2189 * - start/endspaces is the number of columns that are taken by the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2190 * first/last deleted char minus the number of columns that have to be
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
2191 * deleted.
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
2192 * for yank and tilde:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 * - textlen includes the first/last char to be wholly yanked
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 * - start/endspaces is the number of columns of the first/last yanked char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 * that are to be yanked.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 */
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18100
diff changeset
2197 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2198 block_prep(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2199 oparg_T *oap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2200 struct block_def *bdp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2201 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2202 int is_del)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 int incr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 char_u *pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 char_u *pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 char_u *prev_pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 char_u *prev_pend;
19176
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2210 #ifdef FEAT_LINEBREAK
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2211 int lbr_saved = curwin->w_p_lbr;
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2212
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2213 // Avoid a problem with unwanted linebreaks in block mode.
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2214 curwin->w_p_lbr = FALSE;
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2215 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 bdp->startspaces = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 bdp->endspaces = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 bdp->textlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 bdp->start_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 bdp->end_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 bdp->is_short = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 bdp->is_oneChar = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 bdp->pre_whitesp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 bdp->pre_whitesp_c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 bdp->end_char_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 bdp->start_char_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 line = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229 pstart = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 prev_pstart = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 while (bdp->start_vcol < oap->start_vcol && *pstart)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2233 // Count a tab for what it's worth (if list mode not on)
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
2234 incr = lbr_chartabsize(line, pstart, bdp->start_vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 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
2236 if (VIM_ISWHITE(*pstart))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2237 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 bdp->pre_whitesp += incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 bdp->pre_whitesp_c++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2242 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 bdp->pre_whitesp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 bdp->pre_whitesp_c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 prev_pstart = pstart;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2247 MB_PTR_ADV(pstart);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2248 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 bdp->start_char_vcols = incr;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2250 if (bdp->start_vcol < oap->start_vcol) // line too short
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 bdp->end_vcol = bdp->start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 bdp->is_short = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 if (!is_del || oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2257 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2259 // notice: this converts partly selected Multibyte characters to
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2260 // spaces, too.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2261 bdp->startspaces = bdp->start_vcol - oap->start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2262 if (is_del && bdp->startspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 pend = pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265 bdp->end_vcol = bdp->start_vcol;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2266 if (bdp->end_vcol > oap->end_vcol) // it's all in one character
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 bdp->is_oneChar = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269 if (oap->op_type == OP_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 else if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2279 if (is_del && oap->op_type != OP_LSHIFT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2280 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2281 // just putting the sum of those two into
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2282 // bdp->startspaces doesn't work for Visual replace,
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2283 // so we have to split the tab in two
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 bdp->startspaces = bdp->start_char_vcols
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 - (bdp->start_vcol - oap->start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2288 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 prev_pend = pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2295 // Count a tab for what it's worth (if list mode not on)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 prev_pend = pend;
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
2297 incr = lbr_chartabsize_adv(line, &pend, bdp->end_vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 bdp->end_vcol += incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300 if (bdp->end_vcol <= oap->end_vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2301 && (!is_del
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2302 || oap->op_type == OP_APPEND
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2303 || oap->op_type == OP_REPLACE)) // line too short
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 bdp->is_short = TRUE;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2306 // Alternative: include spaces to fill up the block.
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2307 // Disadvantage: can lead to trailing spaces when the line is
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2308 // short where the text is put
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2309 // if (!is_del || oap->op_type == OP_APPEND)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310 if (oap->op_type == OP_APPEND || virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 bdp->endspaces = oap->end_vcol - bdp->end_vcol
593
d220eb88e4e4 updated for version 7.0168
vimboss
parents: 557
diff changeset
2312 + oap->inclusive;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 else
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2314 bdp->endspaces = 0; // replace doesn't add characters
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 else if (bdp->end_vcol > oap->end_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 if (!is_del && bdp->endspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 bdp->endspaces = incr - bdp->endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 if (pend != pstart)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 pend = prev_pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2325 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2326 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2327 bdp->end_char_vcols = incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 if (is_del && bdp->startspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329 pstart = prev_pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2330 bdp->textlen = (int)(pend - pstart);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2331 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2332 bdp->textcol = (colnr_T) (pstart - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2333 bdp->textstart = pstart;
19176
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2334 #ifdef FEAT_LINEBREAK
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2335 curwin->w_p_lbr = lbr_saved;
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
2336 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2337 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2338
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2339 /*
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2340 * Handle the add/subtract operator.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2341 */
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2342 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2343 op_addsub(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2344 oparg_T *oap,
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2345 linenr_T Prenum1, // Amount of add/subtract
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2346 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
2347 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2348 pos_T pos;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2349 struct block_def bd;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2350 int change_cnt = 0;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2351 linenr_T amount = Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2352
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2353 // 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
2354 // 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
2355 // 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
2356 #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
2357 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
2358 #endif
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2359
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2360 if (!VIsual_active)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2361 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2362 pos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2363 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
2364 {
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2365 #ifdef FEAT_FOLDING
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2366 disable_fold_update--;
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2367 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2368 return;
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2369 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2370 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
2371 #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
2372 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
2373 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2374 if (change_cnt)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2375 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
2376 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2377 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2378 {
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2379 int one_change;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2380 int length;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2381 pos_T startpos;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2382
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2383 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
2384 (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
2385 {
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2386 #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
2387 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
2388 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2389 return;
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2390 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2391
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2392 pos = oap->start;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2393 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
2394 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2395 if (oap->block_mode) // Visual block mode
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2396 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2397 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
2398 pos.col = bd.textcol;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2399 length = bd.textlen;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2400 }
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2401 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
2402 {
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2403 curwin->w_cursor.col = 0;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2404 pos.col = 0;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2405 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
2406 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2407 else // oap->motion_type == MCHAR
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2408 {
12996
973a0037f4c3 patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents: 12642
diff changeset
2409 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
2410 dec(&(oap->end));
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2411 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
2412 pos.col = 0;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2413 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
2414 {
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2415 pos.col += oap->start.col;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2416 length -= oap->start.col;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2417 }
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2418 if (pos.lnum == oap->end.lnum)
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2419 {
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2420 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
2421 if (oap->end.col >= length)
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2422 oap->end.col = length - 1;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2423 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
2424 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2425 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2426 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
2427 if (one_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2428 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2429 // Remember the start position of the first change.
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2430 if (change_cnt == 0)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2431 startpos = curbuf->b_op_start;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2432 ++change_cnt;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2433 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2434
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2435 #ifdef FEAT_NETBEANS_INTG
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2436 if (netbeans_active() && one_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2437 {
24756
ac7ad168caed patch 8.2.2916: operators are not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
2438 char_u *ptr;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2439
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2440 netbeans_removed(curbuf, pos.lnum, pos.col, (long)length);
24756
ac7ad168caed patch 8.2.2916: operators are not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 24665
diff changeset
2441 ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2442 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
2443 &ptr[pos.col], length);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2444 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2445 #endif
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2446 if (g_cmd && one_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2447 amount += Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2448 }
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2449
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2450 #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
2451 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
2452 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2453 if (change_cnt)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2454 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
2455
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2456 if (!change_cnt && oap->is_VIsual)
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2457 // No change: need to remove the Visual selection
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2458 redraw_curbuf_later(INVERTED);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2459
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2460 // Set '[ mark if something changed. Keep the last end
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2461 // position from do_addsub().
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
2462 if (change_cnt > 0 && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2463 curbuf->b_op_start = startpos;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2464
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2465 if (change_cnt > p_report)
19760
9daed26b788b patch 8.2.0436: no warnings for incorrect printf arguments
Bram Moolenaar <Bram@vim.org>
parents: 19665
diff changeset
2466 smsg(NGETTEXT("%d line changed", "%d lines changed",
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
2467 change_cnt), change_cnt);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2468 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2469 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2470
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2471 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2472 * 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
2473 * 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
2474 *
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2475 * 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
2476 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2477 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2478 do_addsub(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2479 int op_type,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2480 pos_T *pos,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2481 int length,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2482 linenr_T Prenum1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 int col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 char_u *buf1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 char_u buf2[NUMBUFLEN];
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2487 int pre; // 'X'/'x': hex; '0': octal; 'B'/'b': bin
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2488 static int hexupper = FALSE; // 0xABC
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2489 uvarnumber_T n;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2490 uvarnumber_T oldn;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 int todel;
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2494 int do_hex;
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2495 int do_oct;
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2496 int do_bin;
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2497 int do_alpha;
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2498 int do_unsigned;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 int firstdigit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2500 int subtract;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2501 int negative = FALSE;
6891
f9876721bedc patch 7.4.765
Bram Moolenaar <bram@vim.org>
parents: 6868
diff changeset
2502 int was_positive = TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2503 int visual = VIsual_active;
6921
1f78058351a6 patch 7.4.779
Bram Moolenaar <bram@vim.org>
parents: 6919
diff changeset
2504 int did_change = FALSE;
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2505 pos_T save_cursor = curwin->w_cursor;
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
2506 int maxlen = 0;
7570
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
2507 pos_T startpos;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
2508 pos_T endpos;
20822
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2509 colnr_T save_coladd = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2510
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2511 do_hex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX"
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2512 do_oct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal"
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2513 do_bin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin"
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2514 do_alpha = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha"
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2515 do_unsigned = (vim_strchr(curbuf->b_p_nf, 'u') != NULL); // "Unsigned"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516
20822
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2517 if (virtual_active())
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2518 {
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2519 save_coladd = pos->coladd;
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2520 pos->coladd = 0;
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2521 }
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2522
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2523 curwin->w_cursor = *pos;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2524 ptr = ml_get(pos->lnum);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2525 col = pos->col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2526
20822
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2527 if (*ptr == NUL || col + !!save_coladd >= (int)STRLEN(ptr))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2528 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2529
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2530 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2531 * First check if we are on a hexadecimal number, after the "0x".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 */
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2533 if (!VIsual_active)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2534 {
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2535 if (do_bin)
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2536 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
2537 {
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2538 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2539 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2540 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
2541 }
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2542
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2543 if (do_hex)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2544 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
2545 {
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2546 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2547 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2548 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
2549 }
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2550
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2551 if ( do_bin
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2552 && do_hex
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2553 && ! ((col > 0
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2554 && (ptr[col] == 'X'
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2555 || ptr[col] == 'x')
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2556 && ptr[col - 1] == '0'
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2557 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2558 !(*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
2559 && vim_isxdigit(ptr[col + 1]))))
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2560 {
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2561
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2562 // In case of binary/hexadecimal pattern overlap match, rescan
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2563
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2564 col = pos->col;
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2565
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2566 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
2567 {
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2568 col--;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2569 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2570 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
2571 }
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2572 }
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2573
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2574 if (( do_hex
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2575 && col > 0
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2576 && (ptr[col] == 'X'
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2577 || ptr[col] == 'x')
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2578 && ptr[col - 1] == '0'
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2579 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2580 !(*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
2581 && vim_isxdigit(ptr[col + 1])) ||
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2582 ( do_bin
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2583 && col > 0
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2584 && (ptr[col] == 'B'
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2585 || ptr[col] == 'b')
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
2586 && ptr[col - 1] == '0'
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2587 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2588 !(*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
2589 && vim_isbdigit(ptr[col + 1])))
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2590 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2591 // Found hexadecimal or binary number, move to its start.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2593 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2594 col -= (*mb_head_off)(ptr, ptr + col);
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2595 }
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2596 else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2597 {
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2598 /*
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2599 * Search forward and then backward to find the start of number.
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2600 */
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2601 col = pos->col;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2602
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2603 while (ptr[col] != NUL
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2604 && !vim_isdigit(ptr[col])
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2605 && !(do_alpha && ASCII_ISALPHA(ptr[col])))
18251
c8a53c0daeed patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18219
diff changeset
2606 col += mb_ptr2len(ptr + col);
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2607
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2608 while (col > 0
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2609 && vim_isdigit(ptr[col - 1])
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2610 && !(do_alpha && ASCII_ISALPHA(ptr[col])))
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2611 {
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2612 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2613 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2614 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
2615 }
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2616 }
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2617 }
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2618
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2619 if (visual)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2620 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2621 while (ptr[col] != NUL && length > 0
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2622 && !vim_isdigit(ptr[col])
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2623 && !(do_alpha && ASCII_ISALPHA(ptr[col])))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2624 {
18251
c8a53c0daeed patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18219
diff changeset
2625 int mb_len = mb_ptr2len(ptr + col);
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2626
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2627 col += mb_len;
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2628 length -= mb_len;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2629 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2630
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2631 if (length == 0)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2632 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2633
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2634 if (col > pos->col && ptr[col - 1] == '-'
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2635 && (!has_mbyte || !(*mb_head_off)(ptr, ptr + col - 1))
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2636 && !do_unsigned)
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2637 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2638 negative = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2639 was_positive = FALSE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2640 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2641 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2642
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2643 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2644 * 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
2645 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2646 firstdigit = ptr[col];
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2647 if (!VIM_ISDIGIT(firstdigit) && !(do_alpha && ASCII_ISALPHA(firstdigit)))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2648 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2649 beep_flush();
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2650 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2651 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2652
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2653 if (do_alpha && ASCII_ISALPHA(firstdigit))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2654 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2655 // decrement or increment alphabetic character
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2656 if (op_type == OP_NR_SUB)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2657 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2658 if (CharOrd(firstdigit) < Prenum1)
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
2659 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2660 if (isupper(firstdigit))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2661 firstdigit = 'A';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2662 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2663 firstdigit = 'a';
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
2664 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2665 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2666 firstdigit -= Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2667 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2668 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2669 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2670 if (26 - CharOrd(firstdigit) - 1 < Prenum1)
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
2671 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2672 if (isupper(firstdigit))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2673 firstdigit = 'Z';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2674 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2675 firstdigit = 'z';
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
2676 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2677 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2678 firstdigit += Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2679 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2680 curwin->w_cursor.col = col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2681 if (!did_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2682 startpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2683 did_change = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2684 (void)del_char(FALSE);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2685 ins_char(firstdigit);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2686 endpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2687 curwin->w_cursor.col = col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2688 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2689 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2690 {
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2691 pos_T save_pos;
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2692 int i;
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2693
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2694 if (col > 0 && ptr[col - 1] == '-'
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2695 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
2696 !(*mb_head_off)(ptr, ptr + col - 1))
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2697 && !visual
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2698 && !do_unsigned)
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2699 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2700 // negative number
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2701 --col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2702 negative = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2703 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2704 // get the number value (unsigned)
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2705 if (visual && VIsual_mode != 'V')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2706 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
2707 ? (int)STRLEN(ptr) - col
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2708 : length);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2709
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2710 vim_str2nr(ptr + col, &pre, &length,
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2711 0 + (do_bin ? STR2NR_BIN : 0)
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2712 + (do_oct ? STR2NR_OCT : 0)
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2713 + (do_hex ? STR2NR_HEX : 0),
16706
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
2714 NULL, &n, maxlen, FALSE);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2715
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2716 // ignore leading '-' for hex and octal and bin numbers
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2717 if (pre && negative)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2718 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2719 ++col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2720 --length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2721 negative = FALSE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2722 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2723 // add or subtract
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2724 subtract = FALSE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2725 if (op_type == OP_NR_SUB)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2726 subtract ^= TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2727 if (negative)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2728 subtract ^= TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2729
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2730 oldn = n;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2731 if (subtract)
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2732 n -= (uvarnumber_T)Prenum1;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2733 else
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2734 n += (uvarnumber_T)Prenum1;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2735 // handle wraparound for decimal numbers
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2736 if (!pre)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2737 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2738 if (subtract)
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
2739 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2740 if (n > oldn)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2741 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2742 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
2743 negative ^= TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2744 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2746 else
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2747 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2748 // add
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2749 if (n < oldn)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2750 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2751 n = (n ^ (uvarnumber_T)-1);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2752 negative ^= TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2753 }
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
2754 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2755 if (n == 0)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2756 negative = FALSE;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2757 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2758
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2759 if (do_unsigned && negative)
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2760 {
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2761 if (subtract)
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2762 // sticking at zero.
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2763 n = (uvarnumber_T)0;
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2764 else
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2765 // sticking at 2^64 - 1.
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2766 n = (uvarnumber_T)(-1);
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2767 negative = FALSE;
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2768 }
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2769
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2770 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
2771 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2772 // need to remove the '-'
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2773 col--;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2774 length++;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2775 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2776
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2777 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2778 * Delete the old number.
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2779 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2780 curwin->w_cursor.col = col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2781 if (!did_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2782 startpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2783 did_change = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2784 todel = length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2785 c = gchar_cursor();
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2786 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2787 * 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
2788 * 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
2789 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2790 if (c == '-')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2791 --length;
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2792
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2793 save_pos = curwin->w_cursor;
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2794 for (i = 0; i < todel; ++i)
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2795 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2796 if (c < 0x100 && isalpha(c))
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2797 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2798 if (isupper(c))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2799 hexupper = TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2800 else
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2801 hexupper = FALSE;
6891
f9876721bedc patch 7.4.765
Bram Moolenaar <bram@vim.org>
parents: 6868
diff changeset
2802 }
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2803 inc_cursor();
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2804 c = gchar_cursor();
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2805 }
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2806 curwin->w_cursor = save_pos;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2807
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2808 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2809 * Prepare the leading characters in buf1[].
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2810 * 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
2811 * Allocate a bit too much.
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2812 */
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2813 buf1 = alloc(length + NUMBUFLEN);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2814 if (buf1 == NULL)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2815 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2816 ptr = buf1;
8989
e600e696c0a1 commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
2817 if (negative && (!visual || was_positive))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2818 *ptr++ = '-';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2819 if (pre)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2820 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2821 *ptr++ = '0';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2822 --length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2823 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2824 if (pre == 'b' || pre == 'B' ||
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2825 pre == 'x' || pre == 'X')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2826 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2827 *ptr++ = pre;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2828 --length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2829 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2830
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2831 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2832 * Put the number characters in buf2[].
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2833 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2834 if (pre == 'b' || pre == 'B')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2835 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2836 int bit = 0;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2837 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
2838
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2839 // leading zeros
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2840 for (bit = bits; bit > 0; bit--)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2841 if ((n >> (bit - 1)) & 0x1) break;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2842
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2843 for (i = 0; bit > 0; bit--)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2844 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
2845
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2846 buf2[i] = '\0';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2847 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2848 else if (pre == 0)
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
2849 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2850 else if (pre == '0')
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
2851 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2852 else if (pre && hexupper)
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
2853 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2854 else
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
2855 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2856 length -= (int)STRLEN(buf2);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2857
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2858 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2859 * 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
2860 * 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
2861 * Don't do this when
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2862 * 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
2863 */
20613
9edb439adbea patch 8.2.0860: cannot use CTRL-A and CTRL-X on unsigned numbers
Bram Moolenaar <Bram@vim.org>
parents: 20583
diff changeset
2864 if (firstdigit == '0' && !(do_oct && pre == 0))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2865 while (length-- > 0)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
2866 *ptr++ = '0';
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2867 *ptr = NUL;
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2868
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2869 STRCAT(buf1, buf2);
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2870
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2871 // Insert just after the first character to be removed, so that any
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2872 // text properties will be adjusted. Then delete the old number
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2873 // afterwards.
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2874 save_pos = curwin->w_cursor;
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2875 if (todel > 0)
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2876 inc_cursor();
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2877 ins_str(buf1); // insert the new number
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2878 vim_free(buf1);
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2879
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2880 // del_char() will also mark line needing displaying
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2881 if (todel > 0)
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2882 {
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2883 int bytes_after = (int)STRLEN(ml_get_curline())
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2884 - curwin->w_cursor.col;
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2885
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2886 // Delete the one character before the insert.
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2887 curwin->w_cursor = save_pos;
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2888 (void)del_char(FALSE);
22290
9debc021e99e patch 8.2.1694: compiler warning for loss if data
Bram Moolenaar <Bram@vim.org>
parents: 22282
diff changeset
2889 curwin->w_cursor.col = (colnr_T)(STRLEN(ml_get_curline())
9debc021e99e patch 8.2.1694: compiler warning for loss if data
Bram Moolenaar <Bram@vim.org>
parents: 22282
diff changeset
2890 - bytes_after);
22278
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2891 --todel;
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2892 }
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2893 while (todel-- > 0)
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2894 (void)del_char(FALSE);
0416105e103b patch 8.2.1688: increment/decrement removes text property
Bram Moolenaar <Bram@vim.org>
parents: 20830
diff changeset
2895
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2896 endpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2897 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
2898 --curwin->w_cursor.col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2899 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2900
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
2901 if (did_change && (cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
7570
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
2902 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2903 // set the '[ and '] marks
7570
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
2904 curbuf->b_op_start = startpos;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
2905 curbuf->b_op_end = endpos;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
2906 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
2907 --curbuf->b_op_end.col;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
2908 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2909
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2910 theend:
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2911 if (visual)
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2912 curwin->w_cursor = save_cursor;
8690
6a1becf4f282 commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents: 8399
diff changeset
2913 else if (did_change)
6a1becf4f282 commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents: 8399
diff changeset
2914 curwin->w_set_curswant = TRUE;
20822
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2915 else if (virtual_active())
8e5f991db3b4 patch 8.2.0963: number increment/decrement does not work with 'virtualedit'
Bram Moolenaar <Bram@vim.org>
parents: 20695
diff changeset
2916 curwin->w_cursor.coladd = save_coladd;
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2917
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2918 return did_change;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2919 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2920
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2921 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2922 clear_oparg(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2923 {
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19774
diff changeset
2924 CLEAR_POINTER(oap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2925 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2926
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2927 /*
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2928 * Count the number of bytes, characters and "words" in a line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2929 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2930 * "Words" are counted by looking for boundaries between non-space and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2931 * space characters. (it seems to produce results that match 'wc'.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2932 *
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2933 * Return value is byte count; word count for the line is added to "*wc".
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2934 * Char count is added to "*cc".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2935 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2936 * The function will only examine the first "limit" characters in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2937 * line, stopping if it encounters an end-of-line (NUL byte). In that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2938 * case, eol_size will be added to the character count to account for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2939 * the size of the EOL character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2940 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2941 static varnumber_T
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2942 line_count_info(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2943 char_u *line,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2944 varnumber_T *wc,
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2945 varnumber_T *cc,
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2946 varnumber_T limit,
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2947 int eol_size)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2948 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2949 varnumber_T i;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2950 varnumber_T words = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2951 varnumber_T chars = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2952 int is_word = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2953
3626
802b1a1b275f updated for version 7.3.573
Bram Moolenaar <bram@vim.org>
parents: 3584
diff changeset
2954 for (i = 0; i < limit && line[i] != NUL; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2955 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2956 if (is_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2957 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2958 if (vim_isspace(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2959 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2960 words++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2961 is_word = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2962 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2963 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2964 else if (!vim_isspace(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2965 is_word = 1;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2966 ++chars;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 446
diff changeset
2967 i += (*mb_ptr2len)(line + i);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2968 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2969
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2970 if (is_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2971 words++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2972 *wc += words;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2973
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
2974 // Add eol_size if the end of line was reached before hitting limit.
2996
b9182da84c7e updated for version 7.3.270
Bram Moolenaar <bram@vim.org>
parents: 2957
diff changeset
2975 if (i < limit && line[i] == NUL)
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2976 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2977 i += eol_size;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2978 chars += eol_size;
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2979 }
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
2980 *cc += chars;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2981 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2982 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2983
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2984 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2985 * Give some info about the position of the cursor (for "g CTRL-G").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2986 * In Visual mode, give some info about the selected region. (In this case,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2987 * 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
2988 * When "dict" is not NULL store the info there instead of showing it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2989 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2990 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2991 cursor_pos_info(dict_T *dict)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2992 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2993 char_u *p;
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
2994 char_u buf1[50];
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
2995 char_u buf2[40];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2996 linenr_T lnum;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2997 varnumber_T byte_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2998 varnumber_T bom_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
2999 varnumber_T byte_count_cursor = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3000 varnumber_T char_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3001 varnumber_T char_count_cursor = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3002 varnumber_T word_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3003 varnumber_T word_count_cursor = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3004 int eol_size;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3005 varnumber_T last_check = 100000L;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3006 long line_count_selected = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3007 pos_T min_pos, max_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3008 oparg_T oparg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3009 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3010
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3011 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3012 * Compute the length of the file in characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3013 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3014 if (curbuf->b_ml.ml_flags & ML_EMPTY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3015 {
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3016 if (dict == NULL)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3017 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
3018 msg(_(no_lines_msg));
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3019 return;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3020 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3022 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3024 if (get_fileformat(curbuf) == EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3025 eol_size = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 eol_size = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 if (VIsual_active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 {
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11065
diff changeset
3031 if (LT_POS(VIsual, curwin->w_cursor))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 min_pos = VIsual;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 max_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3035 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3036 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3037 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3038 min_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3039 max_pos = VIsual;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3040 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3041 if (*p_sel == 'e' && max_pos.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3042 --max_pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3044 if (VIsual_mode == Ctrl_V)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3045 {
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3046 #ifdef FEAT_LINEBREAK
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3047 char_u * saved_sbr = p_sbr;
18574
8b0114ffde2b patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents: 18481
diff changeset
3048 char_u * saved_w_sbr = curwin->w_p_sbr;
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3049
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3050 // Make 'sbr' empty for a moment to get the correct size.
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3051 p_sbr = empty_option;
18574
8b0114ffde2b patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents: 18481
diff changeset
3052 curwin->w_p_sbr = empty_option;
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3053 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3054 oparg.is_VIsual = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3055 oparg.block_mode = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 oparg.op_type = OP_NOP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 getvcols(curwin, &min_pos, &max_pos,
688
bcd2edc4539e updated for version 7.0207
vimboss
parents: 681
diff changeset
3058 &oparg.start_vcol, &oparg.end_vcol);
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3059 #ifdef FEAT_LINEBREAK
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3060 p_sbr = saved_sbr;
18574
8b0114ffde2b patch 8.1.2281: 'showbreak' cannot be set for one window
Bram Moolenaar <Bram@vim.org>
parents: 18481
diff changeset
3061 curwin->w_p_sbr = saved_w_sbr;
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3062 #endif
688
bcd2edc4539e updated for version 7.0207
vimboss
parents: 681
diff changeset
3063 if (curwin->w_curswant == MAXCOL)
bcd2edc4539e updated for version 7.0207
vimboss
parents: 681
diff changeset
3064 oparg.end_vcol = MAXCOL;
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3065 // Swap the start, end vcol if needed
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3066 if (oparg.end_vcol < oparg.start_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3067 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3068 oparg.end_vcol += oparg.start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3069 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3070 oparg.end_vcol -= oparg.start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3071 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3072 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3073 line_count_selected = max_pos.lnum - min_pos.lnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3074 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3075
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3076 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3077 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3078 // Check for a CTRL-C every 100000 characters.
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3079 if (byte_count > last_check)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3080 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3081 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3082 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3083 return;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3084 last_check = byte_count + 100000L;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3085 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3086
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3087 // Do extra processing for VIsual mode.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3088 if (VIsual_active
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3089 && lnum >= min_pos.lnum && lnum <= max_pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3090 {
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3091 char_u *s = NULL;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3092 long len = 0L;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3093
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3094 switch (VIsual_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3095 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3096 case Ctrl_V:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3097 virtual_op = virtual_active();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3098 block_prep(&oparg, &bd, lnum, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3099 virtual_op = MAYBE;
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3100 s = bd.textstart;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3101 len = (long)bd.textlen;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3102 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3103 case 'V':
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3104 s = ml_get(lnum);
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3105 len = MAXCOL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3106 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3107 case 'v':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3108 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3109 colnr_T start_col = (lnum == min_pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3110 ? min_pos.col : 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3111 colnr_T end_col = (lnum == max_pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3112 ? max_pos.col - start_col + 1 : MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3113
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3114 s = ml_get(lnum) + start_col;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3115 len = end_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3116 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3117 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 }
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3119 if (s != NULL)
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3120 {
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3121 byte_count_cursor += line_count_info(s, &word_count_cursor,
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3122 &char_count_cursor, len, eol_size);
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3123 if (lnum == curbuf->b_ml.ml_line_count
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3124 && !curbuf->b_p_eol
6933
62ba356c2d4e patch 7.4.785
Bram Moolenaar <bram@vim.org>
parents: 6929
diff changeset
3125 && (curbuf->b_p_bin || !curbuf->b_p_fixeol)
50
90188be4861f updated for version 7.0028
vimboss
parents: 45
diff changeset
3126 && (long)STRLEN(s) < len)
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3127 byte_count_cursor -= eol_size;
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3128 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3129 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3130 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3131 {
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3132 // In non-visual mode, check for the line the cursor is on
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3133 if (lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3134 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3135 word_count_cursor += word_count;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3136 char_count_cursor += char_count;
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3137 byte_count_cursor = byte_count +
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3138 line_count_info(ml_get(lnum),
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3139 &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
3140 (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
3141 eol_size);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3142 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3143 }
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3144 // Add to the running totals
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3145 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
3146 &char_count, (varnumber_T)MAXCOL,
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3147 eol_size);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3148 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3149
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3150 // Correction for when last line doesn't have an EOL.
6933
62ba356c2d4e patch 7.4.785
Bram Moolenaar <bram@vim.org>
parents: 6929
diff changeset
3151 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol))
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3152 byte_count -= eol_size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3153
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3154 if (dict == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3155 {
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3156 if (VIsual_active)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3157 {
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3158 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
3159 {
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3160 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
3161 &max_pos.col);
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3162 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
3163 (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
3164 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3165 else
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3166 buf1[0] = NUL;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3167
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3168 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
3169 && char_count == byte_count)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3170 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3171 _("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
3172 buf1, line_count_selected,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3173 (long)curbuf->b_ml.ml_line_count,
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3174 word_count_cursor,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3175 word_count,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3176 byte_count_cursor,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3177 byte_count);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3178 else
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3179 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3180 _("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
3181 buf1, line_count_selected,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3182 (long)curbuf->b_ml.ml_line_count,
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3183 word_count_cursor,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3184 word_count,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3185 char_count_cursor,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3186 char_count,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3187 byte_count_cursor,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3188 byte_count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3189 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3190 else
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3191 {
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3192 p = ml_get_curline();
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3193 validate_virtcol();
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3194 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
3195 (int)curwin->w_virtcol + 1);
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3196 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
3197 linetabsize(p));
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3198
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3199 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
3200 && char_count == byte_count)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3201 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3202 _("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
3203 (char *)buf1, (char *)buf2,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3204 (long)curwin->w_cursor.lnum,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3205 (long)curbuf->b_ml.ml_line_count,
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3206 word_count_cursor, word_count,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3207 byte_count_cursor, byte_count);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3208 else
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3209 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3210 _("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
3211 (char *)buf1, (char *)buf2,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3212 (long)curwin->w_cursor.lnum,
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3213 (long)curbuf->b_ml.ml_line_count,
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3214 word_count_cursor, word_count,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3215 char_count_cursor, char_count,
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3216 byte_count_cursor, byte_count);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3217 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3218 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3219
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3220 bom_count = bomb_size();
18062
0b351691071c patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 17797
diff changeset
3221 if (dict == NULL && bom_count > 0)
19005
53088656f5ed patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents: 18914
diff changeset
3222 {
53088656f5ed patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents: 18914
diff changeset
3223 size_t len = STRLEN(IObuff);
53088656f5ed patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents: 18914
diff changeset
3224
53088656f5ed patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents: 18914
diff changeset
3225 vim_snprintf((char *)IObuff + len, IOSIZE - len,
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27263
diff changeset
3226 _("(+%lld for BOM)"), bom_count);
19005
53088656f5ed patch 8.2.0063: wrong size argument to vim_snprintf()
Bram Moolenaar <Bram@vim.org>
parents: 18914
diff changeset
3227 }
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3228 if (dict == NULL)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3229 {
18062
0b351691071c patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 17797
diff changeset
3230 // 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
3231 p = p_shm;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3232 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
3233 msg((char *)IObuff);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3234 p_shm = p;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3235 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3236 }
7484
1fe988587423 commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents: 7480
diff changeset
3237 #if defined(FEAT_EVAL)
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3238 if (dict != NULL)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3239 {
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14216
diff changeset
3240 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
3241 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
3242 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
3243 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
3244 byte_count_cursor);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14216
diff changeset
3245 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
3246 char_count_cursor);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14216
diff changeset
3247 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
3248 word_count_cursor);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3249 }
7484
1fe988587423 commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents: 7480
diff changeset
3250 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3251 }
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3252
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3253 /*
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3254 * Handle indent and format operators and visual mode ":".
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3255 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3256 static void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3257 op_colon(oparg_T *oap)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3258 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3259 stuffcharReadbuff(':');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3260 if (oap->is_VIsual)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3261 stuffReadbuff((char_u *)"'<,'>");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3262 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3263 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3264 // Make the range look nice, so it can be repeated.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3265 if (oap->start.lnum == curwin->w_cursor.lnum)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3266 stuffcharReadbuff('.');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3267 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3268 stuffnumReadbuff((long)oap->start.lnum);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3269 if (oap->end.lnum != oap->start.lnum)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3270 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3271 stuffcharReadbuff(',');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3272 if (oap->end.lnum == curwin->w_cursor.lnum)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3273 stuffcharReadbuff('.');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3274 else if (oap->end.lnum == curbuf->b_ml.ml_line_count)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3275 stuffcharReadbuff('$');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3276 else if (oap->start.lnum == curwin->w_cursor.lnum)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3277 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3278 stuffReadbuff((char_u *)".+");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3279 stuffnumReadbuff((long)oap->line_count - 1);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3280 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3281 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3282 stuffnumReadbuff((long)oap->end.lnum);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3283 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3284 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3285 if (oap->op_type != OP_COLON)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3286 stuffReadbuff((char_u *)"!");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3287 if (oap->op_type == OP_INDENT)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3288 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3289 if (*get_equalprg() == NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3290 stuffReadbuff((char_u *)"indent");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3291 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3292 stuffReadbuff(get_equalprg());
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3293 stuffReadbuff((char_u *)"\n");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3294 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3295 else if (oap->op_type == OP_FORMAT)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3296 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3297 if (*curbuf->b_p_fp != NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3298 stuffReadbuff(curbuf->b_p_fp);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3299 else if (*p_fp != NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3300 stuffReadbuff(p_fp);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3301 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3302 stuffReadbuff((char_u *)"fmt");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3303 stuffReadbuff((char_u *)"\n']");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3304 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3305
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3306 // do_cmdline() does the rest
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3307 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3308
26175
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3309 // callback function for 'operatorfunc'
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3310 static callback_T opfunc_cb;
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3311
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3312 /*
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3313 * Process the 'operatorfunc' option value.
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3314 * Returns OK or FAIL.
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3315 */
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3316 int
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3317 set_operatorfunc_option(void)
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3318 {
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3319 return option_set_callback_func(p_opfunc, &opfunc_cb);
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3320 }
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3321
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3322 #if defined(EXITFREE) || defined(PROTO)
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3323 void
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3324 free_operatorfunc_option(void)
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3325 {
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3326 # ifdef FEAT_EVAL
26175
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3327 free_callback(&opfunc_cb);
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3328 # endif
26175
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3329 }
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3330 #endif
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3331
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
3332 #if defined(FEAT_EVAL) || defined(PROTO)
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3333 /*
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3334 * Mark the global 'operatorfunc' callback with 'copyID' so that it is not
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3335 * garbage collected.
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3336 */
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3337 int
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3338 set_ref_in_opfunc(int copyID UNUSED)
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3339 {
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3340 int abort = FALSE;
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3341
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3342 abort = set_ref_in_callback(&opfunc_cb, copyID);
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3343
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3344 return abort;
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3345 }
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26958
diff changeset
3346 #endif
26518
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3347
13ba00ef7687 patch 8.2.3788: lambda for option that is a function may be freed
Bram Moolenaar <Bram@vim.org>
parents: 26313
diff changeset
3348 /*
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3349 * Handle the "g@" operator: call 'operatorfunc'.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3350 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3351 static void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3352 op_function(oparg_T *oap UNUSED)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3353 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3354 #ifdef FEAT_EVAL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3355 typval_T argv[2];
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3356 int save_virtual_op = virtual_op;
26007
1d2e1c23e458 patch 8.2.3537: mode() does not return the right value in 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 25808
diff changeset
3357 int save_finish_op = finish_op;
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3358 pos_T orig_start = curbuf->b_op_start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3359 pos_T orig_end = curbuf->b_op_end;
26175
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3360 typval_T rettv;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3361
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3362 if (*p_opfunc == NUL)
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26903
diff changeset
3363 emsg(_(e_operatorfunc_is_empty));
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3364 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3365 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3366 // Set '[ and '] marks to text to be operated on.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3367 curbuf->b_op_start = oap->start;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3368 curbuf->b_op_end = oap->end;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3369 if (oap->motion_type != MLINE && !oap->inclusive)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3370 // Exclude the end position.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3371 decl(&curbuf->b_op_end);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3372
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3373 argv[0].v_type = VAR_STRING;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3374 if (oap->block_mode)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3375 argv[0].vval.v_string = (char_u *)"block";
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3376 else if (oap->motion_type == MLINE)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3377 argv[0].vval.v_string = (char_u *)"line";
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3378 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3379 argv[0].vval.v_string = (char_u *)"char";
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3380 argv[1].v_type = VAR_UNKNOWN;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3381
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3382 // Reset virtual_op so that 'virtualedit' can be changed in the
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3383 // function.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3384 virtual_op = MAYBE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3385
26007
1d2e1c23e458 patch 8.2.3537: mode() does not return the right value in 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 25808
diff changeset
3386 // Reset finish_op so that mode() returns the right value.
1d2e1c23e458 patch 8.2.3537: mode() does not return the right value in 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 25808
diff changeset
3387 finish_op = FALSE;
1d2e1c23e458 patch 8.2.3537: mode() does not return the right value in 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 25808
diff changeset
3388
26175
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3389 if (call_callback(&opfunc_cb, 0, &rettv, 1, argv) != FAIL)
6b4f017d7005 patch 8.2.3619: cannot use a lambda for 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 26007
diff changeset
3390 clear_tv(&rettv);
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3391
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3392 virtual_op = save_virtual_op;
26007
1d2e1c23e458 patch 8.2.3537: mode() does not return the right value in 'operatorfunc'
Bram Moolenaar <Bram@vim.org>
parents: 25808
diff changeset
3393 finish_op = save_finish_op;
22699
e82579016863 patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents: 22290
diff changeset
3394 if (cmdmod.cmod_flags & CMOD_LOCKMARKS)
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3395 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3396 curbuf->b_op_start = orig_start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3397 curbuf->b_op_end = orig_end;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3398 }
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3399 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3400 #else
26958
d92e0d85923f patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26903
diff changeset
3401 emsg(_(e_eval_feature_not_available));
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3402 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3403 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3404
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3405 /*
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3406 * Calculate start/end virtual columns for operating in block mode.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3407 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3408 static void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3409 get_op_vcol(
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3410 oparg_T *oap,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3411 colnr_T redo_VIsual_vcol,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3412 int initial) // when TRUE adjust position for 'selectmode'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3413 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3414 colnr_T start, end;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3415
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3416 if (VIsual_mode != Ctrl_V
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3417 || (!initial && oap->end.col < curwin->w_width))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3418 return;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3419
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3420 oap->block_mode = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3421
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3422 // prevent from moving onto a trail byte
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3423 if (has_mbyte)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3424 mb_adjustpos(curwin->w_buffer, &oap->end);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3425
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3426 getvvcol(curwin, &(oap->start), &oap->start_vcol, NULL, &oap->end_vcol);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3427
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3428 if (!redo_VIsual_busy)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3429 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3430 getvvcol(curwin, &(oap->end), &start, NULL, &end);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3431
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3432 if (start < oap->start_vcol)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3433 oap->start_vcol = start;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3434 if (end > oap->end_vcol)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3435 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3436 if (initial && *p_sel == 'e' && start >= 1
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3437 && start - 1 >= oap->end_vcol)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3438 oap->end_vcol = start - 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3439 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3440 oap->end_vcol = end;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3441 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3442 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3443
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3444 // if '$' was used, get oap->end_vcol from longest line
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3445 if (curwin->w_curswant == MAXCOL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3446 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3447 curwin->w_cursor.col = MAXCOL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3448 oap->end_vcol = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3449 for (curwin->w_cursor.lnum = oap->start.lnum;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3450 curwin->w_cursor.lnum <= oap->end.lnum;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3451 ++curwin->w_cursor.lnum)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3452 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3453 getvvcol(curwin, &curwin->w_cursor, NULL, NULL, &end);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3454 if (end > oap->end_vcol)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3455 oap->end_vcol = end;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3456 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3457 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3458 else if (redo_VIsual_busy)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3459 oap->end_vcol = oap->start_vcol + redo_VIsual_vcol - 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3460 // Correct oap->end.col and oap->start.col to be the
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3461 // upper-left and lower-right corner of the block area.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3462 //
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3463 // (Actually, this does convert column positions into character
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3464 // positions)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3465 curwin->w_cursor.lnum = oap->end.lnum;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3466 coladvance(oap->end_vcol);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3467 oap->end = curwin->w_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3468
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3469 curwin->w_cursor = oap->start;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3470 coladvance(oap->start_vcol);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3471 oap->start = curwin->w_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3472 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3473
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3474 // Information for redoing the previous Visual selection.
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3475 typedef struct {
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3476 int rv_mode; // 'v', 'V', or Ctrl-V
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3477 linenr_T rv_line_count; // number of lines
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3478 colnr_T rv_vcol; // number of cols or end column
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3479 long rv_count; // count for Visual operator
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3480 int rv_arg; // extra argument
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3481 } redo_VIsual_T;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3482
27140
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3483 static int
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3484 is_ex_cmdchar(cmdarg_T *cap)
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3485 {
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3486 return cap->cmdchar == ':'
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3487 || cap->cmdchar == K_COMMAND
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3488 || cap->cmdchar == K_SCRIPT_COMMAND;
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3489 }
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3490
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3491 /*
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3492 * Handle an operator after Visual mode or when the movement is finished.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3493 * "gui_yank" is true when yanking text for the clipboard.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3494 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3495 void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3496 do_pending_operator(cmdarg_T *cap, int old_col, int gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3497 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3498 oparg_T *oap = cap->oap;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3499 pos_T old_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3500 int empty_region_error;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3501 int restart_edit_save;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3502 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3503 int lbr_saved = curwin->w_p_lbr;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3504 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3505
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3506 // The visual area is remembered for redo
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3507 static redo_VIsual_T redo_VIsual = {NUL, 0, 0, 0,0};
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3508
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3509 int include_line_break = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3510
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3511 #if defined(FEAT_CLIPBOARD)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3512 // Yank the visual area into the GUI selection register before we operate
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3513 // on it and lose it forever.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3514 // Don't do it if a specific register was specified, so that ""x"*P works.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3515 // This could call do_pending_operator() recursively, but that's OK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3516 // because gui_yank will be TRUE for the nested call.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3517 if ((clip_star.available || clip_plus.available)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3518 && oap->op_type != OP_NOP
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3519 && !gui_yank
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3520 && VIsual_active
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3521 && !redo_VIsual_busy
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3522 && oap->regname == 0)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3523 clip_auto_select();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3524 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3525 old_cursor = curwin->w_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3526
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3527 // If an operation is pending, handle it...
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3528 if ((finish_op || VIsual_active) && oap->op_type != OP_NOP)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3529 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3530 // Yank can be redone when 'y' is in 'cpoptions', but not when yanking
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3531 // for the clipboard.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3532 int redo_yank = vim_strchr(p_cpo, CPO_YANK) != NULL && !gui_yank;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3533
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3534 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3535 // Avoid a problem with unwanted linebreaks in block mode.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3536 if (curwin->w_p_lbr)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3537 curwin->w_valid &= ~VALID_VIRTCOL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3538 curwin->w_p_lbr = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3539 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3540 oap->is_VIsual = VIsual_active;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3541 if (oap->motion_force == 'V')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3542 oap->motion_type = MLINE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3543 else if (oap->motion_force == 'v')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3544 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3545 // If the motion was linewise, "inclusive" will not have been set.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3546 // Use "exclusive" to be consistent. Makes "dvj" work nice.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3547 if (oap->motion_type == MLINE)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3548 oap->inclusive = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3549 // If the motion already was characterwise, toggle "inclusive"
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3550 else if (oap->motion_type == MCHAR)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3551 oap->inclusive = !oap->inclusive;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3552 oap->motion_type = MCHAR;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3553 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3554 else if (oap->motion_force == Ctrl_V)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3555 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3556 // Change line- or characterwise motion into Visual block mode.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3557 if (!VIsual_active)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3558 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3559 VIsual_active = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3560 VIsual = oap->start;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3561 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3562 VIsual_mode = Ctrl_V;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3563 VIsual_select = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3564 VIsual_reselect = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3565 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3566
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3567 // Only redo yank when 'y' flag is in 'cpoptions'.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3568 // Never redo "zf" (define fold).
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3569 if ((redo_yank || oap->op_type != OP_YANK)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3570 && ((!VIsual_active || oap->motion_force)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3571 // Also redo Operator-pending Visual mode mappings
22916
1fe53aae3ba0 patch 8.2.2005: redoing a mapping with <Cmd> doesn't work properly
Bram Moolenaar <Bram@vim.org>
parents: 22862
diff changeset
3572 || (VIsual_active
27140
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3573 && is_ex_cmdchar(cap) && oap->op_type != OP_COLON))
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3574 && cap->cmdchar != 'D'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3575 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3576 && oap->op_type != OP_FOLD
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3577 && oap->op_type != OP_FOLDOPEN
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3578 && oap->op_type != OP_FOLDOPENREC
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3579 && oap->op_type != OP_FOLDCLOSE
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3580 && oap->op_type != OP_FOLDCLOSEREC
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3581 && oap->op_type != OP_FOLDDEL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3582 && oap->op_type != OP_FOLDDELREC
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3583 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3584 )
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3585 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3586 prep_redo(oap->regname, cap->count0,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3587 get_op_char(oap->op_type), get_extra_op_char(oap->op_type),
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3588 oap->motion_force, cap->cmdchar, cap->nchar);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3589 if (cap->cmdchar == '/' || cap->cmdchar == '?') // was a search
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3590 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3591 // If 'cpoptions' does not contain 'r', insert the search
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3592 // pattern to really repeat the same command.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3593 if (vim_strchr(p_cpo, CPO_REDO) == NULL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3594 AppendToRedobuffLit(cap->searchbuf, -1);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3595 AppendToRedobuff(NL_STR);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3596 }
27140
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3597 else if (is_ex_cmdchar(cap))
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3598 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3599 // do_cmdline() has stored the first typed line in
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3600 // "repeat_cmdline". When several lines are typed repeating
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3601 // won't be possible.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3602 if (repeat_cmdline == NULL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3603 ResetRedobuff();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3604 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3605 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3606 AppendToRedobuffLit(repeat_cmdline, -1);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3607 AppendToRedobuff(NL_STR);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3608 VIM_CLEAR(repeat_cmdline);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3609 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3610 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3611 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3612
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3613 if (redo_VIsual_busy)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3614 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3615 // Redo of an operation on a Visual area. Use the same size from
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3616 // redo_VIsual.rv_line_count and redo_VIsual.rv_vcol.
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3617 oap->start = curwin->w_cursor;
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3618 curwin->w_cursor.lnum += redo_VIsual.rv_line_count - 1;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3619 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3620 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count;
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3621 VIsual_mode = redo_VIsual.rv_mode;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3622 if (redo_VIsual.rv_vcol == MAXCOL || VIsual_mode == 'v')
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3623 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3624 if (VIsual_mode == 'v')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3625 {
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3626 if (redo_VIsual.rv_line_count <= 1)
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3627 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3628 validate_virtcol();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3629 curwin->w_curswant =
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3630 curwin->w_virtcol + redo_VIsual.rv_vcol - 1;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3631 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3632 else
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3633 curwin->w_curswant = redo_VIsual.rv_vcol;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3634 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3635 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3636 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3637 curwin->w_curswant = MAXCOL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3638 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3639 coladvance(curwin->w_curswant);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3640 }
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3641 cap->count0 = redo_VIsual.rv_count;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3642 if (redo_VIsual.rv_count != 0)
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3643 cap->count1 = redo_VIsual.rv_count;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3644 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3645 cap->count1 = 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3646 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3647 else if (VIsual_active)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3648 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3649 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3650 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3651 // Save the current VIsual area for '< and '> marks, and "gv"
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3652 curbuf->b_visual.vi_start = VIsual;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3653 curbuf->b_visual.vi_end = curwin->w_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3654 curbuf->b_visual.vi_mode = VIsual_mode;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3655 restore_visual_mode();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3656 curbuf->b_visual.vi_curswant = curwin->w_curswant;
27521
3ad379c0ab28 patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
3657 #ifdef FEAT_EVAL
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3658 curbuf->b_visual_mode_eval = VIsual_mode;
27521
3ad379c0ab28 patch 8.2.4288: preprocessor indents are inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 27490
diff changeset
3659 #endif
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3660 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3661
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3662 // In Select mode, a linewise selection is operated upon like a
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3663 // characterwise selection.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3664 // Special case: gH<Del> deletes the last line.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3665 if (VIsual_select && VIsual_mode == 'V'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3666 && cap->oap->op_type != OP_DELETE)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3667 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3668 if (LT_POS(VIsual, curwin->w_cursor))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3669 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3670 VIsual.col = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3671 curwin->w_cursor.col =
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3672 (colnr_T)STRLEN(ml_get(curwin->w_cursor.lnum));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3673 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3674 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3675 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3676 curwin->w_cursor.col = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3677 VIsual.col = (colnr_T)STRLEN(ml_get(VIsual.lnum));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3678 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3679 VIsual_mode = 'v';
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3680 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3681 // If 'selection' is "exclusive", backup one character for
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3682 // charwise selections.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3683 else if (VIsual_mode == 'v')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3684 include_line_break = unadjust_for_sel();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3685
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3686 oap->start = VIsual;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3687 if (VIsual_mode == 'V')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3688 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3689 oap->start.col = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3690 oap->start.coladd = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3691 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3692 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3693
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3694 // Set oap->start to the first position of the operated text, oap->end
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3695 // to the end of the operated text. w_cursor is equal to oap->start.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3696 if (LT_POS(oap->start, curwin->w_cursor))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3697 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3698 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3699 // Include folded lines completely.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3700 if (!VIsual_active)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3701 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3702 if (hasFolding(oap->start.lnum, &oap->start.lnum, NULL))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3703 oap->start.col = 0;
18882
f9e41ffd3539 patch 8.2.0002: "dj" only deletes first line of closed fold
Bram Moolenaar <Bram@vim.org>
parents: 18808
diff changeset
3704 if ((curwin->w_cursor.col > 0 || oap->inclusive
f9e41ffd3539 patch 8.2.0002: "dj" only deletes first line of closed fold
Bram Moolenaar <Bram@vim.org>
parents: 18808
diff changeset
3705 || oap->motion_type == MLINE)
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3706 && hasFolding(curwin->w_cursor.lnum, NULL,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3707 &curwin->w_cursor.lnum))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3708 curwin->w_cursor.col = (colnr_T)STRLEN(ml_get_curline());
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3709 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3710 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3711 oap->end = curwin->w_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3712 curwin->w_cursor = oap->start;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3713
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3714 // w_virtcol may have been updated; if the cursor goes back to its
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3715 // previous position w_virtcol becomes invalid and isn't updated
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3716 // automatically.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3717 curwin->w_valid &= ~VALID_VIRTCOL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3718 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3719 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3720 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3721 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3722 // Include folded lines completely.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3723 if (!VIsual_active && oap->motion_type == MLINE)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3724 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3725 if (hasFolding(curwin->w_cursor.lnum, &curwin->w_cursor.lnum,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3726 NULL))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3727 curwin->w_cursor.col = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3728 if (hasFolding(oap->start.lnum, NULL, &oap->start.lnum))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3729 oap->start.col = (colnr_T)STRLEN(ml_get(oap->start.lnum));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3730 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3731 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3732 oap->end = oap->start;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3733 oap->start = curwin->w_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3734 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3735
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3736 // Just in case lines were deleted that make the position invalid.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3737 check_pos(curwin->w_buffer, &oap->end);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3738 oap->line_count = oap->end.lnum - oap->start.lnum + 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3739
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3740 // Set "virtual_op" before resetting VIsual_active.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3741 virtual_op = virtual_active();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3742
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3743 if (VIsual_active || redo_VIsual_busy)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3744 {
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3745 get_op_vcol(oap, redo_VIsual.rv_vcol, TRUE);
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3746
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3747 if (!redo_VIsual_busy && !gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3748 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3749 // Prepare to reselect and redo Visual: this is based on the
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3750 // size of the Visual text
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3751 resel_VIsual_mode = VIsual_mode;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3752 if (curwin->w_curswant == MAXCOL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3753 resel_VIsual_vcol = MAXCOL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3754 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3755 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3756 if (VIsual_mode != Ctrl_V)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3757 getvvcol(curwin, &(oap->end),
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3758 NULL, NULL, &oap->end_vcol);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3759 if (VIsual_mode == Ctrl_V || oap->line_count <= 1)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3760 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3761 if (VIsual_mode != Ctrl_V)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3762 getvvcol(curwin, &(oap->start),
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3763 &oap->start_vcol, NULL, NULL);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3764 resel_VIsual_vcol = oap->end_vcol - oap->start_vcol + 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3765 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3766 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3767 resel_VIsual_vcol = oap->end_vcol;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3768 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3769 resel_VIsual_line_count = oap->line_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3770 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3771
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3772 // can't redo yank (unless 'y' is in 'cpoptions') and ":"
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3773 if ((redo_yank || oap->op_type != OP_YANK)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3774 && oap->op_type != OP_COLON
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3775 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3776 && oap->op_type != OP_FOLD
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3777 && oap->op_type != OP_FOLDOPEN
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3778 && oap->op_type != OP_FOLDOPENREC
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3779 && oap->op_type != OP_FOLDCLOSE
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3780 && oap->op_type != OP_FOLDCLOSEREC
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3781 && oap->op_type != OP_FOLDDEL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3782 && oap->op_type != OP_FOLDDELREC
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3783 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3784 && oap->motion_force == NUL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3785 )
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3786 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3787 // Prepare for redoing. Only use the nchar field for "r",
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3788 // otherwise it might be the second char of the operator.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3789 if (cap->cmdchar == 'g' && (cap->nchar == 'n'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3790 || cap->nchar == 'N'))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3791 prep_redo(oap->regname, cap->count0,
18808
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3792 get_op_char(oap->op_type),
7982f65d8f54 patch 8.1.2392: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18763
diff changeset
3793 get_extra_op_char(oap->op_type),
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3794 oap->motion_force, cap->cmdchar, cap->nchar);
27140
a9eeb18e749c patch 8.2.4099: Vim9: cannot use Vim9 syntax in mapping
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
3795 else if (!is_ex_cmdchar(cap))
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3796 {
26226
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3797 int opchar = get_op_char(oap->op_type);
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3798 int extra_opchar = get_extra_op_char(oap->op_type);
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3799 int nchar = oap->op_type == OP_REPLACE ? cap->nchar : NUL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3800
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3801 // reverse what nv_replace() did
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3802 if (nchar == REPLACE_CR_NCHAR)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3803 nchar = CAR;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3804 else if (nchar == REPLACE_NL_NCHAR)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3805 nchar = NL;
26226
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3806
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3807 if (opchar == 'g' && extra_opchar == '@')
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3808 // also repeat the count for 'operatorfunc'
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3809 prep_redo_num2(oap->regname, 0L, NUL, 'v',
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3810 cap->count0, opchar, extra_opchar, nchar);
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3811 else
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3812 prep_redo(oap->regname, 0L, NUL, 'v',
9a8e9383e4cd patch 8.2.3644: count for 'operatorfunc' in Visual mode is not redone
Bram Moolenaar <Bram@vim.org>
parents: 26175
diff changeset
3813 opchar, extra_opchar, nchar);
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3814 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3815 if (!redo_VIsual_busy)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3816 {
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3817 redo_VIsual.rv_mode = resel_VIsual_mode;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3818 redo_VIsual.rv_vcol = resel_VIsual_vcol;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3819 redo_VIsual.rv_line_count = resel_VIsual_line_count;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3820 redo_VIsual.rv_count = cap->count0;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
3821 redo_VIsual.rv_arg = cap->arg;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3822 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3823 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3824
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3825 // oap->inclusive defaults to TRUE.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3826 // If oap->end is on a NUL (empty line) oap->inclusive becomes
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3827 // FALSE. This makes "d}P" and "v}dP" work the same.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3828 if (oap->motion_force == NUL || oap->motion_type == MLINE)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3829 oap->inclusive = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3830 if (VIsual_mode == 'V')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3831 oap->motion_type = MLINE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3832 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3833 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3834 oap->motion_type = MCHAR;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3835 if (VIsual_mode != Ctrl_V && *ml_get_pos(&(oap->end)) == NUL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3836 && (include_line_break || !virtual_op))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3837 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3838 oap->inclusive = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3839 // Try to include the newline, unless it's an operator
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3840 // that works on lines only.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3841 if (*p_sel != 'o'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3842 && !op_on_lines(oap->op_type)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3843 && oap->end.lnum < curbuf->b_ml.ml_line_count)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3844 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3845 ++oap->end.lnum;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3846 oap->end.col = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3847 oap->end.coladd = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3848 ++oap->line_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3849 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3850 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3851 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3852
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3853 redo_VIsual_busy = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3854
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3855 // Switch Visual off now, so screen updating does
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3856 // not show inverted text when the screen is redrawn.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3857 // With OP_YANK and sometimes with OP_COLON and OP_FILTER there is
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3858 // no screen redraw, so it is done here to remove the inverted
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3859 // part.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3860 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3861 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3862 VIsual_active = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3863 setmouse();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3864 mouse_dragging = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3865 may_clear_cmdline();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3866 if ((oap->op_type == OP_YANK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3867 || oap->op_type == OP_COLON
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3868 || oap->op_type == OP_FUNCTION
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3869 || oap->op_type == OP_FILTER)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3870 && oap->motion_force == NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3871 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3872 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3873 // make sure redrawing is correct
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3874 curwin->w_p_lbr = lbr_saved;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3875 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3876 redraw_curbuf_later(INVERTED);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3877 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3878 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3879 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3880
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3881 // Include the trailing byte of a multi-byte char.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3882 if (has_mbyte && oap->inclusive)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3883 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3884 int l;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3885
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3886 l = (*mb_ptr2len)(ml_get_pos(&oap->end));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3887 if (l > 1)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3888 oap->end.col += l - 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3889 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3890 curwin->w_set_curswant = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3891
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3892 // oap->empty is set when start and end are the same. The inclusive
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3893 // flag affects this too, unless yanking and the end is on a NUL.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3894 oap->empty = (oap->motion_type == MCHAR
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3895 && (!oap->inclusive
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3896 || (oap->op_type == OP_YANK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3897 && gchar_pos(&oap->end) == NUL))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3898 && EQUAL_POS(oap->start, oap->end)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3899 && !(virtual_op && oap->start.coladd != oap->end.coladd));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3900 // For delete, change and yank, it's an error to operate on an
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3901 // empty region, when 'E' included in 'cpoptions' (Vi compatible).
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3902 empty_region_error = (oap->empty
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3903 && vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3904
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3905 // Force a redraw when operating on an empty Visual region, when
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3906 // 'modifiable is off or creating a fold.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3907 if (oap->is_VIsual && (oap->empty || !curbuf->b_p_ma
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3908 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3909 || oap->op_type == OP_FOLD
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3910 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3911 ))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3912 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3913 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3914 curwin->w_p_lbr = lbr_saved;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3915 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3916 redraw_curbuf_later(INVERTED);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3917 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3918
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3919 // If the end of an operator is in column one while oap->motion_type
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3920 // is MCHAR and oap->inclusive is FALSE, we put op_end after the last
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3921 // character in the previous line. If op_start is on or before the
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3922 // first non-blank in the line, the operator becomes linewise
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3923 // (strange, but that's the way vi does it).
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3924 if ( oap->motion_type == MCHAR
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3925 && oap->inclusive == FALSE
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3926 && !(cap->retval & CA_NO_ADJ_OP_END)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3927 && oap->end.col == 0
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3928 && (!oap->is_VIsual || *p_sel == 'o')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3929 && !oap->block_mode
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3930 && oap->line_count > 1)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3931 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3932 oap->end_adjusted = TRUE; // remember that we did this
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3933 --oap->line_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3934 --oap->end.lnum;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3935 if (inindent(0))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3936 oap->motion_type = MLINE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3937 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3938 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3939 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3940 if (oap->end.col)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3941 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3942 --oap->end.col;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3943 oap->inclusive = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3944 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3945 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3946 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3947 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3948 oap->end_adjusted = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3949
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3950 switch (oap->op_type)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3951 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3952 case OP_LSHIFT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3953 case OP_RSHIFT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3954 op_shift(oap, TRUE, oap->is_VIsual ? (int)cap->count1 : 1);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3955 auto_format(FALSE, TRUE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3956 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3957
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3958 case OP_JOIN_NS:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3959 case OP_JOIN:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3960 if (oap->line_count < 2)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3961 oap->line_count = 2;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3962 if (curwin->w_cursor.lnum + oap->line_count - 1 >
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3963 curbuf->b_ml.ml_line_count)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3964 beep_flush();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3965 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3966 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3967 (void)do_join(oap->line_count, oap->op_type == OP_JOIN,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3968 TRUE, TRUE, TRUE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3969 auto_format(FALSE, TRUE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3970 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3971 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3972
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3973 case OP_DELETE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3974 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3975 if (empty_region_error)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3976 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3977 vim_beep(BO_OPER);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3978 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3979 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3980 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3981 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3982 (void)op_delete(oap);
22965
473a1413d09b patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents: 22916
diff changeset
3983 // save cursor line for undo if it wasn't saved yet
473a1413d09b patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents: 22916
diff changeset
3984 if (oap->motion_type == MLINE && has_format_option(FO_AUTO)
473a1413d09b patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents: 22916
diff changeset
3985 && u_save_cursor() == OK)
473a1413d09b patch 8.2.2029: Coverity warns for not checking return value
Bram Moolenaar <Bram@vim.org>
parents: 22916
diff changeset
3986 auto_format(FALSE, TRUE);
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3987 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3988 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3989
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3990 case OP_YANK:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3991 if (empty_region_error)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3992 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3993 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3994 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3995 vim_beep(BO_OPER);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3996 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3997 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3998 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3999 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4000 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4001 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4002 curwin->w_p_lbr = lbr_saved;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4003 #endif
24866
f1121eb17e14 patch 8.2.2971: cannot yank a block without trailing spaces
Bram Moolenaar <Bram@vim.org>
parents: 24768
diff changeset
4004 oap->excl_tr_ws = cap->cmdchar == 'z';
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4005 (void)op_yank(oap, FALSE, !gui_yank);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4006 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4007 check_cursor_col();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4008 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4009
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4010 case OP_CHANGE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4011 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4012 if (empty_region_error)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4013 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4014 vim_beep(BO_OPER);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4015 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4016 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4017 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4018 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4019 // This is a new edit command, not a restart. Need to
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4020 // remember it to make 'insertmode' work with mappings for
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4021 // Visual mode. But do this only once and not when typed and
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4022 // 'insertmode' isn't set.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4023 if (p_im || !KeyTyped)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4024 restart_edit_save = restart_edit;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4025 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4026 restart_edit_save = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4027 restart_edit = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4028 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4029 // Restore linebreak, so that when the user edits it looks as
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4030 // before.
19176
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
4031 curwin->w_p_lbr = lbr_saved;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4032 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4033 // Reset finish_op now, don't want it set inside edit().
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4034 finish_op = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4035 if (op_change(oap)) // will call edit()
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4036 cap->retval |= CA_COMMAND_BUSY;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4037 if (restart_edit == 0)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4038 restart_edit = restart_edit_save;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4039 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4040 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4041
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4042 case OP_FILTER:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4043 if (vim_strchr(p_cpo, CPO_FILTER) != NULL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4044 AppendToRedobuff((char_u *)"!\r"); // use any last used !cmd
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4045 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4046 bangredo = TRUE; // do_bang() will put cmd in redo buffer
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4047 // FALLTHROUGH
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4048
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4049 case OP_INDENT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4050 case OP_COLON:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4051
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4052 // If 'equalprg' is empty, do the indenting internally.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4053 if (oap->op_type == OP_INDENT && *get_equalprg() == NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4054 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4055 if (curbuf->b_p_lisp)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4056 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4057 op_reindent(oap, get_lisp_indent);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4058 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4059 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4060 op_reindent(oap,
28942
6cdf55afaae9 patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents: 28869
diff changeset
4061 #ifdef FEAT_EVAL
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4062 *curbuf->b_p_inde != NUL ? get_expr_indent :
28942
6cdf55afaae9 patch 8.2.4993: smart/C/lisp indenting is optional
Bram Moolenaar <Bram@vim.org>
parents: 28869
diff changeset
4063 #endif
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4064 get_c_indent);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4065 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4066 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4067
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4068 op_colon(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4069 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4070
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4071 case OP_TILDE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4072 case OP_UPPER:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4073 case OP_LOWER:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4074 case OP_ROT13:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4075 if (empty_region_error)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4076 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4077 vim_beep(BO_OPER);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4078 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4079 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4080 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4081 op_tilde(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4082 check_cursor_col();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4083 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4084
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4085 case OP_FORMAT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4086 #if defined(FEAT_EVAL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4087 if (*curbuf->b_p_fex != NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4088 op_formatexpr(oap); // use expression
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4089 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4090 #endif
24665
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 23287
diff changeset
4091 {
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4092 if (*p_fp != NUL || *curbuf->b_p_fp != NUL)
24665
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 23287
diff changeset
4093 op_colon(oap); // use external command
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 23287
diff changeset
4094 else
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 23287
diff changeset
4095 op_format(oap, FALSE); // use internal function
661d15592d3c patch 8.2.2871: unnessary VIM_ISDIGIT() calls, badly indented code
Bram Moolenaar <Bram@vim.org>
parents: 23287
diff changeset
4096 }
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4097 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4098 case OP_FORMAT2:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4099 op_format(oap, TRUE); // use internal function
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4100 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4101
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4102 case OP_FUNCTION:
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4103 {
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4104 redo_VIsual_T save_redo_VIsual = redo_VIsual;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4105
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4106 #ifdef FEAT_LINEBREAK
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4107 // Restore linebreak, so that when the user edits it looks as
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4108 // before.
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4109 curwin->w_p_lbr = lbr_saved;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4110 #endif
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4111 // call 'operatorfunc'
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4112 op_function(oap);
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4113
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4114 // Restore the info for redoing Visual mode, the function may
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4115 // invoke another operator and unintentionally change it.
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4116 redo_VIsual = save_redo_VIsual;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4117 break;
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4118 }
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4119
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4120 case OP_INSERT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4121 case OP_APPEND:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4122 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4123 if (empty_region_error)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4124 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4125 vim_beep(BO_OPER);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4126 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4127 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4128 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4129 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4130 // This is a new edit command, not a restart. Need to
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4131 // remember it to make 'insertmode' work with mappings for
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4132 // Visual mode. But do this only once.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4133 restart_edit_save = restart_edit;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4134 restart_edit = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4135 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4136 // Restore linebreak, so that when the user edits it looks as
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4137 // before.
19176
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
4138 curwin->w_p_lbr = lbr_saved;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4139 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4140 op_insert(oap, cap->count1);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4141 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4142 // Reset linebreak, so that formatting works correctly.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4143 curwin->w_p_lbr = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4144 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4145
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4146 // TODO: when inserting in several lines, should format all
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4147 // the lines.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4148 auto_format(FALSE, TRUE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4149
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4150 if (restart_edit == 0)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4151 restart_edit = restart_edit_save;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4152 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4153 cap->retval |= CA_COMMAND_BUSY;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4154 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4155 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4156
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4157 case OP_REPLACE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4158 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4159 if (empty_region_error)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4160 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4161 vim_beep(BO_OPER);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4162 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4163 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4164 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4165 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4166 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4167 // Restore linebreak, so that when the user edits it looks as
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4168 // before.
19176
be81baeb69f8 patch 8.2.0147: block Visual mode operators not correct when 'linebreak' set
Bram Moolenaar <Bram@vim.org>
parents: 19005
diff changeset
4169 curwin->w_p_lbr = lbr_saved;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4170 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4171 op_replace(oap, cap->nchar);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4172 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4173 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4174
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4175 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4176 case OP_FOLD:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4177 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4178 foldCreate(oap->start.lnum, oap->end.lnum);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4179 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4180
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4181 case OP_FOLDOPEN:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4182 case OP_FOLDOPENREC:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4183 case OP_FOLDCLOSE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4184 case OP_FOLDCLOSEREC:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4185 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4186 opFoldRange(oap->start.lnum, oap->end.lnum,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4187 oap->op_type == OP_FOLDOPEN
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4188 || oap->op_type == OP_FOLDOPENREC,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4189 oap->op_type == OP_FOLDOPENREC
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4190 || oap->op_type == OP_FOLDCLOSEREC,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4191 oap->is_VIsual);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4192 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4193
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4194 case OP_FOLDDEL:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4195 case OP_FOLDDELREC:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4196 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4197 deleteFold(oap->start.lnum, oap->end.lnum,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4198 oap->op_type == OP_FOLDDELREC, oap->is_VIsual);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4199 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4200 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4201 case OP_NR_ADD:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4202 case OP_NR_SUB:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4203 if (empty_region_error)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4204 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4205 vim_beep(BO_OPER);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4206 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4207 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4208 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4209 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4210 VIsual_active = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4211 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4212 curwin->w_p_lbr = lbr_saved;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4213 #endif
26903
5aa9e8db975c patch 8.2.3980: if 'operatorfunc' invokes an operator Visual mode is changed
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
4214 op_addsub(oap, cap->count1, redo_VIsual.rv_arg);
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4215 VIsual_active = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4216 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4217 check_cursor_col();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4218 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4219 default:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4220 clearopbeep(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4221 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4222 virtual_op = MAYBE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4223 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4224 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4225 // if 'sol' not set, go back to old column for some commands
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4226 if (!p_sol && oap->motion_type == MLINE && !oap->end_adjusted
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4227 && (oap->op_type == OP_LSHIFT || oap->op_type == OP_RSHIFT
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4228 || oap->op_type == OP_DELETE))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4229 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4230 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4231 curwin->w_p_lbr = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4232 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4233 coladvance(curwin->w_curswant = old_col);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4234 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4235 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4236 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4237 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4238 curwin->w_cursor = old_cursor;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4239 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4240 oap->block_mode = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4241 clearop(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4242 motion_force = NUL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4243 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4244 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4245 curwin->w_p_lbr = lbr_saved;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4246 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4247 }