annotate src/ops.c @ 18763:49b78d6465e5 v8.1.2371

patch 8.1.2371: FEAT_TEXT_PROP is a confusing name Commit: https://github.com/vim/vim/commit/05ad5ff0ab34ed9a5296dedd420ca81698b8ce22 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 30 22:48:27 2019 +0100 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name Problem: FEAT_TEXT_PROP is a confusing name. Solution: Use FEAT_PROP_POPUP. (Naruhiko Nishino, closes https://github.com/vim/vim/issues/5291)
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 Nov 2019 23:00:05 +0100
parents 788d76db02ac
children 7982f65d8f54
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,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 * op_change, op_yank, do_put, do_join
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);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7576
diff changeset
20 static int ends_in_white(linenr_T lnum);
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7576
diff changeset
21 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
23 // Flags for third item in "opchars".
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
24 #define OPF_LINES 1 // operator always works on lines
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
25 #define OPF_CHANGE 2 // operator changes text
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
26
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 * The names of operators.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 * IMPORTANT: Index must correspond with defines in vim.h!!!
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
30 * The third field holds OPF_ flags.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 static char opchars[][3] =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 {
14019
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
34 {NUL, NUL, 0}, // OP_NOP
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
35 {'d', NUL, OPF_CHANGE}, // OP_DELETE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
36 {'y', NUL, 0}, // OP_YANK
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
37 {'c', NUL, OPF_CHANGE}, // OP_CHANGE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
38 {'<', NUL, OPF_LINES | OPF_CHANGE}, // OP_LSHIFT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
39 {'>', NUL, OPF_LINES | OPF_CHANGE}, // OP_RSHIFT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
40 {'!', NUL, OPF_LINES | OPF_CHANGE}, // OP_FILTER
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
41 {'g', '~', OPF_CHANGE}, // OP_TILDE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
42 {'=', NUL, OPF_LINES | OPF_CHANGE}, // OP_INDENT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
43 {'g', 'q', OPF_LINES | OPF_CHANGE}, // OP_FORMAT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
44 {':', NUL, OPF_LINES}, // OP_COLON
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
45 {'g', 'U', OPF_CHANGE}, // OP_UPPER
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
46 {'g', 'u', OPF_CHANGE}, // OP_LOWER
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
47 {'J', NUL, OPF_LINES | OPF_CHANGE}, // DO_JOIN
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
48 {'g', 'J', OPF_LINES | OPF_CHANGE}, // DO_JOIN_NS
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
49 {'g', '?', OPF_CHANGE}, // OP_ROT13
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
50 {'r', NUL, OPF_CHANGE}, // OP_REPLACE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
51 {'I', NUL, OPF_CHANGE}, // OP_INSERT
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
52 {'A', NUL, OPF_CHANGE}, // OP_APPEND
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
53 {'z', 'f', OPF_LINES}, // OP_FOLD
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
54 {'z', 'o', OPF_LINES}, // OP_FOLDOPEN
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
55 {'z', 'O', OPF_LINES}, // OP_FOLDOPENREC
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
56 {'z', 'c', OPF_LINES}, // OP_FOLDCLOSE
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
57 {'z', 'C', OPF_LINES}, // OP_FOLDCLOSEREC
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
58 {'z', 'd', OPF_LINES}, // OP_FOLDDEL
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
59 {'z', 'D', OPF_LINES}, // OP_FOLDDELREC
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
60 {'g', 'w', OPF_LINES | OPF_CHANGE}, // OP_FORMAT2
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
61 {'g', '@', OPF_CHANGE}, // OP_FUNCTION
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
62 {Ctrl_A, NUL, OPF_CHANGE}, // OP_NR_ADD
dc67449d648c patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents: 14004
diff changeset
63 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 };
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 * Translate a command name into an operator type.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 * Must only be called with a valid operator name!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
71 get_op_type(int char1, int char2)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 int i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 if (char1 == 'r') /* ignore second character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 return OP_REPLACE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 if (char1 == '~') /* when tilde is an operator */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 return OP_TILDE;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
79 if (char1 == 'g' && char2 == Ctrl_A) /* add */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
80 return OP_NR_ADD;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
81 if (char1 == 'g' && char2 == Ctrl_X) /* subtract */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
82 return OP_NR_SUB;
7
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;
13072
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
87 if (i == (int)(sizeof(opchars) / sizeof(char [3]) - 1))
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
88 {
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
89 internal_error("get_op_type()");
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
90 break;
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
91 }
50aa6da392ce patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents: 13047
diff changeset
92 }
7
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();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 if (first_char == NUL) /* empty line */
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 /* Move the line right if it doesn't start with '#', 'smartindent'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 if (first_char != '#' || !preprocs_left())
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 #endif
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1477
diff changeset
165 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
168
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 curwin->w_cursor.lnum = oap->start.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 curwin->w_cursor.col = block_col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 }
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
175 else if (curs_top) /* put cursor on first line, for ">>" */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 curwin->w_cursor.lnum = oap->start.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182
10486
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
183 #ifdef FEAT_FOLDING
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
184 /* The cursor line is not in a closed fold */
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
185 foldOpenCursor();
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
186 #endif
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
187
99896ee0cac5 commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents: 10104
diff changeset
188
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 if (oap->line_count > p_report)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 {
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
191 char *op;
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
192 char *msg_line_single;
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
193 char *msg_line_plural;
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
194
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 if (oap->op_type == OP_RSHIFT)
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
196 op = ">";
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 else
14585
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
198 op = "<";
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
199 msg_line_single = NGETTEXT("%ld line %sed %d time",
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
200 "%ld line %sed %d times", amount);
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
201 msg_line_plural = NGETTEXT("%ld lines %sed %d time",
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
202 "%ld lines %sed %d times", amount);
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
203 vim_snprintf((char *)IObuff, IOSIZE,
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
204 NGETTEXT(msg_line_single, msg_line_plural, oap->line_count),
c8f07e8b273e patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents: 14424
diff changeset
205 oap->line_count, op, amount);
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
206 msg((char *)IObuff);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
209 if (!cmdmod.lockmarks)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
210 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
211 // Set "'[" and "']" marks.
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
212 curbuf->b_op_start = oap->start;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
213 curbuf->b_op_end.lnum = oap->end.lnum;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
214 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
215 if (curbuf->b_op_end.col > 0)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
216 --curbuf->b_op_end.col;
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
217 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220 /*
15422
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
221 * Shift the current line one shiftwidth left (if left != 0) or right
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
222 * leaves cursor on first blank in the line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
225 shift_line(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
226 int left,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
227 int round,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
228 int amount,
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
229 int call_changed_bytes) // call changed_bytes()
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 int i, j;
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
233 int sw_val = (int)get_sw_value_indent(curbuf);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
235 count = get_indent(); // get current indent
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
236
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
237 if (round) // round off indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 {
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
239 i = count / sw_val; // number of 'shiftwidth' rounded down
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
240 j = count % sw_val; // extra spaces
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
241 if (j && left) // first remove extra spaces
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 --amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243 if (left)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 i -= amount;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 if (i < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 i = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 i += amount;
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
251 count = i * sw_val;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 }
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
253 else // original vi indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255 if (left)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 {
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
257 count -= sw_val * amount;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 if (count < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 count = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 else
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
262 count += sw_val * amount;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
265 // Set new indent
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 if (State & VREPLACE_FLAG)
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1477
diff changeset
267 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 else
1516
ee9d2d24ea9b updated for version 7.1-231
vimboss
parents: 1477
diff changeset
269 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 * Shift one line of the current block one shiftwidth right or left.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 * Leaves cursor on first character in block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
277 shift_block(oparg_T *oap, int amount)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 int left = (oap->op_type == OP_LSHIFT);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 int oldstate = State;
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
281 int total;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
282 char_u *newp, *oldp;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 int oldcol = curwin->w_cursor.col;
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
284 int sw_val = (int)get_sw_value_indent(curbuf);
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
285 int ts_val = (int)curbuf->b_p_ts;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 int incr;
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
288 colnr_T ws_vcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289 int i = 0, j = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 int len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 int old_p_ri = p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
4352
04736b4030ec updated for version 7.3.925
Bram Moolenaar <bram@vim.org>
parents: 4209
diff changeset
294 p_ri = 0; /* don't want revins in indent */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297 State = INSERT; /* don't want REPLACE for State */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299 if (bd.is_short)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302 /* total is number of screen columns to be inserted/removed */
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
303 total = (int)((unsigned)amount * (unsigned)sw_val);
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
304 if ((total / sw_val) != amount)
11997
66b677c77467 patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents: 11688
diff changeset
305 return; /* multiplication overflow */
66b677c77467 patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents: 11688
diff changeset
306
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 oldp = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 if (!left)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312 * 1. Get start vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313 * 2. Total ws vcols
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 * 3. Divvy into TABs & spp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315 * 4. Construct new string
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 ws_vcol = bd.start_vcol - bd.pre_whitesp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 if (bd.startspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 if (has_mbyte)
8399
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
322 {
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
323 if ((*mb_ptr2len)(bd.textstart) == 1)
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
324 ++bd.textstart;
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
325 else
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
326 {
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
327 ws_vcol = 0;
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
328 bd.startspaces = 0;
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
329 }
7d1c42e3ce11 commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents: 7829
diff changeset
330 }
1995
92809ecb9a47 updated for version 7.2-292
vimboss
parents: 1982
diff changeset
331 else
92809ecb9a47 updated for version 7.2-292
vimboss
parents: 1982
diff changeset
332 ++bd.textstart;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 }
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
334 for ( ; VIM_ISWHITE(*bd.textstart); )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
336 /* TODO: is passing bd.textstart for start of the line OK? */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
337 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart,
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
338 (colnr_T)(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 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 /* OK, now total=all the VWS reqd, and textstart points at the 1st
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343 * non-ws char in the block. */
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
344 #ifdef FEAT_VARTABS
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
345 if (!curbuf->b_p_et)
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
346 tabstop_fromto(ws_vcol, ws_vcol + total,
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
347 ts_val, curbuf->b_p_vts_array, &i, &j);
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
348 else
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
349 j = total;
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
350 #else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351 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
352 i = ((ws_vcol % ts_val) + total) / ts_val; /* number of tabs */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 if (i)
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
354 j = ((ws_vcol % ts_val) + total) % ts_val; /* number of spp */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356 j = total;
14175
2ad722003b36 patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents: 14019
diff changeset
357 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 /* if we're splitting a TAB, allow for it */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 len = (int)STRLEN(bd.textstart) + 1;
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
361 newp = alloc(bd.textcol + i + j + len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 mch_memmove(newp, oldp, (size_t)bd.textcol);
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
366 vim_memset(newp + bd.textcol, TAB, (size_t)i);
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
367 vim_memset(newp + bd.textcol + i, ' ', (size_t)j);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 /* the end */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
371 else /* left */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 {
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
373 colnr_T destination_col; /* column to which text in block will
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
374 be shifted */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
375 char_u *verbatim_copy_end; /* end of the part of the line which is
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
376 copied verbatim */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
377 colnr_T verbatim_copy_width;/* the (displayed) width of this part
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
378 of line */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
379 unsigned fill; /* nr of spaces that replace a TAB */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
380 unsigned new_line_len; /* the length of the line after the
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
381 block shift */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
382 size_t block_space_width;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
383 size_t shift_amount;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
384 char_u *non_white = bd.textstart;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
385 colnr_T non_white_col;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
386
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
387 /*
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
388 * Firstly, let's find the first non-whitespace character that is
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
389 * displayed after the block's start column and the character's column
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
390 * number. Also, let's calculate the width of all the whitespace
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
391 * characters that are displayed in the block and precede the searched
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
392 * non-whitespace character.
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
393 */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
394
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
395 /* If "bd.startspaces" is set, "bd.textstart" points to the character,
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
396 * the part of which is displayed at the block's beginning. Let's start
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
397 * searching from the next character. */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
398 if (bd.startspaces)
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
399 MB_PTR_ADV(non_white);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
400
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
401 /* The character's column is in "bd.start_vcol". */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
402 non_white_col = bd.start_vcol;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
403
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
404 while (VIM_ISWHITE(*non_white))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
406 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
407 non_white_col += incr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408 }
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
409
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
410 block_space_width = non_white_col - oap->start_vcol;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
411 /* We will shift by "total" or "block_space_width", whichever is less.
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
412 */
1860
f765f9c139de updated for version 7.2-158
vimboss
parents: 1839
diff changeset
413 shift_amount = (block_space_width < (size_t)total
f765f9c139de updated for version 7.2-158
vimboss
parents: 1839
diff changeset
414 ? block_space_width : (size_t)total);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
415
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
416 /* The column to which we will shift the text. */
1860
f765f9c139de updated for version 7.2-158
vimboss
parents: 1839
diff changeset
417 destination_col = (colnr_T)(non_white_col - shift_amount);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
418
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
419 /* Now let's find out how much of the beginning of the line we can
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
420 * reuse without modification. */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
421 verbatim_copy_end = bd.textstart;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
422 verbatim_copy_width = bd.start_vcol;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
423
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
424 /* If "bd.startspaces" is set, "bd.textstart" points to the character
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
425 * preceding the block. We have to subtract its width to obtain its
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
426 * column number. */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
427 if (bd.startspaces)
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
428 verbatim_copy_width -= bd.start_char_vcols;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
429 while (verbatim_copy_width < destination_col)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 {
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
431 char_u *line = verbatim_copy_end;
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
432
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
433 /* TODO: is passing verbatim_copy_end for start of the line OK? */
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
434 incr = lbr_chartabsize(line, verbatim_copy_end,
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
435 verbatim_copy_width);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
436 if (verbatim_copy_width + incr > destination_col)
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
437 break;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
438 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
439 MB_PTR_ADV(verbatim_copy_end);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
442 /* If "destination_col" is different from the width of the initial
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
443 * part of the line that will be copied, it means we encountered a tab
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
444 * character, which we will have to partly replace with spaces. */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
445 fill = destination_col - verbatim_copy_width;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
446
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
447 /* The replacement line will consist of:
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
448 * - the beginning of the original line up to "verbatim_copy_end",
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
449 * - "fill" number of spaces,
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
450 * - the rest of the line, pointed to by non_white. */
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
451 new_line_len = (unsigned)(verbatim_copy_end - oldp)
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
452 + fill
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
453 + (unsigned)STRLEN(non_white) + 1;
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
454
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
455 newp = alloc(new_line_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 return;
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
458 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
459 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill);
1839
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
460 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 /* replace the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 ml_replace(curwin->w_cursor.lnum, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 State = oldstate;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 curwin->w_cursor.col = oldcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 #ifdef FEAT_RIGHTLEFT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468 p_ri = old_p_ri;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 }
15422
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
471
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 * Insert string "s" (b_insert ? before : after) block :AKelly
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 * Caller must prepare for undo.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
477 block_insert(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
478 oparg_T *oap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
479 char_u *s,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
480 int b_insert,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
481 struct block_def *bdp)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 {
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
483 int ts_val;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 int count = 0; /* extra spaces to replace a cut TAB */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 int spaces = 0; /* non-zero if cutting a TAB */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 colnr_T offset; /* pointer along new line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 unsigned s_len; /* STRLEN(s) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 char_u *newp, *oldp; /* new, old lines */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 linenr_T lnum; /* loop var */
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 State = INSERT; /* don't want REPLACE for State */
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)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 continue; /* OP_INSERT, line ends before block start */
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)
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
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 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511 else /* append */
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;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 if (!bdp->is_short) /* spaces = padding after block */
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)
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
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 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521 else /* spaces = padding to block edge */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 /* if $ used, just append to EOL (ie spaces==0) */
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)
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
532 {
6460
29f5cfca3388 updated for version 7.4.559
Bram Moolenaar <bram@vim.org>
parents: 6379
diff changeset
533 int off;
29f5cfca3388 updated for version 7.4.559
Bram Moolenaar <bram@vim.org>
parents: 6379
diff changeset
534
6140
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
535 /* Avoid starting halfway a multi-byte character. */
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
536 if (b_insert)
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
537 {
6460
29f5cfca3388 updated for version 7.4.559
Bram Moolenaar <bram@vim.org>
parents: 6379
diff changeset
538 off = (*mb_head_off)(oldp, oldp + offset + spaces);
6140
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
539 }
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
540 else
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
541 {
6460
29f5cfca3388 updated for version 7.4.559
Bram Moolenaar <bram@vim.org>
parents: 6379
diff changeset
542 off = (*mb_off_next)(oldp, oldp + offset);
6140
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
543 offset += off;
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
544 }
6460
29f5cfca3388 updated for version 7.4.559
Bram Moolenaar <bram@vim.org>
parents: 6379
diff changeset
545 spaces -= off;
29f5cfca3388 updated for version 7.4.559
Bram Moolenaar <bram@vim.org>
parents: 6379
diff changeset
546 count -= off;
6140
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
547 }
cb3218a69c2f updated for version 7.4.408
Bram Moolenaar <bram@vim.org>
parents: 6116
diff changeset
548
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
549 newp = alloc(STRLEN(oldp) + s_len + count + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
550 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
551 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
552
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
553 /* copy up to shifted part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
554 mch_memmove(newp, oldp, (size_t)(offset));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
555 oldp += offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
556
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
557 /* insert pre-padding */
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
558 vim_memset(newp + offset, ' ', (size_t)spaces);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
559
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
560 /* copy the new text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
561 mch_memmove(newp + offset + spaces, s, (size_t)s_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
562 offset += s_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
563
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
564 if (spaces && !bdp->is_short)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
565 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
566 /* insert post-padding */
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
567 vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
568 /* We're splitting a TAB, don't copy it. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
569 oldp++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
570 /* We allowed for that TAB, remember this now */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
571 count++;
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
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
580 if (lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
581 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
582 /* Set "']" mark to the end of the block instead of the end of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
583 * the insert in the first line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
584 curbuf->b_op_end.lnum = oap->end.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
585 curbuf->b_op_end.col = offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
586 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
587 } /* for all lnum */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
588
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
589 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
590
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
591 State = oldstate;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
592 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
593
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
594 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
595 * Stuff a string into the typeahead buffer, such that edit() will insert it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
596 * literally ("literally" TRUE) or interpret is as typed characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
597 */
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18100
diff changeset
598 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
599 stuffescaped(char_u *arg, int literally)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
600 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
601 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
602 char_u *start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
603
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
604 while (*arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
605 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
606 /* Stuff a sequence of normal ASCII characters, that's fast. Also
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
607 * stuff K_SPECIAL to get the effect of a special key when "literally"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
608 * is TRUE. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
609 start = arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
610 while ((*arg >= ' '
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
611 #ifndef EBCDIC
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
612 && *arg < DEL /* EBCDIC: chars above space are normal */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
613 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
614 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
615 || (*arg == K_SPECIAL && !literally))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
616 ++arg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
617 if (arg > start)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
618 stuffReadbuffLen(start, (long)(arg - start));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
619
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
620 /* stuff a single special character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
621 if (*arg != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
622 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
623 if (has_mbyte)
2446
348f64c129df Fixed: CTRL-R in Insert mode doesn't insert composing characters.
Bram Moolenaar <bram@vim.org>
parents: 2311
diff changeset
624 c = mb_cptr2char_adv(&arg);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
625 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
626 c = *arg++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
627 if (literally && ((c < ' ' && c != TAB) || c == DEL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
628 stuffcharReadbuff(Ctrl_V);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
629 stuffcharReadbuff(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
630 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
631 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
632 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
633
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
634 /*
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
635 * Handle a delete operation.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
636 *
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
637 * Return FAIL if undo failed, OK otherwise.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
638 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
639 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
640 op_delete(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
641 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
642 int n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
643 linenr_T lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
644 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
645 char_u *newp, *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
646 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
647 linenr_T old_lcount = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
648 int did_yank = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
649
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
650 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
651 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
652
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
653 /* Nothing to delete, return here. Do prepare undo, for op_change(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
654 if (oap->empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
655 return u_save_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
656
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
657 if (!curbuf->b_p_ma)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
658 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15428
diff changeset
659 emsg(_(e_modifiable));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
660 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
661 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
662
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
663 #ifdef FEAT_CLIPBOARD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
664 adjust_clip_reg(&oap->regname);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
665 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
666
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
667 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
668 mb_adjust_opend(oap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
669
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
670 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
671 * 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
672 * 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
673 * 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
674 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
675 if ( oap->motion_type == MCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
676 && !oap->is_VIsual
50
90188be4861f updated for version 7.0028
vimboss
parents: 45
diff changeset
677 && !oap->block_mode
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
678 && oap->line_count > 1
3254
2f075595590f updated for version 7.3.396
Bram Moolenaar <bram@vim.org>
parents: 3252
diff changeset
679 && oap->motion_force == NUL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
680 && oap->op_type == OP_DELETE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
681 {
2957
fe6ad3fd8532 updated for version 7.3.251
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
682 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
683 if (*ptr != NUL)
fe6ad3fd8532 updated for version 7.3.251
Bram Moolenaar <bram@vim.org>
parents: 2896
diff changeset
684 ptr += oap->inclusive;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
685 ptr = skipwhite(ptr);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
686 if (*ptr == NUL && inindent(0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
687 oap->motion_type = MLINE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
688 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
689
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
690 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
691 * 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
692 * 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
693 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
694 if ( oap->motion_type == MCHAR
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
695 && oap->line_count == 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
696 && oap->op_type == OP_DELETE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
697 && *ml_get(oap->start.lnum) == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
698 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
699 /*
446
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
700 * 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
701 * 'cpoptions' (Vi compatible).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
702 */
446
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
703 if (virtual_op)
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
704 /* Virtual editing: Nothing gets deleted, but we set the '[ and ']
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
705 * marks as if it happened. */
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
706 goto setmarks;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
707 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
708 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
709 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
710 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
711
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
712 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
713 * 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
714 * 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
715 * 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
716 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
717 if (oap->regname != '_')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
718 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
719 if (oap->regname != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
720 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
721 /* check for read-only register */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
722 if (!valid_yank_reg(oap->regname, TRUE))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
723 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
724 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
725 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
727 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
728 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
729 did_yank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
730 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
731
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
732 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
733 * 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
734 * 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
735 * compatible)
3782
063765c3cebb updated for version 7.3.649
Bram Moolenaar <bram@vim.org>
parents: 3740
diff changeset
736 * 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
737 * changed it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
738 */
15987
29de75f53b1a patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents: 15967
diff changeset
739 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
740 || oap->use_reg_one)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
741 {
10827
e366b968bf08 patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents: 10803
diff changeset
742 shift_delete_registers();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
743 if (op_yank(oap, TRUE, FALSE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
744 did_yank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
746
3468
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
747 /* Yank into small delete register when no named register specified
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
748 * and the delete is within one line. */
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
749 if ((
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
750 #ifdef FEAT_CLIPBOARD
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
751 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') ||
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
752 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') ||
3468
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
753 #endif
b1a42d2522fb updated for version 7.3.498
Bram Moolenaar <bram@vim.org>
parents: 3421
diff changeset
754 oap->regname == 0) && oap->motion_type != MLINE
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
755 && oap->line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
756 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
757 oap->regname = '-';
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
758 get_yank_register(oap->regname, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
759 if (op_yank(oap, TRUE, FALSE) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
760 did_yank = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
761 oap->regname = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
762 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
763
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
764 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
765 * 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
766 * confirmation before doing the delete. This is crude, but simple.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
767 * 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
768 * want.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
769 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
770 if (!did_yank)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
771 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
772 int msg_silent_save = msg_silent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
773
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
774 msg_silent = 0; /* must display the prompt */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
775 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
776 msg_silent = msg_silent_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
777 if (n != 'y')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
778 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15428
diff changeset
779 emsg(_(e_abort));
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
780 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
781 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
782 }
13037
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 12996
diff changeset
783
13380
69517d67421f patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents: 13254
diff changeset
784 #if defined(FEAT_EVAL)
13037
6e81a68d63a1 patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents: 12996
diff changeset
785 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
786 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
787 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
788 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
789
2289
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
790 /*
3331756e4232 Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents: 2278
diff changeset
791 * 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
792 */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
793 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
794 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
795 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
796 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
797 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
798
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
799 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
800 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
801 block_prep(oap, &bd, lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
802 if (bd.textlen == 0) /* nothing to delete */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
803 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
804
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
805 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
806 if (lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
807 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
808 curwin->w_cursor.col = bd.textcol + bd.startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
809 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
810 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
811
16682
7847d281cbbf patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents: 16680
diff changeset
812 // "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
813 // 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
814 // Thus the number of characters may increase!
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
815 n = bd.textlen - bd.startspaces - bd.endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
816 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
817 newp = alloc(STRLEN(oldp) + 1 - n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
818 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
819 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
820 /* copy up to deleted part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
821 mch_memmove(newp, oldp, (size_t)bd.textcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
822 /* insert spaces */
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
823 vim_memset(newp + bd.textcol, ' ',
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
824 (size_t)(bd.startspaces + bd.endspaces));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
825 /* copy the part after the deleted part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
826 oldp += bd.textcol + bd.textlen;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1563
diff changeset
827 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
828 /* replace the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
829 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
830
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
831 #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
832 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
833 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
834 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
835 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
836
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
837 check_cursor_col();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
838 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
839 oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
840 oap->line_count = 0; /* no lines deleted */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
841 }
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
842 else if (oap->motion_type == MLINE)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
844 if (oap->op_type == OP_CHANGE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
845 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
846 /* Delete the lines except the first one. Temporarily move the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
847 * cursor to the next line. Save the current line number, if the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
848 * last line is deleted it may be changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
849 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
850 if (oap->line_count > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
851 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
852 lnum = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
853 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
854 del_lines((long)(oap->line_count - 1), TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
855 curwin->w_cursor.lnum = lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
856 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
857 if (u_save_cursor() == FAIL)
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 (curbuf->b_p_ai) /* don't delete indent */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
860 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
861 beginline(BL_WHITE); /* cursor on first non-white */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
862 did_ai = TRUE; /* delete the indent when ESC hit */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
863 ai_col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
865 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
866 beginline(0); /* cursor in column 0 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
867 truncate_line(FALSE); /* delete the rest of the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
868 /* leave cursor past last char in line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
869 if (oap->line_count > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
870 u_clearline(); /* "U" command not possible after "2cc" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
871 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
872 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
873 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
874 del_lines(oap->line_count, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
875 beginline(BL_WHITE | BL_FIX);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
876 u_clearline(); /* "U" command not possible after "dd" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
877 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
878 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
879 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
880 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
881 if (virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
882 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
883 int endcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
884
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
885 /* For virtualedit: break the tabs that are partly included. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
886 if (gchar_pos(&oap->start) == '\t')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
887 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
888 if (u_save_cursor() == FAIL) /* save first line for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
889 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
890 if (oap->line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
891 endcol = getviscol2(oap->end.col, oap->end.coladd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
892 coladvance_force(getviscol2(oap->start.col, oap->start.coladd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
893 oap->start = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
894 if (oap->line_count == 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
895 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
896 coladvance(endcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
897 oap->end.col = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
898 oap->end.coladd = curwin->w_cursor.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
899 curwin->w_cursor = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
900 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
901 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
902
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
903 /* Break a tab only when it's included in the area. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
904 if (gchar_pos(&oap->end) == '\t'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
905 && (int)oap->end.coladd < oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
906 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
907 /* save last line for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
908 if (u_save((linenr_T)(oap->end.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
909 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
910 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
911 curwin->w_cursor = oap->end;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
912 coladvance_force(getviscol2(oap->end.col, oap->end.coladd));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
913 oap->end = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
914 curwin->w_cursor = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
915 }
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
916 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
917 mb_adjust_opend(oap);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
918 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
919
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
920 if (oap->line_count == 1) /* delete characters within one line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
921 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
922 if (u_save_cursor() == FAIL) /* save line for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
923 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
924
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
925 /* 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
926 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
927 && oap->op_type == OP_CHANGE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
928 && oap->end.lnum == curwin->w_cursor.lnum
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
929 && !oap->is_VIsual)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
930 display_dollar(oap->end.col - !oap->inclusive);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
931
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
932 n = oap->end.col - oap->start.col + 1 - !oap->inclusive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
933
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
934 if (virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
935 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
936 /* fix up things for virtualedit-delete:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
937 * break the tabs which are going to get in our way
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
938 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
939 char_u *curline = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
940 int len = (int)STRLEN(curline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
941
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
942 if (oap->end.coladd != 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
943 && (int)oap->end.col >= len - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
944 && !(oap->start.coladd && (int)oap->end.col >= len - 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
945 n++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
946 /* Delete at least one char (e.g, when on a control char). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
947 if (n == 0 && oap->start.coladd != oap->end.coladd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
948 n = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
949
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
950 /* When deleted a char in the line, reset coladd. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
951 if (gchar_cursor() != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
952 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
953 }
6826
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
954 (void)del_bytes((long)n, !virtual_op,
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
955 oap->op_type == OP_DELETE && !oap->is_VIsual);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
956 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
957 else /* delete characters between lines */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
958 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
959 pos_T curpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
960
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
961 /* save deleted and changed lines for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
962 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
963 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
964 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
965
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
966 truncate_line(TRUE); /* delete from cursor to end of line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
967
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
968 curpos = curwin->w_cursor; /* remember curwin->w_cursor */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
969 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
970 del_lines((long)(oap->line_count - 2), FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
971
6826
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
972 /* 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
973 n = (oap->end.col + 1 - !oap->inclusive);
6826
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
974 curwin->w_cursor.col = 0;
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
975 (void)del_bytes((long)n, !virtual_op,
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
976 oap->op_type == OP_DELETE && !oap->is_VIsual);
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
977 curwin->w_cursor = curpos; /* restore curwin->w_cursor */
bf3e6012dfbd patch 7.4.734
Bram Moolenaar <bram@vim.org>
parents: 6807
diff changeset
978 (void)do_join(2, FALSE, FALSE, FALSE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
979 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
980 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
981
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
982 msgmore(curbuf->b_ml.ml_line_count - old_lcount);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
983
446
7472c565592a updated for version 7.0117
vimboss
parents: 419
diff changeset
984 setmarks:
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
985 if (!cmdmod.lockmarks)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
986 {
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
987 if (oap->block_mode)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
988 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
989 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
990 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
991 }
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
992 else
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
993 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
994 curbuf->b_op_start = oap->start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
995 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
996
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
997 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
998 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
999
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1000 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1001 * Adjust end of operating area for ending on a multi-byte character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1002 * Used for deletion.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1003 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1004 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1005 mb_adjust_opend(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1006 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1007 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1008
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1009 if (oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1010 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1011 p = ml_get(oap->end.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1012 oap->end.col += mb_tail_off(p, p + oap->end.col);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1013 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1014 }
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1015
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
1016 /*
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1017 * 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
1018 * 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
1019 */
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1020 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
1021 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
1022 {
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1023 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
1024
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
1025 State = REPLACE;
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1026 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
1027 State = n;
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1028 /* Backup to the replaced character. */
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1029 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
1030 }
15422
b55b89692fd2 patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15326
diff changeset
1031
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1032 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1033 * Replace a whole area with one character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1034 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1035 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1036 op_replace(oparg_T *oap, int c)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1037 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1038 int n, numc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1039 int num_chars;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1040 char_u *newp, *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1041 size_t oldlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1042 struct block_def bd;
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1043 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
1044 int had_ctrl_v_cr = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1045
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1046 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1047 return OK; /* nothing to do */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1048
13202
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1049 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
1050 {
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1051 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
1052 c = CAR;
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1053 }
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1054 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
1055 {
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1056 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
1057 c = NL;
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1058 }
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1059
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1060 if (has_mbyte)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1061 mb_adjust_opend(oap);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1062
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1063 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1064 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1065 return FAIL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1066
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1067 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1068 * block mode replace
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1069 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1070 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1071 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1072 bd.is_MAX = (curwin->w_curswant == MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1073 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1074 {
1982
b1b09b68d706 updated for version 7.2-279
vimboss
parents: 1969
diff changeset
1075 curwin->w_cursor.col = 0; /* make sure cursor position is valid */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1076 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1077 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1078 continue; /* nothing to replace */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1079
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1080 /* n == number of extra chars required
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1081 * If we split a TAB, it may be replaced by several characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1082 * Thus the number of characters may increase!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1083 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1084 /* If the range starts in virtual space, count the initial
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1085 * coladd offset as part of "startspaces" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1086 if (virtual_op && bd.is_short && *bd.textstart == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1087 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1088 pos_T vpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1089
1982
b1b09b68d706 updated for version 7.2-279
vimboss
parents: 1969
diff changeset
1090 vpos.lnum = curwin->w_cursor.lnum;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1091 getvpos(&vpos, oap->start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1092 bd.startspaces += vpos.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1093 n = bd.startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1094 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1095 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1096 /* allow for pre spaces */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1097 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1098
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1099 /* allow for post spp */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1100 n += (bd.endspaces
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1101 && !bd.is_oneChar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1102 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1103 /* Figure out how many characters to replace. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1104 numc = oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1105 if (bd.is_short && (!virtual_op || bd.is_MAX))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1106 numc -= (oap->end_vcol - bd.end_vcol) + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1107
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1108 /* A double-wide character can be replaced only up to half the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1109 * times. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1110 if ((*mb_char2cells)(c) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1111 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1112 if ((numc & 1) && !bd.is_short)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1113 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1114 ++bd.endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1115 ++n;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1116 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1117 numc = numc / 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1118 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1119
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1120 /* Compute bytes needed, move character count to num_chars. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1121 num_chars = numc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1122 numc *= (*mb_char2len)(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1123 /* oldlen includes textlen, so don't double count */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1124 n += numc - bd.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1126 oldp = ml_get_curline();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1127 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
1128 newp = alloc(oldlen + 1 + n);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1129 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1130 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1131 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1132 /* copy up to deleted part */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1133 mch_memmove(newp, oldp, (size_t)bd.textcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1134 oldp += bd.textcol + bd.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1135 /* insert pre-spaces */
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1136 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1137 /* insert replacement chars CHECK FOR ALLOCATED SPACE */
13202
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1138 /* REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR
2941a86f8aaa patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents: 13072
diff changeset
1139 * literally. */
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1140 if (had_ctrl_v_cr || (c != '\r' && c != '\n'))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1141 {
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1142 if (has_mbyte)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1143 {
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1144 n = (int)STRLEN(newp);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1145 while (--num_chars >= 0)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1146 n += (*mb_char2bytes)(c, newp + n);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1147 }
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1148 else
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1149 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
1150 if (!bd.is_short)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1151 {
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1152 /* insert post-spaces */
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1153 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces);
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1154 /* copy the part after the changed part */
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1155 STRMOVE(newp + STRLEN(newp), oldp);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1156 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1157 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1158 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1159 {
5428
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1160 /* 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
1161 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
1162 if (after_p != NULL)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1163 STRMOVE(after_p, oldp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1164 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1165 /* replace the line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1166 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
1167 if (after_p != NULL)
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1168 {
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1169 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
1170 appended_lines_mark(curwin->w_cursor.lnum, 1L);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1171 oap->end.lnum++;
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1172 vim_free(after_p);
d06223965468 updated for version 7.4.064
Bram Moolenaar <bram@vim.org>
parents: 5415
diff changeset
1173 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1174 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1175 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1176 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1177 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1178 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1179 * MCHAR and MLINE motion replace.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1180 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1181 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1182 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1183 oap->start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1184 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1185 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1186 if (oap->end.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1187 --oap->end.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1188 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1189 else if (!oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1190 dec(&(oap->end));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1191
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11065
diff changeset
1192 while (LTOREQ_POS(curwin->w_cursor, oap->end))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1193 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1194 n = gchar_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1195 if (n != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1196 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1197 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1198 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1199 /* This is slow, but it handles replacing a single-byte
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1200 * 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
1201 if (curwin->w_cursor.lnum == oap->end.lnum)
eea32254940f updated for version 7.3.853
Bram Moolenaar <bram@vim.org>
parents: 4201
diff changeset
1202 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n);
14216
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1203 replace_character(c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1204 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1205 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1206 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1207 if (n == TAB)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1208 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1209 int end_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1210
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1211 if (curwin->w_cursor.lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1212 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1213 /* oap->end has to be recalculated when
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1214 * the tab breaks */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1215 end_vcol = getviscol2(oap->end.col,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1216 oap->end.coladd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1217 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1218 coladvance_force(getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1219 if (curwin->w_cursor.lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1220 getvpos(&oap->end, end_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1221 }
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
1222 PBYTE(curwin->w_cursor, c);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1223 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1224 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1225 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1226 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1227 int virtcols = oap->end.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1228
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1229 if (curwin->w_cursor.lnum == oap->start.lnum
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1230 && oap->start.col == oap->end.col && oap->start.coladd)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1231 virtcols -= oap->start.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1232
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1233 /* oap->end has been trimmed so it's effectively inclusive;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1234 * as a result an extra +1 must be counted so we don't
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1235 * trample the NUL byte. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1236 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1237 curwin->w_cursor.col -= (virtcols + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1238 for (; virtcols >= 0; virtcols--)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1239 {
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
1240 if ((*mb_char2len)(c) > 1)
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1241 replace_character(c);
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1242 else
12bdbf9f7e20 patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents: 14202
diff changeset
1243 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
1244 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
1245 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1247 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1249 /* Advance to next character, stop at the end of the file. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1250 if (inc_cursor() == -1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1251 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1253 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1255 curwin->w_cursor = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1256 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1257 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1258
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1259 if (!cmdmod.lockmarks)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1260 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1261 /* Set "'[" and "']" marks. */
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1262 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
1263 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
1264 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1266 return OK;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1267 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1268
7805
0b6c37dd858d commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents: 7576
diff changeset
1269 static int swapchars(int op_type, pos_T *pos, int length);
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1270
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1271 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1272 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1273 */
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
1274 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1275 op_tilde(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1276 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1277 pos_T pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1278 struct block_def bd;
1528
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1279 int did_change = FALSE;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1280
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1281 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1282 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1283 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1284
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1285 pos = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1286 if (oap->block_mode) /* Visual block mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1287 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1288 for (; pos.lnum <= oap->end.lnum; ++pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1289 {
1766
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1290 int one_change;
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1291
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1292 block_prep(oap, &bd, pos.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1293 pos.col = bd.textcol;
1766
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1294 one_change = swapchars(oap->op_type, &pos, bd.textlen);
bb4797166e4c updated for version 7.2-064
vimboss
parents: 1622
diff changeset
1295 did_change |= one_change;
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1296
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
1297 #ifdef FEAT_NETBEANS_INTG
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1298 if (netbeans_active() && one_change)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1299 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1300 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1301
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1302 netbeans_removed(curbuf, pos.lnum, bd.textcol,
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1303 (long)bd.textlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1304 netbeans_inserted(curbuf, pos.lnum, bd.textcol,
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1305 &ptr[bd.textcol], bd.textlen);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1306 }
5735
50dbef5e774a updated for version 7.4.212
Bram Moolenaar <bram@vim.org>
parents: 5730
diff changeset
1307 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1308 }
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 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1311 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1312 else /* not block mode */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1313 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1314 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1315 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1316 oap->start.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1317 pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1318 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1319 if (oap->end.col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1320 --oap->end.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1321 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1322 else if (!oap->inclusive)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1323 dec(&(oap->end));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1324
1528
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1325 if (pos.lnum == oap->end.lnum)
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1326 did_change = swapchars(oap->op_type, &pos,
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1327 oap->end.col - pos.col + 1);
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1328 else
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1329 for (;;)
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1330 {
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1331 did_change |= swapchars(oap->op_type, &pos,
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1332 pos.lnum == oap->end.lnum ? oap->end.col + 1:
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1333 (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
1334 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1)
1528
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1335 break;
e212d1a40ca9 updated for version 7.1-243
vimboss
parents: 1525
diff changeset
1336 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1337 if (did_change)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1338 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1339 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1340 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1341 #ifdef FEAT_NETBEANS_INTG
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1342 if (netbeans_active() && did_change)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1343 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1344 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1345 int count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1347 pos = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1348 while (pos.lnum < oap->end.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1349 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1350 ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
835
8bebcabccc2c updated for version 7.0e01
vimboss
parents: 777
diff changeset
1351 count = (int)STRLEN(ptr) - pos.col;
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1352 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1353 netbeans_inserted(curbuf, pos.lnum, pos.col,
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1354 &ptr[pos.col], count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1355 pos.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1356 pos.lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1357 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1358 ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1359 count = oap->end.col - pos.col + 1;
33
f6033dcbaf31 updated for version 7.0020
vimboss
parents: 22
diff changeset
1360 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1361 netbeans_inserted(curbuf, pos.lnum, pos.col,
2210
8c6a66e2b3cc Add :nbstart and :nbclose.
Bram Moolenaar <bram@vim.org>
parents: 2061
diff changeset
1362 &ptr[pos.col], count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1363 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1364 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1365 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1366 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1367
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1368 if (!did_change && oap->is_VIsual)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1369 /* No change: need to remove the Visual selection */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1370 redraw_curbuf_later(INVERTED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1371
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1372 if (!cmdmod.lockmarks)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1373 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1374 // Set '[ and '] marks.
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1375 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
1376 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
1377 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1379 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
1380 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
1381 oap->line_count), oap->line_count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1382 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1383
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1384 /*
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1385 * Invoke swapchar() on "length" bytes at position "pos".
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1386 * "pos" is advanced to just after the changed characters.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1387 * "length" is rounded up to include the whole last multi-byte character.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1388 * Also works correctly when the number of bytes changes.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1389 * Returns TRUE if some character was changed.
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1390 */
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1391 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1392 swapchars(int op_type, pos_T *pos, int length)
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1393 {
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1394 int todo;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1395 int did_change = 0;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1396
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1397 for (todo = length; todo > 0; --todo)
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1398 {
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1399 if (has_mbyte)
5288
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1400 {
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1401 int len = (*mb_ptr2len)(ml_get_pos(pos));
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1402
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1403 /* we're counting bytes, not characters */
5288
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1404 if (len > 0)
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1405 todo -= len - 1;
46cf49cc9289 updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents: 5245
diff changeset
1406 }
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1407 did_change |= swapchar(op_type, pos);
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1408 if (inc(pos) == -1) /* at end of file */
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1409 break;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1410 }
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1411 return did_change;
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1412 }
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1413
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1414 /*
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1415 * If op_type == OP_UPPER: make uppercase,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1416 * if op_type == OP_LOWER: make lowercase,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1417 * if op_type == OP_ROT13: do rot13 encoding,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1418 * else swap case of character at 'pos'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1419 * returns TRUE when something actually changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1420 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1421 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1422 swapchar(int op_type, pos_T *pos)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1423 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1424 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1425 int nc;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1427 c = gchar_pos(pos);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1428
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1429 /* Only do rot13 encoding for ASCII characters. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1430 if (c >= 0x80 && op_type == OP_ROT13)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1431 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1432
1525
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1433 if (op_type == OP_UPPER && c == 0xdf
76985a406456 updated for version 7.1-240
vimboss
parents: 1516
diff changeset
1434 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0))
493
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1435 {
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1436 pos_T sp = curwin->w_cursor;
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1437
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1438 /* Special handling of German sharp s: change to "SS". */
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1439 curwin->w_cursor = *pos;
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1440 del_char(FALSE);
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1441 ins_char('S');
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1442 ins_char('S');
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1443 curwin->w_cursor = sp;
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1444 inc(pos);
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1445 }
06364aa0d597 updated for version 7.0135
vimboss
parents: 480
diff changeset
1446
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1447 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1448 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1449 nc = c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1450 if (MB_ISLOWER(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1451 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1452 if (op_type == OP_ROT13)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1453 nc = ROT13(c, 'a');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1454 else if (op_type != OP_LOWER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1455 nc = MB_TOUPPER(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1456 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1457 else if (MB_ISUPPER(c))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1458 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1459 if (op_type == OP_ROT13)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1460 nc = ROT13(c, 'A');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1461 else if (op_type != OP_UPPER)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1462 nc = MB_TOLOWER(c);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1463 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1464 if (nc != c)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1466 if (enc_utf8 && (c >= 0x80 || nc >= 0x80))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1467 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1468 pos_T sp = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1469
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1470 curwin->w_cursor = *pos;
2451
0b8612c2814d Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents: 2446
diff changeset
1471 /* don't use del_char(), it also removes composing chars */
0b8612c2814d Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents: 2446
diff changeset
1472 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1473 ins_char(nc);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1474 curwin->w_cursor = sp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1475 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1476 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
1477 PBYTE(*pos, nc);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1478 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1479 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1480 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1481 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1483 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1484 * op_insert - Insert and append operators for Visual mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1485 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1486 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1487 op_insert(oparg_T *oap, long count1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1488 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1489 long ins_len, pre_textlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1490 char_u *firstline, *ins_text;
12329
0b10cff73322 patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12327
diff changeset
1491 colnr_T ind_pre = 0, ind_post;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1492 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1493 int i;
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1494 pos_T t1;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1496 /* edit() changes this - record it for OP_APPEND */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1497 bd.is_MAX = (curwin->w_curswant == MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1498
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1499 /* vis block is still marked. Get rid of it now. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1500 curwin->w_cursor.lnum = oap->start.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1501 update_screen(INVERTED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1503 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1504 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1505 /* When 'virtualedit' is used, need to insert the extra spaces before
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1506 * doing block_prep(). When only "block" is used, virtual edit is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1507 * already disabled, but still need it when calling
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1508 * coladvance_force(). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1509 if (curwin->w_cursor.coladd > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1510 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1511 int old_ve_flags = ve_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1512
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1513 ve_flags = VE_ALL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1514 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1515 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1516 coladvance_force(oap->op_type == OP_APPEND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1517 ? oap->end_vcol + 1 : getviscol());
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1518 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1519 --curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1520 ve_flags = old_ve_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1521 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1522 /* Get the info about the block before entering the text */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1523 block_prep(oap, &bd, oap->start.lnum, TRUE);
12323
4dba3e4f3b01 patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents: 11997
diff changeset
1524 /* Get indent information */
4dba3e4f3b01 patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents: 11997
diff changeset
1525 ind_pre = (colnr_T)getwhitecols_curline();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1526 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
1527
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1528 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1529 firstline += bd.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1530 pre_textlen = (long)STRLEN(firstline);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1531 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1533 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1534 {
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1535 if (oap->block_mode && curwin->w_cursor.coladd == 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1536 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1537 /* Move the cursor to the character right of the block. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1538 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1539 while (*ml_get_cursor() != NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1540 && (curwin->w_cursor.col < bd.textcol + bd.textlen))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1541 ++curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1542 if (bd.is_short && !bd.is_MAX)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1543 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1544 /* First line was too short, make it longer and adjust the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1545 * values in "bd". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1546 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1547 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1548 for (i = 0; i < bd.endspaces; ++i)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1549 ins_char(' ');
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1550 bd.textlen += bd.endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1551 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1552 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1553 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1554 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1555 curwin->w_cursor = oap->end;
893
bf7803d0f5b9 updated for version 7.0-019
vimboss
parents: 856
diff changeset
1556 check_cursor_col();
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1557
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1558 /* 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
1559 if (!LINEEMPTY(curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1560 && oap->start_vcol != oap->end_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1561 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1562 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1563 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1564
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1565 t1 = oap->start;
10803
065da86ca6d2 patch 8.0.0291: Visual block insertion does not insert in all lines
Christian Brabandt <cb@256bit.org>
parents: 10785
diff changeset
1566 (void)edit(NUL, FALSE, (linenr_T)count1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1567
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1568 /* When a tab was inserted, and the characters in front of the tab
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1569 * have been converted to a tab as well, the column of the cursor
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1570 * might have actually been reduced, so need to adjust here. */
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1571 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
1572 && 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
1573 oap->start = curbuf->b_op_start_orig;
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1574
1477
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1575 /* If user has moved off this line, we don't know what to do, so do
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1576 * nothing.
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1577 * Also don't repeat the insert when Insert mode ended with CTRL-C. */
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1578 if (curwin->w_cursor.lnum != oap->start.lnum || got_int)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1579 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1580
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1581 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1582 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1583 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
1584 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
1585 size_t len;
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1586 int add;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1587
12327
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1588 /* If indent kicked in, the firstline might have changed
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1589 * but only do that, if the indent actually increased. */
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1590 ind_post = (colnr_T)getwhitecols_curline();
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1591 if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre)
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1592 {
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1593 bd.textcol += ind_post - ind_pre;
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1594 bd.start_vcol += ind_post - ind_pre;
13620
4faf77b96432 patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents: 13614
diff changeset
1595 did_indent = TRUE;
12327
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1596 }
17ed65e87db1 patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents: 12323
diff changeset
1597
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1598 /* The user may have moved the cursor before inserting something, try
13620
4faf77b96432 patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents: 13614
diff changeset
1599 * to adjust the block for that. But only do it, if the difference
4faf77b96432 patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents: 13614
diff changeset
1600 * does not come from indent kicking in. */
4faf77b96432 patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents: 13614
diff changeset
1601 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
1602 && !bd.is_MAX && !did_indent)
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1603 {
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1604 if (oap->op_type == OP_INSERT
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1605 && oap->start.col + oap->start.coladd
5730
420fd9cb86d5 updated for version 7.4.210
Bram Moolenaar <bram@vim.org>
parents: 5680
diff changeset
1606 != curbuf->b_op_start_orig.col
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1607 + curbuf->b_op_start_orig.coladd)
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1608 {
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1609 int t = getviscol2(curbuf->b_op_start_orig.col,
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1610 curbuf->b_op_start_orig.coladd);
5680
4d12112c5efa updated for version 7.4.186
Bram Moolenaar <bram@vim.org>
parents: 5664
diff changeset
1611 oap->start.col = curbuf->b_op_start_orig.col;
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1612 pre_textlen -= t - oap->start_vcol;
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1613 oap->start_vcol = t;
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1614 }
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1615 else if (oap->op_type == OP_APPEND
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1616 && oap->end.col + oap->end.coladd
5730
420fd9cb86d5 updated for version 7.4.210
Bram Moolenaar <bram@vim.org>
parents: 5680
diff changeset
1617 >= curbuf->b_op_start_orig.col
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1618 + curbuf->b_op_start_orig.coladd)
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1619 {
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1620 int t = getviscol2(curbuf->b_op_start_orig.col,
15636
6f1c7e9a6393 patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15597
diff changeset
1621 curbuf->b_op_start_orig.coladd);
5680
4d12112c5efa updated for version 7.4.186
Bram Moolenaar <bram@vim.org>
parents: 5664
diff changeset
1622 oap->start.col = curbuf->b_op_start_orig.col;
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1623 /* reset pre_textlen to the value of OP_INSERT */
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1624 pre_textlen += bd.textlen;
6579
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1625 pre_textlen -= t - oap->start_vcol;
a287b0e9e87b updated for version 7.4.616
Bram Moolenaar <bram@vim.org>
parents: 6557
diff changeset
1626 oap->start_vcol = t;
5471
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1627 oap->op_type = OP_INSERT;
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1628 }
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1629 }
70c3289803b3 updated for version 7.4.085
Bram Moolenaar <bram@vim.org>
parents: 5438
diff changeset
1630
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1631 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1632 * Spaces and tabs in the indent may have changed to other spaces and
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1633 * tabs. Get the starting column again and correct the length.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1634 * Don't do this when "$" used, end-of-line will have changed.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1635 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1636 block_prep(oap, &bd2, oap->start.lnum, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1637 if (!bd.is_MAX || bd2.textlen < bd.textlen)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1638 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1639 if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1640 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1641 pre_textlen += bd2.textlen - bd.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1642 if (bd2.endspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1643 --bd2.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1644 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1645 bd.textcol = bd2.textcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1646 bd.textlen = bd2.textlen;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1647 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1648
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1649 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1650 * Subsequent calls to ml_get() flush the firstline data - take a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1651 * copy of the required string.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1652 */
13814
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1653 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
1654 len = STRLEN(firstline);
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1655 add = bd.textcol;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1656 if (oap->op_type == OP_APPEND)
13814
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1657 add += bd.textlen;
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1658 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
1659 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
1660 else
7ed76dcf0d94 patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents: 13620
diff changeset
1661 firstline += add;
3421
fb2c5a51dac7 updated for version 7.3.476
Bram Moolenaar <bram@vim.org>
parents: 3400
diff changeset
1662 if (pre_textlen >= 0
fb2c5a51dac7 updated for version 7.3.476
Bram Moolenaar <bram@vim.org>
parents: 3400
diff changeset
1663 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1664 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1665 ins_text = vim_strnsave(firstline, (int)ins_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1666 if (ins_text != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1667 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1668 /* block handled here */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1669 if (u_save(oap->start.lnum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1670 (linenr_T)(oap->end.lnum + 1)) == OK)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1671 block_insert(oap, ins_text, (oap->op_type == OP_INSERT),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1672 &bd);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1673
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1674 curwin->w_cursor.col = oap->start.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1675 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1676 vim_free(ins_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1677 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1678 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1679 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1680 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1682 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1683 * op_change - handle a change operation
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1684 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1685 * return TRUE if edit() returns because of a CTRL-O command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1686 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1687 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1688 op_change(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1689 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1690 colnr_T l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1691 int retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1692 long offset;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1693 linenr_T linenr;
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1694 long ins_len;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1695 long pre_textlen = 0;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1696 long pre_indent = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1697 char_u *firstline;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1698 char_u *ins_text, *newp, *oldp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1699 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1700
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1701 l = oap->start.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1702 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1703 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1704 l = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1705 #ifdef FEAT_SMARTINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1706 if (!p_paste && curbuf->b_p_si
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1707 # ifdef FEAT_CINDENT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1708 && !curbuf->b_p_cin
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1709 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1710 )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1711 can_si = TRUE; /* It's like opening a new line, do si */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1712 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1713 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1715 /* First delete the text in the region. In an empty buffer only need to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1716 * save for undo */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1717 if (curbuf->b_ml.ml_flags & ML_EMPTY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1718 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1719 if (u_save_cursor() == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1720 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1721 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1722 else if (op_delete(oap) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1723 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1724
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11065
diff changeset
1725 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1726 && !virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1727 inc_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1728
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1729 /* check for still on same line (<CR> in inserted text meaningless) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1730 /* skip blank lines too */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1731 if (oap->block_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1732 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1733 /* Add spaces before getting the current line length. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1734 if (virtual_op && (curwin->w_cursor.coladd > 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1735 || gchar_cursor() == NUL))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1736 coladvance_force(getviscol());
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1737 firstline = ml_get(oap->start.lnum);
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1738 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
1739 pre_indent = (long)getwhitecols(firstline);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1740 bd.textcol = curwin->w_cursor.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1741 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1742
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1743 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1744 if (oap->motion_type == MLINE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1745 fix_indent();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1746 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1747
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1748 retval = edit(NUL, FALSE, (linenr_T)1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1749
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1750 /*
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 36
diff changeset
1751 * 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
1752 * block.
1477
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1753 * Don't repeat the insert when Insert mode ended with CTRL-C.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1754 */
1477
2951f28a9bd3 updated for version 7.1-192
vimboss
parents: 1451
diff changeset
1755 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1756 {
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1757 /* Auto-indenting may have changed the indent. If the cursor was past
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1758 * the indent, exclude that indent change from the inserted text. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1759 firstline = ml_get(oap->start.lnum);
1403
871231399cf5 updated for version 7.1-118
vimboss
parents: 1392
diff changeset
1760 if (bd.textcol > (colnr_T)pre_indent)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1761 {
12323
4dba3e4f3b01 patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents: 11997
diff changeset
1762 long new_indent = (long)getwhitecols(firstline);
1392
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1763
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1764 pre_textlen += new_indent - pre_indent;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1765 bd.textcol += new_indent - pre_indent;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1766 }
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 ins_len = (long)STRLEN(firstline) - pre_textlen;
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1769 if (ins_len > 0)
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 /* Subsequent calls to ml_get() flush the firstline data - take a
27782797c331 updated for version 7.1-107
vimboss
parents: 1304
diff changeset
1772 * 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
1773 if ((ins_text = alloc(ins_len + 1)) != NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1774 {
419
f713fc55bf7b updated for version 7.0109
vimboss
parents: 356
diff changeset
1775 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1776 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1777 linenr++)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1778 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1779 block_prep(oap, &bd, linenr, TRUE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1780 if (!bd.is_short || virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1781 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1782 pos_T vpos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1783
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1784 /* If the block starts in virtual space, count the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1785 * initial coladd offset as part of "startspaces" */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1786 if (bd.is_short)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1787 {
1982
b1b09b68d706 updated for version 7.2-279
vimboss
parents: 1969
diff changeset
1788 vpos.lnum = linenr;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1789 (void)getvpos(&vpos, oap->start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1790 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1791 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1792 vpos.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1793 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
1794 newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1795 if (newp == NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1796 continue;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1797 /* copy up to block start */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1798 mch_memmove(newp, oldp, (size_t)bd.textcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1799 offset = bd.textcol;
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
1800 vim_memset(newp + offset, ' ', (size_t)vpos.coladd);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1801 offset += vpos.coladd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1802 mch_memmove(newp + offset, ins_text, (size_t)ins_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1803 offset += ins_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1804 oldp += bd.textcol;
1622
149d8b46404c updated for version 7.2a
vimboss
parents: 1563
diff changeset
1805 STRMOVE(newp + offset, oldp);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1806 ml_replace(linenr, newp, FALSE);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1807 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1808 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1809 check_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1810
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1811 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1812 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1813 vim_free(ins_text);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1814 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1815 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1816
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1817 return retval;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1818 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1819
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1820 /*
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1821 * 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
1822 * there move it left.
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1823 */
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1824 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1825 adjust_cursor_eol(void)
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1826 {
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1827 if (curwin->w_cursor.col > 0
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1828 && gchar_cursor() == NUL
773
8c9ef63b1ccc updated for version 7.0226
vimboss
parents: 714
diff changeset
1829 && (ve_flags & VE_ONEMORE) == 0
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1830 && !(restart_edit || (State & INSERT)))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1831 {
557
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1832 /* Put the cursor on the last character in the line. */
555
a5efb97bc104 updated for version 7.0157
vimboss
parents: 530
diff changeset
1833 dec_cursor();
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
1834
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1835 if (ve_flags == VE_ALL)
557
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1836 {
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1837 colnr_T scol, ecol;
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1838
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1839 /* Coladd is set to the width of the last character. */
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1840 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol);
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1841 curwin->w_cursor.coladd = ecol - scol + 1;
862863033fdd updated for version 7.0158
vimboss
parents: 555
diff changeset
1842 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1843 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1844 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1845
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1846 /*
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1847 * 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
1848 * 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
1849 * 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
1850 * "is_comment".
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1851 * line - line to be processed,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1852 * 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
1853 * comment,
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1854 * 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
1855 * 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
1856 * comment.
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1857 */
11131
8d9ecf09183a patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents: 11129
diff changeset
1858 char_u *
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1859 skip_comment(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1860 char_u *line,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1861 int process,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1862 int include_space,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1863 int *is_comment)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1864 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1865 char_u *comment_flags = NULL;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1866 int lead_len;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1867 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
1868
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1869 *is_comment = FALSE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1870 if (leader_offset != -1)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1871 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1872 /* Let's check whether the line ends with an unclosed comment.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1873 * If the last comment leader has COM_END in flags, there's no comment.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1874 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1875 while (*comment_flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1876 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1877 if (*comment_flags == COM_END
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1878 || *comment_flags == ':')
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1879 break;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1880 ++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 if (*comment_flags != COM_END)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1883 *is_comment = TRUE;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1884 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1885
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1886 if (process == FALSE)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1887 return line;
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 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
1890
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1891 if (lead_len == 0)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1892 return line;
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 /* Find:
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1895 * - COM_END,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1896 * - colon,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1897 * whichever comes first.
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1898 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1899 while (*comment_flags)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1900 {
3580
297771eff080 updated for version 7.3.550
Bram Moolenaar <bram@vim.org>
parents: 3576
diff changeset
1901 if (*comment_flags == COM_END
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1902 || *comment_flags == ':')
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1903 break;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1904 ++comment_flags;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1905 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1906
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1907 /* If we found a colon, it means that we are not processing a line
3580
297771eff080 updated for version 7.3.550
Bram Moolenaar <bram@vim.org>
parents: 3576
diff changeset
1908 * starting with a closing part of a three-part comment. That's good,
297771eff080 updated for version 7.3.550
Bram Moolenaar <bram@vim.org>
parents: 3576
diff changeset
1909 * 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
1910 */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1911 if (*comment_flags == ':' || *comment_flags == NUL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1912 line += lead_len;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1913
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1914 return line;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1915 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1916
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1917 /*
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1918 * 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
1919 * 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
1920 * 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
1921 * leaders should not be removed.
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
1922 * 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
1923 * to set those marks.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1924 *
1217
82274b284600 updated for version 7.1b
vimboss
parents: 1157
diff changeset
1925 * return FAIL for failure, OK otherwise
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1926 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1927 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1928 do_join(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1929 long count,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1930 int insert_space,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1931 int save_undo,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1932 int use_formatoptions UNUSED,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
1933 int setmark)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1934 {
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1935 char_u *curr = NULL;
2597
c3b5d3fe9404 updated for version 7.3.020
Bram Moolenaar <bram@vim.org>
parents: 2451
diff changeset
1936 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
1937 char_u *cend;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1938 char_u *newp;
2597
c3b5d3fe9404 updated for version 7.3.020
Bram Moolenaar <bram@vim.org>
parents: 2451
diff changeset
1939 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
1940 int endcurr1 = NUL;
3e4574a4b627 Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents: 2298
diff changeset
1941 int endcurr2 = NUL;
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1942 int currsize = 0; /* size of the current line */
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1943 int sumsize = 0; /* size of the long new line */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1944 linenr_T t;
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1945 colnr_T col = 0;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1946 int ret = OK;
3574
4f4db5d661c4 updated for version 7.3.547
Bram Moolenaar <bram@vim.org>
parents: 3562
diff changeset
1947 int *comments = NULL;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1948 int remove_comments = (use_formatoptions == TRUE)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1949 && has_format_option(FO_REMOVE_COMS);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1950 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
1951 #ifdef FEAT_PROP_POPUP
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1952 textprop_T **prop_lines = NULL;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1953 int *prop_lengths = NULL;
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1954 #endif
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1955
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1956 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
1957 (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
1958 return FAIL;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1959
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1960 /* Allocate an array to store the number of spaces inserted before each
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1961 * line. We will use it to pre-compute the length of the new line and the
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1962 * 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
1963 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
1964 if (spaces == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1965 return FAIL;
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1966 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1967 {
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
1968 comments = lalloc_clear(count * sizeof(int), TRUE);
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1969 if (comments == NULL)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1970 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1971 vim_free(spaces);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1972 return FAIL;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1973 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1974 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1975
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1976 /*
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
1977 * 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
1978 * 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
1979 * This loops forward over the joined lines.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1980 */
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
1981 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
1982 {
2597
c3b5d3fe9404 updated for version 7.3.020
Bram Moolenaar <bram@vim.org>
parents: 2451
diff changeset
1983 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t));
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
1984 if (t == 0 && setmark && !cmdmod.lockmarks)
5664
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
1985 {
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
1986 /* Set the '[ mark. */
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
1987 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
1988 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
1989 }
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1990 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1991 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1992 /* We don't want to remove the comment leader if the
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1993 * previous line is not a comment. */
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1994 if (t > 0 && prev_was_comment)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1995 {
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1996
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
1997 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
1998 &prev_was_comment);
3576
8625e38066db updated for version 7.3.548
Bram Moolenaar <bram@vim.org>
parents: 3574
diff changeset
1999 comments[t] = (int)(new_curr - curr);
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2000 curr = new_curr;
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2001 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2002 else
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2003 curr = skip_comment(curr, FALSE, insert_space,
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2004 &prev_was_comment);
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2005 }
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2006
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2007 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
2008 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2009 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
2010 if (*curr != NUL && *curr != ')'
9cbdd58eeeb2 patch 8.1.2293: join adds trailing space when second line is empty
Bram Moolenaar <Bram@vim.org>
parents: 18574
diff changeset
2011 && currsize != 0 && endcurr1 != TAB
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2012 && (!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
2013 || (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
2014 && (!has_format_option(FO_MBYTE_JOIN2)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2015 || 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
2016 )
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2017 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2018 /* don't add a space if the line is ending in a space */
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2019 if (endcurr1 == ' ')
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2020 endcurr1 = endcurr2;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2021 else
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2022 ++spaces[t];
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2023 /* extra space when 'joinspaces' set and line ends in '.' */
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2024 if ( p_js
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2025 && (endcurr1 == '.'
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2026 || (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
2027 && (endcurr1 == '?' || endcurr1 == '!'))))
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2028 ++spaces[t];
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2029 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2030 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2031 currsize = (int)STRLEN(curr);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2032 sumsize += currsize + spaces[t];
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2033 endcurr1 = endcurr2 = NUL;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2034 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
2035 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2036 if (has_mbyte)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2037 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2038 cend = curr + currsize;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2039 MB_PTR_BACK(curr, cend);
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2040 endcurr1 = (*mb_ptr2char)(cend);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2041 if (cend > curr)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2042 {
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2043 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
2044 endcurr2 = (*mb_ptr2char)(cend);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2045 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2046 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2047 else
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2048 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2049 endcurr1 = *(curr + currsize - 1);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2050 if (currsize > 1)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2051 endcurr2 = *(curr + currsize - 2);
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 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2054 line_breakcheck();
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2055 if (got_int)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2056 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2057 ret = FAIL;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2058 goto theend;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2059 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2060 }
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2061
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2062 /* store the column position before last line */
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2063 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
2064
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2065 /* allocate the space for the new line */
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
2066 newp = alloc(sumsize + 1);
17797
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2067 if (newp == NULL)
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2068 {
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2069 ret = FAIL;
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2070 goto theend;
ec1717981acf patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17789
diff changeset
2071 }
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2072 cend = newp + sumsize;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2073 *cend = 0;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2074
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
2075 #ifdef FEAT_PROP_POPUP
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2076 // We need to move properties of the lines that are going to be deleted to
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2077 // the new long one.
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2078 if (curbuf->b_has_textprop && !text_prop_frozen)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2079 {
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2080 // Allocate an array to copy the text properties of joined lines into.
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2081 // And another array to store the number of properties in each line.
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
2082 prop_lines = ALLOC_CLEAR_MULT(textprop_T *, count - 1);
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16782
diff changeset
2083 prop_lengths = ALLOC_CLEAR_MULT(int, count - 1);
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2084 if (prop_lengths == NULL)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2085 VIM_CLEAR(prop_lines);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2086 }
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2087 #endif
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2088
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2089 /*
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2090 * 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
2091 * 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
2092 *
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2093 * 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
2094 * 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
2095 * 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
2096 */
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2097 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
2098 {
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2099 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
2100
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2101 cend -= currsize;
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2102 mch_memmove(cend, curr, (size_t)currsize);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2103 if (spaces[t] > 0)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2104 {
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2105 cend -= spaces[t];
6929
e55929fca0cf patch 7.4.783
Bram Moolenaar <bram@vim.org>
parents: 6927
diff changeset
2106 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
2107 }
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2108
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2109 // 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
2110 // 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
2111 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
2112
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2113 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t,
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2114 (long)(cend - newp - spaces_removed), spaces_removed);
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2115 if (t == 0)
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2116 break;
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
2117 #ifdef FEAT_PROP_POPUP
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2118 if (prop_lines != NULL)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2119 adjust_props_for_join(curwin->w_cursor.lnum + t,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2120 prop_lines + t - 1, prop_lengths + t - 1,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2121 (long)(cend - newp - spaces_removed), spaces_removed);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2122 #endif
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2123
2597
c3b5d3fe9404 updated for version 7.3.020
Bram Moolenaar <bram@vim.org>
parents: 2451
diff changeset
2124 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
2125 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2126 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
2127 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
2128 curr = skipwhite(curr);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2129 currsize = (int)STRLEN(curr);
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2130 }
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2131
18763
49b78d6465e5 patch 8.1.2371: FEAT_TEXT_PROP is a confusing name
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
2132 #ifdef FEAT_PROP_POPUP
16678
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2133 if (prop_lines != NULL)
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2134 join_prop_lines(curwin->w_cursor.lnum, newp,
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2135 prop_lines, prop_lengths, count);
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2136 else
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2137 #endif
6f453673eb19 patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents: 16429
diff changeset
2138 ml_replace(curwin->w_cursor.lnum, newp, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2139
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2140 if (setmark && !cmdmod.lockmarks)
5848
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
2141 {
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
2142 /* Set the '] mark. */
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
2143 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
2144 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
2145 }
5664
647e6bb15aa3 updated for version 7.4.178
Bram Moolenaar <bram@vim.org>
parents: 5596
diff changeset
2146
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2147 /* Only report the change in the first line here, del_lines() will report
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2148 * the deleted line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2149 changed_lines(curwin->w_cursor.lnum, currsize,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2150 curwin->w_cursor.lnum + 1, 0L);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2151 /*
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2152 * Delete following lines. To do this we move the cursor there
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2153 * briefly, and then move it back. After del_lines() the cursor may
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2154 * have moved up (last line deleted), so the current lnum is kept in t.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2155 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2156 t = curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2157 ++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
2158 del_lines(count - 1, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2159 curwin->w_cursor.lnum = t;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2161 /*
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2162 * Set the cursor column:
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2163 * 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
2164 * vim: use the column of the last join
7
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 curwin->w_cursor.col =
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2167 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2168 check_cursor_col();
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2169
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2170 curwin->w_cursor.coladd = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2171 curwin->w_set_curswant = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2172
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2173 theend:
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2174 vim_free(spaces);
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2175 if (remove_comments)
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2176 vim_free(comments);
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2177 return ret;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2178 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2179
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2180 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2181 * Return TRUE if the two comment leaders given are the same. "lnum" is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2182 * the first line. White-space is ignored. Note that the whole of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2183 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2184 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2185 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2186 same_leader(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2187 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2188 int leader1_len,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2189 char_u *leader1_flags,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2190 int leader2_len,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2191 char_u *leader2_flags)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2192 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2193 int idx1 = 0, idx2 = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2194 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2195 char_u *line1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2196 char_u *line2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2198 if (leader1_len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2199 return (leader2_len == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2200
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2201 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2202 * If first leader has 'f' flag, the lines can be joined only if the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2203 * second line does not have a leader.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2204 * If first leader has 'e' flag, the lines can never be joined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2205 * If fist leader has 's' flag, the lines can only be joined if there is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2206 * some text after it and the second line has the 'm' flag.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2207 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2208 if (leader1_flags != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2209 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2210 for (p = leader1_flags; *p && *p != ':'; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2211 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2212 if (*p == COM_FIRST)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2213 return (leader2_len == 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2214 if (*p == COM_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2215 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2216 if (*p == COM_START)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2217 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2218 if (*(ml_get(lnum) + leader1_len) == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2219 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2220 if (leader2_flags == NULL || leader2_len == 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2221 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2222 for (p = leader2_flags; *p && *p != ':'; ++p)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2223 if (*p == COM_MIDDLE)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2224 return TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2225 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2226 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2227 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2228 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2230 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2231 * Get current line and next line, compare the leaders.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2232 * The first line has to be saved, only one line can be locked at a time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2233 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2234 line1 = vim_strsave(ml_get(lnum));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2235 if (line1 != NULL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2236 {
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2237 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2238 ;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2239 line2 = ml_get(lnum + 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2240 for (idx2 = 0; idx2 < leader2_len; ++idx2)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2241 {
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2242 if (!VIM_ISWHITE(line2[idx2]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2243 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2244 if (line1[idx1++] != line2[idx2])
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2245 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2246 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2247 else
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2248 while (VIM_ISWHITE(line1[idx1]))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2249 ++idx1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2250 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2251 vim_free(line1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2252 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2253 return (idx2 == leader2_len && idx1 == leader1_len);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2254 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2256 /*
3252
80c529a5650f updated for version 7.3.395
Bram Moolenaar <bram@vim.org>
parents: 3093
diff changeset
2257 * Implementation of the format operator 'gq'.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2258 */
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
2259 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2260 op_format(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2261 oparg_T *oap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2262 int keep_cursor) /* keep cursor on same text char */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2263 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2264 long old_line_count = curbuf->b_ml.ml_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2265
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2266 /* Place the cursor where the "gq" or "gw" command was given, so that "u"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2267 * can put it back there. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2268 curwin->w_cursor = oap->cursor_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2270 if (u_save((linenr_T)(oap->start.lnum - 1),
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2271 (linenr_T)(oap->end.lnum + 1)) == FAIL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2272 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2273 curwin->w_cursor = oap->start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2274
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2275 if (oap->is_VIsual)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2276 /* When there is no change: need to remove the Visual selection */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2277 redraw_curbuf_later(INVERTED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2278
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2279 if (!cmdmod.lockmarks)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2280 /* Set '[ mark at the start of the formatted area */
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2281 curbuf->b_op_start = oap->start;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2282
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2283 /* For "gw" remember the cursor position and put it back below (adjusted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2284 * for joined and split lines). */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2285 if (keep_cursor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2286 saved_cursor = oap->cursor_start;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2287
1563
ed7fefbef738 updated for version 7.1-276
vimboss
parents: 1550
diff changeset
2288 format_lines(oap->line_count, keep_cursor);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2289
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2290 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2291 * Leave the cursor at the first non-blank of the last formatted line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2292 * If the cursor was moved one line back (e.g. with "Q}") go to the next
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2293 * line, so "." will do the next lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2294 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2295 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2296 ++curwin->w_cursor.lnum;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2297 beginline(BL_WHITE | BL_FIX);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2298 old_line_count = curbuf->b_ml.ml_line_count - old_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2299 msgmore(old_line_count);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2300
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2301 if (!cmdmod.lockmarks)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2302 /* put '] mark on the end of the formatted area */
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2303 curbuf->b_op_end = curwin->w_cursor;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2304
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2305 if (keep_cursor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2306 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2307 curwin->w_cursor = saved_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2308 saved_cursor.lnum = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2309 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2310
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2311 if (oap->is_VIsual)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2312 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2313 win_T *wp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2314
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2315 FOR_ALL_WINDOWS(wp)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2316 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2317 if (wp->w_old_cursor_lnum != 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2318 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2319 /* When lines have been inserted or deleted, adjust the end of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2320 * the Visual area to be redrawn. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2321 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2322 wp->w_old_cursor_lnum += old_line_count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2323 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2324 wp->w_old_visual_lnum += old_line_count;
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 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2328 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2329
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2330 #if defined(FEAT_EVAL) || defined(PROTO)
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2331 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2332 * Implementation of the format operator 'gq' for when using 'formatexpr'.
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2333 */
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
2334 static void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2335 op_formatexpr(oparg_T *oap)
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2336 {
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2337 if (oap->is_VIsual)
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2338 /* When there is no change: need to remove the Visual selection */
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2339 redraw_curbuf_later(INVERTED);
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2340
2298
a3562a127cf6 When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents: 2294
diff changeset
2341 if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0)
a3562a127cf6 When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents: 2294
diff changeset
2342 /* As documented: when 'formatexpr' returns non-zero fall back to
a3562a127cf6 When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents: 2294
diff changeset
2343 * internal formatting. */
a3562a127cf6 When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents: 2294
diff changeset
2344 op_format(oap, FALSE);
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2345 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2346
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2347 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2348 fex_format(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2349 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2350 long count,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2351 int c) /* character to be inserted */
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2352 {
681
9364d114ed8d updated for version 7.0204
vimboss
parents: 667
diff changeset
2353 int use_sandbox = was_set_insecurely((char_u *)"formatexpr",
9364d114ed8d updated for version 7.0204
vimboss
parents: 667
diff changeset
2354 OPT_LOCAL);
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2355 int r;
10104
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2356 char_u *fex;
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2357
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2358 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2359 * Set v:lnum to the first line number and v:count to the number of lines.
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
2360 * Set v:char to the character to be inserted (can be NUL).
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2361 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2362 set_vim_var_nr(VV_LNUM, lnum);
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2363 set_vim_var_nr(VV_COUNT, count);
1969
2e915ea7110f updated for version 7.2-266
vimboss
parents: 1924
diff changeset
2364 set_vim_var_char(c);
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
2365
10104
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2366 /* Make a copy, the option could be changed while calling it. */
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2367 fex = vim_strsave(curbuf->b_p_fex);
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2368 if (fex == NULL)
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2369 return 0;
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2370
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2371 /*
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2372 * Evaluate the function.
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2373 */
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2374 if (use_sandbox)
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2375 ++sandbox;
10104
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2376 r = (int)eval_to_number(fex);
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2377 if (use_sandbox)
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2378 --sandbox;
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
2379
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
2380 set_vim_var_string(VV_CHAR, NULL, -1);
10104
b2dbe79639a2 commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
2381 vim_free(fex);
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 840
diff changeset
2382
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2383 return r;
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2384 }
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2385 #endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 613
diff changeset
2386
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2387 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2388 * Format "line_count" lines, starting at the cursor position.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2389 * When "line_count" is negative, format until the end of the paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2390 * Lines after the cursor line are saved for undo, caller must have saved the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2391 * first line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2392 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2393 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2394 format_lines(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2395 linenr_T line_count,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2396 int avoid_fex) /* don't use 'formatexpr' */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2397 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2398 int max_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2399 int is_not_par; /* current line not part of parag. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2400 int next_is_not_par; /* next line not part of paragraph */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2401 int is_end_par; /* at end of paragraph */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2402 int prev_is_end_par = FALSE;/* prev. line not part of parag. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2403 int next_is_start_par = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2404 int leader_len = 0; /* leader len of current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2405 int next_leader_len; /* leader len of next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2406 char_u *leader_flags = NULL; /* flags for leader of current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2407 char_u *next_leader_flags; /* flags for leader of next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2408 int do_comments; /* format comments */
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2409 int do_comments_list = 0; /* format comments with 'n' or '2' */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2410 int advance = TRUE;
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2411 int second_indent = -1; /* indent for second line (comment
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2412 * aware) */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2413 int do_second_indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2414 int do_number_indent;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2415 int do_trail_white;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2416 int first_par_line = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2417 int smd_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2418 long count;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2419 int need_set_indent = TRUE; /* set indent of next paragraph */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2420 int force_format = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2421 int old_State = State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2422
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2423 /* length of a line to force formatting: 3 * 'tw' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2424 max_len = comp_textwidth(TRUE) * 3;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2425
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2426 /* check for 'q', '2' and '1' in 'formatoptions' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2427 do_comments = has_format_option(FO_Q_COMS);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2428 do_second_indent = has_format_option(FO_Q_SECOND);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2429 do_number_indent = has_format_option(FO_Q_NUMBER);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2430 do_trail_white = has_format_option(FO_WHITE_PAR);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2431
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2432 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2433 * Get info about the previous and current line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2434 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2435 if (curwin->w_cursor.lnum > 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2436 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2437 , &leader_len, &leader_flags, do_comments);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2438 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2439 is_not_par = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2440 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2441 , &next_leader_len, &next_leader_flags, do_comments);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2442 is_end_par = (is_not_par || next_is_not_par);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2443 if (!is_end_par && do_trail_white)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2444 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2446 curwin->w_cursor.lnum--;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2447 for (count = line_count; count != 0 && !got_int; --count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2448 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2449 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2450 * Advance to next paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2451 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2452 if (advance)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2453 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2454 curwin->w_cursor.lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2455 prev_is_end_par = is_end_par;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2456 is_not_par = next_is_not_par;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2457 leader_len = next_leader_len;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2458 leader_flags = next_leader_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2459 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2461 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2462 * The last line to be formatted.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2463 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2464 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2465 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2466 next_is_not_par = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2467 next_leader_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2468 next_leader_flags = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2469 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2470 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2471 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2472 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2473 , &next_leader_len, &next_leader_flags, do_comments);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2474 if (do_number_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2475 next_is_start_par =
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2476 (get_number_indent(curwin->w_cursor.lnum + 1) > 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2477 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2478 advance = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2479 is_end_par = (is_not_par || next_is_not_par || next_is_start_par);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2480 if (!is_end_par && do_trail_white)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2481 is_end_par = !ends_in_white(curwin->w_cursor.lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2483 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2484 * Skip lines that are not in a paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2485 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2486 if (is_not_par)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2487 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2488 if (line_count < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2489 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2490 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2491 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2492 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2493 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2494 * For the first line of a paragraph, check indent of second line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2495 * Don't do this for comments and empty lines.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2496 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2497 if (first_par_line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2498 && (do_second_indent || do_number_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2499 && prev_is_end_par
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2500 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2501 {
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11065
diff changeset
2502 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1))
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2503 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2504 if (leader_len == 0 && next_leader_len == 0)
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2505 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2506 /* no comment found */
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2507 second_indent =
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2508 get_indent_lnum(curwin->w_cursor.lnum + 1);
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2509 }
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2510 else
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2511 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2512 second_indent = next_leader_len;
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2513 do_comments_list = 1;
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2514 }
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2515 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2516 else if (do_number_indent)
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2517 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2518 if (leader_len == 0 && next_leader_len == 0)
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2519 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2520 /* no comment found */
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2521 second_indent =
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2522 get_number_indent(curwin->w_cursor.lnum);
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2523 }
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2524 else
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2525 {
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2526 /* get_number_indent() is now "comment aware"... */
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2527 second_indent =
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2528 get_number_indent(curwin->w_cursor.lnum);
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2529 do_comments_list = 1;
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2530 }
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2531 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2532 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2533
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2534 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2535 * When the comment leader changes, it's the end of the paragraph.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2536 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2537 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2538 || !same_leader(curwin->w_cursor.lnum,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2539 leader_len, leader_flags,
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2540 next_leader_len, next_leader_flags))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2541 is_end_par = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2542
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2543 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2544 * If we have got to the end of a paragraph, or the line is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2545 * getting long, format it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2546 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2547 if (is_end_par || force_format)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2548 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2549 if (need_set_indent)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2550 /* replace indent in first line with minimal number of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2551 * tabs and spaces, according to current options */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2552 (void)set_indent(get_indent(), SIN_CHANGED);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2553
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2554 /* put cursor on last non-space */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2555 State = NORMAL; /* don't go past end-of-line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2556 coladvance((colnr_T)MAXCOL);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2557 while (curwin->w_cursor.col && vim_isspace(gchar_cursor()))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2558 dec_cursor();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2559
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2560 /* do the formatting, without 'showmode' */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2561 State = INSERT; /* for open_line() */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2562 smd_save = p_smd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2563 p_smd = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2564 insertchar(NUL, INSCHAR_FORMAT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2565 + (do_comments ? INSCHAR_DO_COM : 0)
3584
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2566 + (do_comments && do_comments_list
443c50cd3e88 updated for version 7.3.552
Bram Moolenaar <bram@vim.org>
parents: 3580
diff changeset
2567 ? INSCHAR_COM_LIST : 0)
1563
ed7fefbef738 updated for version 7.1-276
vimboss
parents: 1550
diff changeset
2568 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2569 State = old_State;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2570 p_smd = smd_save;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2571 second_indent = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2572 /* at end of par.: need to set indent of next par. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2573 need_set_indent = is_end_par;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2574 if (is_end_par)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2575 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2576 /* When called with a negative line count, break at the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2577 * end of the paragraph. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2578 if (line_count < 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2579 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2580 first_par_line = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2581 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2582 force_format = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2583 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2584
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2585 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2586 * When still in same paragraph, join the lines together. But
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2587 * first delete the leader from the second line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2588 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2589 if (!is_end_par)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2590 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2591 advance = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2592 curwin->w_cursor.lnum++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2593 curwin->w_cursor.col = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2594 if (line_count < 0 && u_save_cursor() == FAIL)
2294
2209060c340d Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents: 2289
diff changeset
2595 break;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2596 if (next_leader_len > 0)
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2597 {
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2598 (void)del_bytes((long)next_leader_len, FALSE, FALSE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2599 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L,
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2600 (long)-next_leader_len, 0);
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2601 }
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2602 else if (second_indent > 0) // the "leader" for FO_Q_SECOND
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2603 {
12323
4dba3e4f3b01 patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents: 11997
diff changeset
2604 int indent = getwhitecols_curline();
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2605
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2606 if (indent > 0)
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2607 {
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2608 (void)del_bytes(indent, FALSE, FALSE);
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2609 mark_col_adjust(curwin->w_cursor.lnum,
15326
fe428bee74b3 patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents: 15062
diff changeset
2610 (colnr_T)0, 0L, (long)-indent, 0);
5415
fa8447ec5823 updated for version 7.4.058
Bram Moolenaar <bram@vim.org>
parents: 5403
diff changeset
2611 }
5403
b9c1c1f4cda9 updated for version 7.4.052
Bram Moolenaar <bram@vim.org>
parents: 5380
diff changeset
2612 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2613 curwin->w_cursor.lnum--;
5848
75f222d67cea updated for version 7.4.267
Bram Moolenaar <bram@vim.org>
parents: 5828
diff changeset
2614 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2615 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2616 beep_flush();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2617 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2618 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2619 first_par_line = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2620 /* If the line is getting long, format it next time */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2621 if (STRLEN(ml_get_curline()) > (size_t)max_len)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2622 force_format = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2623 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2624 force_format = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2625 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2626 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2627 line_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2628 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2629 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2630
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2631 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2632 * Return TRUE if line "lnum" ends in a white character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2633 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2634 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2635 ends_in_white(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2636 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2637 char_u *s = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2638 size_t l;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2639
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2640 if (*s == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2641 return FALSE;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2642 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2643 * invocation may call function multiple times". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2644 l = STRLEN(s) - 1;
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11127
diff changeset
2645 return VIM_ISWHITE(s[l]);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2646 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2647
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2648 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2649 * Blank lines, and lines containing only the comment leader, are left
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2650 * untouched by the formatting. The function returns TRUE in this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2651 * case. It also returns TRUE when a line starts with the end of a comment
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2652 * ('e' in comment flags), so that this line is skipped, and not joined to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2653 * previous line. A new paragraph starts after a blank line, or when the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2654 * comment leader changes -- webb.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2655 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2656 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2657 fmt_check_par(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2658 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2659 int *leader_len,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2660 char_u **leader_flags,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2661 int do_comments)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2662 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2663 char_u *flags = NULL; /* init for GCC */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2664 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2665
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2666 ptr = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2667 if (do_comments)
3562
5c1aaf9b4b1b updated for version 7.3.541
Bram Moolenaar <bram@vim.org>
parents: 3510
diff changeset
2668 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2669 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2670 *leader_len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2671
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2672 if (*leader_len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2673 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2674 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2675 * Search for 'e' flag in comment leader flags.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2676 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2677 flags = *leader_flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2678 while (*flags && *flags != ':' && *flags != COM_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2679 ++flags;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2680 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2681
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2682 return (*skipwhite(ptr + *leader_len) == NUL
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2683 || (*leader_len > 0 && *flags == COM_END)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2684 || startPS(lnum, NUL, FALSE));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2685 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2686
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2687 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2688 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2689 * previous line is in the same paragraph. Used for auto-formatting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2690 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2691 int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2692 paragraph_start(linenr_T lnum)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2693 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2694 char_u *p;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2695 int leader_len = 0; /* leader len of current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2696 char_u *leader_flags = NULL; /* flags for leader of current line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2697 int next_leader_len; /* leader len of next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2698 char_u *next_leader_flags; /* flags for leader of next line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2699 int do_comments; /* format comments */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2700
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2701 if (lnum <= 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2702 return TRUE; /* start of the file */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2703
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2704 p = ml_get(lnum - 1);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2705 if (*p == NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2706 return TRUE; /* after empty line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2707
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2708 do_comments = has_format_option(FO_Q_COMS);
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2709 if (fmt_check_par(lnum - 1, &leader_len, &leader_flags, do_comments))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2710 return TRUE; /* after non-paragraph line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2711
18203
e0ec4cd7a865 patch 8.1.2096: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 18164
diff changeset
2712 if (fmt_check_par(lnum, &next_leader_len, &next_leader_flags, do_comments))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2713 return TRUE; /* "lnum" is not a paragraph line */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2714
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2715 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2716 return TRUE; /* missing trailing space in previous line. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2717
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2718 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2719 return TRUE; /* numbered item starts in "lnum". */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2720
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2721 if (!same_leader(lnum - 1, leader_len, leader_flags,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2722 next_leader_len, next_leader_flags))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2723 return TRUE; /* change of comment leader. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2724
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2725 return FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2726 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2727
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2728 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2729 * prepare a few things for block mode yank/delete/tilde
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2730 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2731 * for delete:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2732 * - textlen includes the first/last char to be (partly) deleted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2733 * - start/endspaces is the number of columns that are taken by the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2734 * 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
2735 * deleted.
df7ceb64b0c6 updated for version 7.2-137
vimboss
parents: 1766
diff changeset
2736 * for yank and tilde:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2737 * - textlen includes the first/last char to be wholly yanked
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2738 * - start/endspaces is the number of columns of the first/last yanked char
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2739 * that are to be yanked.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2740 */
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18100
diff changeset
2741 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2742 block_prep(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2743 oparg_T *oap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2744 struct block_def *bdp,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2745 linenr_T lnum,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2746 int is_del)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2747 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2748 int incr = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2749 char_u *pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2750 char_u *pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2751 char_u *line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2752 char_u *prev_pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2753 char_u *prev_pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2754
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2755 bdp->startspaces = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2756 bdp->endspaces = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2757 bdp->textlen = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2758 bdp->start_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2759 bdp->end_vcol = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2760 bdp->is_short = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2761 bdp->is_oneChar = FALSE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2762 bdp->pre_whitesp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2763 bdp->pre_whitesp_c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2764 bdp->end_char_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2765 bdp->start_char_vcols = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2766
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2767 line = ml_get(lnum);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2768 pstart = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2769 prev_pstart = line;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2770 while (bdp->start_vcol < oap->start_vcol && *pstart)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2771 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2772 /* Count a tab for what it's worth (if list mode not on) */
5995
ef83b423ebf7 updated for version 7.4.338
Bram Moolenaar <bram@vim.org>
parents: 5981
diff changeset
2773 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2774 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
2775 if (VIM_ISWHITE(*pstart))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2776 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2777 bdp->pre_whitesp += incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2778 bdp->pre_whitesp_c++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2779 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2780 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2781 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2782 bdp->pre_whitesp = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2783 bdp->pre_whitesp_c = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2784 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2785 prev_pstart = pstart;
11127
506f5d8b7d8b patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11121
diff changeset
2786 MB_PTR_ADV(pstart);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2787 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2788 bdp->start_char_vcols = incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2789 if (bdp->start_vcol < oap->start_vcol) /* line too short */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2790 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2791 bdp->end_vcol = bdp->start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2792 bdp->is_short = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2793 if (!is_del || oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2794 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2795 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2796 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2797 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2798 /* notice: this converts partly selected Multibyte characters to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2799 * spaces, too. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2800 bdp->startspaces = bdp->start_vcol - oap->start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2801 if (is_del && bdp->startspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2802 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2803 pend = pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2804 bdp->end_vcol = bdp->start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2805 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2806 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2807 bdp->is_oneChar = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2808 if (oap->op_type == OP_INSERT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2809 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2810 else if (oap->op_type == OP_APPEND)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2811 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2812 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2813 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2814 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2815 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2816 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2817 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2818 if (is_del && oap->op_type != OP_LSHIFT)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2819 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2820 /* just putting the sum of those two into
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2821 * bdp->startspaces doesn't work for Visual replace,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2822 * so we have to split the tab in two */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2823 bdp->startspaces = bdp->start_char_vcols
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2824 - (bdp->start_vcol - oap->start_vcol);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2825 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2826 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2827 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2828 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2829 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2830 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2831 prev_pend = pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2832 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2833 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2834 /* Count a tab for what it's worth (if list mode not on) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2835 prev_pend = pend;
6535
f9d02ce2f745 updated for version 7.4.594
Bram Moolenaar <bram@vim.org>
parents: 6508
diff changeset
2836 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2837 bdp->end_vcol += incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2838 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2839 if (bdp->end_vcol <= oap->end_vcol
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2840 && (!is_del
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2841 || oap->op_type == OP_APPEND
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2842 || oap->op_type == OP_REPLACE)) /* line too short */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2843 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2844 bdp->is_short = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2845 /* Alternative: include spaces to fill up the block.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2846 * Disadvantage: can lead to trailing spaces when the line is
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2847 * short where the text is put */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2848 /* if (!is_del || oap->op_type == OP_APPEND) */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2849 if (oap->op_type == OP_APPEND || virtual_op)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2850 bdp->endspaces = oap->end_vcol - bdp->end_vcol
593
d220eb88e4e4 updated for version 7.0168
vimboss
parents: 557
diff changeset
2851 + oap->inclusive;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2852 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2853 bdp->endspaces = 0; /* replace doesn't add characters */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2854 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2855 else if (bdp->end_vcol > oap->end_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2856 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2857 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2858 if (!is_del && bdp->endspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2859 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2860 bdp->endspaces = incr - bdp->endspaces;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2861 if (pend != pstart)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2862 pend = prev_pend;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2863 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2864 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2865 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2866 bdp->end_char_vcols = incr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2867 if (is_del && bdp->startspaces)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2868 pstart = prev_pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2869 bdp->textlen = (int)(pend - pstart);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2870 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2871 bdp->textcol = (colnr_T) (pstart - line);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2872 bdp->textstart = pstart;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2873 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2874
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2875 /*
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2876 * Handle the add/subtract operator.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2877 */
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2878 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2879 op_addsub(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2880 oparg_T *oap,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2881 linenr_T Prenum1, /* Amount of add/subtract */
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
2882 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
2883 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2884 pos_T pos;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2885 struct block_def bd;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2886 int change_cnt = 0;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2887 linenr_T amount = Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2888
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2889 // 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
2890 // 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
2891 // 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
2892 #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
2893 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
2894 #endif
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2895
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2896 if (!VIsual_active)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2897 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2898 pos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2899 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
2900 {
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2901 #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
2902 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
2903 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2904 return;
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2905 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2906 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
2907 #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
2908 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
2909 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2910 if (change_cnt)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2911 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
2912 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2913 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2914 {
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2915 int one_change;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2916 int length;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2917 pos_T startpos;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2918
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2919 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
2920 (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
2921 {
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2922 #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
2923 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
2924 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2925 return;
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2926 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2927
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2928 pos = oap->start;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2929 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
2930 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2931 if (oap->block_mode) /* Visual block mode */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2932 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2933 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
2934 pos.col = bd.textcol;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2935 length = bd.textlen;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2936 }
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2937 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
2938 {
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2939 curwin->w_cursor.col = 0;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2940 pos.col = 0;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2941 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
2942 }
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2943 else /* oap->motion_type == MCHAR */
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2944 {
12996
973a0037f4c3 patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents: 12642
diff changeset
2945 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
2946 dec(&(oap->end));
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2947 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
2948 pos.col = 0;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2949 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
2950 {
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2951 pos.col += oap->start.col;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2952 length -= oap->start.col;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2953 }
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2954 if (pos.lnum == oap->end.lnum)
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2955 {
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2956 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
2957 if (oap->end.col >= length)
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2958 oap->end.col = length - 1;
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
2959 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
2960 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2961 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2962 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
2963 if (one_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2964 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2965 /* Remember the start position of the first change. */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2966 if (change_cnt == 0)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2967 startpos = curbuf->b_op_start;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2968 ++change_cnt;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2969 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2970
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2971 #ifdef FEAT_NETBEANS_INTG
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2972 if (netbeans_active() && one_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2973 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2974 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2975
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2976 netbeans_removed(curbuf, pos.lnum, pos.col, (long)length);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2977 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
2978 &ptr[pos.col], length);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2979 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2980 #endif
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2981 if (g_cmd && one_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2982 amount += Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2983 }
15048
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2984
73f59cd01ba7 patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents: 14862
diff changeset
2985 #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
2986 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
2987 #endif
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2988 if (change_cnt)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2989 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
2990
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2991 if (!change_cnt && oap->is_VIsual)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2992 /* No change: need to remove the Visual selection */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2993 redraw_curbuf_later(INVERTED);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2994
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2995 /* Set '[ mark if something changed. Keep the last end
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2996 * position from do_addsub(). */
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
2997 if (change_cnt > 0 && !cmdmod.lockmarks)
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2998 curbuf->b_op_start = startpos;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
2999
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3000 if (change_cnt > p_report)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15428
diff changeset
3001 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
3002 change_cnt), change_cnt);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3003 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3004 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3005
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3006 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3007 * 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
3008 * 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
3009 *
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3010 * 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
3011 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3012 static int
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3013 do_addsub(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3014 int op_type,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3015 pos_T *pos,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3016 int length,
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3017 linenr_T Prenum1)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3018 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3019 int col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3020 char_u *buf1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3021 char_u buf2[NUMBUFLEN];
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3022 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3023 static int hexupper = FALSE; /* 0xABC */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3024 uvarnumber_T n;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3025 uvarnumber_T oldn;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3026 char_u *ptr;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3027 int c;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3028 int todel;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3029 int dohex;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3030 int dooct;
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3031 int dobin;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3032 int doalp;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3033 int firstdigit;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3034 int subtract;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3035 int negative = FALSE;
6891
f9876721bedc patch 7.4.765
Bram Moolenaar <bram@vim.org>
parents: 6868
diff changeset
3036 int was_positive = TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3037 int visual = VIsual_active;
6921
1f78058351a6 patch 7.4.779
Bram Moolenaar <bram@vim.org>
parents: 6919
diff changeset
3038 int did_change = FALSE;
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
3039 pos_T save_cursor = curwin->w_cursor;
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
3040 int maxlen = 0;
7570
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3041 pos_T startpos;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3042 pos_T endpos;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3043
18100
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
3044 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX"
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
3045 dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal"
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
3046 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin"
df5778d73320 patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18062
diff changeset
3047 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3048
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3049 curwin->w_cursor = *pos;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3050 ptr = ml_get(pos->lnum);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3051 col = pos->col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3052
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3053 if (*ptr == NUL)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3054 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3055
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3056 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3057 * First check if we are on a hexadecimal number, after the "0x".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3058 */
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3059 if (!VIsual_active)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3060 {
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3061 if (dobin)
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3062 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
3063 {
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3064 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3065 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3066 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
3067 }
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3068
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3069 if (dohex)
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3070 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
3071 {
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3072 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3073 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3074 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
3075 }
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3076
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3077 if ( dobin
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3078 && dohex
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3079 && ! ((col > 0
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3080 && (ptr[col] == 'X'
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3081 || ptr[col] == 'x')
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3082 && ptr[col - 1] == '0'
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3083 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3084 !(*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
3085 && vim_isxdigit(ptr[col + 1]))))
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3086 {
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3087
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3088 /* In case of binary/hexadecimal pattern overlap match, rescan */
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3089
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3090 col = pos->col;
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3091
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3092 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
3093 {
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3094 col--;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3095 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3096 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
3097 }
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3098 }
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3099
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3100 if (( dohex
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3101 && col > 0
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3102 && (ptr[col] == 'X'
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3103 || ptr[col] == 'x')
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3104 && ptr[col - 1] == '0'
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3105 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3106 !(*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
3107 && vim_isxdigit(ptr[col + 1])) ||
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3108 ( dobin
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3109 && col > 0
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3110 && (ptr[col] == 'B'
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3111 || ptr[col] == 'b')
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3112 && ptr[col - 1] == '0'
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3113 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3114 !(*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
3115 && vim_isbdigit(ptr[col + 1])))
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3116 {
7447
ad432f8f68fb commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents: 7336
diff changeset
3117 /* Found hexadecimal or binary number, move to its start. */
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3118 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3119 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3120 col -= (*mb_head_off)(ptr, ptr + col);
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3121 }
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3122 else
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3123 {
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3124 /*
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3125 * 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
3126 */
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3127 col = pos->col;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3128
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3129 while (ptr[col] != NUL
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3130 && !vim_isdigit(ptr[col])
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3131 && !(doalp && ASCII_ISALPHA(ptr[col])))
18251
c8a53c0daeed patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18219
diff changeset
3132 col += mb_ptr2len(ptr + col);
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3133
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3134 while (col > 0
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3135 && vim_isdigit(ptr[col - 1])
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3136 && !(doalp && ASCII_ISALPHA(ptr[col])))
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3137 {
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3138 --col;
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3139 if (has_mbyte)
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3140 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
3141 }
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3142 }
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3143 }
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3144
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3145 if (visual)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3146 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3147 while (ptr[col] != NUL && length > 0
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3148 && !vim_isdigit(ptr[col])
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3149 && !(doalp && ASCII_ISALPHA(ptr[col])))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3150 {
18251
c8a53c0daeed patch 8.1.2120: some MB_ macros are more complicated than necessary
Bram Moolenaar <Bram@vim.org>
parents: 18219
diff changeset
3151 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
3152
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3153 col += mb_len;
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3154 length -= mb_len;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3155 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3156
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3157 if (length == 0)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3158 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3159
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3160 if (col > pos->col && ptr[col - 1] == '-'
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
3161 && (!has_mbyte || !(*mb_head_off)(ptr, ptr + col - 1)))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3162 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3163 negative = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3164 was_positive = FALSE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3165 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3166 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3167
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3168 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3169 * 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
3170 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3171 firstdigit = ptr[col];
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3172 if (!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit)))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3173 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3174 beep_flush();
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3175 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3176 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3177
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3178 if (doalp && ASCII_ISALPHA(firstdigit))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3179 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3180 /* decrement or increment alphabetic character */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3181 if (op_type == OP_NR_SUB)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3182 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3183 if (CharOrd(firstdigit) < Prenum1)
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
3184 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3185 if (isupper(firstdigit))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3186 firstdigit = 'A';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3187 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3188 firstdigit = 'a';
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
3189 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3190 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3191 #ifdef EBCDIC
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3192 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3193 #else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3194 firstdigit -= Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3195 #endif
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3196 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3197 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3198 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3199 if (26 - CharOrd(firstdigit) - 1 < Prenum1)
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
3200 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3201 if (isupper(firstdigit))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3202 firstdigit = 'Z';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3203 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3204 firstdigit = 'z';
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
3205 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3206 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3207 #ifdef EBCDIC
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3208 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3209 #else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3210 firstdigit += Prenum1;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3211 #endif
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3212 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3213 curwin->w_cursor.col = col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3214 if (!did_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3215 startpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3216 did_change = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3217 (void)del_char(FALSE);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3218 ins_char(firstdigit);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3219 endpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3220 curwin->w_cursor.col = col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3221 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3222 else
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3223 {
9332
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3224 if (col > 0 && ptr[col - 1] == '-'
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3225 && (!has_mbyte ||
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3226 !(*mb_head_off)(ptr, ptr + col - 1))
a9b8f5613601 commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents: 9307
diff changeset
3227 && !visual)
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3228 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3229 /* negative number */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3230 --col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3231 negative = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3232 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3233 /* get the number value (unsigned) */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3234 if (visual && VIsual_mode != 'V')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3235 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
3236 ? (int)STRLEN(ptr) - col
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3237 : length);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3238
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3239 vim_str2nr(ptr + col, &pre, &length,
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3240 0 + (dobin ? STR2NR_BIN : 0)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3241 + (dooct ? STR2NR_OCT : 0)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3242 + (dohex ? STR2NR_HEX : 0),
16706
77bcb5055fec patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents: 16698
diff changeset
3243 NULL, &n, maxlen, FALSE);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3244
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3245 /* ignore leading '-' for hex and octal and bin numbers */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3246 if (pre && negative)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3247 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3248 ++col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3249 --length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3250 negative = FALSE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3251 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3252 /* add or subtract */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3253 subtract = FALSE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3254 if (op_type == OP_NR_SUB)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3255 subtract ^= TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3256 if (negative)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3257 subtract ^= TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3258
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3259 oldn = n;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3260 if (subtract)
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3261 n -= (uvarnumber_T)Prenum1;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3262 else
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3263 n += (uvarnumber_T)Prenum1;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3264 /* handle wraparound for decimal numbers */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3265 if (!pre)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3266 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3267 if (subtract)
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
3268 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3269 if (n > oldn)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3270 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3271 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
3272 negative ^= TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3273 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3274 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3275 else
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3276 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3277 /* add */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3278 if (n < oldn)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3279 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3280 n = (n ^ (uvarnumber_T)-1);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3281 negative ^= TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3282 }
6927
58d9f967ae1a patch 7.4.782
Bram Moolenaar <bram@vim.org>
parents: 6923
diff changeset
3283 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3284 if (n == 0)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3285 negative = FALSE;
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3286 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3287
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3288 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
3289 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3290 /* need to remove the '-' */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3291 col--;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3292 length++;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3293 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3294
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3295 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3296 * Delete the old number.
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3297 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3298 curwin->w_cursor.col = col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3299 if (!did_change)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3300 startpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3301 did_change = TRUE;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3302 todel = length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3303 c = gchar_cursor();
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3304 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3305 * 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
3306 * 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
3307 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3308 if (c == '-')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3309 --length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3310 while (todel-- > 0)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3311 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3312 if (c < 0x100 && isalpha(c))
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3313 {
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3314 if (isupper(c))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3315 hexupper = TRUE;
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3316 else
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3317 hexupper = FALSE;
6891
f9876721bedc patch 7.4.765
Bram Moolenaar <bram@vim.org>
parents: 6868
diff changeset
3318 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3319 /* del_char() will mark line needing displaying */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3320 (void)del_char(FALSE);
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3321 c = gchar_cursor();
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3322 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3323
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3324 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3325 * Prepare the leading characters in buf1[].
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3326 * 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
3327 * Allocate a bit too much.
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3328 */
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16714
diff changeset
3329 buf1 = alloc(length + NUMBUFLEN);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3330 if (buf1 == NULL)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3331 goto theend;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3332 ptr = buf1;
8989
e600e696c0a1 commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents: 8863
diff changeset
3333 if (negative && (!visual || was_positive))
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3334 *ptr++ = '-';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3335 if (pre)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3336 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3337 *ptr++ = '0';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3338 --length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3339 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3340 if (pre == 'b' || pre == 'B' ||
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3341 pre == 'x' || pre == 'X')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3342 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3343 *ptr++ = pre;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3344 --length;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3345 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3346
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3347 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3348 * Put the number characters in buf2[].
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3349 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3350 if (pre == 'b' || pre == 'B')
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3351 {
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3352 int i;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3353 int bit = 0;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3354 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
3355
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3356 /* leading zeros */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3357 for (bit = bits; bit > 0; bit--)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3358 if ((n >> (bit - 1)) & 0x1) break;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3359
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3360 for (i = 0; bit > 0; bit--)
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3361 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
3362
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3363 buf2[i] = '\0';
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3364 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3365 else if (pre == 0)
13610
e76499e85744 patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents: 13425
diff changeset
3366 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu",
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3367 (long_long_u_T)n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3368 else if (pre == '0')
13610
e76499e85744 patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents: 13425
diff changeset
3369 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo",
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3370 (long_long_u_T)n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3371 else if (pre && hexupper)
13610
e76499e85744 patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents: 13425
diff changeset
3372 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX",
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3373 (long_long_u_T)n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3374 else
13610
e76499e85744 patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents: 13425
diff changeset
3375 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx",
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3376 (long_long_u_T)n);
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3377 length -= (int)STRLEN(buf2);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3378
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3379 /*
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3380 * 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
3381 * 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
3382 * Don't do this when
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3383 * 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
3384 */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3385 if (firstdigit == '0' && !(dooct && pre == 0))
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3386 while (length-- > 0)
6868
9798a98a1583 patch 7.4.754
Bram Moolenaar <bram@vim.org>
parents: 6845
diff changeset
3387 *ptr++ = '0';
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3388 *ptr = NUL;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3389 STRCAT(buf1, buf2);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3390 ins_str(buf1); /* insert the new number */
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3391 vim_free(buf1);
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3392 endpos = curwin->w_cursor;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3393 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
3394 --curwin->w_cursor.col;
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3395 }
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3396
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3397 if (did_change && !cmdmod.lockmarks)
7570
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3398 {
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3399 /* set the '[ and '] marks */
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3400 curbuf->b_op_start = startpos;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3401 curbuf->b_op_end = endpos;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3402 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
3403 --curbuf->b_op_end.col;
4250ecde6009 commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents: 7551
diff changeset
3404 }
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3405
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
3406 theend:
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
3407 if (visual)
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
3408 curwin->w_cursor = save_cursor;
8690
6a1becf4f282 commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents: 8399
diff changeset
3409 else if (did_change)
6a1becf4f282 commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents: 8399
diff changeset
3410 curwin->w_set_curswant = TRUE;
7576
e008ca0e2af2 commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents: 7574
diff changeset
3411
7574
b872724c37db commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents: 7570
diff changeset
3412 return did_change;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3413 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3414
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3415 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3416 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3417 * SELECTION / PRIMARY ('*')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3418 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3419 * Text selection stuff that uses the GUI selection register '*'. When using a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3420 * GUI this may be text from another window, otherwise it is the last text we
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3421 * had highlighted with VIsual mode. With mouse support, clicking the middle
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3422 * button performs the paste, otherwise you will need to do <"*p>. "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3423 * If not under X, it is synonymous with the clipboard register '+'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3424 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3425 * X CLIPBOARD ('+')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3426 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3427 * Text selection stuff that uses the GUI clipboard register '+'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3428 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3429 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed",
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3430 * otherwise you will need to do <"+p>. "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3431 * If not under X, it is synonymous with the selection register '*'.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3432 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3434 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3435 * Routine to export any final X selection we had to the environment
11065
f5bd684e47a1 patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents: 10827
diff changeset
3436 * so that the text is still available after Vim has exited. X selections
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3437 * only exist while the owning application exists, so we write to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3438 * permanent (while X runs) store CUT_BUFFER0.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3439 * Dump the CLIPBOARD selection if we own it (it's logically the more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3440 * 'permanent' of the two), otherwise the PRIMARY one.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3441 * For now, use a hard-coded sanity limit of 1Mb of data.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3442 */
9834
80ace3687eec commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents: 9389
diff changeset
3443 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3444 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3445 x11_export_final_selection(void)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3446 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3447 Display *dpy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3448 char_u *str = NULL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3449 long_u len = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3450 int motion_type = -1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3451
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3452 # ifdef FEAT_GUI
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3453 if (gui.in_use)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3454 dpy = X_DISPLAY;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3455 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3456 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3457 # ifdef FEAT_XCLIPBOARD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3458 dpy = xterm_dpy;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3459 # else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3460 return;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3461 # endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3462
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3463 /* Get selection to export */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3464 if (clip_plus.owned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3465 motion_type = clip_convert_selection(&str, &len, &clip_plus);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3466 else if (clip_star.owned)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3467 motion_type = clip_convert_selection(&str, &len, &clip_star);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3469 /* Check it's OK */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3470 if (dpy != NULL && str != NULL && motion_type >= 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3471 && len < 1024*1024 && len > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3472 {
4201
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3473 int ok = TRUE;
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3474
1924
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3475 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3476 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3477 * encoding conversion usually doesn't work, so keep the text as-is.
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3478 */
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3479 if (has_mbyte)
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3480 {
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3481 vimconv_T vc;
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3482
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3483 vc.vc_type = CONV_NONE;
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3484 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK)
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3485 {
2047
85da03763130 updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents: 2007
diff changeset
3486 int intlen = len;
85da03763130 updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents: 2007
diff changeset
3487 char_u *conv_str;
2007
b8ab4ba6b110 updated for version 7.2-304
vimboss
parents: 2000
diff changeset
3488
4201
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3489 vc.vc_fail = TRUE;
2007
b8ab4ba6b110 updated for version 7.2-304
vimboss
parents: 2000
diff changeset
3490 conv_str = string_convert(&vc, str, &intlen);
b8ab4ba6b110 updated for version 7.2-304
vimboss
parents: 2000
diff changeset
3491 len = intlen;
1924
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3492 if (conv_str != NULL)
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3493 {
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3494 vim_free(str);
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3495 str = conv_str;
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3496 }
4201
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3497 else
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3498 {
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3499 ok = FALSE;
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3500 }
1924
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3501 convert_setup(&vc, NULL, NULL);
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3502 }
4201
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3503 else
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3504 {
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3505 ok = FALSE;
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3506 }
1924
75a69023117c updated for version 7.2-221
vimboss
parents: 1893
diff changeset
3507 }
4201
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3508
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3509 /* Do not store the string if conversion failed. Better to use any
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3510 * other selection than garbled text. */
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3511 if (ok)
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3512 {
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3513 XStoreBuffer(dpy, (char *)str, (int)len, 0);
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3514 XFlush(dpy);
3fd805ca2a6a updated for version 7.3.852
Bram Moolenaar <bram@vim.org>
parents: 4005
diff changeset
3515 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3516 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3517
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3518 vim_free(str);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3519 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3520 #endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3521 #endif /* FEAT_CLIPBOARD || PROTO */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3522
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3523 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3524 clear_oparg(oparg_T *oap)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3525 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3526 vim_memset(oap, 0, sizeof(oparg_T));
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3527 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3528
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3529 /*
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3530 * Count the number of bytes, characters and "words" in a line.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3531 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3532 * "Words" are counted by looking for boundaries between non-space and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3533 * space characters. (it seems to produce results that match 'wc'.)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3534 *
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3535 * 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
3536 * Char count is added to "*cc".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3537 *
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3538 * The function will only examine the first "limit" characters in the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3539 * line, stopping if it encounters an end-of-line (NUL byte). In that
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3540 * case, eol_size will be added to the character count to account for
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3541 * the size of the EOL character.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3542 */
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3543 static varnumber_T
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3544 line_count_info(
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3545 char_u *line,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3546 varnumber_T *wc,
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3547 varnumber_T *cc,
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3548 varnumber_T limit,
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3549 int eol_size)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3550 {
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3551 varnumber_T i;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3552 varnumber_T words = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3553 varnumber_T chars = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3554 int is_word = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3555
3626
802b1a1b275f updated for version 7.3.573
Bram Moolenaar <bram@vim.org>
parents: 3584
diff changeset
3556 for (i = 0; i < limit && line[i] != NUL; )
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3557 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3558 if (is_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3559 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3560 if (vim_isspace(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3561 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3562 words++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3563 is_word = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3564 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3565 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3566 else if (!vim_isspace(line[i]))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3567 is_word = 1;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3568 ++chars;
474
a5fcf36ef512 updated for version 7.0127
vimboss
parents: 446
diff changeset
3569 i += (*mb_ptr2len)(line + i);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3570 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3571
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3572 if (is_word)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3573 words++;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3574 *wc += words;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3575
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3576 /* 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
3577 if (i < limit && line[i] == NUL)
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3578 {
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3579 i += eol_size;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3580 chars += eol_size;
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3581 }
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3582 *cc += chars;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3583 return i;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3584 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3585
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3586 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3587 * Give some info about the position of the cursor (for "g CTRL-G").
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3588 * In Visual mode, give some info about the selected region. (In this case,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3589 * 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
3590 * When "dict" is not NULL store the info there instead of showing it.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3591 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3592 void
7829
2a8d6b2dd925 commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents: 7805
diff changeset
3593 cursor_pos_info(dict_T *dict)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3594 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3595 char_u *p;
274
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
3596 char_u buf1[50];
8fa8d7964cf1 updated for version 7.0073
vimboss
parents: 237
diff changeset
3597 char_u buf2[40];
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3598 linenr_T lnum;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3599 varnumber_T byte_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3600 varnumber_T bom_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3601 varnumber_T byte_count_cursor = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3602 varnumber_T char_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3603 varnumber_T char_count_cursor = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3604 varnumber_T word_count = 0;
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3605 varnumber_T word_count_cursor = 0;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3606 int eol_size;
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3607 varnumber_T last_check = 100000L;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3608 long line_count_selected = 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3609 pos_T min_pos, max_pos;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3610 oparg_T oparg;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3611 struct block_def bd;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3612
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3613 /*
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3614 * Compute the length of the file in characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3615 */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3616 if (curbuf->b_ml.ml_flags & ML_EMPTY)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3617 {
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3618 if (dict == NULL)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3619 {
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15517
diff changeset
3620 msg(_(no_lines_msg));
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3621 return;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3622 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3623 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3624 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3625 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3626 if (get_fileformat(curbuf) == EOL_DOS)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3627 eol_size = 2;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3628 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3629 eol_size = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3630
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3631 if (VIsual_active)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3632 {
11121
778c10516955 patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 11065
diff changeset
3633 if (LT_POS(VIsual, curwin->w_cursor))
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3634 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3635 min_pos = VIsual;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3636 max_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3637 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3638 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3639 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3640 min_pos = curwin->w_cursor;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3641 max_pos = VIsual;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3642 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3643 if (*p_sel == 'e' && max_pos.col > 0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3644 --max_pos.col;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3645
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3646 if (VIsual_mode == Ctrl_V)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3647 {
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3648 #ifdef FEAT_LINEBREAK
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3649 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
3650 char_u * saved_w_sbr = curwin->w_p_sbr;
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3651
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3652 /* Make 'sbr' empty for a moment to get the correct size. */
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3653 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
3654 curwin->w_p_sbr = empty_option;
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3655 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3656 oparg.is_VIsual = 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3657 oparg.block_mode = TRUE;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3658 oparg.op_type = OP_NOP;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3659 getvcols(curwin, &min_pos, &max_pos,
688
bcd2edc4539e updated for version 7.0207
vimboss
parents: 681
diff changeset
3660 &oparg.start_vcol, &oparg.end_vcol);
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3661 #ifdef FEAT_LINEBREAK
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3662 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
3663 curwin->w_p_sbr = saved_w_sbr;
1866
c474f5691c0c updated for version 7.2-164
vimboss
parents: 1860
diff changeset
3664 #endif
688
bcd2edc4539e updated for version 7.0207
vimboss
parents: 681
diff changeset
3665 if (curwin->w_curswant == MAXCOL)
bcd2edc4539e updated for version 7.0207
vimboss
parents: 681
diff changeset
3666 oparg.end_vcol = MAXCOL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3667 /* Swap the start, end vcol if needed */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3668 if (oparg.end_vcol < oparg.start_vcol)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3669 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3670 oparg.end_vcol += oparg.start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3671 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3672 oparg.end_vcol -= oparg.start_vcol;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3673 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3674 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3675 line_count_selected = max_pos.lnum - min_pos.lnum + 1;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3676 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3677
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3678 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3679 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3680 /* Check for a CTRL-C every 100000 characters. */
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3681 if (byte_count > last_check)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3682 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3683 ui_breakcheck();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3684 if (got_int)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3685 return;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3686 last_check = byte_count + 100000L;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3687 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3688
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3689 /* Do extra processing for VIsual mode. */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3690 if (VIsual_active
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3691 && lnum >= min_pos.lnum && lnum <= max_pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3692 {
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3693 char_u *s = NULL;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3694 long len = 0L;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3695
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3696 switch (VIsual_mode)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3697 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3698 case Ctrl_V:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3699 virtual_op = virtual_active();
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3700 block_prep(&oparg, &bd, lnum, 0);
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3701 virtual_op = MAYBE;
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3702 s = bd.textstart;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3703 len = (long)bd.textlen;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3704 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3705 case 'V':
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3706 s = ml_get(lnum);
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3707 len = MAXCOL;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3708 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3709 case 'v':
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3710 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3711 colnr_T start_col = (lnum == min_pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3712 ? min_pos.col : 0;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3713 colnr_T end_col = (lnum == max_pos.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3714 ? max_pos.col - start_col + 1 : MAXCOL;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3715
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3716 s = ml_get(lnum) + start_col;
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3717 len = end_col;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3718 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3719 break;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3720 }
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3721 if (s != NULL)
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3722 {
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3723 byte_count_cursor += line_count_info(s, &word_count_cursor,
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3724 &char_count_cursor, len, eol_size);
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3725 if (lnum == curbuf->b_ml.ml_line_count
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3726 && !curbuf->b_p_eol
6933
62ba356c2d4e patch 7.4.785
Bram Moolenaar <bram@vim.org>
parents: 6929
diff changeset
3727 && (curbuf->b_p_bin || !curbuf->b_p_fixeol)
50
90188be4861f updated for version 7.0028
vimboss
parents: 45
diff changeset
3728 && (long)STRLEN(s) < len)
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3729 byte_count_cursor -= eol_size;
45
e474bae3795f updated for version 7.0027
vimboss
parents: 39
diff changeset
3730 }
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3731 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3732 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3733 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3734 /* In non-visual mode, check for the line the cursor is on */
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3735 if (lnum == curwin->w_cursor.lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3736 {
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3737 word_count_cursor += word_count;
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3738 char_count_cursor += char_count;
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3739 byte_count_cursor = byte_count +
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3740 line_count_info(ml_get(lnum),
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3741 &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
3742 (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
3743 eol_size);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3744 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3745 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3746 /* Add to the running totals */
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3747 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
3748 &char_count, (varnumber_T)MAXCOL,
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3749 eol_size);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3750 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3751
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3752 /* 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
3753 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
3754 byte_count -= eol_size;
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3755
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3756 if (dict == NULL)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3757 {
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3758 if (VIsual_active)
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3759 {
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3760 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
3761 {
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3762 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
3763 &max_pos.col);
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3764 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
3765 (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
3766 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3767 else
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3768 buf1[0] = NUL;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3769
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3770 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
3771 && char_count == byte_count)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3772 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3773 _("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
3774 buf1, line_count_selected,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3775 (long)curbuf->b_ml.ml_line_count,
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3776 (long_long_T)word_count_cursor,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3777 (long_long_T)word_count,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3778 (long_long_T)byte_count_cursor,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3779 (long_long_T)byte_count);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3780 else
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3781 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3782 _("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
3783 buf1, line_count_selected,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3784 (long)curbuf->b_ml.ml_line_count,
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3785 (long_long_T)word_count_cursor,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3786 (long_long_T)word_count,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3787 (long_long_T)char_count_cursor,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3788 (long_long_T)char_count,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3789 (long_long_T)byte_count_cursor,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3790 (long_long_T)byte_count);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3791 }
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3792 else
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3793 {
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3794 p = ml_get_curline();
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3795 validate_virtcol();
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3796 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
3797 (int)curwin->w_virtcol + 1);
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3798 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
3799 linetabsize(p));
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3800
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3801 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
3802 && char_count == byte_count)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3803 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3804 _("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
3805 (char *)buf1, (char *)buf2,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3806 (long)curwin->w_cursor.lnum,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3807 (long)curbuf->b_ml.ml_line_count,
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3808 (long_long_T)word_count_cursor, (long_long_T)word_count,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3809 (long_long_T)byte_count_cursor, (long_long_T)byte_count);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3810 else
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3811 vim_snprintf((char *)IObuff, IOSIZE,
9389
32e34e574716 commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents: 9332
diff changeset
3812 _("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
3813 (char *)buf1, (char *)buf2,
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3814 (long)curwin->w_cursor.lnum,
161
6df0106fc595 updated for version 7.0049
vimboss
parents: 140
diff changeset
3815 (long)curbuf->b_ml.ml_line_count,
15517
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3816 (long_long_T)word_count_cursor, (long_long_T)word_count,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3817 (long_long_T)char_count_cursor, (long_long_T)char_count,
2ad5f0ffaa2e patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
3818 (long_long_T)byte_count_cursor, (long_long_T)byte_count);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3819 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3820 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3821
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3822 bom_count = bomb_size();
18062
0b351691071c patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 17797
diff changeset
3823 if (dict == NULL && bom_count > 0)
7496
6d969668bfc8 commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents: 7484
diff changeset
3824 vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE,
15597
536dd2bc5ac9 patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
3825 _("(+%lld for BOM)"), (long_long_T)bom_count);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3826 if (dict == NULL)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3827 {
18062
0b351691071c patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents: 17797
diff changeset
3828 // 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
3829 p = p_shm;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3830 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
3831 msg((char *)IObuff);
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3832 p_shm = p;
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3833 }
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3834 }
7484
1fe988587423 commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents: 7480
diff changeset
3835 #if defined(FEAT_EVAL)
7480
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3836 if (dict != NULL)
a49163681559 commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents: 7447
diff changeset
3837 {
14301
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14216
diff changeset
3838 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
3839 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
3840 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
3841 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
3842 byte_count_cursor);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14216
diff changeset
3843 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
3844 char_count_cursor);
3c80092eb211 patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents: 14216
diff changeset
3845 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
3846 word_count_cursor);
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3847 }
7484
1fe988587423 commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents: 7480
diff changeset
3848 #endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3849 }
18219
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 * 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
3853 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3854 static void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3855 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
3856 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3857 stuffcharReadbuff(':');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3858 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
3859 stuffReadbuff((char_u *)"'<,'>");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3860 else
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 // 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
3863 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
3864 stuffcharReadbuff('.');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3865 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3866 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
3867 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
3868 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3869 stuffcharReadbuff(',');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3870 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
3871 stuffcharReadbuff('.');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3872 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
3873 stuffcharReadbuff('$');
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3874 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
3875 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3876 stuffReadbuff((char_u *)".+");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3877 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
3878 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3879 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3880 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
3881 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3882 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3883 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
3884 stuffReadbuff((char_u *)"!");
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3885 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
3886 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3887 #ifndef FEAT_CINDENT
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3888 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
3889 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
3890 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3891 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3892 stuffReadbuff(get_equalprg());
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3893 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
3894 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3895 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
3896 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3897 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
3898 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
3899 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
3900 stuffReadbuff(p_fp);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3901 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3902 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
3903 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
3904 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3905
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3906 // 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
3907 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3908
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3909 /*
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3910 * 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
3911 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3912 static void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3913 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
3914 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3915 #ifdef FEAT_EVAL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3916 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
3917 int save_virtual_op = virtual_op;
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3918 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
3919 pos_T orig_end = curbuf->b_op_end;
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3920
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3921 if (*p_opfunc == NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3922 emsg(_("E774: 'operatorfunc' is empty"));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3923 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3924 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3925 // 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
3926 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
3927 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
3928 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
3929 // 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
3930 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
3931
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3932 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
3933 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
3934 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
3935 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
3936 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
3937 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3938 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
3939 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
3940
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3941 // 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
3942 // function.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3943 virtual_op = MAYBE;
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 (void)call_func_retnr(p_opfunc, 1, argv);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3946
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3947 virtual_op = save_virtual_op;
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3948 if (cmdmod.lockmarks)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3949 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18599
diff changeset
3950 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
3951 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
3952 }
18219
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3953 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3954 #else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3955 emsg(_("E775: Eval feature not available"));
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3956 #endif
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
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3959 /*
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3960 * 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
3961 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3962 static void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3963 get_op_vcol(
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3964 oparg_T *oap,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3965 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
3966 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
3967 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3968 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
3969
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3970 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
3971 || (!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
3972 return;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3973
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3974 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
3975
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3976 // 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
3977 if (has_mbyte)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3978 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
3979
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3980 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
3981
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3982 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
3983 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3984 getvvcol(curwin, &(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
3985
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3986 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
3987 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
3988 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
3989 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3990 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
3991 && 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
3992 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
3993 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3994 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
3995 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3996 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3997
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
3998 // 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
3999 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
4000 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4001 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
4002 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
4003 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
4004 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
4005 ++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
4006 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4007 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
4008 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
4009 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
4010 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4011 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4012 else 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
4013 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
4014 // 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
4015 // 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
4016 //
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4017 // (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
4018 // positions)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4019 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
4020 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
4021 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
4022
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4023 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
4024 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
4025 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
4026 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4027
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4028 /*
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4029 * 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
4030 * "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
4031 */
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4032 void
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4033 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
4034 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4035 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
4036 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
4037 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
4038 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
4039 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4040 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
4041 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4042
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4043 // The visual area is remembered for redo
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4044 static int redo_VIsual_mode = NUL; // 'v', 'V', or Ctrl-V
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4045 static linenr_T redo_VIsual_line_count; // number of lines
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4046 static colnr_T redo_VIsual_vcol; // number of cols or end column
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4047 static long redo_VIsual_count; // count for Visual operator
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4048 static int redo_VIsual_arg; // extra argument
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4049 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
4050
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4051 #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
4052 // 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
4053 // 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
4054 // 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
4055 // 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
4056 // 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
4057 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
4058 && 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
4059 && !gui_yank
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4060 && VIsual_active
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4061 && !redo_VIsual_busy
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4062 && oap->regname == 0)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4063 clip_auto_select();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4064 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4065 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
4066
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4067 // 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
4068 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
4069 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4070 // 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
4071 // for the clipboard.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4072 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
4073
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4074 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4075 // 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
4076 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
4077 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
4078 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
4079 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4080 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
4081 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
4082 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
4083 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
4084 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4085 // 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
4086 // 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
4087 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
4088 oap->inclusive = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4089 // 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
4090 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
4091 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
4092 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
4093 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4094 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
4095 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4096 // 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
4097 if (!VIsual_active)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4098 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4099 VIsual_active = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4100 VIsual = oap->start;
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 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
4103 VIsual_select = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4104 VIsual_reselect = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4105 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4106
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4107 // 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
4108 // 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
4109 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
4110 && ((!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
4111 // Also redo Operator-pending Visual mode mappings
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4112 || (VIsual_active && cap->cmdchar == ':'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4113 && 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
4114 && cap->cmdchar != 'D'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4115 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4116 && 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
4117 && 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
4118 && 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
4119 && 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
4120 && 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
4121 && 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
4122 && 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
4123 #endif
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 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4126 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
4127 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
4128 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
4129 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
4130 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4131 // 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
4132 // 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
4133 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
4134 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
4135 AppendToRedobuff(NL_STR);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4136 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4137 else if (cap->cmdchar == ':')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4138 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4139 // 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
4140 // "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
4141 // 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
4142 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
4143 ResetRedobuff();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4144 else
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 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
4147 AppendToRedobuff(NL_STR);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4148 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
4149 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4150 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4151 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4152
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4153 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
4154 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4155 // Redo of an operation on a Visual area. Use the same size from
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4156 // redo_VIsual_line_count and redo_VIsual_vcol.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4157 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
4158 curwin->w_cursor.lnum += redo_VIsual_line_count - 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4159 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
4160 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
4161 VIsual_mode = redo_VIsual_mode;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4162 if (redo_VIsual_vcol == MAXCOL || VIsual_mode == 'v')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4163 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4164 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
4165 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4166 if (redo_VIsual_line_count <= 1)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4167 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4168 validate_virtcol();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4169 curwin->w_curswant =
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4170 curwin->w_virtcol + redo_VIsual_vcol - 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4171 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4172 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4173 curwin->w_curswant = redo_VIsual_vcol;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4174 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4175 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4176 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4177 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
4178 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4179 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
4180 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4181 cap->count0 = redo_VIsual_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4182 if (redo_VIsual_count != 0)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4183 cap->count1 = redo_VIsual_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4184 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4185 cap->count1 = 1;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4186 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4187 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
4188 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4189 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4190 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4191 // 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
4192 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
4193 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
4194 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
4195 restore_visual_mode();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4196 curbuf->b_visual.vi_curswant = curwin->w_curswant;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4197 # ifdef FEAT_EVAL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4198 curbuf->b_visual_mode_eval = VIsual_mode;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4199 # endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4200 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4201
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4202 // 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
4203 // characterwise selection.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4204 // 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
4205 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
4206 && 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
4207 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4208 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
4209 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4210 VIsual.col = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4211 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
4212 (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
4213 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4214 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4215 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4216 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
4217 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
4218 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4219 VIsual_mode = 'v';
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4220 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4221 // 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
4222 // charwise selections.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4223 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
4224 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
4225
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4226 oap->start = VIsual;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4227 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
4228 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4229 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
4230 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
4231 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4232 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4233
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4234 // 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
4235 // 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
4236 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
4237 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4238 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4239 // 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
4240 if (!VIsual_active)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4241 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4242 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
4243 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
4244 if ((curwin->w_cursor.col > 0 || oap->inclusive)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4245 && 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
4246 &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
4247 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
4248 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4249 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4250 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
4251 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
4252
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4253 // 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
4254 // 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
4255 // automatically.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4256 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
4257 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4258 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4259 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4260 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4261 // 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
4262 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
4263 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4264 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
4265 NULL))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4266 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
4267 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
4268 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
4269 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4270 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4271 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
4272 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
4273 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4274
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4275 // 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
4276 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
4277 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
4278
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4279 // 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
4280 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
4281
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4282 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
4283 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4284 get_op_vcol(oap, redo_VIsual_vcol, TRUE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4285
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4286 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
4287 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4288 // 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
4289 // 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
4290 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
4291 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
4292 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
4293 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4294 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4295 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
4296 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
4297 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
4298 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
4299 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4300 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
4301 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
4302 &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
4303 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
4304 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4305 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4306 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
4307 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4308 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
4309 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4310
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4311 // 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
4312 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
4313 && 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
4314 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4315 && 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
4316 && 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
4317 && 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
4318 && 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
4319 && 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
4320 && 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
4321 && 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
4322 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4323 && 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
4324 )
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4325 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4326 // 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
4327 // 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
4328 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
4329 || cap->nchar == 'N'))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4330 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
4331 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
4332 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
4333 else if (cap->cmdchar != ':')
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4334 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4335 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
4336
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4337 // 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
4338 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
4339 nchar = CAR;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4340 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
4341 nchar = NL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4342 prep_redo(oap->regname, 0L, NUL, 'v',
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4343 get_op_char(oap->op_type),
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4344 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
4345 nchar);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4346 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4347 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
4348 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4349 redo_VIsual_mode = resel_VIsual_mode;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4350 redo_VIsual_vcol = resel_VIsual_vcol;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4351 redo_VIsual_line_count = resel_VIsual_line_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4352 redo_VIsual_count = cap->count0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4353 redo_VIsual_arg = cap->arg;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4354 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4355 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4356
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4357 // 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
4358 // 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
4359 // 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
4360 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
4361 oap->inclusive = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4362 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
4363 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
4364 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4365 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4366 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
4367 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
4368 && (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
4369 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4370 oap->inclusive = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4371 // 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
4372 // 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
4373 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
4374 && !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
4375 && 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
4376 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4377 ++oap->end.lnum;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4378 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
4379 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
4380 ++oap->line_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4381 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4382 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4383 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4384
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4385 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
4386
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4387 // 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
4388 // 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
4389 // 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
4390 // 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
4391 // part.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4392 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4393 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4394 VIsual_active = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4395 setmouse();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4396 mouse_dragging = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4397 may_clear_cmdline();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4398 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
4399 || 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
4400 || 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
4401 || 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
4402 && 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
4403 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4404 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4405 // 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
4406 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
4407 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4408 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
4409 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4410 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4411 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4412
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4413 // 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
4414 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
4415 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4416 int l;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4417
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4418 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
4419 if (l > 1)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4420 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
4421 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4422 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
4423
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4424 // 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
4425 // 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
4426 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
4427 && (!oap->inclusive
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4428 || (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
4429 && 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
4430 && 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
4431 && !(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
4432 // 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
4433 // 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
4434 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
4435 && 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
4436
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4437 // 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
4438 // '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
4439 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
4440 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4441 || 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
4442 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4443 ))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4444 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4445 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4446 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
4447 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4448 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
4449 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4450
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4451 // 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
4452 // 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
4453 // 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
4454 // 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
4455 // (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
4456 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
4457 && oap->inclusive == FALSE
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4458 && !(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
4459 && 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
4460 && (!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
4461 && !oap->block_mode
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4462 && 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
4463 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4464 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
4465 --oap->line_count;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4466 --oap->end.lnum;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4467 if (inindent(0))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4468 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
4469 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4470 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4471 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
4472 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
4473 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4474 --oap->end.col;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4475 oap->inclusive = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4476 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4477 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4478 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4479 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4480 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
4481
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4482 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
4483 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4484 case OP_LSHIFT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4485 case OP_RSHIFT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4486 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
4487 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
4488 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4489
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4490 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
4491 case OP_JOIN:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4492 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
4493 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
4494 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
4495 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
4496 beep_flush();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4497 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4498 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4499 (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
4500 TRUE, TRUE, TRUE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4501 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
4502 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4503 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4504
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4505 case OP_DELETE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4506 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
4507 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
4508 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4509 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
4510 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4511 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4512 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4513 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4514 (void)op_delete(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4515 if (oap->motion_type == MLINE && has_format_option(FO_AUTO))
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4516 u_save_cursor(); // cursor line wasn't saved yet
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4517 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
4518 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4519 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4520
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4521 case OP_YANK:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4522 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
4523 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4524 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4525 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4526 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
4527 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4528 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4529 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4530 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4531 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4532 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4533 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
4534 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4535 (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
4536 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4537 check_cursor_col();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4538 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4539
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4540 case OP_CHANGE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4541 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
4542 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
4543 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4544 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
4545 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4546 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4547 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4548 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4549 // 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
4550 // 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
4551 // 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
4552 // '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
4553 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
4554 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
4555 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4556 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
4557 restart_edit = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4558 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4559 // 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
4560 // before.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4561 if (curwin->w_p_lbr != lbr_saved)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4562 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4563 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
4564 get_op_vcol(oap, redo_VIsual_mode, FALSE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4565 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4566 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4567 // 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
4568 finish_op = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4569 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
4570 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
4571 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
4572 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
4573 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4574 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4575
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4576 case OP_FILTER:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4577 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
4578 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
4579 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4580 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
4581 // FALLTHROUGH
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4582
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4583 case OP_INDENT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4584 case OP_COLON:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4585
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4586 #if defined(FEAT_LISP) || defined(FEAT_CINDENT)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4587 // 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
4588 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
4589 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4590 # ifdef FEAT_LISP
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4591 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
4592 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4593 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
4594 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4595 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4596 # endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4597 # ifdef FEAT_CINDENT
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4598 op_reindent(oap,
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4599 # ifdef FEAT_EVAL
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4600 *curbuf->b_p_inde != NUL ? get_expr_indent :
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4601 # endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4602 get_c_indent);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4603 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4604 # endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4605 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4606 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4607
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4608 op_colon(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4609 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4610
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4611 case OP_TILDE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4612 case OP_UPPER:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4613 case OP_LOWER:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4614 case OP_ROT13:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4615 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
4616 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4617 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
4618 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4619 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4620 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4621 op_tilde(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4622 check_cursor_col();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4623 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4624
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4625 case OP_FORMAT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4626 #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
4627 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
4628 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
4629 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4630 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4631 if (*p_fp != NUL || *curbuf->b_p_fp != NUL)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4632 op_colon(oap); // use external command
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4633 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4634 op_format(oap, FALSE); // use internal function
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4635 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4636
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4637 case OP_FORMAT2:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4638 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
4639 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4640
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4641 case OP_FUNCTION:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4642 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4643 // Restore linebreak, so that when the user edits it looks as
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4644 // before.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4645 curwin->w_p_lbr = lbr_saved;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4646 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4647 op_function(oap); // call 'operatorfunc'
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4648 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4649
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4650 case OP_INSERT:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4651 case OP_APPEND:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4652 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
4653 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
4654 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4655 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
4656 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4657 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4658 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4659 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4660 // 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
4661 // 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
4662 // 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
4663 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
4664 restart_edit = 0;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4665 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4666 // 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
4667 // before.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4668 if (curwin->w_p_lbr != lbr_saved)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4669 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4670 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
4671 get_op_vcol(oap, redo_VIsual_mode, FALSE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4672 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4673 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4674 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
4675 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4676 // 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
4677 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
4678 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4679
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4680 // 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
4681 // the lines.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4682 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
4683
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4684 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
4685 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
4686 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4687 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
4688 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4689 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4690
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4691 case OP_REPLACE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4692 VIsual_reselect = FALSE; // don't reselect now
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4693 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
4694 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4695 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
4696 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4697 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4698 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4699 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4700 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4701 // 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
4702 // before.
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4703 if (curwin->w_p_lbr != lbr_saved)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4704 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4705 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
4706 get_op_vcol(oap, redo_VIsual_mode, FALSE);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4707 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4708 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4709 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
4710 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4711 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4712
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4713 #ifdef FEAT_FOLDING
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4714 case OP_FOLD:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4715 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
4716 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
4717 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4718
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4719 case OP_FOLDOPEN:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4720 case OP_FOLDOPENREC:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4721 case OP_FOLDCLOSE:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4722 case OP_FOLDCLOSEREC:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4723 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
4724 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
4725 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
4726 || 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
4727 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
4728 || 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
4729 oap->is_VIsual);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4730 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4731
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4732 case OP_FOLDDEL:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4733 case OP_FOLDDELREC:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4734 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
4735 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
4736 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
4737 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4738 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4739 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
4740 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
4741 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
4742 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4743 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
4744 CancelRedo();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4745 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4746 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4747 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4748 VIsual_active = TRUE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4749 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4750 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
4751 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4752 op_addsub(oap, cap->count1, redo_VIsual_arg);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4753 VIsual_active = FALSE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4754 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4755 check_cursor_col();
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4756 break;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4757 default:
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4758 clearopbeep(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4759 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4760 virtual_op = MAYBE;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4761 if (!gui_yank)
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4762 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4763 // 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
4764 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
4765 && (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
4766 || 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
4767 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4768 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4769 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
4770 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4771 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
4772 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4773 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4774 else
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4775 {
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4776 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
4777 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4778 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
4779 clearop(oap);
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4780 motion_force = NUL;
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4781 }
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4782 #ifdef FEAT_LINEBREAK
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4783 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
4784 #endif
5d67f207f7c3 patch 8.1.2104: the normal.c file is too big
Bram Moolenaar <Bram@vim.org>
parents: 18203
diff changeset
4785 }