Mercurial > vim
annotate src/ops.c @ 15840:734b1928a5aa v8.1.0927
patch 8.1.0927: USE_CR is never defined
commit https://github.com/vim/vim/commit/00590740081489db69f43d9f1c0e3f70e29ce6da
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 15 21:06:09 2019 +0100
patch 8.1.0927: USE_CR is never defined
Problem: USE_CR is never defined.
Solution: Remove usage of USE_CR. (Ken Takata, closes https://github.com/vim/vim/issues/3958)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 15 Feb 2019 21:15:07 +0100 |
parents | 6f1c7e9a6393 |
children | ddd82b1c9e9d |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9834
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, | |
12 * op_change, op_yank, do_put, do_join | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * Number of registers. | |
19 * 0 = unnamed register, for normal yanks and puts | |
20 * 1..9 = registers '1' to '9', for deletes | |
21 * 10..35 = registers 'a' to 'z' | |
22 * 36 = delete register '-' | |
23 * 37 = Selection register '*'. Only if FEAT_CLIPBOARD defined | |
24 * 38 = Clipboard register '+'. Only if FEAT_CLIPBOARD and FEAT_X11 defined | |
25 */ | |
26 /* | |
27 * Symbolic names for some registers. | |
28 */ | |
29 #define DELETION_REGISTER 36 | |
30 #ifdef FEAT_CLIPBOARD | |
31 # define STAR_REGISTER 37 | |
32 # ifdef FEAT_X11 | |
33 # define PLUS_REGISTER 38 | |
34 # else | |
35 # define PLUS_REGISTER STAR_REGISTER /* there is only one */ | |
36 # endif | |
37 #endif | |
38 #ifdef FEAT_DND | |
39 # define TILDE_REGISTER (PLUS_REGISTER + 1) | |
40 #endif | |
41 | |
42 #ifdef FEAT_CLIPBOARD | |
43 # ifdef FEAT_DND | |
44 # define NUM_REGISTERS (TILDE_REGISTER + 1) | |
45 # else | |
46 # define NUM_REGISTERS (PLUS_REGISTER + 1) | |
47 # endif | |
48 #else | |
49 # define NUM_REGISTERS 37 | |
50 #endif | |
51 | |
52 /* | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
53 * Each yank register has an array of pointers to lines. |
7 | 54 */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
55 typedef struct |
7 | 56 { |
57 char_u **y_array; /* pointer to array of line pointers */ | |
58 linenr_T y_size; /* number of lines in y_array */ | |
59 char_u y_type; /* MLINE, MCHAR or MBLOCK */ | |
60 colnr_T y_width; /* only set if y_type == MBLOCK */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
61 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
62 time_t y_time_set; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
63 #endif |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
64 } yankreg_T; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
65 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
66 static yankreg_T y_regs[NUM_REGISTERS]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
67 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
68 static yankreg_T *y_current; /* ptr to current yankreg */ |
7 | 69 static int y_append; /* TRUE when appending */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
70 static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */ |
7 | 71 |
72 /* | |
73 * structure used by block_prep, op_delete and op_yank for blockwise operators | |
74 * also op_change, op_shift, op_insert, op_replace - AKelly | |
75 */ | |
76 struct block_def | |
77 { | |
1839 | 78 int startspaces; /* 'extra' cols before first char */ |
79 int endspaces; /* 'extra' cols after last char */ | |
7 | 80 int textlen; /* chars in block */ |
1839 | 81 char_u *textstart; /* pointer to 1st char (partially) in block */ |
82 colnr_T textcol; /* index of chars (partially) in block */ | |
7 | 83 colnr_T start_vcol; /* start col of 1st char wholly inside block */ |
84 colnr_T end_vcol; /* start col of 1st char wholly after block */ | |
85 int is_short; /* TRUE if line is too short to fit in block */ | |
86 int is_MAX; /* TRUE if curswant==MAXCOL when starting */ | |
87 int is_oneChar; /* TRUE if block within one character */ | |
88 int pre_whitesp; /* screen cols of ws before block */ | |
89 int pre_whitesp_c; /* chars of ws before block */ | |
90 colnr_T end_char_vcols; /* number of vcols of post-block char */ | |
91 colnr_T start_char_vcols; /* number of vcols of pre-block char */ | |
92 }; | |
93 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
94 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
|
95 static int stuff_yank(int, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
96 static void put_reedit_in_typebuf(int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
97 static int put_in_typebuf(char_u *s, int esc, int colon, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
98 int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
99 static void stuffescaped(char_u *arg, int literally); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
100 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
|
101 static void free_yank_all(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
102 static int yank_copy_line(struct block_def *bd, long y_idx); |
7 | 103 #ifdef FEAT_CLIPBOARD |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
104 static void copy_yank_reg(yankreg_T *reg); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
105 static void may_set_selection(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
106 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
107 static void dis_msg(char_u *p, int skip_esc); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
108 static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
109 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
7 | 110 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
111 static void str_to_reg(yankreg_T *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
112 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
113 static int ends_in_white(linenr_T lnum); |
7 | 114 #ifdef FEAT_COMMENTS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
115 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 116 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
117 static int fmt_check_par(linenr_T); |
7 | 118 #endif |
119 | |
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
|
120 // 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
|
121 #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
|
122 #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
|
123 |
7 | 124 /* |
125 * The names of operators. | |
126 * 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
|
127 * The third field holds OPF_ flags. |
7 | 128 */ |
129 static char opchars[][3] = | |
130 { | |
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
|
131 {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
|
132 {'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
|
133 {'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
|
134 {'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
|
135 {'<', 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
|
136 {'>', 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
|
137 {'!', 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
|
138 {'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
|
139 {'=', 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
|
140 {'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
|
141 {':', 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
|
142 {'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
|
143 {'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
|
144 {'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
|
145 {'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
|
146 {'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
|
147 {'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
|
148 {'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
|
149 {'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
|
150 {'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
|
151 {'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
|
152 {'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
|
153 {'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
|
154 {'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
|
155 {'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
|
156 {'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
|
157 {'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
|
158 {'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
|
159 {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
|
160 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB |
7 | 161 }; |
162 | |
163 /* | |
164 * Translate a command name into an operator type. | |
165 * Must only be called with a valid operator name! | |
166 */ | |
167 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
168 get_op_type(int char1, int char2) |
7 | 169 { |
170 int i; | |
171 | |
172 if (char1 == 'r') /* ignore second character */ | |
173 return OP_REPLACE; | |
174 if (char1 == '~') /* when tilde is an operator */ | |
175 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
176 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
|
177 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
178 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
|
179 return OP_NR_SUB; |
7 | 180 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
|
181 { |
7 | 182 if (opchars[i][0] == char1 && opchars[i][1] == char2) |
183 break; | |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
184 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
|
185 { |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
186 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
|
187 break; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
188 } |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
189 } |
7 | 190 return i; |
191 } | |
192 | |
193 /* | |
194 * Return TRUE if operator "op" always works on whole lines. | |
195 */ | |
196 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
197 op_on_lines(int op) |
7 | 198 { |
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
|
199 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
|
200 } |
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
|
201 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
202 #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
|
203 /* |
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
|
204 * 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
|
205 */ |
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
|
206 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
|
207 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
|
208 { |
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
|
209 return opchars[op][2] & OPF_CHANGE; |
7 | 210 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
211 #endif |
7 | 212 |
213 /* | |
214 * Get first operator command character. | |
215 * Returns 'g' or 'z' if there is another command character. | |
216 */ | |
217 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
218 get_op_char(int optype) |
7 | 219 { |
220 return opchars[optype][0]; | |
221 } | |
222 | |
223 /* | |
224 * Get second operator command character. | |
225 */ | |
226 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
227 get_extra_op_char(int optype) |
7 | 228 { |
229 return opchars[optype][1]; | |
230 } | |
231 | |
232 /* | |
233 * op_shift - handle a shift operation | |
234 */ | |
235 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
236 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 237 { |
238 long i; | |
239 int first_char; | |
240 int block_col = 0; | |
241 | |
242 if (u_save((linenr_T)(oap->start.lnum - 1), | |
243 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
244 return; | |
245 | |
246 if (oap->block_mode) | |
247 block_col = curwin->w_cursor.col; | |
248 | |
249 for (i = oap->line_count; --i >= 0; ) | |
250 { | |
251 first_char = *ml_get_curline(); | |
252 if (first_char == NUL) /* empty line */ | |
253 curwin->w_cursor.col = 0; | |
254 else if (oap->block_mode) | |
255 shift_block(oap, amount); | |
256 else | |
257 /* Move the line right if it doesn't start with '#', 'smartindent' | |
258 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
259 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
260 if (first_char != '#' || !preprocs_left()) | |
261 #endif | |
262 { | |
1516 | 263 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 264 } |
265 ++curwin->w_cursor.lnum; | |
266 } | |
267 | |
268 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
269 if (oap->block_mode) | |
270 { | |
271 curwin->w_cursor.lnum = oap->start.lnum; | |
272 curwin->w_cursor.col = block_col; | |
273 } | |
5735 | 274 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 275 { |
276 curwin->w_cursor.lnum = oap->start.lnum; | |
277 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
278 } | |
279 else | |
280 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
281 | |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
282 #ifdef FEAT_FOLDING |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
283 /* 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
|
284 foldOpenCursor(); |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
285 #endif |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
286 |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
287 |
7 | 288 if (oap->line_count > p_report) |
289 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
290 char *op; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
291 char *msg_line_single; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
292 char *msg_line_plural; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
293 |
7 | 294 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
|
295 op = ">"; |
7 | 296 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
297 op = "<"; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
298 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
|
299 "%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
|
300 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
|
301 "%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
|
302 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
|
303 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
|
304 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
|
305 msg((char *)IObuff); |
7 | 306 } |
307 | |
308 /* | |
309 * Set "'[" and "']" marks. | |
310 */ | |
311 curbuf->b_op_start = oap->start; | |
312 curbuf->b_op_end.lnum = oap->end.lnum; | |
313 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
314 if (curbuf->b_op_end.col > 0) | |
315 --curbuf->b_op_end.col; | |
316 } | |
317 | |
318 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
319 * 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
|
320 * leaves cursor on first blank in the line. |
7 | 321 */ |
322 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
323 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
324 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
325 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
326 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
327 int call_changed_bytes) /* call changed_bytes() */ |
7 | 328 { |
329 int count; | |
330 int i, j; | |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
15048
diff
changeset
|
331 int p_sw = (int)get_sw_value_indent(curbuf); |
7 | 332 |
333 count = get_indent(); /* get current indent */ | |
334 | |
335 if (round) /* round off indent */ | |
336 { | |
337 i = count / p_sw; /* number of p_sw rounded down */ | |
338 j = count % p_sw; /* extra spaces */ | |
339 if (j && left) /* first remove extra spaces */ | |
340 --amount; | |
341 if (left) | |
342 { | |
343 i -= amount; | |
344 if (i < 0) | |
345 i = 0; | |
346 } | |
347 else | |
348 i += amount; | |
349 count = i * p_sw; | |
350 } | |
351 else /* original vi indent */ | |
352 { | |
353 if (left) | |
354 { | |
355 count -= p_sw * amount; | |
356 if (count < 0) | |
357 count = 0; | |
358 } | |
359 else | |
360 count += p_sw * amount; | |
361 } | |
362 | |
363 /* Set new indent */ | |
364 if (State & VREPLACE_FLAG) | |
1516 | 365 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 366 else |
1516 | 367 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 368 } |
369 | |
370 /* | |
371 * Shift one line of the current block one shiftwidth right or left. | |
372 * Leaves cursor on first character in block. | |
373 */ | |
374 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
375 shift_block(oparg_T *oap, int amount) |
7 | 376 { |
377 int left = (oap->op_type == OP_LSHIFT); | |
378 int oldstate = State; | |
1839 | 379 int total; |
380 char_u *newp, *oldp; | |
7 | 381 int oldcol = curwin->w_cursor.col; |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
15048
diff
changeset
|
382 int p_sw = (int)get_sw_value_indent(curbuf); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
383 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
384 int *p_vts = curbuf->b_p_vts_array; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
385 #endif |
7 | 386 int p_ts = (int)curbuf->b_p_ts; |
387 struct block_def bd; | |
388 int incr; | |
1839 | 389 colnr_T ws_vcol; |
7 | 390 int i = 0, j = 0; |
391 int len; | |
392 #ifdef FEAT_RIGHTLEFT | |
393 int old_p_ri = p_ri; | |
394 | |
4352 | 395 p_ri = 0; /* don't want revins in indent */ |
7 | 396 #endif |
397 | |
398 State = INSERT; /* don't want REPLACE for State */ | |
399 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
400 if (bd.is_short) | |
401 return; | |
402 | |
403 /* total is number of screen columns to be inserted/removed */ | |
11997
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
404 total = (int)((unsigned)amount * (unsigned)p_sw); |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
405 if ((total / p_sw) != amount) |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
406 return; /* multiplication overflow */ |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
407 |
7 | 408 oldp = ml_get_curline(); |
409 | |
410 if (!left) | |
411 { | |
412 /* | |
413 * 1. Get start vcol | |
414 * 2. Total ws vcols | |
415 * 3. Divvy into TABs & spp | |
416 * 4. Construct new string | |
417 */ | |
418 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
419 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
420 if (bd.startspaces) | |
421 { | |
422 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
423 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
424 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
425 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
426 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
427 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
428 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
429 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
430 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
431 } |
1995 | 432 else |
433 ++bd.textstart; | |
7 | 434 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
435 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 436 { |
5995 | 437 /* TODO: is passing bd.textstart for start of the line OK? */ |
438 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
439 (colnr_T)(bd.start_vcol)); | |
7 | 440 total += incr; |
441 bd.start_vcol += incr; | |
442 } | |
443 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
444 * 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
|
445 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
446 if (!curbuf->b_p_et) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
447 tabstop_fromto(ws_vcol, ws_vcol + total, p_ts, p_vts, &i, &j); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
448 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
449 j = total; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
450 #else |
7 | 451 if (!curbuf->b_p_et) |
452 i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ | |
453 if (i) | |
454 j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ | |
455 else | |
456 j = total; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
457 #endif |
7 | 458 /* if we're splitting a TAB, allow for it */ |
459 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
460 len = (int)STRLEN(bd.textstart) + 1; | |
461 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | |
462 if (newp == NULL) | |
463 return; | |
464 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
465 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 466 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
467 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 468 /* the end */ |
469 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
470 } | |
471 else /* left */ | |
472 { | |
1839 | 473 colnr_T destination_col; /* column to which text in block will |
474 be shifted */ | |
475 char_u *verbatim_copy_end; /* end of the part of the line which is | |
476 copied verbatim */ | |
477 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
478 of line */ | |
479 unsigned fill; /* nr of spaces that replace a TAB */ | |
480 unsigned new_line_len; /* the length of the line after the | |
481 block shift */ | |
482 size_t block_space_width; | |
483 size_t shift_amount; | |
484 char_u *non_white = bd.textstart; | |
485 colnr_T non_white_col; | |
486 | |
487 /* | |
488 * Firstly, let's find the first non-whitespace character that is | |
489 * displayed after the block's start column and the character's column | |
490 * number. Also, let's calculate the width of all the whitespace | |
491 * characters that are displayed in the block and precede the searched | |
492 * non-whitespace character. | |
493 */ | |
494 | |
495 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
496 * the part of which is displayed at the block's beginning. Let's start | |
497 * searching from the next character. */ | |
498 if (bd.startspaces) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
499 MB_PTR_ADV(non_white); |
1839 | 500 |
501 /* The character's column is in "bd.start_vcol". */ | |
502 non_white_col = bd.start_vcol; | |
503 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
504 while (VIM_ISWHITE(*non_white)) |
7 | 505 { |
5995 | 506 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 507 non_white_col += incr; |
7 | 508 } |
1839 | 509 |
510 block_space_width = non_white_col - oap->start_vcol; | |
511 /* We will shift by "total" or "block_space_width", whichever is less. | |
512 */ | |
1860 | 513 shift_amount = (block_space_width < (size_t)total |
514 ? block_space_width : (size_t)total); | |
1839 | 515 |
516 /* The column to which we will shift the text. */ | |
1860 | 517 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 518 |
519 /* Now let's find out how much of the beginning of the line we can | |
520 * reuse without modification. */ | |
521 verbatim_copy_end = bd.textstart; | |
522 verbatim_copy_width = bd.start_vcol; | |
523 | |
524 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
525 * preceding the block. We have to subtract its width to obtain its | |
526 * column number. */ | |
527 if (bd.startspaces) | |
528 verbatim_copy_width -= bd.start_char_vcols; | |
529 while (verbatim_copy_width < destination_col) | |
7 | 530 { |
5995 | 531 char_u *line = verbatim_copy_end; |
532 | |
533 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
534 incr = lbr_chartabsize(line, verbatim_copy_end, | |
535 verbatim_copy_width); | |
1839 | 536 if (verbatim_copy_width + incr > destination_col) |
537 break; | |
538 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
|
539 MB_PTR_ADV(verbatim_copy_end); |
7 | 540 } |
541 | |
1839 | 542 /* If "destination_col" is different from the width of the initial |
543 * part of the line that will be copied, it means we encountered a tab | |
544 * character, which we will have to partly replace with spaces. */ | |
545 fill = destination_col - verbatim_copy_width; | |
546 | |
547 /* The replacement line will consist of: | |
548 * - the beginning of the original line up to "verbatim_copy_end", | |
549 * - "fill" number of spaces, | |
550 * - the rest of the line, pointed to by non_white. */ | |
551 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
552 + fill | |
553 + (unsigned)STRLEN(non_white) + 1; | |
554 | |
555 newp = alloc_check(new_line_len); | |
7 | 556 if (newp == NULL) |
557 return; | |
1839 | 558 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 559 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 560 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 561 } |
562 /* replace the line */ | |
563 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
564 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
565 State = oldstate; | |
566 curwin->w_cursor.col = oldcol; | |
567 #ifdef FEAT_RIGHTLEFT | |
568 p_ri = old_p_ri; | |
569 #endif | |
570 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
571 |
7 | 572 /* |
573 * Insert string "s" (b_insert ? before : after) block :AKelly | |
574 * Caller must prepare for undo. | |
575 */ | |
576 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
577 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
578 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
579 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
580 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
581 struct block_def *bdp) |
7 | 582 { |
583 int p_ts; | |
584 int count = 0; /* extra spaces to replace a cut TAB */ | |
585 int spaces = 0; /* non-zero if cutting a TAB */ | |
586 colnr_T offset; /* pointer along new line */ | |
587 unsigned s_len; /* STRLEN(s) */ | |
588 char_u *newp, *oldp; /* new, old lines */ | |
589 linenr_T lnum; /* loop var */ | |
590 int oldstate = State; | |
591 | |
592 State = INSERT; /* don't want REPLACE for State */ | |
593 s_len = (unsigned)STRLEN(s); | |
594 | |
595 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
596 { | |
597 block_prep(oap, bdp, lnum, TRUE); | |
598 if (bdp->is_short && b_insert) | |
599 continue; /* OP_INSERT, line ends before block start */ | |
600 | |
601 oldp = ml_get(lnum); | |
602 | |
603 if (b_insert) | |
604 { | |
605 p_ts = bdp->start_char_vcols; | |
606 spaces = bdp->startspaces; | |
607 if (spaces != 0) | |
608 count = p_ts - 1; /* we're cutting a TAB */ | |
609 offset = bdp->textcol; | |
610 } | |
611 else /* append */ | |
612 { | |
613 p_ts = bdp->end_char_vcols; | |
614 if (!bdp->is_short) /* spaces = padding after block */ | |
615 { | |
616 spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); | |
617 if (spaces != 0) | |
618 count = p_ts - 1; /* we're cutting a TAB */ | |
619 offset = bdp->textcol + bdp->textlen - (spaces != 0); | |
620 } | |
621 else /* spaces = padding to block edge */ | |
622 { | |
623 /* if $ used, just append to EOL (ie spaces==0) */ | |
624 if (!bdp->is_MAX) | |
625 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
626 count = spaces; | |
627 offset = bdp->textcol + bdp->textlen; | |
628 } | |
629 } | |
630 | |
6140 | 631 if (has_mbyte && spaces > 0) |
632 { | |
6460 | 633 int off; |
634 | |
6140 | 635 /* Avoid starting halfway a multi-byte character. */ |
636 if (b_insert) | |
637 { | |
6460 | 638 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 639 } |
640 else | |
641 { | |
6460 | 642 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 643 offset += off; |
644 } | |
6460 | 645 spaces -= off; |
646 count -= off; | |
6140 | 647 } |
648 | |
7 | 649 newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); |
650 if (newp == NULL) | |
651 continue; | |
652 | |
653 /* copy up to shifted part */ | |
654 mch_memmove(newp, oldp, (size_t)(offset)); | |
655 oldp += offset; | |
656 | |
657 /* insert pre-padding */ | |
6929 | 658 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 659 |
660 /* copy the new text */ | |
661 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
662 offset += s_len; | |
663 | |
664 if (spaces && !bdp->is_short) | |
665 { | |
666 /* insert post-padding */ | |
6929 | 667 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
7 | 668 /* We're splitting a TAB, don't copy it. */ |
669 oldp++; | |
670 /* We allowed for that TAB, remember this now */ | |
671 count++; | |
672 } | |
673 | |
674 if (spaces > 0) | |
675 offset += count; | |
1622 | 676 STRMOVE(newp + offset, oldp); |
7 | 677 |
678 ml_replace(lnum, newp, FALSE); | |
679 | |
680 if (lnum == oap->end.lnum) | |
681 { | |
682 /* Set "']" mark to the end of the block instead of the end of | |
683 * the insert in the first line. */ | |
684 curbuf->b_op_end.lnum = oap->end.lnum; | |
685 curbuf->b_op_end.col = offset; | |
686 } | |
687 } /* for all lnum */ | |
688 | |
689 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
690 | |
691 State = oldstate; | |
692 } | |
693 | |
694 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
695 /* | |
696 * op_reindent - handle reindenting a block of lines. | |
697 */ | |
698 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
699 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 700 { |
701 long i; | |
702 char_u *l; | |
6971 | 703 int amount; |
7 | 704 linenr_T first_changed = 0; |
705 linenr_T last_changed = 0; | |
706 linenr_T start_lnum = curwin->w_cursor.lnum; | |
707 | |
216 | 708 /* Don't even try when 'modifiable' is off. */ |
709 if (!curbuf->b_p_ma) | |
710 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
711 emsg(_(e_modifiable)); |
216 | 712 return; |
713 } | |
714 | |
7 | 715 for (i = oap->line_count; --i >= 0 && !got_int; ) |
716 { | |
717 /* it's a slow thing to do, so give feedback so there's no worry that | |
718 * the computer's just hung. */ | |
719 | |
720 if (i > 1 | |
721 && (i % 50 == 0 || i == oap->line_count - 1) | |
722 && 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
|
723 smsg(_("%ld lines to indent... "), i); |
7 | 724 |
725 /* | |
726 * Be vi-compatible: For lisp indenting the first line is not | |
727 * indented, unless there is only one line. | |
728 */ | |
729 #ifdef FEAT_LISP | |
730 if (i != oap->line_count - 1 || oap->line_count == 1 | |
731 || how != get_lisp_indent) | |
732 #endif | |
733 { | |
734 l = skipwhite(ml_get_curline()); | |
735 if (*l == NUL) /* empty or blank line */ | |
6971 | 736 amount = 0; |
7 | 737 else |
6971 | 738 amount = how(); /* get the indent for this line */ |
739 | |
740 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 741 { |
742 /* did change the indent, call changed_lines() later */ | |
743 if (first_changed == 0) | |
744 first_changed = curwin->w_cursor.lnum; | |
745 last_changed = curwin->w_cursor.lnum; | |
746 } | |
747 } | |
748 ++curwin->w_cursor.lnum; | |
1550 | 749 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 750 } |
751 | |
752 /* put cursor on first non-blank of indented line */ | |
753 curwin->w_cursor.lnum = start_lnum; | |
754 beginline(BL_SOL | BL_FIX); | |
755 | |
756 /* Mark changed lines so that they will be redrawn. When Visual | |
757 * highlighting was present, need to continue until the last line. When | |
758 * there is no change still need to remove the Visual highlighting. */ | |
759 if (last_changed != 0) | |
760 changed_lines(first_changed, 0, | |
761 oap->is_VIsual ? start_lnum + oap->line_count : | |
762 last_changed + 1, 0L); | |
763 else if (oap->is_VIsual) | |
764 redraw_curbuf_later(INVERTED); | |
765 | |
766 if (oap->line_count > p_report) | |
767 { | |
768 i = oap->line_count - (i + 1); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
769 smsg(NGETTEXT("%ld line indented ", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
770 "%ld lines indented ", i), i); |
7 | 771 } |
772 /* set '[ and '] marks */ | |
773 curbuf->b_op_start = oap->start; | |
774 curbuf->b_op_end = oap->end; | |
775 } | |
776 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
777 | |
778 #if defined(FEAT_EVAL) || defined(PROTO) | |
779 /* | |
780 * Keep the last expression line here, for repeating. | |
781 */ | |
782 static char_u *expr_line = NULL; | |
783 | |
784 /* | |
785 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
786 * Returns '=' when OK, NUL otherwise. | |
787 */ | |
788 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
789 get_expr_register(void) |
7 | 790 { |
791 char_u *new_line; | |
792 | |
793 new_line = getcmdline('=', 0L, 0); | |
794 if (new_line == NULL) | |
795 return NUL; | |
796 if (*new_line == NUL) /* use previous line */ | |
797 vim_free(new_line); | |
798 else | |
799 set_expr_line(new_line); | |
800 return '='; | |
801 } | |
802 | |
803 /* | |
804 * Set the expression for the '=' register. | |
805 * Argument must be an allocated string. | |
806 */ | |
807 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
808 set_expr_line(char_u *new_line) |
7 | 809 { |
810 vim_free(expr_line); | |
811 expr_line = new_line; | |
812 } | |
813 | |
814 /* | |
815 * Get the result of the '=' register expression. | |
816 * Returns a pointer to allocated memory, or NULL for failure. | |
817 */ | |
818 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
819 get_expr_line(void) |
7 | 820 { |
821 char_u *expr_copy; | |
822 char_u *rv; | |
994 | 823 static int nested = 0; |
7 | 824 |
825 if (expr_line == NULL) | |
826 return NULL; | |
827 | |
828 /* Make a copy of the expression, because evaluating it may cause it to be | |
829 * changed. */ | |
830 expr_copy = vim_strsave(expr_line); | |
831 if (expr_copy == NULL) | |
832 return NULL; | |
833 | |
994 | 834 /* When we are invoked recursively limit the evaluation to 10 levels. |
835 * Then return the string as-is. */ | |
836 if (nested >= 10) | |
837 return expr_copy; | |
838 | |
839 ++nested; | |
714 | 840 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 841 --nested; |
7 | 842 vim_free(expr_copy); |
843 return rv; | |
844 } | |
283 | 845 |
846 /* | |
847 * Get the '=' register expression itself, without evaluating it. | |
848 */ | |
849 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
850 get_expr_line_src(void) |
283 | 851 { |
852 if (expr_line == NULL) | |
853 return NULL; | |
854 return vim_strsave(expr_line); | |
855 } | |
7 | 856 #endif /* FEAT_EVAL */ |
857 | |
858 /* | |
859 * Check if 'regname' is a valid name of a yank register. | |
860 * Note: There is no check for 0 (default register), caller should do this | |
861 */ | |
862 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
863 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
864 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
865 int writing) /* if TRUE check for writable registers */ |
7 | 866 { |
867 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
868 || (!writing && vim_strchr((char_u *) | |
869 #ifdef FEAT_EVAL | |
6557 | 870 "/.%:=" |
7 | 871 #else |
6557 | 872 "/.%:" |
7 | 873 #endif |
874 , regname) != NULL) | |
6557 | 875 || regname == '#' |
7 | 876 || regname == '"' |
877 || regname == '-' | |
878 || regname == '_' | |
879 #ifdef FEAT_CLIPBOARD | |
880 || regname == '*' | |
881 || regname == '+' | |
882 #endif | |
883 #ifdef FEAT_DND | |
884 || (!writing && regname == '~') | |
885 #endif | |
886 ) | |
887 return TRUE; | |
888 return FALSE; | |
889 } | |
890 | |
891 /* | |
892 * Set y_current and y_append, according to the value of "regname". | |
893 * Cannot handle the '_' register. | |
140 | 894 * Must only be called with a valid register name! |
7 | 895 * |
896 * If regname is 0 and writing, use register 0 | |
897 * If regname is 0 and reading, use previous register | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
898 * |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
899 * Return TRUE when the register should be inserted literally (selection or |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
900 * clipboard). |
7 | 901 */ |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
902 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
903 get_yank_register(int regname, int writing) |
7 | 904 { |
905 int i; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
906 int ret = FALSE; |
7 | 907 |
908 y_append = FALSE; | |
909 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
910 { | |
911 y_current = y_previous; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
912 return ret; |
7 | 913 } |
914 i = regname; | |
915 if (VIM_ISDIGIT(i)) | |
916 i -= '0'; | |
917 else if (ASCII_ISLOWER(i)) | |
918 i = CharOrdLow(i) + 10; | |
919 else if (ASCII_ISUPPER(i)) | |
920 { | |
921 i = CharOrdUp(i) + 10; | |
922 y_append = TRUE; | |
923 } | |
924 else if (regname == '-') | |
925 i = DELETION_REGISTER; | |
926 #ifdef FEAT_CLIPBOARD | |
927 /* When selection is not available, use register 0 instead of '*' */ | |
928 else if (clip_star.available && regname == '*') | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
929 { |
7 | 930 i = STAR_REGISTER; |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
931 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
932 } |
7 | 933 /* When clipboard is not available, use register 0 instead of '+' */ |
934 else if (clip_plus.available && regname == '+') | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
935 { |
7 | 936 i = PLUS_REGISTER; |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
937 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
938 } |
7 | 939 #endif |
940 #ifdef FEAT_DND | |
941 else if (!writing && regname == '~') | |
942 i = TILDE_REGISTER; | |
943 #endif | |
944 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
945 i = 0; | |
946 y_current = &(y_regs[i]); | |
947 if (writing) /* remember the register we write into for do_put() */ | |
948 y_previous = y_current; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
949 return ret; |
7 | 950 } |
951 | |
15 | 952 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 953 /* |
954 * When "regname" is a clipboard register, obtain the selection. If it's not | |
955 * available return zero, otherwise return "regname". | |
956 */ | |
15 | 957 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
958 may_get_selection(int regname) |
7 | 959 { |
960 if (regname == '*') | |
961 { | |
962 if (!clip_star.available) | |
963 regname = 0; | |
964 else | |
965 clip_get_selection(&clip_star); | |
966 } | |
967 else if (regname == '+') | |
968 { | |
969 if (!clip_plus.available) | |
970 regname = 0; | |
971 else | |
972 clip_get_selection(&clip_plus); | |
973 } | |
974 return regname; | |
975 } | |
976 #endif | |
977 | |
978 /* | |
979 * Obtain the contents of a "normal" register. The register is made empty. | |
980 * The returned pointer has allocated memory, use put_register() later. | |
981 */ | |
982 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
983 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
984 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
985 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 986 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
987 yankreg_T *reg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
988 int i; |
7 | 989 |
990 #ifdef FEAT_CLIPBOARD | |
991 /* When Visual area changed, may have to update selection. Obtain the | |
992 * selection too. */ | |
1435 | 993 if (name == '*' && clip_star.available) |
7 | 994 { |
3674 | 995 if (clip_isautosel_star()) |
996 clip_update_selection(&clip_star); | |
997 may_get_selection(name); | |
998 } | |
999 if (name == '+' && clip_plus.available) | |
1000 { | |
1001 if (clip_isautosel_plus()) | |
1002 clip_update_selection(&clip_plus); | |
7 | 1003 may_get_selection(name); |
1004 } | |
1005 #endif | |
1006 | |
1007 get_yank_register(name, 0); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1008 reg = (yankreg_T *)alloc((unsigned)sizeof(yankreg_T)); |
7 | 1009 if (reg != NULL) |
1010 { | |
1011 *reg = *y_current; | |
1012 if (copy) | |
1013 { | |
1014 /* If we run out of memory some or all of the lines are empty. */ | |
1015 if (reg->y_size == 0) | |
1016 reg->y_array = NULL; | |
1017 else | |
1018 reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) | |
1019 * reg->y_size)); | |
1020 if (reg->y_array != NULL) | |
1021 { | |
1022 for (i = 0; i < reg->y_size; ++i) | |
1023 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
1024 } | |
1025 } | |
1026 else | |
1027 y_current->y_array = NULL; | |
1028 } | |
1029 return (void *)reg; | |
1030 } | |
1031 | |
1032 /* | |
1451 | 1033 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1034 */ |
1035 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1036 put_register(int name, void *reg) |
7 | 1037 { |
1038 get_yank_register(name, 0); | |
1039 free_yank_all(); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1040 *y_current = *(yankreg_T *)reg; |
1451 | 1041 vim_free(reg); |
7 | 1042 |
5735 | 1043 #ifdef FEAT_CLIPBOARD |
7 | 1044 /* Send text written to clipboard register to the clipboard. */ |
1045 may_set_selection(); | |
5735 | 1046 #endif |
7 | 1047 } |
4209 | 1048 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1049 #if (defined(FEAT_CLIPBOARD) && defined(FEAT_X11) && defined(USE_SYSTEM)) \ |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1050 || defined(PROTO) |
4209 | 1051 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1052 free_register(void *reg) |
4209 | 1053 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1054 yankreg_T tmp; |
4209 | 1055 |
1056 tmp = *y_current; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1057 *y_current = *(yankreg_T *)reg; |
4209 | 1058 free_yank_all(); |
1059 vim_free(reg); | |
1060 *y_current = tmp; | |
1061 } | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1062 #endif |
7 | 1063 |
1064 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1065 /* | |
1066 * return TRUE if the current yank register has type MLINE | |
1067 */ | |
1068 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1069 yank_register_mline(int regname) |
7 | 1070 { |
1071 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1072 return FALSE; | |
1073 if (regname == '_') /* black hole is always empty */ | |
1074 return FALSE; | |
1075 get_yank_register(regname, FALSE); | |
1076 return (y_current->y_type == MLINE); | |
1077 } | |
1078 #endif | |
1079 | |
1080 /* | |
1157 | 1081 * Start or stop recording into a yank register. |
7 | 1082 * |
1157 | 1083 * Return FAIL for failure, OK otherwise. |
7 | 1084 */ |
1085 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1086 do_record(int c) |
7 | 1087 { |
1157 | 1088 char_u *p; |
1089 static int regname; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1090 yankreg_T *old_y_previous, *old_y_current; |
1157 | 1091 int retval; |
7 | 1092 |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1093 if (reg_recording == 0) /* start recording */ |
7 | 1094 { |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1095 /* registers 0-9, a-z and " are allowed */ |
7 | 1096 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) |
1097 retval = FAIL; | |
1098 else | |
1099 { | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1100 reg_recording = c; |
7 | 1101 showmode(); |
1102 regname = c; | |
1103 retval = OK; | |
1104 } | |
1105 } | |
1106 else /* stop recording */ | |
1107 { | |
1108 /* | |
1157 | 1109 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1110 * needs to be removed again to put it in a register. exec_reg then | |
1111 * adds the escaping back later. | |
7 | 1112 */ |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1113 reg_recording = 0; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1114 msg(""); |
7 | 1115 p = get_recorded(); |
1116 if (p == NULL) | |
1117 retval = FAIL; | |
1118 else | |
1119 { | |
1081 | 1120 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1121 vim_unescape_csi(p); | |
1122 | |
7 | 1123 /* |
1124 * We don't want to change the default register here, so save and | |
1125 * restore the current register name. | |
1126 */ | |
1127 old_y_previous = y_previous; | |
1128 old_y_current = y_current; | |
1129 | |
1130 retval = stuff_yank(regname, p); | |
1131 | |
1132 y_previous = old_y_previous; | |
1133 y_current = old_y_current; | |
1134 } | |
1135 } | |
1136 return retval; | |
1137 } | |
1138 | |
1139 /* | |
1140 * Stuff string "p" into yank register "regname" as a single line (append if | |
1141 * uppercase). "p" must have been alloced. | |
1142 * | |
1143 * return FAIL for failure, OK otherwise | |
1144 */ | |
1145 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1146 stuff_yank(int regname, char_u *p) |
7 | 1147 { |
1148 char_u *lp; | |
1149 char_u **pp; | |
1150 | |
1151 /* check for read-only register */ | |
1152 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1153 { | |
1154 vim_free(p); | |
1155 return FAIL; | |
1156 } | |
1157 if (regname == '_') /* black hole: don't do anything */ | |
1158 { | |
1159 vim_free(p); | |
1160 return OK; | |
1161 } | |
1162 get_yank_register(regname, TRUE); | |
1163 if (y_append && y_current->y_array != NULL) | |
1164 { | |
1165 pp = &(y_current->y_array[y_current->y_size - 1]); | |
1166 lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); | |
1167 if (lp == NULL) | |
1168 { | |
1169 vim_free(p); | |
1170 return FAIL; | |
1171 } | |
1172 STRCPY(lp, *pp); | |
1173 STRCAT(lp, p); | |
1174 vim_free(p); | |
1175 vim_free(*pp); | |
1176 *pp = lp; | |
1177 } | |
1178 else | |
1179 { | |
1180 free_yank_all(); | |
1181 if ((y_current->y_array = | |
1182 (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) | |
1183 { | |
1184 vim_free(p); | |
1185 return FAIL; | |
1186 } | |
1187 y_current->y_array[0] = p; | |
1188 y_current->y_size = 1; | |
1189 y_current->y_type = MCHAR; /* used to be MLINE, why? */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1190 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1191 y_current->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1192 #endif |
7 | 1193 } |
1194 return OK; | |
1195 } | |
1196 | |
1893 | 1197 static int execreg_lastc = NUL; |
1198 | |
7 | 1199 /* |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1200 * Execute a yank register: copy it into the stuff buffer. |
7 | 1201 * |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1202 * Return FAIL for failure, OK otherwise. |
7 | 1203 */ |
1204 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1205 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1206 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1207 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1208 int addcr, /* always add '\n' to end of line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1209 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1210 { |
1211 long i; | |
1212 char_u *p; | |
1213 int retval = OK; | |
1214 int remap; | |
1215 | |
1216 if (regname == '@') /* repeat previous one */ | |
168 | 1217 { |
1893 | 1218 if (execreg_lastc == NUL) |
168 | 1219 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1220 emsg(_("E748: No previously used register")); |
168 | 1221 return FAIL; |
1222 } | |
1893 | 1223 regname = execreg_lastc; |
168 | 1224 } |
7 | 1225 /* check for valid regname */ |
1226 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) | |
168 | 1227 { |
1228 emsg_invreg(regname); | |
7 | 1229 return FAIL; |
168 | 1230 } |
1893 | 1231 execreg_lastc = regname; |
7 | 1232 |
1233 #ifdef FEAT_CLIPBOARD | |
1234 regname = may_get_selection(regname); | |
1235 #endif | |
1236 | |
1237 if (regname == '_') /* black hole: don't stuff anything */ | |
1238 return OK; | |
1239 | |
1240 #ifdef FEAT_CMDHIST | |
1241 if (regname == ':') /* use last command line */ | |
1242 { | |
1243 if (last_cmdline == NULL) | |
1244 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1245 emsg(_(e_nolastcmd)); |
7 | 1246 return FAIL; |
1247 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1248 VIM_CLEAR(new_last_cmdline); /* don't keep the cmdline containing @: */ |
16 | 1249 /* Escape all control characters with a CTRL-V */ |
1250 p = vim_strsave_escaped_ext(last_cmdline, | |
20 | 1251 (char_u *)"\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", Ctrl_V, FALSE); |
16 | 1252 if (p != NULL) |
480 | 1253 { |
1254 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1255 * Remove it when it's already there. */ | |
1256 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1257 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1258 else |
1077 | 1259 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1260 } |
16 | 1261 vim_free(p); |
7 | 1262 } |
1263 #endif | |
1264 #ifdef FEAT_EVAL | |
1265 else if (regname == '=') | |
1266 { | |
1267 p = get_expr_line(); | |
1268 if (p == NULL) | |
1269 return FAIL; | |
1077 | 1270 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1271 vim_free(p); |
1272 } | |
1273 #endif | |
1274 else if (regname == '.') /* use last inserted text */ | |
1275 { | |
1276 p = get_last_insert_save(); | |
1277 if (p == NULL) | |
1278 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1279 emsg(_(e_noinstext)); |
7 | 1280 return FAIL; |
1281 } | |
1077 | 1282 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1283 vim_free(p); |
1284 } | |
1285 else | |
1286 { | |
1287 get_yank_register(regname, FALSE); | |
1288 if (y_current->y_array == NULL) | |
1289 return FAIL; | |
1290 | |
1291 /* Disallow remaping for ":@r". */ | |
1292 remap = colon ? REMAP_NONE : REMAP_YES; | |
1293 | |
1294 /* | |
1295 * Insert lines into typeahead buffer, from last one to first one. | |
1296 */ | |
1034 | 1297 put_reedit_in_typebuf(silent); |
7 | 1298 for (i = y_current->y_size; --i >= 0; ) |
1299 { | |
1077 | 1300 char_u *escaped; |
1301 | |
7 | 1302 /* insert NL between lines and after last line if type is MLINE */ |
1303 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1304 || addcr) | |
1305 { | |
1034 | 1306 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1307 return FAIL; |
1308 } | |
1077 | 1309 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1310 if (escaped == NULL) | |
1311 return FAIL; | |
1312 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1313 vim_free(escaped); | |
1314 if (retval == FAIL) | |
7 | 1315 return FAIL; |
1034 | 1316 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1317 == FAIL) |
1318 return FAIL; | |
1319 } | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1320 reg_executing = regname == 0 ? '"' : regname; // disable "q" command |
7 | 1321 } |
1322 return retval; | |
1323 } | |
1324 | |
1325 /* | |
1326 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1327 * used only after other typeahead has been processed. | |
1328 */ | |
1329 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1330 put_reedit_in_typebuf(int silent) |
7 | 1331 { |
1332 char_u buf[3]; | |
1333 | |
1334 if (restart_edit != NUL) | |
1335 { | |
1336 if (restart_edit == 'V') | |
1337 { | |
1338 buf[0] = 'g'; | |
1339 buf[1] = 'R'; | |
1340 buf[2] = NUL; | |
1341 } | |
1342 else | |
1343 { | |
1344 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1345 buf[1] = NUL; | |
1346 } | |
1034 | 1347 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1348 restart_edit = NUL; |
1349 } | |
1350 } | |
1351 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1352 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1353 * Insert register contents "s" into the typeahead buffer, so that it will be |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1354 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1355 * When "esc" is TRUE it is to be taken literally: Escape CSI characters and |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1356 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1357 */ |
7 | 1358 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1359 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1360 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1361 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1362 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1363 int silent) |
7 | 1364 { |
1365 int retval = OK; | |
1366 | |
1034 | 1367 put_reedit_in_typebuf(silent); |
7 | 1368 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1369 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1370 if (retval == OK) |
1077 | 1371 { |
1372 char_u *p; | |
1373 | |
1374 if (esc) | |
1375 p = vim_strsave_escape_csi(s); | |
1376 else | |
1377 p = s; | |
1378 if (p == NULL) | |
1379 retval = FAIL; | |
1380 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1381 retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1382 0, TRUE, silent); |
1077 | 1383 if (esc) |
1384 vim_free(p); | |
1385 } | |
7 | 1386 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1387 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1388 return retval; |
1389 } | |
1390 | |
1391 /* | |
1392 * Insert a yank register: copy it into the Read buffer. | |
1393 * Used by CTRL-R command and middle mouse button in insert mode. | |
1394 * | |
1395 * return FAIL for failure, OK otherwise | |
1396 */ | |
1397 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1398 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1399 int regname, |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1400 int literally_arg) /* insert literally, not as if typed */ |
7 | 1401 { |
1402 long i; | |
1403 int retval = OK; | |
1404 char_u *arg; | |
1405 int allocated; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1406 int literally = literally_arg; |
7 | 1407 |
1408 /* | |
1409 * It is possible to get into an endless loop by having CTRL-R a in | |
1410 * register a and then, in insert mode, doing CTRL-R a. | |
1411 * If you hit CTRL-C, the loop will be broken here. | |
1412 */ | |
1413 ui_breakcheck(); | |
1414 if (got_int) | |
1415 return FAIL; | |
1416 | |
1417 /* check for valid regname */ | |
1418 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1419 return FAIL; | |
1420 | |
1421 #ifdef FEAT_CLIPBOARD | |
1422 regname = may_get_selection(regname); | |
1423 #endif | |
1424 | |
1425 if (regname == '.') /* insert last inserted text */ | |
1426 retval = stuff_inserted(NUL, 1L, TRUE); | |
1427 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1428 { | |
1429 if (arg == NULL) | |
1430 return FAIL; | |
1431 stuffescaped(arg, literally); | |
1432 if (allocated) | |
1433 vim_free(arg); | |
1434 } | |
1435 else /* name or number register */ | |
1436 { | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1437 if (get_yank_register(regname, FALSE)) |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1438 literally = TRUE; |
7 | 1439 if (y_current->y_array == NULL) |
1440 retval = FAIL; | |
1441 else | |
1442 { | |
1443 for (i = 0; i < y_current->y_size; ++i) | |
1444 { | |
1445 stuffescaped(y_current->y_array[i], literally); | |
1446 /* | |
1447 * Insert a newline between lines and after last line if | |
1448 * y_type is MLINE. | |
1449 */ | |
1450 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1451 stuffcharReadbuff('\n'); | |
1452 } | |
1453 } | |
1454 } | |
1455 | |
1456 return retval; | |
1457 } | |
1458 | |
1459 /* | |
1460 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1461 * literally ("literally" TRUE) or interpret is as typed characters. | |
1462 */ | |
1463 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1464 stuffescaped(char_u *arg, int literally) |
7 | 1465 { |
1466 int c; | |
1467 char_u *start; | |
1468 | |
1469 while (*arg != NUL) | |
1470 { | |
1471 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1472 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1473 * is TRUE. */ | |
1474 start = arg; | |
1475 while ((*arg >= ' ' | |
1476 #ifndef EBCDIC | |
1477 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1478 #endif | |
1479 ) | |
1480 || (*arg == K_SPECIAL && !literally)) | |
1481 ++arg; | |
1482 if (arg > start) | |
1483 stuffReadbuffLen(start, (long)(arg - start)); | |
1484 | |
1485 /* stuff a single special character */ | |
1486 if (*arg != NUL) | |
1487 { | |
1488 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
|
1489 c = mb_cptr2char_adv(&arg); |
7 | 1490 else |
1491 c = *arg++; | |
1492 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1493 stuffcharReadbuff(Ctrl_V); | |
1494 stuffcharReadbuff(c); | |
1495 } | |
1496 } | |
1497 } | |
1498 | |
1499 /* | |
1157 | 1500 * If "regname" is a special register, return TRUE and store a pointer to its |
1501 * value in "argp". | |
7 | 1502 */ |
15 | 1503 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1504 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1505 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1506 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1507 int *allocated, /* return: TRUE when value was allocated */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1508 int errmsg) /* give error message when failing */ |
7 | 1509 { |
1510 int cnt; | |
1511 | |
1512 *argp = NULL; | |
1513 *allocated = FALSE; | |
1514 switch (regname) | |
1515 { | |
1516 case '%': /* file name */ | |
1517 if (errmsg) | |
1518 check_fname(); /* will give emsg if not set */ | |
1519 *argp = curbuf->b_fname; | |
1520 return TRUE; | |
1521 | |
1522 case '#': /* alternate file name */ | |
1523 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1524 return TRUE; | |
1525 | |
1526 #ifdef FEAT_EVAL | |
1527 case '=': /* result of expression */ | |
1528 *argp = get_expr_line(); | |
1529 *allocated = TRUE; | |
1530 return TRUE; | |
1531 #endif | |
1532 | |
1533 case ':': /* last command line */ | |
1534 if (last_cmdline == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1535 emsg(_(e_nolastcmd)); |
7 | 1536 *argp = last_cmdline; |
1537 return TRUE; | |
1538 | |
1539 case '/': /* last search-pattern */ | |
1540 if (last_search_pat() == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1541 emsg(_(e_noprevre)); |
7 | 1542 *argp = last_search_pat(); |
1543 return TRUE; | |
1544 | |
1545 case '.': /* last inserted text */ | |
1546 *argp = get_last_insert_save(); | |
1547 *allocated = TRUE; | |
1548 if (*argp == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1549 emsg(_(e_noinstext)); |
7 | 1550 return TRUE; |
1551 | |
1552 #ifdef FEAT_SEARCHPATH | |
1553 case Ctrl_F: /* Filename under cursor */ | |
1554 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1555 if (!errmsg) | |
1556 return FALSE; | |
1557 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1558 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1559 *allocated = TRUE; |
1560 return TRUE; | |
1561 #endif | |
1562 | |
1563 case Ctrl_W: /* word under cursor */ | |
1564 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1565 if (!errmsg) | |
1566 return FALSE; | |
1567 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1568 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1569 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1570 *allocated = TRUE; | |
1571 return TRUE; | |
1572 | |
13831
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1573 case Ctrl_L: /* Line under cursor */ |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1574 if (!errmsg) |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1575 return FALSE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1576 |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1577 *argp = ml_get_buf(curwin->w_buffer, |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1578 curwin->w_cursor.lnum, FALSE); |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1579 return TRUE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1580 |
7 | 1581 case '_': /* black hole: always empty */ |
1582 *argp = (char_u *)""; | |
1583 return TRUE; | |
1584 } | |
1585 | |
1586 return FALSE; | |
1587 } | |
1588 | |
1589 /* | |
15 | 1590 * Paste a yank register into the command line. |
1591 * Only for non-special registers. | |
1592 * Used by CTRL-R command in command-line mode | |
7 | 1593 * insert_reg() can't be used here, because special characters from the |
1594 * register contents will be interpreted as commands. | |
1595 * | |
1596 * return FAIL for failure, OK otherwise | |
1597 */ | |
1598 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1599 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1600 int regname, |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1601 int literally_arg, /* Insert text literally instead of "as typed" */ |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1602 int remcr) /* don't add CR characters */ |
7 | 1603 { |
1604 long i; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1605 int literally = literally_arg; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1606 |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1607 if (get_yank_register(regname, FALSE)) |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1608 literally = TRUE; |
7 | 1609 if (y_current->y_array == NULL) |
1610 return FAIL; | |
1611 | |
1612 for (i = 0; i < y_current->y_size; ++i) | |
1613 { | |
1614 cmdline_paste_str(y_current->y_array[i], literally); | |
1615 | |
1015 | 1616 /* Insert ^M between lines and after last line if type is MLINE. |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
1617 * Don't do this when "remcr" is TRUE. */ |
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
1618 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1619 cmdline_paste_str((char_u *)"\r", literally); |
1620 | |
1621 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1622 * lines and gets bored. */ | |
1623 ui_breakcheck(); | |
1624 if (got_int) | |
1625 return FAIL; | |
1626 } | |
1627 return OK; | |
1628 } | |
1629 | |
1630 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1631 /* | |
1632 * Adjust the register name pointed to with "rp" for the clipboard being | |
1633 * used always and the clipboard being available. | |
1634 */ | |
1635 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1636 adjust_clip_reg(int *rp) |
7 | 1637 { |
2654 | 1638 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1639 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1640 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1641 { | |
1642 if (clip_unnamed != 0) | |
1643 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1644 ? '+' : '*'; |
6116 | 1645 else |
1646 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1647 ? '+' : '*'; | |
1648 } | |
7 | 1649 if (!clip_star.available && *rp == '*') |
1650 *rp = 0; | |
1651 if (!clip_plus.available && *rp == '+') | |
1652 *rp = 0; | |
1653 } | |
1654 #endif | |
1655 | |
1656 /* | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1657 * Shift the delete registers: "9 is cleared, "8 becomes "9, etc. |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1658 */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1659 void |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1660 shift_delete_registers() |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1661 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1662 int n; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1663 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1664 y_current = &y_regs[9]; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1665 free_yank_all(); /* free register nine */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1666 for (n = 9; n > 1; --n) |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1667 y_regs[n] = y_regs[n - 1]; |
11597
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1668 y_current = &y_regs[1]; |
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1669 if (!y_append) |
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1670 y_previous = y_current; |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1671 y_regs[1].y_array = NULL; /* set register one to empty */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1672 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1673 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1674 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1675 static void |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1676 yank_do_autocmd(oparg_T *oap, yankreg_T *reg) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1677 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1678 static int recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1679 dict_T *v_event; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1680 list_T *list; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1681 int n; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1682 char_u buf[NUMBUFLEN + 2]; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1683 long reglen = 0; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1684 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1685 if (recursive) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1686 return; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1687 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1688 v_event = get_vim_var_dict(VV_EVENT); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1689 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1690 list = list_alloc(); |
13254
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1691 if (list == NULL) |
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1692 return; |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1693 for (n = 0; n < reg->y_size; n++) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1694 list_append_string(list, reg->y_array[n], -1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1695 list->lv_lock = VAR_FIXED; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1696 dict_add_list(v_event, "regcontents", list); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1697 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1698 buf[0] = (char_u)oap->regname; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1699 buf[1] = NUL; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1700 dict_add_string(v_event, "regname", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1701 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1702 buf[0] = get_op_char(oap->op_type); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1703 buf[1] = get_extra_op_char(oap->op_type); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1704 buf[2] = NUL; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1705 dict_add_string(v_event, "operator", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1706 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1707 buf[0] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1708 buf[1] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1709 switch (get_reg_type(oap->regname, ®len)) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1710 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1711 case MLINE: buf[0] = 'V'; break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1712 case MCHAR: buf[0] = 'v'; break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1713 case MBLOCK: |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1714 vim_snprintf((char *)buf, sizeof(buf), "%c%ld", Ctrl_V, |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1715 reglen + 1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1716 break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1717 } |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1718 dict_add_string(v_event, "regtype", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1719 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1720 /* Lock the dictionary and its keys */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1721 dict_set_items_ro(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1722 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1723 recursive = TRUE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1724 textlock++; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1725 apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1726 textlock--; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1727 recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1728 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1729 /* Empty the dictionary, v:event is still valid */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1730 dict_free_contents(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1731 hash_init(&v_event->dv_hashtab); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1732 } |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
1733 #endif |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1734 |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1735 /* |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1736 * Handle a delete operation. |
7 | 1737 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1738 * Return FAIL if undo failed, OK otherwise. |
7 | 1739 */ |
1740 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1741 op_delete(oparg_T *oap) |
7 | 1742 { |
1743 int n; | |
1744 linenr_T lnum; | |
1745 char_u *ptr; | |
1746 char_u *newp, *oldp; | |
1747 struct block_def bd; | |
1748 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1749 int did_yank = FALSE; | |
3782 | 1750 int orig_regname = oap->regname; |
7 | 1751 |
1752 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1753 return OK; | |
1754 | |
1755 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1756 if (oap->empty) | |
1757 return u_save_cursor(); | |
1758 | |
1759 if (!curbuf->b_p_ma) | |
1760 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1761 emsg(_(e_modifiable)); |
7 | 1762 return FAIL; |
1763 } | |
1764 | |
1765 #ifdef FEAT_CLIPBOARD | |
1766 adjust_clip_reg(&oap->regname); | |
1767 #endif | |
1768 | |
1769 if (has_mbyte) | |
1770 mb_adjust_opend(oap); | |
1771 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1772 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1773 * 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
|
1774 * 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
|
1775 * 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
|
1776 */ |
7 | 1777 if ( oap->motion_type == MCHAR |
1778 && !oap->is_VIsual | |
50 | 1779 && !oap->block_mode |
7 | 1780 && oap->line_count > 1 |
3254 | 1781 && oap->motion_force == NUL |
7 | 1782 && oap->op_type == OP_DELETE) |
1783 { | |
2957 | 1784 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1785 if (*ptr != NUL) | |
1786 ptr += oap->inclusive; | |
7 | 1787 ptr = skipwhite(ptr); |
1788 if (*ptr == NUL && inindent(0)) | |
1789 oap->motion_type = MLINE; | |
1790 } | |
1791 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1792 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1793 * 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
|
1794 * 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
|
1795 */ |
7 | 1796 if ( oap->motion_type == MCHAR |
1797 && oap->line_count == 1 | |
1798 && oap->op_type == OP_DELETE | |
1799 && *ml_get(oap->start.lnum) == NUL) | |
1800 { | |
1801 /* | |
446 | 1802 * It's an error to operate on an empty region, when 'E' included in |
7 | 1803 * 'cpoptions' (Vi compatible). |
1804 */ | |
446 | 1805 if (virtual_op) |
1806 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1807 * marks as if it happened. */ | |
1808 goto setmarks; | |
7 | 1809 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1810 beep_flush(); | |
1811 return OK; | |
1812 } | |
1813 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1814 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1815 * 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
|
1816 * 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
|
1817 * 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
|
1818 */ |
7 | 1819 if (oap->regname != '_') |
1820 { | |
1821 if (oap->regname != 0) | |
1822 { | |
1823 /* check for read-only register */ | |
1824 if (!valid_yank_reg(oap->regname, TRUE)) | |
1825 { | |
1826 beep_flush(); | |
1827 return OK; | |
1828 } | |
1829 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1830 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1831 did_yank = TRUE; | |
1832 } | |
1833 | |
1834 /* | |
1835 * Put deleted text into register 1 and shift number registers if the | |
1836 * delete contains a line break, or when a regname has been specified. | |
3782 | 1837 * Use the register name from before adjust_clip_reg() may have |
1838 * changed it. | |
7 | 1839 */ |
3782 | 1840 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1841 || oap->line_count > 1 || oap->use_reg_one) |
1842 { | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1843 shift_delete_registers(); |
7 | 1844 if (op_yank(oap, TRUE, FALSE) == OK) |
1845 did_yank = TRUE; | |
1846 } | |
1847 | |
3468 | 1848 /* Yank into small delete register when no named register specified |
1849 * and the delete is within one line. */ | |
1850 if (( | |
1851 #ifdef FEAT_CLIPBOARD | |
3584 | 1852 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1853 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1854 #endif |
1855 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1856 && oap->line_count == 1) |
1857 { | |
1858 oap->regname = '-'; | |
1859 get_yank_register(oap->regname, TRUE); | |
1860 if (op_yank(oap, TRUE, FALSE) == OK) | |
1861 did_yank = TRUE; | |
1862 oap->regname = 0; | |
1863 } | |
1864 | |
1865 /* | |
1866 * If there's too much stuff to fit in the yank register, then get a | |
1867 * confirmation before doing the delete. This is crude, but simple. | |
1868 * And it avoids doing a delete of something we can't put back if we | |
1869 * want. | |
1870 */ | |
1871 if (!did_yank) | |
1872 { | |
1873 int msg_silent_save = msg_silent; | |
1874 | |
1875 msg_silent = 0; /* must display the prompt */ | |
1876 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1877 msg_silent = msg_silent_save; | |
1878 if (n != 'y') | |
1879 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1880 emsg(_(e_abort)); |
7 | 1881 return FAIL; |
1882 } | |
1883 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1884 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1885 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1886 if (did_yank && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1887 yank_do_autocmd(oap, y_current); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1888 #endif |
7 | 1889 } |
1890 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1891 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1892 * 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
|
1893 */ |
7 | 1894 if (oap->block_mode) |
1895 { | |
1896 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1897 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1898 return FAIL; | |
1899 | |
1900 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1901 { | |
1902 block_prep(oap, &bd, lnum, TRUE); | |
1903 if (bd.textlen == 0) /* nothing to delete */ | |
1904 continue; | |
1905 | |
1906 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1907 if (lnum == curwin->w_cursor.lnum) | |
1908 { | |
1909 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1910 curwin->w_cursor.coladd = 0; | |
1911 } | |
1912 | |
1913 /* n == number of chars deleted | |
1914 * If we delete a TAB, it may be replaced by several characters. | |
1915 * Thus the number of characters may increase! | |
1916 */ | |
1917 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1918 oldp = ml_get(lnum); | |
1919 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1920 if (newp == NULL) | |
1921 continue; | |
1922 /* copy up to deleted part */ | |
1923 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1924 /* insert spaces */ | |
6929 | 1925 vim_memset(newp + bd.textcol, ' ', |
7 | 1926 (size_t)(bd.startspaces + bd.endspaces)); |
1927 /* copy the part after the deleted part */ | |
1928 oldp += bd.textcol + bd.textlen; | |
1622 | 1929 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1930 /* replace the line */ |
1931 ml_replace(lnum, newp, FALSE); | |
1932 } | |
1933 | |
1934 check_cursor_col(); | |
1935 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1936 oap->end.lnum + 1, 0L); | |
1937 oap->line_count = 0; /* no lines deleted */ | |
1938 } | |
5735 | 1939 else if (oap->motion_type == MLINE) |
7 | 1940 { |
1941 if (oap->op_type == OP_CHANGE) | |
1942 { | |
1943 /* Delete the lines except the first one. Temporarily move the | |
1944 * cursor to the next line. Save the current line number, if the | |
1945 * last line is deleted it may be changed. | |
1946 */ | |
1947 if (oap->line_count > 1) | |
1948 { | |
1949 lnum = curwin->w_cursor.lnum; | |
1950 ++curwin->w_cursor.lnum; | |
1951 del_lines((long)(oap->line_count - 1), TRUE); | |
1952 curwin->w_cursor.lnum = lnum; | |
1953 } | |
1954 if (u_save_cursor() == FAIL) | |
1955 return FAIL; | |
1956 if (curbuf->b_p_ai) /* don't delete indent */ | |
1957 { | |
1958 beginline(BL_WHITE); /* cursor on first non-white */ | |
1959 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1960 ai_col = curwin->w_cursor.col; | |
1961 } | |
1962 else | |
1963 beginline(0); /* cursor in column 0 */ | |
1964 truncate_line(FALSE); /* delete the rest of the line */ | |
1965 /* leave cursor past last char in line */ | |
1966 if (oap->line_count > 1) | |
1967 u_clearline(); /* "U" command not possible after "2cc" */ | |
1968 } | |
1969 else | |
1970 { | |
1971 del_lines(oap->line_count, TRUE); | |
1972 beginline(BL_WHITE | BL_FIX); | |
1973 u_clearline(); /* "U" command not possible after "dd" */ | |
1974 } | |
1975 } | |
1976 else | |
1977 { | |
1978 if (virtual_op) | |
1979 { | |
1980 int endcol = 0; | |
1981 | |
1982 /* For virtualedit: break the tabs that are partly included. */ | |
1983 if (gchar_pos(&oap->start) == '\t') | |
1984 { | |
1985 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
1986 return FAIL; | |
1987 if (oap->line_count == 1) | |
1988 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
1989 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
1990 oap->start = curwin->w_cursor; | |
1991 if (oap->line_count == 1) | |
1992 { | |
1993 coladvance(endcol); | |
1994 oap->end.col = curwin->w_cursor.col; | |
1995 oap->end.coladd = curwin->w_cursor.coladd; | |
1996 curwin->w_cursor = oap->start; | |
1997 } | |
1998 } | |
1999 | |
2000 /* Break a tab only when it's included in the area. */ | |
2001 if (gchar_pos(&oap->end) == '\t' | |
2002 && (int)oap->end.coladd < oap->inclusive) | |
2003 { | |
2004 /* save last line for undo */ | |
2005 if (u_save((linenr_T)(oap->end.lnum - 1), | |
2006 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2007 return FAIL; | |
2008 curwin->w_cursor = oap->end; | |
2009 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
2010 oap->end = curwin->w_cursor; | |
2011 curwin->w_cursor = oap->start; | |
2012 } | |
2013 } | |
2014 | |
2015 if (oap->line_count == 1) /* delete characters within one line */ | |
2016 { | |
2017 if (u_save_cursor() == FAIL) /* save line for undo */ | |
2018 return FAIL; | |
2019 | |
2020 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 2021 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 2022 && oap->op_type == OP_CHANGE |
2023 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 2024 && !oap->is_VIsual) |
7 | 2025 display_dollar(oap->end.col - !oap->inclusive); |
2026 | |
2027 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
2028 | |
2029 if (virtual_op) | |
2030 { | |
2031 /* fix up things for virtualedit-delete: | |
2032 * break the tabs which are going to get in our way | |
2033 */ | |
2034 char_u *curline = ml_get_curline(); | |
2035 int len = (int)STRLEN(curline); | |
2036 | |
2037 if (oap->end.coladd != 0 | |
2038 && (int)oap->end.col >= len - 1 | |
2039 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
2040 n++; | |
2041 /* Delete at least one char (e.g, when on a control char). */ | |
2042 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
2043 n = 1; | |
2044 | |
2045 /* When deleted a char in the line, reset coladd. */ | |
2046 if (gchar_cursor() != NUL) | |
2047 curwin->w_cursor.coladd = 0; | |
2048 } | |
6826 | 2049 (void)del_bytes((long)n, !virtual_op, |
2050 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 2051 } |
2052 else /* delete characters between lines */ | |
2053 { | |
2054 pos_T curpos; | |
2055 | |
2056 /* save deleted and changed lines for undo */ | |
2057 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
2058 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
2059 return FAIL; | |
2060 | |
2061 truncate_line(TRUE); /* delete from cursor to end of line */ | |
2062 | |
2063 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
2064 ++curwin->w_cursor.lnum; | |
2065 del_lines((long)(oap->line_count - 2), FALSE); | |
2066 | |
6826 | 2067 /* delete from start of line until op_end */ |
2957 | 2068 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 2069 curwin->w_cursor.col = 0; |
2070 (void)del_bytes((long)n, !virtual_op, | |
2071 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
2072 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
2073 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 2074 } |
2075 } | |
2076 | |
2077 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
2078 | |
446 | 2079 setmarks: |
7 | 2080 if (oap->block_mode) |
2081 { | |
2082 curbuf->b_op_end.lnum = oap->end.lnum; | |
2083 curbuf->b_op_end.col = oap->start.col; | |
2084 } | |
2085 else | |
2086 curbuf->b_op_end = oap->start; | |
2087 curbuf->b_op_start = oap->start; | |
2088 | |
2089 return OK; | |
2090 } | |
2091 | |
2092 /* | |
2093 * Adjust end of operating area for ending on a multi-byte character. | |
2094 * Used for deletion. | |
2095 */ | |
2096 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2097 mb_adjust_opend(oparg_T *oap) |
7 | 2098 { |
2099 char_u *p; | |
2100 | |
2101 if (oap->inclusive) | |
2102 { | |
2103 p = ml_get(oap->end.lnum); | |
2104 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2105 } | |
2106 } | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2107 |
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
|
2108 /* |
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
|
2109 * 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
|
2110 * 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
|
2111 */ |
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
|
2112 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
|
2113 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
|
2114 { |
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
|
2115 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
|
2116 |
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
|
2117 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
|
2118 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
|
2119 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
|
2120 /* 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
|
2121 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
|
2122 } |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2123 |
7 | 2124 /* |
2125 * Replace a whole area with one character. | |
2126 */ | |
2127 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2128 op_replace(oparg_T *oap, int c) |
7 | 2129 { |
2130 int n, numc; | |
2131 int num_chars; | |
2132 char_u *newp, *oldp; | |
2133 size_t oldlen; | |
2134 struct block_def bd; | |
5428 | 2135 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
|
2136 int had_ctrl_v_cr = FALSE; |
7 | 2137 |
2138 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2139 return OK; /* nothing to do */ | |
2140 | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2141 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
|
2142 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2143 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
|
2144 c = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2145 } |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2146 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
|
2147 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2148 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
|
2149 c = NL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2150 } |
5428 | 2151 |
7 | 2152 if (has_mbyte) |
2153 mb_adjust_opend(oap); | |
2154 | |
2155 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2156 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2157 return FAIL; | |
2158 | |
2159 /* | |
2160 * block mode replace | |
2161 */ | |
2162 if (oap->block_mode) | |
2163 { | |
2164 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2165 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2166 { | |
1982 | 2167 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2168 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2169 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2170 continue; /* nothing to replace */ | |
2171 | |
2172 /* n == number of extra chars required | |
2173 * If we split a TAB, it may be replaced by several characters. | |
2174 * Thus the number of characters may increase! | |
2175 */ | |
2176 /* If the range starts in virtual space, count the initial | |
2177 * coladd offset as part of "startspaces" */ | |
2178 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2179 { | |
2180 pos_T vpos; | |
2181 | |
1982 | 2182 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2183 getvpos(&vpos, oap->start_vcol); |
2184 bd.startspaces += vpos.coladd; | |
2185 n = bd.startspaces; | |
2186 } | |
2187 else | |
2188 /* allow for pre spaces */ | |
2189 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2190 | |
2191 /* allow for post spp */ | |
2192 n += (bd.endspaces | |
2193 && !bd.is_oneChar | |
2194 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2195 /* Figure out how many characters to replace. */ | |
2196 numc = oap->end_vcol - oap->start_vcol + 1; | |
2197 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2198 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2199 | |
2200 /* A double-wide character can be replaced only up to half the | |
2201 * times. */ | |
2202 if ((*mb_char2cells)(c) > 1) | |
2203 { | |
2204 if ((numc & 1) && !bd.is_short) | |
2205 { | |
2206 ++bd.endspaces; | |
2207 ++n; | |
2208 } | |
2209 numc = numc / 2; | |
2210 } | |
2211 | |
2212 /* Compute bytes needed, move character count to num_chars. */ | |
2213 num_chars = numc; | |
2214 numc *= (*mb_char2len)(c); | |
2215 /* oldlen includes textlen, so don't double count */ | |
2216 n += numc - bd.textlen; | |
2217 | |
2218 oldp = ml_get_curline(); | |
2219 oldlen = STRLEN(oldp); | |
2220 newp = alloc_check((unsigned)oldlen + 1 + n); | |
2221 if (newp == NULL) | |
2222 continue; | |
2223 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2224 /* copy up to deleted part */ | |
2225 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2226 oldp += bd.textcol + bd.textlen; | |
2227 /* insert pre-spaces */ | |
6929 | 2228 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2229 /* 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
|
2230 /* 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
|
2231 * literally. */ |
5428 | 2232 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
7 | 2233 { |
5428 | 2234 if (has_mbyte) |
2235 { | |
2236 n = (int)STRLEN(newp); | |
2237 while (--num_chars >= 0) | |
2238 n += (*mb_char2bytes)(c, newp + n); | |
2239 } | |
2240 else | |
6929 | 2241 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2242 if (!bd.is_short) |
2243 { | |
2244 /* insert post-spaces */ | |
6929 | 2245 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2246 /* copy the part after the changed part */ |
2247 STRMOVE(newp + STRLEN(newp), oldp); | |
2248 } | |
7 | 2249 } |
2250 else | |
2251 { | |
5428 | 2252 /* Replacing with \r or \n means splitting the line. */ |
5475 | 2253 after_p = alloc_check( |
2254 (unsigned)(oldlen + 1 + n - STRLEN(newp))); | |
5428 | 2255 if (after_p != NULL) |
2256 STRMOVE(after_p, oldp); | |
7 | 2257 } |
2258 /* replace the line */ | |
2259 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2260 if (after_p != NULL) |
2261 { | |
2262 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2263 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2264 oap->end.lnum++; | |
2265 vim_free(after_p); | |
2266 } | |
7 | 2267 } |
2268 } | |
2269 else | |
2270 { | |
2271 /* | |
2272 * MCHAR and MLINE motion replace. | |
2273 */ | |
2274 if (oap->motion_type == MLINE) | |
2275 { | |
2276 oap->start.col = 0; | |
2277 curwin->w_cursor.col = 0; | |
2278 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2279 if (oap->end.col) | |
2280 --oap->end.col; | |
2281 } | |
2282 else if (!oap->inclusive) | |
2283 dec(&(oap->end)); | |
2284 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2285 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 2286 { |
2287 n = gchar_cursor(); | |
2288 if (n != NUL) | |
2289 { | |
2290 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2291 { | |
2292 /* This is slow, but it handles replacing a single-byte | |
2293 * with a multi-byte and the other way around. */ | |
4203 | 2294 if (curwin->w_cursor.lnum == oap->end.lnum) |
2295 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
|
2296 replace_character(c); |
7 | 2297 } |
2298 else | |
2299 { | |
2300 if (n == TAB) | |
2301 { | |
2302 int end_vcol = 0; | |
2303 | |
2304 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2305 { | |
2306 /* oap->end has to be recalculated when | |
2307 * the tab breaks */ | |
2308 end_vcol = getviscol2(oap->end.col, | |
2309 oap->end.coladd); | |
2310 } | |
2311 coladvance_force(getviscol()); | |
2312 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2313 getvpos(&oap->end, end_vcol); | |
2314 } | |
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
|
2315 PBYTE(curwin->w_cursor, c); |
7 | 2316 } |
2317 } | |
2318 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2319 { | |
2320 int virtcols = oap->end.coladd; | |
2321 | |
2322 if (curwin->w_cursor.lnum == oap->start.lnum | |
2323 && oap->start.col == oap->end.col && oap->start.coladd) | |
2324 virtcols -= oap->start.coladd; | |
2325 | |
2326 /* oap->end has been trimmed so it's effectively inclusive; | |
2327 * as a result an extra +1 must be counted so we don't | |
2328 * trample the NUL byte. */ | |
2329 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2330 curwin->w_cursor.col -= (virtcols + 1); | |
2331 for (; virtcols >= 0; virtcols--) | |
2332 { | |
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
|
2333 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
|
2334 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
|
2335 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
|
2336 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
|
2337 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
|
2338 break; |
7 | 2339 } |
2340 } | |
2341 | |
2342 /* Advance to next character, stop at the end of the file. */ | |
2343 if (inc_cursor() == -1) | |
2344 break; | |
2345 } | |
2346 } | |
2347 | |
2348 curwin->w_cursor = oap->start; | |
2349 check_cursor(); | |
2350 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2351 | |
2352 /* Set "'[" and "']" marks. */ | |
2353 curbuf->b_op_start = oap->start; | |
2354 curbuf->b_op_end = oap->end; | |
2355 | |
2356 return OK; | |
2357 } | |
2358 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2359 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2360 |
7 | 2361 /* |
2362 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2363 */ | |
2364 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2365 op_tilde(oparg_T *oap) |
7 | 2366 { |
2367 pos_T pos; | |
2368 struct block_def bd; | |
1528 | 2369 int did_change = FALSE; |
7 | 2370 |
2371 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2372 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2373 return; | |
2374 | |
2375 pos = oap->start; | |
2376 if (oap->block_mode) /* Visual block mode */ | |
2377 { | |
2378 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2379 { | |
1766 | 2380 int one_change; |
2381 | |
7 | 2382 block_prep(oap, &bd, pos.lnum, FALSE); |
2383 pos.col = bd.textcol; | |
1766 | 2384 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2385 did_change |= one_change; | |
1525 | 2386 |
5735 | 2387 #ifdef FEAT_NETBEANS_INTG |
2210 | 2388 if (netbeans_active() && one_change) |
7 | 2389 { |
2390 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2391 | |
33 | 2392 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2393 (long)bd.textlen); | |
7 | 2394 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2395 &ptr[bd.textcol], bd.textlen); |
7 | 2396 } |
5735 | 2397 #endif |
7 | 2398 } |
2399 if (did_change) | |
2400 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2401 } | |
2402 else /* not block mode */ | |
2403 { | |
2404 if (oap->motion_type == MLINE) | |
2405 { | |
2406 oap->start.col = 0; | |
2407 pos.col = 0; | |
2408 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2409 if (oap->end.col) | |
2410 --oap->end.col; | |
2411 } | |
2412 else if (!oap->inclusive) | |
2413 dec(&(oap->end)); | |
2414 | |
1528 | 2415 if (pos.lnum == oap->end.lnum) |
2416 did_change = swapchars(oap->op_type, &pos, | |
2417 oap->end.col - pos.col + 1); | |
2418 else | |
2419 for (;;) | |
2420 { | |
2421 did_change |= swapchars(oap->op_type, &pos, | |
2422 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2423 (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
|
2424 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 2425 break; |
2426 } | |
7 | 2427 if (did_change) |
2428 { | |
2429 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2430 0L); | |
2431 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2432 if (netbeans_active() && did_change) |
7 | 2433 { |
2434 char_u *ptr; | |
2435 int count; | |
2436 | |
2437 pos = oap->start; | |
2438 while (pos.lnum < oap->end.lnum) | |
2439 { | |
2440 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2441 count = (int)STRLEN(ptr) - pos.col; |
33 | 2442 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2443 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2444 &ptr[pos.col], count); |
7 | 2445 pos.col = 0; |
2446 pos.lnum++; | |
2447 } | |
2448 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2449 count = oap->end.col - pos.col + 1; | |
33 | 2450 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2451 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2452 &ptr[pos.col], count); |
7 | 2453 } |
2454 #endif | |
2455 } | |
2456 } | |
2457 | |
2458 if (!did_change && oap->is_VIsual) | |
2459 /* No change: need to remove the Visual selection */ | |
2460 redraw_curbuf_later(INVERTED); | |
2461 | |
2462 /* | |
2463 * Set '[ and '] marks. | |
2464 */ | |
2465 curbuf->b_op_start = oap->start; | |
2466 curbuf->b_op_end = oap->end; | |
2467 | |
2468 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
|
2469 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
|
2470 oap->line_count), oap->line_count); |
7 | 2471 } |
2472 | |
2473 /* | |
1525 | 2474 * Invoke swapchar() on "length" bytes at position "pos". |
2475 * "pos" is advanced to just after the changed characters. | |
2476 * "length" is rounded up to include the whole last multi-byte character. | |
2477 * Also works correctly when the number of bytes changes. | |
2478 * Returns TRUE if some character was changed. | |
2479 */ | |
2480 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2481 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2482 { |
2483 int todo; | |
2484 int did_change = 0; | |
2485 | |
2486 for (todo = length; todo > 0; --todo) | |
2487 { | |
2488 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2489 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2490 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2491 |
1525 | 2492 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2493 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2494 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2495 } |
1525 | 2496 did_change |= swapchar(op_type, pos); |
2497 if (inc(pos) == -1) /* at end of file */ | |
2498 break; | |
2499 } | |
2500 return did_change; | |
2501 } | |
2502 | |
2503 /* | |
7 | 2504 * If op_type == OP_UPPER: make uppercase, |
2505 * if op_type == OP_LOWER: make lowercase, | |
2506 * if op_type == OP_ROT13: do rot13 encoding, | |
2507 * else swap case of character at 'pos' | |
2508 * returns TRUE when something actually changed. | |
2509 */ | |
2510 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2511 swapchar(int op_type, pos_T *pos) |
7 | 2512 { |
2513 int c; | |
2514 int nc; | |
2515 | |
2516 c = gchar_pos(pos); | |
2517 | |
2518 /* Only do rot13 encoding for ASCII characters. */ | |
2519 if (c >= 0x80 && op_type == OP_ROT13) | |
2520 return FALSE; | |
2521 | |
1525 | 2522 if (op_type == OP_UPPER && c == 0xdf |
2523 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2524 { |
2525 pos_T sp = curwin->w_cursor; | |
2526 | |
2527 /* Special handling of German sharp s: change to "SS". */ | |
2528 curwin->w_cursor = *pos; | |
2529 del_char(FALSE); | |
2530 ins_char('S'); | |
2531 ins_char('S'); | |
2532 curwin->w_cursor = sp; | |
2533 inc(pos); | |
2534 } | |
2535 | |
7 | 2536 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2537 return FALSE; | |
2538 nc = c; | |
2539 if (MB_ISLOWER(c)) | |
2540 { | |
2541 if (op_type == OP_ROT13) | |
2542 nc = ROT13(c, 'a'); | |
2543 else if (op_type != OP_LOWER) | |
2544 nc = MB_TOUPPER(c); | |
2545 } | |
2546 else if (MB_ISUPPER(c)) | |
2547 { | |
2548 if (op_type == OP_ROT13) | |
2549 nc = ROT13(c, 'A'); | |
2550 else if (op_type != OP_UPPER) | |
2551 nc = MB_TOLOWER(c); | |
2552 } | |
2553 if (nc != c) | |
2554 { | |
2555 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2556 { | |
2557 pos_T sp = curwin->w_cursor; | |
2558 | |
2559 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2560 /* 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
|
2561 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2562 ins_char(nc); |
2563 curwin->w_cursor = sp; | |
2564 } | |
2565 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
|
2566 PBYTE(*pos, nc); |
7 | 2567 return TRUE; |
2568 } | |
2569 return FALSE; | |
2570 } | |
2571 | |
2572 /* | |
2573 * op_insert - Insert and append operators for Visual mode. | |
2574 */ | |
2575 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2576 op_insert(oparg_T *oap, long count1) |
7 | 2577 { |
2578 long ins_len, pre_textlen = 0; | |
2579 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
2580 colnr_T ind_pre = 0, ind_post; |
7 | 2581 struct block_def bd; |
2582 int i; | |
6579 | 2583 pos_T t1; |
7 | 2584 |
2585 /* edit() changes this - record it for OP_APPEND */ | |
2586 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2587 | |
2588 /* vis block is still marked. Get rid of it now. */ | |
2589 curwin->w_cursor.lnum = oap->start.lnum; | |
2590 update_screen(INVERTED); | |
2591 | |
2592 if (oap->block_mode) | |
2593 { | |
2594 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2595 * doing block_prep(). When only "block" is used, virtual edit is | |
2596 * already disabled, but still need it when calling | |
2597 * coladvance_force(). */ | |
2598 if (curwin->w_cursor.coladd > 0) | |
2599 { | |
2600 int old_ve_flags = ve_flags; | |
2601 | |
2602 ve_flags = VE_ALL; | |
2603 if (u_save_cursor() == FAIL) | |
2604 return; | |
2605 coladvance_force(oap->op_type == OP_APPEND | |
2606 ? oap->end_vcol + 1 : getviscol()); | |
2607 if (oap->op_type == OP_APPEND) | |
2608 --curwin->w_cursor.col; | |
2609 ve_flags = old_ve_flags; | |
2610 } | |
2611 /* Get the info about the block before entering the text */ | |
2612 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
|
2613 /* 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
|
2614 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 2615 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
|
2616 |
7 | 2617 if (oap->op_type == OP_APPEND) |
2618 firstline += bd.textlen; | |
2619 pre_textlen = (long)STRLEN(firstline); | |
2620 } | |
2621 | |
2622 if (oap->op_type == OP_APPEND) | |
2623 { | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2624 if (oap->block_mode && curwin->w_cursor.coladd == 0) |
7 | 2625 { |
2626 /* Move the cursor to the character right of the block. */ | |
2627 curwin->w_set_curswant = TRUE; | |
2628 while (*ml_get_cursor() != NUL | |
2629 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2630 ++curwin->w_cursor.col; | |
2631 if (bd.is_short && !bd.is_MAX) | |
2632 { | |
2633 /* First line was too short, make it longer and adjust the | |
2634 * values in "bd". */ | |
2635 if (u_save_cursor() == FAIL) | |
2636 return; | |
2637 for (i = 0; i < bd.endspaces; ++i) | |
2638 ins_char(' '); | |
2639 bd.textlen += bd.endspaces; | |
2640 } | |
2641 } | |
2642 else | |
2643 { | |
2644 curwin->w_cursor = oap->end; | |
893 | 2645 check_cursor_col(); |
7 | 2646 |
2647 /* 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
|
2648 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2649 && oap->start_vcol != oap->end_vcol) |
2650 inc_cursor(); | |
2651 } | |
2652 } | |
2653 | |
6579 | 2654 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
|
2655 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 2656 |
6579 | 2657 /* When a tab was inserted, and the characters in front of the tab |
2658 * have been converted to a tab as well, the column of the cursor | |
2659 * might have actually been reduced, so need to adjust here. */ | |
2660 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
|
2661 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 2662 oap->start = curbuf->b_op_start_orig; |
2663 | |
1477 | 2664 /* If user has moved off this line, we don't know what to do, so do |
2665 * nothing. | |
2666 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2667 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2668 return; |
2669 | |
2670 if (oap->block_mode) | |
2671 { | |
2672 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
|
2673 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
|
2674 size_t len; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2675 int add; |
7 | 2676 |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2677 /* 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
|
2678 * 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
|
2679 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2680 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
|
2681 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2682 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2683 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
|
2684 did_indent = TRUE; |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2685 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2686 |
5471 | 2687 /* 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
|
2688 * 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
|
2689 * 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
|
2690 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
|
2691 && !bd.is_MAX && !did_indent) |
5471 | 2692 { |
2693 if (oap->op_type == OP_INSERT | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2694 && oap->start.col + oap->start.coladd |
5730 | 2695 != curbuf->b_op_start_orig.col |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2696 + curbuf->b_op_start_orig.coladd) |
5471 | 2697 { |
6579 | 2698 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
|
2699 curbuf->b_op_start_orig.coladd); |
5680 | 2700 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2701 pre_textlen -= t - oap->start_vcol; |
2702 oap->start_vcol = t; | |
5471 | 2703 } |
2704 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
|
2705 && oap->end.col + oap->end.coladd |
5730 | 2706 >= curbuf->b_op_start_orig.col |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2707 + curbuf->b_op_start_orig.coladd) |
5471 | 2708 { |
6579 | 2709 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
|
2710 curbuf->b_op_start_orig.coladd); |
5680 | 2711 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2712 /* reset pre_textlen to the value of OP_INSERT */ |
2713 pre_textlen += bd.textlen; | |
6579 | 2714 pre_textlen -= t - oap->start_vcol; |
2715 oap->start_vcol = t; | |
5471 | 2716 oap->op_type = OP_INSERT; |
2717 } | |
2718 } | |
2719 | |
7 | 2720 /* |
2721 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2722 * tabs. Get the starting column again and correct the length. |
7 | 2723 * Don't do this when "$" used, end-of-line will have changed. |
2724 */ | |
2725 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2726 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2727 { | |
2728 if (oap->op_type == OP_APPEND) | |
2729 { | |
2730 pre_textlen += bd2.textlen - bd.textlen; | |
2731 if (bd2.endspaces) | |
2732 --bd2.textlen; | |
2733 } | |
2734 bd.textcol = bd2.textcol; | |
2735 bd.textlen = bd2.textlen; | |
2736 } | |
2737 | |
2738 /* | |
2739 * Subsequent calls to ml_get() flush the firstline data - take a | |
2740 * copy of the required string. | |
2741 */ | |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2742 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
|
2743 len = STRLEN(firstline); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2744 add = bd.textcol; |
7 | 2745 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
|
2746 add += bd.textlen; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2747 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
|
2748 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
|
2749 else |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2750 firstline += add; |
3421 | 2751 if (pre_textlen >= 0 |
2752 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2753 { |
2754 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2755 if (ins_text != NULL) | |
2756 { | |
2757 /* block handled here */ | |
2758 if (u_save(oap->start.lnum, | |
2759 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2760 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2761 &bd); | |
2762 | |
2763 curwin->w_cursor.col = oap->start.col; | |
2764 check_cursor(); | |
2765 vim_free(ins_text); | |
2766 } | |
2767 } | |
2768 } | |
2769 } | |
2770 | |
2771 /* | |
2772 * op_change - handle a change operation | |
2773 * | |
2774 * return TRUE if edit() returns because of a CTRL-O command | |
2775 */ | |
2776 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2777 op_change(oparg_T *oap) |
7 | 2778 { |
2779 colnr_T l; | |
2780 int retval; | |
2781 long offset; | |
2782 linenr_T linenr; | |
1392 | 2783 long ins_len; |
2784 long pre_textlen = 0; | |
2785 long pre_indent = 0; | |
7 | 2786 char_u *firstline; |
2787 char_u *ins_text, *newp, *oldp; | |
2788 struct block_def bd; | |
2789 | |
2790 l = oap->start.col; | |
2791 if (oap->motion_type == MLINE) | |
2792 { | |
2793 l = 0; | |
2794 #ifdef FEAT_SMARTINDENT | |
2795 if (!p_paste && curbuf->b_p_si | |
2796 # ifdef FEAT_CINDENT | |
2797 && !curbuf->b_p_cin | |
2798 # endif | |
2799 ) | |
2800 can_si = TRUE; /* It's like opening a new line, do si */ | |
2801 #endif | |
2802 } | |
2803 | |
2804 /* First delete the text in the region. In an empty buffer only need to | |
2805 * save for undo */ | |
2806 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2807 { | |
2808 if (u_save_cursor() == FAIL) | |
2809 return FALSE; | |
2810 } | |
2811 else if (op_delete(oap) == FAIL) | |
2812 return FALSE; | |
2813 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2814 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2815 && !virtual_op) |
2816 inc_cursor(); | |
2817 | |
2818 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2819 /* skip blank lines too */ | |
2820 if (oap->block_mode) | |
2821 { | |
2822 /* Add spaces before getting the current line length. */ | |
2823 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2824 || gchar_cursor() == NUL)) | |
2825 coladvance_force(getviscol()); | |
1392 | 2826 firstline = ml_get(oap->start.lnum); |
2827 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
|
2828 pre_indent = (long)getwhitecols(firstline); |
7 | 2829 bd.textcol = curwin->w_cursor.col; |
2830 } | |
2831 | |
2832 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2833 if (oap->motion_type == MLINE) | |
2834 fix_indent(); | |
2835 #endif | |
2836 | |
2837 retval = edit(NUL, FALSE, (linenr_T)1); | |
2838 | |
2839 /* | |
39 | 2840 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2841 * block. |
1477 | 2842 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2843 */ |
1477 | 2844 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2845 { |
1392 | 2846 /* Auto-indenting may have changed the indent. If the cursor was past |
2847 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2848 firstline = ml_get(oap->start.lnum); |
1403 | 2849 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2850 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2851 long new_indent = (long)getwhitecols(firstline); |
1392 | 2852 |
2853 pre_textlen += new_indent - pre_indent; | |
2854 bd.textcol += new_indent - pre_indent; | |
2855 } | |
2856 | |
2857 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2858 if (ins_len > 0) | |
2859 { | |
2860 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2861 * copy of the inserted text. */ | |
7 | 2862 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2863 { | |
419 | 2864 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2865 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2866 linenr++) | |
2867 { | |
2868 block_prep(oap, &bd, linenr, TRUE); | |
2869 if (!bd.is_short || virtual_op) | |
2870 { | |
2871 pos_T vpos; | |
2872 | |
2873 /* If the block starts in virtual space, count the | |
2874 * initial coladd offset as part of "startspaces" */ | |
2875 if (bd.is_short) | |
2876 { | |
1982 | 2877 vpos.lnum = linenr; |
7 | 2878 (void)getvpos(&vpos, oap->start_vcol); |
2879 } | |
2880 else | |
2881 vpos.coladd = 0; | |
2882 oldp = ml_get(linenr); | |
2883 newp = alloc_check((unsigned)(STRLEN(oldp) | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2884 + vpos.coladd + ins_len + 1)); |
7 | 2885 if (newp == NULL) |
2886 continue; | |
2887 /* copy up to block start */ | |
2888 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2889 offset = bd.textcol; | |
6929 | 2890 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2891 offset += vpos.coladd; |
2892 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
2893 offset += ins_len; | |
2894 oldp += bd.textcol; | |
1622 | 2895 STRMOVE(newp + offset, oldp); |
7 | 2896 ml_replace(linenr, newp, FALSE); |
2897 } | |
2898 } | |
2899 check_cursor(); | |
2900 | |
2901 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2902 } | |
2903 vim_free(ins_text); | |
2904 } | |
2905 } | |
2906 | |
2907 return retval; | |
2908 } | |
2909 | |
2910 /* | |
2911 * set all the yank registers to empty (called from main()) | |
2912 */ | |
2913 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2914 init_yank(void) |
7 | 2915 { |
2916 int i; | |
2917 | |
2918 for (i = 0; i < NUM_REGISTERS; ++i) | |
2919 y_regs[i].y_array = NULL; | |
2920 } | |
2921 | |
356 | 2922 #if defined(EXITFREE) || defined(PROTO) |
2923 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2924 clear_registers(void) |
356 | 2925 { |
2926 int i; | |
2927 | |
2928 for (i = 0; i < NUM_REGISTERS; ++i) | |
2929 { | |
2930 y_current = &y_regs[i]; | |
2931 if (y_current->y_array != NULL) | |
2932 free_yank_all(); | |
2933 } | |
2934 } | |
2935 #endif | |
2936 | |
7 | 2937 /* |
2938 * Free "n" lines from the current yank register. | |
2939 * Called for normal freeing and in case of error. | |
2940 */ | |
2941 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2942 free_yank(long n) |
7 | 2943 { |
2944 if (y_current->y_array != NULL) | |
2945 { | |
2946 long i; | |
2947 | |
2948 for (i = n; --i >= 0; ) | |
2949 { | |
2950 #ifdef AMIGA /* only for very slow machines */ | |
2951 if ((i & 1023) == 1023) /* this may take a while */ | |
2952 { | |
2953 /* | |
2954 * This message should never cause a hit-return message. | |
2955 * Overwrite this message with any next message. | |
2956 */ | |
2957 ++no_wait_return; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
2958 smsg(_("freeing %ld lines"), i + 1); |
7 | 2959 --no_wait_return; |
2960 msg_didout = FALSE; | |
2961 msg_col = 0; | |
2962 } | |
2963 #endif | |
2964 vim_free(y_current->y_array[i]); | |
2965 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
2966 VIM_CLEAR(y_current->y_array); |
7 | 2967 #ifdef AMIGA |
2968 if (n >= 1000) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
2969 msg(""); |
7 | 2970 #endif |
2971 } | |
2972 } | |
2973 | |
2974 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2975 free_yank_all(void) |
7 | 2976 { |
2977 free_yank(y_current->y_size); | |
2978 } | |
2979 | |
2980 /* | |
2981 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
2982 * If we are to append (uppercase register), we first yank into a new yank | |
2983 * register and then concatenate the old and the new one (so we keep the old | |
2984 * one in case of out-of-memory). | |
2985 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
2986 * Return FAIL for failure, OK otherwise. |
7 | 2987 */ |
2988 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2989 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 2990 { |
2991 long y_idx; /* index in y_array[] */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2992 yankreg_T *curr; /* copy of y_current */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2993 yankreg_T newreg; /* new yank register when appending */ |
7 | 2994 char_u **new_ptr; |
2995 linenr_T lnum; /* current line number */ | |
2996 long j; | |
2997 int yanktype = oap->motion_type; | |
2998 long yanklines = oap->line_count; | |
2999 linenr_T yankendlnum = oap->end.lnum; | |
3000 char_u *p; | |
3001 char_u *pnew; | |
3002 struct block_def bd; | |
2658 | 3003 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 3004 int did_star = FALSE; |
2658 | 3005 #endif |
7 | 3006 |
3007 /* check for read-only register */ | |
3008 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
3009 { | |
3010 beep_flush(); | |
3011 return FAIL; | |
3012 } | |
3013 if (oap->regname == '_') /* black hole: nothing to do */ | |
3014 return OK; | |
3015 | |
3016 #ifdef FEAT_CLIPBOARD | |
3017 if (!clip_star.available && oap->regname == '*') | |
3018 oap->regname = 0; | |
3019 else if (!clip_plus.available && oap->regname == '+') | |
3020 oap->regname = 0; | |
3021 #endif | |
3022 | |
3023 if (!deleting) /* op_delete() already set y_current */ | |
3024 get_yank_register(oap->regname, TRUE); | |
3025 | |
3026 curr = y_current; | |
3027 /* append to existing contents */ | |
3028 if (y_append && y_current->y_array != NULL) | |
3029 y_current = &newreg; | |
3030 else | |
3031 free_yank_all(); /* free previously yanked lines */ | |
3032 | |
593 | 3033 /* |
3034 * If the cursor was in column 1 before and after the movement, and the | |
3035 * operator is not inclusive, the yank is always linewise. | |
3036 */ | |
7 | 3037 if ( oap->motion_type == MCHAR |
3038 && oap->start.col == 0 | |
3039 && !oap->inclusive | |
3040 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 3041 && !oap->block_mode |
7 | 3042 && oap->end.col == 0 |
3043 && yanklines > 1) | |
3044 { | |
3045 yanktype = MLINE; | |
3046 --yankendlnum; | |
3047 --yanklines; | |
3048 } | |
3049 | |
3050 y_current->y_size = yanklines; | |
3051 y_current->y_type = yanktype; /* set the yank register type */ | |
3052 y_current->y_width = 0; | |
3053 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
3054 yanklines), TRUE); | |
3055 if (y_current->y_array == NULL) | |
3056 { | |
3057 y_current = curr; | |
3058 return FAIL; | |
3059 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3060 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3061 y_current->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3062 #endif |
7 | 3063 |
3064 y_idx = 0; | |
3065 lnum = oap->start.lnum; | |
3066 | |
3067 if (oap->block_mode) | |
3068 { | |
3069 /* Visual block mode */ | |
3070 y_current->y_type = MBLOCK; /* set the yank register type */ | |
3071 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
3072 | |
3073 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3074 y_current->y_width--; | |
3075 } | |
3076 | |
3077 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3078 { | |
3079 switch (y_current->y_type) | |
3080 { | |
3081 case MBLOCK: | |
3082 block_prep(oap, &bd, lnum, FALSE); | |
3083 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3084 goto fail; | |
3085 break; | |
3086 | |
3087 case MLINE: | |
3088 if ((y_current->y_array[y_idx] = | |
3089 vim_strsave(ml_get(lnum))) == NULL) | |
3090 goto fail; | |
3091 break; | |
3092 | |
3093 case MCHAR: | |
3094 { | |
3095 colnr_T startcol = 0, endcol = MAXCOL; | |
3096 int is_oneChar = FALSE; | |
3097 colnr_T cs, ce; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3098 |
7 | 3099 p = ml_get(lnum); |
3100 bd.startspaces = 0; | |
3101 bd.endspaces = 0; | |
3102 | |
3103 if (lnum == oap->start.lnum) | |
3104 { | |
3105 startcol = oap->start.col; | |
3106 if (virtual_op) | |
3107 { | |
3108 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3109 if (ce != cs && oap->start.coladd > 0) | |
3110 { | |
3111 /* Part of a tab selected -- but don't | |
3112 * double-count it. */ | |
3113 bd.startspaces = (ce - cs + 1) | |
3114 - oap->start.coladd; | |
3115 startcol++; | |
3116 } | |
3117 } | |
3118 } | |
3119 | |
3120 if (lnum == oap->end.lnum) | |
3121 { | |
3122 endcol = oap->end.col; | |
3123 if (virtual_op) | |
3124 { | |
3125 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3126 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3127 /* Don't add space for double-wide | |
3128 * char; endcol will be on last byte | |
3129 * of multi-byte char. */ | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3130 && (*mb_head_off)(p, p + endcol) == 0)) |
7 | 3131 { |
3132 if (oap->start.lnum == oap->end.lnum | |
3133 && oap->start.col == oap->end.col) | |
3134 { | |
3135 /* Special case: inside a single char */ | |
3136 is_oneChar = TRUE; | |
3137 bd.startspaces = oap->end.coladd | |
3138 - oap->start.coladd + oap->inclusive; | |
3139 endcol = startcol; | |
3140 } | |
3141 else | |
3142 { | |
3143 bd.endspaces = oap->end.coladd | |
3144 + oap->inclusive; | |
3145 endcol -= oap->inclusive; | |
3146 } | |
3147 } | |
3148 } | |
3149 } | |
3510 | 3150 if (endcol == MAXCOL) |
3151 endcol = (colnr_T)STRLEN(p); | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3152 if (startcol > endcol || is_oneChar) |
7 | 3153 bd.textlen = 0; |
3154 else | |
3155 { | |
3156 bd.textlen = endcol - startcol + oap->inclusive; | |
3157 } | |
3158 bd.textstart = p + startcol; | |
3159 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3160 goto fail; | |
3161 break; | |
3162 } | |
3163 /* NOTREACHED */ | |
3164 } | |
3165 } | |
3166 | |
3167 if (curr != y_current) /* append the new block to the old block */ | |
3168 { | |
3169 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3170 (curr->y_size + y_current->y_size)), TRUE); | |
3171 if (new_ptr == NULL) | |
3172 goto fail; | |
3173 for (j = 0; j < curr->y_size; ++j) | |
3174 new_ptr[j] = curr->y_array[j]; | |
3175 vim_free(curr->y_array); | |
3176 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3177 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3178 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3179 #endif |
7 | 3180 |
3181 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3182 curr->y_type = MLINE; | |
3183 | |
164 | 3184 /* Concatenate the last line of the old block with the first line of |
3185 * the new block, unless being Vi compatible. */ | |
3186 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3187 { |
3188 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3189 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3190 if (pnew == NULL) | |
3191 { | |
3192 y_idx = y_current->y_size - 1; | |
3193 goto fail; | |
3194 } | |
3195 STRCPY(pnew, curr->y_array[--j]); | |
3196 STRCAT(pnew, y_current->y_array[0]); | |
3197 vim_free(curr->y_array[j]); | |
3198 vim_free(y_current->y_array[0]); | |
3199 curr->y_array[j++] = pnew; | |
3200 y_idx = 1; | |
3201 } | |
3202 else | |
3203 y_idx = 0; | |
3204 while (y_idx < y_current->y_size) | |
3205 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3206 curr->y_size = j; | |
3207 vim_free(y_current->y_array); | |
3208 y_current = curr; | |
3209 } | |
5981 | 3210 if (curwin->w_p_rnu) |
3211 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3212 if (mess) /* Display message about yank? */ |
3213 { | |
3214 if (yanktype == MCHAR | |
3215 && !oap->block_mode | |
3216 && yanklines == 1) | |
3217 yanklines = 0; | |
3218 /* Some versions of Vi use ">=" here, some don't... */ | |
3219 if (yanklines > p_report) | |
3220 { | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3221 char namebuf[100]; |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3222 |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3223 if (oap->regname == NUL) |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3224 *namebuf = NUL; |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3225 else |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3226 vim_snprintf(namebuf, sizeof(namebuf), |
11688
570f00932da8
patch 8.0.0727: message about what register to yank into is not translated
Christian Brabandt <cb@256bit.org>
parents:
11682
diff
changeset
|
3227 _(" into \"%c"), oap->regname); |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3228 |
7 | 3229 /* redisplay now, so message is not deleted */ |
3230 update_topline_redraw(); | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3231 if (oap->block_mode) |
205 | 3232 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3233 smsg(NGETTEXT("block of %ld line yanked%s", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3234 "block of %ld lines yanked%s", yanklines), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3235 yanklines, namebuf); |
205 | 3236 } |
7 | 3237 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3238 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3239 smsg(NGETTEXT("%ld line yanked%s", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3240 "%ld lines yanked%s", yanklines), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3241 yanklines, namebuf); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3242 } |
7 | 3243 } |
3244 } | |
3245 | |
3246 /* | |
3247 * Set "'[" and "']" marks. | |
3248 */ | |
3249 curbuf->b_op_start = oap->start; | |
3250 curbuf->b_op_end = oap->end; | |
5735 | 3251 if (yanktype == MLINE && !oap->block_mode) |
36 | 3252 { |
3253 curbuf->b_op_start.col = 0; | |
3254 curbuf->b_op_end.col = MAXCOL; | |
3255 } | |
7 | 3256 |
3257 #ifdef FEAT_CLIPBOARD | |
3258 /* | |
3259 * If we were yanking to the '*' register, send result to clipboard. | |
3260 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3261 * to the '*' register. | |
3262 */ | |
3263 if (clip_star.available | |
3264 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3265 || (!deleting && oap->regname == 0 |
6116 | 3266 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3267 { |
3268 if (curr != &(y_regs[STAR_REGISTER])) | |
3269 /* Copy the text from register 0 to the clipboard register. */ | |
3270 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3271 | |
3272 clip_own_selection(&clip_star); | |
3273 clip_gen_set_selection(&clip_star); | |
2658 | 3274 # ifdef FEAT_X11 |
2654 | 3275 did_star = TRUE; |
2658 | 3276 # endif |
7 | 3277 } |
3278 | |
3279 # ifdef FEAT_X11 | |
3280 /* | |
3281 * If we were yanking to the '+' register, send result to selection. | |
3282 * Also copy to the '*' register, in case auto-select is off. | |
3283 */ | |
2654 | 3284 if (clip_plus.available |
3285 && (curr == &(y_regs[PLUS_REGISTER]) | |
3286 || (!deleting && oap->regname == 0 | |
6116 | 3287 && ((clip_unnamed | clip_unnamed_saved) & |
3288 CLIP_UNNAMED_PLUS)))) | |
7 | 3289 { |
2654 | 3290 if (curr != &(y_regs[PLUS_REGISTER])) |
3291 /* Copy the text from register 0 to the clipboard register. */ | |
3292 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3293 | |
7 | 3294 clip_own_selection(&clip_plus); |
3295 clip_gen_set_selection(&clip_plus); | |
12642
d1cbe8cb05d0
patch 8.0.1199: when 'clipboard' is "autoselectplus" star register is set
Christian Brabandt <cb@256bit.org>
parents:
12329
diff
changeset
|
3296 if (!clip_isautosel_star() && !clip_isautosel_plus() |
d1cbe8cb05d0
patch 8.0.1199: when 'clipboard' is "autoselectplus" star register is set
Christian Brabandt <cb@256bit.org>
parents:
12329
diff
changeset
|
3297 && !did_star && curr == &(y_regs[PLUS_REGISTER])) |
7 | 3298 { |
3299 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3300 clip_own_selection(&clip_star); | |
3301 clip_gen_set_selection(&clip_star); | |
3302 } | |
3303 } | |
3304 # endif | |
3305 #endif | |
3306 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
3307 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3308 if (!deleting && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3309 yank_do_autocmd(oap, y_current); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3310 #endif |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3311 |
7 | 3312 return OK; |
3313 | |
3314 fail: /* free the allocated lines */ | |
3315 free_yank(y_idx + 1); | |
3316 y_current = curr; | |
3317 return FAIL; | |
3318 } | |
3319 | |
3320 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3321 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3322 { |
3323 char_u *pnew; | |
3324 | |
3325 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3326 == NULL) | |
3327 return FAIL; | |
3328 y_current->y_array[y_idx] = pnew; | |
6929 | 3329 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3330 pnew += bd->startspaces; |
3331 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3332 pnew += bd->textlen; | |
6929 | 3333 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3334 pnew += bd->endspaces; |
3335 *pnew = NUL; | |
3336 return OK; | |
3337 } | |
3338 | |
3339 #ifdef FEAT_CLIPBOARD | |
3340 /* | |
3341 * Make a copy of the y_current register to register "reg". | |
3342 */ | |
3343 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3344 copy_yank_reg(yankreg_T *reg) |
7 | 3345 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3346 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3347 long j; |
7 | 3348 |
3349 y_current = reg; | |
3350 free_yank_all(); | |
3351 *y_current = *curr; | |
3352 y_current->y_array = (char_u **)lalloc_clear( | |
3353 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3354 if (y_current->y_array == NULL) | |
3355 y_current->y_size = 0; | |
3356 else | |
3357 for (j = 0; j < y_current->y_size; ++j) | |
3358 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3359 { | |
3360 free_yank(j); | |
3361 y_current->y_size = 0; | |
3362 break; | |
3363 } | |
3364 y_current = curr; | |
3365 } | |
3366 #endif | |
3367 | |
3368 /* | |
140 | 3369 * Put contents of register "regname" into the text. |
3370 * Caller must check "regname" to be valid! | |
3371 * "flags": PUT_FIXINDENT make indent look nice | |
3372 * PUT_CURSEND leave cursor after end of new text | |
3373 * PUT_LINE force linewise put (":put") | |
7 | 3374 */ |
3375 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3376 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3377 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3378 int dir, /* BACKWARD for 'P', FORWARD for 'p' */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3379 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3380 int flags) |
7 | 3381 { |
3382 char_u *ptr; | |
3383 char_u *newp, *oldp; | |
3384 int yanklen; | |
3385 int totlen = 0; /* init for gcc */ | |
3386 linenr_T lnum; | |
3387 colnr_T col; | |
3388 long i; /* index in y_array[] */ | |
3389 int y_type; | |
3390 long y_size; | |
3391 int oldlen; | |
3392 long y_width = 0; | |
3393 colnr_T vcol; | |
3394 int delcount; | |
3395 int incr = 0; | |
3396 long j; | |
3397 struct block_def bd; | |
3398 char_u **y_array = NULL; | |
3399 long nr_lines = 0; | |
3400 pos_T new_cursor; | |
3401 int indent; | |
3402 int orig_indent = 0; /* init for gcc */ | |
3403 int indent_diff = 0; /* init for gcc */ | |
3404 int first_indent = TRUE; | |
3405 int lendiff = 0; | |
3406 pos_T old_pos; | |
3407 char_u *insert_string = NULL; | |
3408 int allocated = FALSE; | |
3409 long cnt; | |
3410 | |
3411 #ifdef FEAT_CLIPBOARD | |
3412 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3413 adjust_clip_reg(®name); | |
3414 (void)may_get_selection(regname); | |
3415 #endif | |
3416 | |
3417 if (flags & PUT_FIXINDENT) | |
3418 orig_indent = get_indent(); | |
3419 | |
3420 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3421 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3422 | |
3423 /* | |
3424 * Using inserted text works differently, because the register includes | |
3425 * special characters (newlines, etc.). | |
3426 */ | |
3427 if (regname == '.') | |
3428 { | |
10494
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3429 if (VIsual_active) |
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3430 stuffcharReadbuff(VIsual_mode); |
7 | 3431 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
3432 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3433 /* Putting the text is done later, so can't really move the cursor to | |
3434 * the next character. Use "l" to simulate it. */ | |
3435 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3436 stuffcharReadbuff('l'); | |
3437 return; | |
3438 } | |
3439 | |
3440 /* | |
3441 * For special registers '%' (file name), '#' (alternate file name) and | |
3442 * ':' (last command line), etc. we have to create a fake yank register. | |
3443 */ | |
3444 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3445 { | |
3446 if (insert_string == NULL) | |
3447 return; | |
3448 } | |
3449 | |
14202
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3450 /* Autocommands may be executed when saving lines for undo. This might |
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3451 * make "y_array" invalid, so we start undo now to avoid that. */ |
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3452 if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL) |
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3453 goto end; |
4005 | 3454 |
7 | 3455 if (insert_string != NULL) |
3456 { | |
3457 y_type = MCHAR; | |
3458 #ifdef FEAT_EVAL | |
3459 if (regname == '=') | |
3460 { | |
3461 /* For the = register we need to split the string at NL | |
3093 | 3462 * characters. |
3463 * Loop twice: count the number of lines and save them. */ | |
7 | 3464 for (;;) |
3465 { | |
3466 y_size = 0; | |
3467 ptr = insert_string; | |
3468 while (ptr != NULL) | |
3469 { | |
3470 if (y_array != NULL) | |
3471 y_array[y_size] = ptr; | |
3472 ++y_size; | |
3473 ptr = vim_strchr(ptr, '\n'); | |
3474 if (ptr != NULL) | |
3475 { | |
3476 if (y_array != NULL) | |
3477 *ptr = NUL; | |
3478 ++ptr; | |
3093 | 3479 /* A trailing '\n' makes the register linewise. */ |
7 | 3480 if (*ptr == NUL) |
3481 { | |
3482 y_type = MLINE; | |
3483 break; | |
3484 } | |
3485 } | |
3486 } | |
3487 if (y_array != NULL) | |
3488 break; | |
3489 y_array = (char_u **)alloc((unsigned) | |
3490 (y_size * sizeof(char_u *))); | |
3491 if (y_array == NULL) | |
3492 goto end; | |
3493 } | |
3494 } | |
3495 else | |
3496 #endif | |
3497 { | |
3498 y_size = 1; /* use fake one-line yank register */ | |
3499 y_array = &insert_string; | |
3500 } | |
3501 } | |
3502 else | |
3503 { | |
3504 get_yank_register(regname, FALSE); | |
3505 | |
3506 y_type = y_current->y_type; | |
3507 y_width = y_current->y_width; | |
3508 y_size = y_current->y_size; | |
3509 y_array = y_current->y_array; | |
3510 } | |
3511 | |
3512 if (y_type == MLINE) | |
3513 { | |
3514 if (flags & PUT_LINE_SPLIT) | |
3515 { | |
6845 | 3516 char_u *p; |
3517 | |
7 | 3518 /* "p" or "P" in Visual mode: split the lines to put the text in |
3519 * between. */ | |
3520 if (u_save_cursor() == FAIL) | |
3521 goto end; | |
6845 | 3522 p = ml_get_cursor(); |
3523 if (dir == FORWARD && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3524 MB_PTR_ADV(p); |
6845 | 3525 ptr = vim_strsave(p); |
7 | 3526 if (ptr == NULL) |
3527 goto end; | |
3528 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3529 vim_free(ptr); | |
3530 | |
6845 | 3531 oldp = ml_get_curline(); |
3532 p = oldp + curwin->w_cursor.col; | |
3533 if (dir == FORWARD && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3534 MB_PTR_ADV(p); |
6845 | 3535 ptr = vim_strnsave(oldp, p - oldp); |
7 | 3536 if (ptr == NULL) |
3537 goto end; | |
3538 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3539 ++nr_lines; | |
3540 dir = FORWARD; | |
3541 } | |
3542 if (flags & PUT_LINE_FORWARD) | |
3543 { | |
3544 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3545 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3546 dir = FORWARD; |
3547 } | |
3548 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3549 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3550 } | |
3551 | |
3552 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3553 y_type = MLINE; | |
3554 | |
3555 if (y_size == 0 || y_array == NULL) | |
3556 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3557 semsg(_("E353: Nothing in register %s"), |
7 | 3558 regname == 0 ? (char_u *)"\"" : transchar(regname)); |
3559 goto end; | |
3560 } | |
3561 | |
3562 if (y_type == MBLOCK) | |
3563 { | |
3564 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3565 if (lnum > curbuf->b_ml.ml_line_count) | |
3566 lnum = curbuf->b_ml.ml_line_count + 1; | |
3567 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3568 goto end; | |
3569 } | |
5735 | 3570 else if (y_type == MLINE) |
7 | 3571 { |
3572 lnum = curwin->w_cursor.lnum; | |
3573 #ifdef FEAT_FOLDING | |
3574 /* Correct line number for closed fold. Don't move the cursor yet, | |
3575 * u_save() uses it. */ | |
3576 if (dir == BACKWARD) | |
3577 (void)hasFolding(lnum, &lnum, NULL); | |
3578 else | |
3579 (void)hasFolding(lnum, NULL, &lnum); | |
3580 #endif | |
3581 if (dir == FORWARD) | |
3582 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3583 /* In an empty buffer the empty line is going to be replaced, include |
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3584 * it in the saved lines. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
3585 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3586 goto end; |
3587 #ifdef FEAT_FOLDING | |
3588 if (dir == FORWARD) | |
3589 curwin->w_cursor.lnum = lnum - 1; | |
3590 else | |
3591 curwin->w_cursor.lnum = lnum; | |
3592 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3593 #endif | |
3594 } | |
3595 else if (u_save_cursor() == FAIL) | |
3596 goto end; | |
3597 | |
3598 yanklen = (int)STRLEN(y_array[0]); | |
3599 | |
3600 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3601 { | |
3602 if (gchar_cursor() == TAB) | |
3603 { | |
3604 /* Don't need to insert spaces when "p" on the last position of a | |
3605 * tab or "P" on the first position. */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3606 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3607 int viscol = getviscol(); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3608 if (dir == FORWARD |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3609 ? tabstop_padding(viscol, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3610 curbuf->b_p_vts_array) != 1 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3611 : curwin->w_cursor.coladd > 0) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3612 coladvance_force(viscol); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3613 #else |
7 | 3614 if (dir == FORWARD |
3615 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3616 : curwin->w_cursor.coladd > 0) | |
3617 coladvance_force(getviscol()); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3618 #endif |
7 | 3619 else |
3620 curwin->w_cursor.coladd = 0; | |
3621 } | |
3622 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3623 coladvance_force(getviscol() + (dir == FORWARD)); | |
3624 } | |
3625 | |
3626 lnum = curwin->w_cursor.lnum; | |
3627 col = curwin->w_cursor.col; | |
3628 | |
3629 /* | |
3630 * Block mode | |
3631 */ | |
3632 if (y_type == MBLOCK) | |
3633 { | |
10664
94db9c08e206
patch 8.0.0222: blockwise put on multi-byte character misplaced
Christian Brabandt <cb@256bit.org>
parents:
10494
diff
changeset
|
3634 int c = gchar_cursor(); |
7 | 3635 colnr_T endcol2 = 0; |
3636 | |
3637 if (dir == FORWARD && c != NUL) | |
3638 { | |
3639 if (ve_flags == VE_ALL) | |
3640 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3641 else | |
3642 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3643 | |
3644 if (has_mbyte) | |
3645 /* move to start of next multi-byte character */ | |
474 | 3646 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3647 else |
3648 if (c != TAB || ve_flags != VE_ALL) | |
3649 ++curwin->w_cursor.col; | |
3650 ++col; | |
3651 } | |
3652 else | |
3653 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3654 | |
3655 col += curwin->w_cursor.coladd; | |
1304 | 3656 if (ve_flags == VE_ALL |
3657 && (curwin->w_cursor.coladd > 0 | |
3658 || endcol2 == curwin->w_cursor.col)) | |
7 | 3659 { |
3660 if (dir == FORWARD && c == NUL) | |
3661 ++col; | |
3662 if (dir != FORWARD && c != NUL) | |
3663 ++curwin->w_cursor.col; | |
3664 if (c == TAB) | |
3665 { | |
3666 if (dir == BACKWARD && curwin->w_cursor.col) | |
3667 curwin->w_cursor.col--; | |
3668 if (dir == FORWARD && col - 1 == endcol2) | |
3669 curwin->w_cursor.col++; | |
3670 } | |
3671 } | |
3672 curwin->w_cursor.coladd = 0; | |
699 | 3673 bd.textcol = 0; |
7 | 3674 for (i = 0; i < y_size; ++i) |
3675 { | |
3676 int spaces; | |
3677 char shortline; | |
3678 | |
3679 bd.startspaces = 0; | |
3680 bd.endspaces = 0; | |
3681 vcol = 0; | |
3682 delcount = 0; | |
3683 | |
3684 /* add a new line */ | |
3685 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3686 { | |
3687 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3688 (colnr_T)1, FALSE) == FAIL) | |
3689 break; | |
3690 ++nr_lines; | |
3691 } | |
3692 /* get the old line and advance to the position to insert at */ | |
3693 oldp = ml_get_curline(); | |
3694 oldlen = (int)STRLEN(oldp); | |
3695 for (ptr = oldp; vcol < col && *ptr; ) | |
3696 { | |
3697 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3698 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3699 vcol += incr; |
3700 } | |
3701 bd.textcol = (colnr_T)(ptr - oldp); | |
3702 | |
3703 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3704 | |
3705 if (vcol < col) /* line too short, padd with spaces */ | |
3706 bd.startspaces = col - vcol; | |
3707 else if (vcol > col) | |
3708 { | |
3709 bd.endspaces = vcol - col; | |
3710 bd.startspaces = incr - bd.endspaces; | |
3711 --bd.textcol; | |
3712 delcount = 1; | |
3713 if (has_mbyte) | |
3714 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3715 if (oldp[bd.textcol] != TAB) | |
3716 { | |
3717 /* Only a Tab can be split into spaces. Other | |
3718 * characters will have to be moved to after the | |
3719 * block, causing misalignment. */ | |
3720 delcount = 0; | |
3721 bd.endspaces = 0; | |
3722 } | |
3723 } | |
3724 | |
3725 yanklen = (int)STRLEN(y_array[i]); | |
3726 | |
3727 /* calculate number of spaces required to fill right side of block*/ | |
3728 spaces = y_width + 1; | |
3729 for (j = 0; j < yanklen; j++) | |
5995 | 3730 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3731 if (spaces < 0) |
3732 spaces = 0; | |
3733 | |
3734 /* insert the new text */ | |
3735 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3736 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3737 if (newp == NULL) | |
3738 break; | |
3739 /* copy part up to cursor to new line */ | |
3740 ptr = newp; | |
3741 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3742 ptr += bd.textcol; | |
3743 /* may insert some spaces before the new text */ | |
6929 | 3744 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3745 ptr += bd.startspaces; |
3746 /* insert the new text */ | |
3747 for (j = 0; j < count; ++j) | |
3748 { | |
3749 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3750 ptr += yanklen; | |
3751 | |
3752 /* insert block's trailing spaces only if there's text behind */ | |
3753 if ((j < count - 1 || !shortline) && spaces) | |
3754 { | |
6929 | 3755 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3756 ptr += spaces; |
3757 } | |
3758 } | |
3759 /* may insert some spaces after the new text */ | |
6929 | 3760 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3761 ptr += bd.endspaces; |
3762 /* move the text after the cursor to the end of the line. */ | |
3763 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3764 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3765 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3766 | |
3767 ++curwin->w_cursor.lnum; | |
3768 if (i == 0) | |
3769 curwin->w_cursor.col += bd.startspaces; | |
3770 } | |
3771 | |
3772 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3773 | |
3774 /* Set '[ mark. */ | |
3775 curbuf->b_op_start = curwin->w_cursor; | |
3776 curbuf->b_op_start.lnum = lnum; | |
3777 | |
3778 /* adjust '] mark */ | |
3779 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3780 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
3781 curbuf->b_op_end.coladd = 0; | |
3782 if (flags & PUT_CURSEND) | |
3783 { | |
916 | 3784 colnr_T len; |
3785 | |
7 | 3786 curwin->w_cursor = curbuf->b_op_end; |
3787 curwin->w_cursor.col++; | |
916 | 3788 |
3789 /* in Insert mode we might be after the NUL, correct for that */ | |
3790 len = (colnr_T)STRLEN(ml_get_curline()); | |
3791 if (curwin->w_cursor.col > len) | |
3792 curwin->w_cursor.col = len; | |
7 | 3793 } |
3794 else | |
3795 curwin->w_cursor.lnum = lnum; | |
3796 } | |
3797 else | |
3798 { | |
3799 /* | |
3800 * Character or Line mode | |
3801 */ | |
3802 if (y_type == MCHAR) | |
3803 { | |
3804 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3805 * char */ | |
3806 if (dir == FORWARD && gchar_cursor() != NUL) | |
3807 { | |
3808 if (has_mbyte) | |
3809 { | |
474 | 3810 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3811 |
3812 /* put it on the next of the multi-byte character. */ | |
3813 col += bytelen; | |
3814 if (yanklen) | |
3815 { | |
3816 curwin->w_cursor.col += bytelen; | |
3817 curbuf->b_op_end.col += bytelen; | |
3818 } | |
3819 } | |
3820 else | |
3821 { | |
3822 ++col; | |
3823 if (yanklen) | |
3824 { | |
3825 ++curwin->w_cursor.col; | |
3826 ++curbuf->b_op_end.col; | |
3827 } | |
3828 } | |
3829 } | |
3830 curbuf->b_op_start = curwin->w_cursor; | |
3831 } | |
3832 /* | |
3833 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3834 */ | |
3835 else if (dir == BACKWARD) | |
3836 --lnum; | |
699 | 3837 new_cursor = curwin->w_cursor; |
7 | 3838 |
3839 /* | |
3840 * simple case: insert into current line | |
3841 */ | |
3842 if (y_type == MCHAR && y_size == 1) | |
3843 { | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3844 linenr_T end_lnum = 0; /* init for gcc */ |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3845 |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3846 if (VIsual_active) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3847 { |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3848 end_lnum = curbuf->b_visual.vi_end.lnum; |
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3849 if (end_lnum < curbuf->b_visual.vi_start.lnum) |
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3850 end_lnum = curbuf->b_visual.vi_start.lnum; |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3851 } |
10670
bce3eccea39a
patch 8.0.0225: put in Visual block mode terminates early
Christian Brabandt <cb@256bit.org>
parents:
10664
diff
changeset
|
3852 |
5365 | 3853 do { |
3854 totlen = count * yanklen; | |
3855 if (totlen > 0) | |
7 | 3856 { |
5365 | 3857 oldp = ml_get(lnum); |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3858 if (VIsual_active && col > (int)STRLEN(oldp)) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3859 { |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3860 lnum++; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3861 continue; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3862 } |
5365 | 3863 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); |
3864 if (newp == NULL) | |
3865 goto end; /* alloc() gave an error message */ | |
3866 mch_memmove(newp, oldp, (size_t)col); | |
3867 ptr = newp + col; | |
3868 for (i = 0; i < count; ++i) | |
3869 { | |
3870 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3871 ptr += yanklen; | |
3872 } | |
3873 STRMOVE(ptr, oldp + col); | |
3874 ml_replace(lnum, newp, FALSE); | |
3875 /* Place cursor on last putted char. */ | |
3876 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3877 { |
3878 /* make sure curwin->w_virtcol is updated */ | |
3879 changed_cline_bef_curs(); | |
5365 | 3880 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3881 } |
7 | 3882 } |
5365 | 3883 if (VIsual_active) |
3884 lnum++; | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3885 } while (VIsual_active && lnum <= end_lnum); |
5365 | 3886 |
6379 | 3887 if (VIsual_active) /* reset lnum to the last visual line */ |
3888 lnum--; | |
3889 | |
7 | 3890 curbuf->b_op_end = curwin->w_cursor; |
3891 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
3892 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
3893 ++curwin->w_cursor.col; | |
3894 changed_bytes(lnum, col); | |
3895 } | |
3896 else | |
3897 { | |
3898 /* | |
3899 * Insert at least one line. When y_type is MCHAR, break the first | |
3900 * line in two. | |
3901 */ | |
3902 for (cnt = 1; cnt <= count; ++cnt) | |
3903 { | |
3904 i = 0; | |
3905 if (y_type == MCHAR) | |
3906 { | |
3907 /* | |
3908 * Split the current line in two at the insert position. | |
3909 * First insert y_array[size - 1] in front of second line. | |
3910 * Then append y_array[0] to first line. | |
3911 */ | |
3912 lnum = new_cursor.lnum; | |
3913 ptr = ml_get(lnum) + col; | |
3914 totlen = (int)STRLEN(y_array[y_size - 1]); | |
3915 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
3916 if (newp == NULL) | |
3917 goto error; | |
3918 STRCPY(newp, y_array[y_size - 1]); | |
3919 STRCAT(newp, ptr); | |
3920 /* insert second line */ | |
3921 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
3922 vim_free(newp); | |
3923 | |
3924 oldp = ml_get(lnum); | |
3925 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
3926 if (newp == NULL) | |
3927 goto error; | |
3928 /* copy first part of line */ | |
3929 mch_memmove(newp, oldp, (size_t)col); | |
3930 /* append to first line */ | |
3931 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
3932 ml_replace(lnum, newp, FALSE); | |
3933 | |
3934 curwin->w_cursor.lnum = lnum; | |
3935 i = 1; | |
3936 } | |
3937 | |
3938 for (; i < y_size; ++i) | |
3939 { | |
3940 if ((y_type != MCHAR || i < y_size - 1) | |
3941 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
3942 == FAIL) | |
3943 goto error; | |
3944 lnum++; | |
3945 ++nr_lines; | |
3946 if (flags & PUT_FIXINDENT) | |
3947 { | |
3948 old_pos = curwin->w_cursor; | |
3949 curwin->w_cursor.lnum = lnum; | |
3950 ptr = ml_get(lnum); | |
3951 if (cnt == count && i == y_size - 1) | |
3952 lendiff = (int)STRLEN(ptr); | |
3953 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
3954 if (*ptr == '#' && preprocs_left()) | |
3955 indent = 0; /* Leave # lines at start */ | |
3956 else | |
3957 #endif | |
3958 if (*ptr == NUL) | |
3959 indent = 0; /* Ignore empty lines */ | |
3960 else if (first_indent) | |
3961 { | |
3962 indent_diff = orig_indent - get_indent(); | |
3963 indent = orig_indent; | |
3964 first_indent = FALSE; | |
3965 } | |
3966 else if ((indent = get_indent() + indent_diff) < 0) | |
3967 indent = 0; | |
3968 (void)set_indent(indent, 0); | |
3969 curwin->w_cursor = old_pos; | |
3970 /* remember how many chars were removed */ | |
3971 if (cnt == count && i == y_size - 1) | |
3972 lendiff -= (int)STRLEN(ml_get(lnum)); | |
3973 } | |
3974 } | |
3975 } | |
3976 | |
3977 error: | |
3978 /* Adjust marks. */ | |
3979 if (y_type == MLINE) | |
3980 { | |
3981 curbuf->b_op_start.col = 0; | |
3982 if (dir == FORWARD) | |
3983 curbuf->b_op_start.lnum++; | |
3984 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3985 /* Skip mark_adjust when adding lines after the last one, there |
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
|
3986 * can't be marks there. But still needed in diff mode. */ |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3987 if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines |
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
|
3988 < curbuf->b_ml.ml_line_count |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3989 #ifdef FEAT_DIFF |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3990 || curwin->w_p_diff |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3991 #endif |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3992 ) |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3993 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 3994 (linenr_T)MAXLNUM, nr_lines, 0L); |
3995 | |
3996 /* note changed text for displaying and folding */ | |
3997 if (y_type == MCHAR) | |
3998 changed_lines(curwin->w_cursor.lnum, col, | |
3999 curwin->w_cursor.lnum + 1, nr_lines); | |
4000 else | |
4001 changed_lines(curbuf->b_op_start.lnum, 0, | |
4002 curbuf->b_op_start.lnum, nr_lines); | |
4003 | |
4004 /* put '] mark at last inserted character */ | |
4005 curbuf->b_op_end.lnum = lnum; | |
4006 /* correct length for change in indent */ | |
4007 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
4008 if (col > 1) | |
4009 curbuf->b_op_end.col = col - 1; | |
4010 else | |
4011 curbuf->b_op_end.col = 0; | |
4012 | |
168 | 4013 if (flags & PUT_CURSLINE) |
4014 { | |
237 | 4015 /* ":put": put cursor on last inserted line */ |
168 | 4016 curwin->w_cursor.lnum = lnum; |
4017 beginline(BL_WHITE | BL_FIX); | |
4018 } | |
4019 else if (flags & PUT_CURSEND) | |
7 | 4020 { |
4021 /* put cursor after inserted text */ | |
4022 if (y_type == MLINE) | |
4023 { | |
4024 if (lnum >= curbuf->b_ml.ml_line_count) | |
4025 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4026 else | |
4027 curwin->w_cursor.lnum = lnum + 1; | |
4028 curwin->w_cursor.col = 0; | |
4029 } | |
4030 else | |
4031 { | |
4032 curwin->w_cursor.lnum = lnum; | |
4033 curwin->w_cursor.col = col; | |
4034 } | |
4035 } | |
4036 else if (y_type == MLINE) | |
4037 { | |
168 | 4038 /* put cursor on first non-blank in first inserted line */ |
7 | 4039 curwin->w_cursor.col = 0; |
4040 if (dir == FORWARD) | |
4041 ++curwin->w_cursor.lnum; | |
4042 beginline(BL_WHITE | BL_FIX); | |
4043 } | |
4044 else /* put cursor on first inserted character */ | |
4045 curwin->w_cursor = new_cursor; | |
4046 } | |
4047 } | |
4048 | |
4049 msgmore(nr_lines); | |
4050 curwin->w_set_curswant = TRUE; | |
4051 | |
4052 end: | |
4053 if (allocated) | |
4054 vim_free(insert_string); | |
840 | 4055 if (regname == '=') |
4056 vim_free(y_array); | |
4057 | |
5380 | 4058 VIsual_active = FALSE; |
4059 | |
140 | 4060 /* If the cursor is past the end of the line put it at the end. */ |
844 | 4061 adjust_cursor_eol(); |
4062 } | |
4063 | |
4064 /* | |
4065 * When the cursor is on the NUL past the end of the line and it should not be | |
4066 * there move it left. | |
4067 */ | |
4068 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4069 adjust_cursor_eol(void) |
844 | 4070 { |
4071 if (curwin->w_cursor.col > 0 | |
4072 && gchar_cursor() == NUL | |
773 | 4073 && (ve_flags & VE_ONEMORE) == 0 |
7 | 4074 && !(restart_edit || (State & INSERT))) |
4075 { | |
557 | 4076 /* Put the cursor on the last character in the line. */ |
555 | 4077 dec_cursor(); |
844 | 4078 |
7 | 4079 if (ve_flags == VE_ALL) |
557 | 4080 { |
4081 colnr_T scol, ecol; | |
4082 | |
4083 /* Coladd is set to the width of the last character. */ | |
4084 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4085 curwin->w_cursor.coladd = ecol - scol + 1; | |
4086 } | |
7 | 4087 } |
4088 } | |
4089 | |
4090 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4091 /* | |
4092 * Return TRUE if lines starting with '#' should be left aligned. | |
4093 */ | |
4094 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4095 preprocs_left(void) |
7 | 4096 { |
4097 return | |
4098 # ifdef FEAT_SMARTINDENT | |
4099 # ifdef FEAT_CINDENT | |
4100 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4101 # else | |
4102 curbuf->b_p_si | |
4103 # endif | |
4104 # endif | |
4105 # ifdef FEAT_CINDENT | |
5438 | 4106 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4107 && curbuf->b_ind_hash_comment == 0) | |
7 | 4108 # endif |
4109 ; | |
4110 } | |
4111 #endif | |
4112 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4113 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4114 * Return the character name of the register with the given number. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4115 */ |
7 | 4116 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4117 get_register_name(int num) |
7 | 4118 { |
4119 if (num == -1) | |
4120 return '"'; | |
4121 else if (num < 10) | |
4122 return num + '0'; | |
4123 else if (num == DELETION_REGISTER) | |
4124 return '-'; | |
4125 #ifdef FEAT_CLIPBOARD | |
4126 else if (num == STAR_REGISTER) | |
4127 return '*'; | |
4128 else if (num == PLUS_REGISTER) | |
4129 return '+'; | |
4130 #endif | |
4131 else | |
4132 { | |
4133 #ifdef EBCDIC | |
4134 int i; | |
4135 | |
4136 /* EBCDIC is really braindead ... */ | |
4137 i = 'a' + (num - 10); | |
4138 if (i > 'i') | |
4139 i += 7; | |
4140 if (i > 'r') | |
4141 i += 8; | |
4142 return i; | |
4143 #else | |
4144 return num + 'a' - 10; | |
4145 #endif | |
4146 } | |
4147 } | |
4148 | |
4149 /* | |
4150 * ":dis" and ":registers": Display the contents of the yank registers. | |
4151 */ | |
4152 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4153 ex_display(exarg_T *eap) |
7 | 4154 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4155 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4156 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4157 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4158 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4159 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4160 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4161 char_u *arg = eap->arg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4162 int clen; |
7 | 4163 |
4164 if (arg != NULL && *arg == NUL) | |
4165 arg = NULL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11131
diff
changeset
|
4166 attr = HL_ATTR(HLF_8); |
7 | 4167 |
4168 /* Highlight title */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4169 msg_puts_title(_("\n--- Registers ---")); |
7 | 4170 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) |
4171 { | |
4172 name = get_register_name(i); | |
2644 | 4173 if (arg != NULL && vim_strchr(arg, name) == NULL |
4174 #ifdef ONE_CLIPBOARD | |
4175 /* Star register and plus register contain the same thing. */ | |
4176 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4177 #endif | |
4178 ) | |
7 | 4179 continue; /* did not ask for this register */ |
4180 | |
4181 #ifdef FEAT_CLIPBOARD | |
4182 /* Adjust register name for "unnamed" in 'clipboard'. | |
4183 * When it's a clipboard register, fill it with the current contents | |
4184 * of the clipboard. */ | |
4185 adjust_clip_reg(&name); | |
4186 (void)may_get_selection(name); | |
4187 #endif | |
4188 | |
4189 if (i == -1) | |
4190 { | |
4191 if (y_previous != NULL) | |
4192 yb = y_previous; | |
4193 else | |
4194 yb = &(y_regs[0]); | |
4195 } | |
4196 else | |
4197 yb = &(y_regs[i]); | |
2000 | 4198 |
4199 #ifdef FEAT_EVAL | |
4200 if (name == MB_TOLOWER(redir_reg) | |
4201 || (redir_reg == '"' && yb == y_previous)) | |
4202 continue; /* do not list register being written to, the | |
4203 * pointer can be freed */ | |
4204 #endif | |
4205 | |
7 | 4206 if (yb->y_array != NULL) |
4207 { | |
4208 msg_putchar('\n'); | |
4209 msg_putchar('"'); | |
4210 msg_putchar(name); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4211 msg_puts(" "); |
7 | 4212 |
4213 n = (int)Columns - 6; | |
4214 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4215 { | |
4216 if (j) | |
4217 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4218 msg_puts_attr("^J", attr); |
7 | 4219 n -= 2; |
4220 } | |
4221 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4222 { | |
474 | 4223 clen = (*mb_ptr2len)(p); |
22 | 4224 msg_outtrans_len(p, clen); |
4225 p += clen - 1; | |
7 | 4226 } |
4227 } | |
4228 if (n > 1 && yb->y_type == MLINE) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4229 msg_puts_attr("^J", attr); |
7 | 4230 out_flush(); /* show one line at a time */ |
4231 } | |
4232 ui_breakcheck(); | |
4233 } | |
4234 | |
4235 /* | |
4236 * display last inserted text | |
4237 */ | |
4238 if ((p = get_last_insert()) != NULL | |
4239 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4240 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4241 msg_puts("\n\". "); |
7 | 4242 dis_msg(p, TRUE); |
4243 } | |
4244 | |
4245 /* | |
4246 * display last command line | |
4247 */ | |
4248 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4249 && !got_int) | |
4250 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4251 msg_puts("\n\": "); |
7 | 4252 dis_msg(last_cmdline, FALSE); |
4253 } | |
4254 | |
4255 /* | |
4256 * display current file name | |
4257 */ | |
4258 if (curbuf->b_fname != NULL | |
4259 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4260 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4261 msg_puts("\n\"% "); |
7 | 4262 dis_msg(curbuf->b_fname, FALSE); |
4263 } | |
4264 | |
4265 /* | |
4266 * display alternate file name | |
4267 */ | |
4268 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4269 { | |
4270 char_u *fname; | |
4271 linenr_T dummy; | |
4272 | |
4273 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4274 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4275 msg_puts("\n\"# "); |
7 | 4276 dis_msg(fname, FALSE); |
4277 } | |
4278 } | |
4279 | |
4280 /* | |
4281 * display last search pattern | |
4282 */ | |
4283 if (last_search_pat() != NULL | |
4284 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4285 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4286 msg_puts("\n\"/ "); |
7 | 4287 dis_msg(last_search_pat(), FALSE); |
4288 } | |
4289 | |
4290 #ifdef FEAT_EVAL | |
4291 /* | |
4292 * display last used expression | |
4293 */ | |
4294 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4295 && !got_int) | |
4296 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4297 msg_puts("\n\"= "); |
7 | 4298 dis_msg(expr_line, FALSE); |
4299 } | |
4300 #endif | |
4301 } | |
4302 | |
4303 /* | |
4304 * display a string for do_dis() | |
4305 * truncate at end of screen line | |
4306 */ | |
4307 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4308 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4309 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4310 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4311 { |
4312 int n; | |
4313 int l; | |
4314 | |
4315 n = (int)Columns - 6; | |
4316 while (*p != NUL | |
4317 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4318 && (n -= ptr2cells(p)) >= 0) | |
4319 { | |
474 | 4320 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4321 { |
4322 msg_outtrans_len(p, l); | |
4323 p += l; | |
4324 } | |
4325 else | |
4326 msg_outtrans_len(p++, 1); | |
4327 } | |
4328 ui_breakcheck(); | |
4329 } | |
4330 | |
3562 | 4331 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4332 /* | |
4333 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4334 * after some white space), return a pointer to the text after it. Put a boolean | |
4335 * value indicating whether the line ends with an unclosed comment in | |
4336 * "is_comment". | |
4337 * line - line to be processed, | |
4338 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4339 * comment, |
3562 | 4340 * include_space - whether to also skip space following the comment leader, |
4341 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4342 * comment. |
3562 | 4343 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4344 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4345 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4346 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4347 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4348 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4349 int *is_comment) |
3562 | 4350 { |
4351 char_u *comment_flags = NULL; | |
4352 int lead_len; | |
4353 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4354 | |
4355 *is_comment = FALSE; | |
4356 if (leader_offset != -1) | |
4357 { | |
4358 /* Let's check whether the line ends with an unclosed comment. | |
4359 * If the last comment leader has COM_END in flags, there's no comment. | |
4360 */ | |
4361 while (*comment_flags) | |
4362 { | |
4363 if (*comment_flags == COM_END | |
4364 || *comment_flags == ':') | |
4365 break; | |
4366 ++comment_flags; | |
4367 } | |
4368 if (*comment_flags != COM_END) | |
4369 *is_comment = TRUE; | |
4370 } | |
4371 | |
4372 if (process == FALSE) | |
4373 return line; | |
4374 | |
4375 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4376 | |
4377 if (lead_len == 0) | |
4378 return line; | |
4379 | |
4380 /* Find: | |
4381 * - COM_END, | |
4382 * - colon, | |
4383 * whichever comes first. | |
4384 */ | |
4385 while (*comment_flags) | |
4386 { | |
3580 | 4387 if (*comment_flags == COM_END |
3562 | 4388 || *comment_flags == ':') |
4389 { | |
4390 break; | |
4391 } | |
4392 ++comment_flags; | |
4393 } | |
4394 | |
4395 /* If we found a colon, it means that we are not processing a line | |
3580 | 4396 * starting with a closing part of a three-part comment. That's good, |
4397 * because we don't want to remove those as this would be annoying. | |
3562 | 4398 */ |
4399 if (*comment_flags == ':' || *comment_flags == NUL) | |
4400 line += lead_len; | |
4401 | |
4402 return line; | |
4403 } | |
4404 #endif | |
4405 | |
7 | 4406 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4407 * 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
|
4408 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4409 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4410 * leaders should not be removed. | |
4411 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4412 * to set those marks. | |
7 | 4413 * |
1217 | 4414 * return FAIL for failure, OK otherwise |
7 | 4415 */ |
4416 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4417 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4418 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4419 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4420 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4421 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4422 int setmark) |
7 | 4423 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4424 char_u *curr = NULL; |
2597 | 4425 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
|
4426 char_u *cend; |
7 | 4427 char_u *newp; |
2597 | 4428 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
|
4429 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4430 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4431 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
|
4432 int sumsize = 0; /* size of the long new line */ |
7 | 4433 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4434 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4435 int ret = OK; |
3562 | 4436 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4437 int *comments = NULL; |
3562 | 4438 int remove_comments = (use_formatoptions == TRUE) |
4439 && has_format_option(FO_REMOVE_COMS); | |
4440 int prev_was_comment; | |
4441 #endif | |
4442 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4443 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4444 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
|
4445 (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
|
4446 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4447 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4448 /* 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
|
4449 * 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
|
4450 * proper placement of each original line in the new one. */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4451 spaces = lalloc_clear((long_u)count, TRUE); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4452 if (spaces == NULL) |
7 | 4453 return FAIL; |
3562 | 4454 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4455 if (remove_comments) | |
4456 { | |
4457 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4458 if (comments == NULL) | |
4459 { | |
4460 vim_free(spaces); | |
4461 return FAIL; | |
4462 } | |
4463 } | |
4464 #endif | |
7 | 4465 |
4466 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4467 * Don't move anything, just compute the final line length |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4468 * and setup the array of space strings lengths |
7 | 4469 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4470 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
|
4471 { |
2597 | 4472 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4473 if (t == 0 && setmark) |
5664 | 4474 { |
4475 /* Set the '[ mark. */ | |
4476 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4477 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4478 } | |
3562 | 4479 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4480 if (remove_comments) | |
4481 { | |
4482 /* We don't want to remove the comment leader if the | |
4483 * previous line is not a comment. */ | |
4484 if (t > 0 && prev_was_comment) | |
4485 { | |
4486 | |
4487 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4488 &prev_was_comment); | |
3576 | 4489 comments[t] = (int)(new_curr - curr); |
3562 | 4490 curr = new_curr; |
4491 } | |
4492 else | |
4493 curr = skip_comment(curr, FALSE, insert_space, | |
4494 &prev_was_comment); | |
4495 } | |
4496 #endif | |
4497 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4498 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
|
4499 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4500 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4501 if (*curr != ')' && currsize != 0 && endcurr1 != TAB |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4502 && (!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
|
4503 || (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
|
4504 && (!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
|
4505 || 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
|
4506 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4507 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4508 /* 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
|
4509 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4510 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4511 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4512 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4513 /* 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
|
4514 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4515 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4516 || (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
|
4517 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4518 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4519 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4520 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4521 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4522 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4523 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4524 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
|
4525 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4526 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4527 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4528 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4529 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
|
4530 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4531 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4532 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4533 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
|
4534 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4535 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4536 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4537 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4538 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4539 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4540 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4541 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4542 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4543 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4544 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4545 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4546 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4547 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4548 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4549 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4550 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4551 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4552 /* 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
|
4553 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
|
4554 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4555 /* allocate the space for the new line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4556 newp = alloc_check((unsigned)(sumsize + 1)); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4557 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4558 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4559 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4560 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4561 * Move affected lines to the new long one. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4562 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4563 * 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
|
4564 * 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
|
4565 * 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
|
4566 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4567 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
|
4568 { |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4569 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
|
4570 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4571 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4572 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
|
4573 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4574 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4575 cend -= spaces[t]; |
6929 | 4576 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
|
4577 } |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4578 |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4579 // 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
|
4580 // 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
|
4581 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
|
4582 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4583 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
|
4584 (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
|
4585 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4586 break; |
2597 | 4587 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4588 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4589 if (remove_comments) | |
4590 curr += comments[t - 1]; | |
4591 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4592 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
|
4593 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4594 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4595 } |
7 | 4596 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4597 | |
5848 | 4598 if (setmark) |
4599 { | |
4600 /* Set the '] mark. */ | |
4601 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4602 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4603 } | |
5664 | 4604 |
7 | 4605 /* Only report the change in the first line here, del_lines() will report |
4606 * the deleted line. */ | |
4607 changed_lines(curwin->w_cursor.lnum, currsize, | |
4608 curwin->w_cursor.lnum + 1, 0L); | |
4609 | |
4610 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4611 * Delete following lines. To do this we move the cursor there |
7 | 4612 * briefly, and then move it back. After del_lines() the cursor may |
4613 * have moved up (last line deleted), so the current lnum is kept in t. | |
4614 */ | |
4615 t = curwin->w_cursor.lnum; | |
4616 ++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
|
4617 del_lines(count - 1, FALSE); |
7 | 4618 curwin->w_cursor.lnum = t; |
4619 | |
4620 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4621 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4622 * 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
|
4623 * vim: use the column of the last join |
7 | 4624 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4625 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4626 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4627 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4628 |
7 | 4629 curwin->w_cursor.coladd = 0; |
4630 curwin->w_set_curswant = TRUE; | |
4631 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4632 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4633 vim_free(spaces); |
3562 | 4634 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4635 if (remove_comments) | |
4636 vim_free(comments); | |
4637 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4638 return ret; |
7 | 4639 } |
4640 | |
4641 #ifdef FEAT_COMMENTS | |
4642 /* | |
4643 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4644 * the first line. White-space is ignored. Note that the whole of | |
4645 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4646 */ | |
4647 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4648 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4649 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4650 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4651 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4652 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4653 char_u *leader2_flags) |
7 | 4654 { |
4655 int idx1 = 0, idx2 = 0; | |
4656 char_u *p; | |
4657 char_u *line1; | |
4658 char_u *line2; | |
4659 | |
4660 if (leader1_len == 0) | |
4661 return (leader2_len == 0); | |
4662 | |
4663 /* | |
4664 * If first leader has 'f' flag, the lines can be joined only if the | |
4665 * second line does not have a leader. | |
4666 * If first leader has 'e' flag, the lines can never be joined. | |
4667 * If fist leader has 's' flag, the lines can only be joined if there is | |
4668 * some text after it and the second line has the 'm' flag. | |
4669 */ | |
4670 if (leader1_flags != NULL) | |
4671 { | |
4672 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4673 { | |
4674 if (*p == COM_FIRST) | |
4675 return (leader2_len == 0); | |
4676 if (*p == COM_END) | |
4677 return FALSE; | |
4678 if (*p == COM_START) | |
4679 { | |
4680 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4681 return FALSE; | |
4682 if (leader2_flags == NULL || leader2_len == 0) | |
4683 return FALSE; | |
4684 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4685 if (*p == COM_MIDDLE) | |
4686 return TRUE; | |
4687 return FALSE; | |
4688 } | |
4689 } | |
4690 } | |
4691 | |
4692 /* | |
4693 * Get current line and next line, compare the leaders. | |
4694 * The first line has to be saved, only one line can be locked at a time. | |
4695 */ | |
4696 line1 = vim_strsave(ml_get(lnum)); | |
4697 if (line1 != NULL) | |
4698 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4699 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 4700 ; |
4701 line2 = ml_get(lnum + 1); | |
4702 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4703 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4704 if (!VIM_ISWHITE(line2[idx2])) |
7 | 4705 { |
4706 if (line1[idx1++] != line2[idx2]) | |
4707 break; | |
4708 } | |
4709 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4710 while (VIM_ISWHITE(line1[idx1])) |
7 | 4711 ++idx1; |
4712 } | |
4713 vim_free(line1); | |
4714 } | |
4715 return (idx2 == leader2_len && idx1 == leader1_len); | |
4716 } | |
4717 #endif | |
4718 | |
4719 /* | |
3252 | 4720 * Implementation of the format operator 'gq'. |
7 | 4721 */ |
4722 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4723 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4724 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4725 int keep_cursor) /* keep cursor on same text char */ |
7 | 4726 { |
4727 long old_line_count = curbuf->b_ml.ml_line_count; | |
4728 | |
4729 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4730 * can put it back there. */ | |
4731 curwin->w_cursor = oap->cursor_start; | |
4732 | |
4733 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4734 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4735 return; | |
4736 curwin->w_cursor = oap->start; | |
4737 | |
4738 if (oap->is_VIsual) | |
4739 /* When there is no change: need to remove the Visual selection */ | |
4740 redraw_curbuf_later(INVERTED); | |
4741 | |
4742 /* Set '[ mark at the start of the formatted area */ | |
4743 curbuf->b_op_start = oap->start; | |
4744 | |
4745 /* For "gw" remember the cursor position and put it back below (adjusted | |
4746 * for joined and split lines). */ | |
4747 if (keep_cursor) | |
4748 saved_cursor = oap->cursor_start; | |
4749 | |
1563 | 4750 format_lines(oap->line_count, keep_cursor); |
7 | 4751 |
4752 /* | |
4753 * Leave the cursor at the first non-blank of the last formatted line. | |
4754 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4755 * line, so "." will do the next lines. | |
4756 */ | |
4757 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4758 ++curwin->w_cursor.lnum; | |
4759 beginline(BL_WHITE | BL_FIX); | |
4760 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4761 msgmore(old_line_count); | |
4762 | |
4763 /* put '] mark on the end of the formatted area */ | |
4764 curbuf->b_op_end = curwin->w_cursor; | |
4765 | |
4766 if (keep_cursor) | |
4767 { | |
4768 curwin->w_cursor = saved_cursor; | |
4769 saved_cursor.lnum = 0; | |
4770 } | |
4771 | |
4772 if (oap->is_VIsual) | |
4773 { | |
4774 win_T *wp; | |
4775 | |
4776 FOR_ALL_WINDOWS(wp) | |
4777 { | |
4778 if (wp->w_old_cursor_lnum != 0) | |
4779 { | |
4780 /* When lines have been inserted or deleted, adjust the end of | |
4781 * the Visual area to be redrawn. */ | |
4782 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4783 wp->w_old_cursor_lnum += old_line_count; | |
4784 else | |
4785 wp->w_old_visual_lnum += old_line_count; | |
4786 } | |
4787 } | |
4788 } | |
4789 } | |
4790 | |
667 | 4791 #if defined(FEAT_EVAL) || defined(PROTO) |
4792 /* | |
4793 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4794 */ | |
4795 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4796 op_formatexpr(oparg_T *oap) |
667 | 4797 { |
4798 if (oap->is_VIsual) | |
4799 /* When there is no change: need to remove the Visual selection */ | |
4800 redraw_curbuf_later(INVERTED); | |
4801 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4802 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
|
4803 /* 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
|
4804 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4805 op_format(oap, FALSE); |
667 | 4806 } |
4807 | |
4808 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4809 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4810 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4811 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4812 int c) /* character to be inserted */ |
667 | 4813 { |
681 | 4814 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4815 OPT_LOCAL); | |
667 | 4816 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4817 char_u *fex; |
667 | 4818 |
4819 /* | |
4820 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4821 * Set v:char to the character to be inserted (can be NUL). |
667 | 4822 */ |
4823 set_vim_var_nr(VV_LNUM, lnum); | |
4824 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4825 set_vim_var_char(c); |
844 | 4826 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4827 /* 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
|
4828 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
|
4829 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4830 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4831 |
667 | 4832 /* |
4833 * Evaluate the function. | |
4834 */ | |
4835 if (use_sandbox) | |
4836 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4837 r = (int)eval_to_number(fex); |
667 | 4838 if (use_sandbox) |
4839 --sandbox; | |
844 | 4840 |
4841 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
|
4842 vim_free(fex); |
844 | 4843 |
667 | 4844 return r; |
4845 } | |
4846 #endif | |
4847 | |
7 | 4848 /* |
4849 * Format "line_count" lines, starting at the cursor position. | |
4850 * When "line_count" is negative, format until the end of the paragraph. | |
4851 * Lines after the cursor line are saved for undo, caller must have saved the | |
4852 * first line. | |
4853 */ | |
4854 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4855 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4856 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4857 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4858 { |
4859 int max_len; | |
4860 int is_not_par; /* current line not part of parag. */ | |
4861 int next_is_not_par; /* next line not part of paragraph */ | |
4862 int is_end_par; /* at end of paragraph */ | |
4863 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4864 int next_is_start_par = FALSE; | |
4865 #ifdef FEAT_COMMENTS | |
4866 int leader_len = 0; /* leader len of current line */ | |
4867 int next_leader_len; /* leader len of next line */ | |
4868 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
4869 char_u *next_leader_flags; /* flags for leader of next line */ | |
4870 int do_comments; /* format comments */ | |
3584 | 4871 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 4872 #endif |
4873 int advance = TRUE; | |
3584 | 4874 int second_indent = -1; /* indent for second line (comment |
4875 * aware) */ | |
7 | 4876 int do_second_indent; |
4877 int do_number_indent; | |
4878 int do_trail_white; | |
4879 int first_par_line = TRUE; | |
4880 int smd_save; | |
4881 long count; | |
4882 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
4883 int force_format = FALSE; | |
4884 int old_State = State; | |
4885 | |
4886 /* length of a line to force formatting: 3 * 'tw' */ | |
4887 max_len = comp_textwidth(TRUE) * 3; | |
4888 | |
4889 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
4890 #ifdef FEAT_COMMENTS | |
4891 do_comments = has_format_option(FO_Q_COMS); | |
4892 #endif | |
4893 do_second_indent = has_format_option(FO_Q_SECOND); | |
4894 do_number_indent = has_format_option(FO_Q_NUMBER); | |
4895 do_trail_white = has_format_option(FO_WHITE_PAR); | |
4896 | |
4897 /* | |
4898 * Get info about the previous and current line. | |
4899 */ | |
4900 if (curwin->w_cursor.lnum > 1) | |
4901 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
4902 #ifdef FEAT_COMMENTS | |
4903 , &leader_len, &leader_flags, do_comments | |
4904 #endif | |
4905 ); | |
4906 else | |
4907 is_not_par = TRUE; | |
4908 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
4909 #ifdef FEAT_COMMENTS | |
4910 , &next_leader_len, &next_leader_flags, do_comments | |
4911 #endif | |
4912 ); | |
4913 is_end_par = (is_not_par || next_is_not_par); | |
4914 if (!is_end_par && do_trail_white) | |
4915 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
4916 | |
4917 curwin->w_cursor.lnum--; | |
4918 for (count = line_count; count != 0 && !got_int; --count) | |
4919 { | |
4920 /* | |
4921 * Advance to next paragraph. | |
4922 */ | |
4923 if (advance) | |
4924 { | |
4925 curwin->w_cursor.lnum++; | |
4926 prev_is_end_par = is_end_par; | |
4927 is_not_par = next_is_not_par; | |
4928 #ifdef FEAT_COMMENTS | |
4929 leader_len = next_leader_len; | |
4930 leader_flags = next_leader_flags; | |
4931 #endif | |
4932 } | |
4933 | |
4934 /* | |
4935 * The last line to be formatted. | |
4936 */ | |
4937 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4938 { | |
4939 next_is_not_par = TRUE; | |
4940 #ifdef FEAT_COMMENTS | |
4941 next_leader_len = 0; | |
4942 next_leader_flags = NULL; | |
4943 #endif | |
4944 } | |
4945 else | |
4946 { | |
4947 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
4948 #ifdef FEAT_COMMENTS | |
4949 , &next_leader_len, &next_leader_flags, do_comments | |
4950 #endif | |
4951 ); | |
4952 if (do_number_indent) | |
4953 next_is_start_par = | |
4954 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
4955 } | |
4956 advance = TRUE; | |
4957 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
4958 if (!is_end_par && do_trail_white) | |
4959 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
4960 | |
4961 /* | |
4962 * Skip lines that are not in a paragraph. | |
4963 */ | |
4964 if (is_not_par) | |
4965 { | |
4966 if (line_count < 0) | |
4967 break; | |
4968 } | |
4969 else | |
4970 { | |
4971 /* | |
4972 * For the first line of a paragraph, check indent of second line. | |
4973 * Don't do this for comments and empty lines. | |
4974 */ | |
4975 if (first_par_line | |
4976 && (do_second_indent || do_number_indent) | |
4977 && prev_is_end_par | |
3584 | 4978 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
4979 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
4980 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 4981 { |
4982 #ifdef FEAT_COMMENTS | |
4983 if (leader_len == 0 && next_leader_len == 0) | |
4984 { | |
4985 /* no comment found */ | |
4986 #endif | |
4987 second_indent = | |
4988 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 4989 #ifdef FEAT_COMMENTS |
3584 | 4990 } |
4991 else | |
4992 { | |
4993 second_indent = next_leader_len; | |
4994 do_comments_list = 1; | |
4995 } | |
4996 #endif | |
4997 } | |
7 | 4998 else if (do_number_indent) |
3584 | 4999 { |
5000 #ifdef FEAT_COMMENTS | |
5001 if (leader_len == 0 && next_leader_len == 0) | |
5002 { | |
5003 /* no comment found */ | |
5004 #endif | |
5005 second_indent = | |
5006 get_number_indent(curwin->w_cursor.lnum); | |
5007 #ifdef FEAT_COMMENTS | |
5008 } | |
5009 else | |
5010 { | |
5011 /* get_number_indent() is now "comment aware"... */ | |
5012 second_indent = | |
5013 get_number_indent(curwin->w_cursor.lnum); | |
5014 do_comments_list = 1; | |
5015 } | |
5016 #endif | |
5017 } | |
7 | 5018 } |
5019 | |
5020 /* | |
5021 * When the comment leader changes, it's the end of the paragraph. | |
5022 */ | |
5023 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
5024 #ifdef FEAT_COMMENTS | |
5025 || !same_leader(curwin->w_cursor.lnum, | |
5026 leader_len, leader_flags, | |
5027 next_leader_len, next_leader_flags) | |
5028 #endif | |
5029 ) | |
5030 is_end_par = TRUE; | |
5031 | |
5032 /* | |
5033 * If we have got to the end of a paragraph, or the line is | |
5034 * getting long, format it. | |
5035 */ | |
5036 if (is_end_par || force_format) | |
5037 { | |
5038 if (need_set_indent) | |
5039 /* replace indent in first line with minimal number of | |
5040 * tabs and spaces, according to current options */ | |
5041 (void)set_indent(get_indent(), SIN_CHANGED); | |
5042 | |
5043 /* put cursor on last non-space */ | |
5044 State = NORMAL; /* don't go past end-of-line */ | |
5045 coladvance((colnr_T)MAXCOL); | |
5046 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
5047 dec_cursor(); | |
5048 | |
5049 /* do the formatting, without 'showmode' */ | |
5050 State = INSERT; /* for open_line() */ | |
5051 smd_save = p_smd; | |
5052 p_smd = FALSE; | |
5053 insertchar(NUL, INSCHAR_FORMAT | |
5054 #ifdef FEAT_COMMENTS | |
5055 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 5056 + (do_comments && do_comments_list |
5057 ? INSCHAR_COM_LIST : 0) | |
7 | 5058 #endif |
1563 | 5059 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 5060 State = old_State; |
5061 p_smd = smd_save; | |
5062 second_indent = -1; | |
5063 /* at end of par.: need to set indent of next par. */ | |
5064 need_set_indent = is_end_par; | |
5065 if (is_end_par) | |
5066 { | |
5067 /* When called with a negative line count, break at the | |
5068 * end of the paragraph. */ | |
5069 if (line_count < 0) | |
5070 break; | |
5071 first_par_line = TRUE; | |
5072 } | |
5073 force_format = FALSE; | |
5074 } | |
5075 | |
5076 /* | |
5077 * When still in same paragraph, join the lines together. But | |
5403 | 5078 * first delete the leader from the second line. |
7 | 5079 */ |
5080 if (!is_end_par) | |
5081 { | |
5082 advance = FALSE; | |
5083 curwin->w_cursor.lnum++; | |
5084 curwin->w_cursor.col = 0; | |
5085 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
|
5086 break; |
7 | 5087 #ifdef FEAT_COMMENTS |
5088 if (next_leader_len > 0) | |
5403 | 5089 { |
5090 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5091 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5092 (long)-next_leader_len, 0); |
5403 | 5093 } else |
5094 #endif | |
5095 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5096 { | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
5097 int indent = getwhitecols_curline(); |
5403 | 5098 |
5099 if (indent > 0) | |
5100 { | |
5101 (void)del_bytes(indent, FALSE, FALSE); | |
5102 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
|
5103 (colnr_T)0, 0L, (long)-indent, 0); |
5415 | 5104 } |
5403 | 5105 } |
7 | 5106 curwin->w_cursor.lnum--; |
5848 | 5107 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5108 { |
5109 beep_flush(); | |
5110 break; | |
5111 } | |
5112 first_par_line = FALSE; | |
5113 /* If the line is getting long, format it next time */ | |
5114 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5115 force_format = TRUE; | |
5116 else | |
5117 force_format = FALSE; | |
5118 } | |
5119 } | |
5120 line_breakcheck(); | |
5121 } | |
5122 } | |
5123 | |
5124 /* | |
5125 * Return TRUE if line "lnum" ends in a white character. | |
5126 */ | |
5127 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5128 ends_in_white(linenr_T lnum) |
7 | 5129 { |
5130 char_u *s = ml_get(lnum); | |
5131 size_t l; | |
5132 | |
5133 if (*s == NUL) | |
5134 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5135 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 5136 * invocation may call function multiple times". */ |
5137 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
|
5138 return VIM_ISWHITE(s[l]); |
7 | 5139 } |
5140 | |
5141 /* | |
5142 * Blank lines, and lines containing only the comment leader, are left | |
5143 * untouched by the formatting. The function returns TRUE in this | |
5144 * case. It also returns TRUE when a line starts with the end of a comment | |
5145 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5146 * previous line. A new paragraph starts after a blank line, or when the | |
5147 * comment leader changes -- webb. | |
5148 */ | |
5149 #ifdef FEAT_COMMENTS | |
5150 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5151 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5152 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5153 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5154 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5155 int do_comments) |
7 | 5156 { |
5157 char_u *flags = NULL; /* init for GCC */ | |
5158 char_u *ptr; | |
5159 | |
5160 ptr = ml_get(lnum); | |
5161 if (do_comments) | |
3562 | 5162 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5163 else |
5164 *leader_len = 0; | |
5165 | |
5166 if (*leader_len > 0) | |
5167 { | |
5168 /* | |
5169 * Search for 'e' flag in comment leader flags. | |
5170 */ | |
5171 flags = *leader_flags; | |
5172 while (*flags && *flags != ':' && *flags != COM_END) | |
5173 ++flags; | |
5174 } | |
5175 | |
5176 return (*skipwhite(ptr + *leader_len) == NUL | |
5177 || (*leader_len > 0 && *flags == COM_END) | |
5178 || startPS(lnum, NUL, FALSE)); | |
5179 } | |
5180 #else | |
5181 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5182 fmt_check_par(linenr_T lnum) |
7 | 5183 { |
5184 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5185 } | |
5186 #endif | |
5187 | |
5188 /* | |
5189 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5190 * previous line is in the same paragraph. Used for auto-formatting. | |
5191 */ | |
5192 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5193 paragraph_start(linenr_T lnum) |
7 | 5194 { |
5195 char_u *p; | |
5196 #ifdef FEAT_COMMENTS | |
5197 int leader_len = 0; /* leader len of current line */ | |
5198 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5199 int next_leader_len; /* leader len of next line */ | |
5200 char_u *next_leader_flags; /* flags for leader of next line */ | |
5201 int do_comments; /* format comments */ | |
5202 #endif | |
5203 | |
5204 if (lnum <= 1) | |
5205 return TRUE; /* start of the file */ | |
5206 | |
5207 p = ml_get(lnum - 1); | |
5208 if (*p == NUL) | |
5209 return TRUE; /* after empty line */ | |
5210 | |
5211 #ifdef FEAT_COMMENTS | |
5212 do_comments = has_format_option(FO_Q_COMS); | |
5213 #endif | |
5214 if (fmt_check_par(lnum - 1 | |
5215 #ifdef FEAT_COMMENTS | |
5216 , &leader_len, &leader_flags, do_comments | |
5217 #endif | |
5218 )) | |
5219 return TRUE; /* after non-paragraph line */ | |
5220 | |
5221 if (fmt_check_par(lnum | |
5222 #ifdef FEAT_COMMENTS | |
5223 , &next_leader_len, &next_leader_flags, do_comments | |
5224 #endif | |
5225 )) | |
5226 return TRUE; /* "lnum" is not a paragraph line */ | |
5227 | |
5228 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5229 return TRUE; /* missing trailing space in previous line. */ | |
5230 | |
5231 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5232 return TRUE; /* numbered item starts in "lnum". */ | |
5233 | |
5234 #ifdef FEAT_COMMENTS | |
5235 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5236 next_leader_len, next_leader_flags)) | |
5237 return TRUE; /* change of comment leader. */ | |
5238 #endif | |
5239 | |
5240 return FALSE; | |
5241 } | |
5242 | |
5243 /* | |
5244 * prepare a few things for block mode yank/delete/tilde | |
5245 * | |
5246 * for delete: | |
5247 * - textlen includes the first/last char to be (partly) deleted | |
5248 * - start/endspaces is the number of columns that are taken by the | |
5249 * first/last deleted char minus the number of columns that have to be | |
1839 | 5250 * deleted. |
5251 * for yank and tilde: | |
7 | 5252 * - textlen includes the first/last char to be wholly yanked |
5253 * - start/endspaces is the number of columns of the first/last yanked char | |
5254 * that are to be yanked. | |
5255 */ | |
5256 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5257 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5258 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5259 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5260 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5261 int is_del) |
7 | 5262 { |
5263 int incr = 0; | |
5264 char_u *pend; | |
5265 char_u *pstart; | |
5266 char_u *line; | |
5267 char_u *prev_pstart; | |
5268 char_u *prev_pend; | |
5269 | |
5270 bdp->startspaces = 0; | |
5271 bdp->endspaces = 0; | |
5272 bdp->textlen = 0; | |
5273 bdp->start_vcol = 0; | |
5274 bdp->end_vcol = 0; | |
5275 bdp->is_short = FALSE; | |
5276 bdp->is_oneChar = FALSE; | |
5277 bdp->pre_whitesp = 0; | |
5278 bdp->pre_whitesp_c = 0; | |
5279 bdp->end_char_vcols = 0; | |
5280 bdp->start_char_vcols = 0; | |
5281 | |
5282 line = ml_get(lnum); | |
5283 pstart = line; | |
5284 prev_pstart = line; | |
5285 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5286 { | |
5287 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5288 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5289 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
|
5290 if (VIM_ISWHITE(*pstart)) |
7 | 5291 { |
5292 bdp->pre_whitesp += incr; | |
5293 bdp->pre_whitesp_c++; | |
5294 } | |
5295 else | |
5296 { | |
5297 bdp->pre_whitesp = 0; | |
5298 bdp->pre_whitesp_c = 0; | |
5299 } | |
5300 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5301 MB_PTR_ADV(pstart); |
7 | 5302 } |
5303 bdp->start_char_vcols = incr; | |
5304 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5305 { | |
5306 bdp->end_vcol = bdp->start_vcol; | |
5307 bdp->is_short = TRUE; | |
5308 if (!is_del || oap->op_type == OP_APPEND) | |
5309 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5310 } | |
5311 else | |
5312 { | |
5313 /* notice: this converts partly selected Multibyte characters to | |
5314 * spaces, too. */ | |
5315 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5316 if (is_del && bdp->startspaces) | |
5317 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5318 pend = pstart; | |
5319 bdp->end_vcol = bdp->start_vcol; | |
5320 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5321 { | |
5322 bdp->is_oneChar = TRUE; | |
5323 if (oap->op_type == OP_INSERT) | |
5324 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5325 else if (oap->op_type == OP_APPEND) | |
5326 { | |
5327 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5328 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5329 } | |
5330 else | |
5331 { | |
5332 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5333 if (is_del && oap->op_type != OP_LSHIFT) | |
5334 { | |
5335 /* just putting the sum of those two into | |
5336 * bdp->startspaces doesn't work for Visual replace, | |
5337 * so we have to split the tab in two */ | |
5338 bdp->startspaces = bdp->start_char_vcols | |
5339 - (bdp->start_vcol - oap->start_vcol); | |
5340 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5341 } | |
5342 } | |
5343 } | |
5344 else | |
5345 { | |
5346 prev_pend = pend; | |
5347 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5348 { | |
5349 /* Count a tab for what it's worth (if list mode not on) */ | |
5350 prev_pend = pend; | |
6535 | 5351 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5352 bdp->end_vcol += incr; |
5353 } | |
5354 if (bdp->end_vcol <= oap->end_vcol | |
5355 && (!is_del | |
5356 || oap->op_type == OP_APPEND | |
5357 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5358 { | |
5359 bdp->is_short = TRUE; | |
5360 /* Alternative: include spaces to fill up the block. | |
5361 * Disadvantage: can lead to trailing spaces when the line is | |
5362 * short where the text is put */ | |
5363 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5364 if (oap->op_type == OP_APPEND || virtual_op) | |
5365 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5366 + oap->inclusive; |
7 | 5367 else |
5368 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5369 } | |
5370 else if (bdp->end_vcol > oap->end_vcol) | |
5371 { | |
5372 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5373 if (!is_del && bdp->endspaces) | |
5374 { | |
5375 bdp->endspaces = incr - bdp->endspaces; | |
5376 if (pend != pstart) | |
5377 pend = prev_pend; | |
5378 } | |
5379 } | |
5380 } | |
5381 bdp->end_char_vcols = incr; | |
5382 if (is_del && bdp->startspaces) | |
5383 pstart = prev_pstart; | |
5384 bdp->textlen = (int)(pend - pstart); | |
5385 } | |
5386 bdp->textcol = (colnr_T) (pstart - line); | |
5387 bdp->textstart = pstart; | |
5388 } | |
5389 | |
5390 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5391 * Handle the add/subtract operator. |
7 | 5392 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5393 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5394 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5395 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5396 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
|
5397 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
|
5398 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5399 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5400 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5401 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5402 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5403 |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5404 // do_addsub() might trigger re-evaluation of 'foldexpr' halfway, when the |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5405 // buffer is not completly updated yet. Postpone updating folds until before |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5406 // 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
|
5407 #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
|
5408 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
|
5409 #endif |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5410 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5411 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5412 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5413 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5414 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
|
5415 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5416 #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
|
5417 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
|
5418 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5419 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5420 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5421 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
|
5422 #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
|
5423 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
|
5424 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5425 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5426 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
|
5427 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5428 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5429 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5430 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5431 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5432 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5433 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5434 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
|
5435 (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
|
5436 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5437 #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
|
5438 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
|
5439 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5440 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5441 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5442 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5443 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5444 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
|
5445 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5446 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
|
5447 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5448 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
|
5449 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5450 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5451 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5452 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
|
5453 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5454 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5455 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5456 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
|
5457 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5458 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5459 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
5460 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
|
5461 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5462 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
|
5463 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5464 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
|
5465 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5466 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5467 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5468 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5469 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5470 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5471 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
|
5472 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5473 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5474 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
|
5475 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5476 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5477 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
|
5478 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5479 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5480 /* 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
|
5481 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5482 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5483 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5484 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5485 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5486 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5487 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5488 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5489 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
|
5490 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5491 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
|
5492 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
|
5493 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5494 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5495 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5496 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5497 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5498 } |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5499 |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5500 #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
|
5501 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
|
5502 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5503 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5504 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
|
5505 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5506 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5507 /* 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
|
5508 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5509 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5510 /* 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
|
5511 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5512 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5513 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5514 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5515 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
|
5516 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
|
5517 change_cnt), change_cnt); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5518 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5519 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5520 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5521 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5522 * 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
|
5523 * 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
|
5524 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5525 * 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
|
5526 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5527 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5528 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5529 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5530 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5531 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5532 linenr_T Prenum1) |
7 | 5533 { |
5534 int col; | |
5535 char_u *buf1; | |
5536 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5537 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5538 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5539 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5540 uvarnumber_T oldn; |
7 | 5541 char_u *ptr; |
5542 int c; | |
5543 int todel; | |
5544 int dohex; | |
5545 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5546 int dobin; |
7 | 5547 int doalp; |
5548 int firstdigit; | |
5549 int subtract; | |
6868 | 5550 int negative = FALSE; |
6891 | 5551 int was_positive = TRUE; |
6868 | 5552 int visual = VIsual_active; |
6921 | 5553 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5554 pos_T save_cursor = curwin->w_cursor; |
6927 | 5555 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5556 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5557 pos_T endpos; |
7 | 5558 |
5559 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5560 dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); /* "Octal" */ | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5561 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5562 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5563 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5564 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5565 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5566 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5567 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5568 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5569 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5570 |
7 | 5571 /* |
5572 * First check if we are on a hexadecimal number, after the "0x". | |
5573 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5574 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5575 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5576 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5577 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
|
5578 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5579 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5580 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5581 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
|
5582 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5583 |
6868 | 5584 if (dohex) |
5585 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
|
5586 { |
6868 | 5587 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5588 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5589 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
|
5590 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5591 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5592 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5593 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5594 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5595 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5596 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5597 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5598 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5599 !(*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
|
5600 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5601 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5602 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5603 /* 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
|
5604 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5605 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5606 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5607 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
|
5608 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5609 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5610 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5611 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
|
5612 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5613 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5614 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5615 if (( dohex |
6868 | 5616 && col > 0 |
5617 && (ptr[col] == 'X' | |
5618 || ptr[col] == 'x') | |
5619 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5620 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5621 !(*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
|
5622 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5623 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5624 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5625 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5626 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5627 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5628 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5629 !(*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
|
5630 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5631 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5632 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5633 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5634 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5635 col -= (*mb_head_off)(ptr, ptr + col); |
6868 | 5636 } |
5637 else | |
7 | 5638 { |
6868 | 5639 /* |
5640 * Search forward and then backward to find the start of number. | |
5641 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5642 col = pos->col; |
6868 | 5643 |
5644 while (ptr[col] != NUL | |
5645 && !vim_isdigit(ptr[col]) | |
5646 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5647 col += MB_PTR2LEN(ptr + col); |
6868 | 5648 |
5649 while (col > 0 | |
5650 && vim_isdigit(ptr[col - 1]) | |
5651 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5652 { |
6868 | 5653 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5654 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5655 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
|
5656 } |
6868 | 5657 } |
5658 } | |
5659 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5660 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5661 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5662 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5663 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5664 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5665 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5666 int mb_len = MB_PTR2LEN(ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5667 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5668 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5669 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5670 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5671 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5672 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5673 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5674 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5675 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
|
5676 && (!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
|
5677 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5678 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5679 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5680 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5681 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5682 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5683 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5684 * 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
|
5685 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5686 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5687 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
|
5688 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5689 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5690 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5691 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5692 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5693 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5694 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5695 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5696 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5697 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5698 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5699 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5700 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5701 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5702 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5703 firstdigit = 'a'; |
6927 | 5704 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5705 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5706 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5707 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5708 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5709 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5710 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5711 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5712 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5713 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5714 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5715 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5716 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5717 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5718 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5719 firstdigit = 'z'; |
6927 | 5720 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5721 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5722 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5723 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5724 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5725 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5726 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5727 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5728 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5729 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5730 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5731 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5732 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5733 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5734 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5735 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5736 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5737 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5738 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5739 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5740 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5741 !(*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
|
5742 && !visual) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5743 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5744 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5745 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5746 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5747 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5748 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5749 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5750 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
|
5751 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5752 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5753 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5754 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5755 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5756 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5757 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5758 NULL, &n, maxlen); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5759 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5760 /* 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
|
5761 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5762 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5763 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5764 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5765 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5766 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5767 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5768 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5769 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5770 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5771 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5772 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5773 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5774 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5775 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5776 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5777 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5778 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5779 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5780 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5781 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5782 if (subtract) |
6927 | 5783 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5784 if (n > oldn) |
6868 | 5785 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5786 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
|
5787 negative ^= TRUE; |
6868 | 5788 } |
7 | 5789 } |
5790 else | |
6868 | 5791 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5792 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5793 if (n < oldn) |
6868 | 5794 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5795 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5796 negative ^= TRUE; |
6868 | 5797 } |
6927 | 5798 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5799 if (n == 0) |
6868 | 5800 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5801 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5802 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5803 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
|
5804 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5805 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5806 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5807 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5808 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5809 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5810 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5811 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5812 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5813 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5814 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5816 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5818 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5819 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5820 * 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
|
5821 * 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
|
5822 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5823 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5824 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5825 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5826 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5827 if (c < 0x100 && isalpha(c)) |
6868 | 5828 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5829 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5830 hexupper = TRUE; |
6868 | 5831 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5832 hexupper = FALSE; |
6891 | 5833 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5834 /* 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
|
5835 (void)del_char(FALSE); |
6868 | 5836 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5837 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5838 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5839 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5840 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5841 * 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
|
5842 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5843 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5844 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5845 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5846 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5847 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
5848 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5849 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5850 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5851 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5852 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5853 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5854 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5855 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5856 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5857 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5858 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5859 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5861 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5862 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5863 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5864 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5865 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5866 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5867 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5868 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5869 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5870 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5871 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
|
5872 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5873 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5874 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5875 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5876 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5877 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5878 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
|
5879 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5880 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5881 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5882 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
|
5883 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
|
5884 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5885 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
|
5886 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
|
5887 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5888 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
|
5889 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
|
5890 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5891 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
|
5892 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
|
5893 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5894 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5895 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5896 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5897 * 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
|
5898 * 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
|
5899 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5900 * 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
|
5901 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5902 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5903 while (length-- > 0) |
6868 | 5904 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5905 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5906 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5907 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
|
5908 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5909 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5910 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
|
5911 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5912 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5913 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5914 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5915 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5916 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5917 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5918 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5919 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
|
5920 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5921 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5922 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5923 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5924 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5925 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5926 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5927 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5928 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5929 return did_change; |
7 | 5930 } |
5931 | |
5932 #ifdef FEAT_VIMINFO | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5933 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5934 static yankreg_T *y_read_regs = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5935 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5936 #define REG_PREVIOUS 1 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5937 #define REG_EXEC 2 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5938 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5939 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5940 * Prepare for reading viminfo registers when writing viminfo later. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5941 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5942 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
5943 prepare_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5944 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5945 y_read_regs = (yankreg_T *)alloc_clear(NUM_REGISTERS |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5946 * (int)sizeof(yankreg_T)); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5947 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5948 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5949 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
5950 finish_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5951 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5952 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5953 int j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5954 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5955 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5956 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5957 for (i = 0; i < NUM_REGISTERS; ++i) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5958 if (y_read_regs[i].y_array != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5959 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5960 for (j = 0; j < y_read_regs[i].y_size; j++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5961 vim_free(y_read_regs[i].y_array[j]); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5962 vim_free(y_read_regs[i].y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5963 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
5964 VIM_CLEAR(y_read_regs); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5965 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5966 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
5967 |
7 | 5968 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5969 read_viminfo_register(vir_T *virp, int force) |
7 | 5970 { |
5971 int eof; | |
5972 int do_it = TRUE; | |
5973 int size; | |
5974 int limit; | |
5975 int i; | |
5976 int set_prev = FALSE; | |
5977 char_u *str; | |
5978 char_u **array = NULL; | |
6508 | 5979 int new_type = MCHAR; /* init to shut up compiler */ |
5980 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 5981 |
5982 /* We only get here (hopefully) if line[0] == '"' */ | |
5983 str = virp->vir_line + 1; | |
1893 | 5984 |
5985 /* If the line starts with "" this is the y_previous register. */ | |
7 | 5986 if (*str == '"') |
5987 { | |
5988 set_prev = TRUE; | |
5989 str++; | |
5990 } | |
1893 | 5991 |
7 | 5992 if (!ASCII_ISALNUM(*str) && *str != '-') |
5993 { | |
5994 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
5995 return TRUE; /* too many errors, pretend end-of-file */ | |
5996 do_it = FALSE; | |
5997 } | |
5998 get_yank_register(*str++, FALSE); | |
5999 if (!force && y_current->y_array != NULL) | |
6000 do_it = FALSE; | |
1893 | 6001 |
6002 if (*str == '@') | |
6003 { | |
6004 /* "x@: register x used for @@ */ | |
6005 if (force || execreg_lastc == NUL) | |
6006 execreg_lastc = str[-1]; | |
6007 } | |
6008 | |
7 | 6009 size = 0; |
6010 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
6011 if (do_it) | |
6012 { | |
6462 | 6013 /* |
6014 * Build the new register in array[]. | |
6015 * y_array is kept as-is until done. | |
6016 * The "do_it" flag is reset when something is wrong, in which case | |
6017 * array[] needs to be freed. | |
6018 */ | |
7 | 6019 if (set_prev) |
6020 y_previous = y_current; | |
6462 | 6021 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 6022 str = skipwhite(skiptowhite(str)); |
7 | 6023 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 6024 new_type = MCHAR; |
7 | 6025 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 6026 new_type = MBLOCK; |
7 | 6027 else |
6462 | 6028 new_type = MLINE; |
7 | 6029 /* get the block width; if it's missing we get a zero, which is OK */ |
6030 str = skipwhite(skiptowhite(str)); | |
6462 | 6031 new_width = getdigits(&str); |
7 | 6032 } |
6033 | |
6034 while (!(eof = viminfo_readline(virp)) | |
6035 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
6036 { | |
6037 if (do_it) | |
6038 { | |
6462 | 6039 if (size == limit) |
7 | 6040 { |
6462 | 6041 char_u **new_array = (char_u **) |
7 | 6042 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 6043 |
6044 if (new_array == NULL) | |
6045 { | |
6046 do_it = FALSE; | |
6047 break; | |
6048 } | |
7 | 6049 for (i = 0; i < limit; i++) |
6462 | 6050 new_array[i] = array[i]; |
7 | 6051 vim_free(array); |
6462 | 6052 array = new_array; |
7 | 6053 limit *= 2; |
6054 } | |
6055 str = viminfo_readstring(virp, 1, TRUE); | |
6056 if (str != NULL) | |
6057 array[size++] = str; | |
6058 else | |
6462 | 6059 /* error, don't store the result */ |
7 | 6060 do_it = FALSE; |
6061 } | |
6062 } | |
6508 | 6063 |
7 | 6064 if (do_it) |
6065 { | |
6462 | 6066 /* free y_array[] */ |
6067 for (i = 0; i < y_current->y_size; i++) | |
6068 vim_free(y_current->y_array[i]); | |
6069 vim_free(y_current->y_array); | |
6070 | |
6071 y_current->y_type = new_type; | |
6072 y_current->y_width = new_width; | |
6073 y_current->y_size = size; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6074 y_current->y_time_set = 0; |
7 | 6075 if (size == 0) |
6076 { | |
6077 y_current->y_array = NULL; | |
6078 } | |
6462 | 6079 else |
7 | 6080 { |
6462 | 6081 /* Move the lines from array[] to y_array[]. */ |
7 | 6082 y_current->y_array = |
6083 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
6084 for (i = 0; i < size; i++) | |
6462 | 6085 { |
6086 if (y_current->y_array == NULL) | |
6087 vim_free(array[i]); | |
6088 else | |
6089 y_current->y_array[i] = array[i]; | |
6090 } | |
7 | 6091 } |
6462 | 6092 } |
6093 else | |
6094 { | |
6095 /* Free array[] if it was filled. */ | |
6096 for (i = 0; i < size; i++) | |
6097 vim_free(array[i]); | |
6098 } | |
6099 vim_free(array); | |
6100 | |
7 | 6101 return eof; |
6102 } | |
6103 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6104 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6105 * Accept a new style register line from the viminfo, store it when it's new. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6106 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6107 void |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6108 handle_viminfo_register(garray_T *values, int force) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6109 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6110 bval_T *vp = (bval_T *)values->ga_data; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6111 int flags; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6112 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6113 int type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6114 int linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6115 int width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6116 time_t timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6117 yankreg_T *y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6118 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6119 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6120 /* Check the format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6121 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6122 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6123 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6124 if (values->ga_len < 6 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6125 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6126 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6127 || vp[2].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6128 || vp[3].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6129 || vp[4].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6130 || vp[5].bv_type != BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6131 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6132 flags = vp[0].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6133 name = vp[1].bv_nr; |
9307
eb52a2670c96
commit https://github.com/vim/vim/commit/67e3720a9ddd8a9d2e8344358c28fa1f4196db0d
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
6134 if (name < 0 || name >= NUM_REGISTERS) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6135 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6136 type = vp[2].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6137 if (type != MCHAR && type != MLINE && type != MBLOCK) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6138 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6139 linecount = vp[3].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6140 if (values->ga_len < 6 + linecount) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6141 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6142 width = vp[4].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6143 if (width < 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6144 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6145 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6146 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6147 /* Reading viminfo for merging and writing. Store the register |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6148 * content, don't update the current registers. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6149 y_ptr = &y_read_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6150 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6151 y_ptr = &y_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6152 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6153 /* Do not overwrite unless forced or the timestamp is newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6154 timestamp = (time_t)vp[5].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6155 if (y_ptr->y_array != NULL && !force |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6156 && (timestamp == 0 || y_ptr->y_time_set > timestamp)) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6157 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6158 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6159 if (y_ptr->y_array != NULL) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6160 for (i = 0; i < y_ptr->y_size; i++) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6161 vim_free(y_ptr->y_array[i]); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6162 vim_free(y_ptr->y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6163 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6164 if (y_read_regs == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6165 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6166 if (flags & REG_PREVIOUS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6167 y_previous = y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6168 if ((flags & REG_EXEC) && (force || execreg_lastc == NUL)) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6169 execreg_lastc = get_register_name(name); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6170 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6171 y_ptr->y_type = type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6172 y_ptr->y_width = width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6173 y_ptr->y_size = linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6174 y_ptr->y_time_set = timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6175 if (linecount == 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6176 y_ptr->y_array = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6177 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6178 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6179 y_ptr->y_array = |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6180 (char_u **)alloc((unsigned)(linecount * sizeof(char_u *))); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6181 for (i = 0; i < linecount; i++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6182 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6183 if (vp[i + 6].bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6184 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6185 y_ptr->y_array[i] = vp[i + 6].bv_string; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6186 vp[i + 6].bv_string = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6187 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6188 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6189 y_ptr->y_array[i] = vim_strsave(vp[i + 6].bv_string); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6190 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6191 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6192 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6193 |
7 | 6194 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6195 write_viminfo_registers(FILE *fp) |
7 | 6196 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6197 int i, j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6198 char_u *type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6199 char_u c; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6200 int num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6201 int max_num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6202 int max_kbyte; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6203 long len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6204 yankreg_T *y_ptr; |
7 | 6205 |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6206 fputs(_("\n# Registers:\n"), fp); |
7 | 6207 |
6208 /* Get '<' value, use old '"' value if '<' is not found. */ | |
6209 max_num_lines = get_viminfo_parameter('<'); | |
6210 if (max_num_lines < 0) | |
6211 max_num_lines = get_viminfo_parameter('"'); | |
6212 if (max_num_lines == 0) | |
6213 return; | |
6214 max_kbyte = get_viminfo_parameter('s'); | |
6215 if (max_kbyte == 0) | |
6216 return; | |
1893 | 6217 |
7 | 6218 for (i = 0; i < NUM_REGISTERS; i++) |
6219 { | |
6220 #ifdef FEAT_CLIPBOARD | |
6221 /* Skip '*'/'+' register, we don't want them back next time */ | |
6222 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
6223 continue; | |
6224 #endif | |
6225 #ifdef FEAT_DND | |
6226 /* Neither do we want the '~' register */ | |
6227 if (i == TILDE_REGISTER) | |
6228 continue; | |
6229 #endif | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6230 /* When reading viminfo for merging and writing: Use the register from |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6231 * viminfo if it's newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6232 if (y_read_regs != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6233 && y_read_regs[i].y_array != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6234 && (y_regs[i].y_array == NULL || |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6235 y_read_regs[i].y_time_set > y_regs[i].y_time_set)) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6236 y_ptr = &y_read_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6237 else if (y_regs[i].y_array == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6238 continue; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6239 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6240 y_ptr = &y_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6241 |
55 | 6242 /* Skip empty registers. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6243 num_lines = y_ptr->y_size; |
55 | 6244 if (num_lines == 0 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6245 || (num_lines == 1 && y_ptr->y_type == MCHAR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6246 && *y_ptr->y_array[0] == NUL)) |
55 | 6247 continue; |
6248 | |
7 | 6249 if (max_kbyte > 0) |
6250 { | |
6251 /* Skip register if there is more text than the maximum size. */ | |
6252 len = 0; | |
6253 for (j = 0; j < num_lines; j++) | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6254 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
7 | 6255 if (len > (long)max_kbyte * 1024L) |
6256 continue; | |
6257 } | |
6258 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6259 switch (y_ptr->y_type) |
7 | 6260 { |
6261 case MLINE: | |
6262 type = (char_u *)"LINE"; | |
6263 break; | |
6264 case MCHAR: | |
6265 type = (char_u *)"CHAR"; | |
6266 break; | |
6267 case MBLOCK: | |
6268 type = (char_u *)"BLOCK"; | |
6269 break; | |
6270 default: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6271 semsg(_("E574: Unknown register type %d"), y_ptr->y_type); |
7 | 6272 type = (char_u *)"LINE"; |
6273 break; | |
6274 } | |
6275 if (y_previous == &y_regs[i]) | |
6276 fprintf(fp, "\""); | |
6277 c = get_register_name(i); | |
1893 | 6278 fprintf(fp, "\"%c", c); |
6279 if (c == execreg_lastc) | |
6280 fprintf(fp, "@"); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6281 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
7 | 6282 |
6283 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
6284 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6285 num_lines = max_num_lines; | |
6286 for (j = 0; j < num_lines; j++) | |
6287 { | |
6288 putc('\t', fp); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6289 viminfo_writestring(fp, y_ptr->y_array[j]); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6290 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6291 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6292 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6293 int flags = 0; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6294 int remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6295 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6296 /* New style with a bar line. Format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6297 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6298 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6299 * flags: REG_PREVIOUS - register is y_previous |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
6300 * REG_EXEC - used for @@ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6301 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6302 if (y_previous == &y_regs[i]) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6303 flags |= REG_PREVIOUS; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6304 if (c == execreg_lastc) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6305 flags |= REG_EXEC; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6306 fprintf(fp, "|%d,%d,%d,%d,%d,%d,%ld", BARTYPE_REGISTER, flags, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6307 i, y_ptr->y_type, num_lines, (int)y_ptr->y_width, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6308 (long)y_ptr->y_time_set); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6309 /* 11 chars for type/flags/name/type, 3 * 20 for numbers */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6310 remaining = LSIZE - 71; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6311 for (j = 0; j < num_lines; j++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6312 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6313 putc(',', fp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6314 --remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6315 remaining = barline_writestring(fp, y_ptr->y_array[j], |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6316 remaining); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6317 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6318 putc('\n', fp); |
7 | 6319 } |
6320 } | |
6321 } | |
6322 #endif /* FEAT_VIMINFO */ | |
6323 | |
6324 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6325 /* | |
6326 * SELECTION / PRIMARY ('*') | |
6327 * | |
6328 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6329 * GUI this may be text from another window, otherwise it is the last text we | |
6330 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6331 * button performs the paste, otherwise you will need to do <"*p>. " | |
6332 * If not under X, it is synonymous with the clipboard register '+'. | |
6333 * | |
6334 * X CLIPBOARD ('+') | |
6335 * | |
6336 * Text selection stuff that uses the GUI clipboard register '+'. | |
6337 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6338 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6339 * otherwise you will need to do <"+p>. " | |
6340 * If not under X, it is synonymous with the selection register '*'. | |
6341 */ | |
6342 | |
6343 /* | |
6344 * 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
|
6345 * so that the text is still available after Vim has exited. X selections |
7 | 6346 * only exist while the owning application exists, so we write to the |
6347 * permanent (while X runs) store CUT_BUFFER0. | |
6348 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6349 * 'permanent' of the two), otherwise the PRIMARY one. | |
6350 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6351 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6352 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 6353 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6354 x11_export_final_selection(void) |
7 | 6355 { |
6356 Display *dpy; | |
6357 char_u *str = NULL; | |
6358 long_u len = 0; | |
6359 int motion_type = -1; | |
6360 | |
6361 # ifdef FEAT_GUI | |
6362 if (gui.in_use) | |
6363 dpy = X_DISPLAY; | |
6364 else | |
6365 # endif | |
6366 # ifdef FEAT_XCLIPBOARD | |
6367 dpy = xterm_dpy; | |
6368 # else | |
6369 return; | |
6370 # endif | |
6371 | |
6372 /* Get selection to export */ | |
6373 if (clip_plus.owned) | |
6374 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6375 else if (clip_star.owned) | |
6376 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6377 | |
6378 /* Check it's OK */ | |
6379 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6380 && len < 1024*1024 && len > 0) | |
6381 { | |
4201 | 6382 int ok = TRUE; |
6383 | |
1924 | 6384 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6385 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6386 * encoding conversion usually doesn't work, so keep the text as-is. | |
6387 */ | |
6388 if (has_mbyte) | |
6389 { | |
6390 vimconv_T vc; | |
6391 | |
6392 vc.vc_type = CONV_NONE; | |
6393 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6394 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6395 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6396 char_u *conv_str; |
2007 | 6397 |
4201 | 6398 vc.vc_fail = TRUE; |
2007 | 6399 conv_str = string_convert(&vc, str, &intlen); |
6400 len = intlen; | |
1924 | 6401 if (conv_str != NULL) |
6402 { | |
6403 vim_free(str); | |
6404 str = conv_str; | |
6405 } | |
4201 | 6406 else |
6407 { | |
6408 ok = FALSE; | |
6409 } | |
1924 | 6410 convert_setup(&vc, NULL, NULL); |
6411 } | |
4201 | 6412 else |
6413 { | |
6414 ok = FALSE; | |
6415 } | |
1924 | 6416 } |
4201 | 6417 |
6418 /* Do not store the string if conversion failed. Better to use any | |
6419 * other selection than garbled text. */ | |
6420 if (ok) | |
6421 { | |
6422 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6423 XFlush(dpy); | |
6424 } | |
7 | 6425 } |
6426 | |
6427 vim_free(str); | |
6428 } | |
6429 #endif | |
6430 | |
6431 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6432 clip_free_selection(VimClipboard *cbd) |
7 | 6433 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6434 yankreg_T *y_ptr = y_current; |
7 | 6435 |
6436 if (cbd == &clip_plus) | |
6437 y_current = &y_regs[PLUS_REGISTER]; | |
6438 else | |
6439 y_current = &y_regs[STAR_REGISTER]; | |
6440 free_yank_all(); | |
6441 y_current->y_size = 0; | |
6442 y_current = y_ptr; | |
6443 } | |
6444 | |
6445 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
6446 * Get the selected text and put it in register '*' or '+'. |
7 | 6447 */ |
6448 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6449 clip_get_selection(VimClipboard *cbd) |
7 | 6450 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6451 yankreg_T *old_y_previous, *old_y_current; |
7 | 6452 pos_T old_cursor; |
6453 pos_T old_visual; | |
6454 int old_visual_mode; | |
6455 colnr_T old_curswant; | |
6456 int old_set_curswant; | |
6457 pos_T old_op_start, old_op_end; | |
6458 oparg_T oa; | |
6459 cmdarg_T ca; | |
6460 | |
6461 if (cbd->owned) | |
6462 { | |
6463 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6464 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6465 return; | |
6466 | |
6467 /* Get the text between clip_star.start & clip_star.end */ | |
6468 old_y_previous = y_previous; | |
6469 old_y_current = y_current; | |
6470 old_cursor = curwin->w_cursor; | |
6471 old_curswant = curwin->w_curswant; | |
6472 old_set_curswant = curwin->w_set_curswant; | |
6473 old_op_start = curbuf->b_op_start; | |
6474 old_op_end = curbuf->b_op_end; | |
6475 old_visual = VIsual; | |
6476 old_visual_mode = VIsual_mode; | |
6477 clear_oparg(&oa); | |
6478 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6479 oa.op_type = OP_YANK; | |
6480 vim_memset(&ca, 0, sizeof(ca)); | |
6481 ca.oap = &oa; | |
6482 ca.cmdchar = 'y'; | |
6483 ca.count1 = 1; | |
6484 ca.retval = CA_NO_ADJ_OP_END; | |
6485 do_pending_operator(&ca, 0, TRUE); | |
6486 y_previous = old_y_previous; | |
6487 y_current = old_y_current; | |
6488 curwin->w_cursor = old_cursor; | |
688 | 6489 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6490 curwin->w_curswant = old_curswant; |
6491 curwin->w_set_curswant = old_set_curswant; | |
6492 curbuf->b_op_start = old_op_start; | |
6493 curbuf->b_op_end = old_op_end; | |
6494 VIsual = old_visual; | |
6495 VIsual_mode = old_visual_mode; | |
6496 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6497 else if (!is_clipboard_needs_update()) |
7 | 6498 { |
6499 clip_free_selection(cbd); | |
6500 | |
6501 /* Try to get selected text from another window */ | |
6502 clip_gen_request_selection(cbd); | |
6503 } | |
6504 } | |
6505 | |
2896 | 6506 /* |
6507 * Convert from the GUI selection string into the '*'/'+' register. | |
6508 */ | |
7 | 6509 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6510 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6511 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6512 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6513 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6514 VimClipboard *cbd) |
7 | 6515 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6516 yankreg_T *y_ptr; |
7 | 6517 |
6518 if (cbd == &clip_plus) | |
6519 y_ptr = &y_regs[PLUS_REGISTER]; | |
6520 else | |
6521 y_ptr = &y_regs[STAR_REGISTER]; | |
6522 | |
6523 clip_free_selection(cbd); | |
6524 | |
5798 | 6525 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6526 } |
6527 | |
6528 /* | |
6529 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6530 * with length *len. | |
6531 * Returns the motion type, or -1 for failure. | |
6532 */ | |
6533 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6534 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6535 { |
6536 char_u *p; | |
6537 int lnum; | |
6538 int i, j; | |
6539 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6540 yankreg_T *y_ptr; |
7 | 6541 |
6542 if (cbd == &clip_plus) | |
6543 y_ptr = &y_regs[PLUS_REGISTER]; | |
6544 else | |
6545 y_ptr = &y_regs[STAR_REGISTER]; | |
6546 | |
6547 #ifdef USE_CRNL | |
6548 eolsize = 2; | |
6549 #else | |
6550 eolsize = 1; | |
6551 #endif | |
6552 | |
6553 *str = NULL; | |
6554 *len = 0; | |
6555 if (y_ptr->y_array == NULL) | |
6556 return -1; | |
6557 | |
6558 for (i = 0; i < y_ptr->y_size; i++) | |
6559 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6560 | |
6561 /* | |
6562 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6563 */ | |
6564 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6565 *len -= eolsize; | |
6566 | |
6567 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6568 if (p == NULL) | |
6569 return -1; | |
6570 lnum = 0; | |
6571 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6572 { | |
6573 if (y_ptr->y_array[lnum][j] == '\n') | |
6574 p[i] = NUL; | |
6575 else if (y_ptr->y_array[lnum][j] == NUL) | |
6576 { | |
6577 #ifdef USE_CRNL | |
6578 p[i++] = '\r'; | |
6579 #endif | |
6580 p[i] = '\n'; | |
6581 lnum++; | |
6582 j = -1; | |
6583 } | |
6584 else | |
6585 p[i] = y_ptr->y_array[lnum][j]; | |
6586 } | |
6587 return y_ptr->y_type; | |
6588 } | |
6589 | |
6590 | |
6591 /* | |
6592 * If we have written to a clipboard register, send the text to the clipboard. | |
6593 */ | |
6594 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6595 may_set_selection(void) |
7 | 6596 { |
6597 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6598 { | |
6599 clip_own_selection(&clip_star); | |
6600 clip_gen_set_selection(&clip_star); | |
6601 } | |
6602 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6603 { | |
6604 clip_own_selection(&clip_plus); | |
6605 clip_gen_set_selection(&clip_plus); | |
6606 } | |
6607 } | |
6608 | |
6609 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6610 | |
6611 | |
6612 #if defined(FEAT_DND) || defined(PROTO) | |
6613 /* | |
6614 * Replace the contents of the '~' register with str. | |
6615 */ | |
6616 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6617 dnd_yank_drag_data(char_u *str, long len) |
7 | 6618 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6619 yankreg_T *curr; |
7 | 6620 |
6621 curr = y_current; | |
6622 y_current = &y_regs[TILDE_REGISTER]; | |
6623 free_yank_all(); | |
5798 | 6624 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6625 y_current = curr; |
6626 } | |
6627 #endif | |
6628 | |
6629 | |
6630 #if defined(FEAT_EVAL) || defined(PROTO) | |
6631 /* | |
6632 * Return the type of a register. | |
6633 * Used for getregtype() | |
6634 * Returns MAUTO for error. | |
6635 */ | |
6636 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6637 get_reg_type(int regname, long *reglen) |
7 | 6638 { |
6639 switch (regname) | |
6640 { | |
6641 case '%': /* file name */ | |
6642 case '#': /* alternate file name */ | |
6643 case '=': /* expression */ | |
6644 case ':': /* last command line */ | |
6645 case '/': /* last search-pattern */ | |
6646 case '.': /* last inserted text */ | |
6647 #ifdef FEAT_SEARCHPATH | |
6648 case Ctrl_F: /* Filename under cursor */ | |
6649 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6650 #endif | |
6651 case Ctrl_W: /* word under cursor */ | |
6652 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6653 case '_': /* black hole: always empty */ | |
6654 return MCHAR; | |
6655 } | |
6656 | |
6657 #ifdef FEAT_CLIPBOARD | |
6658 regname = may_get_selection(regname); | |
6659 #endif | |
6660 | |
5596 | 6661 if (regname != NUL && !valid_yank_reg(regname, FALSE)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
6662 return MAUTO; |
5596 | 6663 |
7 | 6664 get_yank_register(regname, FALSE); |
6665 | |
6666 if (y_current->y_array != NULL) | |
6667 { | |
6668 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6669 *reglen = y_current->y_width; | |
6670 return y_current->y_type; | |
6671 } | |
6672 return MAUTO; | |
6673 } | |
6674 | |
5796 | 6675 /* |
6676 * When "flags" has GREG_LIST return a list with text "s". | |
6677 * Otherwise just return "s". | |
6678 */ | |
6679 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6680 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6681 { |
6682 if (flags & GREG_LIST) | |
6683 { | |
6684 list_T *list = list_alloc(); | |
6685 | |
6686 if (list != NULL) | |
6687 { | |
6688 if (list_append_string(list, NULL, -1) == FAIL) | |
6689 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6690 list_free(list); |
5796 | 6691 return NULL; |
6692 } | |
6693 list->lv_first->li_tv.vval.v_string = s; | |
6694 } | |
6695 return (char_u *)list; | |
6696 } | |
6697 return s; | |
6698 } | |
6699 | |
7 | 6700 /* |
6701 * Return the contents of a register as a single allocated string. | |
6702 * Used for "@r" in expressions and for getreg(). | |
6703 * Returns NULL for error. | |
5796 | 6704 * Flags: |
6705 * GREG_NO_EXPR Do not allow expression register | |
6706 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6707 * not the result of its evaluation. | |
6708 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6709 */ |
6710 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6711 get_reg_contents(int regname, int flags) |
7 | 6712 { |
6713 long i; | |
6714 char_u *retval; | |
6715 int allocated; | |
6716 long len; | |
6717 | |
6718 /* Don't allow using an expression register inside an expression */ | |
6719 if (regname == '=') | |
6720 { | |
5796 | 6721 if (flags & GREG_NO_EXPR) |
6722 return NULL; | |
6723 if (flags & GREG_EXPR_SRC) | |
6724 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6725 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6726 } |
6727 | |
6728 if (regname == '@') /* "@@" is used for unnamed register */ | |
6729 regname = '"'; | |
6730 | |
6731 /* check for valid regname */ | |
6732 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6733 return NULL; | |
6734 | |
6735 #ifdef FEAT_CLIPBOARD | |
6736 regname = may_get_selection(regname); | |
6737 #endif | |
6738 | |
6739 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6740 { | |
6741 if (retval == NULL) | |
6742 return NULL; | |
5796 | 6743 if (allocated) |
6744 return getreg_wrap_one_line(retval, flags); | |
6745 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6746 } |
6747 | |
6748 get_yank_register(regname, FALSE); | |
6749 if (y_current->y_array == NULL) | |
6750 return NULL; | |
6751 | |
5796 | 6752 if (flags & GREG_LIST) |
6753 { | |
6754 list_T *list = list_alloc(); | |
6755 int error = FALSE; | |
6756 | |
6757 if (list == NULL) | |
6758 return NULL; | |
6759 for (i = 0; i < y_current->y_size; ++i) | |
6760 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6761 error = TRUE; | |
6762 if (error) | |
6763 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6764 list_free(list); |
5796 | 6765 return NULL; |
6766 } | |
6767 return (char_u *)list; | |
6768 } | |
6769 | |
7 | 6770 /* |
6771 * Compute length of resulting string. | |
6772 */ | |
6773 len = 0; | |
6774 for (i = 0; i < y_current->y_size; ++i) | |
6775 { | |
6776 len += (long)STRLEN(y_current->y_array[i]); | |
6777 /* | |
6778 * Insert a newline between lines and after last line if | |
6779 * y_type is MLINE. | |
6780 */ | |
6781 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6782 ++len; | |
6783 } | |
6784 | |
6785 retval = lalloc(len + 1, TRUE); | |
6786 | |
6787 /* | |
6788 * Copy the lines of the yank register into the string. | |
6789 */ | |
6790 if (retval != NULL) | |
6791 { | |
6792 len = 0; | |
6793 for (i = 0; i < y_current->y_size; ++i) | |
6794 { | |
6795 STRCPY(retval + len, y_current->y_array[i]); | |
6796 len += (long)STRLEN(retval + len); | |
6797 | |
6798 /* | |
6799 * Insert a NL between lines and after the last line if y_type is | |
6800 * MLINE. | |
6801 */ | |
6802 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6803 retval[len++] = '\n'; | |
6804 } | |
6805 retval[len] = NUL; | |
6806 } | |
6807 | |
6808 return retval; | |
6809 } | |
6810 | |
5798 | 6811 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6812 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6813 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6814 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6815 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6816 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6817 int *yank_type UNUSED) |
5798 | 6818 { |
6819 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6820 { | |
6821 emsg_invreg(name); | |
6822 return FAIL; | |
6823 } | |
6824 | |
6825 /* Don't want to change the current (unnamed) register */ | |
6826 *old_y_previous = y_previous; | |
6827 *old_y_current = y_current; | |
6828 | |
6829 get_yank_register(name, TRUE); | |
6830 if (!y_append && !must_append) | |
6831 free_yank_all(); | |
6832 return OK; | |
6833 } | |
6834 | |
6835 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6836 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6837 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6838 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6839 yankreg_T *old_y_current) |
5798 | 6840 { |
6841 # ifdef FEAT_CLIPBOARD | |
6842 /* Send text of clipboard register to the clipboard. */ | |
6843 may_set_selection(); | |
6844 # endif | |
6845 | |
6846 /* ':let @" = "val"' should change the meaning of the "" register */ | |
6847 if (name != '"') | |
6848 y_previous = old_y_previous; | |
6849 y_current = old_y_current; | |
6850 } | |
6851 | |
7 | 6852 /* |
6853 * Store string "str" in register "name". | |
6854 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
6855 * If "must_append" is TRUE, always append to the register. Otherwise append | |
6856 * if "name" is an uppercase letter. | |
6857 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
6858 * Careful: 'str' is modified, you may have to use a copy! | |
6859 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
6860 */ | |
6861 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6862 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6863 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6864 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6865 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6866 int must_append) |
7 | 6867 { |
6868 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
6869 } | |
6870 | |
6871 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6872 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6873 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6874 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6875 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6876 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6877 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6878 long block_len) |
5798 | 6879 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6880 yankreg_T *old_y_previous, *old_y_current; |
5798 | 6881 |
6882 if (name == '/' | |
6883 #ifdef FEAT_EVAL | |
6884 || name == '=' | |
6885 #endif | |
6886 ) | |
6887 { | |
6888 char_u *s; | |
6889 | |
6890 if (strings[0] == NULL) | |
6891 s = (char_u *)""; | |
6892 else if (strings[1] != NULL) | |
6893 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6894 emsg(_("E883: search pattern and expression register may not " |
5798 | 6895 "contain two or more lines")); |
6896 return; | |
6897 } | |
6898 else | |
6899 s = strings[0]; | |
6900 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
6901 return; | |
6902 } | |
6903 | |
6904 if (name == '_') /* black hole: nothing to do */ | |
6905 return; | |
6906 | |
6907 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
6908 &yank_type) == FAIL) | |
6909 return; | |
6910 | |
6911 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
6912 | |
6913 finish_write_reg(name, old_y_previous, old_y_current); | |
6914 } | |
6915 | |
6916 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6917 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6918 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6919 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6920 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6921 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6922 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6923 long block_len) |
7 | 6924 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6925 yankreg_T *old_y_previous, *old_y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6926 long len; |
7 | 6927 |
336 | 6928 if (maxlen >= 0) |
6929 len = maxlen; | |
6930 else | |
6931 len = (long)STRLEN(str); | |
6932 | |
7 | 6933 /* Special case: '/' search pattern */ |
6934 if (name == '/') | |
6935 { | |
6936 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
6937 return; | |
6938 } | |
6939 | |
6557 | 6940 if (name == '#') |
6941 { | |
6942 buf_T *buf; | |
6943 | |
6944 if (VIM_ISDIGIT(*str)) | |
6945 { | |
6946 int num = atoi((char *)str); | |
6947 | |
6948 buf = buflist_findnr(num); | |
6949 if (buf == NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6950 semsg(_(e_nobufnr), (long)num); |
6557 | 6951 } |
6952 else | |
6953 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
6954 TRUE, FALSE, FALSE)); | |
6955 if (buf == NULL) | |
6956 return; | |
6957 curwin->w_alt_fnum = buf->b_fnum; | |
6958 return; | |
6959 } | |
6960 | |
336 | 6961 #ifdef FEAT_EVAL |
6962 if (name == '=') | |
6963 { | |
6964 char_u *p, *s; | |
6965 | |
6966 p = vim_strnsave(str, (int)len); | |
6967 if (p == NULL) | |
6968 return; | |
6969 if (must_append) | |
6970 { | |
6971 s = concat_str(get_expr_line_src(), p); | |
6972 vim_free(p); | |
6973 p = s; | |
6974 } | |
6975 set_expr_line(p); | |
6976 return; | |
6977 } | |
6978 #endif | |
6979 | |
7 | 6980 if (name == '_') /* black hole: nothing to do */ |
6981 return; | |
6982 | |
5798 | 6983 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
6984 &yank_type) == FAIL) | |
6985 return; | |
6986 | |
6987 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
6988 | |
6989 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 6990 } |
6991 #endif /* FEAT_EVAL */ | |
6992 | |
6993 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
6994 /* | |
6995 * Put a string into a register. When the register is not empty, the string | |
6996 * is appended. | |
6997 */ | |
6998 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6999 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7000 yankreg_T *y_ptr, /* pointer to yank register */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7001 int yank_type, /* MCHAR, MLINE, MBLOCK, MAUTO */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7002 char_u *str, /* string to put in register */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7003 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7004 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7005 int str_list) /* TRUE if str is char_u ** */ |
7 | 7006 { |
2896 | 7007 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 7008 int lnum; |
7009 long start; | |
7010 long i; | |
7011 int extra; | |
7012 int newlines; /* number of lines added */ | |
7013 int extraline = 0; /* extra line at the end */ | |
7014 int append = FALSE; /* append to last line in register */ | |
7015 char_u *s; | |
5798 | 7016 char_u **ss; |
7 | 7017 char_u **pp; |
7018 long maxlen; | |
7019 | |
2000 | 7020 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 7021 y_ptr->y_size = 0; |
7022 | |
2896 | 7023 if (yank_type == MAUTO) |
5798 | 7024 type = ((str_list || (len > 0 && (str[len - 1] == NL |
7025 || str[len - 1] == CAR))) | |
2896 | 7026 ? MLINE : MCHAR); |
7027 else | |
7028 type = yank_type; | |
7029 | |
7 | 7030 /* |
7031 * Count the number of lines within the string | |
7032 */ | |
7033 newlines = 0; | |
5798 | 7034 if (str_list) |
7035 { | |
7036 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 7037 ++newlines; |
5798 | 7038 } |
7039 else | |
7040 { | |
7041 for (i = 0; i < len; i++) | |
7042 if (str[i] == '\n') | |
7043 ++newlines; | |
7044 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
7045 { | |
7046 extraline = 1; | |
7047 ++newlines; /* count extra newline at the end */ | |
7048 } | |
7049 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
7050 { | |
7051 append = TRUE; | |
7052 --newlines; /* uncount newline when appending first line */ | |
7053 } | |
7 | 7054 } |
7055 | |
6807 | 7056 /* Without any lines make the register empty. */ |
7057 if (y_ptr->y_size + newlines == 0) | |
7058 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
7059 VIM_CLEAR(y_ptr->y_array); |
6807 | 7060 return; |
7061 } | |
7062 | |
7 | 7063 /* |
7064 * Allocate an array to hold the pointers to the new register lines. | |
7065 * If the register was not empty, move the existing lines to the new array. | |
7066 */ | |
7067 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
7068 * sizeof(char_u *), TRUE); | |
7069 if (pp == NULL) /* out of memory */ | |
7070 return; | |
7071 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
7072 pp[lnum] = y_ptr->y_array[lnum]; | |
7073 vim_free(y_ptr->y_array); | |
7074 y_ptr->y_array = pp; | |
7075 maxlen = 0; | |
7076 | |
7077 /* | |
7078 * Find the end of each line and save it into the array. | |
7079 */ | |
5798 | 7080 if (str_list) |
7081 { | |
7082 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 7083 { |
5856 | 7084 i = (long)STRLEN(*ss); |
5798 | 7085 pp[lnum] = vim_strnsave(*ss, i); |
7086 if (i > maxlen) | |
7087 maxlen = i; | |
7 | 7088 } |
5798 | 7089 } |
7090 else | |
7091 { | |
7092 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 7093 { |
5798 | 7094 for (i = start; i < len; ++i) /* find the end of the line */ |
7095 if (str[i] == '\n') | |
7096 break; | |
7097 i -= start; /* i is now length of line */ | |
7098 if (i > maxlen) | |
7099 maxlen = i; | |
7100 if (append) | |
7101 { | |
7102 --lnum; | |
7103 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
7104 } | |
7105 else | |
7106 extra = 0; | |
7107 s = alloc((unsigned)(i + extra + 1)); | |
7108 if (s == NULL) | |
7109 break; | |
7110 if (extra) | |
7111 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
7112 if (append) | |
7113 vim_free(y_ptr->y_array[lnum]); | |
7114 if (i) | |
7115 mch_memmove(s + extra, str + start, (size_t)i); | |
7116 extra += i; | |
7117 s[extra] = NUL; | |
7118 y_ptr->y_array[lnum++] = s; | |
7119 while (--extra >= 0) | |
7120 { | |
7121 if (*s == NUL) | |
7122 *s = '\n'; /* replace NUL with newline */ | |
7123 ++s; | |
7124 } | |
7125 append = FALSE; /* only first line is appended */ | |
7 | 7126 } |
7127 } | |
7128 y_ptr->y_type = type; | |
7129 y_ptr->y_size = lnum; | |
7130 if (type == MBLOCK) | |
7131 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
7132 else | |
7133 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7134 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7135 y_ptr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7136 #endif |
7 | 7137 } |
7138 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
7139 | |
7140 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7141 clear_oparg(oparg_T *oap) |
7 | 7142 { |
7143 vim_memset(oap, 0, sizeof(oparg_T)); | |
7144 } | |
7145 | |
7146 /* | |
161 | 7147 * Count the number of bytes, characters and "words" in a line. |
7 | 7148 * |
7149 * "Words" are counted by looking for boundaries between non-space and | |
7150 * space characters. (it seems to produce results that match 'wc'.) | |
7151 * | |
161 | 7152 * Return value is byte count; word count for the line is added to "*wc". |
7153 * Char count is added to "*cc". | |
7 | 7154 * |
7155 * The function will only examine the first "limit" characters in the | |
7156 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
7157 * case, eol_size will be added to the character count to account for | |
7158 * the size of the EOL character. | |
7159 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7160 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7161 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7162 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7163 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7164 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7165 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7166 int eol_size) |
7 | 7167 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7168 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7169 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7170 varnumber_T chars = 0; |
7 | 7171 int is_word = 0; |
7172 | |
3626 | 7173 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 7174 { |
7175 if (is_word) | |
7176 { | |
7177 if (vim_isspace(line[i])) | |
7178 { | |
7179 words++; | |
7180 is_word = 0; | |
7181 } | |
7182 } | |
7183 else if (!vim_isspace(line[i])) | |
7184 is_word = 1; | |
161 | 7185 ++chars; |
474 | 7186 i += (*mb_ptr2len)(line + i); |
7 | 7187 } |
7188 | |
7189 if (is_word) | |
7190 words++; | |
7191 *wc += words; | |
7192 | |
7193 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 7194 if (i < limit && line[i] == NUL) |
161 | 7195 { |
7 | 7196 i += eol_size; |
161 | 7197 chars += eol_size; |
7198 } | |
7199 *cc += chars; | |
7 | 7200 return i; |
7201 } | |
7202 | |
7203 /* | |
7204 * Give some info about the position of the cursor (for "g CTRL-G"). | |
7205 * In Visual mode, give some info about the selected region. (In this case, | |
7206 * 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
|
7207 * When "dict" is not NULL store the info there instead of showing it. |
7 | 7208 */ |
7209 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7210 cursor_pos_info(dict_T *dict) |
7 | 7211 { |
7212 char_u *p; | |
274 | 7213 char_u buf1[50]; |
7214 char_u buf2[40]; | |
7 | 7215 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7216 varnumber_T byte_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7217 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7218 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7219 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7220 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7221 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7222 varnumber_T word_count_cursor = 0; |
7 | 7223 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7224 varnumber_T last_check = 100000L; |
7 | 7225 long line_count_selected = 0; |
7226 pos_T min_pos, max_pos; | |
7227 oparg_T oparg; | |
7228 struct block_def bd; | |
7229 | |
7230 /* | |
7231 * Compute the length of the file in characters. | |
7232 */ | |
7233 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
7234 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7235 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7236 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
7237 msg(_(no_lines_msg)); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7238 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7239 } |
7 | 7240 } |
7241 else | |
7242 { | |
7243 if (get_fileformat(curbuf) == EOL_DOS) | |
7244 eol_size = 2; | |
7245 else | |
7246 eol_size = 1; | |
7247 | |
7248 if (VIsual_active) | |
7249 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
7250 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 7251 { |
7252 min_pos = VIsual; | |
7253 max_pos = curwin->w_cursor; | |
7254 } | |
7255 else | |
7256 { | |
7257 min_pos = curwin->w_cursor; | |
7258 max_pos = VIsual; | |
7259 } | |
7260 if (*p_sel == 'e' && max_pos.col > 0) | |
7261 --max_pos.col; | |
7262 | |
7263 if (VIsual_mode == Ctrl_V) | |
7264 { | |
1866 | 7265 #ifdef FEAT_LINEBREAK |
7266 char_u * saved_sbr = p_sbr; | |
7267 | |
7268 /* Make 'sbr' empty for a moment to get the correct size. */ | |
7269 p_sbr = empty_option; | |
7270 #endif | |
7 | 7271 oparg.is_VIsual = 1; |
7272 oparg.block_mode = TRUE; | |
7273 oparg.op_type = OP_NOP; | |
7274 getvcols(curwin, &min_pos, &max_pos, | |
688 | 7275 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 7276 #ifdef FEAT_LINEBREAK |
7277 p_sbr = saved_sbr; | |
7278 #endif | |
688 | 7279 if (curwin->w_curswant == MAXCOL) |
7280 oparg.end_vcol = MAXCOL; | |
7 | 7281 /* Swap the start, end vcol if needed */ |
7282 if (oparg.end_vcol < oparg.start_vcol) | |
7283 { | |
7284 oparg.end_vcol += oparg.start_vcol; | |
7285 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
7286 oparg.end_vcol -= oparg.start_vcol; | |
7287 } | |
7288 } | |
7289 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
7290 } | |
7291 | |
7292 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
7293 { | |
7294 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 7295 if (byte_count > last_check) |
7 | 7296 { |
7297 ui_breakcheck(); | |
7298 if (got_int) | |
7299 return; | |
161 | 7300 last_check = byte_count + 100000L; |
7 | 7301 } |
7302 | |
7303 /* Do extra processing for VIsual mode. */ | |
7304 if (VIsual_active | |
7305 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7306 { | |
45 | 7307 char_u *s = NULL; |
7308 long len = 0L; | |
7309 | |
7 | 7310 switch (VIsual_mode) |
7311 { | |
7312 case Ctrl_V: | |
7313 virtual_op = virtual_active(); | |
7314 block_prep(&oparg, &bd, lnum, 0); | |
7315 virtual_op = MAYBE; | |
45 | 7316 s = bd.textstart; |
7317 len = (long)bd.textlen; | |
7 | 7318 break; |
7319 case 'V': | |
45 | 7320 s = ml_get(lnum); |
7321 len = MAXCOL; | |
7 | 7322 break; |
7323 case 'v': | |
7324 { | |
7325 colnr_T start_col = (lnum == min_pos.lnum) | |
7326 ? min_pos.col : 0; | |
7327 colnr_T end_col = (lnum == max_pos.lnum) | |
7328 ? max_pos.col - start_col + 1 : MAXCOL; | |
7329 | |
45 | 7330 s = ml_get(lnum) + start_col; |
7331 len = end_col; | |
7 | 7332 } |
7333 break; | |
7334 } | |
45 | 7335 if (s != NULL) |
7336 { | |
161 | 7337 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7338 &char_count_cursor, len, eol_size); | |
45 | 7339 if (lnum == curbuf->b_ml.ml_line_count |
7340 && !curbuf->b_p_eol | |
6933 | 7341 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7342 && (long)STRLEN(s) < len) |
161 | 7343 byte_count_cursor -= eol_size; |
45 | 7344 } |
7 | 7345 } |
7346 else | |
7347 { | |
7348 /* In non-visual mode, check for the line the cursor is on */ | |
7349 if (lnum == curwin->w_cursor.lnum) | |
7350 { | |
7351 word_count_cursor += word_count; | |
161 | 7352 char_count_cursor += char_count; |
7353 byte_count_cursor = byte_count + | |
7354 line_count_info(ml_get(lnum), | |
7355 &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
|
7356 (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
|
7357 eol_size); |
7 | 7358 } |
7359 } | |
7360 /* Add to the running totals */ | |
161 | 7361 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
|
7362 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7363 eol_size); |
7 | 7364 } |
7365 | |
7366 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7367 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7368 byte_count -= eol_size; |
7 | 7369 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7370 if (dict == NULL) |
7 | 7371 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7372 if (VIsual_active) |
7 | 7373 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7374 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
|
7375 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7376 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
|
7377 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7378 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
|
7379 (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
|
7380 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7381 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7382 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7383 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7384 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
|
7385 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7386 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7387 _("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
|
7388 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7389 (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
|
7390 (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
|
7391 (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
|
7392 (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
|
7393 (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7394 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7395 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7396 _("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
|
7397 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7398 (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
|
7399 (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
|
7400 (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
|
7401 (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
|
7402 (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
|
7403 (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
|
7404 (long_long_T)byte_count); |
7 | 7405 } |
7406 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7407 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7408 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7409 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7410 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
|
7411 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7412 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
|
7413 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7414 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7415 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
|
7416 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7417 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7418 _("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
|
7419 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7420 (long)curwin->w_cursor.lnum, |
7 | 7421 (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
|
7422 (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
|
7423 (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
|
7424 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7425 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7426 _("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
|
7427 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7428 (long)curwin->w_cursor.lnum, |
161 | 7429 (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
|
7430 (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
|
7431 (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
|
7432 (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
|
7433 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7434 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7435 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7436 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7437 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7438 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
|
7439 _("(+%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
|
7440 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7441 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7442 /* 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
|
7443 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7444 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
|
7445 msg((char *)IObuff); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7446 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7447 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7448 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7449 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7450 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7451 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7452 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
|
7453 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
|
7454 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
|
7455 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
|
7456 byte_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7457 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
|
7458 char_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7459 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
|
7460 word_count_cursor); |
7 | 7461 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7462 #endif |
7 | 7463 } |