Mercurial > vim
annotate src/ops.c @ 14214:68166b841ee9 v8.1.0124
patch 8.1.0124: has('vcon') returns true even for non-win32 terminal
commit https://github.com/vim/vim/commit/d8b37a53bd29cab78c6997aa75207385213f23e2
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jun 28 15:50:28 2018 +0200
patch 8.1.0124: has('vcon') returns true even for non-win32 terminal
Problem: has('vcon') returns true even for non-win32 terminal.
Solution: Check the terminal type. (Nobuhiro Takasaki, closes https://github.com/vim/vim/issues/3106)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 28 Jun 2018 16:00:07 +0200 |
parents | 51693b1a640e |
children | 12bdbf9f7e20 |
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 #ifdef FEAT_VISUALEXTRA | |
86 int is_short; /* TRUE if line is too short to fit in block */ | |
87 int is_MAX; /* TRUE if curswant==MAXCOL when starting */ | |
88 int is_oneChar; /* TRUE if block within one character */ | |
89 int pre_whitesp; /* screen cols of ws before block */ | |
90 int pre_whitesp_c; /* chars of ws before block */ | |
91 colnr_T end_char_vcols; /* number of vcols of post-block char */ | |
92 #endif | |
93 colnr_T start_char_vcols; /* number of vcols of pre-block char */ | |
94 }; | |
95 | |
96 #ifdef FEAT_VISUALEXTRA | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
97 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
|
98 static void block_insert(oparg_T *oap, char_u *s, int b_insert, struct block_def*bdp); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
99 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
104 static void stuffescaped(char_u *arg, int literally); |
7 | 105 #ifdef FEAT_MBYTE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
106 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
|
107 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
108 static void free_yank(long); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
109 static void free_yank_all(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
110 static int yank_copy_line(struct block_def *bd, long y_idx); |
7 | 111 #ifdef FEAT_CLIPBOARD |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
112 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
|
113 static void may_set_selection(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
114 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
115 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
|
116 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
|
117 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
7 | 118 #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
|
119 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
|
120 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
121 static int ends_in_white(linenr_T lnum); |
7 | 122 #ifdef FEAT_COMMENTS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
123 static int same_leader(linenr_T lnum, int, char_u *, int, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
124 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 125 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
126 static int fmt_check_par(linenr_T); |
7 | 127 #endif |
128 | |
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
|
129 // 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
|
130 #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
|
131 #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
|
132 |
7 | 133 /* |
134 * The names of operators. | |
135 * 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
|
136 * The third field holds OPF_ flags. |
7 | 137 */ |
138 static char opchars[][3] = | |
139 { | |
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
|
140 {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
|
141 {'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
|
142 {'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
|
143 {'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
|
144 {'<', 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
|
145 {'>', 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
|
146 {'!', 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
|
147 {'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
|
148 {'=', 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
|
149 {'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
|
150 {':', 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
|
151 {'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
|
152 {'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
|
153 {'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
|
154 {'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
|
155 {'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
|
156 {'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
|
157 {'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
|
158 {'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
|
159 {'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
|
160 {'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
|
161 {'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
|
162 {'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
|
163 {'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
|
164 {'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
|
165 {'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
|
166 {'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
|
167 {'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
|
168 {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
|
169 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB |
7 | 170 }; |
171 | |
172 /* | |
173 * Translate a command name into an operator type. | |
174 * Must only be called with a valid operator name! | |
175 */ | |
176 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
177 get_op_type(int char1, int char2) |
7 | 178 { |
179 int i; | |
180 | |
181 if (char1 == 'r') /* ignore second character */ | |
182 return OP_REPLACE; | |
183 if (char1 == '~') /* when tilde is an operator */ | |
184 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
185 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
|
186 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
187 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
|
188 return OP_NR_SUB; |
7 | 189 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
|
190 { |
7 | 191 if (opchars[i][0] == char1 && opchars[i][1] == char2) |
192 break; | |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
193 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
|
194 { |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
195 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
|
196 break; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
197 } |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
198 } |
7 | 199 return i; |
200 } | |
201 | |
202 /* | |
203 * Return TRUE if operator "op" always works on whole lines. | |
204 */ | |
205 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
206 op_on_lines(int op) |
7 | 207 { |
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
|
208 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
|
209 } |
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
|
210 |
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
|
211 /* |
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
|
212 * 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
|
213 */ |
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
|
214 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
|
215 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
|
216 { |
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
|
217 return opchars[op][2] & OPF_CHANGE; |
7 | 218 } |
219 | |
220 /* | |
221 * Get first operator command character. | |
222 * Returns 'g' or 'z' if there is another command character. | |
223 */ | |
224 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
225 get_op_char(int optype) |
7 | 226 { |
227 return opchars[optype][0]; | |
228 } | |
229 | |
230 /* | |
231 * Get second operator command character. | |
232 */ | |
233 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
234 get_extra_op_char(int optype) |
7 | 235 { |
236 return opchars[optype][1]; | |
237 } | |
238 | |
239 /* | |
240 * op_shift - handle a shift operation | |
241 */ | |
242 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
243 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 244 { |
245 long i; | |
246 int first_char; | |
247 char_u *s; | |
248 int block_col = 0; | |
249 | |
250 if (u_save((linenr_T)(oap->start.lnum - 1), | |
251 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
252 return; | |
253 | |
254 if (oap->block_mode) | |
255 block_col = curwin->w_cursor.col; | |
256 | |
257 for (i = oap->line_count; --i >= 0; ) | |
258 { | |
259 first_char = *ml_get_curline(); | |
260 if (first_char == NUL) /* empty line */ | |
261 curwin->w_cursor.col = 0; | |
262 #ifdef FEAT_VISUALEXTRA | |
263 else if (oap->block_mode) | |
264 shift_block(oap, amount); | |
265 #endif | |
266 else | |
267 /* Move the line right if it doesn't start with '#', 'smartindent' | |
268 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
269 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
270 if (first_char != '#' || !preprocs_left()) | |
271 #endif | |
272 { | |
1516 | 273 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 274 } |
275 ++curwin->w_cursor.lnum; | |
276 } | |
277 | |
278 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
279 if (oap->block_mode) | |
280 { | |
281 curwin->w_cursor.lnum = oap->start.lnum; | |
282 curwin->w_cursor.col = block_col; | |
283 } | |
5735 | 284 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 285 { |
286 curwin->w_cursor.lnum = oap->start.lnum; | |
287 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
288 } | |
289 else | |
290 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
291 | |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
292 #ifdef FEAT_FOLDING |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
293 /* 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
|
294 foldOpenCursor(); |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
295 #endif |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
296 |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
297 |
7 | 298 if (oap->line_count > p_report) |
299 { | |
300 if (oap->op_type == OP_RSHIFT) | |
301 s = (char_u *)">"; | |
302 else | |
303 s = (char_u *)"<"; | |
304 if (oap->line_count == 1) | |
305 { | |
306 if (amount == 1) | |
307 sprintf((char *)IObuff, _("1 line %sed 1 time"), s); | |
308 else | |
309 sprintf((char *)IObuff, _("1 line %sed %d times"), s, amount); | |
310 } | |
311 else | |
312 { | |
313 if (amount == 1) | |
314 sprintf((char *)IObuff, _("%ld lines %sed 1 time"), | |
315 oap->line_count, s); | |
316 else | |
317 sprintf((char *)IObuff, _("%ld lines %sed %d times"), | |
318 oap->line_count, s, amount); | |
319 } | |
320 msg(IObuff); | |
321 } | |
322 | |
323 /* | |
324 * Set "'[" and "']" marks. | |
325 */ | |
326 curbuf->b_op_start = oap->start; | |
327 curbuf->b_op_end.lnum = oap->end.lnum; | |
328 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
329 if (curbuf->b_op_end.col > 0) | |
330 --curbuf->b_op_end.col; | |
331 } | |
332 | |
333 /* | |
334 * shift the current line one shiftwidth left (if left != 0) or right | |
335 * leaves cursor on first blank in the line | |
336 */ | |
337 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
338 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
339 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
340 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
341 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
342 int call_changed_bytes) /* call changed_bytes() */ |
7 | 343 { |
344 int count; | |
345 int i, j; | |
5438 | 346 int p_sw = (int)get_sw_value(curbuf); |
7 | 347 |
348 count = get_indent(); /* get current indent */ | |
349 | |
350 if (round) /* round off indent */ | |
351 { | |
352 i = count / p_sw; /* number of p_sw rounded down */ | |
353 j = count % p_sw; /* extra spaces */ | |
354 if (j && left) /* first remove extra spaces */ | |
355 --amount; | |
356 if (left) | |
357 { | |
358 i -= amount; | |
359 if (i < 0) | |
360 i = 0; | |
361 } | |
362 else | |
363 i += amount; | |
364 count = i * p_sw; | |
365 } | |
366 else /* original vi indent */ | |
367 { | |
368 if (left) | |
369 { | |
370 count -= p_sw * amount; | |
371 if (count < 0) | |
372 count = 0; | |
373 } | |
374 else | |
375 count += p_sw * amount; | |
376 } | |
377 | |
378 /* Set new indent */ | |
379 #ifdef FEAT_VREPLACE | |
380 if (State & VREPLACE_FLAG) | |
1516 | 381 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 382 else |
383 #endif | |
1516 | 384 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 385 } |
386 | |
387 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
388 /* | |
389 * Shift one line of the current block one shiftwidth right or left. | |
390 * Leaves cursor on first character in block. | |
391 */ | |
392 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
393 shift_block(oparg_T *oap, int amount) |
7 | 394 { |
395 int left = (oap->op_type == OP_LSHIFT); | |
396 int oldstate = State; | |
1839 | 397 int total; |
398 char_u *newp, *oldp; | |
7 | 399 int oldcol = curwin->w_cursor.col; |
5438 | 400 int p_sw = (int)get_sw_value(curbuf); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
401 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
402 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
|
403 #endif |
7 | 404 int p_ts = (int)curbuf->b_p_ts; |
405 struct block_def bd; | |
406 int incr; | |
1839 | 407 colnr_T ws_vcol; |
7 | 408 int i = 0, j = 0; |
409 int len; | |
410 #ifdef FEAT_RIGHTLEFT | |
411 int old_p_ri = p_ri; | |
412 | |
4352 | 413 p_ri = 0; /* don't want revins in indent */ |
7 | 414 #endif |
415 | |
416 State = INSERT; /* don't want REPLACE for State */ | |
417 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
418 if (bd.is_short) | |
419 return; | |
420 | |
421 /* 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
|
422 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
|
423 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
|
424 return; /* multiplication overflow */ |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
425 |
7 | 426 oldp = ml_get_curline(); |
427 | |
428 if (!left) | |
429 { | |
430 /* | |
431 * 1. Get start vcol | |
432 * 2. Total ws vcols | |
433 * 3. Divvy into TABs & spp | |
434 * 4. Construct new string | |
435 */ | |
436 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
437 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
438 if (bd.startspaces) | |
439 { | |
440 #ifdef FEAT_MBYTE | |
441 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
442 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
443 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
444 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
445 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
446 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
447 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
448 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
449 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
450 } |
1995 | 451 else |
452 #endif | |
453 ++bd.textstart; | |
7 | 454 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
455 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 456 { |
5995 | 457 /* TODO: is passing bd.textstart for start of the line OK? */ |
458 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
459 (colnr_T)(bd.start_vcol)); | |
7 | 460 total += incr; |
461 bd.start_vcol += incr; | |
462 } | |
463 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
464 * 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
|
465 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
466 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
|
467 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
|
468 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
469 j = total; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
470 #else |
7 | 471 if (!curbuf->b_p_et) |
472 i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ | |
473 if (i) | |
474 j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ | |
475 else | |
476 j = total; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
477 #endif |
7 | 478 /* if we're splitting a TAB, allow for it */ |
479 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
480 len = (int)STRLEN(bd.textstart) + 1; | |
481 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | |
482 if (newp == NULL) | |
483 return; | |
484 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
485 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 486 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
487 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 488 /* the end */ |
489 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
490 } | |
491 else /* left */ | |
492 { | |
1839 | 493 colnr_T destination_col; /* column to which text in block will |
494 be shifted */ | |
495 char_u *verbatim_copy_end; /* end of the part of the line which is | |
496 copied verbatim */ | |
497 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
498 of line */ | |
499 unsigned fill; /* nr of spaces that replace a TAB */ | |
500 unsigned new_line_len; /* the length of the line after the | |
501 block shift */ | |
502 size_t block_space_width; | |
503 size_t shift_amount; | |
504 char_u *non_white = bd.textstart; | |
505 colnr_T non_white_col; | |
506 | |
507 /* | |
508 * Firstly, let's find the first non-whitespace character that is | |
509 * displayed after the block's start column and the character's column | |
510 * number. Also, let's calculate the width of all the whitespace | |
511 * characters that are displayed in the block and precede the searched | |
512 * non-whitespace character. | |
513 */ | |
514 | |
515 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
516 * the part of which is displayed at the block's beginning. Let's start | |
517 * searching from the next character. */ | |
518 if (bd.startspaces) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
519 MB_PTR_ADV(non_white); |
1839 | 520 |
521 /* The character's column is in "bd.start_vcol". */ | |
522 non_white_col = bd.start_vcol; | |
523 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
524 while (VIM_ISWHITE(*non_white)) |
7 | 525 { |
5995 | 526 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 527 non_white_col += incr; |
7 | 528 } |
1839 | 529 |
530 block_space_width = non_white_col - oap->start_vcol; | |
531 /* We will shift by "total" or "block_space_width", whichever is less. | |
532 */ | |
1860 | 533 shift_amount = (block_space_width < (size_t)total |
534 ? block_space_width : (size_t)total); | |
1839 | 535 |
536 /* The column to which we will shift the text. */ | |
1860 | 537 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 538 |
539 /* Now let's find out how much of the beginning of the line we can | |
540 * reuse without modification. */ | |
541 verbatim_copy_end = bd.textstart; | |
542 verbatim_copy_width = bd.start_vcol; | |
543 | |
544 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
545 * preceding the block. We have to subtract its width to obtain its | |
546 * column number. */ | |
547 if (bd.startspaces) | |
548 verbatim_copy_width -= bd.start_char_vcols; | |
549 while (verbatim_copy_width < destination_col) | |
7 | 550 { |
5995 | 551 char_u *line = verbatim_copy_end; |
552 | |
553 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
554 incr = lbr_chartabsize(line, verbatim_copy_end, | |
555 verbatim_copy_width); | |
1839 | 556 if (verbatim_copy_width + incr > destination_col) |
557 break; | |
558 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
|
559 MB_PTR_ADV(verbatim_copy_end); |
7 | 560 } |
561 | |
1839 | 562 /* If "destination_col" is different from the width of the initial |
563 * part of the line that will be copied, it means we encountered a tab | |
564 * character, which we will have to partly replace with spaces. */ | |
565 fill = destination_col - verbatim_copy_width; | |
566 | |
567 /* The replacement line will consist of: | |
568 * - the beginning of the original line up to "verbatim_copy_end", | |
569 * - "fill" number of spaces, | |
570 * - the rest of the line, pointed to by non_white. */ | |
571 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
572 + fill | |
573 + (unsigned)STRLEN(non_white) + 1; | |
574 | |
575 newp = alloc_check(new_line_len); | |
7 | 576 if (newp == NULL) |
577 return; | |
1839 | 578 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 579 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 580 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 581 } |
582 /* replace the line */ | |
583 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
584 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
585 State = oldstate; | |
586 curwin->w_cursor.col = oldcol; | |
587 #ifdef FEAT_RIGHTLEFT | |
588 p_ri = old_p_ri; | |
589 #endif | |
590 } | |
591 #endif | |
592 | |
593 #ifdef FEAT_VISUALEXTRA | |
594 /* | |
595 * Insert string "s" (b_insert ? before : after) block :AKelly | |
596 * Caller must prepare for undo. | |
597 */ | |
598 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
599 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
600 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
601 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
602 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
603 struct block_def *bdp) |
7 | 604 { |
605 int p_ts; | |
606 int count = 0; /* extra spaces to replace a cut TAB */ | |
607 int spaces = 0; /* non-zero if cutting a TAB */ | |
608 colnr_T offset; /* pointer along new line */ | |
609 unsigned s_len; /* STRLEN(s) */ | |
610 char_u *newp, *oldp; /* new, old lines */ | |
611 linenr_T lnum; /* loop var */ | |
612 int oldstate = State; | |
613 | |
614 State = INSERT; /* don't want REPLACE for State */ | |
615 s_len = (unsigned)STRLEN(s); | |
616 | |
617 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
618 { | |
619 block_prep(oap, bdp, lnum, TRUE); | |
620 if (bdp->is_short && b_insert) | |
621 continue; /* OP_INSERT, line ends before block start */ | |
622 | |
623 oldp = ml_get(lnum); | |
624 | |
625 if (b_insert) | |
626 { | |
627 p_ts = bdp->start_char_vcols; | |
628 spaces = bdp->startspaces; | |
629 if (spaces != 0) | |
630 count = p_ts - 1; /* we're cutting a TAB */ | |
631 offset = bdp->textcol; | |
632 } | |
633 else /* append */ | |
634 { | |
635 p_ts = bdp->end_char_vcols; | |
636 if (!bdp->is_short) /* spaces = padding after block */ | |
637 { | |
638 spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); | |
639 if (spaces != 0) | |
640 count = p_ts - 1; /* we're cutting a TAB */ | |
641 offset = bdp->textcol + bdp->textlen - (spaces != 0); | |
642 } | |
643 else /* spaces = padding to block edge */ | |
644 { | |
645 /* if $ used, just append to EOL (ie spaces==0) */ | |
646 if (!bdp->is_MAX) | |
647 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
648 count = spaces; | |
649 offset = bdp->textcol + bdp->textlen; | |
650 } | |
651 } | |
652 | |
6140 | 653 #ifdef FEAT_MBYTE |
654 if (has_mbyte && spaces > 0) | |
655 { | |
6460 | 656 int off; |
657 | |
6140 | 658 /* Avoid starting halfway a multi-byte character. */ |
659 if (b_insert) | |
660 { | |
6460 | 661 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 662 } |
663 else | |
664 { | |
6460 | 665 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 666 offset += off; |
667 } | |
6460 | 668 spaces -= off; |
669 count -= off; | |
6140 | 670 } |
671 #endif | |
672 | |
7 | 673 newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); |
674 if (newp == NULL) | |
675 continue; | |
676 | |
677 /* copy up to shifted part */ | |
678 mch_memmove(newp, oldp, (size_t)(offset)); | |
679 oldp += offset; | |
680 | |
681 /* insert pre-padding */ | |
6929 | 682 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 683 |
684 /* copy the new text */ | |
685 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
686 offset += s_len; | |
687 | |
688 if (spaces && !bdp->is_short) | |
689 { | |
690 /* insert post-padding */ | |
6929 | 691 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
7 | 692 /* We're splitting a TAB, don't copy it. */ |
693 oldp++; | |
694 /* We allowed for that TAB, remember this now */ | |
695 count++; | |
696 } | |
697 | |
698 if (spaces > 0) | |
699 offset += count; | |
1622 | 700 STRMOVE(newp + offset, oldp); |
7 | 701 |
702 ml_replace(lnum, newp, FALSE); | |
703 | |
704 if (lnum == oap->end.lnum) | |
705 { | |
706 /* Set "']" mark to the end of the block instead of the end of | |
707 * the insert in the first line. */ | |
708 curbuf->b_op_end.lnum = oap->end.lnum; | |
709 curbuf->b_op_end.col = offset; | |
710 } | |
711 } /* for all lnum */ | |
712 | |
713 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
714 | |
715 State = oldstate; | |
716 } | |
717 #endif | |
718 | |
719 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
720 /* | |
721 * op_reindent - handle reindenting a block of lines. | |
722 */ | |
723 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
724 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 725 { |
726 long i; | |
727 char_u *l; | |
6971 | 728 int amount; |
7 | 729 linenr_T first_changed = 0; |
730 linenr_T last_changed = 0; | |
731 linenr_T start_lnum = curwin->w_cursor.lnum; | |
732 | |
216 | 733 /* Don't even try when 'modifiable' is off. */ |
734 if (!curbuf->b_p_ma) | |
735 { | |
736 EMSG(_(e_modifiable)); | |
737 return; | |
738 } | |
739 | |
7 | 740 for (i = oap->line_count; --i >= 0 && !got_int; ) |
741 { | |
742 /* it's a slow thing to do, so give feedback so there's no worry that | |
743 * the computer's just hung. */ | |
744 | |
745 if (i > 1 | |
746 && (i % 50 == 0 || i == oap->line_count - 1) | |
747 && oap->line_count > p_report) | |
748 smsg((char_u *)_("%ld lines to indent... "), i); | |
749 | |
750 /* | |
751 * Be vi-compatible: For lisp indenting the first line is not | |
752 * indented, unless there is only one line. | |
753 */ | |
754 #ifdef FEAT_LISP | |
755 if (i != oap->line_count - 1 || oap->line_count == 1 | |
756 || how != get_lisp_indent) | |
757 #endif | |
758 { | |
759 l = skipwhite(ml_get_curline()); | |
760 if (*l == NUL) /* empty or blank line */ | |
6971 | 761 amount = 0; |
7 | 762 else |
6971 | 763 amount = how(); /* get the indent for this line */ |
764 | |
765 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 766 { |
767 /* did change the indent, call changed_lines() later */ | |
768 if (first_changed == 0) | |
769 first_changed = curwin->w_cursor.lnum; | |
770 last_changed = curwin->w_cursor.lnum; | |
771 } | |
772 } | |
773 ++curwin->w_cursor.lnum; | |
1550 | 774 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 775 } |
776 | |
777 /* put cursor on first non-blank of indented line */ | |
778 curwin->w_cursor.lnum = start_lnum; | |
779 beginline(BL_SOL | BL_FIX); | |
780 | |
781 /* Mark changed lines so that they will be redrawn. When Visual | |
782 * highlighting was present, need to continue until the last line. When | |
783 * there is no change still need to remove the Visual highlighting. */ | |
784 if (last_changed != 0) | |
785 changed_lines(first_changed, 0, | |
786 oap->is_VIsual ? start_lnum + oap->line_count : | |
787 last_changed + 1, 0L); | |
788 else if (oap->is_VIsual) | |
789 redraw_curbuf_later(INVERTED); | |
790 | |
791 if (oap->line_count > p_report) | |
792 { | |
793 i = oap->line_count - (i + 1); | |
794 if (i == 1) | |
795 MSG(_("1 line indented ")); | |
796 else | |
797 smsg((char_u *)_("%ld lines indented "), i); | |
798 } | |
799 /* set '[ and '] marks */ | |
800 curbuf->b_op_start = oap->start; | |
801 curbuf->b_op_end = oap->end; | |
802 } | |
803 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
804 | |
805 #if defined(FEAT_EVAL) || defined(PROTO) | |
806 /* | |
807 * Keep the last expression line here, for repeating. | |
808 */ | |
809 static char_u *expr_line = NULL; | |
810 | |
811 /* | |
812 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
813 * Returns '=' when OK, NUL otherwise. | |
814 */ | |
815 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
816 get_expr_register(void) |
7 | 817 { |
818 char_u *new_line; | |
819 | |
820 new_line = getcmdline('=', 0L, 0); | |
821 if (new_line == NULL) | |
822 return NUL; | |
823 if (*new_line == NUL) /* use previous line */ | |
824 vim_free(new_line); | |
825 else | |
826 set_expr_line(new_line); | |
827 return '='; | |
828 } | |
829 | |
830 /* | |
831 * Set the expression for the '=' register. | |
832 * Argument must be an allocated string. | |
833 */ | |
834 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
835 set_expr_line(char_u *new_line) |
7 | 836 { |
837 vim_free(expr_line); | |
838 expr_line = new_line; | |
839 } | |
840 | |
841 /* | |
842 * Get the result of the '=' register expression. | |
843 * Returns a pointer to allocated memory, or NULL for failure. | |
844 */ | |
845 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
846 get_expr_line(void) |
7 | 847 { |
848 char_u *expr_copy; | |
849 char_u *rv; | |
994 | 850 static int nested = 0; |
7 | 851 |
852 if (expr_line == NULL) | |
853 return NULL; | |
854 | |
855 /* Make a copy of the expression, because evaluating it may cause it to be | |
856 * changed. */ | |
857 expr_copy = vim_strsave(expr_line); | |
858 if (expr_copy == NULL) | |
859 return NULL; | |
860 | |
994 | 861 /* When we are invoked recursively limit the evaluation to 10 levels. |
862 * Then return the string as-is. */ | |
863 if (nested >= 10) | |
864 return expr_copy; | |
865 | |
866 ++nested; | |
714 | 867 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 868 --nested; |
7 | 869 vim_free(expr_copy); |
870 return rv; | |
871 } | |
283 | 872 |
873 /* | |
874 * Get the '=' register expression itself, without evaluating it. | |
875 */ | |
876 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
877 get_expr_line_src(void) |
283 | 878 { |
879 if (expr_line == NULL) | |
880 return NULL; | |
881 return vim_strsave(expr_line); | |
882 } | |
7 | 883 #endif /* FEAT_EVAL */ |
884 | |
885 /* | |
886 * Check if 'regname' is a valid name of a yank register. | |
887 * Note: There is no check for 0 (default register), caller should do this | |
888 */ | |
889 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
890 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
891 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
892 int writing) /* if TRUE check for writable registers */ |
7 | 893 { |
894 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
895 || (!writing && vim_strchr((char_u *) | |
896 #ifdef FEAT_EVAL | |
6557 | 897 "/.%:=" |
7 | 898 #else |
6557 | 899 "/.%:" |
7 | 900 #endif |
901 , regname) != NULL) | |
6557 | 902 || regname == '#' |
7 | 903 || regname == '"' |
904 || regname == '-' | |
905 || regname == '_' | |
906 #ifdef FEAT_CLIPBOARD | |
907 || regname == '*' | |
908 || regname == '+' | |
909 #endif | |
910 #ifdef FEAT_DND | |
911 || (!writing && regname == '~') | |
912 #endif | |
913 ) | |
914 return TRUE; | |
915 return FALSE; | |
916 } | |
917 | |
918 /* | |
919 * Set y_current and y_append, according to the value of "regname". | |
920 * Cannot handle the '_' register. | |
140 | 921 * Must only be called with a valid register name! |
7 | 922 * |
923 * If regname is 0 and writing, use register 0 | |
924 * 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
|
925 * |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
926 * 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
|
927 * clipboard). |
7 | 928 */ |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
929 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
930 get_yank_register(int regname, int writing) |
7 | 931 { |
932 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
|
933 int ret = FALSE; |
7 | 934 |
935 y_append = FALSE; | |
936 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
937 { | |
938 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
|
939 return ret; |
7 | 940 } |
941 i = regname; | |
942 if (VIM_ISDIGIT(i)) | |
943 i -= '0'; | |
944 else if (ASCII_ISLOWER(i)) | |
945 i = CharOrdLow(i) + 10; | |
946 else if (ASCII_ISUPPER(i)) | |
947 { | |
948 i = CharOrdUp(i) + 10; | |
949 y_append = TRUE; | |
950 } | |
951 else if (regname == '-') | |
952 i = DELETION_REGISTER; | |
953 #ifdef FEAT_CLIPBOARD | |
954 /* When selection is not available, use register 0 instead of '*' */ | |
955 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
|
956 { |
7 | 957 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
|
958 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
959 } |
7 | 960 /* When clipboard is not available, use register 0 instead of '+' */ |
961 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
|
962 { |
7 | 963 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
|
964 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
965 } |
7 | 966 #endif |
967 #ifdef FEAT_DND | |
968 else if (!writing && regname == '~') | |
969 i = TILDE_REGISTER; | |
970 #endif | |
971 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
972 i = 0; | |
973 y_current = &(y_regs[i]); | |
974 if (writing) /* remember the register we write into for do_put() */ | |
975 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
|
976 return ret; |
7 | 977 } |
978 | |
15 | 979 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 980 /* |
981 * When "regname" is a clipboard register, obtain the selection. If it's not | |
982 * available return zero, otherwise return "regname". | |
983 */ | |
15 | 984 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
985 may_get_selection(int regname) |
7 | 986 { |
987 if (regname == '*') | |
988 { | |
989 if (!clip_star.available) | |
990 regname = 0; | |
991 else | |
992 clip_get_selection(&clip_star); | |
993 } | |
994 else if (regname == '+') | |
995 { | |
996 if (!clip_plus.available) | |
997 regname = 0; | |
998 else | |
999 clip_get_selection(&clip_plus); | |
1000 } | |
1001 return regname; | |
1002 } | |
1003 #endif | |
1004 | |
1005 /* | |
1006 * Obtain the contents of a "normal" register. The register is made empty. | |
1007 * The returned pointer has allocated memory, use put_register() later. | |
1008 */ | |
1009 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1010 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1011 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1012 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 1013 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1014 yankreg_T *reg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1015 int i; |
7 | 1016 |
1017 #ifdef FEAT_CLIPBOARD | |
1018 /* When Visual area changed, may have to update selection. Obtain the | |
1019 * selection too. */ | |
1435 | 1020 if (name == '*' && clip_star.available) |
7 | 1021 { |
3674 | 1022 if (clip_isautosel_star()) |
1023 clip_update_selection(&clip_star); | |
1024 may_get_selection(name); | |
1025 } | |
1026 if (name == '+' && clip_plus.available) | |
1027 { | |
1028 if (clip_isautosel_plus()) | |
1029 clip_update_selection(&clip_plus); | |
7 | 1030 may_get_selection(name); |
1031 } | |
1032 #endif | |
1033 | |
1034 get_yank_register(name, 0); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1035 reg = (yankreg_T *)alloc((unsigned)sizeof(yankreg_T)); |
7 | 1036 if (reg != NULL) |
1037 { | |
1038 *reg = *y_current; | |
1039 if (copy) | |
1040 { | |
1041 /* If we run out of memory some or all of the lines are empty. */ | |
1042 if (reg->y_size == 0) | |
1043 reg->y_array = NULL; | |
1044 else | |
1045 reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) | |
1046 * reg->y_size)); | |
1047 if (reg->y_array != NULL) | |
1048 { | |
1049 for (i = 0; i < reg->y_size; ++i) | |
1050 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
1051 } | |
1052 } | |
1053 else | |
1054 y_current->y_array = NULL; | |
1055 } | |
1056 return (void *)reg; | |
1057 } | |
1058 | |
1059 /* | |
1451 | 1060 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1061 */ |
1062 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1063 put_register(int name, void *reg) |
7 | 1064 { |
1065 get_yank_register(name, 0); | |
1066 free_yank_all(); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1067 *y_current = *(yankreg_T *)reg; |
1451 | 1068 vim_free(reg); |
7 | 1069 |
5735 | 1070 #ifdef FEAT_CLIPBOARD |
7 | 1071 /* Send text written to clipboard register to the clipboard. */ |
1072 may_set_selection(); | |
5735 | 1073 #endif |
7 | 1074 } |
4209 | 1075 |
1076 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1077 free_register(void *reg) |
4209 | 1078 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1079 yankreg_T tmp; |
4209 | 1080 |
1081 tmp = *y_current; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1082 *y_current = *(yankreg_T *)reg; |
4209 | 1083 free_yank_all(); |
1084 vim_free(reg); | |
1085 *y_current = tmp; | |
1086 } | |
7 | 1087 |
1088 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1089 /* | |
1090 * return TRUE if the current yank register has type MLINE | |
1091 */ | |
1092 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1093 yank_register_mline(int regname) |
7 | 1094 { |
1095 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1096 return FALSE; | |
1097 if (regname == '_') /* black hole is always empty */ | |
1098 return FALSE; | |
1099 get_yank_register(regname, FALSE); | |
1100 return (y_current->y_type == MLINE); | |
1101 } | |
1102 #endif | |
1103 | |
1104 /* | |
1157 | 1105 * Start or stop recording into a yank register. |
7 | 1106 * |
1157 | 1107 * Return FAIL for failure, OK otherwise. |
7 | 1108 */ |
1109 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1110 do_record(int c) |
7 | 1111 { |
1157 | 1112 char_u *p; |
1113 static int regname; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1114 yankreg_T *old_y_previous, *old_y_current; |
1157 | 1115 int retval; |
7 | 1116 |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1117 if (reg_recording == 0) /* start recording */ |
7 | 1118 { |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1119 /* registers 0-9, a-z and " are allowed */ |
7 | 1120 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) |
1121 retval = FAIL; | |
1122 else | |
1123 { | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1124 reg_recording = c; |
7 | 1125 showmode(); |
1126 regname = c; | |
1127 retval = OK; | |
1128 } | |
1129 } | |
1130 else /* stop recording */ | |
1131 { | |
1132 /* | |
1157 | 1133 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1134 * needs to be removed again to put it in a register. exec_reg then | |
1135 * adds the escaping back later. | |
7 | 1136 */ |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1137 reg_recording = 0; |
7 | 1138 MSG(""); |
1139 p = get_recorded(); | |
1140 if (p == NULL) | |
1141 retval = FAIL; | |
1142 else | |
1143 { | |
1081 | 1144 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1145 vim_unescape_csi(p); | |
1146 | |
7 | 1147 /* |
1148 * We don't want to change the default register here, so save and | |
1149 * restore the current register name. | |
1150 */ | |
1151 old_y_previous = y_previous; | |
1152 old_y_current = y_current; | |
1153 | |
1154 retval = stuff_yank(regname, p); | |
1155 | |
1156 y_previous = old_y_previous; | |
1157 y_current = old_y_current; | |
1158 } | |
1159 } | |
1160 return retval; | |
1161 } | |
1162 | |
1163 /* | |
1164 * Stuff string "p" into yank register "regname" as a single line (append if | |
1165 * uppercase). "p" must have been alloced. | |
1166 * | |
1167 * return FAIL for failure, OK otherwise | |
1168 */ | |
1169 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1170 stuff_yank(int regname, char_u *p) |
7 | 1171 { |
1172 char_u *lp; | |
1173 char_u **pp; | |
1174 | |
1175 /* check for read-only register */ | |
1176 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1177 { | |
1178 vim_free(p); | |
1179 return FAIL; | |
1180 } | |
1181 if (regname == '_') /* black hole: don't do anything */ | |
1182 { | |
1183 vim_free(p); | |
1184 return OK; | |
1185 } | |
1186 get_yank_register(regname, TRUE); | |
1187 if (y_append && y_current->y_array != NULL) | |
1188 { | |
1189 pp = &(y_current->y_array[y_current->y_size - 1]); | |
1190 lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); | |
1191 if (lp == NULL) | |
1192 { | |
1193 vim_free(p); | |
1194 return FAIL; | |
1195 } | |
1196 STRCPY(lp, *pp); | |
1197 STRCAT(lp, p); | |
1198 vim_free(p); | |
1199 vim_free(*pp); | |
1200 *pp = lp; | |
1201 } | |
1202 else | |
1203 { | |
1204 free_yank_all(); | |
1205 if ((y_current->y_array = | |
1206 (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) | |
1207 { | |
1208 vim_free(p); | |
1209 return FAIL; | |
1210 } | |
1211 y_current->y_array[0] = p; | |
1212 y_current->y_size = 1; | |
1213 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
|
1214 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1215 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
|
1216 #endif |
7 | 1217 } |
1218 return OK; | |
1219 } | |
1220 | |
1893 | 1221 static int execreg_lastc = NUL; |
1222 | |
7 | 1223 /* |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1224 * Execute a yank register: copy it into the stuff buffer. |
7 | 1225 * |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1226 * Return FAIL for failure, OK otherwise. |
7 | 1227 */ |
1228 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1229 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1230 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1231 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1232 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
|
1233 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1234 { |
1235 long i; | |
1236 char_u *p; | |
1237 int retval = OK; | |
1238 int remap; | |
1239 | |
1240 if (regname == '@') /* repeat previous one */ | |
168 | 1241 { |
1893 | 1242 if (execreg_lastc == NUL) |
168 | 1243 { |
1244 EMSG(_("E748: No previously used register")); | |
1245 return FAIL; | |
1246 } | |
1893 | 1247 regname = execreg_lastc; |
168 | 1248 } |
7 | 1249 /* check for valid regname */ |
1250 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) | |
168 | 1251 { |
1252 emsg_invreg(regname); | |
7 | 1253 return FAIL; |
168 | 1254 } |
1893 | 1255 execreg_lastc = regname; |
7 | 1256 |
1257 #ifdef FEAT_CLIPBOARD | |
1258 regname = may_get_selection(regname); | |
1259 #endif | |
1260 | |
1261 if (regname == '_') /* black hole: don't stuff anything */ | |
1262 return OK; | |
1263 | |
1264 #ifdef FEAT_CMDHIST | |
1265 if (regname == ':') /* use last command line */ | |
1266 { | |
1267 if (last_cmdline == NULL) | |
1268 { | |
1269 EMSG(_(e_nolastcmd)); | |
1270 return FAIL; | |
1271 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1272 VIM_CLEAR(new_last_cmdline); /* don't keep the cmdline containing @: */ |
16 | 1273 /* Escape all control characters with a CTRL-V */ |
1274 p = vim_strsave_escaped_ext(last_cmdline, | |
20 | 1275 (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 | 1276 if (p != NULL) |
480 | 1277 { |
1278 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1279 * Remove it when it's already there. */ | |
1280 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1281 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1282 else |
1077 | 1283 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1284 } |
16 | 1285 vim_free(p); |
7 | 1286 } |
1287 #endif | |
1288 #ifdef FEAT_EVAL | |
1289 else if (regname == '=') | |
1290 { | |
1291 p = get_expr_line(); | |
1292 if (p == NULL) | |
1293 return FAIL; | |
1077 | 1294 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1295 vim_free(p); |
1296 } | |
1297 #endif | |
1298 else if (regname == '.') /* use last inserted text */ | |
1299 { | |
1300 p = get_last_insert_save(); | |
1301 if (p == NULL) | |
1302 { | |
1303 EMSG(_(e_noinstext)); | |
1304 return FAIL; | |
1305 } | |
1077 | 1306 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1307 vim_free(p); |
1308 } | |
1309 else | |
1310 { | |
1311 get_yank_register(regname, FALSE); | |
1312 if (y_current->y_array == NULL) | |
1313 return FAIL; | |
1314 | |
1315 /* Disallow remaping for ":@r". */ | |
1316 remap = colon ? REMAP_NONE : REMAP_YES; | |
1317 | |
1318 /* | |
1319 * Insert lines into typeahead buffer, from last one to first one. | |
1320 */ | |
1034 | 1321 put_reedit_in_typebuf(silent); |
7 | 1322 for (i = y_current->y_size; --i >= 0; ) |
1323 { | |
1077 | 1324 char_u *escaped; |
1325 | |
7 | 1326 /* insert NL between lines and after last line if type is MLINE */ |
1327 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1328 || addcr) | |
1329 { | |
1034 | 1330 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1331 return FAIL; |
1332 } | |
1077 | 1333 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1334 if (escaped == NULL) | |
1335 return FAIL; | |
1336 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1337 vim_free(escaped); | |
1338 if (retval == FAIL) | |
7 | 1339 return FAIL; |
1034 | 1340 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1341 == FAIL) |
1342 return FAIL; | |
1343 } | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1344 reg_executing = regname == 0 ? '"' : regname; // disable "q" command |
7 | 1345 } |
1346 return retval; | |
1347 } | |
1348 | |
1349 /* | |
1350 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1351 * used only after other typeahead has been processed. | |
1352 */ | |
1353 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1354 put_reedit_in_typebuf(int silent) |
7 | 1355 { |
1356 char_u buf[3]; | |
1357 | |
1358 if (restart_edit != NUL) | |
1359 { | |
1360 if (restart_edit == 'V') | |
1361 { | |
1362 buf[0] = 'g'; | |
1363 buf[1] = 'R'; | |
1364 buf[2] = NUL; | |
1365 } | |
1366 else | |
1367 { | |
1368 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1369 buf[1] = NUL; | |
1370 } | |
1034 | 1371 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1372 restart_edit = NUL; |
1373 } | |
1374 } | |
1375 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1376 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1377 * 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
|
1378 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1379 * 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
|
1380 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1381 */ |
7 | 1382 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1383 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1384 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1385 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1386 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1387 int silent) |
7 | 1388 { |
1389 int retval = OK; | |
1390 | |
1034 | 1391 put_reedit_in_typebuf(silent); |
7 | 1392 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1393 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1394 if (retval == OK) |
1077 | 1395 { |
1396 char_u *p; | |
1397 | |
1398 if (esc) | |
1399 p = vim_strsave_escape_csi(s); | |
1400 else | |
1401 p = s; | |
1402 if (p == NULL) | |
1403 retval = FAIL; | |
1404 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1405 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
|
1406 0, TRUE, silent); |
1077 | 1407 if (esc) |
1408 vim_free(p); | |
1409 } | |
7 | 1410 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1411 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1412 return retval; |
1413 } | |
1414 | |
1415 /* | |
1416 * Insert a yank register: copy it into the Read buffer. | |
1417 * Used by CTRL-R command and middle mouse button in insert mode. | |
1418 * | |
1419 * return FAIL for failure, OK otherwise | |
1420 */ | |
1421 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1422 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1423 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
|
1424 int literally_arg) /* insert literally, not as if typed */ |
7 | 1425 { |
1426 long i; | |
1427 int retval = OK; | |
1428 char_u *arg; | |
1429 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
|
1430 int literally = literally_arg; |
7 | 1431 |
1432 /* | |
1433 * It is possible to get into an endless loop by having CTRL-R a in | |
1434 * register a and then, in insert mode, doing CTRL-R a. | |
1435 * If you hit CTRL-C, the loop will be broken here. | |
1436 */ | |
1437 ui_breakcheck(); | |
1438 if (got_int) | |
1439 return FAIL; | |
1440 | |
1441 /* check for valid regname */ | |
1442 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1443 return FAIL; | |
1444 | |
1445 #ifdef FEAT_CLIPBOARD | |
1446 regname = may_get_selection(regname); | |
1447 #endif | |
1448 | |
1449 if (regname == '.') /* insert last inserted text */ | |
1450 retval = stuff_inserted(NUL, 1L, TRUE); | |
1451 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1452 { | |
1453 if (arg == NULL) | |
1454 return FAIL; | |
1455 stuffescaped(arg, literally); | |
1456 if (allocated) | |
1457 vim_free(arg); | |
1458 } | |
1459 else /* name or number register */ | |
1460 { | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1461 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
|
1462 literally = TRUE; |
7 | 1463 if (y_current->y_array == NULL) |
1464 retval = FAIL; | |
1465 else | |
1466 { | |
1467 for (i = 0; i < y_current->y_size; ++i) | |
1468 { | |
1469 stuffescaped(y_current->y_array[i], literally); | |
1470 /* | |
1471 * Insert a newline between lines and after last line if | |
1472 * y_type is MLINE. | |
1473 */ | |
1474 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1475 stuffcharReadbuff('\n'); | |
1476 } | |
1477 } | |
1478 } | |
1479 | |
1480 return retval; | |
1481 } | |
1482 | |
1483 /* | |
1484 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1485 * literally ("literally" TRUE) or interpret is as typed characters. | |
1486 */ | |
1487 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1488 stuffescaped(char_u *arg, int literally) |
7 | 1489 { |
1490 int c; | |
1491 char_u *start; | |
1492 | |
1493 while (*arg != NUL) | |
1494 { | |
1495 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1496 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1497 * is TRUE. */ | |
1498 start = arg; | |
1499 while ((*arg >= ' ' | |
1500 #ifndef EBCDIC | |
1501 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1502 #endif | |
1503 ) | |
1504 || (*arg == K_SPECIAL && !literally)) | |
1505 ++arg; | |
1506 if (arg > start) | |
1507 stuffReadbuffLen(start, (long)(arg - start)); | |
1508 | |
1509 /* stuff a single special character */ | |
1510 if (*arg != NUL) | |
1511 { | |
1512 #ifdef FEAT_MBYTE | |
1513 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
|
1514 c = mb_cptr2char_adv(&arg); |
7 | 1515 else |
1516 #endif | |
1517 c = *arg++; | |
1518 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1519 stuffcharReadbuff(Ctrl_V); | |
1520 stuffcharReadbuff(c); | |
1521 } | |
1522 } | |
1523 } | |
1524 | |
1525 /* | |
1157 | 1526 * If "regname" is a special register, return TRUE and store a pointer to its |
1527 * value in "argp". | |
7 | 1528 */ |
15 | 1529 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1530 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1531 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1532 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1533 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
|
1534 int errmsg) /* give error message when failing */ |
7 | 1535 { |
1536 int cnt; | |
1537 | |
1538 *argp = NULL; | |
1539 *allocated = FALSE; | |
1540 switch (regname) | |
1541 { | |
1542 case '%': /* file name */ | |
1543 if (errmsg) | |
1544 check_fname(); /* will give emsg if not set */ | |
1545 *argp = curbuf->b_fname; | |
1546 return TRUE; | |
1547 | |
1548 case '#': /* alternate file name */ | |
1549 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1550 return TRUE; | |
1551 | |
1552 #ifdef FEAT_EVAL | |
1553 case '=': /* result of expression */ | |
1554 *argp = get_expr_line(); | |
1555 *allocated = TRUE; | |
1556 return TRUE; | |
1557 #endif | |
1558 | |
1559 case ':': /* last command line */ | |
1560 if (last_cmdline == NULL && errmsg) | |
1561 EMSG(_(e_nolastcmd)); | |
1562 *argp = last_cmdline; | |
1563 return TRUE; | |
1564 | |
1565 case '/': /* last search-pattern */ | |
1566 if (last_search_pat() == NULL && errmsg) | |
1567 EMSG(_(e_noprevre)); | |
1568 *argp = last_search_pat(); | |
1569 return TRUE; | |
1570 | |
1571 case '.': /* last inserted text */ | |
1572 *argp = get_last_insert_save(); | |
1573 *allocated = TRUE; | |
1574 if (*argp == NULL && errmsg) | |
1575 EMSG(_(e_noinstext)); | |
1576 return TRUE; | |
1577 | |
1578 #ifdef FEAT_SEARCHPATH | |
1579 case Ctrl_F: /* Filename under cursor */ | |
1580 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1581 if (!errmsg) | |
1582 return FALSE; | |
1583 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1584 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1585 *allocated = TRUE; |
1586 return TRUE; | |
1587 #endif | |
1588 | |
1589 case Ctrl_W: /* word under cursor */ | |
1590 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1591 if (!errmsg) | |
1592 return FALSE; | |
1593 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1594 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1595 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1596 *allocated = TRUE; | |
1597 return TRUE; | |
1598 | |
13831
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1599 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
|
1600 if (!errmsg) |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1601 return FALSE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1602 |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1603 *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
|
1604 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
|
1605 return TRUE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1606 |
7 | 1607 case '_': /* black hole: always empty */ |
1608 *argp = (char_u *)""; | |
1609 return TRUE; | |
1610 } | |
1611 | |
1612 return FALSE; | |
1613 } | |
1614 | |
1615 /* | |
15 | 1616 * Paste a yank register into the command line. |
1617 * Only for non-special registers. | |
1618 * Used by CTRL-R command in command-line mode | |
7 | 1619 * insert_reg() can't be used here, because special characters from the |
1620 * register contents will be interpreted as commands. | |
1621 * | |
1622 * return FAIL for failure, OK otherwise | |
1623 */ | |
1624 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1625 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1626 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
|
1627 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
|
1628 int remcr) /* don't add CR characters */ |
7 | 1629 { |
1630 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
|
1631 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
|
1632 |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1633 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
|
1634 literally = TRUE; |
7 | 1635 if (y_current->y_array == NULL) |
1636 return FAIL; | |
1637 | |
1638 for (i = 0; i < y_current->y_size; ++i) | |
1639 { | |
1640 cmdline_paste_str(y_current->y_array[i], literally); | |
1641 | |
1015 | 1642 /* 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
|
1643 * 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
|
1644 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1645 cmdline_paste_str((char_u *)"\r", literally); |
1646 | |
1647 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1648 * lines and gets bored. */ | |
1649 ui_breakcheck(); | |
1650 if (got_int) | |
1651 return FAIL; | |
1652 } | |
1653 return OK; | |
1654 } | |
1655 | |
1656 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1657 /* | |
1658 * Adjust the register name pointed to with "rp" for the clipboard being | |
1659 * used always and the clipboard being available. | |
1660 */ | |
1661 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1662 adjust_clip_reg(int *rp) |
7 | 1663 { |
2654 | 1664 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1665 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1666 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1667 { | |
1668 if (clip_unnamed != 0) | |
1669 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1670 ? '+' : '*'; |
6116 | 1671 else |
1672 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1673 ? '+' : '*'; | |
1674 } | |
7 | 1675 if (!clip_star.available && *rp == '*') |
1676 *rp = 0; | |
1677 if (!clip_plus.available && *rp == '+') | |
1678 *rp = 0; | |
1679 } | |
1680 #endif | |
1681 | |
1682 /* | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1683 * 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
|
1684 */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1685 void |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1686 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
|
1687 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1688 int n; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1689 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1690 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
|
1691 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
|
1692 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
|
1693 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
|
1694 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
|
1695 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
|
1696 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
|
1697 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
|
1698 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1699 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1700 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1701 static void |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1702 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
|
1703 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1704 static int recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1705 dict_T *v_event; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1706 list_T *list; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1707 int n; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1708 char_u buf[NUMBUFLEN + 2]; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1709 long reglen = 0; |
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 if (recursive) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1712 return; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1713 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1714 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
|
1715 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1716 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
|
1717 if (list == NULL) |
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1718 return; |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1719 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
|
1720 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
|
1721 list->lv_lock = VAR_FIXED; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1722 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
|
1723 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1724 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
|
1725 buf[1] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1726 dict_add_nr_str(v_event, "regname", 0, buf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1727 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1728 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
|
1729 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
|
1730 buf[2] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1731 dict_add_nr_str(v_event, "operator", 0, buf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1732 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1733 buf[0] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1734 buf[1] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1735 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
|
1736 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1737 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
|
1738 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
|
1739 case MBLOCK: |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1740 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
|
1741 reglen + 1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1742 break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1743 } |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1744 dict_add_nr_str(v_event, "regtype", 0, buf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1745 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1746 /* 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
|
1747 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
|
1748 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1749 recursive = TRUE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1750 textlock++; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1751 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
|
1752 textlock--; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1753 recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1754 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1755 /* 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
|
1756 dict_free_contents(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1757 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
|
1758 } |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
1759 #endif |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1760 |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1761 /* |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1762 * Handle a delete operation. |
7 | 1763 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1764 * Return FAIL if undo failed, OK otherwise. |
7 | 1765 */ |
1766 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1767 op_delete(oparg_T *oap) |
7 | 1768 { |
1769 int n; | |
1770 linenr_T lnum; | |
1771 char_u *ptr; | |
1772 char_u *newp, *oldp; | |
1773 struct block_def bd; | |
1774 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1775 int did_yank = FALSE; | |
3782 | 1776 int orig_regname = oap->regname; |
7 | 1777 |
1778 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1779 return OK; | |
1780 | |
1781 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1782 if (oap->empty) | |
1783 return u_save_cursor(); | |
1784 | |
1785 if (!curbuf->b_p_ma) | |
1786 { | |
1787 EMSG(_(e_modifiable)); | |
1788 return FAIL; | |
1789 } | |
1790 | |
1791 #ifdef FEAT_CLIPBOARD | |
1792 adjust_clip_reg(&oap->regname); | |
1793 #endif | |
1794 | |
1795 #ifdef FEAT_MBYTE | |
1796 if (has_mbyte) | |
1797 mb_adjust_opend(oap); | |
1798 #endif | |
1799 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1800 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1801 * 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
|
1802 * 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
|
1803 * 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
|
1804 */ |
7 | 1805 if ( oap->motion_type == MCHAR |
1806 && !oap->is_VIsual | |
50 | 1807 && !oap->block_mode |
7 | 1808 && oap->line_count > 1 |
3254 | 1809 && oap->motion_force == NUL |
7 | 1810 && oap->op_type == OP_DELETE) |
1811 { | |
2957 | 1812 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1813 if (*ptr != NUL) | |
1814 ptr += oap->inclusive; | |
7 | 1815 ptr = skipwhite(ptr); |
1816 if (*ptr == NUL && inindent(0)) | |
1817 oap->motion_type = MLINE; | |
1818 } | |
1819 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1820 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1821 * 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
|
1822 * 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
|
1823 */ |
7 | 1824 if ( oap->motion_type == MCHAR |
1825 && oap->line_count == 1 | |
1826 && oap->op_type == OP_DELETE | |
1827 && *ml_get(oap->start.lnum) == NUL) | |
1828 { | |
1829 /* | |
446 | 1830 * It's an error to operate on an empty region, when 'E' included in |
7 | 1831 * 'cpoptions' (Vi compatible). |
1832 */ | |
446 | 1833 #ifdef FEAT_VIRTUALEDIT |
1834 if (virtual_op) | |
1835 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1836 * marks as if it happened. */ | |
1837 goto setmarks; | |
1838 #endif | |
7 | 1839 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1840 beep_flush(); | |
1841 return OK; | |
1842 } | |
1843 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1844 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1845 * 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
|
1846 * 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
|
1847 * 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
|
1848 */ |
7 | 1849 if (oap->regname != '_') |
1850 { | |
1851 if (oap->regname != 0) | |
1852 { | |
1853 /* check for read-only register */ | |
1854 if (!valid_yank_reg(oap->regname, TRUE)) | |
1855 { | |
1856 beep_flush(); | |
1857 return OK; | |
1858 } | |
1859 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1860 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1861 did_yank = TRUE; | |
1862 } | |
1863 | |
1864 /* | |
1865 * Put deleted text into register 1 and shift number registers if the | |
1866 * delete contains a line break, or when a regname has been specified. | |
3782 | 1867 * Use the register name from before adjust_clip_reg() may have |
1868 * changed it. | |
7 | 1869 */ |
3782 | 1870 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1871 || oap->line_count > 1 || oap->use_reg_one) |
1872 { | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1873 shift_delete_registers(); |
7 | 1874 if (op_yank(oap, TRUE, FALSE) == OK) |
1875 did_yank = TRUE; | |
1876 } | |
1877 | |
3468 | 1878 /* Yank into small delete register when no named register specified |
1879 * and the delete is within one line. */ | |
1880 if (( | |
1881 #ifdef FEAT_CLIPBOARD | |
3584 | 1882 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1883 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1884 #endif |
1885 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1886 && oap->line_count == 1) |
1887 { | |
1888 oap->regname = '-'; | |
1889 get_yank_register(oap->regname, TRUE); | |
1890 if (op_yank(oap, TRUE, FALSE) == OK) | |
1891 did_yank = TRUE; | |
1892 oap->regname = 0; | |
1893 } | |
1894 | |
1895 /* | |
1896 * If there's too much stuff to fit in the yank register, then get a | |
1897 * confirmation before doing the delete. This is crude, but simple. | |
1898 * And it avoids doing a delete of something we can't put back if we | |
1899 * want. | |
1900 */ | |
1901 if (!did_yank) | |
1902 { | |
1903 int msg_silent_save = msg_silent; | |
1904 | |
1905 msg_silent = 0; /* must display the prompt */ | |
1906 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1907 msg_silent = msg_silent_save; | |
1908 if (n != 'y') | |
1909 { | |
1910 EMSG(_(e_abort)); | |
1911 return FAIL; | |
1912 } | |
1913 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1914 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1915 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1916 if (did_yank && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1917 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
|
1918 #endif |
7 | 1919 } |
1920 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1921 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1922 * 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
|
1923 */ |
7 | 1924 if (oap->block_mode) |
1925 { | |
1926 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1927 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1928 return FAIL; | |
1929 | |
1930 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1931 { | |
1932 block_prep(oap, &bd, lnum, TRUE); | |
1933 if (bd.textlen == 0) /* nothing to delete */ | |
1934 continue; | |
1935 | |
1936 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1937 if (lnum == curwin->w_cursor.lnum) | |
1938 { | |
1939 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1940 # ifdef FEAT_VIRTUALEDIT | |
1941 curwin->w_cursor.coladd = 0; | |
1942 # endif | |
1943 } | |
1944 | |
1945 /* n == number of chars deleted | |
1946 * If we delete a TAB, it may be replaced by several characters. | |
1947 * Thus the number of characters may increase! | |
1948 */ | |
1949 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1950 oldp = ml_get(lnum); | |
1951 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1952 if (newp == NULL) | |
1953 continue; | |
1954 /* copy up to deleted part */ | |
1955 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1956 /* insert spaces */ | |
6929 | 1957 vim_memset(newp + bd.textcol, ' ', |
7 | 1958 (size_t)(bd.startspaces + bd.endspaces)); |
1959 /* copy the part after the deleted part */ | |
1960 oldp += bd.textcol + bd.textlen; | |
1622 | 1961 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1962 /* replace the line */ |
1963 ml_replace(lnum, newp, FALSE); | |
1964 } | |
1965 | |
1966 check_cursor_col(); | |
1967 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1968 oap->end.lnum + 1, 0L); | |
1969 oap->line_count = 0; /* no lines deleted */ | |
1970 } | |
5735 | 1971 else if (oap->motion_type == MLINE) |
7 | 1972 { |
1973 if (oap->op_type == OP_CHANGE) | |
1974 { | |
1975 /* Delete the lines except the first one. Temporarily move the | |
1976 * cursor to the next line. Save the current line number, if the | |
1977 * last line is deleted it may be changed. | |
1978 */ | |
1979 if (oap->line_count > 1) | |
1980 { | |
1981 lnum = curwin->w_cursor.lnum; | |
1982 ++curwin->w_cursor.lnum; | |
1983 del_lines((long)(oap->line_count - 1), TRUE); | |
1984 curwin->w_cursor.lnum = lnum; | |
1985 } | |
1986 if (u_save_cursor() == FAIL) | |
1987 return FAIL; | |
1988 if (curbuf->b_p_ai) /* don't delete indent */ | |
1989 { | |
1990 beginline(BL_WHITE); /* cursor on first non-white */ | |
1991 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1992 ai_col = curwin->w_cursor.col; | |
1993 } | |
1994 else | |
1995 beginline(0); /* cursor in column 0 */ | |
1996 truncate_line(FALSE); /* delete the rest of the line */ | |
1997 /* leave cursor past last char in line */ | |
1998 if (oap->line_count > 1) | |
1999 u_clearline(); /* "U" command not possible after "2cc" */ | |
2000 } | |
2001 else | |
2002 { | |
2003 del_lines(oap->line_count, TRUE); | |
2004 beginline(BL_WHITE | BL_FIX); | |
2005 u_clearline(); /* "U" command not possible after "dd" */ | |
2006 } | |
2007 } | |
2008 else | |
2009 { | |
2010 #ifdef FEAT_VIRTUALEDIT | |
2011 if (virtual_op) | |
2012 { | |
2013 int endcol = 0; | |
2014 | |
2015 /* For virtualedit: break the tabs that are partly included. */ | |
2016 if (gchar_pos(&oap->start) == '\t') | |
2017 { | |
2018 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
2019 return FAIL; | |
2020 if (oap->line_count == 1) | |
2021 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
2022 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
2023 oap->start = curwin->w_cursor; | |
2024 if (oap->line_count == 1) | |
2025 { | |
2026 coladvance(endcol); | |
2027 oap->end.col = curwin->w_cursor.col; | |
2028 oap->end.coladd = curwin->w_cursor.coladd; | |
2029 curwin->w_cursor = oap->start; | |
2030 } | |
2031 } | |
2032 | |
2033 /* Break a tab only when it's included in the area. */ | |
2034 if (gchar_pos(&oap->end) == '\t' | |
2035 && (int)oap->end.coladd < oap->inclusive) | |
2036 { | |
2037 /* save last line for undo */ | |
2038 if (u_save((linenr_T)(oap->end.lnum - 1), | |
2039 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2040 return FAIL; | |
2041 curwin->w_cursor = oap->end; | |
2042 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
2043 oap->end = curwin->w_cursor; | |
2044 curwin->w_cursor = oap->start; | |
2045 } | |
2046 } | |
2047 #endif | |
2048 | |
2049 if (oap->line_count == 1) /* delete characters within one line */ | |
2050 { | |
2051 if (u_save_cursor() == FAIL) /* save line for undo */ | |
2052 return FAIL; | |
2053 | |
2054 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 2055 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 2056 && oap->op_type == OP_CHANGE |
2057 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 2058 && !oap->is_VIsual) |
7 | 2059 display_dollar(oap->end.col - !oap->inclusive); |
2060 | |
2061 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
2062 | |
2063 #ifdef FEAT_VIRTUALEDIT | |
2064 if (virtual_op) | |
2065 { | |
2066 /* fix up things for virtualedit-delete: | |
2067 * break the tabs which are going to get in our way | |
2068 */ | |
2069 char_u *curline = ml_get_curline(); | |
2070 int len = (int)STRLEN(curline); | |
2071 | |
2072 if (oap->end.coladd != 0 | |
2073 && (int)oap->end.col >= len - 1 | |
2074 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
2075 n++; | |
2076 /* Delete at least one char (e.g, when on a control char). */ | |
2077 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
2078 n = 1; | |
2079 | |
2080 /* When deleted a char in the line, reset coladd. */ | |
2081 if (gchar_cursor() != NUL) | |
2082 curwin->w_cursor.coladd = 0; | |
2083 } | |
2084 #endif | |
6826 | 2085 (void)del_bytes((long)n, !virtual_op, |
2086 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 2087 } |
2088 else /* delete characters between lines */ | |
2089 { | |
2090 pos_T curpos; | |
2091 | |
2092 /* save deleted and changed lines for undo */ | |
2093 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
2094 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
2095 return FAIL; | |
2096 | |
2097 truncate_line(TRUE); /* delete from cursor to end of line */ | |
2098 | |
2099 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
2100 ++curwin->w_cursor.lnum; | |
2101 del_lines((long)(oap->line_count - 2), FALSE); | |
2102 | |
6826 | 2103 /* delete from start of line until op_end */ |
2957 | 2104 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 2105 curwin->w_cursor.col = 0; |
2106 (void)del_bytes((long)n, !virtual_op, | |
2107 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
2108 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
2109 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 2110 } |
2111 } | |
2112 | |
2113 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
2114 | |
446 | 2115 #ifdef FEAT_VIRTUALEDIT |
2116 setmarks: | |
2117 #endif | |
7 | 2118 if (oap->block_mode) |
2119 { | |
2120 curbuf->b_op_end.lnum = oap->end.lnum; | |
2121 curbuf->b_op_end.col = oap->start.col; | |
2122 } | |
2123 else | |
2124 curbuf->b_op_end = oap->start; | |
2125 curbuf->b_op_start = oap->start; | |
2126 | |
2127 return OK; | |
2128 } | |
2129 | |
2130 #ifdef FEAT_MBYTE | |
2131 /* | |
2132 * Adjust end of operating area for ending on a multi-byte character. | |
2133 * Used for deletion. | |
2134 */ | |
2135 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2136 mb_adjust_opend(oparg_T *oap) |
7 | 2137 { |
2138 char_u *p; | |
2139 | |
2140 if (oap->inclusive) | |
2141 { | |
2142 p = ml_get(oap->end.lnum); | |
2143 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2144 } | |
2145 } | |
2146 #endif | |
2147 | |
2148 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2149 /* | |
2150 * Replace a whole area with one character. | |
2151 */ | |
2152 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2153 op_replace(oparg_T *oap, int c) |
7 | 2154 { |
2155 int n, numc; | |
2156 #ifdef FEAT_MBYTE | |
2157 int num_chars; | |
2158 #endif | |
2159 char_u *newp, *oldp; | |
2160 size_t oldlen; | |
2161 struct block_def bd; | |
5428 | 2162 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
|
2163 int had_ctrl_v_cr = FALSE; |
7 | 2164 |
2165 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2166 return OK; /* nothing to do */ | |
2167 | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2168 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
|
2169 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2170 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
|
2171 c = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2172 } |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2173 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
|
2174 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2175 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
|
2176 c = NL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2177 } |
5428 | 2178 |
7 | 2179 #ifdef FEAT_MBYTE |
2180 if (has_mbyte) | |
2181 mb_adjust_opend(oap); | |
2182 #endif | |
2183 | |
2184 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2185 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2186 return FAIL; | |
2187 | |
2188 /* | |
2189 * block mode replace | |
2190 */ | |
2191 if (oap->block_mode) | |
2192 { | |
2193 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2194 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2195 { | |
1982 | 2196 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2197 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2198 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2199 continue; /* nothing to replace */ | |
2200 | |
2201 /* n == number of extra chars required | |
2202 * If we split a TAB, it may be replaced by several characters. | |
2203 * Thus the number of characters may increase! | |
2204 */ | |
2205 #ifdef FEAT_VIRTUALEDIT | |
2206 /* If the range starts in virtual space, count the initial | |
2207 * coladd offset as part of "startspaces" */ | |
2208 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2209 { | |
2210 pos_T vpos; | |
2211 | |
1982 | 2212 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2213 getvpos(&vpos, oap->start_vcol); |
2214 bd.startspaces += vpos.coladd; | |
2215 n = bd.startspaces; | |
2216 } | |
2217 else | |
2218 #endif | |
2219 /* allow for pre spaces */ | |
2220 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2221 | |
2222 /* allow for post spp */ | |
2223 n += (bd.endspaces | |
2224 #ifdef FEAT_VIRTUALEDIT | |
2225 && !bd.is_oneChar | |
2226 #endif | |
2227 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2228 /* Figure out how many characters to replace. */ | |
2229 numc = oap->end_vcol - oap->start_vcol + 1; | |
2230 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2231 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2232 | |
2233 #ifdef FEAT_MBYTE | |
2234 /* A double-wide character can be replaced only up to half the | |
2235 * times. */ | |
2236 if ((*mb_char2cells)(c) > 1) | |
2237 { | |
2238 if ((numc & 1) && !bd.is_short) | |
2239 { | |
2240 ++bd.endspaces; | |
2241 ++n; | |
2242 } | |
2243 numc = numc / 2; | |
2244 } | |
2245 | |
2246 /* Compute bytes needed, move character count to num_chars. */ | |
2247 num_chars = numc; | |
2248 numc *= (*mb_char2len)(c); | |
2249 #endif | |
2250 /* oldlen includes textlen, so don't double count */ | |
2251 n += numc - bd.textlen; | |
2252 | |
2253 oldp = ml_get_curline(); | |
2254 oldlen = STRLEN(oldp); | |
2255 newp = alloc_check((unsigned)oldlen + 1 + n); | |
2256 if (newp == NULL) | |
2257 continue; | |
2258 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2259 /* copy up to deleted part */ | |
2260 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2261 oldp += bd.textcol + bd.textlen; | |
2262 /* insert pre-spaces */ | |
6929 | 2263 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2264 /* 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
|
2265 /* 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
|
2266 * literally. */ |
5428 | 2267 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
7 | 2268 { |
5428 | 2269 #ifdef FEAT_MBYTE |
2270 if (has_mbyte) | |
2271 { | |
2272 n = (int)STRLEN(newp); | |
2273 while (--num_chars >= 0) | |
2274 n += (*mb_char2bytes)(c, newp + n); | |
2275 } | |
2276 else | |
2277 #endif | |
6929 | 2278 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2279 if (!bd.is_short) |
2280 { | |
2281 /* insert post-spaces */ | |
6929 | 2282 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2283 /* copy the part after the changed part */ |
2284 STRMOVE(newp + STRLEN(newp), oldp); | |
2285 } | |
7 | 2286 } |
2287 else | |
2288 { | |
5428 | 2289 /* Replacing with \r or \n means splitting the line. */ |
5475 | 2290 after_p = alloc_check( |
2291 (unsigned)(oldlen + 1 + n - STRLEN(newp))); | |
5428 | 2292 if (after_p != NULL) |
2293 STRMOVE(after_p, oldp); | |
7 | 2294 } |
2295 /* replace the line */ | |
2296 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2297 if (after_p != NULL) |
2298 { | |
2299 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2300 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2301 oap->end.lnum++; | |
2302 vim_free(after_p); | |
2303 } | |
7 | 2304 } |
2305 } | |
2306 else | |
2307 { | |
2308 /* | |
2309 * MCHAR and MLINE motion replace. | |
2310 */ | |
2311 if (oap->motion_type == MLINE) | |
2312 { | |
2313 oap->start.col = 0; | |
2314 curwin->w_cursor.col = 0; | |
2315 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2316 if (oap->end.col) | |
2317 --oap->end.col; | |
2318 } | |
2319 else if (!oap->inclusive) | |
2320 dec(&(oap->end)); | |
2321 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2322 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 2323 { |
2324 n = gchar_cursor(); | |
2325 if (n != NUL) | |
2326 { | |
2327 #ifdef FEAT_MBYTE | |
2328 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2329 { | |
2330 /* This is slow, but it handles replacing a single-byte | |
2331 * with a multi-byte and the other way around. */ | |
4203 | 2332 if (curwin->w_cursor.lnum == oap->end.lnum) |
2333 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | |
7 | 2334 n = State; |
2335 State = REPLACE; | |
2336 ins_char(c); | |
2337 State = n; | |
2338 /* Backup to the replaced character. */ | |
2339 dec_cursor(); | |
2340 } | |
2341 else | |
2342 #endif | |
2343 { | |
2344 #ifdef FEAT_VIRTUALEDIT | |
2345 if (n == TAB) | |
2346 { | |
2347 int end_vcol = 0; | |
2348 | |
2349 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2350 { | |
2351 /* oap->end has to be recalculated when | |
2352 * the tab breaks */ | |
2353 end_vcol = getviscol2(oap->end.col, | |
2354 oap->end.coladd); | |
2355 } | |
2356 coladvance_force(getviscol()); | |
2357 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2358 getvpos(&oap->end, end_vcol); | |
2359 } | |
2360 #endif | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2361 PCHAR(curwin->w_cursor, c); |
7 | 2362 } |
2363 } | |
2364 #ifdef FEAT_VIRTUALEDIT | |
2365 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2366 { | |
2367 int virtcols = oap->end.coladd; | |
2368 | |
2369 if (curwin->w_cursor.lnum == oap->start.lnum | |
2370 && oap->start.col == oap->end.col && oap->start.coladd) | |
2371 virtcols -= oap->start.coladd; | |
2372 | |
2373 /* oap->end has been trimmed so it's effectively inclusive; | |
2374 * as a result an extra +1 must be counted so we don't | |
2375 * trample the NUL byte. */ | |
2376 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2377 curwin->w_cursor.col -= (virtcols + 1); | |
2378 for (; virtcols >= 0; virtcols--) | |
2379 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2380 PCHAR(curwin->w_cursor, c); |
7 | 2381 if (inc(&curwin->w_cursor) == -1) |
2382 break; | |
2383 } | |
2384 } | |
2385 #endif | |
2386 | |
2387 /* Advance to next character, stop at the end of the file. */ | |
2388 if (inc_cursor() == -1) | |
2389 break; | |
2390 } | |
2391 } | |
2392 | |
2393 curwin->w_cursor = oap->start; | |
2394 check_cursor(); | |
2395 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2396 | |
2397 /* Set "'[" and "']" marks. */ | |
2398 curbuf->b_op_start = oap->start; | |
2399 curbuf->b_op_end = oap->end; | |
2400 | |
2401 return OK; | |
2402 } | |
2403 #endif | |
2404 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2405 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2406 |
7 | 2407 /* |
2408 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2409 */ | |
2410 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2411 op_tilde(oparg_T *oap) |
7 | 2412 { |
2413 pos_T pos; | |
2414 struct block_def bd; | |
1528 | 2415 int did_change = FALSE; |
7 | 2416 |
2417 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2418 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2419 return; | |
2420 | |
2421 pos = oap->start; | |
2422 if (oap->block_mode) /* Visual block mode */ | |
2423 { | |
2424 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2425 { | |
1766 | 2426 int one_change; |
2427 | |
7 | 2428 block_prep(oap, &bd, pos.lnum, FALSE); |
2429 pos.col = bd.textcol; | |
1766 | 2430 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2431 did_change |= one_change; | |
1525 | 2432 |
5735 | 2433 #ifdef FEAT_NETBEANS_INTG |
2210 | 2434 if (netbeans_active() && one_change) |
7 | 2435 { |
2436 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2437 | |
33 | 2438 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2439 (long)bd.textlen); | |
7 | 2440 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2441 &ptr[bd.textcol], bd.textlen); |
7 | 2442 } |
5735 | 2443 #endif |
7 | 2444 } |
2445 if (did_change) | |
2446 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2447 } | |
2448 else /* not block mode */ | |
2449 { | |
2450 if (oap->motion_type == MLINE) | |
2451 { | |
2452 oap->start.col = 0; | |
2453 pos.col = 0; | |
2454 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2455 if (oap->end.col) | |
2456 --oap->end.col; | |
2457 } | |
2458 else if (!oap->inclusive) | |
2459 dec(&(oap->end)); | |
2460 | |
1528 | 2461 if (pos.lnum == oap->end.lnum) |
2462 did_change = swapchars(oap->op_type, &pos, | |
2463 oap->end.col - pos.col + 1); | |
2464 else | |
2465 for (;;) | |
2466 { | |
2467 did_change |= swapchars(oap->op_type, &pos, | |
2468 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2469 (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
|
2470 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 2471 break; |
2472 } | |
7 | 2473 if (did_change) |
2474 { | |
2475 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2476 0L); | |
2477 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2478 if (netbeans_active() && did_change) |
7 | 2479 { |
2480 char_u *ptr; | |
2481 int count; | |
2482 | |
2483 pos = oap->start; | |
2484 while (pos.lnum < oap->end.lnum) | |
2485 { | |
2486 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2487 count = (int)STRLEN(ptr) - pos.col; |
33 | 2488 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2489 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2490 &ptr[pos.col], count); |
7 | 2491 pos.col = 0; |
2492 pos.lnum++; | |
2493 } | |
2494 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2495 count = oap->end.col - pos.col + 1; | |
33 | 2496 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2497 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2498 &ptr[pos.col], count); |
7 | 2499 } |
2500 #endif | |
2501 } | |
2502 } | |
2503 | |
2504 if (!did_change && oap->is_VIsual) | |
2505 /* No change: need to remove the Visual selection */ | |
2506 redraw_curbuf_later(INVERTED); | |
2507 | |
2508 /* | |
2509 * Set '[ and '] marks. | |
2510 */ | |
2511 curbuf->b_op_start = oap->start; | |
2512 curbuf->b_op_end = oap->end; | |
2513 | |
2514 if (oap->line_count > p_report) | |
2515 { | |
2516 if (oap->line_count == 1) | |
2517 MSG(_("1 line changed")); | |
2518 else | |
2519 smsg((char_u *)_("%ld lines changed"), oap->line_count); | |
2520 } | |
2521 } | |
2522 | |
2523 /* | |
1525 | 2524 * Invoke swapchar() on "length" bytes at position "pos". |
2525 * "pos" is advanced to just after the changed characters. | |
2526 * "length" is rounded up to include the whole last multi-byte character. | |
2527 * Also works correctly when the number of bytes changes. | |
2528 * Returns TRUE if some character was changed. | |
2529 */ | |
2530 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2531 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2532 { |
2533 int todo; | |
2534 int did_change = 0; | |
2535 | |
2536 for (todo = length; todo > 0; --todo) | |
2537 { | |
2538 # ifdef FEAT_MBYTE | |
2539 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2540 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2541 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2542 |
1525 | 2543 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2544 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2545 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2546 } |
1525 | 2547 # endif |
2548 did_change |= swapchar(op_type, pos); | |
2549 if (inc(pos) == -1) /* at end of file */ | |
2550 break; | |
2551 } | |
2552 return did_change; | |
2553 } | |
2554 | |
2555 /* | |
7 | 2556 * If op_type == OP_UPPER: make uppercase, |
2557 * if op_type == OP_LOWER: make lowercase, | |
2558 * if op_type == OP_ROT13: do rot13 encoding, | |
2559 * else swap case of character at 'pos' | |
2560 * returns TRUE when something actually changed. | |
2561 */ | |
2562 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2563 swapchar(int op_type, pos_T *pos) |
7 | 2564 { |
2565 int c; | |
2566 int nc; | |
2567 | |
2568 c = gchar_pos(pos); | |
2569 | |
2570 /* Only do rot13 encoding for ASCII characters. */ | |
2571 if (c >= 0x80 && op_type == OP_ROT13) | |
2572 return FALSE; | |
2573 | |
2574 #ifdef FEAT_MBYTE | |
1525 | 2575 if (op_type == OP_UPPER && c == 0xdf |
2576 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2577 { |
2578 pos_T sp = curwin->w_cursor; | |
2579 | |
2580 /* Special handling of German sharp s: change to "SS". */ | |
2581 curwin->w_cursor = *pos; | |
2582 del_char(FALSE); | |
2583 ins_char('S'); | |
2584 ins_char('S'); | |
2585 curwin->w_cursor = sp; | |
2586 inc(pos); | |
2587 } | |
2588 | |
7 | 2589 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2590 return FALSE; | |
2591 #endif | |
2592 nc = c; | |
2593 if (MB_ISLOWER(c)) | |
2594 { | |
2595 if (op_type == OP_ROT13) | |
2596 nc = ROT13(c, 'a'); | |
2597 else if (op_type != OP_LOWER) | |
2598 nc = MB_TOUPPER(c); | |
2599 } | |
2600 else if (MB_ISUPPER(c)) | |
2601 { | |
2602 if (op_type == OP_ROT13) | |
2603 nc = ROT13(c, 'A'); | |
2604 else if (op_type != OP_UPPER) | |
2605 nc = MB_TOLOWER(c); | |
2606 } | |
2607 if (nc != c) | |
2608 { | |
2609 #ifdef FEAT_MBYTE | |
2610 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2611 { | |
2612 pos_T sp = curwin->w_cursor; | |
2613 | |
2614 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2615 /* 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
|
2616 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2617 ins_char(nc); |
2618 curwin->w_cursor = sp; | |
2619 } | |
2620 else | |
2621 #endif | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2622 PCHAR(*pos, nc); |
7 | 2623 return TRUE; |
2624 } | |
2625 return FALSE; | |
2626 } | |
2627 | |
2628 #if defined(FEAT_VISUALEXTRA) || defined(PROTO) | |
2629 /* | |
2630 * op_insert - Insert and append operators for Visual mode. | |
2631 */ | |
2632 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2633 op_insert(oparg_T *oap, long count1) |
7 | 2634 { |
2635 long ins_len, pre_textlen = 0; | |
2636 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
2637 colnr_T ind_pre = 0, ind_post; |
7 | 2638 struct block_def bd; |
2639 int i; | |
6579 | 2640 pos_T t1; |
7 | 2641 |
2642 /* edit() changes this - record it for OP_APPEND */ | |
2643 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2644 | |
2645 /* vis block is still marked. Get rid of it now. */ | |
2646 curwin->w_cursor.lnum = oap->start.lnum; | |
2647 update_screen(INVERTED); | |
2648 | |
2649 if (oap->block_mode) | |
2650 { | |
2651 #ifdef FEAT_VIRTUALEDIT | |
2652 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2653 * doing block_prep(). When only "block" is used, virtual edit is | |
2654 * already disabled, but still need it when calling | |
2655 * coladvance_force(). */ | |
2656 if (curwin->w_cursor.coladd > 0) | |
2657 { | |
2658 int old_ve_flags = ve_flags; | |
2659 | |
2660 ve_flags = VE_ALL; | |
2661 if (u_save_cursor() == FAIL) | |
2662 return; | |
2663 coladvance_force(oap->op_type == OP_APPEND | |
2664 ? oap->end_vcol + 1 : getviscol()); | |
2665 if (oap->op_type == OP_APPEND) | |
2666 --curwin->w_cursor.col; | |
2667 ve_flags = old_ve_flags; | |
2668 } | |
2669 #endif | |
2670 /* Get the info about the block before entering the text */ | |
2671 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
|
2672 /* 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
|
2673 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 2674 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
|
2675 |
7 | 2676 if (oap->op_type == OP_APPEND) |
2677 firstline += bd.textlen; | |
2678 pre_textlen = (long)STRLEN(firstline); | |
2679 } | |
2680 | |
2681 if (oap->op_type == OP_APPEND) | |
2682 { | |
2683 if (oap->block_mode | |
2684 #ifdef FEAT_VIRTUALEDIT | |
2685 && curwin->w_cursor.coladd == 0 | |
2686 #endif | |
2687 ) | |
2688 { | |
2689 /* Move the cursor to the character right of the block. */ | |
2690 curwin->w_set_curswant = TRUE; | |
2691 while (*ml_get_cursor() != NUL | |
2692 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2693 ++curwin->w_cursor.col; | |
2694 if (bd.is_short && !bd.is_MAX) | |
2695 { | |
2696 /* First line was too short, make it longer and adjust the | |
2697 * values in "bd". */ | |
2698 if (u_save_cursor() == FAIL) | |
2699 return; | |
2700 for (i = 0; i < bd.endspaces; ++i) | |
2701 ins_char(' '); | |
2702 bd.textlen += bd.endspaces; | |
2703 } | |
2704 } | |
2705 else | |
2706 { | |
2707 curwin->w_cursor = oap->end; | |
893 | 2708 check_cursor_col(); |
7 | 2709 |
2710 /* 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
|
2711 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2712 && oap->start_vcol != oap->end_vcol) |
2713 inc_cursor(); | |
2714 } | |
2715 } | |
2716 | |
6579 | 2717 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
|
2718 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 2719 |
6579 | 2720 /* When a tab was inserted, and the characters in front of the tab |
2721 * have been converted to a tab as well, the column of the cursor | |
2722 * might have actually been reduced, so need to adjust here. */ | |
2723 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
|
2724 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 2725 oap->start = curbuf->b_op_start_orig; |
2726 | |
1477 | 2727 /* If user has moved off this line, we don't know what to do, so do |
2728 * nothing. | |
2729 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2730 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2731 return; |
2732 | |
2733 if (oap->block_mode) | |
2734 { | |
2735 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
|
2736 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
|
2737 size_t len; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2738 int add; |
7 | 2739 |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2740 /* 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
|
2741 * 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
|
2742 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2743 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
|
2744 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2745 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2746 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
|
2747 did_indent = TRUE; |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2748 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2749 |
5471 | 2750 /* 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
|
2751 * 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
|
2752 * 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
|
2753 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
|
2754 && !bd.is_MAX && !did_indent) |
5471 | 2755 { |
2756 if (oap->op_type == OP_INSERT | |
5730 | 2757 && oap->start.col |
2758 #ifdef FEAT_VIRTUALEDIT | |
2759 + oap->start.coladd | |
2760 #endif | |
2761 != curbuf->b_op_start_orig.col | |
2762 #ifdef FEAT_VIRTUALEDIT | |
2763 + curbuf->b_op_start_orig.coladd | |
2764 #endif | |
2765 ) | |
5471 | 2766 { |
6579 | 2767 int t = getviscol2(curbuf->b_op_start_orig.col, |
2768 curbuf->b_op_start_orig.coladd); | |
5680 | 2769 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2770 pre_textlen -= t - oap->start_vcol; |
2771 oap->start_vcol = t; | |
5471 | 2772 } |
2773 else if (oap->op_type == OP_APPEND | |
5730 | 2774 && oap->end.col |
2775 #ifdef FEAT_VIRTUALEDIT | |
2776 + oap->end.coladd | |
2777 #endif | |
2778 >= curbuf->b_op_start_orig.col | |
2779 #ifdef FEAT_VIRTUALEDIT | |
2780 + curbuf->b_op_start_orig.coladd | |
2781 #endif | |
2782 ) | |
5471 | 2783 { |
6579 | 2784 int t = getviscol2(curbuf->b_op_start_orig.col, |
2785 curbuf->b_op_start_orig.coladd); | |
5680 | 2786 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2787 /* reset pre_textlen to the value of OP_INSERT */ |
2788 pre_textlen += bd.textlen; | |
6579 | 2789 pre_textlen -= t - oap->start_vcol; |
2790 oap->start_vcol = t; | |
5471 | 2791 oap->op_type = OP_INSERT; |
2792 } | |
2793 } | |
2794 | |
7 | 2795 /* |
2796 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2797 * tabs. Get the starting column again and correct the length. |
7 | 2798 * Don't do this when "$" used, end-of-line will have changed. |
2799 */ | |
2800 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2801 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2802 { | |
2803 if (oap->op_type == OP_APPEND) | |
2804 { | |
2805 pre_textlen += bd2.textlen - bd.textlen; | |
2806 if (bd2.endspaces) | |
2807 --bd2.textlen; | |
2808 } | |
2809 bd.textcol = bd2.textcol; | |
2810 bd.textlen = bd2.textlen; | |
2811 } | |
2812 | |
2813 /* | |
2814 * Subsequent calls to ml_get() flush the firstline data - take a | |
2815 * copy of the required string. | |
2816 */ | |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2817 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
|
2818 len = STRLEN(firstline); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2819 add = bd.textcol; |
7 | 2820 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
|
2821 add += bd.textlen; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2822 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
|
2823 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
|
2824 else |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2825 firstline += add; |
3421 | 2826 if (pre_textlen >= 0 |
2827 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2828 { |
2829 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2830 if (ins_text != NULL) | |
2831 { | |
2832 /* block handled here */ | |
2833 if (u_save(oap->start.lnum, | |
2834 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2835 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2836 &bd); | |
2837 | |
2838 curwin->w_cursor.col = oap->start.col; | |
2839 check_cursor(); | |
2840 vim_free(ins_text); | |
2841 } | |
2842 } | |
2843 } | |
2844 } | |
2845 #endif | |
2846 | |
2847 /* | |
2848 * op_change - handle a change operation | |
2849 * | |
2850 * return TRUE if edit() returns because of a CTRL-O command | |
2851 */ | |
2852 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2853 op_change(oparg_T *oap) |
7 | 2854 { |
2855 colnr_T l; | |
2856 int retval; | |
2857 #ifdef FEAT_VISUALEXTRA | |
2858 long offset; | |
2859 linenr_T linenr; | |
1392 | 2860 long ins_len; |
2861 long pre_textlen = 0; | |
2862 long pre_indent = 0; | |
7 | 2863 char_u *firstline; |
2864 char_u *ins_text, *newp, *oldp; | |
2865 struct block_def bd; | |
2866 #endif | |
2867 | |
2868 l = oap->start.col; | |
2869 if (oap->motion_type == MLINE) | |
2870 { | |
2871 l = 0; | |
2872 #ifdef FEAT_SMARTINDENT | |
2873 if (!p_paste && curbuf->b_p_si | |
2874 # ifdef FEAT_CINDENT | |
2875 && !curbuf->b_p_cin | |
2876 # endif | |
2877 ) | |
2878 can_si = TRUE; /* It's like opening a new line, do si */ | |
2879 #endif | |
2880 } | |
2881 | |
2882 /* First delete the text in the region. In an empty buffer only need to | |
2883 * save for undo */ | |
2884 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2885 { | |
2886 if (u_save_cursor() == FAIL) | |
2887 return FALSE; | |
2888 } | |
2889 else if (op_delete(oap) == FAIL) | |
2890 return FALSE; | |
2891 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2892 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2893 && !virtual_op) |
2894 inc_cursor(); | |
2895 | |
2896 #ifdef FEAT_VISUALEXTRA | |
2897 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2898 /* skip blank lines too */ | |
2899 if (oap->block_mode) | |
2900 { | |
2901 # ifdef FEAT_VIRTUALEDIT | |
2902 /* Add spaces before getting the current line length. */ | |
2903 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2904 || gchar_cursor() == NUL)) | |
2905 coladvance_force(getviscol()); | |
2906 # endif | |
1392 | 2907 firstline = ml_get(oap->start.lnum); |
2908 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
|
2909 pre_indent = (long)getwhitecols(firstline); |
7 | 2910 bd.textcol = curwin->w_cursor.col; |
2911 } | |
2912 #endif | |
2913 | |
2914 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2915 if (oap->motion_type == MLINE) | |
2916 fix_indent(); | |
2917 #endif | |
2918 | |
2919 retval = edit(NUL, FALSE, (linenr_T)1); | |
2920 | |
2921 #ifdef FEAT_VISUALEXTRA | |
2922 /* | |
39 | 2923 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2924 * block. |
1477 | 2925 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2926 */ |
1477 | 2927 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2928 { |
1392 | 2929 /* Auto-indenting may have changed the indent. If the cursor was past |
2930 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2931 firstline = ml_get(oap->start.lnum); |
1403 | 2932 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2933 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2934 long new_indent = (long)getwhitecols(firstline); |
1392 | 2935 |
2936 pre_textlen += new_indent - pre_indent; | |
2937 bd.textcol += new_indent - pre_indent; | |
2938 } | |
2939 | |
2940 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2941 if (ins_len > 0) | |
2942 { | |
2943 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2944 * copy of the inserted text. */ | |
7 | 2945 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2946 { | |
419 | 2947 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2948 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2949 linenr++) | |
2950 { | |
2951 block_prep(oap, &bd, linenr, TRUE); | |
2952 if (!bd.is_short || virtual_op) | |
2953 { | |
2954 # ifdef FEAT_VIRTUALEDIT | |
2955 pos_T vpos; | |
2956 | |
2957 /* If the block starts in virtual space, count the | |
2958 * initial coladd offset as part of "startspaces" */ | |
2959 if (bd.is_short) | |
2960 { | |
1982 | 2961 vpos.lnum = linenr; |
7 | 2962 (void)getvpos(&vpos, oap->start_vcol); |
2963 } | |
2964 else | |
2965 vpos.coladd = 0; | |
2966 # endif | |
2967 oldp = ml_get(linenr); | |
2968 newp = alloc_check((unsigned)(STRLEN(oldp) | |
2969 # ifdef FEAT_VIRTUALEDIT | |
2970 + vpos.coladd | |
2971 # endif | |
2972 + ins_len + 1)); | |
2973 if (newp == NULL) | |
2974 continue; | |
2975 /* copy up to block start */ | |
2976 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2977 offset = bd.textcol; | |
2978 # ifdef FEAT_VIRTUALEDIT | |
6929 | 2979 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2980 offset += vpos.coladd; |
2981 # endif | |
2982 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
2983 offset += ins_len; | |
2984 oldp += bd.textcol; | |
1622 | 2985 STRMOVE(newp + offset, oldp); |
7 | 2986 ml_replace(linenr, newp, FALSE); |
2987 } | |
2988 } | |
2989 check_cursor(); | |
2990 | |
2991 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2992 } | |
2993 vim_free(ins_text); | |
2994 } | |
2995 } | |
2996 #endif | |
2997 | |
2998 return retval; | |
2999 } | |
3000 | |
3001 /* | |
3002 * set all the yank registers to empty (called from main()) | |
3003 */ | |
3004 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3005 init_yank(void) |
7 | 3006 { |
3007 int i; | |
3008 | |
3009 for (i = 0; i < NUM_REGISTERS; ++i) | |
3010 y_regs[i].y_array = NULL; | |
3011 } | |
3012 | |
356 | 3013 #if defined(EXITFREE) || defined(PROTO) |
3014 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3015 clear_registers(void) |
356 | 3016 { |
3017 int i; | |
3018 | |
3019 for (i = 0; i < NUM_REGISTERS; ++i) | |
3020 { | |
3021 y_current = &y_regs[i]; | |
3022 if (y_current->y_array != NULL) | |
3023 free_yank_all(); | |
3024 } | |
3025 } | |
3026 #endif | |
3027 | |
7 | 3028 /* |
3029 * Free "n" lines from the current yank register. | |
3030 * Called for normal freeing and in case of error. | |
3031 */ | |
3032 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3033 free_yank(long n) |
7 | 3034 { |
3035 if (y_current->y_array != NULL) | |
3036 { | |
3037 long i; | |
3038 | |
3039 for (i = n; --i >= 0; ) | |
3040 { | |
3041 #ifdef AMIGA /* only for very slow machines */ | |
3042 if ((i & 1023) == 1023) /* this may take a while */ | |
3043 { | |
3044 /* | |
3045 * This message should never cause a hit-return message. | |
3046 * Overwrite this message with any next message. | |
3047 */ | |
3048 ++no_wait_return; | |
3049 smsg((char_u *)_("freeing %ld lines"), i + 1); | |
3050 --no_wait_return; | |
3051 msg_didout = FALSE; | |
3052 msg_col = 0; | |
3053 } | |
3054 #endif | |
3055 vim_free(y_current->y_array[i]); | |
3056 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
3057 VIM_CLEAR(y_current->y_array); |
7 | 3058 #ifdef AMIGA |
3059 if (n >= 1000) | |
3060 MSG(""); | |
3061 #endif | |
3062 } | |
3063 } | |
3064 | |
3065 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3066 free_yank_all(void) |
7 | 3067 { |
3068 free_yank(y_current->y_size); | |
3069 } | |
3070 | |
3071 /* | |
3072 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
3073 * If we are to append (uppercase register), we first yank into a new yank | |
3074 * register and then concatenate the old and the new one (so we keep the old | |
3075 * one in case of out-of-memory). | |
3076 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
3077 * Return FAIL for failure, OK otherwise. |
7 | 3078 */ |
3079 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3080 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 3081 { |
3082 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
|
3083 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
|
3084 yankreg_T newreg; /* new yank register when appending */ |
7 | 3085 char_u **new_ptr; |
3086 linenr_T lnum; /* current line number */ | |
3087 long j; | |
3088 int yanktype = oap->motion_type; | |
3089 long yanklines = oap->line_count; | |
3090 linenr_T yankendlnum = oap->end.lnum; | |
3091 char_u *p; | |
3092 char_u *pnew; | |
3093 struct block_def bd; | |
2658 | 3094 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 3095 int did_star = FALSE; |
2658 | 3096 #endif |
7 | 3097 |
3098 /* check for read-only register */ | |
3099 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
3100 { | |
3101 beep_flush(); | |
3102 return FAIL; | |
3103 } | |
3104 if (oap->regname == '_') /* black hole: nothing to do */ | |
3105 return OK; | |
3106 | |
3107 #ifdef FEAT_CLIPBOARD | |
3108 if (!clip_star.available && oap->regname == '*') | |
3109 oap->regname = 0; | |
3110 else if (!clip_plus.available && oap->regname == '+') | |
3111 oap->regname = 0; | |
3112 #endif | |
3113 | |
3114 if (!deleting) /* op_delete() already set y_current */ | |
3115 get_yank_register(oap->regname, TRUE); | |
3116 | |
3117 curr = y_current; | |
3118 /* append to existing contents */ | |
3119 if (y_append && y_current->y_array != NULL) | |
3120 y_current = &newreg; | |
3121 else | |
3122 free_yank_all(); /* free previously yanked lines */ | |
3123 | |
593 | 3124 /* |
3125 * If the cursor was in column 1 before and after the movement, and the | |
3126 * operator is not inclusive, the yank is always linewise. | |
3127 */ | |
7 | 3128 if ( oap->motion_type == MCHAR |
3129 && oap->start.col == 0 | |
3130 && !oap->inclusive | |
3131 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 3132 && !oap->block_mode |
7 | 3133 && oap->end.col == 0 |
3134 && yanklines > 1) | |
3135 { | |
3136 yanktype = MLINE; | |
3137 --yankendlnum; | |
3138 --yanklines; | |
3139 } | |
3140 | |
3141 y_current->y_size = yanklines; | |
3142 y_current->y_type = yanktype; /* set the yank register type */ | |
3143 y_current->y_width = 0; | |
3144 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
3145 yanklines), TRUE); | |
3146 if (y_current->y_array == NULL) | |
3147 { | |
3148 y_current = curr; | |
3149 return FAIL; | |
3150 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3151 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3152 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
|
3153 #endif |
7 | 3154 |
3155 y_idx = 0; | |
3156 lnum = oap->start.lnum; | |
3157 | |
3158 if (oap->block_mode) | |
3159 { | |
3160 /* Visual block mode */ | |
3161 y_current->y_type = MBLOCK; /* set the yank register type */ | |
3162 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
3163 | |
3164 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3165 y_current->y_width--; | |
3166 } | |
3167 | |
3168 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3169 { | |
3170 switch (y_current->y_type) | |
3171 { | |
3172 case MBLOCK: | |
3173 block_prep(oap, &bd, lnum, FALSE); | |
3174 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3175 goto fail; | |
3176 break; | |
3177 | |
3178 case MLINE: | |
3179 if ((y_current->y_array[y_idx] = | |
3180 vim_strsave(ml_get(lnum))) == NULL) | |
3181 goto fail; | |
3182 break; | |
3183 | |
3184 case MCHAR: | |
3185 { | |
3186 colnr_T startcol = 0, endcol = MAXCOL; | |
3187 #ifdef FEAT_VIRTUALEDIT | |
3188 int is_oneChar = FALSE; | |
3189 colnr_T cs, ce; | |
3190 #endif | |
3191 p = ml_get(lnum); | |
3192 bd.startspaces = 0; | |
3193 bd.endspaces = 0; | |
3194 | |
3195 if (lnum == oap->start.lnum) | |
3196 { | |
3197 startcol = oap->start.col; | |
3198 #ifdef FEAT_VIRTUALEDIT | |
3199 if (virtual_op) | |
3200 { | |
3201 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3202 if (ce != cs && oap->start.coladd > 0) | |
3203 { | |
3204 /* Part of a tab selected -- but don't | |
3205 * double-count it. */ | |
3206 bd.startspaces = (ce - cs + 1) | |
3207 - oap->start.coladd; | |
3208 startcol++; | |
3209 } | |
3210 } | |
3211 #endif | |
3212 } | |
3213 | |
3214 if (lnum == oap->end.lnum) | |
3215 { | |
3216 endcol = oap->end.col; | |
3217 #ifdef FEAT_VIRTUALEDIT | |
3218 if (virtual_op) | |
3219 { | |
3220 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3221 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3222 # ifdef FEAT_MBYTE | |
3223 /* Don't add space for double-wide | |
3224 * char; endcol will be on last byte | |
3225 * of multi-byte char. */ | |
3226 && (*mb_head_off)(p, p + endcol) == 0 | |
3227 # endif | |
3228 )) | |
3229 { | |
3230 if (oap->start.lnum == oap->end.lnum | |
3231 && oap->start.col == oap->end.col) | |
3232 { | |
3233 /* Special case: inside a single char */ | |
3234 is_oneChar = TRUE; | |
3235 bd.startspaces = oap->end.coladd | |
3236 - oap->start.coladd + oap->inclusive; | |
3237 endcol = startcol; | |
3238 } | |
3239 else | |
3240 { | |
3241 bd.endspaces = oap->end.coladd | |
3242 + oap->inclusive; | |
3243 endcol -= oap->inclusive; | |
3244 } | |
3245 } | |
3246 } | |
3247 #endif | |
3248 } | |
3510 | 3249 if (endcol == MAXCOL) |
3250 endcol = (colnr_T)STRLEN(p); | |
7 | 3251 if (startcol > endcol |
3252 #ifdef FEAT_VIRTUALEDIT | |
3253 || is_oneChar | |
3254 #endif | |
3255 ) | |
3256 bd.textlen = 0; | |
3257 else | |
3258 { | |
3259 bd.textlen = endcol - startcol + oap->inclusive; | |
3260 } | |
3261 bd.textstart = p + startcol; | |
3262 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3263 goto fail; | |
3264 break; | |
3265 } | |
3266 /* NOTREACHED */ | |
3267 } | |
3268 } | |
3269 | |
3270 if (curr != y_current) /* append the new block to the old block */ | |
3271 { | |
3272 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3273 (curr->y_size + y_current->y_size)), TRUE); | |
3274 if (new_ptr == NULL) | |
3275 goto fail; | |
3276 for (j = 0; j < curr->y_size; ++j) | |
3277 new_ptr[j] = curr->y_array[j]; | |
3278 vim_free(curr->y_array); | |
3279 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3280 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3281 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3282 #endif |
7 | 3283 |
3284 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3285 curr->y_type = MLINE; | |
3286 | |
164 | 3287 /* Concatenate the last line of the old block with the first line of |
3288 * the new block, unless being Vi compatible. */ | |
3289 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3290 { |
3291 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3292 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3293 if (pnew == NULL) | |
3294 { | |
3295 y_idx = y_current->y_size - 1; | |
3296 goto fail; | |
3297 } | |
3298 STRCPY(pnew, curr->y_array[--j]); | |
3299 STRCAT(pnew, y_current->y_array[0]); | |
3300 vim_free(curr->y_array[j]); | |
3301 vim_free(y_current->y_array[0]); | |
3302 curr->y_array[j++] = pnew; | |
3303 y_idx = 1; | |
3304 } | |
3305 else | |
3306 y_idx = 0; | |
3307 while (y_idx < y_current->y_size) | |
3308 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3309 curr->y_size = j; | |
3310 vim_free(y_current->y_array); | |
3311 y_current = curr; | |
3312 } | |
5981 | 3313 if (curwin->w_p_rnu) |
3314 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3315 if (mess) /* Display message about yank? */ |
3316 { | |
3317 if (yanktype == MCHAR | |
3318 && !oap->block_mode | |
3319 && yanklines == 1) | |
3320 yanklines = 0; | |
3321 /* Some versions of Vi use ">=" here, some don't... */ | |
3322 if (yanklines > p_report) | |
3323 { | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3324 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
|
3325 |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3326 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
|
3327 *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
|
3328 else |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3329 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
|
3330 _(" 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
|
3331 |
7 | 3332 /* redisplay now, so message is not deleted */ |
3333 update_topline_redraw(); | |
3334 if (yanklines == 1) | |
205 | 3335 { |
3336 if (oap->block_mode) | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3337 smsg((char_u *)_("block of 1 line yanked%s"), namebuf); |
205 | 3338 else |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3339 smsg((char_u *)_("1 line yanked%s"), namebuf); |
205 | 3340 } |
3341 else if (oap->block_mode) | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3342 smsg((char_u *)_("block of %ld lines yanked%s"), |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3343 yanklines, namebuf); |
7 | 3344 else |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3345 smsg((char_u *)_("%ld lines yanked%s"), yanklines, |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3346 namebuf); |
7 | 3347 } |
3348 } | |
3349 | |
3350 /* | |
3351 * Set "'[" and "']" marks. | |
3352 */ | |
3353 curbuf->b_op_start = oap->start; | |
3354 curbuf->b_op_end = oap->end; | |
5735 | 3355 if (yanktype == MLINE && !oap->block_mode) |
36 | 3356 { |
3357 curbuf->b_op_start.col = 0; | |
3358 curbuf->b_op_end.col = MAXCOL; | |
3359 } | |
7 | 3360 |
3361 #ifdef FEAT_CLIPBOARD | |
3362 /* | |
3363 * If we were yanking to the '*' register, send result to clipboard. | |
3364 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3365 * to the '*' register. | |
3366 */ | |
3367 if (clip_star.available | |
3368 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3369 || (!deleting && oap->regname == 0 |
6116 | 3370 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3371 { |
3372 if (curr != &(y_regs[STAR_REGISTER])) | |
3373 /* Copy the text from register 0 to the clipboard register. */ | |
3374 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3375 | |
3376 clip_own_selection(&clip_star); | |
3377 clip_gen_set_selection(&clip_star); | |
2658 | 3378 # ifdef FEAT_X11 |
2654 | 3379 did_star = TRUE; |
2658 | 3380 # endif |
7 | 3381 } |
3382 | |
3383 # ifdef FEAT_X11 | |
3384 /* | |
3385 * If we were yanking to the '+' register, send result to selection. | |
3386 * Also copy to the '*' register, in case auto-select is off. | |
3387 */ | |
2654 | 3388 if (clip_plus.available |
3389 && (curr == &(y_regs[PLUS_REGISTER]) | |
3390 || (!deleting && oap->regname == 0 | |
6116 | 3391 && ((clip_unnamed | clip_unnamed_saved) & |
3392 CLIP_UNNAMED_PLUS)))) | |
7 | 3393 { |
2654 | 3394 if (curr != &(y_regs[PLUS_REGISTER])) |
3395 /* Copy the text from register 0 to the clipboard register. */ | |
3396 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3397 | |
7 | 3398 clip_own_selection(&clip_plus); |
3399 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
|
3400 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
|
3401 && !did_star && curr == &(y_regs[PLUS_REGISTER])) |
7 | 3402 { |
3403 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3404 clip_own_selection(&clip_star); | |
3405 clip_gen_set_selection(&clip_star); | |
3406 } | |
3407 } | |
3408 # endif | |
3409 #endif | |
3410 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
3411 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3412 if (!deleting && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3413 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
|
3414 #endif |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3415 |
7 | 3416 return OK; |
3417 | |
3418 fail: /* free the allocated lines */ | |
3419 free_yank(y_idx + 1); | |
3420 y_current = curr; | |
3421 return FAIL; | |
3422 } | |
3423 | |
3424 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3425 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3426 { |
3427 char_u *pnew; | |
3428 | |
3429 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3430 == NULL) | |
3431 return FAIL; | |
3432 y_current->y_array[y_idx] = pnew; | |
6929 | 3433 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3434 pnew += bd->startspaces; |
3435 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3436 pnew += bd->textlen; | |
6929 | 3437 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3438 pnew += bd->endspaces; |
3439 *pnew = NUL; | |
3440 return OK; | |
3441 } | |
3442 | |
3443 #ifdef FEAT_CLIPBOARD | |
3444 /* | |
3445 * Make a copy of the y_current register to register "reg". | |
3446 */ | |
3447 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3448 copy_yank_reg(yankreg_T *reg) |
7 | 3449 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3450 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3451 long j; |
7 | 3452 |
3453 y_current = reg; | |
3454 free_yank_all(); | |
3455 *y_current = *curr; | |
3456 y_current->y_array = (char_u **)lalloc_clear( | |
3457 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3458 if (y_current->y_array == NULL) | |
3459 y_current->y_size = 0; | |
3460 else | |
3461 for (j = 0; j < y_current->y_size; ++j) | |
3462 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3463 { | |
3464 free_yank(j); | |
3465 y_current->y_size = 0; | |
3466 break; | |
3467 } | |
3468 y_current = curr; | |
3469 } | |
3470 #endif | |
3471 | |
3472 /* | |
140 | 3473 * Put contents of register "regname" into the text. |
3474 * Caller must check "regname" to be valid! | |
3475 * "flags": PUT_FIXINDENT make indent look nice | |
3476 * PUT_CURSEND leave cursor after end of new text | |
3477 * PUT_LINE force linewise put (":put") | |
7 | 3478 */ |
3479 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3480 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3481 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3482 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
|
3483 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3484 int flags) |
7 | 3485 { |
3486 char_u *ptr; | |
3487 char_u *newp, *oldp; | |
3488 int yanklen; | |
3489 int totlen = 0; /* init for gcc */ | |
3490 linenr_T lnum; | |
3491 colnr_T col; | |
3492 long i; /* index in y_array[] */ | |
3493 int y_type; | |
3494 long y_size; | |
3495 int oldlen; | |
3496 long y_width = 0; | |
3497 colnr_T vcol; | |
3498 int delcount; | |
3499 int incr = 0; | |
3500 long j; | |
3501 struct block_def bd; | |
3502 char_u **y_array = NULL; | |
3503 long nr_lines = 0; | |
3504 pos_T new_cursor; | |
3505 int indent; | |
3506 int orig_indent = 0; /* init for gcc */ | |
3507 int indent_diff = 0; /* init for gcc */ | |
3508 int first_indent = TRUE; | |
3509 int lendiff = 0; | |
3510 pos_T old_pos; | |
3511 char_u *insert_string = NULL; | |
3512 int allocated = FALSE; | |
3513 long cnt; | |
3514 | |
3515 #ifdef FEAT_CLIPBOARD | |
3516 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3517 adjust_clip_reg(®name); | |
3518 (void)may_get_selection(regname); | |
3519 #endif | |
3520 | |
3521 if (flags & PUT_FIXINDENT) | |
3522 orig_indent = get_indent(); | |
3523 | |
3524 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3525 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3526 | |
3527 /* | |
3528 * Using inserted text works differently, because the register includes | |
3529 * special characters (newlines, etc.). | |
3530 */ | |
3531 if (regname == '.') | |
3532 { | |
10494
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3533 if (VIsual_active) |
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3534 stuffcharReadbuff(VIsual_mode); |
7 | 3535 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
3536 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3537 /* Putting the text is done later, so can't really move the cursor to | |
3538 * the next character. Use "l" to simulate it. */ | |
3539 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3540 stuffcharReadbuff('l'); | |
3541 return; | |
3542 } | |
3543 | |
3544 /* | |
3545 * For special registers '%' (file name), '#' (alternate file name) and | |
3546 * ':' (last command line), etc. we have to create a fake yank register. | |
3547 */ | |
3548 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3549 { | |
3550 if (insert_string == NULL) | |
3551 return; | |
3552 } | |
3553 | |
14202
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3554 /* 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
|
3555 * 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
|
3556 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
|
3557 goto end; |
4005 | 3558 |
7 | 3559 if (insert_string != NULL) |
3560 { | |
3561 y_type = MCHAR; | |
3562 #ifdef FEAT_EVAL | |
3563 if (regname == '=') | |
3564 { | |
3565 /* For the = register we need to split the string at NL | |
3093 | 3566 * characters. |
3567 * Loop twice: count the number of lines and save them. */ | |
7 | 3568 for (;;) |
3569 { | |
3570 y_size = 0; | |
3571 ptr = insert_string; | |
3572 while (ptr != NULL) | |
3573 { | |
3574 if (y_array != NULL) | |
3575 y_array[y_size] = ptr; | |
3576 ++y_size; | |
3577 ptr = vim_strchr(ptr, '\n'); | |
3578 if (ptr != NULL) | |
3579 { | |
3580 if (y_array != NULL) | |
3581 *ptr = NUL; | |
3582 ++ptr; | |
3093 | 3583 /* A trailing '\n' makes the register linewise. */ |
7 | 3584 if (*ptr == NUL) |
3585 { | |
3586 y_type = MLINE; | |
3587 break; | |
3588 } | |
3589 } | |
3590 } | |
3591 if (y_array != NULL) | |
3592 break; | |
3593 y_array = (char_u **)alloc((unsigned) | |
3594 (y_size * sizeof(char_u *))); | |
3595 if (y_array == NULL) | |
3596 goto end; | |
3597 } | |
3598 } | |
3599 else | |
3600 #endif | |
3601 { | |
3602 y_size = 1; /* use fake one-line yank register */ | |
3603 y_array = &insert_string; | |
3604 } | |
3605 } | |
3606 else | |
3607 { | |
3608 get_yank_register(regname, FALSE); | |
3609 | |
3610 y_type = y_current->y_type; | |
3611 y_width = y_current->y_width; | |
3612 y_size = y_current->y_size; | |
3613 y_array = y_current->y_array; | |
3614 } | |
3615 | |
3616 if (y_type == MLINE) | |
3617 { | |
3618 if (flags & PUT_LINE_SPLIT) | |
3619 { | |
6845 | 3620 char_u *p; |
3621 | |
7 | 3622 /* "p" or "P" in Visual mode: split the lines to put the text in |
3623 * between. */ | |
3624 if (u_save_cursor() == FAIL) | |
3625 goto end; | |
6845 | 3626 p = ml_get_cursor(); |
3627 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
|
3628 MB_PTR_ADV(p); |
6845 | 3629 ptr = vim_strsave(p); |
7 | 3630 if (ptr == NULL) |
3631 goto end; | |
3632 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3633 vim_free(ptr); | |
3634 | |
6845 | 3635 oldp = ml_get_curline(); |
3636 p = oldp + curwin->w_cursor.col; | |
3637 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
|
3638 MB_PTR_ADV(p); |
6845 | 3639 ptr = vim_strnsave(oldp, p - oldp); |
7 | 3640 if (ptr == NULL) |
3641 goto end; | |
3642 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3643 ++nr_lines; | |
3644 dir = FORWARD; | |
3645 } | |
3646 if (flags & PUT_LINE_FORWARD) | |
3647 { | |
3648 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3649 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3650 dir = FORWARD; |
3651 } | |
3652 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3653 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3654 } | |
3655 | |
3656 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3657 y_type = MLINE; | |
3658 | |
3659 if (y_size == 0 || y_array == NULL) | |
3660 { | |
3661 EMSG2(_("E353: Nothing in register %s"), | |
3662 regname == 0 ? (char_u *)"\"" : transchar(regname)); | |
3663 goto end; | |
3664 } | |
3665 | |
3666 if (y_type == MBLOCK) | |
3667 { | |
3668 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3669 if (lnum > curbuf->b_ml.ml_line_count) | |
3670 lnum = curbuf->b_ml.ml_line_count + 1; | |
3671 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3672 goto end; | |
3673 } | |
5735 | 3674 else if (y_type == MLINE) |
7 | 3675 { |
3676 lnum = curwin->w_cursor.lnum; | |
3677 #ifdef FEAT_FOLDING | |
3678 /* Correct line number for closed fold. Don't move the cursor yet, | |
3679 * u_save() uses it. */ | |
3680 if (dir == BACKWARD) | |
3681 (void)hasFolding(lnum, &lnum, NULL); | |
3682 else | |
3683 (void)hasFolding(lnum, NULL, &lnum); | |
3684 #endif | |
3685 if (dir == FORWARD) | |
3686 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3687 /* 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
|
3688 * 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
|
3689 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3690 goto end; |
3691 #ifdef FEAT_FOLDING | |
3692 if (dir == FORWARD) | |
3693 curwin->w_cursor.lnum = lnum - 1; | |
3694 else | |
3695 curwin->w_cursor.lnum = lnum; | |
3696 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3697 #endif | |
3698 } | |
3699 else if (u_save_cursor() == FAIL) | |
3700 goto end; | |
3701 | |
3702 yanklen = (int)STRLEN(y_array[0]); | |
3703 | |
3704 #ifdef FEAT_VIRTUALEDIT | |
3705 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3706 { | |
3707 if (gchar_cursor() == TAB) | |
3708 { | |
3709 /* Don't need to insert spaces when "p" on the last position of a | |
3710 * 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
|
3711 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3712 int viscol = getviscol(); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3713 if (dir == FORWARD |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3714 ? 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
|
3715 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
|
3716 : 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
|
3717 coladvance_force(viscol); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3718 #else |
7 | 3719 if (dir == FORWARD |
3720 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3721 : curwin->w_cursor.coladd > 0) | |
3722 coladvance_force(getviscol()); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3723 #endif |
7 | 3724 else |
3725 curwin->w_cursor.coladd = 0; | |
3726 } | |
3727 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3728 coladvance_force(getviscol() + (dir == FORWARD)); | |
3729 } | |
3730 #endif | |
3731 | |
3732 lnum = curwin->w_cursor.lnum; | |
3733 col = curwin->w_cursor.col; | |
3734 | |
3735 /* | |
3736 * Block mode | |
3737 */ | |
3738 if (y_type == MBLOCK) | |
3739 { | |
10664
94db9c08e206
patch 8.0.0222: blockwise put on multi-byte character misplaced
Christian Brabandt <cb@256bit.org>
parents:
10494
diff
changeset
|
3740 int c = gchar_cursor(); |
7 | 3741 colnr_T endcol2 = 0; |
3742 | |
3743 if (dir == FORWARD && c != NUL) | |
3744 { | |
3745 #ifdef FEAT_VIRTUALEDIT | |
3746 if (ve_flags == VE_ALL) | |
3747 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3748 else | |
3749 #endif | |
3750 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3751 | |
3752 #ifdef FEAT_MBYTE | |
3753 if (has_mbyte) | |
3754 /* move to start of next multi-byte character */ | |
474 | 3755 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3756 else |
3757 #endif | |
3758 #ifdef FEAT_VIRTUALEDIT | |
3759 if (c != TAB || ve_flags != VE_ALL) | |
3760 #endif | |
3761 ++curwin->w_cursor.col; | |
3762 ++col; | |
3763 } | |
3764 else | |
3765 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3766 | |
3767 #ifdef FEAT_VIRTUALEDIT | |
3768 col += curwin->w_cursor.coladd; | |
1304 | 3769 if (ve_flags == VE_ALL |
3770 && (curwin->w_cursor.coladd > 0 | |
3771 || endcol2 == curwin->w_cursor.col)) | |
7 | 3772 { |
3773 if (dir == FORWARD && c == NUL) | |
3774 ++col; | |
3775 if (dir != FORWARD && c != NUL) | |
3776 ++curwin->w_cursor.col; | |
3777 if (c == TAB) | |
3778 { | |
3779 if (dir == BACKWARD && curwin->w_cursor.col) | |
3780 curwin->w_cursor.col--; | |
3781 if (dir == FORWARD && col - 1 == endcol2) | |
3782 curwin->w_cursor.col++; | |
3783 } | |
3784 } | |
3785 curwin->w_cursor.coladd = 0; | |
3786 #endif | |
699 | 3787 bd.textcol = 0; |
7 | 3788 for (i = 0; i < y_size; ++i) |
3789 { | |
3790 int spaces; | |
3791 char shortline; | |
3792 | |
3793 bd.startspaces = 0; | |
3794 bd.endspaces = 0; | |
3795 vcol = 0; | |
3796 delcount = 0; | |
3797 | |
3798 /* add a new line */ | |
3799 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3800 { | |
3801 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3802 (colnr_T)1, FALSE) == FAIL) | |
3803 break; | |
3804 ++nr_lines; | |
3805 } | |
3806 /* get the old line and advance to the position to insert at */ | |
3807 oldp = ml_get_curline(); | |
3808 oldlen = (int)STRLEN(oldp); | |
3809 for (ptr = oldp; vcol < col && *ptr; ) | |
3810 { | |
3811 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3812 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3813 vcol += incr; |
3814 } | |
3815 bd.textcol = (colnr_T)(ptr - oldp); | |
3816 | |
3817 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3818 | |
3819 if (vcol < col) /* line too short, padd with spaces */ | |
3820 bd.startspaces = col - vcol; | |
3821 else if (vcol > col) | |
3822 { | |
3823 bd.endspaces = vcol - col; | |
3824 bd.startspaces = incr - bd.endspaces; | |
3825 --bd.textcol; | |
3826 delcount = 1; | |
3827 #ifdef FEAT_MBYTE | |
3828 if (has_mbyte) | |
3829 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3830 #endif | |
3831 if (oldp[bd.textcol] != TAB) | |
3832 { | |
3833 /* Only a Tab can be split into spaces. Other | |
3834 * characters will have to be moved to after the | |
3835 * block, causing misalignment. */ | |
3836 delcount = 0; | |
3837 bd.endspaces = 0; | |
3838 } | |
3839 } | |
3840 | |
3841 yanklen = (int)STRLEN(y_array[i]); | |
3842 | |
3843 /* calculate number of spaces required to fill right side of block*/ | |
3844 spaces = y_width + 1; | |
3845 for (j = 0; j < yanklen; j++) | |
5995 | 3846 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3847 if (spaces < 0) |
3848 spaces = 0; | |
3849 | |
3850 /* insert the new text */ | |
3851 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3852 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3853 if (newp == NULL) | |
3854 break; | |
3855 /* copy part up to cursor to new line */ | |
3856 ptr = newp; | |
3857 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3858 ptr += bd.textcol; | |
3859 /* may insert some spaces before the new text */ | |
6929 | 3860 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3861 ptr += bd.startspaces; |
3862 /* insert the new text */ | |
3863 for (j = 0; j < count; ++j) | |
3864 { | |
3865 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3866 ptr += yanklen; | |
3867 | |
3868 /* insert block's trailing spaces only if there's text behind */ | |
3869 if ((j < count - 1 || !shortline) && spaces) | |
3870 { | |
6929 | 3871 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3872 ptr += spaces; |
3873 } | |
3874 } | |
3875 /* may insert some spaces after the new text */ | |
6929 | 3876 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3877 ptr += bd.endspaces; |
3878 /* move the text after the cursor to the end of the line. */ | |
3879 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3880 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3881 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3882 | |
3883 ++curwin->w_cursor.lnum; | |
3884 if (i == 0) | |
3885 curwin->w_cursor.col += bd.startspaces; | |
3886 } | |
3887 | |
3888 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3889 | |
3890 /* Set '[ mark. */ | |
3891 curbuf->b_op_start = curwin->w_cursor; | |
3892 curbuf->b_op_start.lnum = lnum; | |
3893 | |
3894 /* adjust '] mark */ | |
3895 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3896 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
237 | 3897 # ifdef FEAT_VIRTUALEDIT |
7 | 3898 curbuf->b_op_end.coladd = 0; |
237 | 3899 # endif |
7 | 3900 if (flags & PUT_CURSEND) |
3901 { | |
916 | 3902 colnr_T len; |
3903 | |
7 | 3904 curwin->w_cursor = curbuf->b_op_end; |
3905 curwin->w_cursor.col++; | |
916 | 3906 |
3907 /* in Insert mode we might be after the NUL, correct for that */ | |
3908 len = (colnr_T)STRLEN(ml_get_curline()); | |
3909 if (curwin->w_cursor.col > len) | |
3910 curwin->w_cursor.col = len; | |
7 | 3911 } |
3912 else | |
3913 curwin->w_cursor.lnum = lnum; | |
3914 } | |
3915 else | |
3916 { | |
3917 /* | |
3918 * Character or Line mode | |
3919 */ | |
3920 if (y_type == MCHAR) | |
3921 { | |
3922 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3923 * char */ | |
3924 if (dir == FORWARD && gchar_cursor() != NUL) | |
3925 { | |
3926 #ifdef FEAT_MBYTE | |
3927 if (has_mbyte) | |
3928 { | |
474 | 3929 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3930 |
3931 /* put it on the next of the multi-byte character. */ | |
3932 col += bytelen; | |
3933 if (yanklen) | |
3934 { | |
3935 curwin->w_cursor.col += bytelen; | |
3936 curbuf->b_op_end.col += bytelen; | |
3937 } | |
3938 } | |
3939 else | |
3940 #endif | |
3941 { | |
3942 ++col; | |
3943 if (yanklen) | |
3944 { | |
3945 ++curwin->w_cursor.col; | |
3946 ++curbuf->b_op_end.col; | |
3947 } | |
3948 } | |
3949 } | |
3950 curbuf->b_op_start = curwin->w_cursor; | |
3951 } | |
3952 /* | |
3953 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3954 */ | |
3955 else if (dir == BACKWARD) | |
3956 --lnum; | |
699 | 3957 new_cursor = curwin->w_cursor; |
7 | 3958 |
3959 /* | |
3960 * simple case: insert into current line | |
3961 */ | |
3962 if (y_type == MCHAR && y_size == 1) | |
3963 { | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3964 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
|
3965 |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3966 if (VIsual_active) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3967 { |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3968 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
|
3969 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
|
3970 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
|
3971 } |
10670
bce3eccea39a
patch 8.0.0225: put in Visual block mode terminates early
Christian Brabandt <cb@256bit.org>
parents:
10664
diff
changeset
|
3972 |
5365 | 3973 do { |
3974 totlen = count * yanklen; | |
3975 if (totlen > 0) | |
7 | 3976 { |
5365 | 3977 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
|
3978 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
|
3979 { |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3980 lnum++; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3981 continue; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3982 } |
5365 | 3983 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); |
3984 if (newp == NULL) | |
3985 goto end; /* alloc() gave an error message */ | |
3986 mch_memmove(newp, oldp, (size_t)col); | |
3987 ptr = newp + col; | |
3988 for (i = 0; i < count; ++i) | |
3989 { | |
3990 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3991 ptr += yanklen; | |
3992 } | |
3993 STRMOVE(ptr, oldp + col); | |
3994 ml_replace(lnum, newp, FALSE); | |
3995 /* Place cursor on last putted char. */ | |
3996 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3997 { |
3998 /* make sure curwin->w_virtcol is updated */ | |
3999 changed_cline_bef_curs(); | |
5365 | 4000 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 4001 } |
7 | 4002 } |
5365 | 4003 if (VIsual_active) |
4004 lnum++; | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
4005 } while (VIsual_active && lnum <= end_lnum); |
5365 | 4006 |
6379 | 4007 if (VIsual_active) /* reset lnum to the last visual line */ |
4008 lnum--; | |
4009 | |
7 | 4010 curbuf->b_op_end = curwin->w_cursor; |
4011 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
4012 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
4013 ++curwin->w_cursor.col; | |
4014 changed_bytes(lnum, col); | |
4015 } | |
4016 else | |
4017 { | |
4018 /* | |
4019 * Insert at least one line. When y_type is MCHAR, break the first | |
4020 * line in two. | |
4021 */ | |
4022 for (cnt = 1; cnt <= count; ++cnt) | |
4023 { | |
4024 i = 0; | |
4025 if (y_type == MCHAR) | |
4026 { | |
4027 /* | |
4028 * Split the current line in two at the insert position. | |
4029 * First insert y_array[size - 1] in front of second line. | |
4030 * Then append y_array[0] to first line. | |
4031 */ | |
4032 lnum = new_cursor.lnum; | |
4033 ptr = ml_get(lnum) + col; | |
4034 totlen = (int)STRLEN(y_array[y_size - 1]); | |
4035 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
4036 if (newp == NULL) | |
4037 goto error; | |
4038 STRCPY(newp, y_array[y_size - 1]); | |
4039 STRCAT(newp, ptr); | |
4040 /* insert second line */ | |
4041 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
4042 vim_free(newp); | |
4043 | |
4044 oldp = ml_get(lnum); | |
4045 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
4046 if (newp == NULL) | |
4047 goto error; | |
4048 /* copy first part of line */ | |
4049 mch_memmove(newp, oldp, (size_t)col); | |
4050 /* append to first line */ | |
4051 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
4052 ml_replace(lnum, newp, FALSE); | |
4053 | |
4054 curwin->w_cursor.lnum = lnum; | |
4055 i = 1; | |
4056 } | |
4057 | |
4058 for (; i < y_size; ++i) | |
4059 { | |
4060 if ((y_type != MCHAR || i < y_size - 1) | |
4061 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
4062 == FAIL) | |
4063 goto error; | |
4064 lnum++; | |
4065 ++nr_lines; | |
4066 if (flags & PUT_FIXINDENT) | |
4067 { | |
4068 old_pos = curwin->w_cursor; | |
4069 curwin->w_cursor.lnum = lnum; | |
4070 ptr = ml_get(lnum); | |
4071 if (cnt == count && i == y_size - 1) | |
4072 lendiff = (int)STRLEN(ptr); | |
4073 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
4074 if (*ptr == '#' && preprocs_left()) | |
4075 indent = 0; /* Leave # lines at start */ | |
4076 else | |
4077 #endif | |
4078 if (*ptr == NUL) | |
4079 indent = 0; /* Ignore empty lines */ | |
4080 else if (first_indent) | |
4081 { | |
4082 indent_diff = orig_indent - get_indent(); | |
4083 indent = orig_indent; | |
4084 first_indent = FALSE; | |
4085 } | |
4086 else if ((indent = get_indent() + indent_diff) < 0) | |
4087 indent = 0; | |
4088 (void)set_indent(indent, 0); | |
4089 curwin->w_cursor = old_pos; | |
4090 /* remember how many chars were removed */ | |
4091 if (cnt == count && i == y_size - 1) | |
4092 lendiff -= (int)STRLEN(ml_get(lnum)); | |
4093 } | |
4094 } | |
4095 } | |
4096 | |
4097 error: | |
4098 /* Adjust marks. */ | |
4099 if (y_type == MLINE) | |
4100 { | |
4101 curbuf->b_op_start.col = 0; | |
4102 if (dir == FORWARD) | |
4103 curbuf->b_op_start.lnum++; | |
4104 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4105 /* 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
|
4106 * 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
|
4107 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
|
4108 < 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
|
4109 #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
|
4110 || 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
|
4111 #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
|
4112 ) |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4113 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 4114 (linenr_T)MAXLNUM, nr_lines, 0L); |
4115 | |
4116 /* note changed text for displaying and folding */ | |
4117 if (y_type == MCHAR) | |
4118 changed_lines(curwin->w_cursor.lnum, col, | |
4119 curwin->w_cursor.lnum + 1, nr_lines); | |
4120 else | |
4121 changed_lines(curbuf->b_op_start.lnum, 0, | |
4122 curbuf->b_op_start.lnum, nr_lines); | |
4123 | |
4124 /* put '] mark at last inserted character */ | |
4125 curbuf->b_op_end.lnum = lnum; | |
4126 /* correct length for change in indent */ | |
4127 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
4128 if (col > 1) | |
4129 curbuf->b_op_end.col = col - 1; | |
4130 else | |
4131 curbuf->b_op_end.col = 0; | |
4132 | |
168 | 4133 if (flags & PUT_CURSLINE) |
4134 { | |
237 | 4135 /* ":put": put cursor on last inserted line */ |
168 | 4136 curwin->w_cursor.lnum = lnum; |
4137 beginline(BL_WHITE | BL_FIX); | |
4138 } | |
4139 else if (flags & PUT_CURSEND) | |
7 | 4140 { |
4141 /* put cursor after inserted text */ | |
4142 if (y_type == MLINE) | |
4143 { | |
4144 if (lnum >= curbuf->b_ml.ml_line_count) | |
4145 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4146 else | |
4147 curwin->w_cursor.lnum = lnum + 1; | |
4148 curwin->w_cursor.col = 0; | |
4149 } | |
4150 else | |
4151 { | |
4152 curwin->w_cursor.lnum = lnum; | |
4153 curwin->w_cursor.col = col; | |
4154 } | |
4155 } | |
4156 else if (y_type == MLINE) | |
4157 { | |
168 | 4158 /* put cursor on first non-blank in first inserted line */ |
7 | 4159 curwin->w_cursor.col = 0; |
4160 if (dir == FORWARD) | |
4161 ++curwin->w_cursor.lnum; | |
4162 beginline(BL_WHITE | BL_FIX); | |
4163 } | |
4164 else /* put cursor on first inserted character */ | |
4165 curwin->w_cursor = new_cursor; | |
4166 } | |
4167 } | |
4168 | |
4169 msgmore(nr_lines); | |
4170 curwin->w_set_curswant = TRUE; | |
4171 | |
4172 end: | |
4173 if (allocated) | |
4174 vim_free(insert_string); | |
840 | 4175 if (regname == '=') |
4176 vim_free(y_array); | |
4177 | |
5380 | 4178 VIsual_active = FALSE; |
4179 | |
140 | 4180 /* If the cursor is past the end of the line put it at the end. */ |
844 | 4181 adjust_cursor_eol(); |
4182 } | |
4183 | |
4184 /* | |
4185 * When the cursor is on the NUL past the end of the line and it should not be | |
4186 * there move it left. | |
4187 */ | |
4188 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4189 adjust_cursor_eol(void) |
844 | 4190 { |
4191 if (curwin->w_cursor.col > 0 | |
4192 && gchar_cursor() == NUL | |
773 | 4193 #ifdef FEAT_VIRTUALEDIT |
4194 && (ve_flags & VE_ONEMORE) == 0 | |
4195 #endif | |
7 | 4196 && !(restart_edit || (State & INSERT))) |
4197 { | |
557 | 4198 /* Put the cursor on the last character in the line. */ |
555 | 4199 dec_cursor(); |
844 | 4200 |
7 | 4201 #ifdef FEAT_VIRTUALEDIT |
4202 if (ve_flags == VE_ALL) | |
557 | 4203 { |
4204 colnr_T scol, ecol; | |
4205 | |
4206 /* Coladd is set to the width of the last character. */ | |
4207 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4208 curwin->w_cursor.coladd = ecol - scol + 1; | |
4209 } | |
7 | 4210 #endif |
4211 } | |
4212 } | |
4213 | |
4214 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4215 /* | |
4216 * Return TRUE if lines starting with '#' should be left aligned. | |
4217 */ | |
4218 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4219 preprocs_left(void) |
7 | 4220 { |
4221 return | |
4222 # ifdef FEAT_SMARTINDENT | |
4223 # ifdef FEAT_CINDENT | |
4224 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4225 # else | |
4226 curbuf->b_p_si | |
4227 # endif | |
4228 # endif | |
4229 # ifdef FEAT_CINDENT | |
5438 | 4230 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4231 && curbuf->b_ind_hash_comment == 0) | |
7 | 4232 # endif |
4233 ; | |
4234 } | |
4235 #endif | |
4236 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4237 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4238 * 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
|
4239 */ |
7 | 4240 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4241 get_register_name(int num) |
7 | 4242 { |
4243 if (num == -1) | |
4244 return '"'; | |
4245 else if (num < 10) | |
4246 return num + '0'; | |
4247 else if (num == DELETION_REGISTER) | |
4248 return '-'; | |
4249 #ifdef FEAT_CLIPBOARD | |
4250 else if (num == STAR_REGISTER) | |
4251 return '*'; | |
4252 else if (num == PLUS_REGISTER) | |
4253 return '+'; | |
4254 #endif | |
4255 else | |
4256 { | |
4257 #ifdef EBCDIC | |
4258 int i; | |
4259 | |
4260 /* EBCDIC is really braindead ... */ | |
4261 i = 'a' + (num - 10); | |
4262 if (i > 'i') | |
4263 i += 7; | |
4264 if (i > 'r') | |
4265 i += 8; | |
4266 return i; | |
4267 #else | |
4268 return num + 'a' - 10; | |
4269 #endif | |
4270 } | |
4271 } | |
4272 | |
4273 /* | |
4274 * ":dis" and ":registers": Display the contents of the yank registers. | |
4275 */ | |
4276 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4277 ex_display(exarg_T *eap) |
7 | 4278 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4279 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4280 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4281 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4282 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4283 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4284 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4285 char_u *arg = eap->arg; |
22 | 4286 #ifdef FEAT_MBYTE |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4287 int clen; |
22 | 4288 #else |
4289 # define clen 1 | |
4290 #endif | |
7 | 4291 |
4292 if (arg != NULL && *arg == NUL) | |
4293 arg = NULL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11131
diff
changeset
|
4294 attr = HL_ATTR(HLF_8); |
7 | 4295 |
4296 /* Highlight title */ | |
4297 MSG_PUTS_TITLE(_("\n--- Registers ---")); | |
4298 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) | |
4299 { | |
4300 name = get_register_name(i); | |
2644 | 4301 if (arg != NULL && vim_strchr(arg, name) == NULL |
4302 #ifdef ONE_CLIPBOARD | |
4303 /* Star register and plus register contain the same thing. */ | |
4304 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4305 #endif | |
4306 ) | |
7 | 4307 continue; /* did not ask for this register */ |
4308 | |
4309 #ifdef FEAT_CLIPBOARD | |
4310 /* Adjust register name for "unnamed" in 'clipboard'. | |
4311 * When it's a clipboard register, fill it with the current contents | |
4312 * of the clipboard. */ | |
4313 adjust_clip_reg(&name); | |
4314 (void)may_get_selection(name); | |
4315 #endif | |
4316 | |
4317 if (i == -1) | |
4318 { | |
4319 if (y_previous != NULL) | |
4320 yb = y_previous; | |
4321 else | |
4322 yb = &(y_regs[0]); | |
4323 } | |
4324 else | |
4325 yb = &(y_regs[i]); | |
2000 | 4326 |
4327 #ifdef FEAT_EVAL | |
4328 if (name == MB_TOLOWER(redir_reg) | |
4329 || (redir_reg == '"' && yb == y_previous)) | |
4330 continue; /* do not list register being written to, the | |
4331 * pointer can be freed */ | |
4332 #endif | |
4333 | |
7 | 4334 if (yb->y_array != NULL) |
4335 { | |
4336 msg_putchar('\n'); | |
4337 msg_putchar('"'); | |
4338 msg_putchar(name); | |
4339 MSG_PUTS(" "); | |
4340 | |
4341 n = (int)Columns - 6; | |
4342 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4343 { | |
4344 if (j) | |
4345 { | |
4346 MSG_PUTS_ATTR("^J", attr); | |
4347 n -= 2; | |
4348 } | |
4349 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4350 { | |
4351 #ifdef FEAT_MBYTE | |
474 | 4352 clen = (*mb_ptr2len)(p); |
22 | 4353 #endif |
4354 msg_outtrans_len(p, clen); | |
4355 #ifdef FEAT_MBYTE | |
4356 p += clen - 1; | |
7 | 4357 #endif |
4358 } | |
4359 } | |
4360 if (n > 1 && yb->y_type == MLINE) | |
4361 MSG_PUTS_ATTR("^J", attr); | |
4362 out_flush(); /* show one line at a time */ | |
4363 } | |
4364 ui_breakcheck(); | |
4365 } | |
4366 | |
4367 /* | |
4368 * display last inserted text | |
4369 */ | |
4370 if ((p = get_last_insert()) != NULL | |
4371 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4372 { | |
4373 MSG_PUTS("\n\". "); | |
4374 dis_msg(p, TRUE); | |
4375 } | |
4376 | |
4377 /* | |
4378 * display last command line | |
4379 */ | |
4380 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4381 && !got_int) | |
4382 { | |
4383 MSG_PUTS("\n\": "); | |
4384 dis_msg(last_cmdline, FALSE); | |
4385 } | |
4386 | |
4387 /* | |
4388 * display current file name | |
4389 */ | |
4390 if (curbuf->b_fname != NULL | |
4391 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4392 { | |
4393 MSG_PUTS("\n\"% "); | |
4394 dis_msg(curbuf->b_fname, FALSE); | |
4395 } | |
4396 | |
4397 /* | |
4398 * display alternate file name | |
4399 */ | |
4400 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4401 { | |
4402 char_u *fname; | |
4403 linenr_T dummy; | |
4404 | |
4405 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4406 { | |
4407 MSG_PUTS("\n\"# "); | |
4408 dis_msg(fname, FALSE); | |
4409 } | |
4410 } | |
4411 | |
4412 /* | |
4413 * display last search pattern | |
4414 */ | |
4415 if (last_search_pat() != NULL | |
4416 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4417 { | |
4418 MSG_PUTS("\n\"/ "); | |
4419 dis_msg(last_search_pat(), FALSE); | |
4420 } | |
4421 | |
4422 #ifdef FEAT_EVAL | |
4423 /* | |
4424 * display last used expression | |
4425 */ | |
4426 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4427 && !got_int) | |
4428 { | |
4429 MSG_PUTS("\n\"= "); | |
4430 dis_msg(expr_line, FALSE); | |
4431 } | |
4432 #endif | |
4433 } | |
4434 | |
4435 /* | |
4436 * display a string for do_dis() | |
4437 * truncate at end of screen line | |
4438 */ | |
4439 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4440 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4441 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4442 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4443 { |
4444 int n; | |
4445 #ifdef FEAT_MBYTE | |
4446 int l; | |
4447 #endif | |
4448 | |
4449 n = (int)Columns - 6; | |
4450 while (*p != NUL | |
4451 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4452 && (n -= ptr2cells(p)) >= 0) | |
4453 { | |
4454 #ifdef FEAT_MBYTE | |
474 | 4455 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4456 { |
4457 msg_outtrans_len(p, l); | |
4458 p += l; | |
4459 } | |
4460 else | |
4461 #endif | |
4462 msg_outtrans_len(p++, 1); | |
4463 } | |
4464 ui_breakcheck(); | |
4465 } | |
4466 | |
3562 | 4467 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4468 /* | |
4469 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4470 * after some white space), return a pointer to the text after it. Put a boolean | |
4471 * value indicating whether the line ends with an unclosed comment in | |
4472 * "is_comment". | |
4473 * line - line to be processed, | |
4474 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4475 * comment, |
3562 | 4476 * include_space - whether to also skip space following the comment leader, |
4477 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4478 * comment. |
3562 | 4479 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4480 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4481 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4482 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4483 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4484 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4485 int *is_comment) |
3562 | 4486 { |
4487 char_u *comment_flags = NULL; | |
4488 int lead_len; | |
4489 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4490 | |
4491 *is_comment = FALSE; | |
4492 if (leader_offset != -1) | |
4493 { | |
4494 /* Let's check whether the line ends with an unclosed comment. | |
4495 * If the last comment leader has COM_END in flags, there's no comment. | |
4496 */ | |
4497 while (*comment_flags) | |
4498 { | |
4499 if (*comment_flags == COM_END | |
4500 || *comment_flags == ':') | |
4501 break; | |
4502 ++comment_flags; | |
4503 } | |
4504 if (*comment_flags != COM_END) | |
4505 *is_comment = TRUE; | |
4506 } | |
4507 | |
4508 if (process == FALSE) | |
4509 return line; | |
4510 | |
4511 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4512 | |
4513 if (lead_len == 0) | |
4514 return line; | |
4515 | |
4516 /* Find: | |
4517 * - COM_END, | |
4518 * - colon, | |
4519 * whichever comes first. | |
4520 */ | |
4521 while (*comment_flags) | |
4522 { | |
3580 | 4523 if (*comment_flags == COM_END |
3562 | 4524 || *comment_flags == ':') |
4525 { | |
4526 break; | |
4527 } | |
4528 ++comment_flags; | |
4529 } | |
4530 | |
4531 /* If we found a colon, it means that we are not processing a line | |
3580 | 4532 * starting with a closing part of a three-part comment. That's good, |
4533 * because we don't want to remove those as this would be annoying. | |
3562 | 4534 */ |
4535 if (*comment_flags == ':' || *comment_flags == NUL) | |
4536 line += lead_len; | |
4537 | |
4538 return line; | |
4539 } | |
4540 #endif | |
4541 | |
7 | 4542 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4543 * 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
|
4544 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4545 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4546 * leaders should not be removed. | |
4547 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4548 * to set those marks. | |
7 | 4549 * |
1217 | 4550 * return FAIL for failure, OK otherwise |
7 | 4551 */ |
4552 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4553 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4554 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4555 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4556 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4557 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4558 int setmark) |
7 | 4559 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4560 char_u *curr = NULL; |
2597 | 4561 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
|
4562 char_u *cend; |
7 | 4563 char_u *newp; |
2597 | 4564 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
|
4565 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4566 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4567 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
|
4568 int sumsize = 0; /* size of the long new line */ |
7 | 4569 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4570 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4571 int ret = OK; |
3562 | 4572 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4573 int *comments = NULL; |
3562 | 4574 int remove_comments = (use_formatoptions == TRUE) |
4575 && has_format_option(FO_REMOVE_COMS); | |
4576 int prev_was_comment; | |
4577 #endif | |
4578 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4579 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4580 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
|
4581 (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
|
4582 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4583 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4584 /* 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
|
4585 * 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
|
4586 * 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
|
4587 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
|
4588 if (spaces == NULL) |
7 | 4589 return FAIL; |
3562 | 4590 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4591 if (remove_comments) | |
4592 { | |
4593 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4594 if (comments == NULL) | |
4595 { | |
4596 vim_free(spaces); | |
4597 return FAIL; | |
4598 } | |
4599 } | |
4600 #endif | |
7 | 4601 |
4602 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4603 * 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
|
4604 * and setup the array of space strings lengths |
7 | 4605 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4606 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
|
4607 { |
2597 | 4608 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4609 if (t == 0 && setmark) |
5664 | 4610 { |
4611 /* Set the '[ mark. */ | |
4612 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4613 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4614 } | |
3562 | 4615 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4616 if (remove_comments) | |
4617 { | |
4618 /* We don't want to remove the comment leader if the | |
4619 * previous line is not a comment. */ | |
4620 if (t > 0 && prev_was_comment) | |
4621 { | |
4622 | |
4623 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4624 &prev_was_comment); | |
3576 | 4625 comments[t] = (int)(new_curr - curr); |
3562 | 4626 curr = new_curr; |
4627 } | |
4628 else | |
4629 curr = skip_comment(curr, FALSE, insert_space, | |
4630 &prev_was_comment); | |
4631 } | |
4632 #endif | |
4633 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4634 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
|
4635 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4636 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4637 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
|
4638 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4639 && (!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
|
4640 || (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
|
4641 && (!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
|
4642 || 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
|
4643 #endif |
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 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4646 /* 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
|
4647 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4648 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4649 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4650 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4651 /* 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
|
4652 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4653 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4654 || (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
|
4655 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4656 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4657 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4658 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4659 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4660 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4661 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4662 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
|
4663 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4664 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4665 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4666 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4667 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4668 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
|
4669 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4670 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4671 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4672 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
|
4673 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4674 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4675 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4676 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4677 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4678 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4679 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4680 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4681 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4682 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4683 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4684 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4685 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4686 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4687 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4688 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4689 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4690 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4691 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4692 /* 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
|
4693 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
|
4694 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4695 /* 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
|
4696 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
|
4697 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4698 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4699 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4700 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4701 * 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
|
4702 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4703 * 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
|
4704 * 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
|
4705 * 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
|
4706 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4707 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
|
4708 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4709 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4710 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
|
4711 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4712 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4713 cend -= spaces[t]; |
6929 | 4714 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
|
4715 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4716 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
2597 | 4717 (long)(cend - newp + spaces[t] - (curr - curr_start))); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4718 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4719 break; |
2597 | 4720 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4721 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4722 if (remove_comments) | |
4723 curr += comments[t - 1]; | |
4724 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4725 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
|
4726 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4727 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4728 } |
7 | 4729 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4730 | |
5848 | 4731 if (setmark) |
4732 { | |
4733 /* Set the '] mark. */ | |
4734 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4735 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4736 } | |
5664 | 4737 |
7 | 4738 /* Only report the change in the first line here, del_lines() will report |
4739 * the deleted line. */ | |
4740 changed_lines(curwin->w_cursor.lnum, currsize, | |
4741 curwin->w_cursor.lnum + 1, 0L); | |
4742 | |
4743 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4744 * Delete following lines. To do this we move the cursor there |
7 | 4745 * briefly, and then move it back. After del_lines() the cursor may |
4746 * have moved up (last line deleted), so the current lnum is kept in t. | |
4747 */ | |
4748 t = curwin->w_cursor.lnum; | |
4749 ++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
|
4750 del_lines(count - 1, FALSE); |
7 | 4751 curwin->w_cursor.lnum = t; |
4752 | |
4753 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4754 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4755 * 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
|
4756 * vim: use the column of the last join |
7 | 4757 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4758 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4759 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4760 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4761 |
7 | 4762 #ifdef FEAT_VIRTUALEDIT |
4763 curwin->w_cursor.coladd = 0; | |
4764 #endif | |
4765 curwin->w_set_curswant = TRUE; | |
4766 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4767 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4768 vim_free(spaces); |
3562 | 4769 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4770 if (remove_comments) | |
4771 vim_free(comments); | |
4772 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4773 return ret; |
7 | 4774 } |
4775 | |
4776 #ifdef FEAT_COMMENTS | |
4777 /* | |
4778 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4779 * the first line. White-space is ignored. Note that the whole of | |
4780 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4781 */ | |
4782 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4783 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4784 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4785 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4786 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4787 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4788 char_u *leader2_flags) |
7 | 4789 { |
4790 int idx1 = 0, idx2 = 0; | |
4791 char_u *p; | |
4792 char_u *line1; | |
4793 char_u *line2; | |
4794 | |
4795 if (leader1_len == 0) | |
4796 return (leader2_len == 0); | |
4797 | |
4798 /* | |
4799 * If first leader has 'f' flag, the lines can be joined only if the | |
4800 * second line does not have a leader. | |
4801 * If first leader has 'e' flag, the lines can never be joined. | |
4802 * If fist leader has 's' flag, the lines can only be joined if there is | |
4803 * some text after it and the second line has the 'm' flag. | |
4804 */ | |
4805 if (leader1_flags != NULL) | |
4806 { | |
4807 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4808 { | |
4809 if (*p == COM_FIRST) | |
4810 return (leader2_len == 0); | |
4811 if (*p == COM_END) | |
4812 return FALSE; | |
4813 if (*p == COM_START) | |
4814 { | |
4815 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4816 return FALSE; | |
4817 if (leader2_flags == NULL || leader2_len == 0) | |
4818 return FALSE; | |
4819 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4820 if (*p == COM_MIDDLE) | |
4821 return TRUE; | |
4822 return FALSE; | |
4823 } | |
4824 } | |
4825 } | |
4826 | |
4827 /* | |
4828 * Get current line and next line, compare the leaders. | |
4829 * The first line has to be saved, only one line can be locked at a time. | |
4830 */ | |
4831 line1 = vim_strsave(ml_get(lnum)); | |
4832 if (line1 != NULL) | |
4833 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4834 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 4835 ; |
4836 line2 = ml_get(lnum + 1); | |
4837 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4838 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4839 if (!VIM_ISWHITE(line2[idx2])) |
7 | 4840 { |
4841 if (line1[idx1++] != line2[idx2]) | |
4842 break; | |
4843 } | |
4844 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4845 while (VIM_ISWHITE(line1[idx1])) |
7 | 4846 ++idx1; |
4847 } | |
4848 vim_free(line1); | |
4849 } | |
4850 return (idx2 == leader2_len && idx1 == leader1_len); | |
4851 } | |
4852 #endif | |
4853 | |
4854 /* | |
3252 | 4855 * Implementation of the format operator 'gq'. |
7 | 4856 */ |
4857 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4858 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4859 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4860 int keep_cursor) /* keep cursor on same text char */ |
7 | 4861 { |
4862 long old_line_count = curbuf->b_ml.ml_line_count; | |
4863 | |
4864 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4865 * can put it back there. */ | |
4866 curwin->w_cursor = oap->cursor_start; | |
4867 | |
4868 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4869 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4870 return; | |
4871 curwin->w_cursor = oap->start; | |
4872 | |
4873 if (oap->is_VIsual) | |
4874 /* When there is no change: need to remove the Visual selection */ | |
4875 redraw_curbuf_later(INVERTED); | |
4876 | |
4877 /* Set '[ mark at the start of the formatted area */ | |
4878 curbuf->b_op_start = oap->start; | |
4879 | |
4880 /* For "gw" remember the cursor position and put it back below (adjusted | |
4881 * for joined and split lines). */ | |
4882 if (keep_cursor) | |
4883 saved_cursor = oap->cursor_start; | |
4884 | |
1563 | 4885 format_lines(oap->line_count, keep_cursor); |
7 | 4886 |
4887 /* | |
4888 * Leave the cursor at the first non-blank of the last formatted line. | |
4889 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4890 * line, so "." will do the next lines. | |
4891 */ | |
4892 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4893 ++curwin->w_cursor.lnum; | |
4894 beginline(BL_WHITE | BL_FIX); | |
4895 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4896 msgmore(old_line_count); | |
4897 | |
4898 /* put '] mark on the end of the formatted area */ | |
4899 curbuf->b_op_end = curwin->w_cursor; | |
4900 | |
4901 if (keep_cursor) | |
4902 { | |
4903 curwin->w_cursor = saved_cursor; | |
4904 saved_cursor.lnum = 0; | |
4905 } | |
4906 | |
4907 if (oap->is_VIsual) | |
4908 { | |
4909 win_T *wp; | |
4910 | |
4911 FOR_ALL_WINDOWS(wp) | |
4912 { | |
4913 if (wp->w_old_cursor_lnum != 0) | |
4914 { | |
4915 /* When lines have been inserted or deleted, adjust the end of | |
4916 * the Visual area to be redrawn. */ | |
4917 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4918 wp->w_old_cursor_lnum += old_line_count; | |
4919 else | |
4920 wp->w_old_visual_lnum += old_line_count; | |
4921 } | |
4922 } | |
4923 } | |
4924 } | |
4925 | |
667 | 4926 #if defined(FEAT_EVAL) || defined(PROTO) |
4927 /* | |
4928 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4929 */ | |
4930 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4931 op_formatexpr(oparg_T *oap) |
667 | 4932 { |
4933 if (oap->is_VIsual) | |
4934 /* When there is no change: need to remove the Visual selection */ | |
4935 redraw_curbuf_later(INVERTED); | |
4936 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4937 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
|
4938 /* 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
|
4939 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4940 op_format(oap, FALSE); |
667 | 4941 } |
4942 | |
4943 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4944 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4945 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4946 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4947 int c) /* character to be inserted */ |
667 | 4948 { |
681 | 4949 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4950 OPT_LOCAL); | |
667 | 4951 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4952 char_u *fex; |
667 | 4953 |
4954 /* | |
4955 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4956 * Set v:char to the character to be inserted (can be NUL). |
667 | 4957 */ |
4958 set_vim_var_nr(VV_LNUM, lnum); | |
4959 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4960 set_vim_var_char(c); |
844 | 4961 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4962 /* 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
|
4963 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
|
4964 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4965 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4966 |
667 | 4967 /* |
4968 * Evaluate the function. | |
4969 */ | |
4970 if (use_sandbox) | |
4971 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4972 r = (int)eval_to_number(fex); |
667 | 4973 if (use_sandbox) |
4974 --sandbox; | |
844 | 4975 |
4976 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
|
4977 vim_free(fex); |
844 | 4978 |
667 | 4979 return r; |
4980 } | |
4981 #endif | |
4982 | |
7 | 4983 /* |
4984 * Format "line_count" lines, starting at the cursor position. | |
4985 * When "line_count" is negative, format until the end of the paragraph. | |
4986 * Lines after the cursor line are saved for undo, caller must have saved the | |
4987 * first line. | |
4988 */ | |
4989 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4990 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4991 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4992 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4993 { |
4994 int max_len; | |
4995 int is_not_par; /* current line not part of parag. */ | |
4996 int next_is_not_par; /* next line not part of paragraph */ | |
4997 int is_end_par; /* at end of paragraph */ | |
4998 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4999 int next_is_start_par = FALSE; | |
5000 #ifdef FEAT_COMMENTS | |
5001 int leader_len = 0; /* leader len of current line */ | |
5002 int next_leader_len; /* leader len of next line */ | |
5003 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5004 char_u *next_leader_flags; /* flags for leader of next line */ | |
5005 int do_comments; /* format comments */ | |
3584 | 5006 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 5007 #endif |
5008 int advance = TRUE; | |
3584 | 5009 int second_indent = -1; /* indent for second line (comment |
5010 * aware) */ | |
7 | 5011 int do_second_indent; |
5012 int do_number_indent; | |
5013 int do_trail_white; | |
5014 int first_par_line = TRUE; | |
5015 int smd_save; | |
5016 long count; | |
5017 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
5018 int force_format = FALSE; | |
5019 int old_State = State; | |
5020 | |
5021 /* length of a line to force formatting: 3 * 'tw' */ | |
5022 max_len = comp_textwidth(TRUE) * 3; | |
5023 | |
5024 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
5025 #ifdef FEAT_COMMENTS | |
5026 do_comments = has_format_option(FO_Q_COMS); | |
5027 #endif | |
5028 do_second_indent = has_format_option(FO_Q_SECOND); | |
5029 do_number_indent = has_format_option(FO_Q_NUMBER); | |
5030 do_trail_white = has_format_option(FO_WHITE_PAR); | |
5031 | |
5032 /* | |
5033 * Get info about the previous and current line. | |
5034 */ | |
5035 if (curwin->w_cursor.lnum > 1) | |
5036 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
5037 #ifdef FEAT_COMMENTS | |
5038 , &leader_len, &leader_flags, do_comments | |
5039 #endif | |
5040 ); | |
5041 else | |
5042 is_not_par = TRUE; | |
5043 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
5044 #ifdef FEAT_COMMENTS | |
5045 , &next_leader_len, &next_leader_flags, do_comments | |
5046 #endif | |
5047 ); | |
5048 is_end_par = (is_not_par || next_is_not_par); | |
5049 if (!is_end_par && do_trail_white) | |
5050 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
5051 | |
5052 curwin->w_cursor.lnum--; | |
5053 for (count = line_count; count != 0 && !got_int; --count) | |
5054 { | |
5055 /* | |
5056 * Advance to next paragraph. | |
5057 */ | |
5058 if (advance) | |
5059 { | |
5060 curwin->w_cursor.lnum++; | |
5061 prev_is_end_par = is_end_par; | |
5062 is_not_par = next_is_not_par; | |
5063 #ifdef FEAT_COMMENTS | |
5064 leader_len = next_leader_len; | |
5065 leader_flags = next_leader_flags; | |
5066 #endif | |
5067 } | |
5068 | |
5069 /* | |
5070 * The last line to be formatted. | |
5071 */ | |
5072 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
5073 { | |
5074 next_is_not_par = TRUE; | |
5075 #ifdef FEAT_COMMENTS | |
5076 next_leader_len = 0; | |
5077 next_leader_flags = NULL; | |
5078 #endif | |
5079 } | |
5080 else | |
5081 { | |
5082 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
5083 #ifdef FEAT_COMMENTS | |
5084 , &next_leader_len, &next_leader_flags, do_comments | |
5085 #endif | |
5086 ); | |
5087 if (do_number_indent) | |
5088 next_is_start_par = | |
5089 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
5090 } | |
5091 advance = TRUE; | |
5092 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
5093 if (!is_end_par && do_trail_white) | |
5094 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
5095 | |
5096 /* | |
5097 * Skip lines that are not in a paragraph. | |
5098 */ | |
5099 if (is_not_par) | |
5100 { | |
5101 if (line_count < 0) | |
5102 break; | |
5103 } | |
5104 else | |
5105 { | |
5106 /* | |
5107 * For the first line of a paragraph, check indent of second line. | |
5108 * Don't do this for comments and empty lines. | |
5109 */ | |
5110 if (first_par_line | |
5111 && (do_second_indent || do_number_indent) | |
5112 && prev_is_end_par | |
3584 | 5113 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
5114 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
5115 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 5116 { |
5117 #ifdef FEAT_COMMENTS | |
5118 if (leader_len == 0 && next_leader_len == 0) | |
5119 { | |
5120 /* no comment found */ | |
5121 #endif | |
5122 second_indent = | |
5123 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 5124 #ifdef FEAT_COMMENTS |
3584 | 5125 } |
5126 else | |
5127 { | |
5128 second_indent = next_leader_len; | |
5129 do_comments_list = 1; | |
5130 } | |
5131 #endif | |
5132 } | |
7 | 5133 else if (do_number_indent) |
3584 | 5134 { |
5135 #ifdef FEAT_COMMENTS | |
5136 if (leader_len == 0 && next_leader_len == 0) | |
5137 { | |
5138 /* no comment found */ | |
5139 #endif | |
5140 second_indent = | |
5141 get_number_indent(curwin->w_cursor.lnum); | |
5142 #ifdef FEAT_COMMENTS | |
5143 } | |
5144 else | |
5145 { | |
5146 /* get_number_indent() is now "comment aware"... */ | |
5147 second_indent = | |
5148 get_number_indent(curwin->w_cursor.lnum); | |
5149 do_comments_list = 1; | |
5150 } | |
5151 #endif | |
5152 } | |
7 | 5153 } |
5154 | |
5155 /* | |
5156 * When the comment leader changes, it's the end of the paragraph. | |
5157 */ | |
5158 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
5159 #ifdef FEAT_COMMENTS | |
5160 || !same_leader(curwin->w_cursor.lnum, | |
5161 leader_len, leader_flags, | |
5162 next_leader_len, next_leader_flags) | |
5163 #endif | |
5164 ) | |
5165 is_end_par = TRUE; | |
5166 | |
5167 /* | |
5168 * If we have got to the end of a paragraph, or the line is | |
5169 * getting long, format it. | |
5170 */ | |
5171 if (is_end_par || force_format) | |
5172 { | |
5173 if (need_set_indent) | |
5174 /* replace indent in first line with minimal number of | |
5175 * tabs and spaces, according to current options */ | |
5176 (void)set_indent(get_indent(), SIN_CHANGED); | |
5177 | |
5178 /* put cursor on last non-space */ | |
5179 State = NORMAL; /* don't go past end-of-line */ | |
5180 coladvance((colnr_T)MAXCOL); | |
5181 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
5182 dec_cursor(); | |
5183 | |
5184 /* do the formatting, without 'showmode' */ | |
5185 State = INSERT; /* for open_line() */ | |
5186 smd_save = p_smd; | |
5187 p_smd = FALSE; | |
5188 insertchar(NUL, INSCHAR_FORMAT | |
5189 #ifdef FEAT_COMMENTS | |
5190 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 5191 + (do_comments && do_comments_list |
5192 ? INSCHAR_COM_LIST : 0) | |
7 | 5193 #endif |
1563 | 5194 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 5195 State = old_State; |
5196 p_smd = smd_save; | |
5197 second_indent = -1; | |
5198 /* at end of par.: need to set indent of next par. */ | |
5199 need_set_indent = is_end_par; | |
5200 if (is_end_par) | |
5201 { | |
5202 /* When called with a negative line count, break at the | |
5203 * end of the paragraph. */ | |
5204 if (line_count < 0) | |
5205 break; | |
5206 first_par_line = TRUE; | |
5207 } | |
5208 force_format = FALSE; | |
5209 } | |
5210 | |
5211 /* | |
5212 * When still in same paragraph, join the lines together. But | |
5403 | 5213 * first delete the leader from the second line. |
7 | 5214 */ |
5215 if (!is_end_par) | |
5216 { | |
5217 advance = FALSE; | |
5218 curwin->w_cursor.lnum++; | |
5219 curwin->w_cursor.col = 0; | |
5220 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
|
5221 break; |
7 | 5222 #ifdef FEAT_COMMENTS |
5223 if (next_leader_len > 0) | |
5403 | 5224 { |
5225 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5226 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
5227 (long)-next_leader_len); | |
5403 | 5228 } else |
5229 #endif | |
5230 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5231 { | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
5232 int indent = getwhitecols_curline(); |
5403 | 5233 |
5234 if (indent > 0) | |
5235 { | |
5236 (void)del_bytes(indent, FALSE, FALSE); | |
5237 mark_col_adjust(curwin->w_cursor.lnum, | |
5238 (colnr_T)0, 0L, (long)-indent); | |
5415 | 5239 } |
5403 | 5240 } |
7 | 5241 curwin->w_cursor.lnum--; |
5848 | 5242 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5243 { |
5244 beep_flush(); | |
5245 break; | |
5246 } | |
5247 first_par_line = FALSE; | |
5248 /* If the line is getting long, format it next time */ | |
5249 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5250 force_format = TRUE; | |
5251 else | |
5252 force_format = FALSE; | |
5253 } | |
5254 } | |
5255 line_breakcheck(); | |
5256 } | |
5257 } | |
5258 | |
5259 /* | |
5260 * Return TRUE if line "lnum" ends in a white character. | |
5261 */ | |
5262 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5263 ends_in_white(linenr_T lnum) |
7 | 5264 { |
5265 char_u *s = ml_get(lnum); | |
5266 size_t l; | |
5267 | |
5268 if (*s == NUL) | |
5269 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5270 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 5271 * invocation may call function multiple times". */ |
5272 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
|
5273 return VIM_ISWHITE(s[l]); |
7 | 5274 } |
5275 | |
5276 /* | |
5277 * Blank lines, and lines containing only the comment leader, are left | |
5278 * untouched by the formatting. The function returns TRUE in this | |
5279 * case. It also returns TRUE when a line starts with the end of a comment | |
5280 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5281 * previous line. A new paragraph starts after a blank line, or when the | |
5282 * comment leader changes -- webb. | |
5283 */ | |
5284 #ifdef FEAT_COMMENTS | |
5285 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5286 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5287 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5288 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5289 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5290 int do_comments) |
7 | 5291 { |
5292 char_u *flags = NULL; /* init for GCC */ | |
5293 char_u *ptr; | |
5294 | |
5295 ptr = ml_get(lnum); | |
5296 if (do_comments) | |
3562 | 5297 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5298 else |
5299 *leader_len = 0; | |
5300 | |
5301 if (*leader_len > 0) | |
5302 { | |
5303 /* | |
5304 * Search for 'e' flag in comment leader flags. | |
5305 */ | |
5306 flags = *leader_flags; | |
5307 while (*flags && *flags != ':' && *flags != COM_END) | |
5308 ++flags; | |
5309 } | |
5310 | |
5311 return (*skipwhite(ptr + *leader_len) == NUL | |
5312 || (*leader_len > 0 && *flags == COM_END) | |
5313 || startPS(lnum, NUL, FALSE)); | |
5314 } | |
5315 #else | |
5316 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5317 fmt_check_par(linenr_T lnum) |
7 | 5318 { |
5319 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5320 } | |
5321 #endif | |
5322 | |
5323 /* | |
5324 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5325 * previous line is in the same paragraph. Used for auto-formatting. | |
5326 */ | |
5327 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5328 paragraph_start(linenr_T lnum) |
7 | 5329 { |
5330 char_u *p; | |
5331 #ifdef FEAT_COMMENTS | |
5332 int leader_len = 0; /* leader len of current line */ | |
5333 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5334 int next_leader_len; /* leader len of next line */ | |
5335 char_u *next_leader_flags; /* flags for leader of next line */ | |
5336 int do_comments; /* format comments */ | |
5337 #endif | |
5338 | |
5339 if (lnum <= 1) | |
5340 return TRUE; /* start of the file */ | |
5341 | |
5342 p = ml_get(lnum - 1); | |
5343 if (*p == NUL) | |
5344 return TRUE; /* after empty line */ | |
5345 | |
5346 #ifdef FEAT_COMMENTS | |
5347 do_comments = has_format_option(FO_Q_COMS); | |
5348 #endif | |
5349 if (fmt_check_par(lnum - 1 | |
5350 #ifdef FEAT_COMMENTS | |
5351 , &leader_len, &leader_flags, do_comments | |
5352 #endif | |
5353 )) | |
5354 return TRUE; /* after non-paragraph line */ | |
5355 | |
5356 if (fmt_check_par(lnum | |
5357 #ifdef FEAT_COMMENTS | |
5358 , &next_leader_len, &next_leader_flags, do_comments | |
5359 #endif | |
5360 )) | |
5361 return TRUE; /* "lnum" is not a paragraph line */ | |
5362 | |
5363 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5364 return TRUE; /* missing trailing space in previous line. */ | |
5365 | |
5366 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5367 return TRUE; /* numbered item starts in "lnum". */ | |
5368 | |
5369 #ifdef FEAT_COMMENTS | |
5370 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5371 next_leader_len, next_leader_flags)) | |
5372 return TRUE; /* change of comment leader. */ | |
5373 #endif | |
5374 | |
5375 return FALSE; | |
5376 } | |
5377 | |
5378 /* | |
5379 * prepare a few things for block mode yank/delete/tilde | |
5380 * | |
5381 * for delete: | |
5382 * - textlen includes the first/last char to be (partly) deleted | |
5383 * - start/endspaces is the number of columns that are taken by the | |
5384 * first/last deleted char minus the number of columns that have to be | |
1839 | 5385 * deleted. |
5386 * for yank and tilde: | |
7 | 5387 * - textlen includes the first/last char to be wholly yanked |
5388 * - start/endspaces is the number of columns of the first/last yanked char | |
5389 * that are to be yanked. | |
5390 */ | |
5391 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5392 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5393 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5394 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5395 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5396 int is_del) |
7 | 5397 { |
5398 int incr = 0; | |
5399 char_u *pend; | |
5400 char_u *pstart; | |
5401 char_u *line; | |
5402 char_u *prev_pstart; | |
5403 char_u *prev_pend; | |
5404 | |
5405 bdp->startspaces = 0; | |
5406 bdp->endspaces = 0; | |
5407 bdp->textlen = 0; | |
5408 bdp->start_vcol = 0; | |
5409 bdp->end_vcol = 0; | |
5410 #ifdef FEAT_VISUALEXTRA | |
5411 bdp->is_short = FALSE; | |
5412 bdp->is_oneChar = FALSE; | |
5413 bdp->pre_whitesp = 0; | |
5414 bdp->pre_whitesp_c = 0; | |
5415 bdp->end_char_vcols = 0; | |
5416 #endif | |
5417 bdp->start_char_vcols = 0; | |
5418 | |
5419 line = ml_get(lnum); | |
5420 pstart = line; | |
5421 prev_pstart = line; | |
5422 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5423 { | |
5424 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5425 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5426 bdp->start_vcol += incr; |
5427 #ifdef FEAT_VISUALEXTRA | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5428 if (VIM_ISWHITE(*pstart)) |
7 | 5429 { |
5430 bdp->pre_whitesp += incr; | |
5431 bdp->pre_whitesp_c++; | |
5432 } | |
5433 else | |
5434 { | |
5435 bdp->pre_whitesp = 0; | |
5436 bdp->pre_whitesp_c = 0; | |
5437 } | |
5438 #endif | |
5439 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5440 MB_PTR_ADV(pstart); |
7 | 5441 } |
5442 bdp->start_char_vcols = incr; | |
5443 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5444 { | |
5445 bdp->end_vcol = bdp->start_vcol; | |
5446 #ifdef FEAT_VISUALEXTRA | |
5447 bdp->is_short = TRUE; | |
5448 #endif | |
5449 if (!is_del || oap->op_type == OP_APPEND) | |
5450 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5451 } | |
5452 else | |
5453 { | |
5454 /* notice: this converts partly selected Multibyte characters to | |
5455 * spaces, too. */ | |
5456 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5457 if (is_del && bdp->startspaces) | |
5458 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5459 pend = pstart; | |
5460 bdp->end_vcol = bdp->start_vcol; | |
5461 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5462 { | |
5463 #ifdef FEAT_VISUALEXTRA | |
5464 bdp->is_oneChar = TRUE; | |
5465 #endif | |
5466 if (oap->op_type == OP_INSERT) | |
5467 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5468 else if (oap->op_type == OP_APPEND) | |
5469 { | |
5470 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5471 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5472 } | |
5473 else | |
5474 { | |
5475 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5476 if (is_del && oap->op_type != OP_LSHIFT) | |
5477 { | |
5478 /* just putting the sum of those two into | |
5479 * bdp->startspaces doesn't work for Visual replace, | |
5480 * so we have to split the tab in two */ | |
5481 bdp->startspaces = bdp->start_char_vcols | |
5482 - (bdp->start_vcol - oap->start_vcol); | |
5483 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5484 } | |
5485 } | |
5486 } | |
5487 else | |
5488 { | |
5489 prev_pend = pend; | |
5490 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5491 { | |
5492 /* Count a tab for what it's worth (if list mode not on) */ | |
5493 prev_pend = pend; | |
6535 | 5494 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5495 bdp->end_vcol += incr; |
5496 } | |
5497 if (bdp->end_vcol <= oap->end_vcol | |
5498 && (!is_del | |
5499 || oap->op_type == OP_APPEND | |
5500 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5501 { | |
5502 #ifdef FEAT_VISUALEXTRA | |
5503 bdp->is_short = TRUE; | |
5504 #endif | |
5505 /* Alternative: include spaces to fill up the block. | |
5506 * Disadvantage: can lead to trailing spaces when the line is | |
5507 * short where the text is put */ | |
5508 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5509 if (oap->op_type == OP_APPEND || virtual_op) | |
5510 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5511 + oap->inclusive; |
7 | 5512 else |
5513 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5514 } | |
5515 else if (bdp->end_vcol > oap->end_vcol) | |
5516 { | |
5517 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5518 if (!is_del && bdp->endspaces) | |
5519 { | |
5520 bdp->endspaces = incr - bdp->endspaces; | |
5521 if (pend != pstart) | |
5522 pend = prev_pend; | |
5523 } | |
5524 } | |
5525 } | |
5526 #ifdef FEAT_VISUALEXTRA | |
5527 bdp->end_char_vcols = incr; | |
5528 #endif | |
5529 if (is_del && bdp->startspaces) | |
5530 pstart = prev_pstart; | |
5531 bdp->textlen = (int)(pend - pstart); | |
5532 } | |
5533 bdp->textcol = (colnr_T) (pstart - line); | |
5534 bdp->textstart = pstart; | |
5535 } | |
5536 | |
5537 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5538 * Handle the add/subtract operator. |
7 | 5539 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5540 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5541 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5542 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5543 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
|
5544 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
|
5545 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5546 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5547 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5548 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5549 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5550 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5551 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5552 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5553 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5554 if (u_save_cursor() == FAIL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5555 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5556 change_cnt = do_addsub(oap->op_type, &pos, 0, amount); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5557 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5558 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
|
5559 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5560 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5561 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5562 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5563 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5564 pos_T startpos; |
7574
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 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
|
5567 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5568 return; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5569 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5570 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5571 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
|
5572 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5573 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
|
5574 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5575 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
|
5576 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5577 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5578 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5579 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
|
5580 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5581 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5582 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5583 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
|
5584 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5585 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5586 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
5587 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
|
5588 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5589 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
|
5590 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5591 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
|
5592 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5593 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5594 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5595 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5596 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5597 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5598 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
|
5599 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5600 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5601 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
|
5602 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5603 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5604 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
|
5605 if (one_change) |
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 /* 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
|
5608 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5609 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5610 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5611 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5612 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5613 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5614 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5615 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5616 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
|
5617 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5618 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
|
5619 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
|
5620 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5621 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5622 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5623 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5624 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5625 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5626 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5627 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
|
5628 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5629 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5630 /* 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
|
5631 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5632 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5633 /* 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
|
5634 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5635 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5636 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5637 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5638 if (change_cnt > p_report) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5639 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5640 if (change_cnt == 1) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5641 MSG(_("1 line changed")); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5642 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5643 smsg((char_u *)_("%ld lines changed"), change_cnt); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5644 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5645 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5646 } |
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 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5649 * 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
|
5650 * 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
|
5651 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5652 * 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
|
5653 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5654 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5655 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5656 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5657 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5658 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5659 linenr_T Prenum1) |
7 | 5660 { |
5661 int col; | |
5662 char_u *buf1; | |
5663 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5664 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5665 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5666 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5667 uvarnumber_T oldn; |
7 | 5668 char_u *ptr; |
5669 int c; | |
5670 int todel; | |
5671 int dohex; | |
5672 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5673 int dobin; |
7 | 5674 int doalp; |
5675 int firstdigit; | |
5676 int subtract; | |
6868 | 5677 int negative = FALSE; |
6891 | 5678 int was_positive = TRUE; |
6868 | 5679 int visual = VIsual_active; |
6921 | 5680 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5681 pos_T save_cursor = curwin->w_cursor; |
6927 | 5682 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5683 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5684 pos_T endpos; |
7 | 5685 |
5686 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5687 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
|
5688 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5689 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5690 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5691 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5692 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5693 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5694 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5695 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5696 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5697 |
7 | 5698 /* |
5699 * First check if we are on a hexadecimal number, after the "0x". | |
5700 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5701 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5702 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5703 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5704 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
|
5705 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5706 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5707 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5708 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5709 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
|
5710 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5711 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5712 |
6868 | 5713 if (dohex) |
5714 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
|
5715 { |
6868 | 5716 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5717 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5718 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5719 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
|
5720 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5721 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5722 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5723 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5724 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5725 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5726 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5727 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5728 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5729 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5730 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5731 !(*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
|
5732 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5733 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5734 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5735 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5736 /* 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
|
5737 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5738 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5739 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5740 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
|
5741 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5742 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5743 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5744 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5745 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
|
5746 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5747 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5748 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5749 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5750 if (( dohex |
6868 | 5751 && col > 0 |
5752 && (ptr[col] == 'X' | |
5753 || ptr[col] == 'x') | |
5754 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5755 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5756 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5757 !(*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
|
5758 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5759 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5760 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5761 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5762 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5763 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5764 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5765 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5766 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5767 !(*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
|
5768 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5769 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5770 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5771 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5772 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5773 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5774 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5775 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
|
5776 #endif |
6868 | 5777 } |
5778 else | |
7 | 5779 { |
6868 | 5780 /* |
5781 * Search forward and then backward to find the start of number. | |
5782 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5783 col = pos->col; |
6868 | 5784 |
5785 while (ptr[col] != NUL | |
5786 && !vim_isdigit(ptr[col]) | |
5787 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5788 col += MB_PTR2LEN(ptr + col); |
6868 | 5789 |
5790 while (col > 0 | |
5791 && vim_isdigit(ptr[col - 1]) | |
5792 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5793 { |
6868 | 5794 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5795 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5796 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5797 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
|
5798 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5799 } |
6868 | 5800 } |
5801 } | |
5802 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5803 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5804 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5805 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5806 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5807 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5808 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5809 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
|
5810 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5811 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5812 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5813 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5814 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5816 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5818 if (col > pos->col && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5819 #ifdef FEAT_MBYTE |
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 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5823 ) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5824 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5825 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5826 was_positive = FALSE; |
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 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5829 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5830 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5831 * 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
|
5832 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5833 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5834 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
|
5835 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5836 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5837 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5838 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5839 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5840 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5841 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5842 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5843 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5844 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5845 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5846 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5847 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5848 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5849 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5850 firstdigit = 'a'; |
6927 | 5851 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5852 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5853 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5854 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5855 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5856 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5857 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5858 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5859 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5861 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5862 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5863 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5864 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5865 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5866 firstdigit = 'z'; |
6927 | 5867 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5868 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5869 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5870 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5871 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5872 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5873 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5874 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5875 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5876 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5877 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5878 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5879 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5880 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5881 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5882 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5883 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5884 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5885 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5886 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5887 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5888 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5889 !(*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
|
5890 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5891 && !visual) |
7574
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 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5894 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5895 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5896 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5897 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5898 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5899 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
|
5900 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5901 : length); |
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 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5904 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5905 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5906 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5907 NULL, &n, maxlen); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5908 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5909 /* 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
|
5910 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5911 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5912 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5913 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5914 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5915 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5916 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5917 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5918 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5919 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5920 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5921 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5922 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5923 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5924 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5925 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5926 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5927 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5928 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5929 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5930 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5931 if (subtract) |
6927 | 5932 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5933 if (n > oldn) |
6868 | 5934 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5935 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
|
5936 negative ^= TRUE; |
6868 | 5937 } |
7 | 5938 } |
5939 else | |
6868 | 5940 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5941 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5942 if (n < oldn) |
6868 | 5943 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5944 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5945 negative ^= TRUE; |
6868 | 5946 } |
6927 | 5947 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5948 if (n == 0) |
6868 | 5949 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5950 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5951 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5952 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
|
5953 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5954 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5955 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5956 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5957 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5958 |
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 * Delete the old number. |
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 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5963 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5964 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5965 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5966 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5967 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5968 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5969 * 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
|
5970 * 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
|
5971 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5972 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5973 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5974 while (todel-- > 0) |
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 if (c < 0x100 && isalpha(c)) |
6868 | 5977 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5978 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5979 hexupper = TRUE; |
6868 | 5980 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5981 hexupper = FALSE; |
6891 | 5982 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5983 /* 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
|
5984 (void)del_char(FALSE); |
6868 | 5985 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5986 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5987 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5988 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5989 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5990 * 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
|
5991 * Allocate a bit too much. |
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 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5994 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5995 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5996 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
5997 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5998 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5999 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6000 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6001 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6002 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6003 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6004 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6005 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6006 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6007 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6008 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6009 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6010 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6011 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6012 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6013 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6014 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6015 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6016 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6017 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6018 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6019 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6020 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
|
6021 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6022 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6023 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6024 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6025 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6026 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6027 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
|
6028 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6029 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6030 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6031 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
|
6032 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
6033 (long long unsigned)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6034 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
|
6035 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
6036 (long long unsigned)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6037 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
|
6038 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
6039 (long long unsigned)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6040 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
|
6041 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
6042 (long long unsigned)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6043 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6044 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6045 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6046 * 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
|
6047 * 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
|
6048 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6049 * 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
|
6050 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6051 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6052 while (length-- > 0) |
6868 | 6053 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6054 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6055 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6056 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
|
6057 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6058 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6059 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
|
6060 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6061 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6062 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6063 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6064 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6065 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6066 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6067 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6068 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
|
6069 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6070 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6071 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6072 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6073 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6074 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6075 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6076 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6077 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6078 return did_change; |
7 | 6079 } |
6080 | |
6081 #ifdef FEAT_VIMINFO | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6082 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6083 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
|
6084 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6085 #define REG_PREVIOUS 1 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6086 #define REG_EXEC 2 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6087 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6088 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6089 * 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
|
6090 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6091 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6092 prepare_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6093 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6094 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
|
6095 * (int)sizeof(yankreg_T)); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6096 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6097 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6098 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6099 finish_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6100 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6101 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6102 int j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6103 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6104 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6105 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6106 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
|
6107 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
|
6108 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6109 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
|
6110 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
|
6111 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
|
6112 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
6113 VIM_CLEAR(y_read_regs); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6114 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6115 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6116 |
7 | 6117 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6118 read_viminfo_register(vir_T *virp, int force) |
7 | 6119 { |
6120 int eof; | |
6121 int do_it = TRUE; | |
6122 int size; | |
6123 int limit; | |
6124 int i; | |
6125 int set_prev = FALSE; | |
6126 char_u *str; | |
6127 char_u **array = NULL; | |
6508 | 6128 int new_type = MCHAR; /* init to shut up compiler */ |
6129 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 6130 |
6131 /* We only get here (hopefully) if line[0] == '"' */ | |
6132 str = virp->vir_line + 1; | |
1893 | 6133 |
6134 /* If the line starts with "" this is the y_previous register. */ | |
7 | 6135 if (*str == '"') |
6136 { | |
6137 set_prev = TRUE; | |
6138 str++; | |
6139 } | |
1893 | 6140 |
7 | 6141 if (!ASCII_ISALNUM(*str) && *str != '-') |
6142 { | |
6143 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
6144 return TRUE; /* too many errors, pretend end-of-file */ | |
6145 do_it = FALSE; | |
6146 } | |
6147 get_yank_register(*str++, FALSE); | |
6148 if (!force && y_current->y_array != NULL) | |
6149 do_it = FALSE; | |
1893 | 6150 |
6151 if (*str == '@') | |
6152 { | |
6153 /* "x@: register x used for @@ */ | |
6154 if (force || execreg_lastc == NUL) | |
6155 execreg_lastc = str[-1]; | |
6156 } | |
6157 | |
7 | 6158 size = 0; |
6159 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
6160 if (do_it) | |
6161 { | |
6462 | 6162 /* |
6163 * Build the new register in array[]. | |
6164 * y_array is kept as-is until done. | |
6165 * The "do_it" flag is reset when something is wrong, in which case | |
6166 * array[] needs to be freed. | |
6167 */ | |
7 | 6168 if (set_prev) |
6169 y_previous = y_current; | |
6462 | 6170 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 6171 str = skipwhite(skiptowhite(str)); |
7 | 6172 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 6173 new_type = MCHAR; |
7 | 6174 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 6175 new_type = MBLOCK; |
7 | 6176 else |
6462 | 6177 new_type = MLINE; |
7 | 6178 /* get the block width; if it's missing we get a zero, which is OK */ |
6179 str = skipwhite(skiptowhite(str)); | |
6462 | 6180 new_width = getdigits(&str); |
7 | 6181 } |
6182 | |
6183 while (!(eof = viminfo_readline(virp)) | |
6184 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
6185 { | |
6186 if (do_it) | |
6187 { | |
6462 | 6188 if (size == limit) |
7 | 6189 { |
6462 | 6190 char_u **new_array = (char_u **) |
7 | 6191 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 6192 |
6193 if (new_array == NULL) | |
6194 { | |
6195 do_it = FALSE; | |
6196 break; | |
6197 } | |
7 | 6198 for (i = 0; i < limit; i++) |
6462 | 6199 new_array[i] = array[i]; |
7 | 6200 vim_free(array); |
6462 | 6201 array = new_array; |
7 | 6202 limit *= 2; |
6203 } | |
6204 str = viminfo_readstring(virp, 1, TRUE); | |
6205 if (str != NULL) | |
6206 array[size++] = str; | |
6207 else | |
6462 | 6208 /* error, don't store the result */ |
7 | 6209 do_it = FALSE; |
6210 } | |
6211 } | |
6508 | 6212 |
7 | 6213 if (do_it) |
6214 { | |
6462 | 6215 /* free y_array[] */ |
6216 for (i = 0; i < y_current->y_size; i++) | |
6217 vim_free(y_current->y_array[i]); | |
6218 vim_free(y_current->y_array); | |
6219 | |
6220 y_current->y_type = new_type; | |
6221 y_current->y_width = new_width; | |
6222 y_current->y_size = size; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6223 y_current->y_time_set = 0; |
7 | 6224 if (size == 0) |
6225 { | |
6226 y_current->y_array = NULL; | |
6227 } | |
6462 | 6228 else |
7 | 6229 { |
6462 | 6230 /* Move the lines from array[] to y_array[]. */ |
7 | 6231 y_current->y_array = |
6232 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
6233 for (i = 0; i < size; i++) | |
6462 | 6234 { |
6235 if (y_current->y_array == NULL) | |
6236 vim_free(array[i]); | |
6237 else | |
6238 y_current->y_array[i] = array[i]; | |
6239 } | |
7 | 6240 } |
6462 | 6241 } |
6242 else | |
6243 { | |
6244 /* Free array[] if it was filled. */ | |
6245 for (i = 0; i < size; i++) | |
6246 vim_free(array[i]); | |
6247 } | |
6248 vim_free(array); | |
6249 | |
7 | 6250 return eof; |
6251 } | |
6252 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6253 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6254 * 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
|
6255 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6256 void |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6257 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
|
6258 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6259 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
|
6260 int flags; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6261 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6262 int type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6263 int linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6264 int width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6265 time_t timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6266 yankreg_T *y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6267 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6268 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6269 /* Check the format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6270 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6271 * {linecount},{width},{timestamp},"line1","line2" |
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 if (values->ga_len < 6 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6274 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6275 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6276 || vp[2].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6277 || vp[3].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6278 || vp[4].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6279 || vp[5].bv_type != BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6280 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6281 flags = vp[0].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6282 name = vp[1].bv_nr; |
9307
eb52a2670c96
commit https://github.com/vim/vim/commit/67e3720a9ddd8a9d2e8344358c28fa1f4196db0d
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
6283 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
|
6284 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6285 type = vp[2].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6286 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
|
6287 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6288 linecount = vp[3].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6289 if (values->ga_len < 6 + linecount) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6290 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6291 width = vp[4].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6292 if (width < 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6293 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6294 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6295 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6296 /* 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
|
6297 * 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
|
6298 y_ptr = &y_read_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6299 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6300 y_ptr = &y_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6301 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6302 /* 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
|
6303 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
|
6304 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
|
6305 && (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
|
6306 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6307 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6308 if (y_ptr->y_array != NULL) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6309 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
|
6310 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
|
6311 vim_free(y_ptr->y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6312 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6313 if (y_read_regs == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6314 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6315 if (flags & REG_PREVIOUS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6316 y_previous = y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6317 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
|
6318 execreg_lastc = get_register_name(name); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6319 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6320 y_ptr->y_type = type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6321 y_ptr->y_width = width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6322 y_ptr->y_size = linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6323 y_ptr->y_time_set = timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6324 if (linecount == 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6325 y_ptr->y_array = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6326 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6327 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6328 y_ptr->y_array = |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6329 (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
|
6330 for (i = 0; i < linecount; i++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6331 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6332 if (vp[i + 6].bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6333 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6334 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
|
6335 vp[i + 6].bv_string = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6336 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6337 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6338 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
|
6339 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6340 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6341 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6342 |
7 | 6343 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6344 write_viminfo_registers(FILE *fp) |
7 | 6345 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6346 int i, j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6347 char_u *type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6348 char_u c; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6349 int num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6350 int max_num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6351 int max_kbyte; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6352 long len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6353 yankreg_T *y_ptr; |
7 | 6354 |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6355 fputs(_("\n# Registers:\n"), fp); |
7 | 6356 |
6357 /* Get '<' value, use old '"' value if '<' is not found. */ | |
6358 max_num_lines = get_viminfo_parameter('<'); | |
6359 if (max_num_lines < 0) | |
6360 max_num_lines = get_viminfo_parameter('"'); | |
6361 if (max_num_lines == 0) | |
6362 return; | |
6363 max_kbyte = get_viminfo_parameter('s'); | |
6364 if (max_kbyte == 0) | |
6365 return; | |
1893 | 6366 |
7 | 6367 for (i = 0; i < NUM_REGISTERS; i++) |
6368 { | |
6369 #ifdef FEAT_CLIPBOARD | |
6370 /* Skip '*'/'+' register, we don't want them back next time */ | |
6371 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
6372 continue; | |
6373 #endif | |
6374 #ifdef FEAT_DND | |
6375 /* Neither do we want the '~' register */ | |
6376 if (i == TILDE_REGISTER) | |
6377 continue; | |
6378 #endif | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6379 /* 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
|
6380 * viminfo if it's newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6381 if (y_read_regs != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6382 && 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
|
6383 && (y_regs[i].y_array == NULL || |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6384 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
|
6385 y_ptr = &y_read_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6386 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
|
6387 continue; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6388 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6389 y_ptr = &y_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6390 |
55 | 6391 /* Skip empty registers. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6392 num_lines = y_ptr->y_size; |
55 | 6393 if (num_lines == 0 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6394 || (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
|
6395 && *y_ptr->y_array[0] == NUL)) |
55 | 6396 continue; |
6397 | |
7 | 6398 if (max_kbyte > 0) |
6399 { | |
6400 /* Skip register if there is more text than the maximum size. */ | |
6401 len = 0; | |
6402 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
|
6403 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
7 | 6404 if (len > (long)max_kbyte * 1024L) |
6405 continue; | |
6406 } | |
6407 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6408 switch (y_ptr->y_type) |
7 | 6409 { |
6410 case MLINE: | |
6411 type = (char_u *)"LINE"; | |
6412 break; | |
6413 case MCHAR: | |
6414 type = (char_u *)"CHAR"; | |
6415 break; | |
6416 case MBLOCK: | |
6417 type = (char_u *)"BLOCK"; | |
6418 break; | |
6419 default: | |
6420 sprintf((char *)IObuff, _("E574: Unknown register type %d"), | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6421 y_ptr->y_type); |
7 | 6422 emsg(IObuff); |
6423 type = (char_u *)"LINE"; | |
6424 break; | |
6425 } | |
6426 if (y_previous == &y_regs[i]) | |
6427 fprintf(fp, "\""); | |
6428 c = get_register_name(i); | |
1893 | 6429 fprintf(fp, "\"%c", c); |
6430 if (c == execreg_lastc) | |
6431 fprintf(fp, "@"); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6432 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
7 | 6433 |
6434 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
6435 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6436 num_lines = max_num_lines; | |
6437 for (j = 0; j < num_lines; j++) | |
6438 { | |
6439 putc('\t', fp); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6440 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
|
6441 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6442 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6443 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6444 int flags = 0; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6445 int remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6446 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6447 /* 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
|
6448 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6449 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6450 * 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
|
6451 * REG_EXEC - used for @@ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6452 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6453 if (y_previous == &y_regs[i]) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6454 flags |= REG_PREVIOUS; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6455 if (c == execreg_lastc) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6456 flags |= REG_EXEC; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6457 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
|
6458 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
|
6459 (long)y_ptr->y_time_set); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6460 /* 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
|
6461 remaining = LSIZE - 71; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6462 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
|
6463 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6464 putc(',', fp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6465 --remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6466 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
|
6467 remaining); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6468 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6469 putc('\n', fp); |
7 | 6470 } |
6471 } | |
6472 } | |
6473 #endif /* FEAT_VIMINFO */ | |
6474 | |
6475 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6476 /* | |
6477 * SELECTION / PRIMARY ('*') | |
6478 * | |
6479 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6480 * GUI this may be text from another window, otherwise it is the last text we | |
6481 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6482 * button performs the paste, otherwise you will need to do <"*p>. " | |
6483 * If not under X, it is synonymous with the clipboard register '+'. | |
6484 * | |
6485 * X CLIPBOARD ('+') | |
6486 * | |
6487 * Text selection stuff that uses the GUI clipboard register '+'. | |
6488 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6489 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6490 * otherwise you will need to do <"+p>. " | |
6491 * If not under X, it is synonymous with the selection register '*'. | |
6492 */ | |
6493 | |
6494 /* | |
6495 * 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
|
6496 * so that the text is still available after Vim has exited. X selections |
7 | 6497 * only exist while the owning application exists, so we write to the |
6498 * permanent (while X runs) store CUT_BUFFER0. | |
6499 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6500 * 'permanent' of the two), otherwise the PRIMARY one. | |
6501 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6502 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6503 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 6504 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6505 x11_export_final_selection(void) |
7 | 6506 { |
6507 Display *dpy; | |
6508 char_u *str = NULL; | |
6509 long_u len = 0; | |
6510 int motion_type = -1; | |
6511 | |
6512 # ifdef FEAT_GUI | |
6513 if (gui.in_use) | |
6514 dpy = X_DISPLAY; | |
6515 else | |
6516 # endif | |
6517 # ifdef FEAT_XCLIPBOARD | |
6518 dpy = xterm_dpy; | |
6519 # else | |
6520 return; | |
6521 # endif | |
6522 | |
6523 /* Get selection to export */ | |
6524 if (clip_plus.owned) | |
6525 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6526 else if (clip_star.owned) | |
6527 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6528 | |
6529 /* Check it's OK */ | |
6530 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6531 && len < 1024*1024 && len > 0) | |
6532 { | |
1924 | 6533 #ifdef FEAT_MBYTE |
4201 | 6534 int ok = TRUE; |
6535 | |
1924 | 6536 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6537 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6538 * encoding conversion usually doesn't work, so keep the text as-is. | |
6539 */ | |
6540 if (has_mbyte) | |
6541 { | |
6542 vimconv_T vc; | |
6543 | |
6544 vc.vc_type = CONV_NONE; | |
6545 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6546 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6547 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6548 char_u *conv_str; |
2007 | 6549 |
4201 | 6550 vc.vc_fail = TRUE; |
2007 | 6551 conv_str = string_convert(&vc, str, &intlen); |
6552 len = intlen; | |
1924 | 6553 if (conv_str != NULL) |
6554 { | |
6555 vim_free(str); | |
6556 str = conv_str; | |
6557 } | |
4201 | 6558 else |
6559 { | |
6560 ok = FALSE; | |
6561 } | |
1924 | 6562 convert_setup(&vc, NULL, NULL); |
6563 } | |
4201 | 6564 else |
6565 { | |
6566 ok = FALSE; | |
6567 } | |
1924 | 6568 } |
4201 | 6569 |
6570 /* Do not store the string if conversion failed. Better to use any | |
6571 * other selection than garbled text. */ | |
6572 if (ok) | |
6573 #endif | |
6574 { | |
6575 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6576 XFlush(dpy); | |
6577 } | |
7 | 6578 } |
6579 | |
6580 vim_free(str); | |
6581 } | |
6582 #endif | |
6583 | |
6584 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6585 clip_free_selection(VimClipboard *cbd) |
7 | 6586 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6587 yankreg_T *y_ptr = y_current; |
7 | 6588 |
6589 if (cbd == &clip_plus) | |
6590 y_current = &y_regs[PLUS_REGISTER]; | |
6591 else | |
6592 y_current = &y_regs[STAR_REGISTER]; | |
6593 free_yank_all(); | |
6594 y_current->y_size = 0; | |
6595 y_current = y_ptr; | |
6596 } | |
6597 | |
6598 /* | |
6599 * Get the selected text and put it in the gui selection register '*' or '+'. | |
6600 */ | |
6601 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6602 clip_get_selection(VimClipboard *cbd) |
7 | 6603 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6604 yankreg_T *old_y_previous, *old_y_current; |
7 | 6605 pos_T old_cursor; |
6606 pos_T old_visual; | |
6607 int old_visual_mode; | |
6608 colnr_T old_curswant; | |
6609 int old_set_curswant; | |
6610 pos_T old_op_start, old_op_end; | |
6611 oparg_T oa; | |
6612 cmdarg_T ca; | |
6613 | |
6614 if (cbd->owned) | |
6615 { | |
6616 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6617 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6618 return; | |
6619 | |
6620 /* Get the text between clip_star.start & clip_star.end */ | |
6621 old_y_previous = y_previous; | |
6622 old_y_current = y_current; | |
6623 old_cursor = curwin->w_cursor; | |
6624 old_curswant = curwin->w_curswant; | |
6625 old_set_curswant = curwin->w_set_curswant; | |
6626 old_op_start = curbuf->b_op_start; | |
6627 old_op_end = curbuf->b_op_end; | |
6628 old_visual = VIsual; | |
6629 old_visual_mode = VIsual_mode; | |
6630 clear_oparg(&oa); | |
6631 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6632 oa.op_type = OP_YANK; | |
6633 vim_memset(&ca, 0, sizeof(ca)); | |
6634 ca.oap = &oa; | |
6635 ca.cmdchar = 'y'; | |
6636 ca.count1 = 1; | |
6637 ca.retval = CA_NO_ADJ_OP_END; | |
6638 do_pending_operator(&ca, 0, TRUE); | |
6639 y_previous = old_y_previous; | |
6640 y_current = old_y_current; | |
6641 curwin->w_cursor = old_cursor; | |
688 | 6642 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6643 curwin->w_curswant = old_curswant; |
6644 curwin->w_set_curswant = old_set_curswant; | |
6645 curbuf->b_op_start = old_op_start; | |
6646 curbuf->b_op_end = old_op_end; | |
6647 VIsual = old_visual; | |
6648 VIsual_mode = old_visual_mode; | |
6649 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6650 else if (!is_clipboard_needs_update()) |
7 | 6651 { |
6652 clip_free_selection(cbd); | |
6653 | |
6654 /* Try to get selected text from another window */ | |
6655 clip_gen_request_selection(cbd); | |
6656 } | |
6657 } | |
6658 | |
2896 | 6659 /* |
6660 * Convert from the GUI selection string into the '*'/'+' register. | |
6661 */ | |
7 | 6662 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6663 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6664 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6665 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6666 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6667 VimClipboard *cbd) |
7 | 6668 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6669 yankreg_T *y_ptr; |
7 | 6670 |
6671 if (cbd == &clip_plus) | |
6672 y_ptr = &y_regs[PLUS_REGISTER]; | |
6673 else | |
6674 y_ptr = &y_regs[STAR_REGISTER]; | |
6675 | |
6676 clip_free_selection(cbd); | |
6677 | |
5798 | 6678 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6679 } |
6680 | |
6681 /* | |
6682 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6683 * with length *len. | |
6684 * Returns the motion type, or -1 for failure. | |
6685 */ | |
6686 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6687 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6688 { |
6689 char_u *p; | |
6690 int lnum; | |
6691 int i, j; | |
6692 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6693 yankreg_T *y_ptr; |
7 | 6694 |
6695 if (cbd == &clip_plus) | |
6696 y_ptr = &y_regs[PLUS_REGISTER]; | |
6697 else | |
6698 y_ptr = &y_regs[STAR_REGISTER]; | |
6699 | |
6700 #ifdef USE_CRNL | |
6701 eolsize = 2; | |
6702 #else | |
6703 eolsize = 1; | |
6704 #endif | |
6705 | |
6706 *str = NULL; | |
6707 *len = 0; | |
6708 if (y_ptr->y_array == NULL) | |
6709 return -1; | |
6710 | |
6711 for (i = 0; i < y_ptr->y_size; i++) | |
6712 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6713 | |
6714 /* | |
6715 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6716 */ | |
6717 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6718 *len -= eolsize; | |
6719 | |
6720 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6721 if (p == NULL) | |
6722 return -1; | |
6723 lnum = 0; | |
6724 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6725 { | |
6726 if (y_ptr->y_array[lnum][j] == '\n') | |
6727 p[i] = NUL; | |
6728 else if (y_ptr->y_array[lnum][j] == NUL) | |
6729 { | |
6730 #ifdef USE_CRNL | |
6731 p[i++] = '\r'; | |
6732 #endif | |
6733 #ifdef USE_CR | |
6734 p[i] = '\r'; | |
6735 #else | |
6736 p[i] = '\n'; | |
6737 #endif | |
6738 lnum++; | |
6739 j = -1; | |
6740 } | |
6741 else | |
6742 p[i] = y_ptr->y_array[lnum][j]; | |
6743 } | |
6744 return y_ptr->y_type; | |
6745 } | |
6746 | |
6747 | |
6748 /* | |
6749 * If we have written to a clipboard register, send the text to the clipboard. | |
6750 */ | |
6751 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6752 may_set_selection(void) |
7 | 6753 { |
6754 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6755 { | |
6756 clip_own_selection(&clip_star); | |
6757 clip_gen_set_selection(&clip_star); | |
6758 } | |
6759 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6760 { | |
6761 clip_own_selection(&clip_plus); | |
6762 clip_gen_set_selection(&clip_plus); | |
6763 } | |
6764 } | |
6765 | |
6766 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6767 | |
6768 | |
6769 #if defined(FEAT_DND) || defined(PROTO) | |
6770 /* | |
6771 * Replace the contents of the '~' register with str. | |
6772 */ | |
6773 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6774 dnd_yank_drag_data(char_u *str, long len) |
7 | 6775 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6776 yankreg_T *curr; |
7 | 6777 |
6778 curr = y_current; | |
6779 y_current = &y_regs[TILDE_REGISTER]; | |
6780 free_yank_all(); | |
5798 | 6781 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6782 y_current = curr; |
6783 } | |
6784 #endif | |
6785 | |
6786 | |
6787 #if defined(FEAT_EVAL) || defined(PROTO) | |
6788 /* | |
6789 * Return the type of a register. | |
6790 * Used for getregtype() | |
6791 * Returns MAUTO for error. | |
6792 */ | |
6793 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6794 get_reg_type(int regname, long *reglen) |
7 | 6795 { |
6796 switch (regname) | |
6797 { | |
6798 case '%': /* file name */ | |
6799 case '#': /* alternate file name */ | |
6800 case '=': /* expression */ | |
6801 case ':': /* last command line */ | |
6802 case '/': /* last search-pattern */ | |
6803 case '.': /* last inserted text */ | |
6804 #ifdef FEAT_SEARCHPATH | |
6805 case Ctrl_F: /* Filename under cursor */ | |
6806 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6807 #endif | |
6808 case Ctrl_W: /* word under cursor */ | |
6809 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6810 case '_': /* black hole: always empty */ | |
6811 return MCHAR; | |
6812 } | |
6813 | |
6814 #ifdef FEAT_CLIPBOARD | |
6815 regname = may_get_selection(regname); | |
6816 #endif | |
6817 | |
5596 | 6818 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
|
6819 return MAUTO; |
5596 | 6820 |
7 | 6821 get_yank_register(regname, FALSE); |
6822 | |
6823 if (y_current->y_array != NULL) | |
6824 { | |
6825 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6826 *reglen = y_current->y_width; | |
6827 return y_current->y_type; | |
6828 } | |
6829 return MAUTO; | |
6830 } | |
6831 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
6832 static char_u *getreg_wrap_one_line(char_u *s, int flags); |
5796 | 6833 |
6834 /* | |
6835 * When "flags" has GREG_LIST return a list with text "s". | |
6836 * Otherwise just return "s". | |
6837 */ | |
6838 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6839 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6840 { |
6841 if (flags & GREG_LIST) | |
6842 { | |
6843 list_T *list = list_alloc(); | |
6844 | |
6845 if (list != NULL) | |
6846 { | |
6847 if (list_append_string(list, NULL, -1) == FAIL) | |
6848 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6849 list_free(list); |
5796 | 6850 return NULL; |
6851 } | |
6852 list->lv_first->li_tv.vval.v_string = s; | |
6853 } | |
6854 return (char_u *)list; | |
6855 } | |
6856 return s; | |
6857 } | |
6858 | |
7 | 6859 /* |
6860 * Return the contents of a register as a single allocated string. | |
6861 * Used for "@r" in expressions and for getreg(). | |
6862 * Returns NULL for error. | |
5796 | 6863 * Flags: |
6864 * GREG_NO_EXPR Do not allow expression register | |
6865 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6866 * not the result of its evaluation. | |
6867 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6868 */ |
6869 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6870 get_reg_contents(int regname, int flags) |
7 | 6871 { |
6872 long i; | |
6873 char_u *retval; | |
6874 int allocated; | |
6875 long len; | |
6876 | |
6877 /* Don't allow using an expression register inside an expression */ | |
6878 if (regname == '=') | |
6879 { | |
5796 | 6880 if (flags & GREG_NO_EXPR) |
6881 return NULL; | |
6882 if (flags & GREG_EXPR_SRC) | |
6883 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6884 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6885 } |
6886 | |
6887 if (regname == '@') /* "@@" is used for unnamed register */ | |
6888 regname = '"'; | |
6889 | |
6890 /* check for valid regname */ | |
6891 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6892 return NULL; | |
6893 | |
6894 #ifdef FEAT_CLIPBOARD | |
6895 regname = may_get_selection(regname); | |
6896 #endif | |
6897 | |
6898 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6899 { | |
6900 if (retval == NULL) | |
6901 return NULL; | |
5796 | 6902 if (allocated) |
6903 return getreg_wrap_one_line(retval, flags); | |
6904 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6905 } |
6906 | |
6907 get_yank_register(regname, FALSE); | |
6908 if (y_current->y_array == NULL) | |
6909 return NULL; | |
6910 | |
5796 | 6911 if (flags & GREG_LIST) |
6912 { | |
6913 list_T *list = list_alloc(); | |
6914 int error = FALSE; | |
6915 | |
6916 if (list == NULL) | |
6917 return NULL; | |
6918 for (i = 0; i < y_current->y_size; ++i) | |
6919 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6920 error = TRUE; | |
6921 if (error) | |
6922 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6923 list_free(list); |
5796 | 6924 return NULL; |
6925 } | |
6926 return (char_u *)list; | |
6927 } | |
6928 | |
7 | 6929 /* |
6930 * Compute length of resulting string. | |
6931 */ | |
6932 len = 0; | |
6933 for (i = 0; i < y_current->y_size; ++i) | |
6934 { | |
6935 len += (long)STRLEN(y_current->y_array[i]); | |
6936 /* | |
6937 * Insert a newline between lines and after last line if | |
6938 * y_type is MLINE. | |
6939 */ | |
6940 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6941 ++len; | |
6942 } | |
6943 | |
6944 retval = lalloc(len + 1, TRUE); | |
6945 | |
6946 /* | |
6947 * Copy the lines of the yank register into the string. | |
6948 */ | |
6949 if (retval != NULL) | |
6950 { | |
6951 len = 0; | |
6952 for (i = 0; i < y_current->y_size; ++i) | |
6953 { | |
6954 STRCPY(retval + len, y_current->y_array[i]); | |
6955 len += (long)STRLEN(retval + len); | |
6956 | |
6957 /* | |
6958 * Insert a NL between lines and after the last line if y_type is | |
6959 * MLINE. | |
6960 */ | |
6961 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6962 retval[len++] = '\n'; | |
6963 } | |
6964 retval[len] = NUL; | |
6965 } | |
6966 | |
6967 return retval; | |
6968 } | |
6969 | |
5798 | 6970 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6971 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6972 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6973 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6974 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6975 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6976 int *yank_type UNUSED) |
5798 | 6977 { |
6978 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6979 { | |
6980 emsg_invreg(name); | |
6981 return FAIL; | |
6982 } | |
6983 | |
6984 /* Don't want to change the current (unnamed) register */ | |
6985 *old_y_previous = y_previous; | |
6986 *old_y_current = y_current; | |
6987 | |
6988 get_yank_register(name, TRUE); | |
6989 if (!y_append && !must_append) | |
6990 free_yank_all(); | |
6991 return OK; | |
6992 } | |
6993 | |
6994 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6995 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6996 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6997 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6998 yankreg_T *old_y_current) |
5798 | 6999 { |
7000 # ifdef FEAT_CLIPBOARD | |
7001 /* Send text of clipboard register to the clipboard. */ | |
7002 may_set_selection(); | |
7003 # endif | |
7004 | |
7005 /* ':let @" = "val"' should change the meaning of the "" register */ | |
7006 if (name != '"') | |
7007 y_previous = old_y_previous; | |
7008 y_current = old_y_current; | |
7009 } | |
7010 | |
7 | 7011 /* |
7012 * Store string "str" in register "name". | |
7013 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
7014 * If "must_append" is TRUE, always append to the register. Otherwise append | |
7015 * if "name" is an uppercase letter. | |
7016 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
7017 * Careful: 'str' is modified, you may have to use a copy! | |
7018 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
7019 */ | |
7020 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7021 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7022 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7023 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7024 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7025 int must_append) |
7 | 7026 { |
7027 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
7028 } | |
7029 | |
7030 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7031 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7032 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7033 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7034 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7035 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7036 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7037 long block_len) |
5798 | 7038 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7039 yankreg_T *old_y_previous, *old_y_current; |
5798 | 7040 |
7041 if (name == '/' | |
7042 #ifdef FEAT_EVAL | |
7043 || name == '=' | |
7044 #endif | |
7045 ) | |
7046 { | |
7047 char_u *s; | |
7048 | |
7049 if (strings[0] == NULL) | |
7050 s = (char_u *)""; | |
7051 else if (strings[1] != NULL) | |
7052 { | |
7053 EMSG(_("E883: search pattern and expression register may not " | |
7054 "contain two or more lines")); | |
7055 return; | |
7056 } | |
7057 else | |
7058 s = strings[0]; | |
7059 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
7060 return; | |
7061 } | |
7062 | |
7063 if (name == '_') /* black hole: nothing to do */ | |
7064 return; | |
7065 | |
7066 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
7067 &yank_type) == FAIL) | |
7068 return; | |
7069 | |
7070 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
7071 | |
7072 finish_write_reg(name, old_y_previous, old_y_current); | |
7073 } | |
7074 | |
7075 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7076 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7077 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7078 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7079 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7080 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7081 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7082 long block_len) |
7 | 7083 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7084 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
|
7085 long len; |
7 | 7086 |
336 | 7087 if (maxlen >= 0) |
7088 len = maxlen; | |
7089 else | |
7090 len = (long)STRLEN(str); | |
7091 | |
7 | 7092 /* Special case: '/' search pattern */ |
7093 if (name == '/') | |
7094 { | |
7095 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
7096 return; | |
7097 } | |
7098 | |
6557 | 7099 if (name == '#') |
7100 { | |
7101 buf_T *buf; | |
7102 | |
7103 if (VIM_ISDIGIT(*str)) | |
7104 { | |
7105 int num = atoi((char *)str); | |
7106 | |
7107 buf = buflist_findnr(num); | |
7108 if (buf == NULL) | |
7109 EMSGN(_(e_nobufnr), (long)num); | |
7110 } | |
7111 else | |
7112 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
7113 TRUE, FALSE, FALSE)); | |
7114 if (buf == NULL) | |
7115 return; | |
7116 curwin->w_alt_fnum = buf->b_fnum; | |
7117 return; | |
7118 } | |
7119 | |
336 | 7120 #ifdef FEAT_EVAL |
7121 if (name == '=') | |
7122 { | |
7123 char_u *p, *s; | |
7124 | |
7125 p = vim_strnsave(str, (int)len); | |
7126 if (p == NULL) | |
7127 return; | |
7128 if (must_append) | |
7129 { | |
7130 s = concat_str(get_expr_line_src(), p); | |
7131 vim_free(p); | |
7132 p = s; | |
7133 } | |
7134 set_expr_line(p); | |
7135 return; | |
7136 } | |
7137 #endif | |
7138 | |
7 | 7139 if (name == '_') /* black hole: nothing to do */ |
7140 return; | |
7141 | |
5798 | 7142 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
7143 &yank_type) == FAIL) | |
7144 return; | |
7145 | |
7146 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
7147 | |
7148 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 7149 } |
7150 #endif /* FEAT_EVAL */ | |
7151 | |
7152 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
7153 /* | |
7154 * Put a string into a register. When the register is not empty, the string | |
7155 * is appended. | |
7156 */ | |
7157 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7158 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7159 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
|
7160 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
|
7161 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
|
7162 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7163 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7164 int str_list) /* TRUE if str is char_u ** */ |
7 | 7165 { |
2896 | 7166 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 7167 int lnum; |
7168 long start; | |
7169 long i; | |
7170 int extra; | |
7171 int newlines; /* number of lines added */ | |
7172 int extraline = 0; /* extra line at the end */ | |
7173 int append = FALSE; /* append to last line in register */ | |
7174 char_u *s; | |
5798 | 7175 char_u **ss; |
7 | 7176 char_u **pp; |
7177 long maxlen; | |
7178 | |
2000 | 7179 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 7180 y_ptr->y_size = 0; |
7181 | |
2896 | 7182 if (yank_type == MAUTO) |
5798 | 7183 type = ((str_list || (len > 0 && (str[len - 1] == NL |
7184 || str[len - 1] == CAR))) | |
2896 | 7185 ? MLINE : MCHAR); |
7186 else | |
7187 type = yank_type; | |
7188 | |
7 | 7189 /* |
7190 * Count the number of lines within the string | |
7191 */ | |
7192 newlines = 0; | |
5798 | 7193 if (str_list) |
7194 { | |
7195 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 7196 ++newlines; |
5798 | 7197 } |
7198 else | |
7199 { | |
7200 for (i = 0; i < len; i++) | |
7201 if (str[i] == '\n') | |
7202 ++newlines; | |
7203 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
7204 { | |
7205 extraline = 1; | |
7206 ++newlines; /* count extra newline at the end */ | |
7207 } | |
7208 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
7209 { | |
7210 append = TRUE; | |
7211 --newlines; /* uncount newline when appending first line */ | |
7212 } | |
7 | 7213 } |
7214 | |
6807 | 7215 /* Without any lines make the register empty. */ |
7216 if (y_ptr->y_size + newlines == 0) | |
7217 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
7218 VIM_CLEAR(y_ptr->y_array); |
6807 | 7219 return; |
7220 } | |
7221 | |
7 | 7222 /* |
7223 * Allocate an array to hold the pointers to the new register lines. | |
7224 * If the register was not empty, move the existing lines to the new array. | |
7225 */ | |
7226 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
7227 * sizeof(char_u *), TRUE); | |
7228 if (pp == NULL) /* out of memory */ | |
7229 return; | |
7230 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
7231 pp[lnum] = y_ptr->y_array[lnum]; | |
7232 vim_free(y_ptr->y_array); | |
7233 y_ptr->y_array = pp; | |
7234 maxlen = 0; | |
7235 | |
7236 /* | |
7237 * Find the end of each line and save it into the array. | |
7238 */ | |
5798 | 7239 if (str_list) |
7240 { | |
7241 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 7242 { |
5856 | 7243 i = (long)STRLEN(*ss); |
5798 | 7244 pp[lnum] = vim_strnsave(*ss, i); |
7245 if (i > maxlen) | |
7246 maxlen = i; | |
7 | 7247 } |
5798 | 7248 } |
7249 else | |
7250 { | |
7251 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 7252 { |
5798 | 7253 for (i = start; i < len; ++i) /* find the end of the line */ |
7254 if (str[i] == '\n') | |
7255 break; | |
7256 i -= start; /* i is now length of line */ | |
7257 if (i > maxlen) | |
7258 maxlen = i; | |
7259 if (append) | |
7260 { | |
7261 --lnum; | |
7262 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
7263 } | |
7264 else | |
7265 extra = 0; | |
7266 s = alloc((unsigned)(i + extra + 1)); | |
7267 if (s == NULL) | |
7268 break; | |
7269 if (extra) | |
7270 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
7271 if (append) | |
7272 vim_free(y_ptr->y_array[lnum]); | |
7273 if (i) | |
7274 mch_memmove(s + extra, str + start, (size_t)i); | |
7275 extra += i; | |
7276 s[extra] = NUL; | |
7277 y_ptr->y_array[lnum++] = s; | |
7278 while (--extra >= 0) | |
7279 { | |
7280 if (*s == NUL) | |
7281 *s = '\n'; /* replace NUL with newline */ | |
7282 ++s; | |
7283 } | |
7284 append = FALSE; /* only first line is appended */ | |
7 | 7285 } |
7286 } | |
7287 y_ptr->y_type = type; | |
7288 y_ptr->y_size = lnum; | |
7289 if (type == MBLOCK) | |
7290 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
7291 else | |
7292 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7293 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7294 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
|
7295 #endif |
7 | 7296 } |
7297 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
7298 | |
7299 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7300 clear_oparg(oparg_T *oap) |
7 | 7301 { |
7302 vim_memset(oap, 0, sizeof(oparg_T)); | |
7303 } | |
7304 | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7305 static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *cc, varnumber_T limit, int eol_size); |
7 | 7306 |
7307 /* | |
161 | 7308 * Count the number of bytes, characters and "words" in a line. |
7 | 7309 * |
7310 * "Words" are counted by looking for boundaries between non-space and | |
7311 * space characters. (it seems to produce results that match 'wc'.) | |
7312 * | |
161 | 7313 * Return value is byte count; word count for the line is added to "*wc". |
7314 * Char count is added to "*cc". | |
7 | 7315 * |
7316 * The function will only examine the first "limit" characters in the | |
7317 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
7318 * case, eol_size will be added to the character count to account for | |
7319 * the size of the EOL character. | |
7320 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7321 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7322 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7323 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7324 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7325 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7326 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7327 int eol_size) |
7 | 7328 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7329 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7330 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7331 varnumber_T chars = 0; |
7 | 7332 int is_word = 0; |
7333 | |
3626 | 7334 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 7335 { |
7336 if (is_word) | |
7337 { | |
7338 if (vim_isspace(line[i])) | |
7339 { | |
7340 words++; | |
7341 is_word = 0; | |
7342 } | |
7343 } | |
7344 else if (!vim_isspace(line[i])) | |
7345 is_word = 1; | |
161 | 7346 ++chars; |
7347 #ifdef FEAT_MBYTE | |
474 | 7348 i += (*mb_ptr2len)(line + i); |
161 | 7349 #else |
7350 ++i; | |
7351 #endif | |
7 | 7352 } |
7353 | |
7354 if (is_word) | |
7355 words++; | |
7356 *wc += words; | |
7357 | |
7358 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 7359 if (i < limit && line[i] == NUL) |
161 | 7360 { |
7 | 7361 i += eol_size; |
161 | 7362 chars += eol_size; |
7363 } | |
7364 *cc += chars; | |
7 | 7365 return i; |
7366 } | |
7367 | |
7368 /* | |
7369 * Give some info about the position of the cursor (for "g CTRL-G"). | |
7370 * In Visual mode, give some info about the selected region. (In this case, | |
7371 * 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
|
7372 * When "dict" is not NULL store the info there instead of showing it. |
7 | 7373 */ |
7374 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7375 cursor_pos_info(dict_T *dict) |
7 | 7376 { |
7377 char_u *p; | |
274 | 7378 char_u buf1[50]; |
7379 char_u buf2[40]; | |
7 | 7380 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7381 varnumber_T byte_count = 0; |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7382 #ifdef FEAT_MBYTE |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7383 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7384 #endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7385 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7386 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7387 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7388 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7389 varnumber_T word_count_cursor = 0; |
7 | 7390 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7391 varnumber_T last_check = 100000L; |
7 | 7392 long line_count_selected = 0; |
7393 pos_T min_pos, max_pos; | |
7394 oparg_T oparg; | |
7395 struct block_def bd; | |
7396 | |
7397 /* | |
7398 * Compute the length of the file in characters. | |
7399 */ | |
7400 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
7401 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7402 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7403 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7404 MSG(_(no_lines_msg)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7405 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7406 } |
7 | 7407 } |
7408 else | |
7409 { | |
7410 if (get_fileformat(curbuf) == EOL_DOS) | |
7411 eol_size = 2; | |
7412 else | |
7413 eol_size = 1; | |
7414 | |
7415 if (VIsual_active) | |
7416 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
7417 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 7418 { |
7419 min_pos = VIsual; | |
7420 max_pos = curwin->w_cursor; | |
7421 } | |
7422 else | |
7423 { | |
7424 min_pos = curwin->w_cursor; | |
7425 max_pos = VIsual; | |
7426 } | |
7427 if (*p_sel == 'e' && max_pos.col > 0) | |
7428 --max_pos.col; | |
7429 | |
7430 if (VIsual_mode == Ctrl_V) | |
7431 { | |
1866 | 7432 #ifdef FEAT_LINEBREAK |
7433 char_u * saved_sbr = p_sbr; | |
7434 | |
7435 /* Make 'sbr' empty for a moment to get the correct size. */ | |
7436 p_sbr = empty_option; | |
7437 #endif | |
7 | 7438 oparg.is_VIsual = 1; |
7439 oparg.block_mode = TRUE; | |
7440 oparg.op_type = OP_NOP; | |
7441 getvcols(curwin, &min_pos, &max_pos, | |
688 | 7442 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 7443 #ifdef FEAT_LINEBREAK |
7444 p_sbr = saved_sbr; | |
7445 #endif | |
688 | 7446 if (curwin->w_curswant == MAXCOL) |
7447 oparg.end_vcol = MAXCOL; | |
7 | 7448 /* Swap the start, end vcol if needed */ |
7449 if (oparg.end_vcol < oparg.start_vcol) | |
7450 { | |
7451 oparg.end_vcol += oparg.start_vcol; | |
7452 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
7453 oparg.end_vcol -= oparg.start_vcol; | |
7454 } | |
7455 } | |
7456 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
7457 } | |
7458 | |
7459 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
7460 { | |
7461 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 7462 if (byte_count > last_check) |
7 | 7463 { |
7464 ui_breakcheck(); | |
7465 if (got_int) | |
7466 return; | |
161 | 7467 last_check = byte_count + 100000L; |
7 | 7468 } |
7469 | |
7470 /* Do extra processing for VIsual mode. */ | |
7471 if (VIsual_active | |
7472 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7473 { | |
45 | 7474 char_u *s = NULL; |
7475 long len = 0L; | |
7476 | |
7 | 7477 switch (VIsual_mode) |
7478 { | |
7479 case Ctrl_V: | |
5735 | 7480 #ifdef FEAT_VIRTUALEDIT |
7 | 7481 virtual_op = virtual_active(); |
5735 | 7482 #endif |
7 | 7483 block_prep(&oparg, &bd, lnum, 0); |
5735 | 7484 #ifdef FEAT_VIRTUALEDIT |
7 | 7485 virtual_op = MAYBE; |
5735 | 7486 #endif |
45 | 7487 s = bd.textstart; |
7488 len = (long)bd.textlen; | |
7 | 7489 break; |
7490 case 'V': | |
45 | 7491 s = ml_get(lnum); |
7492 len = MAXCOL; | |
7 | 7493 break; |
7494 case 'v': | |
7495 { | |
7496 colnr_T start_col = (lnum == min_pos.lnum) | |
7497 ? min_pos.col : 0; | |
7498 colnr_T end_col = (lnum == max_pos.lnum) | |
7499 ? max_pos.col - start_col + 1 : MAXCOL; | |
7500 | |
45 | 7501 s = ml_get(lnum) + start_col; |
7502 len = end_col; | |
7 | 7503 } |
7504 break; | |
7505 } | |
45 | 7506 if (s != NULL) |
7507 { | |
161 | 7508 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7509 &char_count_cursor, len, eol_size); | |
45 | 7510 if (lnum == curbuf->b_ml.ml_line_count |
7511 && !curbuf->b_p_eol | |
6933 | 7512 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7513 && (long)STRLEN(s) < len) |
161 | 7514 byte_count_cursor -= eol_size; |
45 | 7515 } |
7 | 7516 } |
7517 else | |
7518 { | |
7519 /* In non-visual mode, check for the line the cursor is on */ | |
7520 if (lnum == curwin->w_cursor.lnum) | |
7521 { | |
7522 word_count_cursor += word_count; | |
161 | 7523 char_count_cursor += char_count; |
7524 byte_count_cursor = byte_count + | |
7525 line_count_info(ml_get(lnum), | |
7526 &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
|
7527 (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
|
7528 eol_size); |
7 | 7529 } |
7530 } | |
7531 /* Add to the running totals */ | |
161 | 7532 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
|
7533 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7534 eol_size); |
7 | 7535 } |
7536 | |
7537 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7538 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7539 byte_count -= eol_size; |
7 | 7540 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7541 if (dict == NULL) |
7 | 7542 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7543 if (VIsual_active) |
7 | 7544 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7545 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
|
7546 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7547 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
|
7548 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7549 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
|
7550 (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
|
7551 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7552 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7553 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7554 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7555 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
|
7556 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7557 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7558 _("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
|
7559 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7560 (long)curbuf->b_ml.ml_line_count, |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7561 (long long)word_count_cursor, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7562 (long long)word_count, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7563 (long long)byte_count_cursor, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7564 (long long)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7565 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7566 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7567 _("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
|
7568 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7569 (long)curbuf->b_ml.ml_line_count, |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7570 (long long)word_count_cursor, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7571 (long long)word_count, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7572 (long long)char_count_cursor, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7573 (long long)char_count, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7574 (long long)byte_count_cursor, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7575 (long long)byte_count); |
7 | 7576 } |
7577 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7578 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7579 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7580 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7581 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
|
7582 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7583 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
|
7584 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7585 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7586 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
|
7587 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7588 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7589 _("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
|
7590 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7591 (long)curwin->w_cursor.lnum, |
7 | 7592 (long)curbuf->b_ml.ml_line_count, |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7593 (long long)word_count_cursor, (long long)word_count, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7594 (long long)byte_count_cursor, (long long)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7595 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7596 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7597 _("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
|
7598 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7599 (long)curwin->w_cursor.lnum, |
161 | 7600 (long)curbuf->b_ml.ml_line_count, |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7601 (long long)word_count_cursor, (long long)word_count, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7602 (long long)char_count_cursor, (long long)char_count, |
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
7603 (long long)byte_count_cursor, (long long)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7604 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7605 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7606 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7607 #ifdef FEAT_MBYTE |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7608 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7609 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7610 vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE, |
13614
87e5629fc915
patch 8.0.1679: compiler warning for printf format
Christian Brabandt <cb@256bit.org>
parents:
13610
diff
changeset
|
7611 _("(+%lld for BOM)"), (long long)bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7612 #endif |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7613 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7614 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7615 /* 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
|
7616 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7617 p_shm = (char_u *)""; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7618 msg(IObuff); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7619 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7620 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7621 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7622 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7623 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7624 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7625 dict_add_nr_str(dict, "words", word_count, NULL); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7626 dict_add_nr_str(dict, "chars", char_count, NULL); |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7627 dict_add_nr_str(dict, "bytes", byte_count |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7628 # ifdef FEAT_MBYTE |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7629 + bom_count |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7630 # endif |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7631 , NULL); |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7632 dict_add_nr_str(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7633 byte_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7634 dict_add_nr_str(dict, VIsual_active ? "visual_chars" : "cursor_chars", |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7635 char_count_cursor, NULL); |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7636 dict_add_nr_str(dict, VIsual_active ? "visual_words" : "cursor_words", |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7637 word_count_cursor, NULL); |
7 | 7638 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7639 #endif |
7 | 7640 } |