Mercurial > vim
annotate src/ops.c @ 15597:536dd2bc5ac9 v8.1.0806
patch 8.1.0806: too many #ifdefs
commit https://github.com/vim/vim/commit/fc3abf47fbe1e426f2b676c316c81ee9ff607075
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jan 24 15:54:21 2019 +0100
patch 8.1.0806: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_MBYTE, part 2.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 24 Jan 2019 16:00:08 +0100 |
parents | d89c5b339c2a |
children | 6f1c7e9a6393 |
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 #ifdef FEAT_VIRTUALEDIT |
1806 if (virtual_op) | |
1807 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1808 * marks as if it happened. */ | |
1809 goto setmarks; | |
1810 #endif | |
7 | 1811 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1812 beep_flush(); | |
1813 return OK; | |
1814 } | |
1815 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1816 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1817 * 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
|
1818 * 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
|
1819 * 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
|
1820 */ |
7 | 1821 if (oap->regname != '_') |
1822 { | |
1823 if (oap->regname != 0) | |
1824 { | |
1825 /* check for read-only register */ | |
1826 if (!valid_yank_reg(oap->regname, TRUE)) | |
1827 { | |
1828 beep_flush(); | |
1829 return OK; | |
1830 } | |
1831 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1832 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1833 did_yank = TRUE; | |
1834 } | |
1835 | |
1836 /* | |
1837 * Put deleted text into register 1 and shift number registers if the | |
1838 * delete contains a line break, or when a regname has been specified. | |
3782 | 1839 * Use the register name from before adjust_clip_reg() may have |
1840 * changed it. | |
7 | 1841 */ |
3782 | 1842 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1843 || oap->line_count > 1 || oap->use_reg_one) |
1844 { | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1845 shift_delete_registers(); |
7 | 1846 if (op_yank(oap, TRUE, FALSE) == OK) |
1847 did_yank = TRUE; | |
1848 } | |
1849 | |
3468 | 1850 /* Yank into small delete register when no named register specified |
1851 * and the delete is within one line. */ | |
1852 if (( | |
1853 #ifdef FEAT_CLIPBOARD | |
3584 | 1854 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1855 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1856 #endif |
1857 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1858 && oap->line_count == 1) |
1859 { | |
1860 oap->regname = '-'; | |
1861 get_yank_register(oap->regname, TRUE); | |
1862 if (op_yank(oap, TRUE, FALSE) == OK) | |
1863 did_yank = TRUE; | |
1864 oap->regname = 0; | |
1865 } | |
1866 | |
1867 /* | |
1868 * If there's too much stuff to fit in the yank register, then get a | |
1869 * confirmation before doing the delete. This is crude, but simple. | |
1870 * And it avoids doing a delete of something we can't put back if we | |
1871 * want. | |
1872 */ | |
1873 if (!did_yank) | |
1874 { | |
1875 int msg_silent_save = msg_silent; | |
1876 | |
1877 msg_silent = 0; /* must display the prompt */ | |
1878 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1879 msg_silent = msg_silent_save; | |
1880 if (n != 'y') | |
1881 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1882 emsg(_(e_abort)); |
7 | 1883 return FAIL; |
1884 } | |
1885 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1886 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1887 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1888 if (did_yank && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1889 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
|
1890 #endif |
7 | 1891 } |
1892 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1893 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1894 * 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
|
1895 */ |
7 | 1896 if (oap->block_mode) |
1897 { | |
1898 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1899 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1900 return FAIL; | |
1901 | |
1902 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1903 { | |
1904 block_prep(oap, &bd, lnum, TRUE); | |
1905 if (bd.textlen == 0) /* nothing to delete */ | |
1906 continue; | |
1907 | |
1908 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1909 if (lnum == curwin->w_cursor.lnum) | |
1910 { | |
1911 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1912 # ifdef FEAT_VIRTUALEDIT | |
1913 curwin->w_cursor.coladd = 0; | |
1914 # endif | |
1915 } | |
1916 | |
1917 /* n == number of chars deleted | |
1918 * If we delete a TAB, it may be replaced by several characters. | |
1919 * Thus the number of characters may increase! | |
1920 */ | |
1921 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1922 oldp = ml_get(lnum); | |
1923 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1924 if (newp == NULL) | |
1925 continue; | |
1926 /* copy up to deleted part */ | |
1927 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1928 /* insert spaces */ | |
6929 | 1929 vim_memset(newp + bd.textcol, ' ', |
7 | 1930 (size_t)(bd.startspaces + bd.endspaces)); |
1931 /* copy the part after the deleted part */ | |
1932 oldp += bd.textcol + bd.textlen; | |
1622 | 1933 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1934 /* replace the line */ |
1935 ml_replace(lnum, newp, FALSE); | |
1936 } | |
1937 | |
1938 check_cursor_col(); | |
1939 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1940 oap->end.lnum + 1, 0L); | |
1941 oap->line_count = 0; /* no lines deleted */ | |
1942 } | |
5735 | 1943 else if (oap->motion_type == MLINE) |
7 | 1944 { |
1945 if (oap->op_type == OP_CHANGE) | |
1946 { | |
1947 /* Delete the lines except the first one. Temporarily move the | |
1948 * cursor to the next line. Save the current line number, if the | |
1949 * last line is deleted it may be changed. | |
1950 */ | |
1951 if (oap->line_count > 1) | |
1952 { | |
1953 lnum = curwin->w_cursor.lnum; | |
1954 ++curwin->w_cursor.lnum; | |
1955 del_lines((long)(oap->line_count - 1), TRUE); | |
1956 curwin->w_cursor.lnum = lnum; | |
1957 } | |
1958 if (u_save_cursor() == FAIL) | |
1959 return FAIL; | |
1960 if (curbuf->b_p_ai) /* don't delete indent */ | |
1961 { | |
1962 beginline(BL_WHITE); /* cursor on first non-white */ | |
1963 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1964 ai_col = curwin->w_cursor.col; | |
1965 } | |
1966 else | |
1967 beginline(0); /* cursor in column 0 */ | |
1968 truncate_line(FALSE); /* delete the rest of the line */ | |
1969 /* leave cursor past last char in line */ | |
1970 if (oap->line_count > 1) | |
1971 u_clearline(); /* "U" command not possible after "2cc" */ | |
1972 } | |
1973 else | |
1974 { | |
1975 del_lines(oap->line_count, TRUE); | |
1976 beginline(BL_WHITE | BL_FIX); | |
1977 u_clearline(); /* "U" command not possible after "dd" */ | |
1978 } | |
1979 } | |
1980 else | |
1981 { | |
1982 #ifdef FEAT_VIRTUALEDIT | |
1983 if (virtual_op) | |
1984 { | |
1985 int endcol = 0; | |
1986 | |
1987 /* For virtualedit: break the tabs that are partly included. */ | |
1988 if (gchar_pos(&oap->start) == '\t') | |
1989 { | |
1990 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
1991 return FAIL; | |
1992 if (oap->line_count == 1) | |
1993 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
1994 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
1995 oap->start = curwin->w_cursor; | |
1996 if (oap->line_count == 1) | |
1997 { | |
1998 coladvance(endcol); | |
1999 oap->end.col = curwin->w_cursor.col; | |
2000 oap->end.coladd = curwin->w_cursor.coladd; | |
2001 curwin->w_cursor = oap->start; | |
2002 } | |
2003 } | |
2004 | |
2005 /* Break a tab only when it's included in the area. */ | |
2006 if (gchar_pos(&oap->end) == '\t' | |
2007 && (int)oap->end.coladd < oap->inclusive) | |
2008 { | |
2009 /* save last line for undo */ | |
2010 if (u_save((linenr_T)(oap->end.lnum - 1), | |
2011 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2012 return FAIL; | |
2013 curwin->w_cursor = oap->end; | |
2014 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
2015 oap->end = curwin->w_cursor; | |
2016 curwin->w_cursor = oap->start; | |
2017 } | |
2018 } | |
2019 #endif | |
2020 | |
2021 if (oap->line_count == 1) /* delete characters within one line */ | |
2022 { | |
2023 if (u_save_cursor() == FAIL) /* save line for undo */ | |
2024 return FAIL; | |
2025 | |
2026 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 2027 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 2028 && oap->op_type == OP_CHANGE |
2029 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 2030 && !oap->is_VIsual) |
7 | 2031 display_dollar(oap->end.col - !oap->inclusive); |
2032 | |
2033 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
2034 | |
2035 #ifdef FEAT_VIRTUALEDIT | |
2036 if (virtual_op) | |
2037 { | |
2038 /* fix up things for virtualedit-delete: | |
2039 * break the tabs which are going to get in our way | |
2040 */ | |
2041 char_u *curline = ml_get_curline(); | |
2042 int len = (int)STRLEN(curline); | |
2043 | |
2044 if (oap->end.coladd != 0 | |
2045 && (int)oap->end.col >= len - 1 | |
2046 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
2047 n++; | |
2048 /* Delete at least one char (e.g, when on a control char). */ | |
2049 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
2050 n = 1; | |
2051 | |
2052 /* When deleted a char in the line, reset coladd. */ | |
2053 if (gchar_cursor() != NUL) | |
2054 curwin->w_cursor.coladd = 0; | |
2055 } | |
2056 #endif | |
6826 | 2057 (void)del_bytes((long)n, !virtual_op, |
2058 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 2059 } |
2060 else /* delete characters between lines */ | |
2061 { | |
2062 pos_T curpos; | |
2063 | |
2064 /* save deleted and changed lines for undo */ | |
2065 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
2066 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
2067 return FAIL; | |
2068 | |
2069 truncate_line(TRUE); /* delete from cursor to end of line */ | |
2070 | |
2071 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
2072 ++curwin->w_cursor.lnum; | |
2073 del_lines((long)(oap->line_count - 2), FALSE); | |
2074 | |
6826 | 2075 /* delete from start of line until op_end */ |
2957 | 2076 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 2077 curwin->w_cursor.col = 0; |
2078 (void)del_bytes((long)n, !virtual_op, | |
2079 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
2080 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
2081 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 2082 } |
2083 } | |
2084 | |
2085 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
2086 | |
446 | 2087 #ifdef FEAT_VIRTUALEDIT |
2088 setmarks: | |
2089 #endif | |
7 | 2090 if (oap->block_mode) |
2091 { | |
2092 curbuf->b_op_end.lnum = oap->end.lnum; | |
2093 curbuf->b_op_end.col = oap->start.col; | |
2094 } | |
2095 else | |
2096 curbuf->b_op_end = oap->start; | |
2097 curbuf->b_op_start = oap->start; | |
2098 | |
2099 return OK; | |
2100 } | |
2101 | |
2102 /* | |
2103 * Adjust end of operating area for ending on a multi-byte character. | |
2104 * Used for deletion. | |
2105 */ | |
2106 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2107 mb_adjust_opend(oparg_T *oap) |
7 | 2108 { |
2109 char_u *p; | |
2110 | |
2111 if (oap->inclusive) | |
2112 { | |
2113 p = ml_get(oap->end.lnum); | |
2114 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2115 } | |
2116 } | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2117 |
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
|
2118 /* |
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 * 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
|
2120 * 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
|
2121 */ |
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 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
|
2123 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
|
2124 { |
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
|
2125 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
|
2126 |
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
|
2127 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
|
2128 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
|
2129 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
|
2130 /* 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
|
2131 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
|
2132 } |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2133 |
7 | 2134 /* |
2135 * Replace a whole area with one character. | |
2136 */ | |
2137 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2138 op_replace(oparg_T *oap, int c) |
7 | 2139 { |
2140 int n, numc; | |
2141 int num_chars; | |
2142 char_u *newp, *oldp; | |
2143 size_t oldlen; | |
2144 struct block_def bd; | |
5428 | 2145 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
|
2146 int had_ctrl_v_cr = FALSE; |
7 | 2147 |
2148 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2149 return OK; /* nothing to do */ | |
2150 | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2151 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
|
2152 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2153 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
|
2154 c = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2155 } |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2156 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
|
2157 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2158 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
|
2159 c = NL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2160 } |
5428 | 2161 |
7 | 2162 if (has_mbyte) |
2163 mb_adjust_opend(oap); | |
2164 | |
2165 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2166 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2167 return FAIL; | |
2168 | |
2169 /* | |
2170 * block mode replace | |
2171 */ | |
2172 if (oap->block_mode) | |
2173 { | |
2174 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2175 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2176 { | |
1982 | 2177 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2178 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2179 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2180 continue; /* nothing to replace */ | |
2181 | |
2182 /* n == number of extra chars required | |
2183 * If we split a TAB, it may be replaced by several characters. | |
2184 * Thus the number of characters may increase! | |
2185 */ | |
2186 #ifdef FEAT_VIRTUALEDIT | |
2187 /* If the range starts in virtual space, count the initial | |
2188 * coladd offset as part of "startspaces" */ | |
2189 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2190 { | |
2191 pos_T vpos; | |
2192 | |
1982 | 2193 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2194 getvpos(&vpos, oap->start_vcol); |
2195 bd.startspaces += vpos.coladd; | |
2196 n = bd.startspaces; | |
2197 } | |
2198 else | |
2199 #endif | |
2200 /* allow for pre spaces */ | |
2201 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2202 | |
2203 /* allow for post spp */ | |
2204 n += (bd.endspaces | |
2205 #ifdef FEAT_VIRTUALEDIT | |
2206 && !bd.is_oneChar | |
2207 #endif | |
2208 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2209 /* Figure out how many characters to replace. */ | |
2210 numc = oap->end_vcol - oap->start_vcol + 1; | |
2211 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2212 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2213 | |
2214 /* A double-wide character can be replaced only up to half the | |
2215 * times. */ | |
2216 if ((*mb_char2cells)(c) > 1) | |
2217 { | |
2218 if ((numc & 1) && !bd.is_short) | |
2219 { | |
2220 ++bd.endspaces; | |
2221 ++n; | |
2222 } | |
2223 numc = numc / 2; | |
2224 } | |
2225 | |
2226 /* Compute bytes needed, move character count to num_chars. */ | |
2227 num_chars = numc; | |
2228 numc *= (*mb_char2len)(c); | |
2229 /* oldlen includes textlen, so don't double count */ | |
2230 n += numc - bd.textlen; | |
2231 | |
2232 oldp = ml_get_curline(); | |
2233 oldlen = STRLEN(oldp); | |
2234 newp = alloc_check((unsigned)oldlen + 1 + n); | |
2235 if (newp == NULL) | |
2236 continue; | |
2237 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2238 /* copy up to deleted part */ | |
2239 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2240 oldp += bd.textcol + bd.textlen; | |
2241 /* insert pre-spaces */ | |
6929 | 2242 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2243 /* 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
|
2244 /* 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
|
2245 * literally. */ |
5428 | 2246 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
7 | 2247 { |
5428 | 2248 if (has_mbyte) |
2249 { | |
2250 n = (int)STRLEN(newp); | |
2251 while (--num_chars >= 0) | |
2252 n += (*mb_char2bytes)(c, newp + n); | |
2253 } | |
2254 else | |
6929 | 2255 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2256 if (!bd.is_short) |
2257 { | |
2258 /* insert post-spaces */ | |
6929 | 2259 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2260 /* copy the part after the changed part */ |
2261 STRMOVE(newp + STRLEN(newp), oldp); | |
2262 } | |
7 | 2263 } |
2264 else | |
2265 { | |
5428 | 2266 /* Replacing with \r or \n means splitting the line. */ |
5475 | 2267 after_p = alloc_check( |
2268 (unsigned)(oldlen + 1 + n - STRLEN(newp))); | |
5428 | 2269 if (after_p != NULL) |
2270 STRMOVE(after_p, oldp); | |
7 | 2271 } |
2272 /* replace the line */ | |
2273 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2274 if (after_p != NULL) |
2275 { | |
2276 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2277 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2278 oap->end.lnum++; | |
2279 vim_free(after_p); | |
2280 } | |
7 | 2281 } |
2282 } | |
2283 else | |
2284 { | |
2285 /* | |
2286 * MCHAR and MLINE motion replace. | |
2287 */ | |
2288 if (oap->motion_type == MLINE) | |
2289 { | |
2290 oap->start.col = 0; | |
2291 curwin->w_cursor.col = 0; | |
2292 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2293 if (oap->end.col) | |
2294 --oap->end.col; | |
2295 } | |
2296 else if (!oap->inclusive) | |
2297 dec(&(oap->end)); | |
2298 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2299 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 2300 { |
2301 n = gchar_cursor(); | |
2302 if (n != NUL) | |
2303 { | |
2304 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2305 { | |
2306 /* This is slow, but it handles replacing a single-byte | |
2307 * with a multi-byte and the other way around. */ | |
4203 | 2308 if (curwin->w_cursor.lnum == oap->end.lnum) |
2309 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
|
2310 replace_character(c); |
7 | 2311 } |
2312 else | |
2313 { | |
2314 #ifdef FEAT_VIRTUALEDIT | |
2315 if (n == TAB) | |
2316 { | |
2317 int end_vcol = 0; | |
2318 | |
2319 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2320 { | |
2321 /* oap->end has to be recalculated when | |
2322 * the tab breaks */ | |
2323 end_vcol = getviscol2(oap->end.col, | |
2324 oap->end.coladd); | |
2325 } | |
2326 coladvance_force(getviscol()); | |
2327 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2328 getvpos(&oap->end, end_vcol); | |
2329 } | |
2330 #endif | |
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
|
2331 PBYTE(curwin->w_cursor, c); |
7 | 2332 } |
2333 } | |
2334 #ifdef FEAT_VIRTUALEDIT | |
2335 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2336 { | |
2337 int virtcols = oap->end.coladd; | |
2338 | |
2339 if (curwin->w_cursor.lnum == oap->start.lnum | |
2340 && oap->start.col == oap->end.col && oap->start.coladd) | |
2341 virtcols -= oap->start.coladd; | |
2342 | |
2343 /* oap->end has been trimmed so it's effectively inclusive; | |
2344 * as a result an extra +1 must be counted so we don't | |
2345 * trample the NUL byte. */ | |
2346 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2347 curwin->w_cursor.col -= (virtcols + 1); | |
2348 for (; virtcols >= 0; virtcols--) | |
2349 { | |
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
|
2350 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
|
2351 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
|
2352 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
|
2353 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
|
2354 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
|
2355 break; |
7 | 2356 } |
2357 } | |
2358 #endif | |
2359 | |
2360 /* Advance to next character, stop at the end of the file. */ | |
2361 if (inc_cursor() == -1) | |
2362 break; | |
2363 } | |
2364 } | |
2365 | |
2366 curwin->w_cursor = oap->start; | |
2367 check_cursor(); | |
2368 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2369 | |
2370 /* Set "'[" and "']" marks. */ | |
2371 curbuf->b_op_start = oap->start; | |
2372 curbuf->b_op_end = oap->end; | |
2373 | |
2374 return OK; | |
2375 } | |
2376 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2377 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2378 |
7 | 2379 /* |
2380 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2381 */ | |
2382 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2383 op_tilde(oparg_T *oap) |
7 | 2384 { |
2385 pos_T pos; | |
2386 struct block_def bd; | |
1528 | 2387 int did_change = FALSE; |
7 | 2388 |
2389 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2390 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2391 return; | |
2392 | |
2393 pos = oap->start; | |
2394 if (oap->block_mode) /* Visual block mode */ | |
2395 { | |
2396 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2397 { | |
1766 | 2398 int one_change; |
2399 | |
7 | 2400 block_prep(oap, &bd, pos.lnum, FALSE); |
2401 pos.col = bd.textcol; | |
1766 | 2402 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2403 did_change |= one_change; | |
1525 | 2404 |
5735 | 2405 #ifdef FEAT_NETBEANS_INTG |
2210 | 2406 if (netbeans_active() && one_change) |
7 | 2407 { |
2408 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2409 | |
33 | 2410 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2411 (long)bd.textlen); | |
7 | 2412 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2413 &ptr[bd.textcol], bd.textlen); |
7 | 2414 } |
5735 | 2415 #endif |
7 | 2416 } |
2417 if (did_change) | |
2418 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2419 } | |
2420 else /* not block mode */ | |
2421 { | |
2422 if (oap->motion_type == MLINE) | |
2423 { | |
2424 oap->start.col = 0; | |
2425 pos.col = 0; | |
2426 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2427 if (oap->end.col) | |
2428 --oap->end.col; | |
2429 } | |
2430 else if (!oap->inclusive) | |
2431 dec(&(oap->end)); | |
2432 | |
1528 | 2433 if (pos.lnum == oap->end.lnum) |
2434 did_change = swapchars(oap->op_type, &pos, | |
2435 oap->end.col - pos.col + 1); | |
2436 else | |
2437 for (;;) | |
2438 { | |
2439 did_change |= swapchars(oap->op_type, &pos, | |
2440 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2441 (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
|
2442 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 2443 break; |
2444 } | |
7 | 2445 if (did_change) |
2446 { | |
2447 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2448 0L); | |
2449 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2450 if (netbeans_active() && did_change) |
7 | 2451 { |
2452 char_u *ptr; | |
2453 int count; | |
2454 | |
2455 pos = oap->start; | |
2456 while (pos.lnum < oap->end.lnum) | |
2457 { | |
2458 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2459 count = (int)STRLEN(ptr) - pos.col; |
33 | 2460 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2461 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2462 &ptr[pos.col], count); |
7 | 2463 pos.col = 0; |
2464 pos.lnum++; | |
2465 } | |
2466 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2467 count = oap->end.col - pos.col + 1; | |
33 | 2468 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2469 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2470 &ptr[pos.col], count); |
7 | 2471 } |
2472 #endif | |
2473 } | |
2474 } | |
2475 | |
2476 if (!did_change && oap->is_VIsual) | |
2477 /* No change: need to remove the Visual selection */ | |
2478 redraw_curbuf_later(INVERTED); | |
2479 | |
2480 /* | |
2481 * Set '[ and '] marks. | |
2482 */ | |
2483 curbuf->b_op_start = oap->start; | |
2484 curbuf->b_op_end = oap->end; | |
2485 | |
2486 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
|
2487 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
|
2488 oap->line_count), oap->line_count); |
7 | 2489 } |
2490 | |
2491 /* | |
1525 | 2492 * Invoke swapchar() on "length" bytes at position "pos". |
2493 * "pos" is advanced to just after the changed characters. | |
2494 * "length" is rounded up to include the whole last multi-byte character. | |
2495 * Also works correctly when the number of bytes changes. | |
2496 * Returns TRUE if some character was changed. | |
2497 */ | |
2498 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2499 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2500 { |
2501 int todo; | |
2502 int did_change = 0; | |
2503 | |
2504 for (todo = length; todo > 0; --todo) | |
2505 { | |
2506 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2507 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2508 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2509 |
1525 | 2510 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2511 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2512 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2513 } |
1525 | 2514 did_change |= swapchar(op_type, pos); |
2515 if (inc(pos) == -1) /* at end of file */ | |
2516 break; | |
2517 } | |
2518 return did_change; | |
2519 } | |
2520 | |
2521 /* | |
7 | 2522 * If op_type == OP_UPPER: make uppercase, |
2523 * if op_type == OP_LOWER: make lowercase, | |
2524 * if op_type == OP_ROT13: do rot13 encoding, | |
2525 * else swap case of character at 'pos' | |
2526 * returns TRUE when something actually changed. | |
2527 */ | |
2528 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2529 swapchar(int op_type, pos_T *pos) |
7 | 2530 { |
2531 int c; | |
2532 int nc; | |
2533 | |
2534 c = gchar_pos(pos); | |
2535 | |
2536 /* Only do rot13 encoding for ASCII characters. */ | |
2537 if (c >= 0x80 && op_type == OP_ROT13) | |
2538 return FALSE; | |
2539 | |
1525 | 2540 if (op_type == OP_UPPER && c == 0xdf |
2541 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2542 { |
2543 pos_T sp = curwin->w_cursor; | |
2544 | |
2545 /* Special handling of German sharp s: change to "SS". */ | |
2546 curwin->w_cursor = *pos; | |
2547 del_char(FALSE); | |
2548 ins_char('S'); | |
2549 ins_char('S'); | |
2550 curwin->w_cursor = sp; | |
2551 inc(pos); | |
2552 } | |
2553 | |
7 | 2554 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2555 return FALSE; | |
2556 nc = c; | |
2557 if (MB_ISLOWER(c)) | |
2558 { | |
2559 if (op_type == OP_ROT13) | |
2560 nc = ROT13(c, 'a'); | |
2561 else if (op_type != OP_LOWER) | |
2562 nc = MB_TOUPPER(c); | |
2563 } | |
2564 else if (MB_ISUPPER(c)) | |
2565 { | |
2566 if (op_type == OP_ROT13) | |
2567 nc = ROT13(c, 'A'); | |
2568 else if (op_type != OP_UPPER) | |
2569 nc = MB_TOLOWER(c); | |
2570 } | |
2571 if (nc != c) | |
2572 { | |
2573 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2574 { | |
2575 pos_T sp = curwin->w_cursor; | |
2576 | |
2577 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2578 /* 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
|
2579 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2580 ins_char(nc); |
2581 curwin->w_cursor = sp; | |
2582 } | |
2583 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
|
2584 PBYTE(*pos, nc); |
7 | 2585 return TRUE; |
2586 } | |
2587 return FALSE; | |
2588 } | |
2589 | |
2590 /* | |
2591 * op_insert - Insert and append operators for Visual mode. | |
2592 */ | |
2593 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2594 op_insert(oparg_T *oap, long count1) |
7 | 2595 { |
2596 long ins_len, pre_textlen = 0; | |
2597 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
2598 colnr_T ind_pre = 0, ind_post; |
7 | 2599 struct block_def bd; |
2600 int i; | |
6579 | 2601 pos_T t1; |
7 | 2602 |
2603 /* edit() changes this - record it for OP_APPEND */ | |
2604 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2605 | |
2606 /* vis block is still marked. Get rid of it now. */ | |
2607 curwin->w_cursor.lnum = oap->start.lnum; | |
2608 update_screen(INVERTED); | |
2609 | |
2610 if (oap->block_mode) | |
2611 { | |
2612 #ifdef FEAT_VIRTUALEDIT | |
2613 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2614 * doing block_prep(). When only "block" is used, virtual edit is | |
2615 * already disabled, but still need it when calling | |
2616 * coladvance_force(). */ | |
2617 if (curwin->w_cursor.coladd > 0) | |
2618 { | |
2619 int old_ve_flags = ve_flags; | |
2620 | |
2621 ve_flags = VE_ALL; | |
2622 if (u_save_cursor() == FAIL) | |
2623 return; | |
2624 coladvance_force(oap->op_type == OP_APPEND | |
2625 ? oap->end_vcol + 1 : getviscol()); | |
2626 if (oap->op_type == OP_APPEND) | |
2627 --curwin->w_cursor.col; | |
2628 ve_flags = old_ve_flags; | |
2629 } | |
2630 #endif | |
2631 /* Get the info about the block before entering the text */ | |
2632 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
|
2633 /* 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
|
2634 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 2635 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
|
2636 |
7 | 2637 if (oap->op_type == OP_APPEND) |
2638 firstline += bd.textlen; | |
2639 pre_textlen = (long)STRLEN(firstline); | |
2640 } | |
2641 | |
2642 if (oap->op_type == OP_APPEND) | |
2643 { | |
2644 if (oap->block_mode | |
2645 #ifdef FEAT_VIRTUALEDIT | |
2646 && curwin->w_cursor.coladd == 0 | |
2647 #endif | |
2648 ) | |
2649 { | |
2650 /* Move the cursor to the character right of the block. */ | |
2651 curwin->w_set_curswant = TRUE; | |
2652 while (*ml_get_cursor() != NUL | |
2653 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2654 ++curwin->w_cursor.col; | |
2655 if (bd.is_short && !bd.is_MAX) | |
2656 { | |
2657 /* First line was too short, make it longer and adjust the | |
2658 * values in "bd". */ | |
2659 if (u_save_cursor() == FAIL) | |
2660 return; | |
2661 for (i = 0; i < bd.endspaces; ++i) | |
2662 ins_char(' '); | |
2663 bd.textlen += bd.endspaces; | |
2664 } | |
2665 } | |
2666 else | |
2667 { | |
2668 curwin->w_cursor = oap->end; | |
893 | 2669 check_cursor_col(); |
7 | 2670 |
2671 /* 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
|
2672 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2673 && oap->start_vcol != oap->end_vcol) |
2674 inc_cursor(); | |
2675 } | |
2676 } | |
2677 | |
6579 | 2678 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
|
2679 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 2680 |
6579 | 2681 /* When a tab was inserted, and the characters in front of the tab |
2682 * have been converted to a tab as well, the column of the cursor | |
2683 * might have actually been reduced, so need to adjust here. */ | |
2684 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
|
2685 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 2686 oap->start = curbuf->b_op_start_orig; |
2687 | |
1477 | 2688 /* If user has moved off this line, we don't know what to do, so do |
2689 * nothing. | |
2690 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2691 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2692 return; |
2693 | |
2694 if (oap->block_mode) | |
2695 { | |
2696 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
|
2697 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
|
2698 size_t len; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2699 int add; |
7 | 2700 |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2701 /* 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
|
2702 * 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
|
2703 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2704 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
|
2705 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2706 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2707 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
|
2708 did_indent = TRUE; |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2709 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2710 |
5471 | 2711 /* 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
|
2712 * 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
|
2713 * 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
|
2714 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
|
2715 && !bd.is_MAX && !did_indent) |
5471 | 2716 { |
2717 if (oap->op_type == OP_INSERT | |
5730 | 2718 && oap->start.col |
2719 #ifdef FEAT_VIRTUALEDIT | |
2720 + oap->start.coladd | |
2721 #endif | |
2722 != curbuf->b_op_start_orig.col | |
2723 #ifdef FEAT_VIRTUALEDIT | |
2724 + curbuf->b_op_start_orig.coladd | |
2725 #endif | |
2726 ) | |
5471 | 2727 { |
6579 | 2728 int t = getviscol2(curbuf->b_op_start_orig.col, |
15428
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2729 #ifdef FEAT_VIRTUALEDIT |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2730 curbuf->b_op_start_orig.coladd |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2731 #else |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2732 0 |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2733 #endif |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2734 ); |
5680 | 2735 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2736 pre_textlen -= t - oap->start_vcol; |
2737 oap->start_vcol = t; | |
5471 | 2738 } |
2739 else if (oap->op_type == OP_APPEND | |
5730 | 2740 && oap->end.col |
2741 #ifdef FEAT_VIRTUALEDIT | |
2742 + oap->end.coladd | |
2743 #endif | |
2744 >= curbuf->b_op_start_orig.col | |
2745 #ifdef FEAT_VIRTUALEDIT | |
2746 + curbuf->b_op_start_orig.coladd | |
2747 #endif | |
2748 ) | |
5471 | 2749 { |
6579 | 2750 int t = getviscol2(curbuf->b_op_start_orig.col, |
15428
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2751 #ifdef FEAT_VIRTUALEDIT |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2752 curbuf->b_op_start_orig.coladd |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2753 #else |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2754 0 |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2755 #endif |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2756 ); |
5680 | 2757 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2758 /* reset pre_textlen to the value of OP_INSERT */ |
2759 pre_textlen += bd.textlen; | |
6579 | 2760 pre_textlen -= t - oap->start_vcol; |
2761 oap->start_vcol = t; | |
5471 | 2762 oap->op_type = OP_INSERT; |
2763 } | |
2764 } | |
2765 | |
7 | 2766 /* |
2767 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2768 * tabs. Get the starting column again and correct the length. |
7 | 2769 * Don't do this when "$" used, end-of-line will have changed. |
2770 */ | |
2771 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2772 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2773 { | |
2774 if (oap->op_type == OP_APPEND) | |
2775 { | |
2776 pre_textlen += bd2.textlen - bd.textlen; | |
2777 if (bd2.endspaces) | |
2778 --bd2.textlen; | |
2779 } | |
2780 bd.textcol = bd2.textcol; | |
2781 bd.textlen = bd2.textlen; | |
2782 } | |
2783 | |
2784 /* | |
2785 * Subsequent calls to ml_get() flush the firstline data - take a | |
2786 * copy of the required string. | |
2787 */ | |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2788 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
|
2789 len = STRLEN(firstline); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2790 add = bd.textcol; |
7 | 2791 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
|
2792 add += bd.textlen; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2793 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
|
2794 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
|
2795 else |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2796 firstline += add; |
3421 | 2797 if (pre_textlen >= 0 |
2798 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2799 { |
2800 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2801 if (ins_text != NULL) | |
2802 { | |
2803 /* block handled here */ | |
2804 if (u_save(oap->start.lnum, | |
2805 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2806 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2807 &bd); | |
2808 | |
2809 curwin->w_cursor.col = oap->start.col; | |
2810 check_cursor(); | |
2811 vim_free(ins_text); | |
2812 } | |
2813 } | |
2814 } | |
2815 } | |
2816 | |
2817 /* | |
2818 * op_change - handle a change operation | |
2819 * | |
2820 * return TRUE if edit() returns because of a CTRL-O command | |
2821 */ | |
2822 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2823 op_change(oparg_T *oap) |
7 | 2824 { |
2825 colnr_T l; | |
2826 int retval; | |
2827 long offset; | |
2828 linenr_T linenr; | |
1392 | 2829 long ins_len; |
2830 long pre_textlen = 0; | |
2831 long pre_indent = 0; | |
7 | 2832 char_u *firstline; |
2833 char_u *ins_text, *newp, *oldp; | |
2834 struct block_def bd; | |
2835 | |
2836 l = oap->start.col; | |
2837 if (oap->motion_type == MLINE) | |
2838 { | |
2839 l = 0; | |
2840 #ifdef FEAT_SMARTINDENT | |
2841 if (!p_paste && curbuf->b_p_si | |
2842 # ifdef FEAT_CINDENT | |
2843 && !curbuf->b_p_cin | |
2844 # endif | |
2845 ) | |
2846 can_si = TRUE; /* It's like opening a new line, do si */ | |
2847 #endif | |
2848 } | |
2849 | |
2850 /* First delete the text in the region. In an empty buffer only need to | |
2851 * save for undo */ | |
2852 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2853 { | |
2854 if (u_save_cursor() == FAIL) | |
2855 return FALSE; | |
2856 } | |
2857 else if (op_delete(oap) == FAIL) | |
2858 return FALSE; | |
2859 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2860 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2861 && !virtual_op) |
2862 inc_cursor(); | |
2863 | |
2864 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2865 /* skip blank lines too */ | |
2866 if (oap->block_mode) | |
2867 { | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2868 #ifdef FEAT_VIRTUALEDIT |
7 | 2869 /* Add spaces before getting the current line length. */ |
2870 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2871 || gchar_cursor() == NUL)) | |
2872 coladvance_force(getviscol()); | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2873 #endif |
1392 | 2874 firstline = ml_get(oap->start.lnum); |
2875 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
|
2876 pre_indent = (long)getwhitecols(firstline); |
7 | 2877 bd.textcol = curwin->w_cursor.col; |
2878 } | |
2879 | |
2880 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2881 if (oap->motion_type == MLINE) | |
2882 fix_indent(); | |
2883 #endif | |
2884 | |
2885 retval = edit(NUL, FALSE, (linenr_T)1); | |
2886 | |
2887 /* | |
39 | 2888 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2889 * block. |
1477 | 2890 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2891 */ |
1477 | 2892 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2893 { |
1392 | 2894 /* Auto-indenting may have changed the indent. If the cursor was past |
2895 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2896 firstline = ml_get(oap->start.lnum); |
1403 | 2897 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2898 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2899 long new_indent = (long)getwhitecols(firstline); |
1392 | 2900 |
2901 pre_textlen += new_indent - pre_indent; | |
2902 bd.textcol += new_indent - pre_indent; | |
2903 } | |
2904 | |
2905 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2906 if (ins_len > 0) | |
2907 { | |
2908 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2909 * copy of the inserted text. */ | |
7 | 2910 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2911 { | |
419 | 2912 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2913 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2914 linenr++) | |
2915 { | |
2916 block_prep(oap, &bd, linenr, TRUE); | |
2917 if (!bd.is_short || virtual_op) | |
2918 { | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2919 #ifdef FEAT_VIRTUALEDIT |
7 | 2920 pos_T vpos; |
2921 | |
2922 /* If the block starts in virtual space, count the | |
2923 * initial coladd offset as part of "startspaces" */ | |
2924 if (bd.is_short) | |
2925 { | |
1982 | 2926 vpos.lnum = linenr; |
7 | 2927 (void)getvpos(&vpos, oap->start_vcol); |
2928 } | |
2929 else | |
2930 vpos.coladd = 0; | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2931 #endif |
7 | 2932 oldp = ml_get(linenr); |
2933 newp = alloc_check((unsigned)(STRLEN(oldp) | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2934 #ifdef FEAT_VIRTUALEDIT |
7 | 2935 + vpos.coladd |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2936 #endif |
7 | 2937 + ins_len + 1)); |
2938 if (newp == NULL) | |
2939 continue; | |
2940 /* copy up to block start */ | |
2941 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2942 offset = bd.textcol; | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2943 #ifdef FEAT_VIRTUALEDIT |
6929 | 2944 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2945 offset += vpos.coladd; |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2946 #endif |
7 | 2947 mch_memmove(newp + offset, ins_text, (size_t)ins_len); |
2948 offset += ins_len; | |
2949 oldp += bd.textcol; | |
1622 | 2950 STRMOVE(newp + offset, oldp); |
7 | 2951 ml_replace(linenr, newp, FALSE); |
2952 } | |
2953 } | |
2954 check_cursor(); | |
2955 | |
2956 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2957 } | |
2958 vim_free(ins_text); | |
2959 } | |
2960 } | |
2961 | |
2962 return retval; | |
2963 } | |
2964 | |
2965 /* | |
2966 * set all the yank registers to empty (called from main()) | |
2967 */ | |
2968 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2969 init_yank(void) |
7 | 2970 { |
2971 int i; | |
2972 | |
2973 for (i = 0; i < NUM_REGISTERS; ++i) | |
2974 y_regs[i].y_array = NULL; | |
2975 } | |
2976 | |
356 | 2977 #if defined(EXITFREE) || defined(PROTO) |
2978 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2979 clear_registers(void) |
356 | 2980 { |
2981 int i; | |
2982 | |
2983 for (i = 0; i < NUM_REGISTERS; ++i) | |
2984 { | |
2985 y_current = &y_regs[i]; | |
2986 if (y_current->y_array != NULL) | |
2987 free_yank_all(); | |
2988 } | |
2989 } | |
2990 #endif | |
2991 | |
7 | 2992 /* |
2993 * Free "n" lines from the current yank register. | |
2994 * Called for normal freeing and in case of error. | |
2995 */ | |
2996 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2997 free_yank(long n) |
7 | 2998 { |
2999 if (y_current->y_array != NULL) | |
3000 { | |
3001 long i; | |
3002 | |
3003 for (i = n; --i >= 0; ) | |
3004 { | |
3005 #ifdef AMIGA /* only for very slow machines */ | |
3006 if ((i & 1023) == 1023) /* this may take a while */ | |
3007 { | |
3008 /* | |
3009 * This message should never cause a hit-return message. | |
3010 * Overwrite this message with any next message. | |
3011 */ | |
3012 ++no_wait_return; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3013 smsg(_("freeing %ld lines"), i + 1); |
7 | 3014 --no_wait_return; |
3015 msg_didout = FALSE; | |
3016 msg_col = 0; | |
3017 } | |
3018 #endif | |
3019 vim_free(y_current->y_array[i]); | |
3020 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
3021 VIM_CLEAR(y_current->y_array); |
7 | 3022 #ifdef AMIGA |
3023 if (n >= 1000) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3024 msg(""); |
7 | 3025 #endif |
3026 } | |
3027 } | |
3028 | |
3029 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3030 free_yank_all(void) |
7 | 3031 { |
3032 free_yank(y_current->y_size); | |
3033 } | |
3034 | |
3035 /* | |
3036 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
3037 * If we are to append (uppercase register), we first yank into a new yank | |
3038 * register and then concatenate the old and the new one (so we keep the old | |
3039 * one in case of out-of-memory). | |
3040 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
3041 * Return FAIL for failure, OK otherwise. |
7 | 3042 */ |
3043 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3044 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 3045 { |
3046 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
|
3047 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
|
3048 yankreg_T newreg; /* new yank register when appending */ |
7 | 3049 char_u **new_ptr; |
3050 linenr_T lnum; /* current line number */ | |
3051 long j; | |
3052 int yanktype = oap->motion_type; | |
3053 long yanklines = oap->line_count; | |
3054 linenr_T yankendlnum = oap->end.lnum; | |
3055 char_u *p; | |
3056 char_u *pnew; | |
3057 struct block_def bd; | |
2658 | 3058 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 3059 int did_star = FALSE; |
2658 | 3060 #endif |
7 | 3061 |
3062 /* check for read-only register */ | |
3063 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
3064 { | |
3065 beep_flush(); | |
3066 return FAIL; | |
3067 } | |
3068 if (oap->regname == '_') /* black hole: nothing to do */ | |
3069 return OK; | |
3070 | |
3071 #ifdef FEAT_CLIPBOARD | |
3072 if (!clip_star.available && oap->regname == '*') | |
3073 oap->regname = 0; | |
3074 else if (!clip_plus.available && oap->regname == '+') | |
3075 oap->regname = 0; | |
3076 #endif | |
3077 | |
3078 if (!deleting) /* op_delete() already set y_current */ | |
3079 get_yank_register(oap->regname, TRUE); | |
3080 | |
3081 curr = y_current; | |
3082 /* append to existing contents */ | |
3083 if (y_append && y_current->y_array != NULL) | |
3084 y_current = &newreg; | |
3085 else | |
3086 free_yank_all(); /* free previously yanked lines */ | |
3087 | |
593 | 3088 /* |
3089 * If the cursor was in column 1 before and after the movement, and the | |
3090 * operator is not inclusive, the yank is always linewise. | |
3091 */ | |
7 | 3092 if ( oap->motion_type == MCHAR |
3093 && oap->start.col == 0 | |
3094 && !oap->inclusive | |
3095 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 3096 && !oap->block_mode |
7 | 3097 && oap->end.col == 0 |
3098 && yanklines > 1) | |
3099 { | |
3100 yanktype = MLINE; | |
3101 --yankendlnum; | |
3102 --yanklines; | |
3103 } | |
3104 | |
3105 y_current->y_size = yanklines; | |
3106 y_current->y_type = yanktype; /* set the yank register type */ | |
3107 y_current->y_width = 0; | |
3108 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
3109 yanklines), TRUE); | |
3110 if (y_current->y_array == NULL) | |
3111 { | |
3112 y_current = curr; | |
3113 return FAIL; | |
3114 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3115 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3116 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
|
3117 #endif |
7 | 3118 |
3119 y_idx = 0; | |
3120 lnum = oap->start.lnum; | |
3121 | |
3122 if (oap->block_mode) | |
3123 { | |
3124 /* Visual block mode */ | |
3125 y_current->y_type = MBLOCK; /* set the yank register type */ | |
3126 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
3127 | |
3128 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3129 y_current->y_width--; | |
3130 } | |
3131 | |
3132 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3133 { | |
3134 switch (y_current->y_type) | |
3135 { | |
3136 case MBLOCK: | |
3137 block_prep(oap, &bd, lnum, FALSE); | |
3138 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3139 goto fail; | |
3140 break; | |
3141 | |
3142 case MLINE: | |
3143 if ((y_current->y_array[y_idx] = | |
3144 vim_strsave(ml_get(lnum))) == NULL) | |
3145 goto fail; | |
3146 break; | |
3147 | |
3148 case MCHAR: | |
3149 { | |
3150 colnr_T startcol = 0, endcol = MAXCOL; | |
3151 #ifdef FEAT_VIRTUALEDIT | |
3152 int is_oneChar = FALSE; | |
3153 colnr_T cs, ce; | |
3154 #endif | |
3155 p = ml_get(lnum); | |
3156 bd.startspaces = 0; | |
3157 bd.endspaces = 0; | |
3158 | |
3159 if (lnum == oap->start.lnum) | |
3160 { | |
3161 startcol = oap->start.col; | |
3162 #ifdef FEAT_VIRTUALEDIT | |
3163 if (virtual_op) | |
3164 { | |
3165 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3166 if (ce != cs && oap->start.coladd > 0) | |
3167 { | |
3168 /* Part of a tab selected -- but don't | |
3169 * double-count it. */ | |
3170 bd.startspaces = (ce - cs + 1) | |
3171 - oap->start.coladd; | |
3172 startcol++; | |
3173 } | |
3174 } | |
3175 #endif | |
3176 } | |
3177 | |
3178 if (lnum == oap->end.lnum) | |
3179 { | |
3180 endcol = oap->end.col; | |
3181 #ifdef FEAT_VIRTUALEDIT | |
3182 if (virtual_op) | |
3183 { | |
3184 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3185 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3186 /* Don't add space for double-wide | |
3187 * char; endcol will be on last byte | |
3188 * of multi-byte char. */ | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3189 && (*mb_head_off)(p, p + endcol) == 0)) |
7 | 3190 { |
3191 if (oap->start.lnum == oap->end.lnum | |
3192 && oap->start.col == oap->end.col) | |
3193 { | |
3194 /* Special case: inside a single char */ | |
3195 is_oneChar = TRUE; | |
3196 bd.startspaces = oap->end.coladd | |
3197 - oap->start.coladd + oap->inclusive; | |
3198 endcol = startcol; | |
3199 } | |
3200 else | |
3201 { | |
3202 bd.endspaces = oap->end.coladd | |
3203 + oap->inclusive; | |
3204 endcol -= oap->inclusive; | |
3205 } | |
3206 } | |
3207 } | |
3208 #endif | |
3209 } | |
3510 | 3210 if (endcol == MAXCOL) |
3211 endcol = (colnr_T)STRLEN(p); | |
7 | 3212 if (startcol > endcol |
3213 #ifdef FEAT_VIRTUALEDIT | |
3214 || is_oneChar | |
3215 #endif | |
3216 ) | |
3217 bd.textlen = 0; | |
3218 else | |
3219 { | |
3220 bd.textlen = endcol - startcol + oap->inclusive; | |
3221 } | |
3222 bd.textstart = p + startcol; | |
3223 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3224 goto fail; | |
3225 break; | |
3226 } | |
3227 /* NOTREACHED */ | |
3228 } | |
3229 } | |
3230 | |
3231 if (curr != y_current) /* append the new block to the old block */ | |
3232 { | |
3233 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3234 (curr->y_size + y_current->y_size)), TRUE); | |
3235 if (new_ptr == NULL) | |
3236 goto fail; | |
3237 for (j = 0; j < curr->y_size; ++j) | |
3238 new_ptr[j] = curr->y_array[j]; | |
3239 vim_free(curr->y_array); | |
3240 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3241 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3242 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3243 #endif |
7 | 3244 |
3245 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3246 curr->y_type = MLINE; | |
3247 | |
164 | 3248 /* Concatenate the last line of the old block with the first line of |
3249 * the new block, unless being Vi compatible. */ | |
3250 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3251 { |
3252 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3253 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3254 if (pnew == NULL) | |
3255 { | |
3256 y_idx = y_current->y_size - 1; | |
3257 goto fail; | |
3258 } | |
3259 STRCPY(pnew, curr->y_array[--j]); | |
3260 STRCAT(pnew, y_current->y_array[0]); | |
3261 vim_free(curr->y_array[j]); | |
3262 vim_free(y_current->y_array[0]); | |
3263 curr->y_array[j++] = pnew; | |
3264 y_idx = 1; | |
3265 } | |
3266 else | |
3267 y_idx = 0; | |
3268 while (y_idx < y_current->y_size) | |
3269 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3270 curr->y_size = j; | |
3271 vim_free(y_current->y_array); | |
3272 y_current = curr; | |
3273 } | |
5981 | 3274 if (curwin->w_p_rnu) |
3275 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3276 if (mess) /* Display message about yank? */ |
3277 { | |
3278 if (yanktype == MCHAR | |
3279 && !oap->block_mode | |
3280 && yanklines == 1) | |
3281 yanklines = 0; | |
3282 /* Some versions of Vi use ">=" here, some don't... */ | |
3283 if (yanklines > p_report) | |
3284 { | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3285 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
|
3286 |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3287 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
|
3288 *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
|
3289 else |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3290 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
|
3291 _(" 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
|
3292 |
7 | 3293 /* redisplay now, so message is not deleted */ |
3294 update_topline_redraw(); | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3295 if (oap->block_mode) |
205 | 3296 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3297 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
|
3298 "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
|
3299 yanklines, namebuf); |
205 | 3300 } |
7 | 3301 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3302 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3303 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
|
3304 "%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
|
3305 yanklines, namebuf); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3306 } |
7 | 3307 } |
3308 } | |
3309 | |
3310 /* | |
3311 * Set "'[" and "']" marks. | |
3312 */ | |
3313 curbuf->b_op_start = oap->start; | |
3314 curbuf->b_op_end = oap->end; | |
5735 | 3315 if (yanktype == MLINE && !oap->block_mode) |
36 | 3316 { |
3317 curbuf->b_op_start.col = 0; | |
3318 curbuf->b_op_end.col = MAXCOL; | |
3319 } | |
7 | 3320 |
3321 #ifdef FEAT_CLIPBOARD | |
3322 /* | |
3323 * If we were yanking to the '*' register, send result to clipboard. | |
3324 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3325 * to the '*' register. | |
3326 */ | |
3327 if (clip_star.available | |
3328 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3329 || (!deleting && oap->regname == 0 |
6116 | 3330 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3331 { |
3332 if (curr != &(y_regs[STAR_REGISTER])) | |
3333 /* Copy the text from register 0 to the clipboard register. */ | |
3334 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3335 | |
3336 clip_own_selection(&clip_star); | |
3337 clip_gen_set_selection(&clip_star); | |
2658 | 3338 # ifdef FEAT_X11 |
2654 | 3339 did_star = TRUE; |
2658 | 3340 # endif |
7 | 3341 } |
3342 | |
3343 # ifdef FEAT_X11 | |
3344 /* | |
3345 * If we were yanking to the '+' register, send result to selection. | |
3346 * Also copy to the '*' register, in case auto-select is off. | |
3347 */ | |
2654 | 3348 if (clip_plus.available |
3349 && (curr == &(y_regs[PLUS_REGISTER]) | |
3350 || (!deleting && oap->regname == 0 | |
6116 | 3351 && ((clip_unnamed | clip_unnamed_saved) & |
3352 CLIP_UNNAMED_PLUS)))) | |
7 | 3353 { |
2654 | 3354 if (curr != &(y_regs[PLUS_REGISTER])) |
3355 /* Copy the text from register 0 to the clipboard register. */ | |
3356 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3357 | |
7 | 3358 clip_own_selection(&clip_plus); |
3359 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
|
3360 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
|
3361 && !did_star && curr == &(y_regs[PLUS_REGISTER])) |
7 | 3362 { |
3363 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3364 clip_own_selection(&clip_star); | |
3365 clip_gen_set_selection(&clip_star); | |
3366 } | |
3367 } | |
3368 # endif | |
3369 #endif | |
3370 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
3371 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3372 if (!deleting && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3373 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
|
3374 #endif |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3375 |
7 | 3376 return OK; |
3377 | |
3378 fail: /* free the allocated lines */ | |
3379 free_yank(y_idx + 1); | |
3380 y_current = curr; | |
3381 return FAIL; | |
3382 } | |
3383 | |
3384 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3385 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3386 { |
3387 char_u *pnew; | |
3388 | |
3389 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3390 == NULL) | |
3391 return FAIL; | |
3392 y_current->y_array[y_idx] = pnew; | |
6929 | 3393 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3394 pnew += bd->startspaces; |
3395 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3396 pnew += bd->textlen; | |
6929 | 3397 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3398 pnew += bd->endspaces; |
3399 *pnew = NUL; | |
3400 return OK; | |
3401 } | |
3402 | |
3403 #ifdef FEAT_CLIPBOARD | |
3404 /* | |
3405 * Make a copy of the y_current register to register "reg". | |
3406 */ | |
3407 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3408 copy_yank_reg(yankreg_T *reg) |
7 | 3409 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3410 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3411 long j; |
7 | 3412 |
3413 y_current = reg; | |
3414 free_yank_all(); | |
3415 *y_current = *curr; | |
3416 y_current->y_array = (char_u **)lalloc_clear( | |
3417 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3418 if (y_current->y_array == NULL) | |
3419 y_current->y_size = 0; | |
3420 else | |
3421 for (j = 0; j < y_current->y_size; ++j) | |
3422 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3423 { | |
3424 free_yank(j); | |
3425 y_current->y_size = 0; | |
3426 break; | |
3427 } | |
3428 y_current = curr; | |
3429 } | |
3430 #endif | |
3431 | |
3432 /* | |
140 | 3433 * Put contents of register "regname" into the text. |
3434 * Caller must check "regname" to be valid! | |
3435 * "flags": PUT_FIXINDENT make indent look nice | |
3436 * PUT_CURSEND leave cursor after end of new text | |
3437 * PUT_LINE force linewise put (":put") | |
7 | 3438 */ |
3439 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3440 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3441 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3442 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
|
3443 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3444 int flags) |
7 | 3445 { |
3446 char_u *ptr; | |
3447 char_u *newp, *oldp; | |
3448 int yanklen; | |
3449 int totlen = 0; /* init for gcc */ | |
3450 linenr_T lnum; | |
3451 colnr_T col; | |
3452 long i; /* index in y_array[] */ | |
3453 int y_type; | |
3454 long y_size; | |
3455 int oldlen; | |
3456 long y_width = 0; | |
3457 colnr_T vcol; | |
3458 int delcount; | |
3459 int incr = 0; | |
3460 long j; | |
3461 struct block_def bd; | |
3462 char_u **y_array = NULL; | |
3463 long nr_lines = 0; | |
3464 pos_T new_cursor; | |
3465 int indent; | |
3466 int orig_indent = 0; /* init for gcc */ | |
3467 int indent_diff = 0; /* init for gcc */ | |
3468 int first_indent = TRUE; | |
3469 int lendiff = 0; | |
3470 pos_T old_pos; | |
3471 char_u *insert_string = NULL; | |
3472 int allocated = FALSE; | |
3473 long cnt; | |
3474 | |
3475 #ifdef FEAT_CLIPBOARD | |
3476 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3477 adjust_clip_reg(®name); | |
3478 (void)may_get_selection(regname); | |
3479 #endif | |
3480 | |
3481 if (flags & PUT_FIXINDENT) | |
3482 orig_indent = get_indent(); | |
3483 | |
3484 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3485 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3486 | |
3487 /* | |
3488 * Using inserted text works differently, because the register includes | |
3489 * special characters (newlines, etc.). | |
3490 */ | |
3491 if (regname == '.') | |
3492 { | |
10494
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3493 if (VIsual_active) |
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3494 stuffcharReadbuff(VIsual_mode); |
7 | 3495 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
3496 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3497 /* Putting the text is done later, so can't really move the cursor to | |
3498 * the next character. Use "l" to simulate it. */ | |
3499 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3500 stuffcharReadbuff('l'); | |
3501 return; | |
3502 } | |
3503 | |
3504 /* | |
3505 * For special registers '%' (file name), '#' (alternate file name) and | |
3506 * ':' (last command line), etc. we have to create a fake yank register. | |
3507 */ | |
3508 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3509 { | |
3510 if (insert_string == NULL) | |
3511 return; | |
3512 } | |
3513 | |
14202
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3514 /* 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
|
3515 * 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
|
3516 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
|
3517 goto end; |
4005 | 3518 |
7 | 3519 if (insert_string != NULL) |
3520 { | |
3521 y_type = MCHAR; | |
3522 #ifdef FEAT_EVAL | |
3523 if (regname == '=') | |
3524 { | |
3525 /* For the = register we need to split the string at NL | |
3093 | 3526 * characters. |
3527 * Loop twice: count the number of lines and save them. */ | |
7 | 3528 for (;;) |
3529 { | |
3530 y_size = 0; | |
3531 ptr = insert_string; | |
3532 while (ptr != NULL) | |
3533 { | |
3534 if (y_array != NULL) | |
3535 y_array[y_size] = ptr; | |
3536 ++y_size; | |
3537 ptr = vim_strchr(ptr, '\n'); | |
3538 if (ptr != NULL) | |
3539 { | |
3540 if (y_array != NULL) | |
3541 *ptr = NUL; | |
3542 ++ptr; | |
3093 | 3543 /* A trailing '\n' makes the register linewise. */ |
7 | 3544 if (*ptr == NUL) |
3545 { | |
3546 y_type = MLINE; | |
3547 break; | |
3548 } | |
3549 } | |
3550 } | |
3551 if (y_array != NULL) | |
3552 break; | |
3553 y_array = (char_u **)alloc((unsigned) | |
3554 (y_size * sizeof(char_u *))); | |
3555 if (y_array == NULL) | |
3556 goto end; | |
3557 } | |
3558 } | |
3559 else | |
3560 #endif | |
3561 { | |
3562 y_size = 1; /* use fake one-line yank register */ | |
3563 y_array = &insert_string; | |
3564 } | |
3565 } | |
3566 else | |
3567 { | |
3568 get_yank_register(regname, FALSE); | |
3569 | |
3570 y_type = y_current->y_type; | |
3571 y_width = y_current->y_width; | |
3572 y_size = y_current->y_size; | |
3573 y_array = y_current->y_array; | |
3574 } | |
3575 | |
3576 if (y_type == MLINE) | |
3577 { | |
3578 if (flags & PUT_LINE_SPLIT) | |
3579 { | |
6845 | 3580 char_u *p; |
3581 | |
7 | 3582 /* "p" or "P" in Visual mode: split the lines to put the text in |
3583 * between. */ | |
3584 if (u_save_cursor() == FAIL) | |
3585 goto end; | |
6845 | 3586 p = ml_get_cursor(); |
3587 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
|
3588 MB_PTR_ADV(p); |
6845 | 3589 ptr = vim_strsave(p); |
7 | 3590 if (ptr == NULL) |
3591 goto end; | |
3592 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3593 vim_free(ptr); | |
3594 | |
6845 | 3595 oldp = ml_get_curline(); |
3596 p = oldp + curwin->w_cursor.col; | |
3597 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
|
3598 MB_PTR_ADV(p); |
6845 | 3599 ptr = vim_strnsave(oldp, p - oldp); |
7 | 3600 if (ptr == NULL) |
3601 goto end; | |
3602 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3603 ++nr_lines; | |
3604 dir = FORWARD; | |
3605 } | |
3606 if (flags & PUT_LINE_FORWARD) | |
3607 { | |
3608 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3609 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3610 dir = FORWARD; |
3611 } | |
3612 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3613 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3614 } | |
3615 | |
3616 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3617 y_type = MLINE; | |
3618 | |
3619 if (y_size == 0 || y_array == NULL) | |
3620 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3621 semsg(_("E353: Nothing in register %s"), |
7 | 3622 regname == 0 ? (char_u *)"\"" : transchar(regname)); |
3623 goto end; | |
3624 } | |
3625 | |
3626 if (y_type == MBLOCK) | |
3627 { | |
3628 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3629 if (lnum > curbuf->b_ml.ml_line_count) | |
3630 lnum = curbuf->b_ml.ml_line_count + 1; | |
3631 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3632 goto end; | |
3633 } | |
5735 | 3634 else if (y_type == MLINE) |
7 | 3635 { |
3636 lnum = curwin->w_cursor.lnum; | |
3637 #ifdef FEAT_FOLDING | |
3638 /* Correct line number for closed fold. Don't move the cursor yet, | |
3639 * u_save() uses it. */ | |
3640 if (dir == BACKWARD) | |
3641 (void)hasFolding(lnum, &lnum, NULL); | |
3642 else | |
3643 (void)hasFolding(lnum, NULL, &lnum); | |
3644 #endif | |
3645 if (dir == FORWARD) | |
3646 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3647 /* 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
|
3648 * 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
|
3649 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3650 goto end; |
3651 #ifdef FEAT_FOLDING | |
3652 if (dir == FORWARD) | |
3653 curwin->w_cursor.lnum = lnum - 1; | |
3654 else | |
3655 curwin->w_cursor.lnum = lnum; | |
3656 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3657 #endif | |
3658 } | |
3659 else if (u_save_cursor() == FAIL) | |
3660 goto end; | |
3661 | |
3662 yanklen = (int)STRLEN(y_array[0]); | |
3663 | |
3664 #ifdef FEAT_VIRTUALEDIT | |
3665 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3666 { | |
3667 if (gchar_cursor() == TAB) | |
3668 { | |
3669 /* Don't need to insert spaces when "p" on the last position of a | |
3670 * 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
|
3671 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3672 int viscol = getviscol(); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3673 if (dir == FORWARD |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3674 ? 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
|
3675 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
|
3676 : 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
|
3677 coladvance_force(viscol); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3678 #else |
7 | 3679 if (dir == FORWARD |
3680 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3681 : curwin->w_cursor.coladd > 0) | |
3682 coladvance_force(getviscol()); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3683 #endif |
7 | 3684 else |
3685 curwin->w_cursor.coladd = 0; | |
3686 } | |
3687 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3688 coladvance_force(getviscol() + (dir == FORWARD)); | |
3689 } | |
3690 #endif | |
3691 | |
3692 lnum = curwin->w_cursor.lnum; | |
3693 col = curwin->w_cursor.col; | |
3694 | |
3695 /* | |
3696 * Block mode | |
3697 */ | |
3698 if (y_type == MBLOCK) | |
3699 { | |
10664
94db9c08e206
patch 8.0.0222: blockwise put on multi-byte character misplaced
Christian Brabandt <cb@256bit.org>
parents:
10494
diff
changeset
|
3700 int c = gchar_cursor(); |
7 | 3701 colnr_T endcol2 = 0; |
3702 | |
3703 if (dir == FORWARD && c != NUL) | |
3704 { | |
3705 #ifdef FEAT_VIRTUALEDIT | |
3706 if (ve_flags == VE_ALL) | |
3707 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3708 else | |
3709 #endif | |
3710 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3711 | |
3712 if (has_mbyte) | |
3713 /* move to start of next multi-byte character */ | |
474 | 3714 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3715 else |
3716 #ifdef FEAT_VIRTUALEDIT | |
3717 if (c != TAB || ve_flags != VE_ALL) | |
3718 #endif | |
3719 ++curwin->w_cursor.col; | |
3720 ++col; | |
3721 } | |
3722 else | |
3723 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3724 | |
3725 #ifdef FEAT_VIRTUALEDIT | |
3726 col += curwin->w_cursor.coladd; | |
1304 | 3727 if (ve_flags == VE_ALL |
3728 && (curwin->w_cursor.coladd > 0 | |
3729 || endcol2 == curwin->w_cursor.col)) | |
7 | 3730 { |
3731 if (dir == FORWARD && c == NUL) | |
3732 ++col; | |
3733 if (dir != FORWARD && c != NUL) | |
3734 ++curwin->w_cursor.col; | |
3735 if (c == TAB) | |
3736 { | |
3737 if (dir == BACKWARD && curwin->w_cursor.col) | |
3738 curwin->w_cursor.col--; | |
3739 if (dir == FORWARD && col - 1 == endcol2) | |
3740 curwin->w_cursor.col++; | |
3741 } | |
3742 } | |
3743 curwin->w_cursor.coladd = 0; | |
3744 #endif | |
699 | 3745 bd.textcol = 0; |
7 | 3746 for (i = 0; i < y_size; ++i) |
3747 { | |
3748 int spaces; | |
3749 char shortline; | |
3750 | |
3751 bd.startspaces = 0; | |
3752 bd.endspaces = 0; | |
3753 vcol = 0; | |
3754 delcount = 0; | |
3755 | |
3756 /* add a new line */ | |
3757 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3758 { | |
3759 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3760 (colnr_T)1, FALSE) == FAIL) | |
3761 break; | |
3762 ++nr_lines; | |
3763 } | |
3764 /* get the old line and advance to the position to insert at */ | |
3765 oldp = ml_get_curline(); | |
3766 oldlen = (int)STRLEN(oldp); | |
3767 for (ptr = oldp; vcol < col && *ptr; ) | |
3768 { | |
3769 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3770 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3771 vcol += incr; |
3772 } | |
3773 bd.textcol = (colnr_T)(ptr - oldp); | |
3774 | |
3775 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3776 | |
3777 if (vcol < col) /* line too short, padd with spaces */ | |
3778 bd.startspaces = col - vcol; | |
3779 else if (vcol > col) | |
3780 { | |
3781 bd.endspaces = vcol - col; | |
3782 bd.startspaces = incr - bd.endspaces; | |
3783 --bd.textcol; | |
3784 delcount = 1; | |
3785 if (has_mbyte) | |
3786 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3787 if (oldp[bd.textcol] != TAB) | |
3788 { | |
3789 /* Only a Tab can be split into spaces. Other | |
3790 * characters will have to be moved to after the | |
3791 * block, causing misalignment. */ | |
3792 delcount = 0; | |
3793 bd.endspaces = 0; | |
3794 } | |
3795 } | |
3796 | |
3797 yanklen = (int)STRLEN(y_array[i]); | |
3798 | |
3799 /* calculate number of spaces required to fill right side of block*/ | |
3800 spaces = y_width + 1; | |
3801 for (j = 0; j < yanklen; j++) | |
5995 | 3802 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3803 if (spaces < 0) |
3804 spaces = 0; | |
3805 | |
3806 /* insert the new text */ | |
3807 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3808 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3809 if (newp == NULL) | |
3810 break; | |
3811 /* copy part up to cursor to new line */ | |
3812 ptr = newp; | |
3813 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3814 ptr += bd.textcol; | |
3815 /* may insert some spaces before the new text */ | |
6929 | 3816 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3817 ptr += bd.startspaces; |
3818 /* insert the new text */ | |
3819 for (j = 0; j < count; ++j) | |
3820 { | |
3821 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3822 ptr += yanklen; | |
3823 | |
3824 /* insert block's trailing spaces only if there's text behind */ | |
3825 if ((j < count - 1 || !shortline) && spaces) | |
3826 { | |
6929 | 3827 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3828 ptr += spaces; |
3829 } | |
3830 } | |
3831 /* may insert some spaces after the new text */ | |
6929 | 3832 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3833 ptr += bd.endspaces; |
3834 /* move the text after the cursor to the end of the line. */ | |
3835 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3836 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3837 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3838 | |
3839 ++curwin->w_cursor.lnum; | |
3840 if (i == 0) | |
3841 curwin->w_cursor.col += bd.startspaces; | |
3842 } | |
3843 | |
3844 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3845 | |
3846 /* Set '[ mark. */ | |
3847 curbuf->b_op_start = curwin->w_cursor; | |
3848 curbuf->b_op_start.lnum = lnum; | |
3849 | |
3850 /* adjust '] mark */ | |
3851 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3852 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
237 | 3853 # ifdef FEAT_VIRTUALEDIT |
7 | 3854 curbuf->b_op_end.coladd = 0; |
237 | 3855 # endif |
7 | 3856 if (flags & PUT_CURSEND) |
3857 { | |
916 | 3858 colnr_T len; |
3859 | |
7 | 3860 curwin->w_cursor = curbuf->b_op_end; |
3861 curwin->w_cursor.col++; | |
916 | 3862 |
3863 /* in Insert mode we might be after the NUL, correct for that */ | |
3864 len = (colnr_T)STRLEN(ml_get_curline()); | |
3865 if (curwin->w_cursor.col > len) | |
3866 curwin->w_cursor.col = len; | |
7 | 3867 } |
3868 else | |
3869 curwin->w_cursor.lnum = lnum; | |
3870 } | |
3871 else | |
3872 { | |
3873 /* | |
3874 * Character or Line mode | |
3875 */ | |
3876 if (y_type == MCHAR) | |
3877 { | |
3878 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3879 * char */ | |
3880 if (dir == FORWARD && gchar_cursor() != NUL) | |
3881 { | |
3882 if (has_mbyte) | |
3883 { | |
474 | 3884 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3885 |
3886 /* put it on the next of the multi-byte character. */ | |
3887 col += bytelen; | |
3888 if (yanklen) | |
3889 { | |
3890 curwin->w_cursor.col += bytelen; | |
3891 curbuf->b_op_end.col += bytelen; | |
3892 } | |
3893 } | |
3894 else | |
3895 { | |
3896 ++col; | |
3897 if (yanklen) | |
3898 { | |
3899 ++curwin->w_cursor.col; | |
3900 ++curbuf->b_op_end.col; | |
3901 } | |
3902 } | |
3903 } | |
3904 curbuf->b_op_start = curwin->w_cursor; | |
3905 } | |
3906 /* | |
3907 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3908 */ | |
3909 else if (dir == BACKWARD) | |
3910 --lnum; | |
699 | 3911 new_cursor = curwin->w_cursor; |
7 | 3912 |
3913 /* | |
3914 * simple case: insert into current line | |
3915 */ | |
3916 if (y_type == MCHAR && y_size == 1) | |
3917 { | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3918 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
|
3919 |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3920 if (VIsual_active) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3921 { |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3922 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
|
3923 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
|
3924 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
|
3925 } |
10670
bce3eccea39a
patch 8.0.0225: put in Visual block mode terminates early
Christian Brabandt <cb@256bit.org>
parents:
10664
diff
changeset
|
3926 |
5365 | 3927 do { |
3928 totlen = count * yanklen; | |
3929 if (totlen > 0) | |
7 | 3930 { |
5365 | 3931 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
|
3932 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
|
3933 { |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3934 lnum++; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3935 continue; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3936 } |
5365 | 3937 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); |
3938 if (newp == NULL) | |
3939 goto end; /* alloc() gave an error message */ | |
3940 mch_memmove(newp, oldp, (size_t)col); | |
3941 ptr = newp + col; | |
3942 for (i = 0; i < count; ++i) | |
3943 { | |
3944 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3945 ptr += yanklen; | |
3946 } | |
3947 STRMOVE(ptr, oldp + col); | |
3948 ml_replace(lnum, newp, FALSE); | |
3949 /* Place cursor on last putted char. */ | |
3950 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3951 { |
3952 /* make sure curwin->w_virtcol is updated */ | |
3953 changed_cline_bef_curs(); | |
5365 | 3954 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3955 } |
7 | 3956 } |
5365 | 3957 if (VIsual_active) |
3958 lnum++; | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3959 } while (VIsual_active && lnum <= end_lnum); |
5365 | 3960 |
6379 | 3961 if (VIsual_active) /* reset lnum to the last visual line */ |
3962 lnum--; | |
3963 | |
7 | 3964 curbuf->b_op_end = curwin->w_cursor; |
3965 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
3966 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
3967 ++curwin->w_cursor.col; | |
3968 changed_bytes(lnum, col); | |
3969 } | |
3970 else | |
3971 { | |
3972 /* | |
3973 * Insert at least one line. When y_type is MCHAR, break the first | |
3974 * line in two. | |
3975 */ | |
3976 for (cnt = 1; cnt <= count; ++cnt) | |
3977 { | |
3978 i = 0; | |
3979 if (y_type == MCHAR) | |
3980 { | |
3981 /* | |
3982 * Split the current line in two at the insert position. | |
3983 * First insert y_array[size - 1] in front of second line. | |
3984 * Then append y_array[0] to first line. | |
3985 */ | |
3986 lnum = new_cursor.lnum; | |
3987 ptr = ml_get(lnum) + col; | |
3988 totlen = (int)STRLEN(y_array[y_size - 1]); | |
3989 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
3990 if (newp == NULL) | |
3991 goto error; | |
3992 STRCPY(newp, y_array[y_size - 1]); | |
3993 STRCAT(newp, ptr); | |
3994 /* insert second line */ | |
3995 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
3996 vim_free(newp); | |
3997 | |
3998 oldp = ml_get(lnum); | |
3999 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
4000 if (newp == NULL) | |
4001 goto error; | |
4002 /* copy first part of line */ | |
4003 mch_memmove(newp, oldp, (size_t)col); | |
4004 /* append to first line */ | |
4005 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
4006 ml_replace(lnum, newp, FALSE); | |
4007 | |
4008 curwin->w_cursor.lnum = lnum; | |
4009 i = 1; | |
4010 } | |
4011 | |
4012 for (; i < y_size; ++i) | |
4013 { | |
4014 if ((y_type != MCHAR || i < y_size - 1) | |
4015 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
4016 == FAIL) | |
4017 goto error; | |
4018 lnum++; | |
4019 ++nr_lines; | |
4020 if (flags & PUT_FIXINDENT) | |
4021 { | |
4022 old_pos = curwin->w_cursor; | |
4023 curwin->w_cursor.lnum = lnum; | |
4024 ptr = ml_get(lnum); | |
4025 if (cnt == count && i == y_size - 1) | |
4026 lendiff = (int)STRLEN(ptr); | |
4027 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
4028 if (*ptr == '#' && preprocs_left()) | |
4029 indent = 0; /* Leave # lines at start */ | |
4030 else | |
4031 #endif | |
4032 if (*ptr == NUL) | |
4033 indent = 0; /* Ignore empty lines */ | |
4034 else if (first_indent) | |
4035 { | |
4036 indent_diff = orig_indent - get_indent(); | |
4037 indent = orig_indent; | |
4038 first_indent = FALSE; | |
4039 } | |
4040 else if ((indent = get_indent() + indent_diff) < 0) | |
4041 indent = 0; | |
4042 (void)set_indent(indent, 0); | |
4043 curwin->w_cursor = old_pos; | |
4044 /* remember how many chars were removed */ | |
4045 if (cnt == count && i == y_size - 1) | |
4046 lendiff -= (int)STRLEN(ml_get(lnum)); | |
4047 } | |
4048 } | |
4049 } | |
4050 | |
4051 error: | |
4052 /* Adjust marks. */ | |
4053 if (y_type == MLINE) | |
4054 { | |
4055 curbuf->b_op_start.col = 0; | |
4056 if (dir == FORWARD) | |
4057 curbuf->b_op_start.lnum++; | |
4058 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4059 /* 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
|
4060 * 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
|
4061 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
|
4062 < 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
|
4063 #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
|
4064 || 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
|
4065 #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
|
4066 ) |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4067 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 4068 (linenr_T)MAXLNUM, nr_lines, 0L); |
4069 | |
4070 /* note changed text for displaying and folding */ | |
4071 if (y_type == MCHAR) | |
4072 changed_lines(curwin->w_cursor.lnum, col, | |
4073 curwin->w_cursor.lnum + 1, nr_lines); | |
4074 else | |
4075 changed_lines(curbuf->b_op_start.lnum, 0, | |
4076 curbuf->b_op_start.lnum, nr_lines); | |
4077 | |
4078 /* put '] mark at last inserted character */ | |
4079 curbuf->b_op_end.lnum = lnum; | |
4080 /* correct length for change in indent */ | |
4081 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
4082 if (col > 1) | |
4083 curbuf->b_op_end.col = col - 1; | |
4084 else | |
4085 curbuf->b_op_end.col = 0; | |
4086 | |
168 | 4087 if (flags & PUT_CURSLINE) |
4088 { | |
237 | 4089 /* ":put": put cursor on last inserted line */ |
168 | 4090 curwin->w_cursor.lnum = lnum; |
4091 beginline(BL_WHITE | BL_FIX); | |
4092 } | |
4093 else if (flags & PUT_CURSEND) | |
7 | 4094 { |
4095 /* put cursor after inserted text */ | |
4096 if (y_type == MLINE) | |
4097 { | |
4098 if (lnum >= curbuf->b_ml.ml_line_count) | |
4099 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4100 else | |
4101 curwin->w_cursor.lnum = lnum + 1; | |
4102 curwin->w_cursor.col = 0; | |
4103 } | |
4104 else | |
4105 { | |
4106 curwin->w_cursor.lnum = lnum; | |
4107 curwin->w_cursor.col = col; | |
4108 } | |
4109 } | |
4110 else if (y_type == MLINE) | |
4111 { | |
168 | 4112 /* put cursor on first non-blank in first inserted line */ |
7 | 4113 curwin->w_cursor.col = 0; |
4114 if (dir == FORWARD) | |
4115 ++curwin->w_cursor.lnum; | |
4116 beginline(BL_WHITE | BL_FIX); | |
4117 } | |
4118 else /* put cursor on first inserted character */ | |
4119 curwin->w_cursor = new_cursor; | |
4120 } | |
4121 } | |
4122 | |
4123 msgmore(nr_lines); | |
4124 curwin->w_set_curswant = TRUE; | |
4125 | |
4126 end: | |
4127 if (allocated) | |
4128 vim_free(insert_string); | |
840 | 4129 if (regname == '=') |
4130 vim_free(y_array); | |
4131 | |
5380 | 4132 VIsual_active = FALSE; |
4133 | |
140 | 4134 /* If the cursor is past the end of the line put it at the end. */ |
844 | 4135 adjust_cursor_eol(); |
4136 } | |
4137 | |
4138 /* | |
4139 * When the cursor is on the NUL past the end of the line and it should not be | |
4140 * there move it left. | |
4141 */ | |
4142 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4143 adjust_cursor_eol(void) |
844 | 4144 { |
4145 if (curwin->w_cursor.col > 0 | |
4146 && gchar_cursor() == NUL | |
773 | 4147 #ifdef FEAT_VIRTUALEDIT |
4148 && (ve_flags & VE_ONEMORE) == 0 | |
4149 #endif | |
7 | 4150 && !(restart_edit || (State & INSERT))) |
4151 { | |
557 | 4152 /* Put the cursor on the last character in the line. */ |
555 | 4153 dec_cursor(); |
844 | 4154 |
7 | 4155 #ifdef FEAT_VIRTUALEDIT |
4156 if (ve_flags == VE_ALL) | |
557 | 4157 { |
4158 colnr_T scol, ecol; | |
4159 | |
4160 /* Coladd is set to the width of the last character. */ | |
4161 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4162 curwin->w_cursor.coladd = ecol - scol + 1; | |
4163 } | |
7 | 4164 #endif |
4165 } | |
4166 } | |
4167 | |
4168 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4169 /* | |
4170 * Return TRUE if lines starting with '#' should be left aligned. | |
4171 */ | |
4172 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4173 preprocs_left(void) |
7 | 4174 { |
4175 return | |
4176 # ifdef FEAT_SMARTINDENT | |
4177 # ifdef FEAT_CINDENT | |
4178 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4179 # else | |
4180 curbuf->b_p_si | |
4181 # endif | |
4182 # endif | |
4183 # ifdef FEAT_CINDENT | |
5438 | 4184 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4185 && curbuf->b_ind_hash_comment == 0) | |
7 | 4186 # endif |
4187 ; | |
4188 } | |
4189 #endif | |
4190 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4191 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4192 * 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
|
4193 */ |
7 | 4194 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4195 get_register_name(int num) |
7 | 4196 { |
4197 if (num == -1) | |
4198 return '"'; | |
4199 else if (num < 10) | |
4200 return num + '0'; | |
4201 else if (num == DELETION_REGISTER) | |
4202 return '-'; | |
4203 #ifdef FEAT_CLIPBOARD | |
4204 else if (num == STAR_REGISTER) | |
4205 return '*'; | |
4206 else if (num == PLUS_REGISTER) | |
4207 return '+'; | |
4208 #endif | |
4209 else | |
4210 { | |
4211 #ifdef EBCDIC | |
4212 int i; | |
4213 | |
4214 /* EBCDIC is really braindead ... */ | |
4215 i = 'a' + (num - 10); | |
4216 if (i > 'i') | |
4217 i += 7; | |
4218 if (i > 'r') | |
4219 i += 8; | |
4220 return i; | |
4221 #else | |
4222 return num + 'a' - 10; | |
4223 #endif | |
4224 } | |
4225 } | |
4226 | |
4227 /* | |
4228 * ":dis" and ":registers": Display the contents of the yank registers. | |
4229 */ | |
4230 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4231 ex_display(exarg_T *eap) |
7 | 4232 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4233 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4234 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4235 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4236 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4237 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4238 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4239 char_u *arg = eap->arg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4240 int clen; |
7 | 4241 |
4242 if (arg != NULL && *arg == NUL) | |
4243 arg = NULL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11131
diff
changeset
|
4244 attr = HL_ATTR(HLF_8); |
7 | 4245 |
4246 /* Highlight title */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4247 msg_puts_title(_("\n--- Registers ---")); |
7 | 4248 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) |
4249 { | |
4250 name = get_register_name(i); | |
2644 | 4251 if (arg != NULL && vim_strchr(arg, name) == NULL |
4252 #ifdef ONE_CLIPBOARD | |
4253 /* Star register and plus register contain the same thing. */ | |
4254 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4255 #endif | |
4256 ) | |
7 | 4257 continue; /* did not ask for this register */ |
4258 | |
4259 #ifdef FEAT_CLIPBOARD | |
4260 /* Adjust register name for "unnamed" in 'clipboard'. | |
4261 * When it's a clipboard register, fill it with the current contents | |
4262 * of the clipboard. */ | |
4263 adjust_clip_reg(&name); | |
4264 (void)may_get_selection(name); | |
4265 #endif | |
4266 | |
4267 if (i == -1) | |
4268 { | |
4269 if (y_previous != NULL) | |
4270 yb = y_previous; | |
4271 else | |
4272 yb = &(y_regs[0]); | |
4273 } | |
4274 else | |
4275 yb = &(y_regs[i]); | |
2000 | 4276 |
4277 #ifdef FEAT_EVAL | |
4278 if (name == MB_TOLOWER(redir_reg) | |
4279 || (redir_reg == '"' && yb == y_previous)) | |
4280 continue; /* do not list register being written to, the | |
4281 * pointer can be freed */ | |
4282 #endif | |
4283 | |
7 | 4284 if (yb->y_array != NULL) |
4285 { | |
4286 msg_putchar('\n'); | |
4287 msg_putchar('"'); | |
4288 msg_putchar(name); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4289 msg_puts(" "); |
7 | 4290 |
4291 n = (int)Columns - 6; | |
4292 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4293 { | |
4294 if (j) | |
4295 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4296 msg_puts_attr("^J", attr); |
7 | 4297 n -= 2; |
4298 } | |
4299 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4300 { | |
474 | 4301 clen = (*mb_ptr2len)(p); |
22 | 4302 msg_outtrans_len(p, clen); |
4303 p += clen - 1; | |
7 | 4304 } |
4305 } | |
4306 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
|
4307 msg_puts_attr("^J", attr); |
7 | 4308 out_flush(); /* show one line at a time */ |
4309 } | |
4310 ui_breakcheck(); | |
4311 } | |
4312 | |
4313 /* | |
4314 * display last inserted text | |
4315 */ | |
4316 if ((p = get_last_insert()) != NULL | |
4317 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4318 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4319 msg_puts("\n\". "); |
7 | 4320 dis_msg(p, TRUE); |
4321 } | |
4322 | |
4323 /* | |
4324 * display last command line | |
4325 */ | |
4326 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4327 && !got_int) | |
4328 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4329 msg_puts("\n\": "); |
7 | 4330 dis_msg(last_cmdline, FALSE); |
4331 } | |
4332 | |
4333 /* | |
4334 * display current file name | |
4335 */ | |
4336 if (curbuf->b_fname != NULL | |
4337 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4338 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4339 msg_puts("\n\"% "); |
7 | 4340 dis_msg(curbuf->b_fname, FALSE); |
4341 } | |
4342 | |
4343 /* | |
4344 * display alternate file name | |
4345 */ | |
4346 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4347 { | |
4348 char_u *fname; | |
4349 linenr_T dummy; | |
4350 | |
4351 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4352 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4353 msg_puts("\n\"# "); |
7 | 4354 dis_msg(fname, FALSE); |
4355 } | |
4356 } | |
4357 | |
4358 /* | |
4359 * display last search pattern | |
4360 */ | |
4361 if (last_search_pat() != NULL | |
4362 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4363 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4364 msg_puts("\n\"/ "); |
7 | 4365 dis_msg(last_search_pat(), FALSE); |
4366 } | |
4367 | |
4368 #ifdef FEAT_EVAL | |
4369 /* | |
4370 * display last used expression | |
4371 */ | |
4372 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4373 && !got_int) | |
4374 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4375 msg_puts("\n\"= "); |
7 | 4376 dis_msg(expr_line, FALSE); |
4377 } | |
4378 #endif | |
4379 } | |
4380 | |
4381 /* | |
4382 * display a string for do_dis() | |
4383 * truncate at end of screen line | |
4384 */ | |
4385 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4386 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4387 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4388 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4389 { |
4390 int n; | |
4391 int l; | |
4392 | |
4393 n = (int)Columns - 6; | |
4394 while (*p != NUL | |
4395 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4396 && (n -= ptr2cells(p)) >= 0) | |
4397 { | |
474 | 4398 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4399 { |
4400 msg_outtrans_len(p, l); | |
4401 p += l; | |
4402 } | |
4403 else | |
4404 msg_outtrans_len(p++, 1); | |
4405 } | |
4406 ui_breakcheck(); | |
4407 } | |
4408 | |
3562 | 4409 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4410 /* | |
4411 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4412 * after some white space), return a pointer to the text after it. Put a boolean | |
4413 * value indicating whether the line ends with an unclosed comment in | |
4414 * "is_comment". | |
4415 * line - line to be processed, | |
4416 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4417 * comment, |
3562 | 4418 * include_space - whether to also skip space following the comment leader, |
4419 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4420 * comment. |
3562 | 4421 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4422 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4423 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4424 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4425 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4426 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4427 int *is_comment) |
3562 | 4428 { |
4429 char_u *comment_flags = NULL; | |
4430 int lead_len; | |
4431 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4432 | |
4433 *is_comment = FALSE; | |
4434 if (leader_offset != -1) | |
4435 { | |
4436 /* Let's check whether the line ends with an unclosed comment. | |
4437 * If the last comment leader has COM_END in flags, there's no comment. | |
4438 */ | |
4439 while (*comment_flags) | |
4440 { | |
4441 if (*comment_flags == COM_END | |
4442 || *comment_flags == ':') | |
4443 break; | |
4444 ++comment_flags; | |
4445 } | |
4446 if (*comment_flags != COM_END) | |
4447 *is_comment = TRUE; | |
4448 } | |
4449 | |
4450 if (process == FALSE) | |
4451 return line; | |
4452 | |
4453 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4454 | |
4455 if (lead_len == 0) | |
4456 return line; | |
4457 | |
4458 /* Find: | |
4459 * - COM_END, | |
4460 * - colon, | |
4461 * whichever comes first. | |
4462 */ | |
4463 while (*comment_flags) | |
4464 { | |
3580 | 4465 if (*comment_flags == COM_END |
3562 | 4466 || *comment_flags == ':') |
4467 { | |
4468 break; | |
4469 } | |
4470 ++comment_flags; | |
4471 } | |
4472 | |
4473 /* If we found a colon, it means that we are not processing a line | |
3580 | 4474 * starting with a closing part of a three-part comment. That's good, |
4475 * because we don't want to remove those as this would be annoying. | |
3562 | 4476 */ |
4477 if (*comment_flags == ':' || *comment_flags == NUL) | |
4478 line += lead_len; | |
4479 | |
4480 return line; | |
4481 } | |
4482 #endif | |
4483 | |
7 | 4484 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4485 * 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
|
4486 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4487 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4488 * leaders should not be removed. | |
4489 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4490 * to set those marks. | |
7 | 4491 * |
1217 | 4492 * return FAIL for failure, OK otherwise |
7 | 4493 */ |
4494 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4495 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4496 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4497 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4498 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4499 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4500 int setmark) |
7 | 4501 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4502 char_u *curr = NULL; |
2597 | 4503 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
|
4504 char_u *cend; |
7 | 4505 char_u *newp; |
2597 | 4506 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
|
4507 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4508 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4509 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
|
4510 int sumsize = 0; /* size of the long new line */ |
7 | 4511 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4512 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4513 int ret = OK; |
3562 | 4514 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4515 int *comments = NULL; |
3562 | 4516 int remove_comments = (use_formatoptions == TRUE) |
4517 && has_format_option(FO_REMOVE_COMS); | |
4518 int prev_was_comment; | |
4519 #endif | |
4520 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4521 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4522 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
|
4523 (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
|
4524 return FAIL; |
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 /* 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
|
4527 * 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
|
4528 * 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
|
4529 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
|
4530 if (spaces == NULL) |
7 | 4531 return FAIL; |
3562 | 4532 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4533 if (remove_comments) | |
4534 { | |
4535 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4536 if (comments == NULL) | |
4537 { | |
4538 vim_free(spaces); | |
4539 return FAIL; | |
4540 } | |
4541 } | |
4542 #endif | |
7 | 4543 |
4544 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4545 * 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
|
4546 * and setup the array of space strings lengths |
7 | 4547 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4548 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
|
4549 { |
2597 | 4550 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4551 if (t == 0 && setmark) |
5664 | 4552 { |
4553 /* Set the '[ mark. */ | |
4554 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4555 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4556 } | |
3562 | 4557 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4558 if (remove_comments) | |
4559 { | |
4560 /* We don't want to remove the comment leader if the | |
4561 * previous line is not a comment. */ | |
4562 if (t > 0 && prev_was_comment) | |
4563 { | |
4564 | |
4565 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4566 &prev_was_comment); | |
3576 | 4567 comments[t] = (int)(new_curr - curr); |
3562 | 4568 curr = new_curr; |
4569 } | |
4570 else | |
4571 curr = skip_comment(curr, FALSE, insert_space, | |
4572 &prev_was_comment); | |
4573 } | |
4574 #endif | |
4575 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4576 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
|
4577 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4578 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4579 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
|
4580 && (!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
|
4581 || (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
|
4582 && (!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
|
4583 || 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
|
4584 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4585 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4586 /* 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
|
4587 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4588 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4589 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4590 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4591 /* 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
|
4592 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4593 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4594 || (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
|
4595 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4596 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4597 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4598 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4599 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4600 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4601 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4602 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
|
4603 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4604 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4605 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4606 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4607 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
|
4608 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4609 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4610 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4611 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
|
4612 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4613 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4614 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4615 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4616 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4617 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4618 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4619 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4620 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4621 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4622 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4623 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4624 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4625 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4626 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4627 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4628 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4629 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4630 /* 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
|
4631 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
|
4632 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4633 /* 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
|
4634 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
|
4635 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4636 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4637 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4638 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4639 * 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
|
4640 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4641 * 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
|
4642 * 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
|
4643 * 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
|
4644 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4645 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
|
4646 { |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4647 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
|
4648 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4649 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4650 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
|
4651 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4652 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4653 cend -= spaces[t]; |
6929 | 4654 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
|
4655 } |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4656 |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4657 // 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
|
4658 // 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
|
4659 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
|
4660 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4661 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
|
4662 (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
|
4663 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4664 break; |
2597 | 4665 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4666 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4667 if (remove_comments) | |
4668 curr += comments[t - 1]; | |
4669 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4670 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
|
4671 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4672 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4673 } |
7 | 4674 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4675 | |
5848 | 4676 if (setmark) |
4677 { | |
4678 /* Set the '] mark. */ | |
4679 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4680 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4681 } | |
5664 | 4682 |
7 | 4683 /* Only report the change in the first line here, del_lines() will report |
4684 * the deleted line. */ | |
4685 changed_lines(curwin->w_cursor.lnum, currsize, | |
4686 curwin->w_cursor.lnum + 1, 0L); | |
4687 | |
4688 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4689 * Delete following lines. To do this we move the cursor there |
7 | 4690 * briefly, and then move it back. After del_lines() the cursor may |
4691 * have moved up (last line deleted), so the current lnum is kept in t. | |
4692 */ | |
4693 t = curwin->w_cursor.lnum; | |
4694 ++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
|
4695 del_lines(count - 1, FALSE); |
7 | 4696 curwin->w_cursor.lnum = t; |
4697 | |
4698 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4699 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4700 * 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
|
4701 * vim: use the column of the last join |
7 | 4702 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4703 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4704 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4705 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4706 |
7 | 4707 #ifdef FEAT_VIRTUALEDIT |
4708 curwin->w_cursor.coladd = 0; | |
4709 #endif | |
4710 curwin->w_set_curswant = TRUE; | |
4711 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4712 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4713 vim_free(spaces); |
3562 | 4714 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4715 if (remove_comments) | |
4716 vim_free(comments); | |
4717 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4718 return ret; |
7 | 4719 } |
4720 | |
4721 #ifdef FEAT_COMMENTS | |
4722 /* | |
4723 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4724 * the first line. White-space is ignored. Note that the whole of | |
4725 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4726 */ | |
4727 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4728 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4729 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4730 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4731 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4732 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4733 char_u *leader2_flags) |
7 | 4734 { |
4735 int idx1 = 0, idx2 = 0; | |
4736 char_u *p; | |
4737 char_u *line1; | |
4738 char_u *line2; | |
4739 | |
4740 if (leader1_len == 0) | |
4741 return (leader2_len == 0); | |
4742 | |
4743 /* | |
4744 * If first leader has 'f' flag, the lines can be joined only if the | |
4745 * second line does not have a leader. | |
4746 * If first leader has 'e' flag, the lines can never be joined. | |
4747 * If fist leader has 's' flag, the lines can only be joined if there is | |
4748 * some text after it and the second line has the 'm' flag. | |
4749 */ | |
4750 if (leader1_flags != NULL) | |
4751 { | |
4752 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4753 { | |
4754 if (*p == COM_FIRST) | |
4755 return (leader2_len == 0); | |
4756 if (*p == COM_END) | |
4757 return FALSE; | |
4758 if (*p == COM_START) | |
4759 { | |
4760 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4761 return FALSE; | |
4762 if (leader2_flags == NULL || leader2_len == 0) | |
4763 return FALSE; | |
4764 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4765 if (*p == COM_MIDDLE) | |
4766 return TRUE; | |
4767 return FALSE; | |
4768 } | |
4769 } | |
4770 } | |
4771 | |
4772 /* | |
4773 * Get current line and next line, compare the leaders. | |
4774 * The first line has to be saved, only one line can be locked at a time. | |
4775 */ | |
4776 line1 = vim_strsave(ml_get(lnum)); | |
4777 if (line1 != NULL) | |
4778 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4779 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 4780 ; |
4781 line2 = ml_get(lnum + 1); | |
4782 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4783 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4784 if (!VIM_ISWHITE(line2[idx2])) |
7 | 4785 { |
4786 if (line1[idx1++] != line2[idx2]) | |
4787 break; | |
4788 } | |
4789 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4790 while (VIM_ISWHITE(line1[idx1])) |
7 | 4791 ++idx1; |
4792 } | |
4793 vim_free(line1); | |
4794 } | |
4795 return (idx2 == leader2_len && idx1 == leader1_len); | |
4796 } | |
4797 #endif | |
4798 | |
4799 /* | |
3252 | 4800 * Implementation of the format operator 'gq'. |
7 | 4801 */ |
4802 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4803 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4804 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4805 int keep_cursor) /* keep cursor on same text char */ |
7 | 4806 { |
4807 long old_line_count = curbuf->b_ml.ml_line_count; | |
4808 | |
4809 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4810 * can put it back there. */ | |
4811 curwin->w_cursor = oap->cursor_start; | |
4812 | |
4813 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4814 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4815 return; | |
4816 curwin->w_cursor = oap->start; | |
4817 | |
4818 if (oap->is_VIsual) | |
4819 /* When there is no change: need to remove the Visual selection */ | |
4820 redraw_curbuf_later(INVERTED); | |
4821 | |
4822 /* Set '[ mark at the start of the formatted area */ | |
4823 curbuf->b_op_start = oap->start; | |
4824 | |
4825 /* For "gw" remember the cursor position and put it back below (adjusted | |
4826 * for joined and split lines). */ | |
4827 if (keep_cursor) | |
4828 saved_cursor = oap->cursor_start; | |
4829 | |
1563 | 4830 format_lines(oap->line_count, keep_cursor); |
7 | 4831 |
4832 /* | |
4833 * Leave the cursor at the first non-blank of the last formatted line. | |
4834 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4835 * line, so "." will do the next lines. | |
4836 */ | |
4837 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4838 ++curwin->w_cursor.lnum; | |
4839 beginline(BL_WHITE | BL_FIX); | |
4840 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4841 msgmore(old_line_count); | |
4842 | |
4843 /* put '] mark on the end of the formatted area */ | |
4844 curbuf->b_op_end = curwin->w_cursor; | |
4845 | |
4846 if (keep_cursor) | |
4847 { | |
4848 curwin->w_cursor = saved_cursor; | |
4849 saved_cursor.lnum = 0; | |
4850 } | |
4851 | |
4852 if (oap->is_VIsual) | |
4853 { | |
4854 win_T *wp; | |
4855 | |
4856 FOR_ALL_WINDOWS(wp) | |
4857 { | |
4858 if (wp->w_old_cursor_lnum != 0) | |
4859 { | |
4860 /* When lines have been inserted or deleted, adjust the end of | |
4861 * the Visual area to be redrawn. */ | |
4862 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4863 wp->w_old_cursor_lnum += old_line_count; | |
4864 else | |
4865 wp->w_old_visual_lnum += old_line_count; | |
4866 } | |
4867 } | |
4868 } | |
4869 } | |
4870 | |
667 | 4871 #if defined(FEAT_EVAL) || defined(PROTO) |
4872 /* | |
4873 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4874 */ | |
4875 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4876 op_formatexpr(oparg_T *oap) |
667 | 4877 { |
4878 if (oap->is_VIsual) | |
4879 /* When there is no change: need to remove the Visual selection */ | |
4880 redraw_curbuf_later(INVERTED); | |
4881 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4882 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
|
4883 /* 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
|
4884 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4885 op_format(oap, FALSE); |
667 | 4886 } |
4887 | |
4888 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4889 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4890 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4891 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4892 int c) /* character to be inserted */ |
667 | 4893 { |
681 | 4894 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4895 OPT_LOCAL); | |
667 | 4896 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4897 char_u *fex; |
667 | 4898 |
4899 /* | |
4900 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4901 * Set v:char to the character to be inserted (can be NUL). |
667 | 4902 */ |
4903 set_vim_var_nr(VV_LNUM, lnum); | |
4904 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4905 set_vim_var_char(c); |
844 | 4906 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4907 /* 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
|
4908 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
|
4909 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4910 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4911 |
667 | 4912 /* |
4913 * Evaluate the function. | |
4914 */ | |
4915 if (use_sandbox) | |
4916 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4917 r = (int)eval_to_number(fex); |
667 | 4918 if (use_sandbox) |
4919 --sandbox; | |
844 | 4920 |
4921 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
|
4922 vim_free(fex); |
844 | 4923 |
667 | 4924 return r; |
4925 } | |
4926 #endif | |
4927 | |
7 | 4928 /* |
4929 * Format "line_count" lines, starting at the cursor position. | |
4930 * When "line_count" is negative, format until the end of the paragraph. | |
4931 * Lines after the cursor line are saved for undo, caller must have saved the | |
4932 * first line. | |
4933 */ | |
4934 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4935 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4936 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4937 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4938 { |
4939 int max_len; | |
4940 int is_not_par; /* current line not part of parag. */ | |
4941 int next_is_not_par; /* next line not part of paragraph */ | |
4942 int is_end_par; /* at end of paragraph */ | |
4943 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4944 int next_is_start_par = FALSE; | |
4945 #ifdef FEAT_COMMENTS | |
4946 int leader_len = 0; /* leader len of current line */ | |
4947 int next_leader_len; /* leader len of next line */ | |
4948 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
4949 char_u *next_leader_flags; /* flags for leader of next line */ | |
4950 int do_comments; /* format comments */ | |
3584 | 4951 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 4952 #endif |
4953 int advance = TRUE; | |
3584 | 4954 int second_indent = -1; /* indent for second line (comment |
4955 * aware) */ | |
7 | 4956 int do_second_indent; |
4957 int do_number_indent; | |
4958 int do_trail_white; | |
4959 int first_par_line = TRUE; | |
4960 int smd_save; | |
4961 long count; | |
4962 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
4963 int force_format = FALSE; | |
4964 int old_State = State; | |
4965 | |
4966 /* length of a line to force formatting: 3 * 'tw' */ | |
4967 max_len = comp_textwidth(TRUE) * 3; | |
4968 | |
4969 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
4970 #ifdef FEAT_COMMENTS | |
4971 do_comments = has_format_option(FO_Q_COMS); | |
4972 #endif | |
4973 do_second_indent = has_format_option(FO_Q_SECOND); | |
4974 do_number_indent = has_format_option(FO_Q_NUMBER); | |
4975 do_trail_white = has_format_option(FO_WHITE_PAR); | |
4976 | |
4977 /* | |
4978 * Get info about the previous and current line. | |
4979 */ | |
4980 if (curwin->w_cursor.lnum > 1) | |
4981 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
4982 #ifdef FEAT_COMMENTS | |
4983 , &leader_len, &leader_flags, do_comments | |
4984 #endif | |
4985 ); | |
4986 else | |
4987 is_not_par = TRUE; | |
4988 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
4989 #ifdef FEAT_COMMENTS | |
4990 , &next_leader_len, &next_leader_flags, do_comments | |
4991 #endif | |
4992 ); | |
4993 is_end_par = (is_not_par || next_is_not_par); | |
4994 if (!is_end_par && do_trail_white) | |
4995 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
4996 | |
4997 curwin->w_cursor.lnum--; | |
4998 for (count = line_count; count != 0 && !got_int; --count) | |
4999 { | |
5000 /* | |
5001 * Advance to next paragraph. | |
5002 */ | |
5003 if (advance) | |
5004 { | |
5005 curwin->w_cursor.lnum++; | |
5006 prev_is_end_par = is_end_par; | |
5007 is_not_par = next_is_not_par; | |
5008 #ifdef FEAT_COMMENTS | |
5009 leader_len = next_leader_len; | |
5010 leader_flags = next_leader_flags; | |
5011 #endif | |
5012 } | |
5013 | |
5014 /* | |
5015 * The last line to be formatted. | |
5016 */ | |
5017 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
5018 { | |
5019 next_is_not_par = TRUE; | |
5020 #ifdef FEAT_COMMENTS | |
5021 next_leader_len = 0; | |
5022 next_leader_flags = NULL; | |
5023 #endif | |
5024 } | |
5025 else | |
5026 { | |
5027 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
5028 #ifdef FEAT_COMMENTS | |
5029 , &next_leader_len, &next_leader_flags, do_comments | |
5030 #endif | |
5031 ); | |
5032 if (do_number_indent) | |
5033 next_is_start_par = | |
5034 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
5035 } | |
5036 advance = TRUE; | |
5037 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
5038 if (!is_end_par && do_trail_white) | |
5039 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
5040 | |
5041 /* | |
5042 * Skip lines that are not in a paragraph. | |
5043 */ | |
5044 if (is_not_par) | |
5045 { | |
5046 if (line_count < 0) | |
5047 break; | |
5048 } | |
5049 else | |
5050 { | |
5051 /* | |
5052 * For the first line of a paragraph, check indent of second line. | |
5053 * Don't do this for comments and empty lines. | |
5054 */ | |
5055 if (first_par_line | |
5056 && (do_second_indent || do_number_indent) | |
5057 && prev_is_end_par | |
3584 | 5058 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
5059 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
5060 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 5061 { |
5062 #ifdef FEAT_COMMENTS | |
5063 if (leader_len == 0 && next_leader_len == 0) | |
5064 { | |
5065 /* no comment found */ | |
5066 #endif | |
5067 second_indent = | |
5068 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 5069 #ifdef FEAT_COMMENTS |
3584 | 5070 } |
5071 else | |
5072 { | |
5073 second_indent = next_leader_len; | |
5074 do_comments_list = 1; | |
5075 } | |
5076 #endif | |
5077 } | |
7 | 5078 else if (do_number_indent) |
3584 | 5079 { |
5080 #ifdef FEAT_COMMENTS | |
5081 if (leader_len == 0 && next_leader_len == 0) | |
5082 { | |
5083 /* no comment found */ | |
5084 #endif | |
5085 second_indent = | |
5086 get_number_indent(curwin->w_cursor.lnum); | |
5087 #ifdef FEAT_COMMENTS | |
5088 } | |
5089 else | |
5090 { | |
5091 /* get_number_indent() is now "comment aware"... */ | |
5092 second_indent = | |
5093 get_number_indent(curwin->w_cursor.lnum); | |
5094 do_comments_list = 1; | |
5095 } | |
5096 #endif | |
5097 } | |
7 | 5098 } |
5099 | |
5100 /* | |
5101 * When the comment leader changes, it's the end of the paragraph. | |
5102 */ | |
5103 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
5104 #ifdef FEAT_COMMENTS | |
5105 || !same_leader(curwin->w_cursor.lnum, | |
5106 leader_len, leader_flags, | |
5107 next_leader_len, next_leader_flags) | |
5108 #endif | |
5109 ) | |
5110 is_end_par = TRUE; | |
5111 | |
5112 /* | |
5113 * If we have got to the end of a paragraph, or the line is | |
5114 * getting long, format it. | |
5115 */ | |
5116 if (is_end_par || force_format) | |
5117 { | |
5118 if (need_set_indent) | |
5119 /* replace indent in first line with minimal number of | |
5120 * tabs and spaces, according to current options */ | |
5121 (void)set_indent(get_indent(), SIN_CHANGED); | |
5122 | |
5123 /* put cursor on last non-space */ | |
5124 State = NORMAL; /* don't go past end-of-line */ | |
5125 coladvance((colnr_T)MAXCOL); | |
5126 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
5127 dec_cursor(); | |
5128 | |
5129 /* do the formatting, without 'showmode' */ | |
5130 State = INSERT; /* for open_line() */ | |
5131 smd_save = p_smd; | |
5132 p_smd = FALSE; | |
5133 insertchar(NUL, INSCHAR_FORMAT | |
5134 #ifdef FEAT_COMMENTS | |
5135 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 5136 + (do_comments && do_comments_list |
5137 ? INSCHAR_COM_LIST : 0) | |
7 | 5138 #endif |
1563 | 5139 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 5140 State = old_State; |
5141 p_smd = smd_save; | |
5142 second_indent = -1; | |
5143 /* at end of par.: need to set indent of next par. */ | |
5144 need_set_indent = is_end_par; | |
5145 if (is_end_par) | |
5146 { | |
5147 /* When called with a negative line count, break at the | |
5148 * end of the paragraph. */ | |
5149 if (line_count < 0) | |
5150 break; | |
5151 first_par_line = TRUE; | |
5152 } | |
5153 force_format = FALSE; | |
5154 } | |
5155 | |
5156 /* | |
5157 * When still in same paragraph, join the lines together. But | |
5403 | 5158 * first delete the leader from the second line. |
7 | 5159 */ |
5160 if (!is_end_par) | |
5161 { | |
5162 advance = FALSE; | |
5163 curwin->w_cursor.lnum++; | |
5164 curwin->w_cursor.col = 0; | |
5165 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
|
5166 break; |
7 | 5167 #ifdef FEAT_COMMENTS |
5168 if (next_leader_len > 0) | |
5403 | 5169 { |
5170 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5171 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
|
5172 (long)-next_leader_len, 0); |
5403 | 5173 } else |
5174 #endif | |
5175 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5176 { | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
5177 int indent = getwhitecols_curline(); |
5403 | 5178 |
5179 if (indent > 0) | |
5180 { | |
5181 (void)del_bytes(indent, FALSE, FALSE); | |
5182 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
|
5183 (colnr_T)0, 0L, (long)-indent, 0); |
5415 | 5184 } |
5403 | 5185 } |
7 | 5186 curwin->w_cursor.lnum--; |
5848 | 5187 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5188 { |
5189 beep_flush(); | |
5190 break; | |
5191 } | |
5192 first_par_line = FALSE; | |
5193 /* If the line is getting long, format it next time */ | |
5194 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5195 force_format = TRUE; | |
5196 else | |
5197 force_format = FALSE; | |
5198 } | |
5199 } | |
5200 line_breakcheck(); | |
5201 } | |
5202 } | |
5203 | |
5204 /* | |
5205 * Return TRUE if line "lnum" ends in a white character. | |
5206 */ | |
5207 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5208 ends_in_white(linenr_T lnum) |
7 | 5209 { |
5210 char_u *s = ml_get(lnum); | |
5211 size_t l; | |
5212 | |
5213 if (*s == NUL) | |
5214 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5215 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 5216 * invocation may call function multiple times". */ |
5217 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
|
5218 return VIM_ISWHITE(s[l]); |
7 | 5219 } |
5220 | |
5221 /* | |
5222 * Blank lines, and lines containing only the comment leader, are left | |
5223 * untouched by the formatting. The function returns TRUE in this | |
5224 * case. It also returns TRUE when a line starts with the end of a comment | |
5225 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5226 * previous line. A new paragraph starts after a blank line, or when the | |
5227 * comment leader changes -- webb. | |
5228 */ | |
5229 #ifdef FEAT_COMMENTS | |
5230 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5231 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5232 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5233 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5234 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5235 int do_comments) |
7 | 5236 { |
5237 char_u *flags = NULL; /* init for GCC */ | |
5238 char_u *ptr; | |
5239 | |
5240 ptr = ml_get(lnum); | |
5241 if (do_comments) | |
3562 | 5242 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5243 else |
5244 *leader_len = 0; | |
5245 | |
5246 if (*leader_len > 0) | |
5247 { | |
5248 /* | |
5249 * Search for 'e' flag in comment leader flags. | |
5250 */ | |
5251 flags = *leader_flags; | |
5252 while (*flags && *flags != ':' && *flags != COM_END) | |
5253 ++flags; | |
5254 } | |
5255 | |
5256 return (*skipwhite(ptr + *leader_len) == NUL | |
5257 || (*leader_len > 0 && *flags == COM_END) | |
5258 || startPS(lnum, NUL, FALSE)); | |
5259 } | |
5260 #else | |
5261 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5262 fmt_check_par(linenr_T lnum) |
7 | 5263 { |
5264 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5265 } | |
5266 #endif | |
5267 | |
5268 /* | |
5269 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5270 * previous line is in the same paragraph. Used for auto-formatting. | |
5271 */ | |
5272 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5273 paragraph_start(linenr_T lnum) |
7 | 5274 { |
5275 char_u *p; | |
5276 #ifdef FEAT_COMMENTS | |
5277 int leader_len = 0; /* leader len of current line */ | |
5278 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5279 int next_leader_len; /* leader len of next line */ | |
5280 char_u *next_leader_flags; /* flags for leader of next line */ | |
5281 int do_comments; /* format comments */ | |
5282 #endif | |
5283 | |
5284 if (lnum <= 1) | |
5285 return TRUE; /* start of the file */ | |
5286 | |
5287 p = ml_get(lnum - 1); | |
5288 if (*p == NUL) | |
5289 return TRUE; /* after empty line */ | |
5290 | |
5291 #ifdef FEAT_COMMENTS | |
5292 do_comments = has_format_option(FO_Q_COMS); | |
5293 #endif | |
5294 if (fmt_check_par(lnum - 1 | |
5295 #ifdef FEAT_COMMENTS | |
5296 , &leader_len, &leader_flags, do_comments | |
5297 #endif | |
5298 )) | |
5299 return TRUE; /* after non-paragraph line */ | |
5300 | |
5301 if (fmt_check_par(lnum | |
5302 #ifdef FEAT_COMMENTS | |
5303 , &next_leader_len, &next_leader_flags, do_comments | |
5304 #endif | |
5305 )) | |
5306 return TRUE; /* "lnum" is not a paragraph line */ | |
5307 | |
5308 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5309 return TRUE; /* missing trailing space in previous line. */ | |
5310 | |
5311 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5312 return TRUE; /* numbered item starts in "lnum". */ | |
5313 | |
5314 #ifdef FEAT_COMMENTS | |
5315 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5316 next_leader_len, next_leader_flags)) | |
5317 return TRUE; /* change of comment leader. */ | |
5318 #endif | |
5319 | |
5320 return FALSE; | |
5321 } | |
5322 | |
5323 /* | |
5324 * prepare a few things for block mode yank/delete/tilde | |
5325 * | |
5326 * for delete: | |
5327 * - textlen includes the first/last char to be (partly) deleted | |
5328 * - start/endspaces is the number of columns that are taken by the | |
5329 * first/last deleted char minus the number of columns that have to be | |
1839 | 5330 * deleted. |
5331 * for yank and tilde: | |
7 | 5332 * - textlen includes the first/last char to be wholly yanked |
5333 * - start/endspaces is the number of columns of the first/last yanked char | |
5334 * that are to be yanked. | |
5335 */ | |
5336 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5337 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5338 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5339 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5340 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5341 int is_del) |
7 | 5342 { |
5343 int incr = 0; | |
5344 char_u *pend; | |
5345 char_u *pstart; | |
5346 char_u *line; | |
5347 char_u *prev_pstart; | |
5348 char_u *prev_pend; | |
5349 | |
5350 bdp->startspaces = 0; | |
5351 bdp->endspaces = 0; | |
5352 bdp->textlen = 0; | |
5353 bdp->start_vcol = 0; | |
5354 bdp->end_vcol = 0; | |
5355 bdp->is_short = FALSE; | |
5356 bdp->is_oneChar = FALSE; | |
5357 bdp->pre_whitesp = 0; | |
5358 bdp->pre_whitesp_c = 0; | |
5359 bdp->end_char_vcols = 0; | |
5360 bdp->start_char_vcols = 0; | |
5361 | |
5362 line = ml_get(lnum); | |
5363 pstart = line; | |
5364 prev_pstart = line; | |
5365 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5366 { | |
5367 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5368 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5369 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
|
5370 if (VIM_ISWHITE(*pstart)) |
7 | 5371 { |
5372 bdp->pre_whitesp += incr; | |
5373 bdp->pre_whitesp_c++; | |
5374 } | |
5375 else | |
5376 { | |
5377 bdp->pre_whitesp = 0; | |
5378 bdp->pre_whitesp_c = 0; | |
5379 } | |
5380 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5381 MB_PTR_ADV(pstart); |
7 | 5382 } |
5383 bdp->start_char_vcols = incr; | |
5384 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5385 { | |
5386 bdp->end_vcol = bdp->start_vcol; | |
5387 bdp->is_short = TRUE; | |
5388 if (!is_del || oap->op_type == OP_APPEND) | |
5389 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5390 } | |
5391 else | |
5392 { | |
5393 /* notice: this converts partly selected Multibyte characters to | |
5394 * spaces, too. */ | |
5395 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5396 if (is_del && bdp->startspaces) | |
5397 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5398 pend = pstart; | |
5399 bdp->end_vcol = bdp->start_vcol; | |
5400 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5401 { | |
5402 bdp->is_oneChar = TRUE; | |
5403 if (oap->op_type == OP_INSERT) | |
5404 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5405 else if (oap->op_type == OP_APPEND) | |
5406 { | |
5407 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5408 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5409 } | |
5410 else | |
5411 { | |
5412 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5413 if (is_del && oap->op_type != OP_LSHIFT) | |
5414 { | |
5415 /* just putting the sum of those two into | |
5416 * bdp->startspaces doesn't work for Visual replace, | |
5417 * so we have to split the tab in two */ | |
5418 bdp->startspaces = bdp->start_char_vcols | |
5419 - (bdp->start_vcol - oap->start_vcol); | |
5420 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5421 } | |
5422 } | |
5423 } | |
5424 else | |
5425 { | |
5426 prev_pend = pend; | |
5427 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5428 { | |
5429 /* Count a tab for what it's worth (if list mode not on) */ | |
5430 prev_pend = pend; | |
6535 | 5431 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5432 bdp->end_vcol += incr; |
5433 } | |
5434 if (bdp->end_vcol <= oap->end_vcol | |
5435 && (!is_del | |
5436 || oap->op_type == OP_APPEND | |
5437 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5438 { | |
5439 bdp->is_short = TRUE; | |
5440 /* Alternative: include spaces to fill up the block. | |
5441 * Disadvantage: can lead to trailing spaces when the line is | |
5442 * short where the text is put */ | |
5443 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5444 if (oap->op_type == OP_APPEND || virtual_op) | |
5445 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5446 + oap->inclusive; |
7 | 5447 else |
5448 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5449 } | |
5450 else if (bdp->end_vcol > oap->end_vcol) | |
5451 { | |
5452 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5453 if (!is_del && bdp->endspaces) | |
5454 { | |
5455 bdp->endspaces = incr - bdp->endspaces; | |
5456 if (pend != pstart) | |
5457 pend = prev_pend; | |
5458 } | |
5459 } | |
5460 } | |
5461 bdp->end_char_vcols = incr; | |
5462 if (is_del && bdp->startspaces) | |
5463 pstart = prev_pstart; | |
5464 bdp->textlen = (int)(pend - pstart); | |
5465 } | |
5466 bdp->textcol = (colnr_T) (pstart - line); | |
5467 bdp->textstart = pstart; | |
5468 } | |
5469 | |
5470 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5471 * Handle the add/subtract operator. |
7 | 5472 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5473 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5474 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5475 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5476 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
|
5477 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
|
5478 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5479 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5480 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5481 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5482 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5483 |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5484 // 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
|
5485 // 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
|
5486 // 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
|
5487 #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
|
5488 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
|
5489 #endif |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5490 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5491 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5492 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5493 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5494 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
|
5495 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5496 #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
|
5497 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
|
5498 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5499 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5500 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5501 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
|
5502 #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
|
5503 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
|
5504 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5505 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5506 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
|
5507 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5508 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5509 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5510 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5511 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5512 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5513 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5514 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
|
5515 (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
|
5516 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5517 #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
|
5518 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
|
5519 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5520 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5521 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5522 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5523 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5524 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
|
5525 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5526 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
|
5527 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5528 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
|
5529 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5530 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5531 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5532 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
|
5533 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5534 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5535 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5536 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
|
5537 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5538 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5539 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
5540 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
|
5541 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5542 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
|
5543 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5544 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
|
5545 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5546 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5547 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5548 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5549 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5550 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5551 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
|
5552 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5553 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5554 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
|
5555 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5556 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5557 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
|
5558 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5559 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5560 /* 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
|
5561 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5562 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5563 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5564 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5565 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5566 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5567 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5568 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5569 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
|
5570 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5571 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
|
5572 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
|
5573 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5574 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5575 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5576 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5577 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5578 } |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5579 |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5580 #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
|
5581 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
|
5582 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5583 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5584 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
|
5585 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5586 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5587 /* 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
|
5588 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5589 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5590 /* 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
|
5591 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5592 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5593 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5594 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5595 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
|
5596 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
|
5597 change_cnt), change_cnt); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5598 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5599 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5600 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5601 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5602 * 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
|
5603 * 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
|
5604 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5605 * 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
|
5606 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5607 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5608 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5609 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5610 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5611 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5612 linenr_T Prenum1) |
7 | 5613 { |
5614 int col; | |
5615 char_u *buf1; | |
5616 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5617 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5618 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5619 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5620 uvarnumber_T oldn; |
7 | 5621 char_u *ptr; |
5622 int c; | |
5623 int todel; | |
5624 int dohex; | |
5625 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5626 int dobin; |
7 | 5627 int doalp; |
5628 int firstdigit; | |
5629 int subtract; | |
6868 | 5630 int negative = FALSE; |
6891 | 5631 int was_positive = TRUE; |
6868 | 5632 int visual = VIsual_active; |
6921 | 5633 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5634 pos_T save_cursor = curwin->w_cursor; |
6927 | 5635 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5636 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5637 pos_T endpos; |
7 | 5638 |
5639 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5640 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
|
5641 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5642 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5643 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5644 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5645 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5646 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5647 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5648 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5649 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5650 |
7 | 5651 /* |
5652 * First check if we are on a hexadecimal number, after the "0x". | |
5653 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5654 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5655 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5656 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5657 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
|
5658 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5659 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5660 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5661 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
|
5662 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5663 |
6868 | 5664 if (dohex) |
5665 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
|
5666 { |
6868 | 5667 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5668 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5669 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
|
5670 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5671 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5672 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5673 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5674 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5675 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5676 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5677 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5678 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5679 !(*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
|
5680 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5681 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5682 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5683 /* 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
|
5684 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5685 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5686 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5687 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
|
5688 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5689 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5690 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5691 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
|
5692 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5693 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5694 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5695 if (( dohex |
6868 | 5696 && col > 0 |
5697 && (ptr[col] == 'X' | |
5698 || ptr[col] == 'x') | |
5699 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5700 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5701 !(*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
|
5702 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5703 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5704 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5705 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5706 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5707 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5708 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5709 !(*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
|
5710 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5711 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5712 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5713 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5714 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5715 col -= (*mb_head_off)(ptr, ptr + col); |
6868 | 5716 } |
5717 else | |
7 | 5718 { |
6868 | 5719 /* |
5720 * Search forward and then backward to find the start of number. | |
5721 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5722 col = pos->col; |
6868 | 5723 |
5724 while (ptr[col] != NUL | |
5725 && !vim_isdigit(ptr[col]) | |
5726 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5727 col += MB_PTR2LEN(ptr + col); |
6868 | 5728 |
5729 while (col > 0 | |
5730 && vim_isdigit(ptr[col - 1]) | |
5731 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5732 { |
6868 | 5733 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5734 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5735 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
|
5736 } |
6868 | 5737 } |
5738 } | |
5739 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5740 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5741 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5742 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5743 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5744 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5745 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5746 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
|
5747 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5748 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5749 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5750 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5751 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5752 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5753 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5754 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5755 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
|
5756 && (!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
|
5757 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5758 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5759 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5760 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5761 } |
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 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5764 * 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
|
5765 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5766 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5767 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
|
5768 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5769 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5770 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5771 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5772 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5773 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5774 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5775 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5776 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5777 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5778 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5779 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5780 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5781 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5782 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5783 firstdigit = 'a'; |
6927 | 5784 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5785 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5786 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5787 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5788 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5789 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5790 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5791 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5792 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5793 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5794 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5795 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5796 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5797 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5798 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5799 firstdigit = 'z'; |
6927 | 5800 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5801 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5802 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5803 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5804 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5805 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5806 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5807 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5808 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5809 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5810 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5811 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5812 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5813 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5814 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5816 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5818 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5819 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5820 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5821 !(*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
|
5822 && !visual) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5823 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5824 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5825 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5826 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5827 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5828 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5829 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5830 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
|
5831 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5832 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5833 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5834 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5835 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5836 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5837 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5838 NULL, &n, maxlen); |
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 /* 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
|
5841 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5842 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5843 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5844 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5845 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5846 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5847 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5848 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5849 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5850 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5851 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5852 subtract ^= TRUE; |
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 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5855 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5856 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5857 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5858 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5859 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5861 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5862 if (subtract) |
6927 | 5863 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5864 if (n > oldn) |
6868 | 5865 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5866 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
|
5867 negative ^= TRUE; |
6868 | 5868 } |
7 | 5869 } |
5870 else | |
6868 | 5871 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5872 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5873 if (n < oldn) |
6868 | 5874 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5875 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5876 negative ^= TRUE; |
6868 | 5877 } |
6927 | 5878 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5879 if (n == 0) |
6868 | 5880 negative = FALSE; |
7574
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 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5883 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
|
5884 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5885 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5886 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5887 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5888 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5889 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5890 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5891 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5892 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5893 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5894 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5895 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5896 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5897 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5898 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5899 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5900 * 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
|
5901 * 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
|
5902 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5903 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5904 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5905 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5906 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5907 if (c < 0x100 && isalpha(c)) |
6868 | 5908 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5909 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5910 hexupper = TRUE; |
6868 | 5911 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5912 hexupper = FALSE; |
6891 | 5913 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5914 /* 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
|
5915 (void)del_char(FALSE); |
6868 | 5916 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5917 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5918 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5919 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5920 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5921 * 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
|
5922 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5923 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5924 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5925 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5926 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5927 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
5928 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5929 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5930 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5931 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5932 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5933 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5934 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5935 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5936 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5937 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5938 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5939 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5940 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5941 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5942 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5943 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5944 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5945 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5946 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5947 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5948 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5949 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5950 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5951 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
|
5952 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5953 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5954 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5955 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5956 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5957 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5958 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
|
5959 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5960 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5961 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5962 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
|
5963 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
|
5964 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5965 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
|
5966 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
|
5967 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5968 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
|
5969 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
|
5970 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5971 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
|
5972 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
|
5973 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5974 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5975 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5976 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5977 * 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
|
5978 * 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
|
5979 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5980 * 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
|
5981 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5982 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5983 while (length-- > 0) |
6868 | 5984 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5985 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5986 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5987 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
|
5988 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5989 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5990 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
|
5991 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5992 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5993 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5994 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5995 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5996 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5997 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5998 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5999 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
|
6000 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6001 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6002 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6003 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6004 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6005 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6006 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6007 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6008 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6009 return did_change; |
7 | 6010 } |
6011 | |
6012 #ifdef FEAT_VIMINFO | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6013 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6014 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
|
6015 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6016 #define REG_PREVIOUS 1 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6017 #define REG_EXEC 2 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6018 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6019 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6020 * 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
|
6021 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6022 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6023 prepare_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6024 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6025 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
|
6026 * (int)sizeof(yankreg_T)); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6027 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6028 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6029 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6030 finish_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6031 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6032 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6033 int j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6034 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6035 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6036 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6037 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
|
6038 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
|
6039 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6040 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
|
6041 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
|
6042 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
|
6043 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
6044 VIM_CLEAR(y_read_regs); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6045 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6046 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6047 |
7 | 6048 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6049 read_viminfo_register(vir_T *virp, int force) |
7 | 6050 { |
6051 int eof; | |
6052 int do_it = TRUE; | |
6053 int size; | |
6054 int limit; | |
6055 int i; | |
6056 int set_prev = FALSE; | |
6057 char_u *str; | |
6058 char_u **array = NULL; | |
6508 | 6059 int new_type = MCHAR; /* init to shut up compiler */ |
6060 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 6061 |
6062 /* We only get here (hopefully) if line[0] == '"' */ | |
6063 str = virp->vir_line + 1; | |
1893 | 6064 |
6065 /* If the line starts with "" this is the y_previous register. */ | |
7 | 6066 if (*str == '"') |
6067 { | |
6068 set_prev = TRUE; | |
6069 str++; | |
6070 } | |
1893 | 6071 |
7 | 6072 if (!ASCII_ISALNUM(*str) && *str != '-') |
6073 { | |
6074 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
6075 return TRUE; /* too many errors, pretend end-of-file */ | |
6076 do_it = FALSE; | |
6077 } | |
6078 get_yank_register(*str++, FALSE); | |
6079 if (!force && y_current->y_array != NULL) | |
6080 do_it = FALSE; | |
1893 | 6081 |
6082 if (*str == '@') | |
6083 { | |
6084 /* "x@: register x used for @@ */ | |
6085 if (force || execreg_lastc == NUL) | |
6086 execreg_lastc = str[-1]; | |
6087 } | |
6088 | |
7 | 6089 size = 0; |
6090 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
6091 if (do_it) | |
6092 { | |
6462 | 6093 /* |
6094 * Build the new register in array[]. | |
6095 * y_array is kept as-is until done. | |
6096 * The "do_it" flag is reset when something is wrong, in which case | |
6097 * array[] needs to be freed. | |
6098 */ | |
7 | 6099 if (set_prev) |
6100 y_previous = y_current; | |
6462 | 6101 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 6102 str = skipwhite(skiptowhite(str)); |
7 | 6103 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 6104 new_type = MCHAR; |
7 | 6105 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 6106 new_type = MBLOCK; |
7 | 6107 else |
6462 | 6108 new_type = MLINE; |
7 | 6109 /* get the block width; if it's missing we get a zero, which is OK */ |
6110 str = skipwhite(skiptowhite(str)); | |
6462 | 6111 new_width = getdigits(&str); |
7 | 6112 } |
6113 | |
6114 while (!(eof = viminfo_readline(virp)) | |
6115 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
6116 { | |
6117 if (do_it) | |
6118 { | |
6462 | 6119 if (size == limit) |
7 | 6120 { |
6462 | 6121 char_u **new_array = (char_u **) |
7 | 6122 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 6123 |
6124 if (new_array == NULL) | |
6125 { | |
6126 do_it = FALSE; | |
6127 break; | |
6128 } | |
7 | 6129 for (i = 0; i < limit; i++) |
6462 | 6130 new_array[i] = array[i]; |
7 | 6131 vim_free(array); |
6462 | 6132 array = new_array; |
7 | 6133 limit *= 2; |
6134 } | |
6135 str = viminfo_readstring(virp, 1, TRUE); | |
6136 if (str != NULL) | |
6137 array[size++] = str; | |
6138 else | |
6462 | 6139 /* error, don't store the result */ |
7 | 6140 do_it = FALSE; |
6141 } | |
6142 } | |
6508 | 6143 |
7 | 6144 if (do_it) |
6145 { | |
6462 | 6146 /* free y_array[] */ |
6147 for (i = 0; i < y_current->y_size; i++) | |
6148 vim_free(y_current->y_array[i]); | |
6149 vim_free(y_current->y_array); | |
6150 | |
6151 y_current->y_type = new_type; | |
6152 y_current->y_width = new_width; | |
6153 y_current->y_size = size; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6154 y_current->y_time_set = 0; |
7 | 6155 if (size == 0) |
6156 { | |
6157 y_current->y_array = NULL; | |
6158 } | |
6462 | 6159 else |
7 | 6160 { |
6462 | 6161 /* Move the lines from array[] to y_array[]. */ |
7 | 6162 y_current->y_array = |
6163 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
6164 for (i = 0; i < size; i++) | |
6462 | 6165 { |
6166 if (y_current->y_array == NULL) | |
6167 vim_free(array[i]); | |
6168 else | |
6169 y_current->y_array[i] = array[i]; | |
6170 } | |
7 | 6171 } |
6462 | 6172 } |
6173 else | |
6174 { | |
6175 /* Free array[] if it was filled. */ | |
6176 for (i = 0; i < size; i++) | |
6177 vim_free(array[i]); | |
6178 } | |
6179 vim_free(array); | |
6180 | |
7 | 6181 return eof; |
6182 } | |
6183 | |
9272
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 * 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
|
6186 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6187 void |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6188 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
|
6189 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6190 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
|
6191 int flags; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6192 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6193 int type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6194 int linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6195 int width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6196 time_t timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6197 yankreg_T *y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6198 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6199 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6200 /* Check the format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6201 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6202 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6203 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6204 if (values->ga_len < 6 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6205 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6206 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6207 || vp[2].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6208 || vp[3].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6209 || vp[4].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6210 || vp[5].bv_type != BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6211 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6212 flags = vp[0].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6213 name = vp[1].bv_nr; |
9307
eb52a2670c96
commit https://github.com/vim/vim/commit/67e3720a9ddd8a9d2e8344358c28fa1f4196db0d
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
6214 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
|
6215 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6216 type = vp[2].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6217 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
|
6218 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6219 linecount = vp[3].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6220 if (values->ga_len < 6 + linecount) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6221 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6222 width = vp[4].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6223 if (width < 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6224 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6225 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6226 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6227 /* 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
|
6228 * 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
|
6229 y_ptr = &y_read_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6230 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6231 y_ptr = &y_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6232 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6233 /* 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
|
6234 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
|
6235 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
|
6236 && (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
|
6237 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6238 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6239 if (y_ptr->y_array != NULL) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6240 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
|
6241 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
|
6242 vim_free(y_ptr->y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6243 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6244 if (y_read_regs == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6245 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6246 if (flags & REG_PREVIOUS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6247 y_previous = y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6248 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
|
6249 execreg_lastc = get_register_name(name); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6250 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6251 y_ptr->y_type = type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6252 y_ptr->y_width = width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6253 y_ptr->y_size = linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6254 y_ptr->y_time_set = timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6255 if (linecount == 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6256 y_ptr->y_array = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6257 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6258 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6259 y_ptr->y_array = |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6260 (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
|
6261 for (i = 0; i < linecount; i++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6262 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6263 if (vp[i + 6].bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6264 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6265 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
|
6266 vp[i + 6].bv_string = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6267 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6268 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6269 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
|
6270 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6271 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6272 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6273 |
7 | 6274 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6275 write_viminfo_registers(FILE *fp) |
7 | 6276 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6277 int i, j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6278 char_u *type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6279 char_u c; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6280 int num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6281 int max_num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6282 int max_kbyte; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6283 long len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6284 yankreg_T *y_ptr; |
7 | 6285 |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6286 fputs(_("\n# Registers:\n"), fp); |
7 | 6287 |
6288 /* Get '<' value, use old '"' value if '<' is not found. */ | |
6289 max_num_lines = get_viminfo_parameter('<'); | |
6290 if (max_num_lines < 0) | |
6291 max_num_lines = get_viminfo_parameter('"'); | |
6292 if (max_num_lines == 0) | |
6293 return; | |
6294 max_kbyte = get_viminfo_parameter('s'); | |
6295 if (max_kbyte == 0) | |
6296 return; | |
1893 | 6297 |
7 | 6298 for (i = 0; i < NUM_REGISTERS; i++) |
6299 { | |
6300 #ifdef FEAT_CLIPBOARD | |
6301 /* Skip '*'/'+' register, we don't want them back next time */ | |
6302 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
6303 continue; | |
6304 #endif | |
6305 #ifdef FEAT_DND | |
6306 /* Neither do we want the '~' register */ | |
6307 if (i == TILDE_REGISTER) | |
6308 continue; | |
6309 #endif | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6310 /* 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
|
6311 * viminfo if it's newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6312 if (y_read_regs != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6313 && 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
|
6314 && (y_regs[i].y_array == NULL || |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6315 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
|
6316 y_ptr = &y_read_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6317 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
|
6318 continue; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6319 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6320 y_ptr = &y_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6321 |
55 | 6322 /* Skip empty registers. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6323 num_lines = y_ptr->y_size; |
55 | 6324 if (num_lines == 0 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6325 || (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
|
6326 && *y_ptr->y_array[0] == NUL)) |
55 | 6327 continue; |
6328 | |
7 | 6329 if (max_kbyte > 0) |
6330 { | |
6331 /* Skip register if there is more text than the maximum size. */ | |
6332 len = 0; | |
6333 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
|
6334 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
7 | 6335 if (len > (long)max_kbyte * 1024L) |
6336 continue; | |
6337 } | |
6338 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6339 switch (y_ptr->y_type) |
7 | 6340 { |
6341 case MLINE: | |
6342 type = (char_u *)"LINE"; | |
6343 break; | |
6344 case MCHAR: | |
6345 type = (char_u *)"CHAR"; | |
6346 break; | |
6347 case MBLOCK: | |
6348 type = (char_u *)"BLOCK"; | |
6349 break; | |
6350 default: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6351 semsg(_("E574: Unknown register type %d"), y_ptr->y_type); |
7 | 6352 type = (char_u *)"LINE"; |
6353 break; | |
6354 } | |
6355 if (y_previous == &y_regs[i]) | |
6356 fprintf(fp, "\""); | |
6357 c = get_register_name(i); | |
1893 | 6358 fprintf(fp, "\"%c", c); |
6359 if (c == execreg_lastc) | |
6360 fprintf(fp, "@"); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6361 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
7 | 6362 |
6363 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
6364 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6365 num_lines = max_num_lines; | |
6366 for (j = 0; j < num_lines; j++) | |
6367 { | |
6368 putc('\t', fp); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6369 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
|
6370 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6371 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6372 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6373 int flags = 0; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6374 int remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6375 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6376 /* 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
|
6377 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6378 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6379 * 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
|
6380 * REG_EXEC - used for @@ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6381 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6382 if (y_previous == &y_regs[i]) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6383 flags |= REG_PREVIOUS; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6384 if (c == execreg_lastc) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6385 flags |= REG_EXEC; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6386 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
|
6387 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
|
6388 (long)y_ptr->y_time_set); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6389 /* 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
|
6390 remaining = LSIZE - 71; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6391 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
|
6392 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6393 putc(',', fp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6394 --remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6395 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
|
6396 remaining); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6397 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6398 putc('\n', fp); |
7 | 6399 } |
6400 } | |
6401 } | |
6402 #endif /* FEAT_VIMINFO */ | |
6403 | |
6404 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6405 /* | |
6406 * SELECTION / PRIMARY ('*') | |
6407 * | |
6408 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6409 * GUI this may be text from another window, otherwise it is the last text we | |
6410 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6411 * button performs the paste, otherwise you will need to do <"*p>. " | |
6412 * If not under X, it is synonymous with the clipboard register '+'. | |
6413 * | |
6414 * X CLIPBOARD ('+') | |
6415 * | |
6416 * Text selection stuff that uses the GUI clipboard register '+'. | |
6417 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6418 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6419 * otherwise you will need to do <"+p>. " | |
6420 * If not under X, it is synonymous with the selection register '*'. | |
6421 */ | |
6422 | |
6423 /* | |
6424 * 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
|
6425 * so that the text is still available after Vim has exited. X selections |
7 | 6426 * only exist while the owning application exists, so we write to the |
6427 * permanent (while X runs) store CUT_BUFFER0. | |
6428 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6429 * 'permanent' of the two), otherwise the PRIMARY one. | |
6430 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6431 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6432 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 6433 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6434 x11_export_final_selection(void) |
7 | 6435 { |
6436 Display *dpy; | |
6437 char_u *str = NULL; | |
6438 long_u len = 0; | |
6439 int motion_type = -1; | |
6440 | |
6441 # ifdef FEAT_GUI | |
6442 if (gui.in_use) | |
6443 dpy = X_DISPLAY; | |
6444 else | |
6445 # endif | |
6446 # ifdef FEAT_XCLIPBOARD | |
6447 dpy = xterm_dpy; | |
6448 # else | |
6449 return; | |
6450 # endif | |
6451 | |
6452 /* Get selection to export */ | |
6453 if (clip_plus.owned) | |
6454 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6455 else if (clip_star.owned) | |
6456 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6457 | |
6458 /* Check it's OK */ | |
6459 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6460 && len < 1024*1024 && len > 0) | |
6461 { | |
4201 | 6462 int ok = TRUE; |
6463 | |
1924 | 6464 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6465 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6466 * encoding conversion usually doesn't work, so keep the text as-is. | |
6467 */ | |
6468 if (has_mbyte) | |
6469 { | |
6470 vimconv_T vc; | |
6471 | |
6472 vc.vc_type = CONV_NONE; | |
6473 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6474 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6475 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6476 char_u *conv_str; |
2007 | 6477 |
4201 | 6478 vc.vc_fail = TRUE; |
2007 | 6479 conv_str = string_convert(&vc, str, &intlen); |
6480 len = intlen; | |
1924 | 6481 if (conv_str != NULL) |
6482 { | |
6483 vim_free(str); | |
6484 str = conv_str; | |
6485 } | |
4201 | 6486 else |
6487 { | |
6488 ok = FALSE; | |
6489 } | |
1924 | 6490 convert_setup(&vc, NULL, NULL); |
6491 } | |
4201 | 6492 else |
6493 { | |
6494 ok = FALSE; | |
6495 } | |
1924 | 6496 } |
4201 | 6497 |
6498 /* Do not store the string if conversion failed. Better to use any | |
6499 * other selection than garbled text. */ | |
6500 if (ok) | |
6501 { | |
6502 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6503 XFlush(dpy); | |
6504 } | |
7 | 6505 } |
6506 | |
6507 vim_free(str); | |
6508 } | |
6509 #endif | |
6510 | |
6511 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6512 clip_free_selection(VimClipboard *cbd) |
7 | 6513 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6514 yankreg_T *y_ptr = y_current; |
7 | 6515 |
6516 if (cbd == &clip_plus) | |
6517 y_current = &y_regs[PLUS_REGISTER]; | |
6518 else | |
6519 y_current = &y_regs[STAR_REGISTER]; | |
6520 free_yank_all(); | |
6521 y_current->y_size = 0; | |
6522 y_current = y_ptr; | |
6523 } | |
6524 | |
6525 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
6526 * Get the selected text and put it in register '*' or '+'. |
7 | 6527 */ |
6528 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6529 clip_get_selection(VimClipboard *cbd) |
7 | 6530 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6531 yankreg_T *old_y_previous, *old_y_current; |
7 | 6532 pos_T old_cursor; |
6533 pos_T old_visual; | |
6534 int old_visual_mode; | |
6535 colnr_T old_curswant; | |
6536 int old_set_curswant; | |
6537 pos_T old_op_start, old_op_end; | |
6538 oparg_T oa; | |
6539 cmdarg_T ca; | |
6540 | |
6541 if (cbd->owned) | |
6542 { | |
6543 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6544 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6545 return; | |
6546 | |
6547 /* Get the text between clip_star.start & clip_star.end */ | |
6548 old_y_previous = y_previous; | |
6549 old_y_current = y_current; | |
6550 old_cursor = curwin->w_cursor; | |
6551 old_curswant = curwin->w_curswant; | |
6552 old_set_curswant = curwin->w_set_curswant; | |
6553 old_op_start = curbuf->b_op_start; | |
6554 old_op_end = curbuf->b_op_end; | |
6555 old_visual = VIsual; | |
6556 old_visual_mode = VIsual_mode; | |
6557 clear_oparg(&oa); | |
6558 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6559 oa.op_type = OP_YANK; | |
6560 vim_memset(&ca, 0, sizeof(ca)); | |
6561 ca.oap = &oa; | |
6562 ca.cmdchar = 'y'; | |
6563 ca.count1 = 1; | |
6564 ca.retval = CA_NO_ADJ_OP_END; | |
6565 do_pending_operator(&ca, 0, TRUE); | |
6566 y_previous = old_y_previous; | |
6567 y_current = old_y_current; | |
6568 curwin->w_cursor = old_cursor; | |
688 | 6569 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6570 curwin->w_curswant = old_curswant; |
6571 curwin->w_set_curswant = old_set_curswant; | |
6572 curbuf->b_op_start = old_op_start; | |
6573 curbuf->b_op_end = old_op_end; | |
6574 VIsual = old_visual; | |
6575 VIsual_mode = old_visual_mode; | |
6576 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6577 else if (!is_clipboard_needs_update()) |
7 | 6578 { |
6579 clip_free_selection(cbd); | |
6580 | |
6581 /* Try to get selected text from another window */ | |
6582 clip_gen_request_selection(cbd); | |
6583 } | |
6584 } | |
6585 | |
2896 | 6586 /* |
6587 * Convert from the GUI selection string into the '*'/'+' register. | |
6588 */ | |
7 | 6589 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6590 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6591 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6592 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6593 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6594 VimClipboard *cbd) |
7 | 6595 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6596 yankreg_T *y_ptr; |
7 | 6597 |
6598 if (cbd == &clip_plus) | |
6599 y_ptr = &y_regs[PLUS_REGISTER]; | |
6600 else | |
6601 y_ptr = &y_regs[STAR_REGISTER]; | |
6602 | |
6603 clip_free_selection(cbd); | |
6604 | |
5798 | 6605 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6606 } |
6607 | |
6608 /* | |
6609 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6610 * with length *len. | |
6611 * Returns the motion type, or -1 for failure. | |
6612 */ | |
6613 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6614 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6615 { |
6616 char_u *p; | |
6617 int lnum; | |
6618 int i, j; | |
6619 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6620 yankreg_T *y_ptr; |
7 | 6621 |
6622 if (cbd == &clip_plus) | |
6623 y_ptr = &y_regs[PLUS_REGISTER]; | |
6624 else | |
6625 y_ptr = &y_regs[STAR_REGISTER]; | |
6626 | |
6627 #ifdef USE_CRNL | |
6628 eolsize = 2; | |
6629 #else | |
6630 eolsize = 1; | |
6631 #endif | |
6632 | |
6633 *str = NULL; | |
6634 *len = 0; | |
6635 if (y_ptr->y_array == NULL) | |
6636 return -1; | |
6637 | |
6638 for (i = 0; i < y_ptr->y_size; i++) | |
6639 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6640 | |
6641 /* | |
6642 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6643 */ | |
6644 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6645 *len -= eolsize; | |
6646 | |
6647 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6648 if (p == NULL) | |
6649 return -1; | |
6650 lnum = 0; | |
6651 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6652 { | |
6653 if (y_ptr->y_array[lnum][j] == '\n') | |
6654 p[i] = NUL; | |
6655 else if (y_ptr->y_array[lnum][j] == NUL) | |
6656 { | |
6657 #ifdef USE_CRNL | |
6658 p[i++] = '\r'; | |
6659 #endif | |
6660 #ifdef USE_CR | |
6661 p[i] = '\r'; | |
6662 #else | |
6663 p[i] = '\n'; | |
6664 #endif | |
6665 lnum++; | |
6666 j = -1; | |
6667 } | |
6668 else | |
6669 p[i] = y_ptr->y_array[lnum][j]; | |
6670 } | |
6671 return y_ptr->y_type; | |
6672 } | |
6673 | |
6674 | |
6675 /* | |
6676 * If we have written to a clipboard register, send the text to the clipboard. | |
6677 */ | |
6678 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6679 may_set_selection(void) |
7 | 6680 { |
6681 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6682 { | |
6683 clip_own_selection(&clip_star); | |
6684 clip_gen_set_selection(&clip_star); | |
6685 } | |
6686 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6687 { | |
6688 clip_own_selection(&clip_plus); | |
6689 clip_gen_set_selection(&clip_plus); | |
6690 } | |
6691 } | |
6692 | |
6693 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6694 | |
6695 | |
6696 #if defined(FEAT_DND) || defined(PROTO) | |
6697 /* | |
6698 * Replace the contents of the '~' register with str. | |
6699 */ | |
6700 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6701 dnd_yank_drag_data(char_u *str, long len) |
7 | 6702 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6703 yankreg_T *curr; |
7 | 6704 |
6705 curr = y_current; | |
6706 y_current = &y_regs[TILDE_REGISTER]; | |
6707 free_yank_all(); | |
5798 | 6708 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6709 y_current = curr; |
6710 } | |
6711 #endif | |
6712 | |
6713 | |
6714 #if defined(FEAT_EVAL) || defined(PROTO) | |
6715 /* | |
6716 * Return the type of a register. | |
6717 * Used for getregtype() | |
6718 * Returns MAUTO for error. | |
6719 */ | |
6720 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6721 get_reg_type(int regname, long *reglen) |
7 | 6722 { |
6723 switch (regname) | |
6724 { | |
6725 case '%': /* file name */ | |
6726 case '#': /* alternate file name */ | |
6727 case '=': /* expression */ | |
6728 case ':': /* last command line */ | |
6729 case '/': /* last search-pattern */ | |
6730 case '.': /* last inserted text */ | |
6731 #ifdef FEAT_SEARCHPATH | |
6732 case Ctrl_F: /* Filename under cursor */ | |
6733 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6734 #endif | |
6735 case Ctrl_W: /* word under cursor */ | |
6736 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6737 case '_': /* black hole: always empty */ | |
6738 return MCHAR; | |
6739 } | |
6740 | |
6741 #ifdef FEAT_CLIPBOARD | |
6742 regname = may_get_selection(regname); | |
6743 #endif | |
6744 | |
5596 | 6745 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
|
6746 return MAUTO; |
5596 | 6747 |
7 | 6748 get_yank_register(regname, FALSE); |
6749 | |
6750 if (y_current->y_array != NULL) | |
6751 { | |
6752 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6753 *reglen = y_current->y_width; | |
6754 return y_current->y_type; | |
6755 } | |
6756 return MAUTO; | |
6757 } | |
6758 | |
5796 | 6759 /* |
6760 * When "flags" has GREG_LIST return a list with text "s". | |
6761 * Otherwise just return "s". | |
6762 */ | |
6763 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6764 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6765 { |
6766 if (flags & GREG_LIST) | |
6767 { | |
6768 list_T *list = list_alloc(); | |
6769 | |
6770 if (list != NULL) | |
6771 { | |
6772 if (list_append_string(list, NULL, -1) == FAIL) | |
6773 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6774 list_free(list); |
5796 | 6775 return NULL; |
6776 } | |
6777 list->lv_first->li_tv.vval.v_string = s; | |
6778 } | |
6779 return (char_u *)list; | |
6780 } | |
6781 return s; | |
6782 } | |
6783 | |
7 | 6784 /* |
6785 * Return the contents of a register as a single allocated string. | |
6786 * Used for "@r" in expressions and for getreg(). | |
6787 * Returns NULL for error. | |
5796 | 6788 * Flags: |
6789 * GREG_NO_EXPR Do not allow expression register | |
6790 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6791 * not the result of its evaluation. | |
6792 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6793 */ |
6794 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6795 get_reg_contents(int regname, int flags) |
7 | 6796 { |
6797 long i; | |
6798 char_u *retval; | |
6799 int allocated; | |
6800 long len; | |
6801 | |
6802 /* Don't allow using an expression register inside an expression */ | |
6803 if (regname == '=') | |
6804 { | |
5796 | 6805 if (flags & GREG_NO_EXPR) |
6806 return NULL; | |
6807 if (flags & GREG_EXPR_SRC) | |
6808 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6809 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6810 } |
6811 | |
6812 if (regname == '@') /* "@@" is used for unnamed register */ | |
6813 regname = '"'; | |
6814 | |
6815 /* check for valid regname */ | |
6816 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6817 return NULL; | |
6818 | |
6819 #ifdef FEAT_CLIPBOARD | |
6820 regname = may_get_selection(regname); | |
6821 #endif | |
6822 | |
6823 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6824 { | |
6825 if (retval == NULL) | |
6826 return NULL; | |
5796 | 6827 if (allocated) |
6828 return getreg_wrap_one_line(retval, flags); | |
6829 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6830 } |
6831 | |
6832 get_yank_register(regname, FALSE); | |
6833 if (y_current->y_array == NULL) | |
6834 return NULL; | |
6835 | |
5796 | 6836 if (flags & GREG_LIST) |
6837 { | |
6838 list_T *list = list_alloc(); | |
6839 int error = FALSE; | |
6840 | |
6841 if (list == NULL) | |
6842 return NULL; | |
6843 for (i = 0; i < y_current->y_size; ++i) | |
6844 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6845 error = TRUE; | |
6846 if (error) | |
6847 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6848 list_free(list); |
5796 | 6849 return NULL; |
6850 } | |
6851 return (char_u *)list; | |
6852 } | |
6853 | |
7 | 6854 /* |
6855 * Compute length of resulting string. | |
6856 */ | |
6857 len = 0; | |
6858 for (i = 0; i < y_current->y_size; ++i) | |
6859 { | |
6860 len += (long)STRLEN(y_current->y_array[i]); | |
6861 /* | |
6862 * Insert a newline between lines and after last line if | |
6863 * y_type is MLINE. | |
6864 */ | |
6865 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6866 ++len; | |
6867 } | |
6868 | |
6869 retval = lalloc(len + 1, TRUE); | |
6870 | |
6871 /* | |
6872 * Copy the lines of the yank register into the string. | |
6873 */ | |
6874 if (retval != NULL) | |
6875 { | |
6876 len = 0; | |
6877 for (i = 0; i < y_current->y_size; ++i) | |
6878 { | |
6879 STRCPY(retval + len, y_current->y_array[i]); | |
6880 len += (long)STRLEN(retval + len); | |
6881 | |
6882 /* | |
6883 * Insert a NL between lines and after the last line if y_type is | |
6884 * MLINE. | |
6885 */ | |
6886 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6887 retval[len++] = '\n'; | |
6888 } | |
6889 retval[len] = NUL; | |
6890 } | |
6891 | |
6892 return retval; | |
6893 } | |
6894 | |
5798 | 6895 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6896 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6897 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6898 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6899 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6900 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6901 int *yank_type UNUSED) |
5798 | 6902 { |
6903 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6904 { | |
6905 emsg_invreg(name); | |
6906 return FAIL; | |
6907 } | |
6908 | |
6909 /* Don't want to change the current (unnamed) register */ | |
6910 *old_y_previous = y_previous; | |
6911 *old_y_current = y_current; | |
6912 | |
6913 get_yank_register(name, TRUE); | |
6914 if (!y_append && !must_append) | |
6915 free_yank_all(); | |
6916 return OK; | |
6917 } | |
6918 | |
6919 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6920 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6921 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6922 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6923 yankreg_T *old_y_current) |
5798 | 6924 { |
6925 # ifdef FEAT_CLIPBOARD | |
6926 /* Send text of clipboard register to the clipboard. */ | |
6927 may_set_selection(); | |
6928 # endif | |
6929 | |
6930 /* ':let @" = "val"' should change the meaning of the "" register */ | |
6931 if (name != '"') | |
6932 y_previous = old_y_previous; | |
6933 y_current = old_y_current; | |
6934 } | |
6935 | |
7 | 6936 /* |
6937 * Store string "str" in register "name". | |
6938 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
6939 * If "must_append" is TRUE, always append to the register. Otherwise append | |
6940 * if "name" is an uppercase letter. | |
6941 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
6942 * Careful: 'str' is modified, you may have to use a copy! | |
6943 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
6944 */ | |
6945 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6946 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6947 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6948 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6949 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6950 int must_append) |
7 | 6951 { |
6952 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
6953 } | |
6954 | |
6955 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6956 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6957 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6958 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6959 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6960 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6961 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6962 long block_len) |
5798 | 6963 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6964 yankreg_T *old_y_previous, *old_y_current; |
5798 | 6965 |
6966 if (name == '/' | |
6967 #ifdef FEAT_EVAL | |
6968 || name == '=' | |
6969 #endif | |
6970 ) | |
6971 { | |
6972 char_u *s; | |
6973 | |
6974 if (strings[0] == NULL) | |
6975 s = (char_u *)""; | |
6976 else if (strings[1] != NULL) | |
6977 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6978 emsg(_("E883: search pattern and expression register may not " |
5798 | 6979 "contain two or more lines")); |
6980 return; | |
6981 } | |
6982 else | |
6983 s = strings[0]; | |
6984 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
6985 return; | |
6986 } | |
6987 | |
6988 if (name == '_') /* black hole: nothing to do */ | |
6989 return; | |
6990 | |
6991 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
6992 &yank_type) == FAIL) | |
6993 return; | |
6994 | |
6995 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
6996 | |
6997 finish_write_reg(name, old_y_previous, old_y_current); | |
6998 } | |
6999 | |
7000 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7001 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7002 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7003 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7004 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7005 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7006 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7007 long block_len) |
7 | 7008 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7009 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
|
7010 long len; |
7 | 7011 |
336 | 7012 if (maxlen >= 0) |
7013 len = maxlen; | |
7014 else | |
7015 len = (long)STRLEN(str); | |
7016 | |
7 | 7017 /* Special case: '/' search pattern */ |
7018 if (name == '/') | |
7019 { | |
7020 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
7021 return; | |
7022 } | |
7023 | |
6557 | 7024 if (name == '#') |
7025 { | |
7026 buf_T *buf; | |
7027 | |
7028 if (VIM_ISDIGIT(*str)) | |
7029 { | |
7030 int num = atoi((char *)str); | |
7031 | |
7032 buf = buflist_findnr(num); | |
7033 if (buf == NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
7034 semsg(_(e_nobufnr), (long)num); |
6557 | 7035 } |
7036 else | |
7037 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
7038 TRUE, FALSE, FALSE)); | |
7039 if (buf == NULL) | |
7040 return; | |
7041 curwin->w_alt_fnum = buf->b_fnum; | |
7042 return; | |
7043 } | |
7044 | |
336 | 7045 #ifdef FEAT_EVAL |
7046 if (name == '=') | |
7047 { | |
7048 char_u *p, *s; | |
7049 | |
7050 p = vim_strnsave(str, (int)len); | |
7051 if (p == NULL) | |
7052 return; | |
7053 if (must_append) | |
7054 { | |
7055 s = concat_str(get_expr_line_src(), p); | |
7056 vim_free(p); | |
7057 p = s; | |
7058 } | |
7059 set_expr_line(p); | |
7060 return; | |
7061 } | |
7062 #endif | |
7063 | |
7 | 7064 if (name == '_') /* black hole: nothing to do */ |
7065 return; | |
7066 | |
5798 | 7067 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
7068 &yank_type) == FAIL) | |
7069 return; | |
7070 | |
7071 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
7072 | |
7073 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 7074 } |
7075 #endif /* FEAT_EVAL */ | |
7076 | |
7077 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
7078 /* | |
7079 * Put a string into a register. When the register is not empty, the string | |
7080 * is appended. | |
7081 */ | |
7082 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7083 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7084 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
|
7085 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
|
7086 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
|
7087 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7088 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7089 int str_list) /* TRUE if str is char_u ** */ |
7 | 7090 { |
2896 | 7091 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 7092 int lnum; |
7093 long start; | |
7094 long i; | |
7095 int extra; | |
7096 int newlines; /* number of lines added */ | |
7097 int extraline = 0; /* extra line at the end */ | |
7098 int append = FALSE; /* append to last line in register */ | |
7099 char_u *s; | |
5798 | 7100 char_u **ss; |
7 | 7101 char_u **pp; |
7102 long maxlen; | |
7103 | |
2000 | 7104 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 7105 y_ptr->y_size = 0; |
7106 | |
2896 | 7107 if (yank_type == MAUTO) |
5798 | 7108 type = ((str_list || (len > 0 && (str[len - 1] == NL |
7109 || str[len - 1] == CAR))) | |
2896 | 7110 ? MLINE : MCHAR); |
7111 else | |
7112 type = yank_type; | |
7113 | |
7 | 7114 /* |
7115 * Count the number of lines within the string | |
7116 */ | |
7117 newlines = 0; | |
5798 | 7118 if (str_list) |
7119 { | |
7120 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 7121 ++newlines; |
5798 | 7122 } |
7123 else | |
7124 { | |
7125 for (i = 0; i < len; i++) | |
7126 if (str[i] == '\n') | |
7127 ++newlines; | |
7128 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
7129 { | |
7130 extraline = 1; | |
7131 ++newlines; /* count extra newline at the end */ | |
7132 } | |
7133 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
7134 { | |
7135 append = TRUE; | |
7136 --newlines; /* uncount newline when appending first line */ | |
7137 } | |
7 | 7138 } |
7139 | |
6807 | 7140 /* Without any lines make the register empty. */ |
7141 if (y_ptr->y_size + newlines == 0) | |
7142 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
7143 VIM_CLEAR(y_ptr->y_array); |
6807 | 7144 return; |
7145 } | |
7146 | |
7 | 7147 /* |
7148 * Allocate an array to hold the pointers to the new register lines. | |
7149 * If the register was not empty, move the existing lines to the new array. | |
7150 */ | |
7151 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
7152 * sizeof(char_u *), TRUE); | |
7153 if (pp == NULL) /* out of memory */ | |
7154 return; | |
7155 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
7156 pp[lnum] = y_ptr->y_array[lnum]; | |
7157 vim_free(y_ptr->y_array); | |
7158 y_ptr->y_array = pp; | |
7159 maxlen = 0; | |
7160 | |
7161 /* | |
7162 * Find the end of each line and save it into the array. | |
7163 */ | |
5798 | 7164 if (str_list) |
7165 { | |
7166 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 7167 { |
5856 | 7168 i = (long)STRLEN(*ss); |
5798 | 7169 pp[lnum] = vim_strnsave(*ss, i); |
7170 if (i > maxlen) | |
7171 maxlen = i; | |
7 | 7172 } |
5798 | 7173 } |
7174 else | |
7175 { | |
7176 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 7177 { |
5798 | 7178 for (i = start; i < len; ++i) /* find the end of the line */ |
7179 if (str[i] == '\n') | |
7180 break; | |
7181 i -= start; /* i is now length of line */ | |
7182 if (i > maxlen) | |
7183 maxlen = i; | |
7184 if (append) | |
7185 { | |
7186 --lnum; | |
7187 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
7188 } | |
7189 else | |
7190 extra = 0; | |
7191 s = alloc((unsigned)(i + extra + 1)); | |
7192 if (s == NULL) | |
7193 break; | |
7194 if (extra) | |
7195 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
7196 if (append) | |
7197 vim_free(y_ptr->y_array[lnum]); | |
7198 if (i) | |
7199 mch_memmove(s + extra, str + start, (size_t)i); | |
7200 extra += i; | |
7201 s[extra] = NUL; | |
7202 y_ptr->y_array[lnum++] = s; | |
7203 while (--extra >= 0) | |
7204 { | |
7205 if (*s == NUL) | |
7206 *s = '\n'; /* replace NUL with newline */ | |
7207 ++s; | |
7208 } | |
7209 append = FALSE; /* only first line is appended */ | |
7 | 7210 } |
7211 } | |
7212 y_ptr->y_type = type; | |
7213 y_ptr->y_size = lnum; | |
7214 if (type == MBLOCK) | |
7215 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
7216 else | |
7217 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7218 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7219 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
|
7220 #endif |
7 | 7221 } |
7222 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
7223 | |
7224 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7225 clear_oparg(oparg_T *oap) |
7 | 7226 { |
7227 vim_memset(oap, 0, sizeof(oparg_T)); | |
7228 } | |
7229 | |
7230 /* | |
161 | 7231 * Count the number of bytes, characters and "words" in a line. |
7 | 7232 * |
7233 * "Words" are counted by looking for boundaries between non-space and | |
7234 * space characters. (it seems to produce results that match 'wc'.) | |
7235 * | |
161 | 7236 * Return value is byte count; word count for the line is added to "*wc". |
7237 * Char count is added to "*cc". | |
7 | 7238 * |
7239 * The function will only examine the first "limit" characters in the | |
7240 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
7241 * case, eol_size will be added to the character count to account for | |
7242 * the size of the EOL character. | |
7243 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7244 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7245 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7246 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7247 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7248 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7249 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7250 int eol_size) |
7 | 7251 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7252 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7253 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7254 varnumber_T chars = 0; |
7 | 7255 int is_word = 0; |
7256 | |
3626 | 7257 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 7258 { |
7259 if (is_word) | |
7260 { | |
7261 if (vim_isspace(line[i])) | |
7262 { | |
7263 words++; | |
7264 is_word = 0; | |
7265 } | |
7266 } | |
7267 else if (!vim_isspace(line[i])) | |
7268 is_word = 1; | |
161 | 7269 ++chars; |
474 | 7270 i += (*mb_ptr2len)(line + i); |
7 | 7271 } |
7272 | |
7273 if (is_word) | |
7274 words++; | |
7275 *wc += words; | |
7276 | |
7277 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 7278 if (i < limit && line[i] == NUL) |
161 | 7279 { |
7 | 7280 i += eol_size; |
161 | 7281 chars += eol_size; |
7282 } | |
7283 *cc += chars; | |
7 | 7284 return i; |
7285 } | |
7286 | |
7287 /* | |
7288 * Give some info about the position of the cursor (for "g CTRL-G"). | |
7289 * In Visual mode, give some info about the selected region. (In this case, | |
7290 * 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
|
7291 * When "dict" is not NULL store the info there instead of showing it. |
7 | 7292 */ |
7293 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7294 cursor_pos_info(dict_T *dict) |
7 | 7295 { |
7296 char_u *p; | |
274 | 7297 char_u buf1[50]; |
7298 char_u buf2[40]; | |
7 | 7299 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7300 varnumber_T byte_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7301 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7302 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7303 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7304 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7305 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7306 varnumber_T word_count_cursor = 0; |
7 | 7307 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7308 varnumber_T last_check = 100000L; |
7 | 7309 long line_count_selected = 0; |
7310 pos_T min_pos, max_pos; | |
7311 oparg_T oparg; | |
7312 struct block_def bd; | |
7313 | |
7314 /* | |
7315 * Compute the length of the file in characters. | |
7316 */ | |
7317 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
7318 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7319 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7320 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
7321 msg(_(no_lines_msg)); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7322 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7323 } |
7 | 7324 } |
7325 else | |
7326 { | |
7327 if (get_fileformat(curbuf) == EOL_DOS) | |
7328 eol_size = 2; | |
7329 else | |
7330 eol_size = 1; | |
7331 | |
7332 if (VIsual_active) | |
7333 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
7334 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 7335 { |
7336 min_pos = VIsual; | |
7337 max_pos = curwin->w_cursor; | |
7338 } | |
7339 else | |
7340 { | |
7341 min_pos = curwin->w_cursor; | |
7342 max_pos = VIsual; | |
7343 } | |
7344 if (*p_sel == 'e' && max_pos.col > 0) | |
7345 --max_pos.col; | |
7346 | |
7347 if (VIsual_mode == Ctrl_V) | |
7348 { | |
1866 | 7349 #ifdef FEAT_LINEBREAK |
7350 char_u * saved_sbr = p_sbr; | |
7351 | |
7352 /* Make 'sbr' empty for a moment to get the correct size. */ | |
7353 p_sbr = empty_option; | |
7354 #endif | |
7 | 7355 oparg.is_VIsual = 1; |
7356 oparg.block_mode = TRUE; | |
7357 oparg.op_type = OP_NOP; | |
7358 getvcols(curwin, &min_pos, &max_pos, | |
688 | 7359 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 7360 #ifdef FEAT_LINEBREAK |
7361 p_sbr = saved_sbr; | |
7362 #endif | |
688 | 7363 if (curwin->w_curswant == MAXCOL) |
7364 oparg.end_vcol = MAXCOL; | |
7 | 7365 /* Swap the start, end vcol if needed */ |
7366 if (oparg.end_vcol < oparg.start_vcol) | |
7367 { | |
7368 oparg.end_vcol += oparg.start_vcol; | |
7369 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
7370 oparg.end_vcol -= oparg.start_vcol; | |
7371 } | |
7372 } | |
7373 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
7374 } | |
7375 | |
7376 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
7377 { | |
7378 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 7379 if (byte_count > last_check) |
7 | 7380 { |
7381 ui_breakcheck(); | |
7382 if (got_int) | |
7383 return; | |
161 | 7384 last_check = byte_count + 100000L; |
7 | 7385 } |
7386 | |
7387 /* Do extra processing for VIsual mode. */ | |
7388 if (VIsual_active | |
7389 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7390 { | |
45 | 7391 char_u *s = NULL; |
7392 long len = 0L; | |
7393 | |
7 | 7394 switch (VIsual_mode) |
7395 { | |
7396 case Ctrl_V: | |
5735 | 7397 #ifdef FEAT_VIRTUALEDIT |
7 | 7398 virtual_op = virtual_active(); |
5735 | 7399 #endif |
7 | 7400 block_prep(&oparg, &bd, lnum, 0); |
5735 | 7401 #ifdef FEAT_VIRTUALEDIT |
7 | 7402 virtual_op = MAYBE; |
5735 | 7403 #endif |
45 | 7404 s = bd.textstart; |
7405 len = (long)bd.textlen; | |
7 | 7406 break; |
7407 case 'V': | |
45 | 7408 s = ml_get(lnum); |
7409 len = MAXCOL; | |
7 | 7410 break; |
7411 case 'v': | |
7412 { | |
7413 colnr_T start_col = (lnum == min_pos.lnum) | |
7414 ? min_pos.col : 0; | |
7415 colnr_T end_col = (lnum == max_pos.lnum) | |
7416 ? max_pos.col - start_col + 1 : MAXCOL; | |
7417 | |
45 | 7418 s = ml_get(lnum) + start_col; |
7419 len = end_col; | |
7 | 7420 } |
7421 break; | |
7422 } | |
45 | 7423 if (s != NULL) |
7424 { | |
161 | 7425 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7426 &char_count_cursor, len, eol_size); | |
45 | 7427 if (lnum == curbuf->b_ml.ml_line_count |
7428 && !curbuf->b_p_eol | |
6933 | 7429 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7430 && (long)STRLEN(s) < len) |
161 | 7431 byte_count_cursor -= eol_size; |
45 | 7432 } |
7 | 7433 } |
7434 else | |
7435 { | |
7436 /* In non-visual mode, check for the line the cursor is on */ | |
7437 if (lnum == curwin->w_cursor.lnum) | |
7438 { | |
7439 word_count_cursor += word_count; | |
161 | 7440 char_count_cursor += char_count; |
7441 byte_count_cursor = byte_count + | |
7442 line_count_info(ml_get(lnum), | |
7443 &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
|
7444 (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
|
7445 eol_size); |
7 | 7446 } |
7447 } | |
7448 /* Add to the running totals */ | |
161 | 7449 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
|
7450 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7451 eol_size); |
7 | 7452 } |
7453 | |
7454 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7455 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7456 byte_count -= eol_size; |
7 | 7457 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7458 if (dict == NULL) |
7 | 7459 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7460 if (VIsual_active) |
7 | 7461 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7462 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
|
7463 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7464 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
|
7465 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7466 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
|
7467 (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
|
7468 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7469 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7470 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7471 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7472 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
|
7473 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7474 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7475 _("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
|
7476 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7477 (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
|
7478 (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
|
7479 (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
|
7480 (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
|
7481 (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7482 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7483 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7484 _("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
|
7485 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7486 (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
|
7487 (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
|
7488 (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
|
7489 (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
|
7490 (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
|
7491 (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
|
7492 (long_long_T)byte_count); |
7 | 7493 } |
7494 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7495 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7496 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7497 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7498 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
|
7499 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7500 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
|
7501 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7502 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7503 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
|
7504 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7505 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7506 _("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
|
7507 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7508 (long)curwin->w_cursor.lnum, |
7 | 7509 (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
|
7510 (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
|
7511 (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
|
7512 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7513 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7514 _("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
|
7515 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7516 (long)curwin->w_cursor.lnum, |
161 | 7517 (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
|
7518 (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
|
7519 (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
|
7520 (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
|
7521 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7522 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7523 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7524 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7525 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7526 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
|
7527 _("(+%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
|
7528 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7529 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7530 /* 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
|
7531 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7532 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
|
7533 msg((char *)IObuff); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7534 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7535 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7536 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7537 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7538 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7539 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7540 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
|
7541 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
|
7542 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
|
7543 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
|
7544 byte_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7545 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
|
7546 char_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7547 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
|
7548 word_count_cursor); |
7 | 7549 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7550 #endif |
7 | 7551 } |