Mercurial > vim
annotate src/ops.c @ 15555:d89c5b339c2a v8.1.0785
patch 8.1.0785: depending on the configuration some functions are unused
commit https://github.com/vim/vim/commit/113e10721f42fc2500b63fe95193f8665658a90c
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jan 20 15:30:40 2019 +0100
patch 8.1.0785: depending on the configuration some functions are unused
Problem: Depending on the configuration some functions are unused.
Solution: Add more #ifdefs, remove unused functions. (Dominique Pelle,
closes #3822)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 20 Jan 2019 15:45:07 +0100 |
parents | dd725a8ab112 |
children | 536dd2bc5ac9 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9834
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, | |
12 * op_change, op_yank, do_put, do_join | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * Number of registers. | |
19 * 0 = unnamed register, for normal yanks and puts | |
20 * 1..9 = registers '1' to '9', for deletes | |
21 * 10..35 = registers 'a' to 'z' | |
22 * 36 = delete register '-' | |
23 * 37 = Selection register '*'. Only if FEAT_CLIPBOARD defined | |
24 * 38 = Clipboard register '+'. Only if FEAT_CLIPBOARD and FEAT_X11 defined | |
25 */ | |
26 /* | |
27 * Symbolic names for some registers. | |
28 */ | |
29 #define DELETION_REGISTER 36 | |
30 #ifdef FEAT_CLIPBOARD | |
31 # define STAR_REGISTER 37 | |
32 # ifdef FEAT_X11 | |
33 # define PLUS_REGISTER 38 | |
34 # else | |
35 # define PLUS_REGISTER STAR_REGISTER /* there is only one */ | |
36 # endif | |
37 #endif | |
38 #ifdef FEAT_DND | |
39 # define TILDE_REGISTER (PLUS_REGISTER + 1) | |
40 #endif | |
41 | |
42 #ifdef FEAT_CLIPBOARD | |
43 # ifdef FEAT_DND | |
44 # define NUM_REGISTERS (TILDE_REGISTER + 1) | |
45 # else | |
46 # define NUM_REGISTERS (PLUS_REGISTER + 1) | |
47 # endif | |
48 #else | |
49 # define NUM_REGISTERS 37 | |
50 #endif | |
51 | |
52 /* | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
53 * Each yank register has an array of pointers to lines. |
7 | 54 */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
55 typedef struct |
7 | 56 { |
57 char_u **y_array; /* pointer to array of line pointers */ | |
58 linenr_T y_size; /* number of lines in y_array */ | |
59 char_u y_type; /* MLINE, MCHAR or MBLOCK */ | |
60 colnr_T y_width; /* only set if y_type == MBLOCK */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
61 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
62 time_t y_time_set; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
63 #endif |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
64 } yankreg_T; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
65 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
66 static yankreg_T y_regs[NUM_REGISTERS]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
67 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
68 static yankreg_T *y_current; /* ptr to current yankreg */ |
7 | 69 static int y_append; /* TRUE when appending */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
70 static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */ |
7 | 71 |
72 /* | |
73 * structure used by block_prep, op_delete and op_yank for blockwise operators | |
74 * also op_change, op_shift, op_insert, op_replace - AKelly | |
75 */ | |
76 struct block_def | |
77 { | |
1839 | 78 int startspaces; /* 'extra' cols before first char */ |
79 int endspaces; /* 'extra' cols after last char */ | |
7 | 80 int textlen; /* chars in block */ |
1839 | 81 char_u *textstart; /* pointer to 1st char (partially) in block */ |
82 colnr_T textcol; /* index of chars (partially) in block */ | |
7 | 83 colnr_T start_vcol; /* start col of 1st char wholly inside block */ |
84 colnr_T end_vcol; /* start col of 1st char wholly after block */ | |
85 int is_short; /* TRUE if line is too short to fit in block */ | |
86 int is_MAX; /* TRUE if curswant==MAXCOL when starting */ | |
87 int is_oneChar; /* TRUE if block within one character */ | |
88 int pre_whitesp; /* screen cols of ws before block */ | |
89 int pre_whitesp_c; /* chars of ws before block */ | |
90 colnr_T end_char_vcols; /* number of vcols of post-block char */ | |
91 colnr_T start_char_vcols; /* number of vcols of pre-block char */ | |
92 }; | |
93 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
94 static void shift_block(oparg_T *oap, int amount); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
95 static int stuff_yank(int, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
96 static void put_reedit_in_typebuf(int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
97 static int put_in_typebuf(char_u *s, int esc, int colon, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
98 int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
99 static void stuffescaped(char_u *arg, int literally); |
7 | 100 #ifdef FEAT_MBYTE |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
101 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
|
102 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
103 static void free_yank_all(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
104 static int yank_copy_line(struct block_def *bd, long y_idx); |
7 | 105 #ifdef FEAT_CLIPBOARD |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
106 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
|
107 static void may_set_selection(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
108 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
109 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
|
110 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
|
111 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
7 | 112 #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
|
113 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
|
114 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
115 static int ends_in_white(linenr_T lnum); |
7 | 116 #ifdef FEAT_COMMENTS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
117 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 118 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
119 static int fmt_check_par(linenr_T); |
7 | 120 #endif |
121 | |
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
|
122 // 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
|
123 #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
|
124 #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
|
125 |
7 | 126 /* |
127 * The names of operators. | |
128 * 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
|
129 * The third field holds OPF_ flags. |
7 | 130 */ |
131 static char opchars[][3] = | |
132 { | |
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
|
133 {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
|
134 {'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
|
135 {'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
|
136 {'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
|
137 {'<', 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
|
138 {'>', 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
|
139 {'!', 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
|
140 {'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
|
141 {'=', 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
|
142 {'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
|
143 {':', 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
|
144 {'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
|
145 {'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
|
146 {'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
|
147 {'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
|
148 {'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
|
149 {'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
|
150 {'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
|
151 {'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
|
152 {'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
|
153 {'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
|
154 {'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
|
155 {'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
|
156 {'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
|
157 {'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
|
158 {'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
|
159 {'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
|
160 {'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
|
161 {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
|
162 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB |
7 | 163 }; |
164 | |
165 /* | |
166 * Translate a command name into an operator type. | |
167 * Must only be called with a valid operator name! | |
168 */ | |
169 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
170 get_op_type(int char1, int char2) |
7 | 171 { |
172 int i; | |
173 | |
174 if (char1 == 'r') /* ignore second character */ | |
175 return OP_REPLACE; | |
176 if (char1 == '~') /* when tilde is an operator */ | |
177 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
178 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
|
179 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
180 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
|
181 return OP_NR_SUB; |
7 | 182 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
|
183 { |
7 | 184 if (opchars[i][0] == char1 && opchars[i][1] == char2) |
185 break; | |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
186 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
|
187 { |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
188 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
|
189 break; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
190 } |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
191 } |
7 | 192 return i; |
193 } | |
194 | |
195 /* | |
196 * Return TRUE if operator "op" always works on whole lines. | |
197 */ | |
198 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
199 op_on_lines(int op) |
7 | 200 { |
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
|
201 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
|
202 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
203 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
204 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
205 /* |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
206 * 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
|
207 */ |
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 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
|
209 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
|
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 return opchars[op][2] & OPF_CHANGE; |
7 | 212 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
213 #endif |
7 | 214 |
215 /* | |
216 * Get first operator command character. | |
217 * Returns 'g' or 'z' if there is another command character. | |
218 */ | |
219 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
220 get_op_char(int optype) |
7 | 221 { |
222 return opchars[optype][0]; | |
223 } | |
224 | |
225 /* | |
226 * Get second operator command character. | |
227 */ | |
228 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
229 get_extra_op_char(int optype) |
7 | 230 { |
231 return opchars[optype][1]; | |
232 } | |
233 | |
234 /* | |
235 * op_shift - handle a shift operation | |
236 */ | |
237 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
238 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 239 { |
240 long i; | |
241 int first_char; | |
242 int block_col = 0; | |
243 | |
244 if (u_save((linenr_T)(oap->start.lnum - 1), | |
245 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
246 return; | |
247 | |
248 if (oap->block_mode) | |
249 block_col = curwin->w_cursor.col; | |
250 | |
251 for (i = oap->line_count; --i >= 0; ) | |
252 { | |
253 first_char = *ml_get_curline(); | |
254 if (first_char == NUL) /* empty line */ | |
255 curwin->w_cursor.col = 0; | |
256 else if (oap->block_mode) | |
257 shift_block(oap, amount); | |
258 else | |
259 /* Move the line right if it doesn't start with '#', 'smartindent' | |
260 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
261 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
262 if (first_char != '#' || !preprocs_left()) | |
263 #endif | |
264 { | |
1516 | 265 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 266 } |
267 ++curwin->w_cursor.lnum; | |
268 } | |
269 | |
270 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
271 if (oap->block_mode) | |
272 { | |
273 curwin->w_cursor.lnum = oap->start.lnum; | |
274 curwin->w_cursor.col = block_col; | |
275 } | |
5735 | 276 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 277 { |
278 curwin->w_cursor.lnum = oap->start.lnum; | |
279 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
280 } | |
281 else | |
282 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
283 | |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
284 #ifdef FEAT_FOLDING |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
285 /* 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
|
286 foldOpenCursor(); |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
287 #endif |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
288 |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
289 |
7 | 290 if (oap->line_count > p_report) |
291 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
292 char *op; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
293 char *msg_line_single; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
294 char *msg_line_plural; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
295 |
7 | 296 if (oap->op_type == OP_RSHIFT) |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
297 op = ">"; |
7 | 298 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
299 op = "<"; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
300 msg_line_single = NGETTEXT("%ld line %sed %d time", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
301 "%ld line %sed %d times", amount); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
302 msg_line_plural = NGETTEXT("%ld lines %sed %d time", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
303 "%ld lines %sed %d times", amount); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
304 vim_snprintf((char *)IObuff, IOSIZE, |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
305 NGETTEXT(msg_line_single, msg_line_plural, oap->line_count), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
306 oap->line_count, op, amount); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
307 msg((char *)IObuff); |
7 | 308 } |
309 | |
310 /* | |
311 * Set "'[" and "']" marks. | |
312 */ | |
313 curbuf->b_op_start = oap->start; | |
314 curbuf->b_op_end.lnum = oap->end.lnum; | |
315 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
316 if (curbuf->b_op_end.col > 0) | |
317 --curbuf->b_op_end.col; | |
318 } | |
319 | |
320 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
321 * Shift the current line one shiftwidth left (if left != 0) or right |
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
322 * leaves cursor on first blank in the line. |
7 | 323 */ |
324 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
325 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
326 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
327 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
328 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
329 int call_changed_bytes) /* call changed_bytes() */ |
7 | 330 { |
331 int count; | |
332 int i, j; | |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
15048
diff
changeset
|
333 int p_sw = (int)get_sw_value_indent(curbuf); |
7 | 334 |
335 count = get_indent(); /* get current indent */ | |
336 | |
337 if (round) /* round off indent */ | |
338 { | |
339 i = count / p_sw; /* number of p_sw rounded down */ | |
340 j = count % p_sw; /* extra spaces */ | |
341 if (j && left) /* first remove extra spaces */ | |
342 --amount; | |
343 if (left) | |
344 { | |
345 i -= amount; | |
346 if (i < 0) | |
347 i = 0; | |
348 } | |
349 else | |
350 i += amount; | |
351 count = i * p_sw; | |
352 } | |
353 else /* original vi indent */ | |
354 { | |
355 if (left) | |
356 { | |
357 count -= p_sw * amount; | |
358 if (count < 0) | |
359 count = 0; | |
360 } | |
361 else | |
362 count += p_sw * amount; | |
363 } | |
364 | |
365 /* Set new indent */ | |
366 if (State & VREPLACE_FLAG) | |
1516 | 367 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 368 else |
1516 | 369 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 370 } |
371 | |
372 /* | |
373 * Shift one line of the current block one shiftwidth right or left. | |
374 * Leaves cursor on first character in block. | |
375 */ | |
376 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
377 shift_block(oparg_T *oap, int amount) |
7 | 378 { |
379 int left = (oap->op_type == OP_LSHIFT); | |
380 int oldstate = State; | |
1839 | 381 int total; |
382 char_u *newp, *oldp; | |
7 | 383 int oldcol = curwin->w_cursor.col; |
15062
3a94f7918980
patch 8.1.0542: shiftwidth() does not take 'vartabstop' into account
Bram Moolenaar <Bram@vim.org>
parents:
15048
diff
changeset
|
384 int p_sw = (int)get_sw_value_indent(curbuf); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
385 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
386 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
|
387 #endif |
7 | 388 int p_ts = (int)curbuf->b_p_ts; |
389 struct block_def bd; | |
390 int incr; | |
1839 | 391 colnr_T ws_vcol; |
7 | 392 int i = 0, j = 0; |
393 int len; | |
394 #ifdef FEAT_RIGHTLEFT | |
395 int old_p_ri = p_ri; | |
396 | |
4352 | 397 p_ri = 0; /* don't want revins in indent */ |
7 | 398 #endif |
399 | |
400 State = INSERT; /* don't want REPLACE for State */ | |
401 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
402 if (bd.is_short) | |
403 return; | |
404 | |
405 /* 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
|
406 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
|
407 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
|
408 return; /* multiplication overflow */ |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
409 |
7 | 410 oldp = ml_get_curline(); |
411 | |
412 if (!left) | |
413 { | |
414 /* | |
415 * 1. Get start vcol | |
416 * 2. Total ws vcols | |
417 * 3. Divvy into TABs & spp | |
418 * 4. Construct new string | |
419 */ | |
420 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
421 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
422 if (bd.startspaces) | |
423 { | |
424 #ifdef FEAT_MBYTE | |
425 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
426 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
427 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
428 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
429 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
430 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
431 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
432 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
433 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
434 } |
1995 | 435 else |
436 #endif | |
437 ++bd.textstart; | |
7 | 438 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
439 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 440 { |
5995 | 441 /* TODO: is passing bd.textstart for start of the line OK? */ |
442 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
443 (colnr_T)(bd.start_vcol)); | |
7 | 444 total += incr; |
445 bd.start_vcol += incr; | |
446 } | |
447 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
448 * 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
|
449 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
450 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
|
451 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
|
452 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
453 j = total; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
454 #else |
7 | 455 if (!curbuf->b_p_et) |
456 i = ((ws_vcol % p_ts) + total) / p_ts; /* number of tabs */ | |
457 if (i) | |
458 j = ((ws_vcol % p_ts) + total) % p_ts; /* number of spp */ | |
459 else | |
460 j = total; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
461 #endif |
7 | 462 /* if we're splitting a TAB, allow for it */ |
463 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
464 len = (int)STRLEN(bd.textstart) + 1; | |
465 newp = alloc_check((unsigned)(bd.textcol + i + j + len)); | |
466 if (newp == NULL) | |
467 return; | |
468 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
469 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 470 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
471 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 472 /* the end */ |
473 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
474 } | |
475 else /* left */ | |
476 { | |
1839 | 477 colnr_T destination_col; /* column to which text in block will |
478 be shifted */ | |
479 char_u *verbatim_copy_end; /* end of the part of the line which is | |
480 copied verbatim */ | |
481 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
482 of line */ | |
483 unsigned fill; /* nr of spaces that replace a TAB */ | |
484 unsigned new_line_len; /* the length of the line after the | |
485 block shift */ | |
486 size_t block_space_width; | |
487 size_t shift_amount; | |
488 char_u *non_white = bd.textstart; | |
489 colnr_T non_white_col; | |
490 | |
491 /* | |
492 * Firstly, let's find the first non-whitespace character that is | |
493 * displayed after the block's start column and the character's column | |
494 * number. Also, let's calculate the width of all the whitespace | |
495 * characters that are displayed in the block and precede the searched | |
496 * non-whitespace character. | |
497 */ | |
498 | |
499 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
500 * the part of which is displayed at the block's beginning. Let's start | |
501 * searching from the next character. */ | |
502 if (bd.startspaces) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
503 MB_PTR_ADV(non_white); |
1839 | 504 |
505 /* The character's column is in "bd.start_vcol". */ | |
506 non_white_col = bd.start_vcol; | |
507 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
508 while (VIM_ISWHITE(*non_white)) |
7 | 509 { |
5995 | 510 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 511 non_white_col += incr; |
7 | 512 } |
1839 | 513 |
514 block_space_width = non_white_col - oap->start_vcol; | |
515 /* We will shift by "total" or "block_space_width", whichever is less. | |
516 */ | |
1860 | 517 shift_amount = (block_space_width < (size_t)total |
518 ? block_space_width : (size_t)total); | |
1839 | 519 |
520 /* The column to which we will shift the text. */ | |
1860 | 521 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 522 |
523 /* Now let's find out how much of the beginning of the line we can | |
524 * reuse without modification. */ | |
525 verbatim_copy_end = bd.textstart; | |
526 verbatim_copy_width = bd.start_vcol; | |
527 | |
528 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
529 * preceding the block. We have to subtract its width to obtain its | |
530 * column number. */ | |
531 if (bd.startspaces) | |
532 verbatim_copy_width -= bd.start_char_vcols; | |
533 while (verbatim_copy_width < destination_col) | |
7 | 534 { |
5995 | 535 char_u *line = verbatim_copy_end; |
536 | |
537 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
538 incr = lbr_chartabsize(line, verbatim_copy_end, | |
539 verbatim_copy_width); | |
1839 | 540 if (verbatim_copy_width + incr > destination_col) |
541 break; | |
542 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
|
543 MB_PTR_ADV(verbatim_copy_end); |
7 | 544 } |
545 | |
1839 | 546 /* If "destination_col" is different from the width of the initial |
547 * part of the line that will be copied, it means we encountered a tab | |
548 * character, which we will have to partly replace with spaces. */ | |
549 fill = destination_col - verbatim_copy_width; | |
550 | |
551 /* The replacement line will consist of: | |
552 * - the beginning of the original line up to "verbatim_copy_end", | |
553 * - "fill" number of spaces, | |
554 * - the rest of the line, pointed to by non_white. */ | |
555 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
556 + fill | |
557 + (unsigned)STRLEN(non_white) + 1; | |
558 | |
559 newp = alloc_check(new_line_len); | |
7 | 560 if (newp == NULL) |
561 return; | |
1839 | 562 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 563 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 564 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 565 } |
566 /* replace the line */ | |
567 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
568 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
569 State = oldstate; | |
570 curwin->w_cursor.col = oldcol; | |
571 #ifdef FEAT_RIGHTLEFT | |
572 p_ri = old_p_ri; | |
573 #endif | |
574 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
575 |
7 | 576 /* |
577 * Insert string "s" (b_insert ? before : after) block :AKelly | |
578 * Caller must prepare for undo. | |
579 */ | |
580 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
581 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
582 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
583 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
584 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
585 struct block_def *bdp) |
7 | 586 { |
587 int p_ts; | |
588 int count = 0; /* extra spaces to replace a cut TAB */ | |
589 int spaces = 0; /* non-zero if cutting a TAB */ | |
590 colnr_T offset; /* pointer along new line */ | |
591 unsigned s_len; /* STRLEN(s) */ | |
592 char_u *newp, *oldp; /* new, old lines */ | |
593 linenr_T lnum; /* loop var */ | |
594 int oldstate = State; | |
595 | |
596 State = INSERT; /* don't want REPLACE for State */ | |
597 s_len = (unsigned)STRLEN(s); | |
598 | |
599 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
600 { | |
601 block_prep(oap, bdp, lnum, TRUE); | |
602 if (bdp->is_short && b_insert) | |
603 continue; /* OP_INSERT, line ends before block start */ | |
604 | |
605 oldp = ml_get(lnum); | |
606 | |
607 if (b_insert) | |
608 { | |
609 p_ts = bdp->start_char_vcols; | |
610 spaces = bdp->startspaces; | |
611 if (spaces != 0) | |
612 count = p_ts - 1; /* we're cutting a TAB */ | |
613 offset = bdp->textcol; | |
614 } | |
615 else /* append */ | |
616 { | |
617 p_ts = bdp->end_char_vcols; | |
618 if (!bdp->is_short) /* spaces = padding after block */ | |
619 { | |
620 spaces = (bdp->endspaces ? p_ts - bdp->endspaces : 0); | |
621 if (spaces != 0) | |
622 count = p_ts - 1; /* we're cutting a TAB */ | |
623 offset = bdp->textcol + bdp->textlen - (spaces != 0); | |
624 } | |
625 else /* spaces = padding to block edge */ | |
626 { | |
627 /* if $ used, just append to EOL (ie spaces==0) */ | |
628 if (!bdp->is_MAX) | |
629 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
630 count = spaces; | |
631 offset = bdp->textcol + bdp->textlen; | |
632 } | |
633 } | |
634 | |
6140 | 635 #ifdef FEAT_MBYTE |
636 if (has_mbyte && spaces > 0) | |
637 { | |
6460 | 638 int off; |
639 | |
6140 | 640 /* Avoid starting halfway a multi-byte character. */ |
641 if (b_insert) | |
642 { | |
6460 | 643 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 644 } |
645 else | |
646 { | |
6460 | 647 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 648 offset += off; |
649 } | |
6460 | 650 spaces -= off; |
651 count -= off; | |
6140 | 652 } |
653 #endif | |
654 | |
7 | 655 newp = alloc_check((unsigned)(STRLEN(oldp)) + s_len + count + 1); |
656 if (newp == NULL) | |
657 continue; | |
658 | |
659 /* copy up to shifted part */ | |
660 mch_memmove(newp, oldp, (size_t)(offset)); | |
661 oldp += offset; | |
662 | |
663 /* insert pre-padding */ | |
6929 | 664 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 665 |
666 /* copy the new text */ | |
667 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
668 offset += s_len; | |
669 | |
670 if (spaces && !bdp->is_short) | |
671 { | |
672 /* insert post-padding */ | |
6929 | 673 vim_memset(newp + offset + spaces, ' ', (size_t)(p_ts - spaces)); |
7 | 674 /* We're splitting a TAB, don't copy it. */ |
675 oldp++; | |
676 /* We allowed for that TAB, remember this now */ | |
677 count++; | |
678 } | |
679 | |
680 if (spaces > 0) | |
681 offset += count; | |
1622 | 682 STRMOVE(newp + offset, oldp); |
7 | 683 |
684 ml_replace(lnum, newp, FALSE); | |
685 | |
686 if (lnum == oap->end.lnum) | |
687 { | |
688 /* Set "']" mark to the end of the block instead of the end of | |
689 * the insert in the first line. */ | |
690 curbuf->b_op_end.lnum = oap->end.lnum; | |
691 curbuf->b_op_end.col = offset; | |
692 } | |
693 } /* for all lnum */ | |
694 | |
695 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
696 | |
697 State = oldstate; | |
698 } | |
699 | |
700 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
701 /* | |
702 * op_reindent - handle reindenting a block of lines. | |
703 */ | |
704 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
705 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 706 { |
707 long i; | |
708 char_u *l; | |
6971 | 709 int amount; |
7 | 710 linenr_T first_changed = 0; |
711 linenr_T last_changed = 0; | |
712 linenr_T start_lnum = curwin->w_cursor.lnum; | |
713 | |
216 | 714 /* Don't even try when 'modifiable' is off. */ |
715 if (!curbuf->b_p_ma) | |
716 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
717 emsg(_(e_modifiable)); |
216 | 718 return; |
719 } | |
720 | |
7 | 721 for (i = oap->line_count; --i >= 0 && !got_int; ) |
722 { | |
723 /* it's a slow thing to do, so give feedback so there's no worry that | |
724 * the computer's just hung. */ | |
725 | |
726 if (i > 1 | |
727 && (i % 50 == 0 || i == oap->line_count - 1) | |
728 && oap->line_count > p_report) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
729 smsg(_("%ld lines to indent... "), i); |
7 | 730 |
731 /* | |
732 * Be vi-compatible: For lisp indenting the first line is not | |
733 * indented, unless there is only one line. | |
734 */ | |
735 #ifdef FEAT_LISP | |
736 if (i != oap->line_count - 1 || oap->line_count == 1 | |
737 || how != get_lisp_indent) | |
738 #endif | |
739 { | |
740 l = skipwhite(ml_get_curline()); | |
741 if (*l == NUL) /* empty or blank line */ | |
6971 | 742 amount = 0; |
7 | 743 else |
6971 | 744 amount = how(); /* get the indent for this line */ |
745 | |
746 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 747 { |
748 /* did change the indent, call changed_lines() later */ | |
749 if (first_changed == 0) | |
750 first_changed = curwin->w_cursor.lnum; | |
751 last_changed = curwin->w_cursor.lnum; | |
752 } | |
753 } | |
754 ++curwin->w_cursor.lnum; | |
1550 | 755 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 756 } |
757 | |
758 /* put cursor on first non-blank of indented line */ | |
759 curwin->w_cursor.lnum = start_lnum; | |
760 beginline(BL_SOL | BL_FIX); | |
761 | |
762 /* Mark changed lines so that they will be redrawn. When Visual | |
763 * highlighting was present, need to continue until the last line. When | |
764 * there is no change still need to remove the Visual highlighting. */ | |
765 if (last_changed != 0) | |
766 changed_lines(first_changed, 0, | |
767 oap->is_VIsual ? start_lnum + oap->line_count : | |
768 last_changed + 1, 0L); | |
769 else if (oap->is_VIsual) | |
770 redraw_curbuf_later(INVERTED); | |
771 | |
772 if (oap->line_count > p_report) | |
773 { | |
774 i = oap->line_count - (i + 1); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
775 smsg(NGETTEXT("%ld line indented ", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
776 "%ld lines indented ", i), i); |
7 | 777 } |
778 /* set '[ and '] marks */ | |
779 curbuf->b_op_start = oap->start; | |
780 curbuf->b_op_end = oap->end; | |
781 } | |
782 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
783 | |
784 #if defined(FEAT_EVAL) || defined(PROTO) | |
785 /* | |
786 * Keep the last expression line here, for repeating. | |
787 */ | |
788 static char_u *expr_line = NULL; | |
789 | |
790 /* | |
791 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
792 * Returns '=' when OK, NUL otherwise. | |
793 */ | |
794 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
795 get_expr_register(void) |
7 | 796 { |
797 char_u *new_line; | |
798 | |
799 new_line = getcmdline('=', 0L, 0); | |
800 if (new_line == NULL) | |
801 return NUL; | |
802 if (*new_line == NUL) /* use previous line */ | |
803 vim_free(new_line); | |
804 else | |
805 set_expr_line(new_line); | |
806 return '='; | |
807 } | |
808 | |
809 /* | |
810 * Set the expression for the '=' register. | |
811 * Argument must be an allocated string. | |
812 */ | |
813 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
814 set_expr_line(char_u *new_line) |
7 | 815 { |
816 vim_free(expr_line); | |
817 expr_line = new_line; | |
818 } | |
819 | |
820 /* | |
821 * Get the result of the '=' register expression. | |
822 * Returns a pointer to allocated memory, or NULL for failure. | |
823 */ | |
824 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
825 get_expr_line(void) |
7 | 826 { |
827 char_u *expr_copy; | |
828 char_u *rv; | |
994 | 829 static int nested = 0; |
7 | 830 |
831 if (expr_line == NULL) | |
832 return NULL; | |
833 | |
834 /* Make a copy of the expression, because evaluating it may cause it to be | |
835 * changed. */ | |
836 expr_copy = vim_strsave(expr_line); | |
837 if (expr_copy == NULL) | |
838 return NULL; | |
839 | |
994 | 840 /* When we are invoked recursively limit the evaluation to 10 levels. |
841 * Then return the string as-is. */ | |
842 if (nested >= 10) | |
843 return expr_copy; | |
844 | |
845 ++nested; | |
714 | 846 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 847 --nested; |
7 | 848 vim_free(expr_copy); |
849 return rv; | |
850 } | |
283 | 851 |
852 /* | |
853 * Get the '=' register expression itself, without evaluating it. | |
854 */ | |
855 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
856 get_expr_line_src(void) |
283 | 857 { |
858 if (expr_line == NULL) | |
859 return NULL; | |
860 return vim_strsave(expr_line); | |
861 } | |
7 | 862 #endif /* FEAT_EVAL */ |
863 | |
864 /* | |
865 * Check if 'regname' is a valid name of a yank register. | |
866 * Note: There is no check for 0 (default register), caller should do this | |
867 */ | |
868 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
869 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
870 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
871 int writing) /* if TRUE check for writable registers */ |
7 | 872 { |
873 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
874 || (!writing && vim_strchr((char_u *) | |
875 #ifdef FEAT_EVAL | |
6557 | 876 "/.%:=" |
7 | 877 #else |
6557 | 878 "/.%:" |
7 | 879 #endif |
880 , regname) != NULL) | |
6557 | 881 || regname == '#' |
7 | 882 || regname == '"' |
883 || regname == '-' | |
884 || regname == '_' | |
885 #ifdef FEAT_CLIPBOARD | |
886 || regname == '*' | |
887 || regname == '+' | |
888 #endif | |
889 #ifdef FEAT_DND | |
890 || (!writing && regname == '~') | |
891 #endif | |
892 ) | |
893 return TRUE; | |
894 return FALSE; | |
895 } | |
896 | |
897 /* | |
898 * Set y_current and y_append, according to the value of "regname". | |
899 * Cannot handle the '_' register. | |
140 | 900 * Must only be called with a valid register name! |
7 | 901 * |
902 * If regname is 0 and writing, use register 0 | |
903 * 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
|
904 * |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
905 * 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
|
906 * clipboard). |
7 | 907 */ |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
908 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
909 get_yank_register(int regname, int writing) |
7 | 910 { |
911 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
|
912 int ret = FALSE; |
7 | 913 |
914 y_append = FALSE; | |
915 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
916 { | |
917 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
|
918 return ret; |
7 | 919 } |
920 i = regname; | |
921 if (VIM_ISDIGIT(i)) | |
922 i -= '0'; | |
923 else if (ASCII_ISLOWER(i)) | |
924 i = CharOrdLow(i) + 10; | |
925 else if (ASCII_ISUPPER(i)) | |
926 { | |
927 i = CharOrdUp(i) + 10; | |
928 y_append = TRUE; | |
929 } | |
930 else if (regname == '-') | |
931 i = DELETION_REGISTER; | |
932 #ifdef FEAT_CLIPBOARD | |
933 /* When selection is not available, use register 0 instead of '*' */ | |
934 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
|
935 { |
7 | 936 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
|
937 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
938 } |
7 | 939 /* When clipboard is not available, use register 0 instead of '+' */ |
940 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
|
941 { |
7 | 942 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
|
943 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
944 } |
7 | 945 #endif |
946 #ifdef FEAT_DND | |
947 else if (!writing && regname == '~') | |
948 i = TILDE_REGISTER; | |
949 #endif | |
950 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
951 i = 0; | |
952 y_current = &(y_regs[i]); | |
953 if (writing) /* remember the register we write into for do_put() */ | |
954 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
|
955 return ret; |
7 | 956 } |
957 | |
15 | 958 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 959 /* |
960 * When "regname" is a clipboard register, obtain the selection. If it's not | |
961 * available return zero, otherwise return "regname". | |
962 */ | |
15 | 963 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
964 may_get_selection(int regname) |
7 | 965 { |
966 if (regname == '*') | |
967 { | |
968 if (!clip_star.available) | |
969 regname = 0; | |
970 else | |
971 clip_get_selection(&clip_star); | |
972 } | |
973 else if (regname == '+') | |
974 { | |
975 if (!clip_plus.available) | |
976 regname = 0; | |
977 else | |
978 clip_get_selection(&clip_plus); | |
979 } | |
980 return regname; | |
981 } | |
982 #endif | |
983 | |
984 /* | |
985 * Obtain the contents of a "normal" register. The register is made empty. | |
986 * The returned pointer has allocated memory, use put_register() later. | |
987 */ | |
988 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
989 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
990 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
991 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 992 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
993 yankreg_T *reg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
994 int i; |
7 | 995 |
996 #ifdef FEAT_CLIPBOARD | |
997 /* When Visual area changed, may have to update selection. Obtain the | |
998 * selection too. */ | |
1435 | 999 if (name == '*' && clip_star.available) |
7 | 1000 { |
3674 | 1001 if (clip_isautosel_star()) |
1002 clip_update_selection(&clip_star); | |
1003 may_get_selection(name); | |
1004 } | |
1005 if (name == '+' && clip_plus.available) | |
1006 { | |
1007 if (clip_isautosel_plus()) | |
1008 clip_update_selection(&clip_plus); | |
7 | 1009 may_get_selection(name); |
1010 } | |
1011 #endif | |
1012 | |
1013 get_yank_register(name, 0); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1014 reg = (yankreg_T *)alloc((unsigned)sizeof(yankreg_T)); |
7 | 1015 if (reg != NULL) |
1016 { | |
1017 *reg = *y_current; | |
1018 if (copy) | |
1019 { | |
1020 /* If we run out of memory some or all of the lines are empty. */ | |
1021 if (reg->y_size == 0) | |
1022 reg->y_array = NULL; | |
1023 else | |
1024 reg->y_array = (char_u **)alloc((unsigned)(sizeof(char_u *) | |
1025 * reg->y_size)); | |
1026 if (reg->y_array != NULL) | |
1027 { | |
1028 for (i = 0; i < reg->y_size; ++i) | |
1029 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
1030 } | |
1031 } | |
1032 else | |
1033 y_current->y_array = NULL; | |
1034 } | |
1035 return (void *)reg; | |
1036 } | |
1037 | |
1038 /* | |
1451 | 1039 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1040 */ |
1041 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1042 put_register(int name, void *reg) |
7 | 1043 { |
1044 get_yank_register(name, 0); | |
1045 free_yank_all(); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1046 *y_current = *(yankreg_T *)reg; |
1451 | 1047 vim_free(reg); |
7 | 1048 |
5735 | 1049 #ifdef FEAT_CLIPBOARD |
7 | 1050 /* Send text written to clipboard register to the clipboard. */ |
1051 may_set_selection(); | |
5735 | 1052 #endif |
7 | 1053 } |
4209 | 1054 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1055 #if (defined(FEAT_CLIPBOARD) && defined(FEAT_X11) && defined(USE_SYSTEM)) \ |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1056 || defined(PROTO) |
4209 | 1057 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1058 free_register(void *reg) |
4209 | 1059 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1060 yankreg_T tmp; |
4209 | 1061 |
1062 tmp = *y_current; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1063 *y_current = *(yankreg_T *)reg; |
4209 | 1064 free_yank_all(); |
1065 vim_free(reg); | |
1066 *y_current = tmp; | |
1067 } | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1068 #endif |
7 | 1069 |
1070 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1071 /* | |
1072 * return TRUE if the current yank register has type MLINE | |
1073 */ | |
1074 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1075 yank_register_mline(int regname) |
7 | 1076 { |
1077 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1078 return FALSE; | |
1079 if (regname == '_') /* black hole is always empty */ | |
1080 return FALSE; | |
1081 get_yank_register(regname, FALSE); | |
1082 return (y_current->y_type == MLINE); | |
1083 } | |
1084 #endif | |
1085 | |
1086 /* | |
1157 | 1087 * Start or stop recording into a yank register. |
7 | 1088 * |
1157 | 1089 * Return FAIL for failure, OK otherwise. |
7 | 1090 */ |
1091 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1092 do_record(int c) |
7 | 1093 { |
1157 | 1094 char_u *p; |
1095 static int regname; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1096 yankreg_T *old_y_previous, *old_y_current; |
1157 | 1097 int retval; |
7 | 1098 |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1099 if (reg_recording == 0) /* start recording */ |
7 | 1100 { |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1101 /* registers 0-9, a-z and " are allowed */ |
7 | 1102 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) |
1103 retval = FAIL; | |
1104 else | |
1105 { | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1106 reg_recording = c; |
7 | 1107 showmode(); |
1108 regname = c; | |
1109 retval = OK; | |
1110 } | |
1111 } | |
1112 else /* stop recording */ | |
1113 { | |
1114 /* | |
1157 | 1115 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1116 * needs to be removed again to put it in a register. exec_reg then | |
1117 * adds the escaping back later. | |
7 | 1118 */ |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1119 reg_recording = 0; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1120 msg(""); |
7 | 1121 p = get_recorded(); |
1122 if (p == NULL) | |
1123 retval = FAIL; | |
1124 else | |
1125 { | |
1081 | 1126 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1127 vim_unescape_csi(p); | |
1128 | |
7 | 1129 /* |
1130 * We don't want to change the default register here, so save and | |
1131 * restore the current register name. | |
1132 */ | |
1133 old_y_previous = y_previous; | |
1134 old_y_current = y_current; | |
1135 | |
1136 retval = stuff_yank(regname, p); | |
1137 | |
1138 y_previous = old_y_previous; | |
1139 y_current = old_y_current; | |
1140 } | |
1141 } | |
1142 return retval; | |
1143 } | |
1144 | |
1145 /* | |
1146 * Stuff string "p" into yank register "regname" as a single line (append if | |
1147 * uppercase). "p" must have been alloced. | |
1148 * | |
1149 * return FAIL for failure, OK otherwise | |
1150 */ | |
1151 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1152 stuff_yank(int regname, char_u *p) |
7 | 1153 { |
1154 char_u *lp; | |
1155 char_u **pp; | |
1156 | |
1157 /* check for read-only register */ | |
1158 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1159 { | |
1160 vim_free(p); | |
1161 return FAIL; | |
1162 } | |
1163 if (regname == '_') /* black hole: don't do anything */ | |
1164 { | |
1165 vim_free(p); | |
1166 return OK; | |
1167 } | |
1168 get_yank_register(regname, TRUE); | |
1169 if (y_append && y_current->y_array != NULL) | |
1170 { | |
1171 pp = &(y_current->y_array[y_current->y_size - 1]); | |
1172 lp = lalloc((long_u)(STRLEN(*pp) + STRLEN(p) + 1), TRUE); | |
1173 if (lp == NULL) | |
1174 { | |
1175 vim_free(p); | |
1176 return FAIL; | |
1177 } | |
1178 STRCPY(lp, *pp); | |
1179 STRCAT(lp, p); | |
1180 vim_free(p); | |
1181 vim_free(*pp); | |
1182 *pp = lp; | |
1183 } | |
1184 else | |
1185 { | |
1186 free_yank_all(); | |
1187 if ((y_current->y_array = | |
1188 (char_u **)alloc((unsigned)sizeof(char_u *))) == NULL) | |
1189 { | |
1190 vim_free(p); | |
1191 return FAIL; | |
1192 } | |
1193 y_current->y_array[0] = p; | |
1194 y_current->y_size = 1; | |
1195 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
|
1196 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1197 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
|
1198 #endif |
7 | 1199 } |
1200 return OK; | |
1201 } | |
1202 | |
1893 | 1203 static int execreg_lastc = NUL; |
1204 | |
7 | 1205 /* |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1206 * Execute a yank register: copy it into the stuff buffer. |
7 | 1207 * |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1208 * Return FAIL for failure, OK otherwise. |
7 | 1209 */ |
1210 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1211 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1212 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1213 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1214 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
|
1215 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1216 { |
1217 long i; | |
1218 char_u *p; | |
1219 int retval = OK; | |
1220 int remap; | |
1221 | |
1222 if (regname == '@') /* repeat previous one */ | |
168 | 1223 { |
1893 | 1224 if (execreg_lastc == NUL) |
168 | 1225 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1226 emsg(_("E748: No previously used register")); |
168 | 1227 return FAIL; |
1228 } | |
1893 | 1229 regname = execreg_lastc; |
168 | 1230 } |
7 | 1231 /* check for valid regname */ |
1232 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) | |
168 | 1233 { |
1234 emsg_invreg(regname); | |
7 | 1235 return FAIL; |
168 | 1236 } |
1893 | 1237 execreg_lastc = regname; |
7 | 1238 |
1239 #ifdef FEAT_CLIPBOARD | |
1240 regname = may_get_selection(regname); | |
1241 #endif | |
1242 | |
1243 if (regname == '_') /* black hole: don't stuff anything */ | |
1244 return OK; | |
1245 | |
1246 #ifdef FEAT_CMDHIST | |
1247 if (regname == ':') /* use last command line */ | |
1248 { | |
1249 if (last_cmdline == NULL) | |
1250 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1251 emsg(_(e_nolastcmd)); |
7 | 1252 return FAIL; |
1253 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
1254 VIM_CLEAR(new_last_cmdline); /* don't keep the cmdline containing @: */ |
16 | 1255 /* Escape all control characters with a CTRL-V */ |
1256 p = vim_strsave_escaped_ext(last_cmdline, | |
20 | 1257 (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 | 1258 if (p != NULL) |
480 | 1259 { |
1260 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1261 * Remove it when it's already there. */ | |
1262 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1263 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1264 else |
1077 | 1265 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1266 } |
16 | 1267 vim_free(p); |
7 | 1268 } |
1269 #endif | |
1270 #ifdef FEAT_EVAL | |
1271 else if (regname == '=') | |
1272 { | |
1273 p = get_expr_line(); | |
1274 if (p == NULL) | |
1275 return FAIL; | |
1077 | 1276 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1277 vim_free(p); |
1278 } | |
1279 #endif | |
1280 else if (regname == '.') /* use last inserted text */ | |
1281 { | |
1282 p = get_last_insert_save(); | |
1283 if (p == NULL) | |
1284 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1285 emsg(_(e_noinstext)); |
7 | 1286 return FAIL; |
1287 } | |
1077 | 1288 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1289 vim_free(p); |
1290 } | |
1291 else | |
1292 { | |
1293 get_yank_register(regname, FALSE); | |
1294 if (y_current->y_array == NULL) | |
1295 return FAIL; | |
1296 | |
1297 /* Disallow remaping for ":@r". */ | |
1298 remap = colon ? REMAP_NONE : REMAP_YES; | |
1299 | |
1300 /* | |
1301 * Insert lines into typeahead buffer, from last one to first one. | |
1302 */ | |
1034 | 1303 put_reedit_in_typebuf(silent); |
7 | 1304 for (i = y_current->y_size; --i >= 0; ) |
1305 { | |
1077 | 1306 char_u *escaped; |
1307 | |
7 | 1308 /* insert NL between lines and after last line if type is MLINE */ |
1309 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1310 || addcr) | |
1311 { | |
1034 | 1312 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1313 return FAIL; |
1314 } | |
1077 | 1315 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1316 if (escaped == NULL) | |
1317 return FAIL; | |
1318 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1319 vim_free(escaped); | |
1320 if (retval == FAIL) | |
7 | 1321 return FAIL; |
1034 | 1322 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1323 == FAIL) |
1324 return FAIL; | |
1325 } | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1326 reg_executing = regname == 0 ? '"' : regname; // disable "q" command |
7 | 1327 } |
1328 return retval; | |
1329 } | |
1330 | |
1331 /* | |
1332 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1333 * used only after other typeahead has been processed. | |
1334 */ | |
1335 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1336 put_reedit_in_typebuf(int silent) |
7 | 1337 { |
1338 char_u buf[3]; | |
1339 | |
1340 if (restart_edit != NUL) | |
1341 { | |
1342 if (restart_edit == 'V') | |
1343 { | |
1344 buf[0] = 'g'; | |
1345 buf[1] = 'R'; | |
1346 buf[2] = NUL; | |
1347 } | |
1348 else | |
1349 { | |
1350 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1351 buf[1] = NUL; | |
1352 } | |
1034 | 1353 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1354 restart_edit = NUL; |
1355 } | |
1356 } | |
1357 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1358 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1359 * 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
|
1360 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1361 * 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
|
1362 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1363 */ |
7 | 1364 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1365 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1366 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1367 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1368 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1369 int silent) |
7 | 1370 { |
1371 int retval = OK; | |
1372 | |
1034 | 1373 put_reedit_in_typebuf(silent); |
7 | 1374 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1375 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1376 if (retval == OK) |
1077 | 1377 { |
1378 char_u *p; | |
1379 | |
1380 if (esc) | |
1381 p = vim_strsave_escape_csi(s); | |
1382 else | |
1383 p = s; | |
1384 if (p == NULL) | |
1385 retval = FAIL; | |
1386 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1387 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
|
1388 0, TRUE, silent); |
1077 | 1389 if (esc) |
1390 vim_free(p); | |
1391 } | |
7 | 1392 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1393 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1394 return retval; |
1395 } | |
1396 | |
1397 /* | |
1398 * Insert a yank register: copy it into the Read buffer. | |
1399 * Used by CTRL-R command and middle mouse button in insert mode. | |
1400 * | |
1401 * return FAIL for failure, OK otherwise | |
1402 */ | |
1403 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1404 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1405 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
|
1406 int literally_arg) /* insert literally, not as if typed */ |
7 | 1407 { |
1408 long i; | |
1409 int retval = OK; | |
1410 char_u *arg; | |
1411 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
|
1412 int literally = literally_arg; |
7 | 1413 |
1414 /* | |
1415 * It is possible to get into an endless loop by having CTRL-R a in | |
1416 * register a and then, in insert mode, doing CTRL-R a. | |
1417 * If you hit CTRL-C, the loop will be broken here. | |
1418 */ | |
1419 ui_breakcheck(); | |
1420 if (got_int) | |
1421 return FAIL; | |
1422 | |
1423 /* check for valid regname */ | |
1424 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1425 return FAIL; | |
1426 | |
1427 #ifdef FEAT_CLIPBOARD | |
1428 regname = may_get_selection(regname); | |
1429 #endif | |
1430 | |
1431 if (regname == '.') /* insert last inserted text */ | |
1432 retval = stuff_inserted(NUL, 1L, TRUE); | |
1433 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1434 { | |
1435 if (arg == NULL) | |
1436 return FAIL; | |
1437 stuffescaped(arg, literally); | |
1438 if (allocated) | |
1439 vim_free(arg); | |
1440 } | |
1441 else /* name or number register */ | |
1442 { | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1443 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
|
1444 literally = TRUE; |
7 | 1445 if (y_current->y_array == NULL) |
1446 retval = FAIL; | |
1447 else | |
1448 { | |
1449 for (i = 0; i < y_current->y_size; ++i) | |
1450 { | |
1451 stuffescaped(y_current->y_array[i], literally); | |
1452 /* | |
1453 * Insert a newline between lines and after last line if | |
1454 * y_type is MLINE. | |
1455 */ | |
1456 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1457 stuffcharReadbuff('\n'); | |
1458 } | |
1459 } | |
1460 } | |
1461 | |
1462 return retval; | |
1463 } | |
1464 | |
1465 /* | |
1466 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1467 * literally ("literally" TRUE) or interpret is as typed characters. | |
1468 */ | |
1469 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1470 stuffescaped(char_u *arg, int literally) |
7 | 1471 { |
1472 int c; | |
1473 char_u *start; | |
1474 | |
1475 while (*arg != NUL) | |
1476 { | |
1477 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1478 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1479 * is TRUE. */ | |
1480 start = arg; | |
1481 while ((*arg >= ' ' | |
1482 #ifndef EBCDIC | |
1483 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1484 #endif | |
1485 ) | |
1486 || (*arg == K_SPECIAL && !literally)) | |
1487 ++arg; | |
1488 if (arg > start) | |
1489 stuffReadbuffLen(start, (long)(arg - start)); | |
1490 | |
1491 /* stuff a single special character */ | |
1492 if (*arg != NUL) | |
1493 { | |
1494 #ifdef FEAT_MBYTE | |
1495 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
|
1496 c = mb_cptr2char_adv(&arg); |
7 | 1497 else |
1498 #endif | |
1499 c = *arg++; | |
1500 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1501 stuffcharReadbuff(Ctrl_V); | |
1502 stuffcharReadbuff(c); | |
1503 } | |
1504 } | |
1505 } | |
1506 | |
1507 /* | |
1157 | 1508 * If "regname" is a special register, return TRUE and store a pointer to its |
1509 * value in "argp". | |
7 | 1510 */ |
15 | 1511 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1512 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1513 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1514 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1515 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
|
1516 int errmsg) /* give error message when failing */ |
7 | 1517 { |
1518 int cnt; | |
1519 | |
1520 *argp = NULL; | |
1521 *allocated = FALSE; | |
1522 switch (regname) | |
1523 { | |
1524 case '%': /* file name */ | |
1525 if (errmsg) | |
1526 check_fname(); /* will give emsg if not set */ | |
1527 *argp = curbuf->b_fname; | |
1528 return TRUE; | |
1529 | |
1530 case '#': /* alternate file name */ | |
1531 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1532 return TRUE; | |
1533 | |
1534 #ifdef FEAT_EVAL | |
1535 case '=': /* result of expression */ | |
1536 *argp = get_expr_line(); | |
1537 *allocated = TRUE; | |
1538 return TRUE; | |
1539 #endif | |
1540 | |
1541 case ':': /* last command line */ | |
1542 if (last_cmdline == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1543 emsg(_(e_nolastcmd)); |
7 | 1544 *argp = last_cmdline; |
1545 return TRUE; | |
1546 | |
1547 case '/': /* last search-pattern */ | |
1548 if (last_search_pat() == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1549 emsg(_(e_noprevre)); |
7 | 1550 *argp = last_search_pat(); |
1551 return TRUE; | |
1552 | |
1553 case '.': /* last inserted text */ | |
1554 *argp = get_last_insert_save(); | |
1555 *allocated = TRUE; | |
1556 if (*argp == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1557 emsg(_(e_noinstext)); |
7 | 1558 return TRUE; |
1559 | |
1560 #ifdef FEAT_SEARCHPATH | |
1561 case Ctrl_F: /* Filename under cursor */ | |
1562 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1563 if (!errmsg) | |
1564 return FALSE; | |
1565 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1566 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1567 *allocated = TRUE; |
1568 return TRUE; | |
1569 #endif | |
1570 | |
1571 case Ctrl_W: /* word under cursor */ | |
1572 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1573 if (!errmsg) | |
1574 return FALSE; | |
1575 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1576 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1577 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1578 *allocated = TRUE; | |
1579 return TRUE; | |
1580 | |
13831
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1581 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
|
1582 if (!errmsg) |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1583 return FALSE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1584 |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1585 *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
|
1586 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
|
1587 return TRUE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1588 |
7 | 1589 case '_': /* black hole: always empty */ |
1590 *argp = (char_u *)""; | |
1591 return TRUE; | |
1592 } | |
1593 | |
1594 return FALSE; | |
1595 } | |
1596 | |
1597 /* | |
15 | 1598 * Paste a yank register into the command line. |
1599 * Only for non-special registers. | |
1600 * Used by CTRL-R command in command-line mode | |
7 | 1601 * insert_reg() can't be used here, because special characters from the |
1602 * register contents will be interpreted as commands. | |
1603 * | |
1604 * return FAIL for failure, OK otherwise | |
1605 */ | |
1606 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1607 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1608 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
|
1609 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
|
1610 int remcr) /* don't add CR characters */ |
7 | 1611 { |
1612 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
|
1613 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
|
1614 |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1615 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
|
1616 literally = TRUE; |
7 | 1617 if (y_current->y_array == NULL) |
1618 return FAIL; | |
1619 | |
1620 for (i = 0; i < y_current->y_size; ++i) | |
1621 { | |
1622 cmdline_paste_str(y_current->y_array[i], literally); | |
1623 | |
1015 | 1624 /* 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
|
1625 * 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
|
1626 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1627 cmdline_paste_str((char_u *)"\r", literally); |
1628 | |
1629 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1630 * lines and gets bored. */ | |
1631 ui_breakcheck(); | |
1632 if (got_int) | |
1633 return FAIL; | |
1634 } | |
1635 return OK; | |
1636 } | |
1637 | |
1638 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1639 /* | |
1640 * Adjust the register name pointed to with "rp" for the clipboard being | |
1641 * used always and the clipboard being available. | |
1642 */ | |
1643 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1644 adjust_clip_reg(int *rp) |
7 | 1645 { |
2654 | 1646 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1647 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1648 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1649 { | |
1650 if (clip_unnamed != 0) | |
1651 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1652 ? '+' : '*'; |
6116 | 1653 else |
1654 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1655 ? '+' : '*'; | |
1656 } | |
7 | 1657 if (!clip_star.available && *rp == '*') |
1658 *rp = 0; | |
1659 if (!clip_plus.available && *rp == '+') | |
1660 *rp = 0; | |
1661 } | |
1662 #endif | |
1663 | |
1664 /* | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1665 * 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
|
1666 */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1667 void |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1668 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
|
1669 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1670 int n; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1671 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1672 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
|
1673 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
|
1674 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
|
1675 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
|
1676 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
|
1677 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
|
1678 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
|
1679 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
|
1680 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1681 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1682 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1683 static void |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1684 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
|
1685 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1686 static int recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1687 dict_T *v_event; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1688 list_T *list; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1689 int n; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1690 char_u buf[NUMBUFLEN + 2]; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1691 long reglen = 0; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1692 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1693 if (recursive) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1694 return; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1695 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1696 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
|
1697 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1698 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
|
1699 if (list == NULL) |
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1700 return; |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1701 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
|
1702 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
|
1703 list->lv_lock = VAR_FIXED; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1704 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
|
1705 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1706 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
|
1707 buf[1] = NUL; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1708 dict_add_string(v_event, "regname", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1709 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1710 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
|
1711 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
|
1712 buf[2] = NUL; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1713 dict_add_string(v_event, "operator", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1714 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1715 buf[0] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1716 buf[1] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1717 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
|
1718 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1719 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
|
1720 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
|
1721 case MBLOCK: |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1722 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
|
1723 reglen + 1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1724 break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1725 } |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1726 dict_add_string(v_event, "regtype", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1727 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1728 /* 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
|
1729 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
|
1730 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1731 recursive = TRUE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1732 textlock++; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1733 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
|
1734 textlock--; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1735 recursive = FALSE; |
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 /* 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
|
1738 dict_free_contents(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1739 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
|
1740 } |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
1741 #endif |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1742 |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1743 /* |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1744 * Handle a delete operation. |
7 | 1745 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1746 * Return FAIL if undo failed, OK otherwise. |
7 | 1747 */ |
1748 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1749 op_delete(oparg_T *oap) |
7 | 1750 { |
1751 int n; | |
1752 linenr_T lnum; | |
1753 char_u *ptr; | |
1754 char_u *newp, *oldp; | |
1755 struct block_def bd; | |
1756 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1757 int did_yank = FALSE; | |
3782 | 1758 int orig_regname = oap->regname; |
7 | 1759 |
1760 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1761 return OK; | |
1762 | |
1763 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1764 if (oap->empty) | |
1765 return u_save_cursor(); | |
1766 | |
1767 if (!curbuf->b_p_ma) | |
1768 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1769 emsg(_(e_modifiable)); |
7 | 1770 return FAIL; |
1771 } | |
1772 | |
1773 #ifdef FEAT_CLIPBOARD | |
1774 adjust_clip_reg(&oap->regname); | |
1775 #endif | |
1776 | |
1777 #ifdef FEAT_MBYTE | |
1778 if (has_mbyte) | |
1779 mb_adjust_opend(oap); | |
1780 #endif | |
1781 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1782 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1783 * 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
|
1784 * 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
|
1785 * 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
|
1786 */ |
7 | 1787 if ( oap->motion_type == MCHAR |
1788 && !oap->is_VIsual | |
50 | 1789 && !oap->block_mode |
7 | 1790 && oap->line_count > 1 |
3254 | 1791 && oap->motion_force == NUL |
7 | 1792 && oap->op_type == OP_DELETE) |
1793 { | |
2957 | 1794 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1795 if (*ptr != NUL) | |
1796 ptr += oap->inclusive; | |
7 | 1797 ptr = skipwhite(ptr); |
1798 if (*ptr == NUL && inindent(0)) | |
1799 oap->motion_type = MLINE; | |
1800 } | |
1801 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1802 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1803 * 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
|
1804 * 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
|
1805 */ |
7 | 1806 if ( oap->motion_type == MCHAR |
1807 && oap->line_count == 1 | |
1808 && oap->op_type == OP_DELETE | |
1809 && *ml_get(oap->start.lnum) == NUL) | |
1810 { | |
1811 /* | |
446 | 1812 * It's an error to operate on an empty region, when 'E' included in |
7 | 1813 * 'cpoptions' (Vi compatible). |
1814 */ | |
446 | 1815 #ifdef FEAT_VIRTUALEDIT |
1816 if (virtual_op) | |
1817 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1818 * marks as if it happened. */ | |
1819 goto setmarks; | |
1820 #endif | |
7 | 1821 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1822 beep_flush(); | |
1823 return OK; | |
1824 } | |
1825 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1826 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1827 * 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
|
1828 * 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
|
1829 * 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
|
1830 */ |
7 | 1831 if (oap->regname != '_') |
1832 { | |
1833 if (oap->regname != 0) | |
1834 { | |
1835 /* check for read-only register */ | |
1836 if (!valid_yank_reg(oap->regname, TRUE)) | |
1837 { | |
1838 beep_flush(); | |
1839 return OK; | |
1840 } | |
1841 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1842 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1843 did_yank = TRUE; | |
1844 } | |
1845 | |
1846 /* | |
1847 * Put deleted text into register 1 and shift number registers if the | |
1848 * delete contains a line break, or when a regname has been specified. | |
3782 | 1849 * Use the register name from before adjust_clip_reg() may have |
1850 * changed it. | |
7 | 1851 */ |
3782 | 1852 if (orig_regname != 0 || oap->motion_type == MLINE |
7 | 1853 || oap->line_count > 1 || oap->use_reg_one) |
1854 { | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1855 shift_delete_registers(); |
7 | 1856 if (op_yank(oap, TRUE, FALSE) == OK) |
1857 did_yank = TRUE; | |
1858 } | |
1859 | |
3468 | 1860 /* Yank into small delete register when no named register specified |
1861 * and the delete is within one line. */ | |
1862 if (( | |
1863 #ifdef FEAT_CLIPBOARD | |
3584 | 1864 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1865 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1866 #endif |
1867 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1868 && oap->line_count == 1) |
1869 { | |
1870 oap->regname = '-'; | |
1871 get_yank_register(oap->regname, TRUE); | |
1872 if (op_yank(oap, TRUE, FALSE) == OK) | |
1873 did_yank = TRUE; | |
1874 oap->regname = 0; | |
1875 } | |
1876 | |
1877 /* | |
1878 * If there's too much stuff to fit in the yank register, then get a | |
1879 * confirmation before doing the delete. This is crude, but simple. | |
1880 * And it avoids doing a delete of something we can't put back if we | |
1881 * want. | |
1882 */ | |
1883 if (!did_yank) | |
1884 { | |
1885 int msg_silent_save = msg_silent; | |
1886 | |
1887 msg_silent = 0; /* must display the prompt */ | |
1888 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1889 msg_silent = msg_silent_save; | |
1890 if (n != 'y') | |
1891 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1892 emsg(_(e_abort)); |
7 | 1893 return FAIL; |
1894 } | |
1895 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1896 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1897 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1898 if (did_yank && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1899 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
|
1900 #endif |
7 | 1901 } |
1902 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1903 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1904 * 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
|
1905 */ |
7 | 1906 if (oap->block_mode) |
1907 { | |
1908 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1909 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1910 return FAIL; | |
1911 | |
1912 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1913 { | |
1914 block_prep(oap, &bd, lnum, TRUE); | |
1915 if (bd.textlen == 0) /* nothing to delete */ | |
1916 continue; | |
1917 | |
1918 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1919 if (lnum == curwin->w_cursor.lnum) | |
1920 { | |
1921 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1922 # ifdef FEAT_VIRTUALEDIT | |
1923 curwin->w_cursor.coladd = 0; | |
1924 # endif | |
1925 } | |
1926 | |
1927 /* n == number of chars deleted | |
1928 * If we delete a TAB, it may be replaced by several characters. | |
1929 * Thus the number of characters may increase! | |
1930 */ | |
1931 n = bd.textlen - bd.startspaces - bd.endspaces; | |
1932 oldp = ml_get(lnum); | |
1933 newp = alloc_check((unsigned)STRLEN(oldp) + 1 - n); | |
1934 if (newp == NULL) | |
1935 continue; | |
1936 /* copy up to deleted part */ | |
1937 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1938 /* insert spaces */ | |
6929 | 1939 vim_memset(newp + bd.textcol, ' ', |
7 | 1940 (size_t)(bd.startspaces + bd.endspaces)); |
1941 /* copy the part after the deleted part */ | |
1942 oldp += bd.textcol + bd.textlen; | |
1622 | 1943 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1944 /* replace the line */ |
1945 ml_replace(lnum, newp, FALSE); | |
1946 } | |
1947 | |
1948 check_cursor_col(); | |
1949 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1950 oap->end.lnum + 1, 0L); | |
1951 oap->line_count = 0; /* no lines deleted */ | |
1952 } | |
5735 | 1953 else if (oap->motion_type == MLINE) |
7 | 1954 { |
1955 if (oap->op_type == OP_CHANGE) | |
1956 { | |
1957 /* Delete the lines except the first one. Temporarily move the | |
1958 * cursor to the next line. Save the current line number, if the | |
1959 * last line is deleted it may be changed. | |
1960 */ | |
1961 if (oap->line_count > 1) | |
1962 { | |
1963 lnum = curwin->w_cursor.lnum; | |
1964 ++curwin->w_cursor.lnum; | |
1965 del_lines((long)(oap->line_count - 1), TRUE); | |
1966 curwin->w_cursor.lnum = lnum; | |
1967 } | |
1968 if (u_save_cursor() == FAIL) | |
1969 return FAIL; | |
1970 if (curbuf->b_p_ai) /* don't delete indent */ | |
1971 { | |
1972 beginline(BL_WHITE); /* cursor on first non-white */ | |
1973 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1974 ai_col = curwin->w_cursor.col; | |
1975 } | |
1976 else | |
1977 beginline(0); /* cursor in column 0 */ | |
1978 truncate_line(FALSE); /* delete the rest of the line */ | |
1979 /* leave cursor past last char in line */ | |
1980 if (oap->line_count > 1) | |
1981 u_clearline(); /* "U" command not possible after "2cc" */ | |
1982 } | |
1983 else | |
1984 { | |
1985 del_lines(oap->line_count, TRUE); | |
1986 beginline(BL_WHITE | BL_FIX); | |
1987 u_clearline(); /* "U" command not possible after "dd" */ | |
1988 } | |
1989 } | |
1990 else | |
1991 { | |
1992 #ifdef FEAT_VIRTUALEDIT | |
1993 if (virtual_op) | |
1994 { | |
1995 int endcol = 0; | |
1996 | |
1997 /* For virtualedit: break the tabs that are partly included. */ | |
1998 if (gchar_pos(&oap->start) == '\t') | |
1999 { | |
2000 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
2001 return FAIL; | |
2002 if (oap->line_count == 1) | |
2003 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
2004 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
2005 oap->start = curwin->w_cursor; | |
2006 if (oap->line_count == 1) | |
2007 { | |
2008 coladvance(endcol); | |
2009 oap->end.col = curwin->w_cursor.col; | |
2010 oap->end.coladd = curwin->w_cursor.coladd; | |
2011 curwin->w_cursor = oap->start; | |
2012 } | |
2013 } | |
2014 | |
2015 /* Break a tab only when it's included in the area. */ | |
2016 if (gchar_pos(&oap->end) == '\t' | |
2017 && (int)oap->end.coladd < oap->inclusive) | |
2018 { | |
2019 /* save last line for undo */ | |
2020 if (u_save((linenr_T)(oap->end.lnum - 1), | |
2021 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2022 return FAIL; | |
2023 curwin->w_cursor = oap->end; | |
2024 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
2025 oap->end = curwin->w_cursor; | |
2026 curwin->w_cursor = oap->start; | |
2027 } | |
2028 } | |
2029 #endif | |
2030 | |
2031 if (oap->line_count == 1) /* delete characters within one line */ | |
2032 { | |
2033 if (u_save_cursor() == FAIL) /* save line for undo */ | |
2034 return FAIL; | |
2035 | |
2036 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 2037 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 2038 && oap->op_type == OP_CHANGE |
2039 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 2040 && !oap->is_VIsual) |
7 | 2041 display_dollar(oap->end.col - !oap->inclusive); |
2042 | |
2043 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
2044 | |
2045 #ifdef FEAT_VIRTUALEDIT | |
2046 if (virtual_op) | |
2047 { | |
2048 /* fix up things for virtualedit-delete: | |
2049 * break the tabs which are going to get in our way | |
2050 */ | |
2051 char_u *curline = ml_get_curline(); | |
2052 int len = (int)STRLEN(curline); | |
2053 | |
2054 if (oap->end.coladd != 0 | |
2055 && (int)oap->end.col >= len - 1 | |
2056 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
2057 n++; | |
2058 /* Delete at least one char (e.g, when on a control char). */ | |
2059 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
2060 n = 1; | |
2061 | |
2062 /* When deleted a char in the line, reset coladd. */ | |
2063 if (gchar_cursor() != NUL) | |
2064 curwin->w_cursor.coladd = 0; | |
2065 } | |
2066 #endif | |
6826 | 2067 (void)del_bytes((long)n, !virtual_op, |
2068 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 2069 } |
2070 else /* delete characters between lines */ | |
2071 { | |
2072 pos_T curpos; | |
2073 | |
2074 /* save deleted and changed lines for undo */ | |
2075 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
2076 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
2077 return FAIL; | |
2078 | |
2079 truncate_line(TRUE); /* delete from cursor to end of line */ | |
2080 | |
2081 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
2082 ++curwin->w_cursor.lnum; | |
2083 del_lines((long)(oap->line_count - 2), FALSE); | |
2084 | |
6826 | 2085 /* delete from start of line until op_end */ |
2957 | 2086 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 2087 curwin->w_cursor.col = 0; |
2088 (void)del_bytes((long)n, !virtual_op, | |
2089 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
2090 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
2091 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 2092 } |
2093 } | |
2094 | |
2095 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
2096 | |
446 | 2097 #ifdef FEAT_VIRTUALEDIT |
2098 setmarks: | |
2099 #endif | |
7 | 2100 if (oap->block_mode) |
2101 { | |
2102 curbuf->b_op_end.lnum = oap->end.lnum; | |
2103 curbuf->b_op_end.col = oap->start.col; | |
2104 } | |
2105 else | |
2106 curbuf->b_op_end = oap->start; | |
2107 curbuf->b_op_start = oap->start; | |
2108 | |
2109 return OK; | |
2110 } | |
2111 | |
2112 #ifdef FEAT_MBYTE | |
2113 /* | |
2114 * Adjust end of operating area for ending on a multi-byte character. | |
2115 * Used for deletion. | |
2116 */ | |
2117 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2118 mb_adjust_opend(oparg_T *oap) |
7 | 2119 { |
2120 char_u *p; | |
2121 | |
2122 if (oap->inclusive) | |
2123 { | |
2124 p = ml_get(oap->end.lnum); | |
2125 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2126 } | |
2127 } | |
2128 #endif | |
2129 | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2130 |
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2131 #ifdef FEAT_MBYTE |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2132 /* |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2133 * Replace the character under the cursor with "c". |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2134 * This takes care of multi-byte characters. |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2135 */ |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2136 static void |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2137 replace_character(int c) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2138 { |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2139 int n = State; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2140 |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2141 State = REPLACE; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2142 ins_char(c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2143 State = n; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2144 /* Backup to the replaced character. */ |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2145 dec_cursor(); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2146 } |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2147 #endif |
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2148 |
7 | 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); | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2334 replace_character(c); |
7 | 2335 } |
2336 else | |
2337 #endif | |
2338 { | |
2339 #ifdef FEAT_VIRTUALEDIT | |
2340 if (n == TAB) | |
2341 { | |
2342 int end_vcol = 0; | |
2343 | |
2344 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2345 { | |
2346 /* oap->end has to be recalculated when | |
2347 * the tab breaks */ | |
2348 end_vcol = getviscol2(oap->end.col, | |
2349 oap->end.coladd); | |
2350 } | |
2351 coladvance_force(getviscol()); | |
2352 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2353 getvpos(&oap->end, end_vcol); | |
2354 } | |
2355 #endif | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2356 PBYTE(curwin->w_cursor, c); |
7 | 2357 } |
2358 } | |
2359 #ifdef FEAT_VIRTUALEDIT | |
2360 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2361 { | |
2362 int virtcols = oap->end.coladd; | |
2363 | |
2364 if (curwin->w_cursor.lnum == oap->start.lnum | |
2365 && oap->start.col == oap->end.col && oap->start.coladd) | |
2366 virtcols -= oap->start.coladd; | |
2367 | |
2368 /* oap->end has been trimmed so it's effectively inclusive; | |
2369 * as a result an extra +1 must be counted so we don't | |
2370 * trample the NUL byte. */ | |
2371 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2372 curwin->w_cursor.col -= (virtcols + 1); | |
2373 for (; virtcols >= 0; virtcols--) | |
2374 { | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2375 # ifdef FEAT_MBYTE |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2376 if ((*mb_char2len)(c) > 1) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2377 replace_character(c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2378 else |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2379 # endif |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2380 PBYTE(curwin->w_cursor, c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2381 if (inc(&curwin->w_cursor) == -1) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2382 break; |
7 | 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 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2404 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2405 |
7 | 2406 /* |
2407 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2408 */ | |
2409 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2410 op_tilde(oparg_T *oap) |
7 | 2411 { |
2412 pos_T pos; | |
2413 struct block_def bd; | |
1528 | 2414 int did_change = FALSE; |
7 | 2415 |
2416 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2417 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2418 return; | |
2419 | |
2420 pos = oap->start; | |
2421 if (oap->block_mode) /* Visual block mode */ | |
2422 { | |
2423 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2424 { | |
1766 | 2425 int one_change; |
2426 | |
7 | 2427 block_prep(oap, &bd, pos.lnum, FALSE); |
2428 pos.col = bd.textcol; | |
1766 | 2429 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2430 did_change |= one_change; | |
1525 | 2431 |
5735 | 2432 #ifdef FEAT_NETBEANS_INTG |
2210 | 2433 if (netbeans_active() && one_change) |
7 | 2434 { |
2435 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2436 | |
33 | 2437 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2438 (long)bd.textlen); | |
7 | 2439 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2440 &ptr[bd.textcol], bd.textlen); |
7 | 2441 } |
5735 | 2442 #endif |
7 | 2443 } |
2444 if (did_change) | |
2445 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2446 } | |
2447 else /* not block mode */ | |
2448 { | |
2449 if (oap->motion_type == MLINE) | |
2450 { | |
2451 oap->start.col = 0; | |
2452 pos.col = 0; | |
2453 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2454 if (oap->end.col) | |
2455 --oap->end.col; | |
2456 } | |
2457 else if (!oap->inclusive) | |
2458 dec(&(oap->end)); | |
2459 | |
1528 | 2460 if (pos.lnum == oap->end.lnum) |
2461 did_change = swapchars(oap->op_type, &pos, | |
2462 oap->end.col - pos.col + 1); | |
2463 else | |
2464 for (;;) | |
2465 { | |
2466 did_change |= swapchars(oap->op_type, &pos, | |
2467 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2468 (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
|
2469 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 2470 break; |
2471 } | |
7 | 2472 if (did_change) |
2473 { | |
2474 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2475 0L); | |
2476 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2477 if (netbeans_active() && did_change) |
7 | 2478 { |
2479 char_u *ptr; | |
2480 int count; | |
2481 | |
2482 pos = oap->start; | |
2483 while (pos.lnum < oap->end.lnum) | |
2484 { | |
2485 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2486 count = (int)STRLEN(ptr) - pos.col; |
33 | 2487 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2488 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2489 &ptr[pos.col], count); |
7 | 2490 pos.col = 0; |
2491 pos.lnum++; | |
2492 } | |
2493 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2494 count = oap->end.col - pos.col + 1; | |
33 | 2495 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2496 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2497 &ptr[pos.col], count); |
7 | 2498 } |
2499 #endif | |
2500 } | |
2501 } | |
2502 | |
2503 if (!did_change && oap->is_VIsual) | |
2504 /* No change: need to remove the Visual selection */ | |
2505 redraw_curbuf_later(INVERTED); | |
2506 | |
2507 /* | |
2508 * Set '[ and '] marks. | |
2509 */ | |
2510 curbuf->b_op_start = oap->start; | |
2511 curbuf->b_op_end = oap->end; | |
2512 | |
2513 if (oap->line_count > p_report) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
2514 smsg(NGETTEXT("%ld line changed", "%ld lines changed", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2515 oap->line_count), oap->line_count); |
7 | 2516 } |
2517 | |
2518 /* | |
1525 | 2519 * Invoke swapchar() on "length" bytes at position "pos". |
2520 * "pos" is advanced to just after the changed characters. | |
2521 * "length" is rounded up to include the whole last multi-byte character. | |
2522 * Also works correctly when the number of bytes changes. | |
2523 * Returns TRUE if some character was changed. | |
2524 */ | |
2525 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2526 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2527 { |
2528 int todo; | |
2529 int did_change = 0; | |
2530 | |
2531 for (todo = length; todo > 0; --todo) | |
2532 { | |
2533 # ifdef FEAT_MBYTE | |
2534 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2535 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2536 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2537 |
1525 | 2538 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2539 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2540 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2541 } |
1525 | 2542 # endif |
2543 did_change |= swapchar(op_type, pos); | |
2544 if (inc(pos) == -1) /* at end of file */ | |
2545 break; | |
2546 } | |
2547 return did_change; | |
2548 } | |
2549 | |
2550 /* | |
7 | 2551 * If op_type == OP_UPPER: make uppercase, |
2552 * if op_type == OP_LOWER: make lowercase, | |
2553 * if op_type == OP_ROT13: do rot13 encoding, | |
2554 * else swap case of character at 'pos' | |
2555 * returns TRUE when something actually changed. | |
2556 */ | |
2557 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2558 swapchar(int op_type, pos_T *pos) |
7 | 2559 { |
2560 int c; | |
2561 int nc; | |
2562 | |
2563 c = gchar_pos(pos); | |
2564 | |
2565 /* Only do rot13 encoding for ASCII characters. */ | |
2566 if (c >= 0x80 && op_type == OP_ROT13) | |
2567 return FALSE; | |
2568 | |
2569 #ifdef FEAT_MBYTE | |
1525 | 2570 if (op_type == OP_UPPER && c == 0xdf |
2571 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2572 { |
2573 pos_T sp = curwin->w_cursor; | |
2574 | |
2575 /* Special handling of German sharp s: change to "SS". */ | |
2576 curwin->w_cursor = *pos; | |
2577 del_char(FALSE); | |
2578 ins_char('S'); | |
2579 ins_char('S'); | |
2580 curwin->w_cursor = sp; | |
2581 inc(pos); | |
2582 } | |
2583 | |
7 | 2584 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2585 return FALSE; | |
2586 #endif | |
2587 nc = c; | |
2588 if (MB_ISLOWER(c)) | |
2589 { | |
2590 if (op_type == OP_ROT13) | |
2591 nc = ROT13(c, 'a'); | |
2592 else if (op_type != OP_LOWER) | |
2593 nc = MB_TOUPPER(c); | |
2594 } | |
2595 else if (MB_ISUPPER(c)) | |
2596 { | |
2597 if (op_type == OP_ROT13) | |
2598 nc = ROT13(c, 'A'); | |
2599 else if (op_type != OP_UPPER) | |
2600 nc = MB_TOLOWER(c); | |
2601 } | |
2602 if (nc != c) | |
2603 { | |
2604 #ifdef FEAT_MBYTE | |
2605 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2606 { | |
2607 pos_T sp = curwin->w_cursor; | |
2608 | |
2609 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2610 /* 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
|
2611 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2612 ins_char(nc); |
2613 curwin->w_cursor = sp; | |
2614 } | |
2615 else | |
2616 #endif | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2617 PBYTE(*pos, nc); |
7 | 2618 return TRUE; |
2619 } | |
2620 return FALSE; | |
2621 } | |
2622 | |
2623 /* | |
2624 * op_insert - Insert and append operators for Visual mode. | |
2625 */ | |
2626 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2627 op_insert(oparg_T *oap, long count1) |
7 | 2628 { |
2629 long ins_len, pre_textlen = 0; | |
2630 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
2631 colnr_T ind_pre = 0, ind_post; |
7 | 2632 struct block_def bd; |
2633 int i; | |
6579 | 2634 pos_T t1; |
7 | 2635 |
2636 /* edit() changes this - record it for OP_APPEND */ | |
2637 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2638 | |
2639 /* vis block is still marked. Get rid of it now. */ | |
2640 curwin->w_cursor.lnum = oap->start.lnum; | |
2641 update_screen(INVERTED); | |
2642 | |
2643 if (oap->block_mode) | |
2644 { | |
2645 #ifdef FEAT_VIRTUALEDIT | |
2646 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2647 * doing block_prep(). When only "block" is used, virtual edit is | |
2648 * already disabled, but still need it when calling | |
2649 * coladvance_force(). */ | |
2650 if (curwin->w_cursor.coladd > 0) | |
2651 { | |
2652 int old_ve_flags = ve_flags; | |
2653 | |
2654 ve_flags = VE_ALL; | |
2655 if (u_save_cursor() == FAIL) | |
2656 return; | |
2657 coladvance_force(oap->op_type == OP_APPEND | |
2658 ? oap->end_vcol + 1 : getviscol()); | |
2659 if (oap->op_type == OP_APPEND) | |
2660 --curwin->w_cursor.col; | |
2661 ve_flags = old_ve_flags; | |
2662 } | |
2663 #endif | |
2664 /* Get the info about the block before entering the text */ | |
2665 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
|
2666 /* 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
|
2667 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 2668 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
|
2669 |
7 | 2670 if (oap->op_type == OP_APPEND) |
2671 firstline += bd.textlen; | |
2672 pre_textlen = (long)STRLEN(firstline); | |
2673 } | |
2674 | |
2675 if (oap->op_type == OP_APPEND) | |
2676 { | |
2677 if (oap->block_mode | |
2678 #ifdef FEAT_VIRTUALEDIT | |
2679 && curwin->w_cursor.coladd == 0 | |
2680 #endif | |
2681 ) | |
2682 { | |
2683 /* Move the cursor to the character right of the block. */ | |
2684 curwin->w_set_curswant = TRUE; | |
2685 while (*ml_get_cursor() != NUL | |
2686 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2687 ++curwin->w_cursor.col; | |
2688 if (bd.is_short && !bd.is_MAX) | |
2689 { | |
2690 /* First line was too short, make it longer and adjust the | |
2691 * values in "bd". */ | |
2692 if (u_save_cursor() == FAIL) | |
2693 return; | |
2694 for (i = 0; i < bd.endspaces; ++i) | |
2695 ins_char(' '); | |
2696 bd.textlen += bd.endspaces; | |
2697 } | |
2698 } | |
2699 else | |
2700 { | |
2701 curwin->w_cursor = oap->end; | |
893 | 2702 check_cursor_col(); |
7 | 2703 |
2704 /* 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
|
2705 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2706 && oap->start_vcol != oap->end_vcol) |
2707 inc_cursor(); | |
2708 } | |
2709 } | |
2710 | |
6579 | 2711 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
|
2712 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 2713 |
6579 | 2714 /* When a tab was inserted, and the characters in front of the tab |
2715 * have been converted to a tab as well, the column of the cursor | |
2716 * might have actually been reduced, so need to adjust here. */ | |
2717 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
|
2718 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 2719 oap->start = curbuf->b_op_start_orig; |
2720 | |
1477 | 2721 /* If user has moved off this line, we don't know what to do, so do |
2722 * nothing. | |
2723 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2724 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2725 return; |
2726 | |
2727 if (oap->block_mode) | |
2728 { | |
2729 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
|
2730 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
|
2731 size_t len; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2732 int add; |
7 | 2733 |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2734 /* 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
|
2735 * 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
|
2736 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2737 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
|
2738 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2739 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2740 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
|
2741 did_indent = TRUE; |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2742 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2743 |
5471 | 2744 /* 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
|
2745 * 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
|
2746 * 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
|
2747 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
|
2748 && !bd.is_MAX && !did_indent) |
5471 | 2749 { |
2750 if (oap->op_type == OP_INSERT | |
5730 | 2751 && oap->start.col |
2752 #ifdef FEAT_VIRTUALEDIT | |
2753 + oap->start.coladd | |
2754 #endif | |
2755 != curbuf->b_op_start_orig.col | |
2756 #ifdef FEAT_VIRTUALEDIT | |
2757 + curbuf->b_op_start_orig.coladd | |
2758 #endif | |
2759 ) | |
5471 | 2760 { |
6579 | 2761 int t = getviscol2(curbuf->b_op_start_orig.col, |
15428
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2762 #ifdef FEAT_VIRTUALEDIT |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2763 curbuf->b_op_start_orig.coladd |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2764 #else |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2765 0 |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2766 #endif |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2767 ); |
5680 | 2768 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2769 pre_textlen -= t - oap->start_vcol; |
2770 oap->start_vcol = t; | |
5471 | 2771 } |
2772 else if (oap->op_type == OP_APPEND | |
5730 | 2773 && oap->end.col |
2774 #ifdef FEAT_VIRTUALEDIT | |
2775 + oap->end.coladd | |
2776 #endif | |
2777 >= curbuf->b_op_start_orig.col | |
2778 #ifdef FEAT_VIRTUALEDIT | |
2779 + curbuf->b_op_start_orig.coladd | |
2780 #endif | |
2781 ) | |
5471 | 2782 { |
6579 | 2783 int t = getviscol2(curbuf->b_op_start_orig.col, |
15428
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2784 #ifdef FEAT_VIRTUALEDIT |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2785 curbuf->b_op_start_orig.coladd |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2786 #else |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2787 0 |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2788 #endif |
eae582bfb293
patch 8.1.0722: cannot build without the virtualedit feature
Bram Moolenaar <Bram@vim.org>
parents:
15422
diff
changeset
|
2789 ); |
5680 | 2790 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2791 /* reset pre_textlen to the value of OP_INSERT */ |
2792 pre_textlen += bd.textlen; | |
6579 | 2793 pre_textlen -= t - oap->start_vcol; |
2794 oap->start_vcol = t; | |
5471 | 2795 oap->op_type = OP_INSERT; |
2796 } | |
2797 } | |
2798 | |
7 | 2799 /* |
2800 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2801 * tabs. Get the starting column again and correct the length. |
7 | 2802 * Don't do this when "$" used, end-of-line will have changed. |
2803 */ | |
2804 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2805 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2806 { | |
2807 if (oap->op_type == OP_APPEND) | |
2808 { | |
2809 pre_textlen += bd2.textlen - bd.textlen; | |
2810 if (bd2.endspaces) | |
2811 --bd2.textlen; | |
2812 } | |
2813 bd.textcol = bd2.textcol; | |
2814 bd.textlen = bd2.textlen; | |
2815 } | |
2816 | |
2817 /* | |
2818 * Subsequent calls to ml_get() flush the firstline data - take a | |
2819 * copy of the required string. | |
2820 */ | |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2821 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
|
2822 len = STRLEN(firstline); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2823 add = bd.textcol; |
7 | 2824 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
|
2825 add += bd.textlen; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2826 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
|
2827 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
|
2828 else |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2829 firstline += add; |
3421 | 2830 if (pre_textlen >= 0 |
2831 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2832 { |
2833 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2834 if (ins_text != NULL) | |
2835 { | |
2836 /* block handled here */ | |
2837 if (u_save(oap->start.lnum, | |
2838 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2839 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2840 &bd); | |
2841 | |
2842 curwin->w_cursor.col = oap->start.col; | |
2843 check_cursor(); | |
2844 vim_free(ins_text); | |
2845 } | |
2846 } | |
2847 } | |
2848 } | |
2849 | |
2850 /* | |
2851 * op_change - handle a change operation | |
2852 * | |
2853 * return TRUE if edit() returns because of a CTRL-O command | |
2854 */ | |
2855 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2856 op_change(oparg_T *oap) |
7 | 2857 { |
2858 colnr_T l; | |
2859 int retval; | |
2860 long offset; | |
2861 linenr_T linenr; | |
1392 | 2862 long ins_len; |
2863 long pre_textlen = 0; | |
2864 long pre_indent = 0; | |
7 | 2865 char_u *firstline; |
2866 char_u *ins_text, *newp, *oldp; | |
2867 struct block_def bd; | |
2868 | |
2869 l = oap->start.col; | |
2870 if (oap->motion_type == MLINE) | |
2871 { | |
2872 l = 0; | |
2873 #ifdef FEAT_SMARTINDENT | |
2874 if (!p_paste && curbuf->b_p_si | |
2875 # ifdef FEAT_CINDENT | |
2876 && !curbuf->b_p_cin | |
2877 # endif | |
2878 ) | |
2879 can_si = TRUE; /* It's like opening a new line, do si */ | |
2880 #endif | |
2881 } | |
2882 | |
2883 /* First delete the text in the region. In an empty buffer only need to | |
2884 * save for undo */ | |
2885 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2886 { | |
2887 if (u_save_cursor() == FAIL) | |
2888 return FALSE; | |
2889 } | |
2890 else if (op_delete(oap) == FAIL) | |
2891 return FALSE; | |
2892 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2893 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2894 && !virtual_op) |
2895 inc_cursor(); | |
2896 | |
2897 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2898 /* skip blank lines too */ | |
2899 if (oap->block_mode) | |
2900 { | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2901 #ifdef FEAT_VIRTUALEDIT |
7 | 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()); | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
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 | |
2913 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2914 if (oap->motion_type == MLINE) | |
2915 fix_indent(); | |
2916 #endif | |
2917 | |
2918 retval = edit(NUL, FALSE, (linenr_T)1); | |
2919 | |
2920 /* | |
39 | 2921 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2922 * block. |
1477 | 2923 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2924 */ |
1477 | 2925 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2926 { |
1392 | 2927 /* Auto-indenting may have changed the indent. If the cursor was past |
2928 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2929 firstline = ml_get(oap->start.lnum); |
1403 | 2930 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2931 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2932 long new_indent = (long)getwhitecols(firstline); |
1392 | 2933 |
2934 pre_textlen += new_indent - pre_indent; | |
2935 bd.textcol += new_indent - pre_indent; | |
2936 } | |
2937 | |
2938 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2939 if (ins_len > 0) | |
2940 { | |
2941 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2942 * copy of the inserted text. */ | |
7 | 2943 if ((ins_text = alloc_check((unsigned)(ins_len + 1))) != NULL) |
2944 { | |
419 | 2945 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2946 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2947 linenr++) | |
2948 { | |
2949 block_prep(oap, &bd, linenr, TRUE); | |
2950 if (!bd.is_short || virtual_op) | |
2951 { | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2952 #ifdef FEAT_VIRTUALEDIT |
7 | 2953 pos_T vpos; |
2954 | |
2955 /* If the block starts in virtual space, count the | |
2956 * initial coladd offset as part of "startspaces" */ | |
2957 if (bd.is_short) | |
2958 { | |
1982 | 2959 vpos.lnum = linenr; |
7 | 2960 (void)getvpos(&vpos, oap->start_vcol); |
2961 } | |
2962 else | |
2963 vpos.coladd = 0; | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2964 #endif |
7 | 2965 oldp = ml_get(linenr); |
2966 newp = alloc_check((unsigned)(STRLEN(oldp) | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2967 #ifdef FEAT_VIRTUALEDIT |
7 | 2968 + vpos.coladd |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2969 #endif |
7 | 2970 + ins_len + 1)); |
2971 if (newp == NULL) | |
2972 continue; | |
2973 /* copy up to block start */ | |
2974 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2975 offset = bd.textcol; | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2976 #ifdef FEAT_VIRTUALEDIT |
6929 | 2977 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2978 offset += vpos.coladd; |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2979 #endif |
7 | 2980 mch_memmove(newp + offset, ins_text, (size_t)ins_len); |
2981 offset += ins_len; | |
2982 oldp += bd.textcol; | |
1622 | 2983 STRMOVE(newp + offset, oldp); |
7 | 2984 ml_replace(linenr, newp, FALSE); |
2985 } | |
2986 } | |
2987 check_cursor(); | |
2988 | |
2989 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2990 } | |
2991 vim_free(ins_text); | |
2992 } | |
2993 } | |
2994 | |
2995 return retval; | |
2996 } | |
2997 | |
2998 /* | |
2999 * set all the yank registers to empty (called from main()) | |
3000 */ | |
3001 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3002 init_yank(void) |
7 | 3003 { |
3004 int i; | |
3005 | |
3006 for (i = 0; i < NUM_REGISTERS; ++i) | |
3007 y_regs[i].y_array = NULL; | |
3008 } | |
3009 | |
356 | 3010 #if defined(EXITFREE) || defined(PROTO) |
3011 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3012 clear_registers(void) |
356 | 3013 { |
3014 int i; | |
3015 | |
3016 for (i = 0; i < NUM_REGISTERS; ++i) | |
3017 { | |
3018 y_current = &y_regs[i]; | |
3019 if (y_current->y_array != NULL) | |
3020 free_yank_all(); | |
3021 } | |
3022 } | |
3023 #endif | |
3024 | |
7 | 3025 /* |
3026 * Free "n" lines from the current yank register. | |
3027 * Called for normal freeing and in case of error. | |
3028 */ | |
3029 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3030 free_yank(long n) |
7 | 3031 { |
3032 if (y_current->y_array != NULL) | |
3033 { | |
3034 long i; | |
3035 | |
3036 for (i = n; --i >= 0; ) | |
3037 { | |
3038 #ifdef AMIGA /* only for very slow machines */ | |
3039 if ((i & 1023) == 1023) /* this may take a while */ | |
3040 { | |
3041 /* | |
3042 * This message should never cause a hit-return message. | |
3043 * Overwrite this message with any next message. | |
3044 */ | |
3045 ++no_wait_return; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3046 smsg(_("freeing %ld lines"), i + 1); |
7 | 3047 --no_wait_return; |
3048 msg_didout = FALSE; | |
3049 msg_col = 0; | |
3050 } | |
3051 #endif | |
3052 vim_free(y_current->y_array[i]); | |
3053 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
3054 VIM_CLEAR(y_current->y_array); |
7 | 3055 #ifdef AMIGA |
3056 if (n >= 1000) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
3057 msg(""); |
7 | 3058 #endif |
3059 } | |
3060 } | |
3061 | |
3062 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3063 free_yank_all(void) |
7 | 3064 { |
3065 free_yank(y_current->y_size); | |
3066 } | |
3067 | |
3068 /* | |
3069 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
3070 * If we are to append (uppercase register), we first yank into a new yank | |
3071 * register and then concatenate the old and the new one (so we keep the old | |
3072 * one in case of out-of-memory). | |
3073 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
3074 * Return FAIL for failure, OK otherwise. |
7 | 3075 */ |
3076 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3077 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 3078 { |
3079 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
|
3080 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
|
3081 yankreg_T newreg; /* new yank register when appending */ |
7 | 3082 char_u **new_ptr; |
3083 linenr_T lnum; /* current line number */ | |
3084 long j; | |
3085 int yanktype = oap->motion_type; | |
3086 long yanklines = oap->line_count; | |
3087 linenr_T yankendlnum = oap->end.lnum; | |
3088 char_u *p; | |
3089 char_u *pnew; | |
3090 struct block_def bd; | |
2658 | 3091 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 3092 int did_star = FALSE; |
2658 | 3093 #endif |
7 | 3094 |
3095 /* check for read-only register */ | |
3096 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
3097 { | |
3098 beep_flush(); | |
3099 return FAIL; | |
3100 } | |
3101 if (oap->regname == '_') /* black hole: nothing to do */ | |
3102 return OK; | |
3103 | |
3104 #ifdef FEAT_CLIPBOARD | |
3105 if (!clip_star.available && oap->regname == '*') | |
3106 oap->regname = 0; | |
3107 else if (!clip_plus.available && oap->regname == '+') | |
3108 oap->regname = 0; | |
3109 #endif | |
3110 | |
3111 if (!deleting) /* op_delete() already set y_current */ | |
3112 get_yank_register(oap->regname, TRUE); | |
3113 | |
3114 curr = y_current; | |
3115 /* append to existing contents */ | |
3116 if (y_append && y_current->y_array != NULL) | |
3117 y_current = &newreg; | |
3118 else | |
3119 free_yank_all(); /* free previously yanked lines */ | |
3120 | |
593 | 3121 /* |
3122 * If the cursor was in column 1 before and after the movement, and the | |
3123 * operator is not inclusive, the yank is always linewise. | |
3124 */ | |
7 | 3125 if ( oap->motion_type == MCHAR |
3126 && oap->start.col == 0 | |
3127 && !oap->inclusive | |
3128 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 3129 && !oap->block_mode |
7 | 3130 && oap->end.col == 0 |
3131 && yanklines > 1) | |
3132 { | |
3133 yanktype = MLINE; | |
3134 --yankendlnum; | |
3135 --yanklines; | |
3136 } | |
3137 | |
3138 y_current->y_size = yanklines; | |
3139 y_current->y_type = yanktype; /* set the yank register type */ | |
3140 y_current->y_width = 0; | |
3141 y_current->y_array = (char_u **)lalloc_clear((long_u)(sizeof(char_u *) * | |
3142 yanklines), TRUE); | |
3143 if (y_current->y_array == NULL) | |
3144 { | |
3145 y_current = curr; | |
3146 return FAIL; | |
3147 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3148 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3149 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
|
3150 #endif |
7 | 3151 |
3152 y_idx = 0; | |
3153 lnum = oap->start.lnum; | |
3154 | |
3155 if (oap->block_mode) | |
3156 { | |
3157 /* Visual block mode */ | |
3158 y_current->y_type = MBLOCK; /* set the yank register type */ | |
3159 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
3160 | |
3161 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3162 y_current->y_width--; | |
3163 } | |
3164 | |
3165 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3166 { | |
3167 switch (y_current->y_type) | |
3168 { | |
3169 case MBLOCK: | |
3170 block_prep(oap, &bd, lnum, FALSE); | |
3171 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3172 goto fail; | |
3173 break; | |
3174 | |
3175 case MLINE: | |
3176 if ((y_current->y_array[y_idx] = | |
3177 vim_strsave(ml_get(lnum))) == NULL) | |
3178 goto fail; | |
3179 break; | |
3180 | |
3181 case MCHAR: | |
3182 { | |
3183 colnr_T startcol = 0, endcol = MAXCOL; | |
3184 #ifdef FEAT_VIRTUALEDIT | |
3185 int is_oneChar = FALSE; | |
3186 colnr_T cs, ce; | |
3187 #endif | |
3188 p = ml_get(lnum); | |
3189 bd.startspaces = 0; | |
3190 bd.endspaces = 0; | |
3191 | |
3192 if (lnum == oap->start.lnum) | |
3193 { | |
3194 startcol = oap->start.col; | |
3195 #ifdef FEAT_VIRTUALEDIT | |
3196 if (virtual_op) | |
3197 { | |
3198 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3199 if (ce != cs && oap->start.coladd > 0) | |
3200 { | |
3201 /* Part of a tab selected -- but don't | |
3202 * double-count it. */ | |
3203 bd.startspaces = (ce - cs + 1) | |
3204 - oap->start.coladd; | |
3205 startcol++; | |
3206 } | |
3207 } | |
3208 #endif | |
3209 } | |
3210 | |
3211 if (lnum == oap->end.lnum) | |
3212 { | |
3213 endcol = oap->end.col; | |
3214 #ifdef FEAT_VIRTUALEDIT | |
3215 if (virtual_op) | |
3216 { | |
3217 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3218 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3219 # ifdef FEAT_MBYTE | |
3220 /* Don't add space for double-wide | |
3221 * char; endcol will be on last byte | |
3222 * of multi-byte char. */ | |
3223 && (*mb_head_off)(p, p + endcol) == 0 | |
3224 # endif | |
3225 )) | |
3226 { | |
3227 if (oap->start.lnum == oap->end.lnum | |
3228 && oap->start.col == oap->end.col) | |
3229 { | |
3230 /* Special case: inside a single char */ | |
3231 is_oneChar = TRUE; | |
3232 bd.startspaces = oap->end.coladd | |
3233 - oap->start.coladd + oap->inclusive; | |
3234 endcol = startcol; | |
3235 } | |
3236 else | |
3237 { | |
3238 bd.endspaces = oap->end.coladd | |
3239 + oap->inclusive; | |
3240 endcol -= oap->inclusive; | |
3241 } | |
3242 } | |
3243 } | |
3244 #endif | |
3245 } | |
3510 | 3246 if (endcol == MAXCOL) |
3247 endcol = (colnr_T)STRLEN(p); | |
7 | 3248 if (startcol > endcol |
3249 #ifdef FEAT_VIRTUALEDIT | |
3250 || is_oneChar | |
3251 #endif | |
3252 ) | |
3253 bd.textlen = 0; | |
3254 else | |
3255 { | |
3256 bd.textlen = endcol - startcol + oap->inclusive; | |
3257 } | |
3258 bd.textstart = p + startcol; | |
3259 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3260 goto fail; | |
3261 break; | |
3262 } | |
3263 /* NOTREACHED */ | |
3264 } | |
3265 } | |
3266 | |
3267 if (curr != y_current) /* append the new block to the old block */ | |
3268 { | |
3269 new_ptr = (char_u **)lalloc((long_u)(sizeof(char_u *) * | |
3270 (curr->y_size + y_current->y_size)), TRUE); | |
3271 if (new_ptr == NULL) | |
3272 goto fail; | |
3273 for (j = 0; j < curr->y_size; ++j) | |
3274 new_ptr[j] = curr->y_array[j]; | |
3275 vim_free(curr->y_array); | |
3276 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3277 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3278 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3279 #endif |
7 | 3280 |
3281 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3282 curr->y_type = MLINE; | |
3283 | |
164 | 3284 /* Concatenate the last line of the old block with the first line of |
3285 * the new block, unless being Vi compatible. */ | |
3286 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3287 { |
3288 pnew = lalloc((long_u)(STRLEN(curr->y_array[curr->y_size - 1]) | |
3289 + STRLEN(y_current->y_array[0]) + 1), TRUE); | |
3290 if (pnew == NULL) | |
3291 { | |
3292 y_idx = y_current->y_size - 1; | |
3293 goto fail; | |
3294 } | |
3295 STRCPY(pnew, curr->y_array[--j]); | |
3296 STRCAT(pnew, y_current->y_array[0]); | |
3297 vim_free(curr->y_array[j]); | |
3298 vim_free(y_current->y_array[0]); | |
3299 curr->y_array[j++] = pnew; | |
3300 y_idx = 1; | |
3301 } | |
3302 else | |
3303 y_idx = 0; | |
3304 while (y_idx < y_current->y_size) | |
3305 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3306 curr->y_size = j; | |
3307 vim_free(y_current->y_array); | |
3308 y_current = curr; | |
3309 } | |
5981 | 3310 if (curwin->w_p_rnu) |
3311 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3312 if (mess) /* Display message about yank? */ |
3313 { | |
3314 if (yanktype == MCHAR | |
3315 && !oap->block_mode | |
3316 && yanklines == 1) | |
3317 yanklines = 0; | |
3318 /* Some versions of Vi use ">=" here, some don't... */ | |
3319 if (yanklines > p_report) | |
3320 { | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3321 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
|
3322 |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3323 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
|
3324 *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
|
3325 else |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3326 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
|
3327 _(" 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
|
3328 |
7 | 3329 /* redisplay now, so message is not deleted */ |
3330 update_topline_redraw(); | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3331 if (oap->block_mode) |
205 | 3332 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3333 smsg(NGETTEXT("block of %ld line yanked%s", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3334 "block of %ld lines yanked%s", yanklines), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3335 yanklines, namebuf); |
205 | 3336 } |
7 | 3337 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3338 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3339 smsg(NGETTEXT("%ld line yanked%s", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3340 "%ld lines yanked%s", yanklines), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3341 yanklines, namebuf); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3342 } |
7 | 3343 } |
3344 } | |
3345 | |
3346 /* | |
3347 * Set "'[" and "']" marks. | |
3348 */ | |
3349 curbuf->b_op_start = oap->start; | |
3350 curbuf->b_op_end = oap->end; | |
5735 | 3351 if (yanktype == MLINE && !oap->block_mode) |
36 | 3352 { |
3353 curbuf->b_op_start.col = 0; | |
3354 curbuf->b_op_end.col = MAXCOL; | |
3355 } | |
7 | 3356 |
3357 #ifdef FEAT_CLIPBOARD | |
3358 /* | |
3359 * If we were yanking to the '*' register, send result to clipboard. | |
3360 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3361 * to the '*' register. | |
3362 */ | |
3363 if (clip_star.available | |
3364 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3365 || (!deleting && oap->regname == 0 |
6116 | 3366 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3367 { |
3368 if (curr != &(y_regs[STAR_REGISTER])) | |
3369 /* Copy the text from register 0 to the clipboard register. */ | |
3370 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3371 | |
3372 clip_own_selection(&clip_star); | |
3373 clip_gen_set_selection(&clip_star); | |
2658 | 3374 # ifdef FEAT_X11 |
2654 | 3375 did_star = TRUE; |
2658 | 3376 # endif |
7 | 3377 } |
3378 | |
3379 # ifdef FEAT_X11 | |
3380 /* | |
3381 * If we were yanking to the '+' register, send result to selection. | |
3382 * Also copy to the '*' register, in case auto-select is off. | |
3383 */ | |
2654 | 3384 if (clip_plus.available |
3385 && (curr == &(y_regs[PLUS_REGISTER]) | |
3386 || (!deleting && oap->regname == 0 | |
6116 | 3387 && ((clip_unnamed | clip_unnamed_saved) & |
3388 CLIP_UNNAMED_PLUS)))) | |
7 | 3389 { |
2654 | 3390 if (curr != &(y_regs[PLUS_REGISTER])) |
3391 /* Copy the text from register 0 to the clipboard register. */ | |
3392 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3393 | |
7 | 3394 clip_own_selection(&clip_plus); |
3395 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
|
3396 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
|
3397 && !did_star && curr == &(y_regs[PLUS_REGISTER])) |
7 | 3398 { |
3399 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3400 clip_own_selection(&clip_star); | |
3401 clip_gen_set_selection(&clip_star); | |
3402 } | |
3403 } | |
3404 # endif | |
3405 #endif | |
3406 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
3407 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3408 if (!deleting && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3409 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
|
3410 #endif |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3411 |
7 | 3412 return OK; |
3413 | |
3414 fail: /* free the allocated lines */ | |
3415 free_yank(y_idx + 1); | |
3416 y_current = curr; | |
3417 return FAIL; | |
3418 } | |
3419 | |
3420 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3421 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3422 { |
3423 char_u *pnew; | |
3424 | |
3425 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3426 == NULL) | |
3427 return FAIL; | |
3428 y_current->y_array[y_idx] = pnew; | |
6929 | 3429 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3430 pnew += bd->startspaces; |
3431 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3432 pnew += bd->textlen; | |
6929 | 3433 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3434 pnew += bd->endspaces; |
3435 *pnew = NUL; | |
3436 return OK; | |
3437 } | |
3438 | |
3439 #ifdef FEAT_CLIPBOARD | |
3440 /* | |
3441 * Make a copy of the y_current register to register "reg". | |
3442 */ | |
3443 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3444 copy_yank_reg(yankreg_T *reg) |
7 | 3445 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3446 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3447 long j; |
7 | 3448 |
3449 y_current = reg; | |
3450 free_yank_all(); | |
3451 *y_current = *curr; | |
3452 y_current->y_array = (char_u **)lalloc_clear( | |
3453 (long_u)(sizeof(char_u *) * y_current->y_size), TRUE); | |
3454 if (y_current->y_array == NULL) | |
3455 y_current->y_size = 0; | |
3456 else | |
3457 for (j = 0; j < y_current->y_size; ++j) | |
3458 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3459 { | |
3460 free_yank(j); | |
3461 y_current->y_size = 0; | |
3462 break; | |
3463 } | |
3464 y_current = curr; | |
3465 } | |
3466 #endif | |
3467 | |
3468 /* | |
140 | 3469 * Put contents of register "regname" into the text. |
3470 * Caller must check "regname" to be valid! | |
3471 * "flags": PUT_FIXINDENT make indent look nice | |
3472 * PUT_CURSEND leave cursor after end of new text | |
3473 * PUT_LINE force linewise put (":put") | |
7 | 3474 */ |
3475 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3476 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3477 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3478 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
|
3479 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3480 int flags) |
7 | 3481 { |
3482 char_u *ptr; | |
3483 char_u *newp, *oldp; | |
3484 int yanklen; | |
3485 int totlen = 0; /* init for gcc */ | |
3486 linenr_T lnum; | |
3487 colnr_T col; | |
3488 long i; /* index in y_array[] */ | |
3489 int y_type; | |
3490 long y_size; | |
3491 int oldlen; | |
3492 long y_width = 0; | |
3493 colnr_T vcol; | |
3494 int delcount; | |
3495 int incr = 0; | |
3496 long j; | |
3497 struct block_def bd; | |
3498 char_u **y_array = NULL; | |
3499 long nr_lines = 0; | |
3500 pos_T new_cursor; | |
3501 int indent; | |
3502 int orig_indent = 0; /* init for gcc */ | |
3503 int indent_diff = 0; /* init for gcc */ | |
3504 int first_indent = TRUE; | |
3505 int lendiff = 0; | |
3506 pos_T old_pos; | |
3507 char_u *insert_string = NULL; | |
3508 int allocated = FALSE; | |
3509 long cnt; | |
3510 | |
3511 #ifdef FEAT_CLIPBOARD | |
3512 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3513 adjust_clip_reg(®name); | |
3514 (void)may_get_selection(regname); | |
3515 #endif | |
3516 | |
3517 if (flags & PUT_FIXINDENT) | |
3518 orig_indent = get_indent(); | |
3519 | |
3520 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3521 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3522 | |
3523 /* | |
3524 * Using inserted text works differently, because the register includes | |
3525 * special characters (newlines, etc.). | |
3526 */ | |
3527 if (regname == '.') | |
3528 { | |
10494
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3529 if (VIsual_active) |
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3530 stuffcharReadbuff(VIsual_mode); |
7 | 3531 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
3532 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3533 /* Putting the text is done later, so can't really move the cursor to | |
3534 * the next character. Use "l" to simulate it. */ | |
3535 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3536 stuffcharReadbuff('l'); | |
3537 return; | |
3538 } | |
3539 | |
3540 /* | |
3541 * For special registers '%' (file name), '#' (alternate file name) and | |
3542 * ':' (last command line), etc. we have to create a fake yank register. | |
3543 */ | |
3544 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3545 { | |
3546 if (insert_string == NULL) | |
3547 return; | |
3548 } | |
3549 | |
14202
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3550 /* 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
|
3551 * 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
|
3552 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
|
3553 goto end; |
4005 | 3554 |
7 | 3555 if (insert_string != NULL) |
3556 { | |
3557 y_type = MCHAR; | |
3558 #ifdef FEAT_EVAL | |
3559 if (regname == '=') | |
3560 { | |
3561 /* For the = register we need to split the string at NL | |
3093 | 3562 * characters. |
3563 * Loop twice: count the number of lines and save them. */ | |
7 | 3564 for (;;) |
3565 { | |
3566 y_size = 0; | |
3567 ptr = insert_string; | |
3568 while (ptr != NULL) | |
3569 { | |
3570 if (y_array != NULL) | |
3571 y_array[y_size] = ptr; | |
3572 ++y_size; | |
3573 ptr = vim_strchr(ptr, '\n'); | |
3574 if (ptr != NULL) | |
3575 { | |
3576 if (y_array != NULL) | |
3577 *ptr = NUL; | |
3578 ++ptr; | |
3093 | 3579 /* A trailing '\n' makes the register linewise. */ |
7 | 3580 if (*ptr == NUL) |
3581 { | |
3582 y_type = MLINE; | |
3583 break; | |
3584 } | |
3585 } | |
3586 } | |
3587 if (y_array != NULL) | |
3588 break; | |
3589 y_array = (char_u **)alloc((unsigned) | |
3590 (y_size * sizeof(char_u *))); | |
3591 if (y_array == NULL) | |
3592 goto end; | |
3593 } | |
3594 } | |
3595 else | |
3596 #endif | |
3597 { | |
3598 y_size = 1; /* use fake one-line yank register */ | |
3599 y_array = &insert_string; | |
3600 } | |
3601 } | |
3602 else | |
3603 { | |
3604 get_yank_register(regname, FALSE); | |
3605 | |
3606 y_type = y_current->y_type; | |
3607 y_width = y_current->y_width; | |
3608 y_size = y_current->y_size; | |
3609 y_array = y_current->y_array; | |
3610 } | |
3611 | |
3612 if (y_type == MLINE) | |
3613 { | |
3614 if (flags & PUT_LINE_SPLIT) | |
3615 { | |
6845 | 3616 char_u *p; |
3617 | |
7 | 3618 /* "p" or "P" in Visual mode: split the lines to put the text in |
3619 * between. */ | |
3620 if (u_save_cursor() == FAIL) | |
3621 goto end; | |
6845 | 3622 p = ml_get_cursor(); |
3623 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
|
3624 MB_PTR_ADV(p); |
6845 | 3625 ptr = vim_strsave(p); |
7 | 3626 if (ptr == NULL) |
3627 goto end; | |
3628 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3629 vim_free(ptr); | |
3630 | |
6845 | 3631 oldp = ml_get_curline(); |
3632 p = oldp + curwin->w_cursor.col; | |
3633 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
|
3634 MB_PTR_ADV(p); |
6845 | 3635 ptr = vim_strnsave(oldp, p - oldp); |
7 | 3636 if (ptr == NULL) |
3637 goto end; | |
3638 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3639 ++nr_lines; | |
3640 dir = FORWARD; | |
3641 } | |
3642 if (flags & PUT_LINE_FORWARD) | |
3643 { | |
3644 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3645 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3646 dir = FORWARD; |
3647 } | |
3648 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3649 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3650 } | |
3651 | |
3652 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3653 y_type = MLINE; | |
3654 | |
3655 if (y_size == 0 || y_array == NULL) | |
3656 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3657 semsg(_("E353: Nothing in register %s"), |
7 | 3658 regname == 0 ? (char_u *)"\"" : transchar(regname)); |
3659 goto end; | |
3660 } | |
3661 | |
3662 if (y_type == MBLOCK) | |
3663 { | |
3664 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3665 if (lnum > curbuf->b_ml.ml_line_count) | |
3666 lnum = curbuf->b_ml.ml_line_count + 1; | |
3667 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3668 goto end; | |
3669 } | |
5735 | 3670 else if (y_type == MLINE) |
7 | 3671 { |
3672 lnum = curwin->w_cursor.lnum; | |
3673 #ifdef FEAT_FOLDING | |
3674 /* Correct line number for closed fold. Don't move the cursor yet, | |
3675 * u_save() uses it. */ | |
3676 if (dir == BACKWARD) | |
3677 (void)hasFolding(lnum, &lnum, NULL); | |
3678 else | |
3679 (void)hasFolding(lnum, NULL, &lnum); | |
3680 #endif | |
3681 if (dir == FORWARD) | |
3682 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3683 /* 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
|
3684 * 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
|
3685 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3686 goto end; |
3687 #ifdef FEAT_FOLDING | |
3688 if (dir == FORWARD) | |
3689 curwin->w_cursor.lnum = lnum - 1; | |
3690 else | |
3691 curwin->w_cursor.lnum = lnum; | |
3692 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3693 #endif | |
3694 } | |
3695 else if (u_save_cursor() == FAIL) | |
3696 goto end; | |
3697 | |
3698 yanklen = (int)STRLEN(y_array[0]); | |
3699 | |
3700 #ifdef FEAT_VIRTUALEDIT | |
3701 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3702 { | |
3703 if (gchar_cursor() == TAB) | |
3704 { | |
3705 /* Don't need to insert spaces when "p" on the last position of a | |
3706 * 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
|
3707 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3708 int viscol = getviscol(); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3709 if (dir == FORWARD |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3710 ? 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
|
3711 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
|
3712 : 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
|
3713 coladvance_force(viscol); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3714 #else |
7 | 3715 if (dir == FORWARD |
3716 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3717 : curwin->w_cursor.coladd > 0) | |
3718 coladvance_force(getviscol()); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3719 #endif |
7 | 3720 else |
3721 curwin->w_cursor.coladd = 0; | |
3722 } | |
3723 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3724 coladvance_force(getviscol() + (dir == FORWARD)); | |
3725 } | |
3726 #endif | |
3727 | |
3728 lnum = curwin->w_cursor.lnum; | |
3729 col = curwin->w_cursor.col; | |
3730 | |
3731 /* | |
3732 * Block mode | |
3733 */ | |
3734 if (y_type == MBLOCK) | |
3735 { | |
10664
94db9c08e206
patch 8.0.0222: blockwise put on multi-byte character misplaced
Christian Brabandt <cb@256bit.org>
parents:
10494
diff
changeset
|
3736 int c = gchar_cursor(); |
7 | 3737 colnr_T endcol2 = 0; |
3738 | |
3739 if (dir == FORWARD && c != NUL) | |
3740 { | |
3741 #ifdef FEAT_VIRTUALEDIT | |
3742 if (ve_flags == VE_ALL) | |
3743 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3744 else | |
3745 #endif | |
3746 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3747 | |
3748 #ifdef FEAT_MBYTE | |
3749 if (has_mbyte) | |
3750 /* move to start of next multi-byte character */ | |
474 | 3751 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3752 else |
3753 #endif | |
3754 #ifdef FEAT_VIRTUALEDIT | |
3755 if (c != TAB || ve_flags != VE_ALL) | |
3756 #endif | |
3757 ++curwin->w_cursor.col; | |
3758 ++col; | |
3759 } | |
3760 else | |
3761 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3762 | |
3763 #ifdef FEAT_VIRTUALEDIT | |
3764 col += curwin->w_cursor.coladd; | |
1304 | 3765 if (ve_flags == VE_ALL |
3766 && (curwin->w_cursor.coladd > 0 | |
3767 || endcol2 == curwin->w_cursor.col)) | |
7 | 3768 { |
3769 if (dir == FORWARD && c == NUL) | |
3770 ++col; | |
3771 if (dir != FORWARD && c != NUL) | |
3772 ++curwin->w_cursor.col; | |
3773 if (c == TAB) | |
3774 { | |
3775 if (dir == BACKWARD && curwin->w_cursor.col) | |
3776 curwin->w_cursor.col--; | |
3777 if (dir == FORWARD && col - 1 == endcol2) | |
3778 curwin->w_cursor.col++; | |
3779 } | |
3780 } | |
3781 curwin->w_cursor.coladd = 0; | |
3782 #endif | |
699 | 3783 bd.textcol = 0; |
7 | 3784 for (i = 0; i < y_size; ++i) |
3785 { | |
3786 int spaces; | |
3787 char shortline; | |
3788 | |
3789 bd.startspaces = 0; | |
3790 bd.endspaces = 0; | |
3791 vcol = 0; | |
3792 delcount = 0; | |
3793 | |
3794 /* add a new line */ | |
3795 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3796 { | |
3797 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3798 (colnr_T)1, FALSE) == FAIL) | |
3799 break; | |
3800 ++nr_lines; | |
3801 } | |
3802 /* get the old line and advance to the position to insert at */ | |
3803 oldp = ml_get_curline(); | |
3804 oldlen = (int)STRLEN(oldp); | |
3805 for (ptr = oldp; vcol < col && *ptr; ) | |
3806 { | |
3807 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3808 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3809 vcol += incr; |
3810 } | |
3811 bd.textcol = (colnr_T)(ptr - oldp); | |
3812 | |
3813 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3814 | |
3815 if (vcol < col) /* line too short, padd with spaces */ | |
3816 bd.startspaces = col - vcol; | |
3817 else if (vcol > col) | |
3818 { | |
3819 bd.endspaces = vcol - col; | |
3820 bd.startspaces = incr - bd.endspaces; | |
3821 --bd.textcol; | |
3822 delcount = 1; | |
3823 #ifdef FEAT_MBYTE | |
3824 if (has_mbyte) | |
3825 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3826 #endif | |
3827 if (oldp[bd.textcol] != TAB) | |
3828 { | |
3829 /* Only a Tab can be split into spaces. Other | |
3830 * characters will have to be moved to after the | |
3831 * block, causing misalignment. */ | |
3832 delcount = 0; | |
3833 bd.endspaces = 0; | |
3834 } | |
3835 } | |
3836 | |
3837 yanklen = (int)STRLEN(y_array[i]); | |
3838 | |
3839 /* calculate number of spaces required to fill right side of block*/ | |
3840 spaces = y_width + 1; | |
3841 for (j = 0; j < yanklen; j++) | |
5995 | 3842 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3843 if (spaces < 0) |
3844 spaces = 0; | |
3845 | |
3846 /* insert the new text */ | |
3847 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
3848 newp = alloc_check((unsigned)totlen + oldlen + 1); | |
3849 if (newp == NULL) | |
3850 break; | |
3851 /* copy part up to cursor to new line */ | |
3852 ptr = newp; | |
3853 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3854 ptr += bd.textcol; | |
3855 /* may insert some spaces before the new text */ | |
6929 | 3856 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3857 ptr += bd.startspaces; |
3858 /* insert the new text */ | |
3859 for (j = 0; j < count; ++j) | |
3860 { | |
3861 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3862 ptr += yanklen; | |
3863 | |
3864 /* insert block's trailing spaces only if there's text behind */ | |
3865 if ((j < count - 1 || !shortline) && spaces) | |
3866 { | |
6929 | 3867 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3868 ptr += spaces; |
3869 } | |
3870 } | |
3871 /* may insert some spaces after the new text */ | |
6929 | 3872 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3873 ptr += bd.endspaces; |
3874 /* move the text after the cursor to the end of the line. */ | |
3875 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3876 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3877 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3878 | |
3879 ++curwin->w_cursor.lnum; | |
3880 if (i == 0) | |
3881 curwin->w_cursor.col += bd.startspaces; | |
3882 } | |
3883 | |
3884 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3885 | |
3886 /* Set '[ mark. */ | |
3887 curbuf->b_op_start = curwin->w_cursor; | |
3888 curbuf->b_op_start.lnum = lnum; | |
3889 | |
3890 /* adjust '] mark */ | |
3891 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3892 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
237 | 3893 # ifdef FEAT_VIRTUALEDIT |
7 | 3894 curbuf->b_op_end.coladd = 0; |
237 | 3895 # endif |
7 | 3896 if (flags & PUT_CURSEND) |
3897 { | |
916 | 3898 colnr_T len; |
3899 | |
7 | 3900 curwin->w_cursor = curbuf->b_op_end; |
3901 curwin->w_cursor.col++; | |
916 | 3902 |
3903 /* in Insert mode we might be after the NUL, correct for that */ | |
3904 len = (colnr_T)STRLEN(ml_get_curline()); | |
3905 if (curwin->w_cursor.col > len) | |
3906 curwin->w_cursor.col = len; | |
7 | 3907 } |
3908 else | |
3909 curwin->w_cursor.lnum = lnum; | |
3910 } | |
3911 else | |
3912 { | |
3913 /* | |
3914 * Character or Line mode | |
3915 */ | |
3916 if (y_type == MCHAR) | |
3917 { | |
3918 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3919 * char */ | |
3920 if (dir == FORWARD && gchar_cursor() != NUL) | |
3921 { | |
3922 #ifdef FEAT_MBYTE | |
3923 if (has_mbyte) | |
3924 { | |
474 | 3925 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3926 |
3927 /* put it on the next of the multi-byte character. */ | |
3928 col += bytelen; | |
3929 if (yanklen) | |
3930 { | |
3931 curwin->w_cursor.col += bytelen; | |
3932 curbuf->b_op_end.col += bytelen; | |
3933 } | |
3934 } | |
3935 else | |
3936 #endif | |
3937 { | |
3938 ++col; | |
3939 if (yanklen) | |
3940 { | |
3941 ++curwin->w_cursor.col; | |
3942 ++curbuf->b_op_end.col; | |
3943 } | |
3944 } | |
3945 } | |
3946 curbuf->b_op_start = curwin->w_cursor; | |
3947 } | |
3948 /* | |
3949 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3950 */ | |
3951 else if (dir == BACKWARD) | |
3952 --lnum; | |
699 | 3953 new_cursor = curwin->w_cursor; |
7 | 3954 |
3955 /* | |
3956 * simple case: insert into current line | |
3957 */ | |
3958 if (y_type == MCHAR && y_size == 1) | |
3959 { | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3960 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
|
3961 |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3962 if (VIsual_active) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3963 { |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3964 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
|
3965 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
|
3966 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
|
3967 } |
10670
bce3eccea39a
patch 8.0.0225: put in Visual block mode terminates early
Christian Brabandt <cb@256bit.org>
parents:
10664
diff
changeset
|
3968 |
5365 | 3969 do { |
3970 totlen = count * yanklen; | |
3971 if (totlen > 0) | |
7 | 3972 { |
5365 | 3973 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
|
3974 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
|
3975 { |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3976 lnum++; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3977 continue; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3978 } |
5365 | 3979 newp = alloc_check((unsigned)(STRLEN(oldp) + totlen + 1)); |
3980 if (newp == NULL) | |
3981 goto end; /* alloc() gave an error message */ | |
3982 mch_memmove(newp, oldp, (size_t)col); | |
3983 ptr = newp + col; | |
3984 for (i = 0; i < count; ++i) | |
3985 { | |
3986 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3987 ptr += yanklen; | |
3988 } | |
3989 STRMOVE(ptr, oldp + col); | |
3990 ml_replace(lnum, newp, FALSE); | |
3991 /* Place cursor on last putted char. */ | |
3992 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3993 { |
3994 /* make sure curwin->w_virtcol is updated */ | |
3995 changed_cline_bef_curs(); | |
5365 | 3996 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3997 } |
7 | 3998 } |
5365 | 3999 if (VIsual_active) |
4000 lnum++; | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
4001 } while (VIsual_active && lnum <= end_lnum); |
5365 | 4002 |
6379 | 4003 if (VIsual_active) /* reset lnum to the last visual line */ |
4004 lnum--; | |
4005 | |
7 | 4006 curbuf->b_op_end = curwin->w_cursor; |
4007 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
4008 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
4009 ++curwin->w_cursor.col; | |
4010 changed_bytes(lnum, col); | |
4011 } | |
4012 else | |
4013 { | |
4014 /* | |
4015 * Insert at least one line. When y_type is MCHAR, break the first | |
4016 * line in two. | |
4017 */ | |
4018 for (cnt = 1; cnt <= count; ++cnt) | |
4019 { | |
4020 i = 0; | |
4021 if (y_type == MCHAR) | |
4022 { | |
4023 /* | |
4024 * Split the current line in two at the insert position. | |
4025 * First insert y_array[size - 1] in front of second line. | |
4026 * Then append y_array[0] to first line. | |
4027 */ | |
4028 lnum = new_cursor.lnum; | |
4029 ptr = ml_get(lnum) + col; | |
4030 totlen = (int)STRLEN(y_array[y_size - 1]); | |
4031 newp = alloc_check((unsigned)(STRLEN(ptr) + totlen + 1)); | |
4032 if (newp == NULL) | |
4033 goto error; | |
4034 STRCPY(newp, y_array[y_size - 1]); | |
4035 STRCAT(newp, ptr); | |
4036 /* insert second line */ | |
4037 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
4038 vim_free(newp); | |
4039 | |
4040 oldp = ml_get(lnum); | |
4041 newp = alloc_check((unsigned)(col + yanklen + 1)); | |
4042 if (newp == NULL) | |
4043 goto error; | |
4044 /* copy first part of line */ | |
4045 mch_memmove(newp, oldp, (size_t)col); | |
4046 /* append to first line */ | |
4047 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
4048 ml_replace(lnum, newp, FALSE); | |
4049 | |
4050 curwin->w_cursor.lnum = lnum; | |
4051 i = 1; | |
4052 } | |
4053 | |
4054 for (; i < y_size; ++i) | |
4055 { | |
4056 if ((y_type != MCHAR || i < y_size - 1) | |
4057 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
4058 == FAIL) | |
4059 goto error; | |
4060 lnum++; | |
4061 ++nr_lines; | |
4062 if (flags & PUT_FIXINDENT) | |
4063 { | |
4064 old_pos = curwin->w_cursor; | |
4065 curwin->w_cursor.lnum = lnum; | |
4066 ptr = ml_get(lnum); | |
4067 if (cnt == count && i == y_size - 1) | |
4068 lendiff = (int)STRLEN(ptr); | |
4069 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
4070 if (*ptr == '#' && preprocs_left()) | |
4071 indent = 0; /* Leave # lines at start */ | |
4072 else | |
4073 #endif | |
4074 if (*ptr == NUL) | |
4075 indent = 0; /* Ignore empty lines */ | |
4076 else if (first_indent) | |
4077 { | |
4078 indent_diff = orig_indent - get_indent(); | |
4079 indent = orig_indent; | |
4080 first_indent = FALSE; | |
4081 } | |
4082 else if ((indent = get_indent() + indent_diff) < 0) | |
4083 indent = 0; | |
4084 (void)set_indent(indent, 0); | |
4085 curwin->w_cursor = old_pos; | |
4086 /* remember how many chars were removed */ | |
4087 if (cnt == count && i == y_size - 1) | |
4088 lendiff -= (int)STRLEN(ml_get(lnum)); | |
4089 } | |
4090 } | |
4091 } | |
4092 | |
4093 error: | |
4094 /* Adjust marks. */ | |
4095 if (y_type == MLINE) | |
4096 { | |
4097 curbuf->b_op_start.col = 0; | |
4098 if (dir == FORWARD) | |
4099 curbuf->b_op_start.lnum++; | |
4100 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4101 /* 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
|
4102 * 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
|
4103 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
|
4104 < 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
|
4105 #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
|
4106 || 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
|
4107 #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
|
4108 ) |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
4109 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 4110 (linenr_T)MAXLNUM, nr_lines, 0L); |
4111 | |
4112 /* note changed text for displaying and folding */ | |
4113 if (y_type == MCHAR) | |
4114 changed_lines(curwin->w_cursor.lnum, col, | |
4115 curwin->w_cursor.lnum + 1, nr_lines); | |
4116 else | |
4117 changed_lines(curbuf->b_op_start.lnum, 0, | |
4118 curbuf->b_op_start.lnum, nr_lines); | |
4119 | |
4120 /* put '] mark at last inserted character */ | |
4121 curbuf->b_op_end.lnum = lnum; | |
4122 /* correct length for change in indent */ | |
4123 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
4124 if (col > 1) | |
4125 curbuf->b_op_end.col = col - 1; | |
4126 else | |
4127 curbuf->b_op_end.col = 0; | |
4128 | |
168 | 4129 if (flags & PUT_CURSLINE) |
4130 { | |
237 | 4131 /* ":put": put cursor on last inserted line */ |
168 | 4132 curwin->w_cursor.lnum = lnum; |
4133 beginline(BL_WHITE | BL_FIX); | |
4134 } | |
4135 else if (flags & PUT_CURSEND) | |
7 | 4136 { |
4137 /* put cursor after inserted text */ | |
4138 if (y_type == MLINE) | |
4139 { | |
4140 if (lnum >= curbuf->b_ml.ml_line_count) | |
4141 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4142 else | |
4143 curwin->w_cursor.lnum = lnum + 1; | |
4144 curwin->w_cursor.col = 0; | |
4145 } | |
4146 else | |
4147 { | |
4148 curwin->w_cursor.lnum = lnum; | |
4149 curwin->w_cursor.col = col; | |
4150 } | |
4151 } | |
4152 else if (y_type == MLINE) | |
4153 { | |
168 | 4154 /* put cursor on first non-blank in first inserted line */ |
7 | 4155 curwin->w_cursor.col = 0; |
4156 if (dir == FORWARD) | |
4157 ++curwin->w_cursor.lnum; | |
4158 beginline(BL_WHITE | BL_FIX); | |
4159 } | |
4160 else /* put cursor on first inserted character */ | |
4161 curwin->w_cursor = new_cursor; | |
4162 } | |
4163 } | |
4164 | |
4165 msgmore(nr_lines); | |
4166 curwin->w_set_curswant = TRUE; | |
4167 | |
4168 end: | |
4169 if (allocated) | |
4170 vim_free(insert_string); | |
840 | 4171 if (regname == '=') |
4172 vim_free(y_array); | |
4173 | |
5380 | 4174 VIsual_active = FALSE; |
4175 | |
140 | 4176 /* If the cursor is past the end of the line put it at the end. */ |
844 | 4177 adjust_cursor_eol(); |
4178 } | |
4179 | |
4180 /* | |
4181 * When the cursor is on the NUL past the end of the line and it should not be | |
4182 * there move it left. | |
4183 */ | |
4184 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4185 adjust_cursor_eol(void) |
844 | 4186 { |
4187 if (curwin->w_cursor.col > 0 | |
4188 && gchar_cursor() == NUL | |
773 | 4189 #ifdef FEAT_VIRTUALEDIT |
4190 && (ve_flags & VE_ONEMORE) == 0 | |
4191 #endif | |
7 | 4192 && !(restart_edit || (State & INSERT))) |
4193 { | |
557 | 4194 /* Put the cursor on the last character in the line. */ |
555 | 4195 dec_cursor(); |
844 | 4196 |
7 | 4197 #ifdef FEAT_VIRTUALEDIT |
4198 if (ve_flags == VE_ALL) | |
557 | 4199 { |
4200 colnr_T scol, ecol; | |
4201 | |
4202 /* Coladd is set to the width of the last character. */ | |
4203 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4204 curwin->w_cursor.coladd = ecol - scol + 1; | |
4205 } | |
7 | 4206 #endif |
4207 } | |
4208 } | |
4209 | |
4210 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4211 /* | |
4212 * Return TRUE if lines starting with '#' should be left aligned. | |
4213 */ | |
4214 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4215 preprocs_left(void) |
7 | 4216 { |
4217 return | |
4218 # ifdef FEAT_SMARTINDENT | |
4219 # ifdef FEAT_CINDENT | |
4220 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4221 # else | |
4222 curbuf->b_p_si | |
4223 # endif | |
4224 # endif | |
4225 # ifdef FEAT_CINDENT | |
5438 | 4226 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4227 && curbuf->b_ind_hash_comment == 0) | |
7 | 4228 # endif |
4229 ; | |
4230 } | |
4231 #endif | |
4232 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4233 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4234 * 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
|
4235 */ |
7 | 4236 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4237 get_register_name(int num) |
7 | 4238 { |
4239 if (num == -1) | |
4240 return '"'; | |
4241 else if (num < 10) | |
4242 return num + '0'; | |
4243 else if (num == DELETION_REGISTER) | |
4244 return '-'; | |
4245 #ifdef FEAT_CLIPBOARD | |
4246 else if (num == STAR_REGISTER) | |
4247 return '*'; | |
4248 else if (num == PLUS_REGISTER) | |
4249 return '+'; | |
4250 #endif | |
4251 else | |
4252 { | |
4253 #ifdef EBCDIC | |
4254 int i; | |
4255 | |
4256 /* EBCDIC is really braindead ... */ | |
4257 i = 'a' + (num - 10); | |
4258 if (i > 'i') | |
4259 i += 7; | |
4260 if (i > 'r') | |
4261 i += 8; | |
4262 return i; | |
4263 #else | |
4264 return num + 'a' - 10; | |
4265 #endif | |
4266 } | |
4267 } | |
4268 | |
4269 /* | |
4270 * ":dis" and ":registers": Display the contents of the yank registers. | |
4271 */ | |
4272 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4273 ex_display(exarg_T *eap) |
7 | 4274 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4275 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4276 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4277 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4278 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4279 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4280 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4281 char_u *arg = eap->arg; |
22 | 4282 #ifdef FEAT_MBYTE |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4283 int clen; |
22 | 4284 #else |
4285 # define clen 1 | |
4286 #endif | |
7 | 4287 |
4288 if (arg != NULL && *arg == NUL) | |
4289 arg = NULL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11131
diff
changeset
|
4290 attr = HL_ATTR(HLF_8); |
7 | 4291 |
4292 /* Highlight title */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4293 msg_puts_title(_("\n--- Registers ---")); |
7 | 4294 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) |
4295 { | |
4296 name = get_register_name(i); | |
2644 | 4297 if (arg != NULL && vim_strchr(arg, name) == NULL |
4298 #ifdef ONE_CLIPBOARD | |
4299 /* Star register and plus register contain the same thing. */ | |
4300 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4301 #endif | |
4302 ) | |
7 | 4303 continue; /* did not ask for this register */ |
4304 | |
4305 #ifdef FEAT_CLIPBOARD | |
4306 /* Adjust register name for "unnamed" in 'clipboard'. | |
4307 * When it's a clipboard register, fill it with the current contents | |
4308 * of the clipboard. */ | |
4309 adjust_clip_reg(&name); | |
4310 (void)may_get_selection(name); | |
4311 #endif | |
4312 | |
4313 if (i == -1) | |
4314 { | |
4315 if (y_previous != NULL) | |
4316 yb = y_previous; | |
4317 else | |
4318 yb = &(y_regs[0]); | |
4319 } | |
4320 else | |
4321 yb = &(y_regs[i]); | |
2000 | 4322 |
4323 #ifdef FEAT_EVAL | |
4324 if (name == MB_TOLOWER(redir_reg) | |
4325 || (redir_reg == '"' && yb == y_previous)) | |
4326 continue; /* do not list register being written to, the | |
4327 * pointer can be freed */ | |
4328 #endif | |
4329 | |
7 | 4330 if (yb->y_array != NULL) |
4331 { | |
4332 msg_putchar('\n'); | |
4333 msg_putchar('"'); | |
4334 msg_putchar(name); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4335 msg_puts(" "); |
7 | 4336 |
4337 n = (int)Columns - 6; | |
4338 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4339 { | |
4340 if (j) | |
4341 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4342 msg_puts_attr("^J", attr); |
7 | 4343 n -= 2; |
4344 } | |
4345 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4346 { | |
4347 #ifdef FEAT_MBYTE | |
474 | 4348 clen = (*mb_ptr2len)(p); |
22 | 4349 #endif |
4350 msg_outtrans_len(p, clen); | |
4351 #ifdef FEAT_MBYTE | |
4352 p += clen - 1; | |
7 | 4353 #endif |
4354 } | |
4355 } | |
4356 if (n > 1 && yb->y_type == MLINE) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4357 msg_puts_attr("^J", attr); |
7 | 4358 out_flush(); /* show one line at a time */ |
4359 } | |
4360 ui_breakcheck(); | |
4361 } | |
4362 | |
4363 /* | |
4364 * display last inserted text | |
4365 */ | |
4366 if ((p = get_last_insert()) != NULL | |
4367 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4368 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4369 msg_puts("\n\". "); |
7 | 4370 dis_msg(p, TRUE); |
4371 } | |
4372 | |
4373 /* | |
4374 * display last command line | |
4375 */ | |
4376 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4377 && !got_int) | |
4378 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4379 msg_puts("\n\": "); |
7 | 4380 dis_msg(last_cmdline, FALSE); |
4381 } | |
4382 | |
4383 /* | |
4384 * display current file name | |
4385 */ | |
4386 if (curbuf->b_fname != NULL | |
4387 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4388 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4389 msg_puts("\n\"% "); |
7 | 4390 dis_msg(curbuf->b_fname, FALSE); |
4391 } | |
4392 | |
4393 /* | |
4394 * display alternate file name | |
4395 */ | |
4396 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4397 { | |
4398 char_u *fname; | |
4399 linenr_T dummy; | |
4400 | |
4401 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4402 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4403 msg_puts("\n\"# "); |
7 | 4404 dis_msg(fname, FALSE); |
4405 } | |
4406 } | |
4407 | |
4408 /* | |
4409 * display last search pattern | |
4410 */ | |
4411 if (last_search_pat() != NULL | |
4412 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4413 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4414 msg_puts("\n\"/ "); |
7 | 4415 dis_msg(last_search_pat(), FALSE); |
4416 } | |
4417 | |
4418 #ifdef FEAT_EVAL | |
4419 /* | |
4420 * display last used expression | |
4421 */ | |
4422 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4423 && !got_int) | |
4424 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4425 msg_puts("\n\"= "); |
7 | 4426 dis_msg(expr_line, FALSE); |
4427 } | |
4428 #endif | |
4429 } | |
4430 | |
4431 /* | |
4432 * display a string for do_dis() | |
4433 * truncate at end of screen line | |
4434 */ | |
4435 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4436 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4437 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4438 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4439 { |
4440 int n; | |
4441 #ifdef FEAT_MBYTE | |
4442 int l; | |
4443 #endif | |
4444 | |
4445 n = (int)Columns - 6; | |
4446 while (*p != NUL | |
4447 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4448 && (n -= ptr2cells(p)) >= 0) | |
4449 { | |
4450 #ifdef FEAT_MBYTE | |
474 | 4451 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4452 { |
4453 msg_outtrans_len(p, l); | |
4454 p += l; | |
4455 } | |
4456 else | |
4457 #endif | |
4458 msg_outtrans_len(p++, 1); | |
4459 } | |
4460 ui_breakcheck(); | |
4461 } | |
4462 | |
3562 | 4463 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4464 /* | |
4465 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4466 * after some white space), return a pointer to the text after it. Put a boolean | |
4467 * value indicating whether the line ends with an unclosed comment in | |
4468 * "is_comment". | |
4469 * line - line to be processed, | |
4470 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4471 * comment, |
3562 | 4472 * include_space - whether to also skip space following the comment leader, |
4473 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4474 * comment. |
3562 | 4475 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4476 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4477 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4478 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4479 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4480 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4481 int *is_comment) |
3562 | 4482 { |
4483 char_u *comment_flags = NULL; | |
4484 int lead_len; | |
4485 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4486 | |
4487 *is_comment = FALSE; | |
4488 if (leader_offset != -1) | |
4489 { | |
4490 /* Let's check whether the line ends with an unclosed comment. | |
4491 * If the last comment leader has COM_END in flags, there's no comment. | |
4492 */ | |
4493 while (*comment_flags) | |
4494 { | |
4495 if (*comment_flags == COM_END | |
4496 || *comment_flags == ':') | |
4497 break; | |
4498 ++comment_flags; | |
4499 } | |
4500 if (*comment_flags != COM_END) | |
4501 *is_comment = TRUE; | |
4502 } | |
4503 | |
4504 if (process == FALSE) | |
4505 return line; | |
4506 | |
4507 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4508 | |
4509 if (lead_len == 0) | |
4510 return line; | |
4511 | |
4512 /* Find: | |
4513 * - COM_END, | |
4514 * - colon, | |
4515 * whichever comes first. | |
4516 */ | |
4517 while (*comment_flags) | |
4518 { | |
3580 | 4519 if (*comment_flags == COM_END |
3562 | 4520 || *comment_flags == ':') |
4521 { | |
4522 break; | |
4523 } | |
4524 ++comment_flags; | |
4525 } | |
4526 | |
4527 /* If we found a colon, it means that we are not processing a line | |
3580 | 4528 * starting with a closing part of a three-part comment. That's good, |
4529 * because we don't want to remove those as this would be annoying. | |
3562 | 4530 */ |
4531 if (*comment_flags == ':' || *comment_flags == NUL) | |
4532 line += lead_len; | |
4533 | |
4534 return line; | |
4535 } | |
4536 #endif | |
4537 | |
7 | 4538 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4539 * 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
|
4540 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4541 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4542 * leaders should not be removed. | |
4543 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4544 * to set those marks. | |
7 | 4545 * |
1217 | 4546 * return FAIL for failure, OK otherwise |
7 | 4547 */ |
4548 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4549 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4550 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4551 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4552 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4553 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4554 int setmark) |
7 | 4555 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4556 char_u *curr = NULL; |
2597 | 4557 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
|
4558 char_u *cend; |
7 | 4559 char_u *newp; |
2597 | 4560 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
|
4561 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4562 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4563 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
|
4564 int sumsize = 0; /* size of the long new line */ |
7 | 4565 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4566 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4567 int ret = OK; |
3562 | 4568 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4569 int *comments = NULL; |
3562 | 4570 int remove_comments = (use_formatoptions == TRUE) |
4571 && has_format_option(FO_REMOVE_COMS); | |
4572 int prev_was_comment; | |
4573 #endif | |
4574 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4575 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4576 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
|
4577 (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
|
4578 return FAIL; |
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 /* 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
|
4581 * 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
|
4582 * 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
|
4583 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
|
4584 if (spaces == NULL) |
7 | 4585 return FAIL; |
3562 | 4586 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4587 if (remove_comments) | |
4588 { | |
4589 comments = (int *)lalloc_clear((long_u)count * sizeof(int), TRUE); | |
4590 if (comments == NULL) | |
4591 { | |
4592 vim_free(spaces); | |
4593 return FAIL; | |
4594 } | |
4595 } | |
4596 #endif | |
7 | 4597 |
4598 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4599 * 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
|
4600 * and setup the array of space strings lengths |
7 | 4601 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4602 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
|
4603 { |
2597 | 4604 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4605 if (t == 0 && setmark) |
5664 | 4606 { |
4607 /* Set the '[ mark. */ | |
4608 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4609 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4610 } | |
3562 | 4611 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4612 if (remove_comments) | |
4613 { | |
4614 /* We don't want to remove the comment leader if the | |
4615 * previous line is not a comment. */ | |
4616 if (t > 0 && prev_was_comment) | |
4617 { | |
4618 | |
4619 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4620 &prev_was_comment); | |
3576 | 4621 comments[t] = (int)(new_curr - curr); |
3562 | 4622 curr = new_curr; |
4623 } | |
4624 else | |
4625 curr = skip_comment(curr, FALSE, insert_space, | |
4626 &prev_was_comment); | |
4627 } | |
4628 #endif | |
4629 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4630 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
|
4631 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4632 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4633 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
|
4634 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4635 && (!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
|
4636 || (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
|
4637 && (!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
|
4638 || 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
|
4639 #endif |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4640 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4641 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4642 /* 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
|
4643 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4644 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4645 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4646 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4647 /* 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
|
4648 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4649 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4650 || (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
|
4651 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4652 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4653 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4654 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4655 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4656 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4657 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4658 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
|
4659 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4660 #ifdef FEAT_MBYTE |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4661 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4662 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4663 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4664 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
|
4665 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4666 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4667 { |
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 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4670 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4671 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4672 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4673 #endif |
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 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4676 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4677 endcurr2 = *(curr + currsize - 2); |
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 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4680 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4681 if (got_int) |
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 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4684 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4685 } |
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 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4688 /* 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
|
4689 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
|
4690 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4691 /* 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
|
4692 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
|
4693 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4694 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4695 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4696 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4697 * 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
|
4698 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4699 * 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
|
4700 * 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
|
4701 * 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
|
4702 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4703 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
|
4704 { |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4705 int spaces_removed; |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4706 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4707 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4708 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
|
4709 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4710 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4711 cend -= spaces[t]; |
6929 | 4712 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
|
4713 } |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4714 |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4715 // If deleting more spaces than adding, the cursor moves no more than |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4716 // what is added if it is inside these spaces. |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4717 spaces_removed = (curr - curr_start) - spaces[t]; |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4718 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4719 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4720 (long)(cend - newp - spaces_removed), spaces_removed); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4721 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4722 break; |
2597 | 4723 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
3562 | 4724 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4725 if (remove_comments) | |
4726 curr += comments[t - 1]; | |
4727 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4728 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
|
4729 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4730 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4731 } |
7 | 4732 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
4733 | |
5848 | 4734 if (setmark) |
4735 { | |
4736 /* Set the '] mark. */ | |
4737 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
4738 curwin->w_buffer->b_op_end.col = (colnr_T)STRLEN(newp); | |
4739 } | |
5664 | 4740 |
7 | 4741 /* Only report the change in the first line here, del_lines() will report |
4742 * the deleted line. */ | |
4743 changed_lines(curwin->w_cursor.lnum, currsize, | |
4744 curwin->w_cursor.lnum + 1, 0L); | |
4745 | |
4746 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4747 * Delete following lines. To do this we move the cursor there |
7 | 4748 * briefly, and then move it back. After del_lines() the cursor may |
4749 * have moved up (last line deleted), so the current lnum is kept in t. | |
4750 */ | |
4751 t = curwin->w_cursor.lnum; | |
4752 ++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
|
4753 del_lines(count - 1, FALSE); |
7 | 4754 curwin->w_cursor.lnum = t; |
4755 | |
4756 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4757 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4758 * 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
|
4759 * vim: use the column of the last join |
7 | 4760 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4761 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4762 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4763 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4764 |
7 | 4765 #ifdef FEAT_VIRTUALEDIT |
4766 curwin->w_cursor.coladd = 0; | |
4767 #endif | |
4768 curwin->w_set_curswant = TRUE; | |
4769 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4770 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4771 vim_free(spaces); |
3562 | 4772 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4773 if (remove_comments) | |
4774 vim_free(comments); | |
4775 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4776 return ret; |
7 | 4777 } |
4778 | |
4779 #ifdef FEAT_COMMENTS | |
4780 /* | |
4781 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4782 * the first line. White-space is ignored. Note that the whole of | |
4783 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4784 */ | |
4785 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4786 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4787 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4788 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4789 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4790 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4791 char_u *leader2_flags) |
7 | 4792 { |
4793 int idx1 = 0, idx2 = 0; | |
4794 char_u *p; | |
4795 char_u *line1; | |
4796 char_u *line2; | |
4797 | |
4798 if (leader1_len == 0) | |
4799 return (leader2_len == 0); | |
4800 | |
4801 /* | |
4802 * If first leader has 'f' flag, the lines can be joined only if the | |
4803 * second line does not have a leader. | |
4804 * If first leader has 'e' flag, the lines can never be joined. | |
4805 * If fist leader has 's' flag, the lines can only be joined if there is | |
4806 * some text after it and the second line has the 'm' flag. | |
4807 */ | |
4808 if (leader1_flags != NULL) | |
4809 { | |
4810 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4811 { | |
4812 if (*p == COM_FIRST) | |
4813 return (leader2_len == 0); | |
4814 if (*p == COM_END) | |
4815 return FALSE; | |
4816 if (*p == COM_START) | |
4817 { | |
4818 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4819 return FALSE; | |
4820 if (leader2_flags == NULL || leader2_len == 0) | |
4821 return FALSE; | |
4822 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4823 if (*p == COM_MIDDLE) | |
4824 return TRUE; | |
4825 return FALSE; | |
4826 } | |
4827 } | |
4828 } | |
4829 | |
4830 /* | |
4831 * Get current line and next line, compare the leaders. | |
4832 * The first line has to be saved, only one line can be locked at a time. | |
4833 */ | |
4834 line1 = vim_strsave(ml_get(lnum)); | |
4835 if (line1 != NULL) | |
4836 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4837 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 4838 ; |
4839 line2 = ml_get(lnum + 1); | |
4840 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4841 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4842 if (!VIM_ISWHITE(line2[idx2])) |
7 | 4843 { |
4844 if (line1[idx1++] != line2[idx2]) | |
4845 break; | |
4846 } | |
4847 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4848 while (VIM_ISWHITE(line1[idx1])) |
7 | 4849 ++idx1; |
4850 } | |
4851 vim_free(line1); | |
4852 } | |
4853 return (idx2 == leader2_len && idx1 == leader1_len); | |
4854 } | |
4855 #endif | |
4856 | |
4857 /* | |
3252 | 4858 * Implementation of the format operator 'gq'. |
7 | 4859 */ |
4860 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4861 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4862 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4863 int keep_cursor) /* keep cursor on same text char */ |
7 | 4864 { |
4865 long old_line_count = curbuf->b_ml.ml_line_count; | |
4866 | |
4867 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4868 * can put it back there. */ | |
4869 curwin->w_cursor = oap->cursor_start; | |
4870 | |
4871 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4872 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4873 return; | |
4874 curwin->w_cursor = oap->start; | |
4875 | |
4876 if (oap->is_VIsual) | |
4877 /* When there is no change: need to remove the Visual selection */ | |
4878 redraw_curbuf_later(INVERTED); | |
4879 | |
4880 /* Set '[ mark at the start of the formatted area */ | |
4881 curbuf->b_op_start = oap->start; | |
4882 | |
4883 /* For "gw" remember the cursor position and put it back below (adjusted | |
4884 * for joined and split lines). */ | |
4885 if (keep_cursor) | |
4886 saved_cursor = oap->cursor_start; | |
4887 | |
1563 | 4888 format_lines(oap->line_count, keep_cursor); |
7 | 4889 |
4890 /* | |
4891 * Leave the cursor at the first non-blank of the last formatted line. | |
4892 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4893 * line, so "." will do the next lines. | |
4894 */ | |
4895 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4896 ++curwin->w_cursor.lnum; | |
4897 beginline(BL_WHITE | BL_FIX); | |
4898 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4899 msgmore(old_line_count); | |
4900 | |
4901 /* put '] mark on the end of the formatted area */ | |
4902 curbuf->b_op_end = curwin->w_cursor; | |
4903 | |
4904 if (keep_cursor) | |
4905 { | |
4906 curwin->w_cursor = saved_cursor; | |
4907 saved_cursor.lnum = 0; | |
4908 } | |
4909 | |
4910 if (oap->is_VIsual) | |
4911 { | |
4912 win_T *wp; | |
4913 | |
4914 FOR_ALL_WINDOWS(wp) | |
4915 { | |
4916 if (wp->w_old_cursor_lnum != 0) | |
4917 { | |
4918 /* When lines have been inserted or deleted, adjust the end of | |
4919 * the Visual area to be redrawn. */ | |
4920 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4921 wp->w_old_cursor_lnum += old_line_count; | |
4922 else | |
4923 wp->w_old_visual_lnum += old_line_count; | |
4924 } | |
4925 } | |
4926 } | |
4927 } | |
4928 | |
667 | 4929 #if defined(FEAT_EVAL) || defined(PROTO) |
4930 /* | |
4931 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4932 */ | |
4933 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4934 op_formatexpr(oparg_T *oap) |
667 | 4935 { |
4936 if (oap->is_VIsual) | |
4937 /* When there is no change: need to remove the Visual selection */ | |
4938 redraw_curbuf_later(INVERTED); | |
4939 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4940 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
|
4941 /* 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
|
4942 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4943 op_format(oap, FALSE); |
667 | 4944 } |
4945 | |
4946 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4947 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4948 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4949 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4950 int c) /* character to be inserted */ |
667 | 4951 { |
681 | 4952 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4953 OPT_LOCAL); | |
667 | 4954 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4955 char_u *fex; |
667 | 4956 |
4957 /* | |
4958 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4959 * Set v:char to the character to be inserted (can be NUL). |
667 | 4960 */ |
4961 set_vim_var_nr(VV_LNUM, lnum); | |
4962 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4963 set_vim_var_char(c); |
844 | 4964 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4965 /* 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
|
4966 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
|
4967 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4968 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4969 |
667 | 4970 /* |
4971 * Evaluate the function. | |
4972 */ | |
4973 if (use_sandbox) | |
4974 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4975 r = (int)eval_to_number(fex); |
667 | 4976 if (use_sandbox) |
4977 --sandbox; | |
844 | 4978 |
4979 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
|
4980 vim_free(fex); |
844 | 4981 |
667 | 4982 return r; |
4983 } | |
4984 #endif | |
4985 | |
7 | 4986 /* |
4987 * Format "line_count" lines, starting at the cursor position. | |
4988 * When "line_count" is negative, format until the end of the paragraph. | |
4989 * Lines after the cursor line are saved for undo, caller must have saved the | |
4990 * first line. | |
4991 */ | |
4992 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4993 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4994 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4995 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4996 { |
4997 int max_len; | |
4998 int is_not_par; /* current line not part of parag. */ | |
4999 int next_is_not_par; /* next line not part of paragraph */ | |
5000 int is_end_par; /* at end of paragraph */ | |
5001 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
5002 int next_is_start_par = FALSE; | |
5003 #ifdef FEAT_COMMENTS | |
5004 int leader_len = 0; /* leader len of current line */ | |
5005 int next_leader_len; /* leader len of next line */ | |
5006 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5007 char_u *next_leader_flags; /* flags for leader of next line */ | |
5008 int do_comments; /* format comments */ | |
3584 | 5009 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 5010 #endif |
5011 int advance = TRUE; | |
3584 | 5012 int second_indent = -1; /* indent for second line (comment |
5013 * aware) */ | |
7 | 5014 int do_second_indent; |
5015 int do_number_indent; | |
5016 int do_trail_white; | |
5017 int first_par_line = TRUE; | |
5018 int smd_save; | |
5019 long count; | |
5020 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
5021 int force_format = FALSE; | |
5022 int old_State = State; | |
5023 | |
5024 /* length of a line to force formatting: 3 * 'tw' */ | |
5025 max_len = comp_textwidth(TRUE) * 3; | |
5026 | |
5027 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
5028 #ifdef FEAT_COMMENTS | |
5029 do_comments = has_format_option(FO_Q_COMS); | |
5030 #endif | |
5031 do_second_indent = has_format_option(FO_Q_SECOND); | |
5032 do_number_indent = has_format_option(FO_Q_NUMBER); | |
5033 do_trail_white = has_format_option(FO_WHITE_PAR); | |
5034 | |
5035 /* | |
5036 * Get info about the previous and current line. | |
5037 */ | |
5038 if (curwin->w_cursor.lnum > 1) | |
5039 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
5040 #ifdef FEAT_COMMENTS | |
5041 , &leader_len, &leader_flags, do_comments | |
5042 #endif | |
5043 ); | |
5044 else | |
5045 is_not_par = TRUE; | |
5046 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
5047 #ifdef FEAT_COMMENTS | |
5048 , &next_leader_len, &next_leader_flags, do_comments | |
5049 #endif | |
5050 ); | |
5051 is_end_par = (is_not_par || next_is_not_par); | |
5052 if (!is_end_par && do_trail_white) | |
5053 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
5054 | |
5055 curwin->w_cursor.lnum--; | |
5056 for (count = line_count; count != 0 && !got_int; --count) | |
5057 { | |
5058 /* | |
5059 * Advance to next paragraph. | |
5060 */ | |
5061 if (advance) | |
5062 { | |
5063 curwin->w_cursor.lnum++; | |
5064 prev_is_end_par = is_end_par; | |
5065 is_not_par = next_is_not_par; | |
5066 #ifdef FEAT_COMMENTS | |
5067 leader_len = next_leader_len; | |
5068 leader_flags = next_leader_flags; | |
5069 #endif | |
5070 } | |
5071 | |
5072 /* | |
5073 * The last line to be formatted. | |
5074 */ | |
5075 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
5076 { | |
5077 next_is_not_par = TRUE; | |
5078 #ifdef FEAT_COMMENTS | |
5079 next_leader_len = 0; | |
5080 next_leader_flags = NULL; | |
5081 #endif | |
5082 } | |
5083 else | |
5084 { | |
5085 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
5086 #ifdef FEAT_COMMENTS | |
5087 , &next_leader_len, &next_leader_flags, do_comments | |
5088 #endif | |
5089 ); | |
5090 if (do_number_indent) | |
5091 next_is_start_par = | |
5092 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
5093 } | |
5094 advance = TRUE; | |
5095 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
5096 if (!is_end_par && do_trail_white) | |
5097 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
5098 | |
5099 /* | |
5100 * Skip lines that are not in a paragraph. | |
5101 */ | |
5102 if (is_not_par) | |
5103 { | |
5104 if (line_count < 0) | |
5105 break; | |
5106 } | |
5107 else | |
5108 { | |
5109 /* | |
5110 * For the first line of a paragraph, check indent of second line. | |
5111 * Don't do this for comments and empty lines. | |
5112 */ | |
5113 if (first_par_line | |
5114 && (do_second_indent || do_number_indent) | |
5115 && prev_is_end_par | |
3584 | 5116 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
5117 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
5118 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 5119 { |
5120 #ifdef FEAT_COMMENTS | |
5121 if (leader_len == 0 && next_leader_len == 0) | |
5122 { | |
5123 /* no comment found */ | |
5124 #endif | |
5125 second_indent = | |
5126 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 5127 #ifdef FEAT_COMMENTS |
3584 | 5128 } |
5129 else | |
5130 { | |
5131 second_indent = next_leader_len; | |
5132 do_comments_list = 1; | |
5133 } | |
5134 #endif | |
5135 } | |
7 | 5136 else if (do_number_indent) |
3584 | 5137 { |
5138 #ifdef FEAT_COMMENTS | |
5139 if (leader_len == 0 && next_leader_len == 0) | |
5140 { | |
5141 /* no comment found */ | |
5142 #endif | |
5143 second_indent = | |
5144 get_number_indent(curwin->w_cursor.lnum); | |
5145 #ifdef FEAT_COMMENTS | |
5146 } | |
5147 else | |
5148 { | |
5149 /* get_number_indent() is now "comment aware"... */ | |
5150 second_indent = | |
5151 get_number_indent(curwin->w_cursor.lnum); | |
5152 do_comments_list = 1; | |
5153 } | |
5154 #endif | |
5155 } | |
7 | 5156 } |
5157 | |
5158 /* | |
5159 * When the comment leader changes, it's the end of the paragraph. | |
5160 */ | |
5161 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
5162 #ifdef FEAT_COMMENTS | |
5163 || !same_leader(curwin->w_cursor.lnum, | |
5164 leader_len, leader_flags, | |
5165 next_leader_len, next_leader_flags) | |
5166 #endif | |
5167 ) | |
5168 is_end_par = TRUE; | |
5169 | |
5170 /* | |
5171 * If we have got to the end of a paragraph, or the line is | |
5172 * getting long, format it. | |
5173 */ | |
5174 if (is_end_par || force_format) | |
5175 { | |
5176 if (need_set_indent) | |
5177 /* replace indent in first line with minimal number of | |
5178 * tabs and spaces, according to current options */ | |
5179 (void)set_indent(get_indent(), SIN_CHANGED); | |
5180 | |
5181 /* put cursor on last non-space */ | |
5182 State = NORMAL; /* don't go past end-of-line */ | |
5183 coladvance((colnr_T)MAXCOL); | |
5184 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
5185 dec_cursor(); | |
5186 | |
5187 /* do the formatting, without 'showmode' */ | |
5188 State = INSERT; /* for open_line() */ | |
5189 smd_save = p_smd; | |
5190 p_smd = FALSE; | |
5191 insertchar(NUL, INSCHAR_FORMAT | |
5192 #ifdef FEAT_COMMENTS | |
5193 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 5194 + (do_comments && do_comments_list |
5195 ? INSCHAR_COM_LIST : 0) | |
7 | 5196 #endif |
1563 | 5197 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 5198 State = old_State; |
5199 p_smd = smd_save; | |
5200 second_indent = -1; | |
5201 /* at end of par.: need to set indent of next par. */ | |
5202 need_set_indent = is_end_par; | |
5203 if (is_end_par) | |
5204 { | |
5205 /* When called with a negative line count, break at the | |
5206 * end of the paragraph. */ | |
5207 if (line_count < 0) | |
5208 break; | |
5209 first_par_line = TRUE; | |
5210 } | |
5211 force_format = FALSE; | |
5212 } | |
5213 | |
5214 /* | |
5215 * When still in same paragraph, join the lines together. But | |
5403 | 5216 * first delete the leader from the second line. |
7 | 5217 */ |
5218 if (!is_end_par) | |
5219 { | |
5220 advance = FALSE; | |
5221 curwin->w_cursor.lnum++; | |
5222 curwin->w_cursor.col = 0; | |
5223 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
|
5224 break; |
7 | 5225 #ifdef FEAT_COMMENTS |
5226 if (next_leader_len > 0) | |
5403 | 5227 { |
5228 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5229 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5230 (long)-next_leader_len, 0); |
5403 | 5231 } else |
5232 #endif | |
5233 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5234 { | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
5235 int indent = getwhitecols_curline(); |
5403 | 5236 |
5237 if (indent > 0) | |
5238 { | |
5239 (void)del_bytes(indent, FALSE, FALSE); | |
5240 mark_col_adjust(curwin->w_cursor.lnum, | |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5241 (colnr_T)0, 0L, (long)-indent, 0); |
5415 | 5242 } |
5403 | 5243 } |
7 | 5244 curwin->w_cursor.lnum--; |
5848 | 5245 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5246 { |
5247 beep_flush(); | |
5248 break; | |
5249 } | |
5250 first_par_line = FALSE; | |
5251 /* If the line is getting long, format it next time */ | |
5252 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5253 force_format = TRUE; | |
5254 else | |
5255 force_format = FALSE; | |
5256 } | |
5257 } | |
5258 line_breakcheck(); | |
5259 } | |
5260 } | |
5261 | |
5262 /* | |
5263 * Return TRUE if line "lnum" ends in a white character. | |
5264 */ | |
5265 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5266 ends_in_white(linenr_T lnum) |
7 | 5267 { |
5268 char_u *s = ml_get(lnum); | |
5269 size_t l; | |
5270 | |
5271 if (*s == NUL) | |
5272 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5273 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 5274 * invocation may call function multiple times". */ |
5275 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
|
5276 return VIM_ISWHITE(s[l]); |
7 | 5277 } |
5278 | |
5279 /* | |
5280 * Blank lines, and lines containing only the comment leader, are left | |
5281 * untouched by the formatting. The function returns TRUE in this | |
5282 * case. It also returns TRUE when a line starts with the end of a comment | |
5283 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5284 * previous line. A new paragraph starts after a blank line, or when the | |
5285 * comment leader changes -- webb. | |
5286 */ | |
5287 #ifdef FEAT_COMMENTS | |
5288 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5289 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5290 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5291 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5292 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5293 int do_comments) |
7 | 5294 { |
5295 char_u *flags = NULL; /* init for GCC */ | |
5296 char_u *ptr; | |
5297 | |
5298 ptr = ml_get(lnum); | |
5299 if (do_comments) | |
3562 | 5300 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5301 else |
5302 *leader_len = 0; | |
5303 | |
5304 if (*leader_len > 0) | |
5305 { | |
5306 /* | |
5307 * Search for 'e' flag in comment leader flags. | |
5308 */ | |
5309 flags = *leader_flags; | |
5310 while (*flags && *flags != ':' && *flags != COM_END) | |
5311 ++flags; | |
5312 } | |
5313 | |
5314 return (*skipwhite(ptr + *leader_len) == NUL | |
5315 || (*leader_len > 0 && *flags == COM_END) | |
5316 || startPS(lnum, NUL, FALSE)); | |
5317 } | |
5318 #else | |
5319 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5320 fmt_check_par(linenr_T lnum) |
7 | 5321 { |
5322 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5323 } | |
5324 #endif | |
5325 | |
5326 /* | |
5327 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5328 * previous line is in the same paragraph. Used for auto-formatting. | |
5329 */ | |
5330 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5331 paragraph_start(linenr_T lnum) |
7 | 5332 { |
5333 char_u *p; | |
5334 #ifdef FEAT_COMMENTS | |
5335 int leader_len = 0; /* leader len of current line */ | |
5336 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5337 int next_leader_len; /* leader len of next line */ | |
5338 char_u *next_leader_flags; /* flags for leader of next line */ | |
5339 int do_comments; /* format comments */ | |
5340 #endif | |
5341 | |
5342 if (lnum <= 1) | |
5343 return TRUE; /* start of the file */ | |
5344 | |
5345 p = ml_get(lnum - 1); | |
5346 if (*p == NUL) | |
5347 return TRUE; /* after empty line */ | |
5348 | |
5349 #ifdef FEAT_COMMENTS | |
5350 do_comments = has_format_option(FO_Q_COMS); | |
5351 #endif | |
5352 if (fmt_check_par(lnum - 1 | |
5353 #ifdef FEAT_COMMENTS | |
5354 , &leader_len, &leader_flags, do_comments | |
5355 #endif | |
5356 )) | |
5357 return TRUE; /* after non-paragraph line */ | |
5358 | |
5359 if (fmt_check_par(lnum | |
5360 #ifdef FEAT_COMMENTS | |
5361 , &next_leader_len, &next_leader_flags, do_comments | |
5362 #endif | |
5363 )) | |
5364 return TRUE; /* "lnum" is not a paragraph line */ | |
5365 | |
5366 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5367 return TRUE; /* missing trailing space in previous line. */ | |
5368 | |
5369 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5370 return TRUE; /* numbered item starts in "lnum". */ | |
5371 | |
5372 #ifdef FEAT_COMMENTS | |
5373 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5374 next_leader_len, next_leader_flags)) | |
5375 return TRUE; /* change of comment leader. */ | |
5376 #endif | |
5377 | |
5378 return FALSE; | |
5379 } | |
5380 | |
5381 /* | |
5382 * prepare a few things for block mode yank/delete/tilde | |
5383 * | |
5384 * for delete: | |
5385 * - textlen includes the first/last char to be (partly) deleted | |
5386 * - start/endspaces is the number of columns that are taken by the | |
5387 * first/last deleted char minus the number of columns that have to be | |
1839 | 5388 * deleted. |
5389 * for yank and tilde: | |
7 | 5390 * - textlen includes the first/last char to be wholly yanked |
5391 * - start/endspaces is the number of columns of the first/last yanked char | |
5392 * that are to be yanked. | |
5393 */ | |
5394 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5395 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5396 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5397 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5398 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5399 int is_del) |
7 | 5400 { |
5401 int incr = 0; | |
5402 char_u *pend; | |
5403 char_u *pstart; | |
5404 char_u *line; | |
5405 char_u *prev_pstart; | |
5406 char_u *prev_pend; | |
5407 | |
5408 bdp->startspaces = 0; | |
5409 bdp->endspaces = 0; | |
5410 bdp->textlen = 0; | |
5411 bdp->start_vcol = 0; | |
5412 bdp->end_vcol = 0; | |
5413 bdp->is_short = FALSE; | |
5414 bdp->is_oneChar = FALSE; | |
5415 bdp->pre_whitesp = 0; | |
5416 bdp->pre_whitesp_c = 0; | |
5417 bdp->end_char_vcols = 0; | |
5418 bdp->start_char_vcols = 0; | |
5419 | |
5420 line = ml_get(lnum); | |
5421 pstart = line; | |
5422 prev_pstart = line; | |
5423 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5424 { | |
5425 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5426 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5427 bdp->start_vcol += incr; |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
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 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5439 MB_PTR_ADV(pstart); |
7 | 5440 } |
5441 bdp->start_char_vcols = incr; | |
5442 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5443 { | |
5444 bdp->end_vcol = bdp->start_vcol; | |
5445 bdp->is_short = TRUE; | |
5446 if (!is_del || oap->op_type == OP_APPEND) | |
5447 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5448 } | |
5449 else | |
5450 { | |
5451 /* notice: this converts partly selected Multibyte characters to | |
5452 * spaces, too. */ | |
5453 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5454 if (is_del && bdp->startspaces) | |
5455 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5456 pend = pstart; | |
5457 bdp->end_vcol = bdp->start_vcol; | |
5458 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5459 { | |
5460 bdp->is_oneChar = TRUE; | |
5461 if (oap->op_type == OP_INSERT) | |
5462 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5463 else if (oap->op_type == OP_APPEND) | |
5464 { | |
5465 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5466 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5467 } | |
5468 else | |
5469 { | |
5470 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5471 if (is_del && oap->op_type != OP_LSHIFT) | |
5472 { | |
5473 /* just putting the sum of those two into | |
5474 * bdp->startspaces doesn't work for Visual replace, | |
5475 * so we have to split the tab in two */ | |
5476 bdp->startspaces = bdp->start_char_vcols | |
5477 - (bdp->start_vcol - oap->start_vcol); | |
5478 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5479 } | |
5480 } | |
5481 } | |
5482 else | |
5483 { | |
5484 prev_pend = pend; | |
5485 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5486 { | |
5487 /* Count a tab for what it's worth (if list mode not on) */ | |
5488 prev_pend = pend; | |
6535 | 5489 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5490 bdp->end_vcol += incr; |
5491 } | |
5492 if (bdp->end_vcol <= oap->end_vcol | |
5493 && (!is_del | |
5494 || oap->op_type == OP_APPEND | |
5495 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5496 { | |
5497 bdp->is_short = TRUE; | |
5498 /* Alternative: include spaces to fill up the block. | |
5499 * Disadvantage: can lead to trailing spaces when the line is | |
5500 * short where the text is put */ | |
5501 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5502 if (oap->op_type == OP_APPEND || virtual_op) | |
5503 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5504 + oap->inclusive; |
7 | 5505 else |
5506 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5507 } | |
5508 else if (bdp->end_vcol > oap->end_vcol) | |
5509 { | |
5510 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5511 if (!is_del && bdp->endspaces) | |
5512 { | |
5513 bdp->endspaces = incr - bdp->endspaces; | |
5514 if (pend != pstart) | |
5515 pend = prev_pend; | |
5516 } | |
5517 } | |
5518 } | |
5519 bdp->end_char_vcols = incr; | |
5520 if (is_del && bdp->startspaces) | |
5521 pstart = prev_pstart; | |
5522 bdp->textlen = (int)(pend - pstart); | |
5523 } | |
5524 bdp->textcol = (colnr_T) (pstart - line); | |
5525 bdp->textstart = pstart; | |
5526 } | |
5527 | |
5528 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5529 * Handle the add/subtract operator. |
7 | 5530 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5531 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5532 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5533 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5534 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
|
5535 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
|
5536 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5537 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5538 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5539 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5540 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5541 |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5542 // do_addsub() might trigger re-evaluation of 'foldexpr' halfway, when the |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5543 // buffer is not completly updated yet. Postpone updating folds until before |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5544 // the call to changed_lines(). |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5545 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5546 disable_fold_update++; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5547 #endif |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5548 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5549 if (!VIsual_active) |
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 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5552 if (u_save_cursor() == FAIL) |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5553 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5554 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5555 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5556 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5557 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5558 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5559 change_cnt = do_addsub(oap->op_type, &pos, 0, amount); |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5560 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5561 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5562 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5563 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5564 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
|
5565 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5566 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5567 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5568 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5569 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5570 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5571 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5572 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
|
5573 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5574 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5575 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5576 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5577 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5578 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5579 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5580 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5581 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5582 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
|
5583 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5584 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
|
5585 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5586 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
|
5587 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5588 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5589 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5590 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
|
5591 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5592 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5593 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5594 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
|
5595 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5596 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5597 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
5598 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
|
5599 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5600 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
|
5601 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5602 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
|
5603 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5604 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5605 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5606 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5607 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5608 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5609 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
|
5610 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5611 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5612 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
|
5613 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5614 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5615 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
|
5616 if (one_change) |
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 /* 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
|
5619 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5620 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5621 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5622 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5623 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5624 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5625 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5626 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5627 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
|
5628 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5629 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
|
5630 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
|
5631 &ptr[pos.col], length); |
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 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5634 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5635 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5636 } |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5637 |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5638 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5639 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5640 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5641 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5642 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
|
5643 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5644 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5645 /* 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
|
5646 redraw_curbuf_later(INVERTED); |
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 /* 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
|
5649 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5650 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5651 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5652 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5653 if (change_cnt > p_report) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
5654 smsg(NGETTEXT("%ld line changed", "%ld lines changed", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
5655 change_cnt), change_cnt); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5656 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5657 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5658 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5659 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5660 * 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
|
5661 * 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
|
5662 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5663 * 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
|
5664 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5665 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5666 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5667 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5668 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5669 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5670 linenr_T Prenum1) |
7 | 5671 { |
5672 int col; | |
5673 char_u *buf1; | |
5674 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5675 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5676 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5677 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5678 uvarnumber_T oldn; |
7 | 5679 char_u *ptr; |
5680 int c; | |
5681 int todel; | |
5682 int dohex; | |
5683 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5684 int dobin; |
7 | 5685 int doalp; |
5686 int firstdigit; | |
5687 int subtract; | |
6868 | 5688 int negative = FALSE; |
6891 | 5689 int was_positive = TRUE; |
6868 | 5690 int visual = VIsual_active; |
6921 | 5691 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5692 pos_T save_cursor = curwin->w_cursor; |
6927 | 5693 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5694 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5695 pos_T endpos; |
7 | 5696 |
5697 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); /* "heX" */ | |
5698 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
|
5699 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); /* "Bin" */ |
7 | 5700 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); /* "alPha" */ |
5701 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5702 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5703 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5704 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5705 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5706 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5707 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5708 |
7 | 5709 /* |
5710 * First check if we are on a hexadecimal number, after the "0x". | |
5711 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5712 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5713 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5714 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5715 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
|
5716 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5717 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5718 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5719 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5720 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
|
5721 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5722 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5723 |
6868 | 5724 if (dohex) |
5725 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
|
5726 { |
6868 | 5727 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5728 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5729 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5730 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
|
5731 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5732 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5733 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5734 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5735 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5736 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5737 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5738 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5739 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5740 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5741 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5742 !(*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
|
5743 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5744 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5745 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5746 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5747 /* 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
|
5748 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5749 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5750 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5751 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
|
5752 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5753 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5754 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5755 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5756 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
|
5757 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5758 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5759 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5760 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5761 if (( dohex |
6868 | 5762 && col > 0 |
5763 && (ptr[col] == 'X' | |
5764 || ptr[col] == 'x') | |
5765 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5766 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5767 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5768 !(*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
|
5769 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5770 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5771 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5772 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5773 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5774 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5775 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5776 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5777 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5778 !(*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
|
5779 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5780 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5781 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5782 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5783 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5784 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5785 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5786 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
|
5787 #endif |
6868 | 5788 } |
5789 else | |
7 | 5790 { |
6868 | 5791 /* |
5792 * Search forward and then backward to find the start of number. | |
5793 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5794 col = pos->col; |
6868 | 5795 |
5796 while (ptr[col] != NUL | |
5797 && !vim_isdigit(ptr[col]) | |
5798 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5799 col += MB_PTR2LEN(ptr + col); |
6868 | 5800 |
5801 while (col > 0 | |
5802 && vim_isdigit(ptr[col - 1]) | |
5803 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5804 { |
6868 | 5805 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5806 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5807 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5808 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
|
5809 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5810 } |
6868 | 5811 } |
5812 } | |
5813 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5814 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5816 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5818 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5819 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5820 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
|
5821 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5822 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5823 length -= mb_len; |
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 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5826 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5827 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5828 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5829 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
|
5830 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5831 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5832 !(*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
|
5833 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5834 ) |
7574
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 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5837 was_positive = FALSE; |
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 |
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 * 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
|
5843 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5844 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5845 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
|
5846 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5847 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5848 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5849 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5850 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5851 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5852 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5853 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5854 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5855 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5856 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5857 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5858 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5859 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5861 firstdigit = 'a'; |
6927 | 5862 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5863 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5864 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5865 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5866 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5867 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5868 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5869 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5870 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5871 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5872 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5873 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5874 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5875 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5876 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5877 firstdigit = 'z'; |
6927 | 5878 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5879 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5880 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5881 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5882 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5883 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5884 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5885 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5886 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5887 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5888 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5889 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5890 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5891 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5892 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5893 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5894 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5895 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5896 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5897 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5898 #ifdef FEAT_MBYTE |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5899 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5900 !(*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
|
5901 #endif |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5902 && !visual) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5903 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5904 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5905 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5906 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5907 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5908 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5909 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5910 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
|
5911 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5912 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5913 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5914 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5915 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5916 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5917 + (dohex ? STR2NR_HEX : 0), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5918 NULL, &n, maxlen); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5919 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5920 /* 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
|
5921 if (pre && negative) |
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 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5924 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5925 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5926 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5927 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5928 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5929 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5930 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5931 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5932 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5933 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5934 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5935 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5936 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5937 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5938 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5939 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5940 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5941 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5942 if (subtract) |
6927 | 5943 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5944 if (n > oldn) |
6868 | 5945 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5946 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
|
5947 negative ^= TRUE; |
6868 | 5948 } |
7 | 5949 } |
5950 else | |
6868 | 5951 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5952 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5953 if (n < oldn) |
6868 | 5954 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5955 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5956 negative ^= TRUE; |
6868 | 5957 } |
6927 | 5958 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5959 if (n == 0) |
6868 | 5960 negative = FALSE; |
7574
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 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5963 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
|
5964 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5965 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5966 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5967 length++; |
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 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5970 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5971 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5972 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5973 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5974 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5975 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5976 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5977 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5978 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5979 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5980 * 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
|
5981 * 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
|
5982 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5983 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5984 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5985 while (todel-- > 0) |
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 if (c < 0x100 && isalpha(c)) |
6868 | 5988 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5989 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5990 hexupper = TRUE; |
6868 | 5991 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5992 hexupper = FALSE; |
6891 | 5993 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5994 /* 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
|
5995 (void)del_char(FALSE); |
6868 | 5996 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5997 } |
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 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6000 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6001 * 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
|
6002 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6003 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6004 buf1 = alloc((unsigned)length + NUMBUFLEN); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6005 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6006 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6007 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
6008 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6009 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6010 *ptr++ = '-'; |
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 if (pre) |
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 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6015 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6016 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6017 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6018 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6019 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6020 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6021 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6022 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6023 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6024 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6025 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6026 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6027 if (pre == 'b' || pre == 'B') |
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 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6030 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6031 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
|
6032 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6033 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6034 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6035 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6036 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6037 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6038 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
|
6039 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6040 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6041 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6042 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
|
6043 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6044 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6045 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
|
6046 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6047 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6048 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
|
6049 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6050 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6051 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
|
6052 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
6053 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6054 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6055 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6056 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6057 * 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
|
6058 * 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
|
6059 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6060 * 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
|
6061 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6062 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6063 while (length-- > 0) |
6868 | 6064 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6065 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6066 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6067 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
|
6068 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6069 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6070 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
|
6071 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6072 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6073 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6074 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6075 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6076 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6077 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6078 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6079 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
|
6080 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
6081 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6082 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6083 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6084 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6085 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6086 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
6087 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
6088 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
6089 return did_change; |
7 | 6090 } |
6091 | |
6092 #ifdef FEAT_VIMINFO | |
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 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
|
6095 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6096 #define REG_PREVIOUS 1 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6097 #define REG_EXEC 2 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6098 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6099 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6100 * 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
|
6101 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6102 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6103 prepare_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6104 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6105 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
|
6106 * (int)sizeof(yankreg_T)); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6107 } |
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 void |
9282
9f97a6290c63
commit https://github.com/vim/vim/commit/cf089463492fab53b2a5d81517829d22f882f82e
Christian Brabandt <cb@256bit.org>
parents:
9272
diff
changeset
|
6110 finish_viminfo_registers(void) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6111 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6112 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6113 int j; |
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 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6116 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6117 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
|
6118 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
|
6119 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6120 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
|
6121 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
|
6122 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
|
6123 } |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
6124 VIM_CLEAR(y_read_regs); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6125 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6126 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6127 |
7 | 6128 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6129 read_viminfo_register(vir_T *virp, int force) |
7 | 6130 { |
6131 int eof; | |
6132 int do_it = TRUE; | |
6133 int size; | |
6134 int limit; | |
6135 int i; | |
6136 int set_prev = FALSE; | |
6137 char_u *str; | |
6138 char_u **array = NULL; | |
6508 | 6139 int new_type = MCHAR; /* init to shut up compiler */ |
6140 colnr_T new_width = 0; /* init to shut up compiler */ | |
7 | 6141 |
6142 /* We only get here (hopefully) if line[0] == '"' */ | |
6143 str = virp->vir_line + 1; | |
1893 | 6144 |
6145 /* If the line starts with "" this is the y_previous register. */ | |
7 | 6146 if (*str == '"') |
6147 { | |
6148 set_prev = TRUE; | |
6149 str++; | |
6150 } | |
1893 | 6151 |
7 | 6152 if (!ASCII_ISALNUM(*str) && *str != '-') |
6153 { | |
6154 if (viminfo_error("E577: ", _("Illegal register name"), virp->vir_line)) | |
6155 return TRUE; /* too many errors, pretend end-of-file */ | |
6156 do_it = FALSE; | |
6157 } | |
6158 get_yank_register(*str++, FALSE); | |
6159 if (!force && y_current->y_array != NULL) | |
6160 do_it = FALSE; | |
1893 | 6161 |
6162 if (*str == '@') | |
6163 { | |
6164 /* "x@: register x used for @@ */ | |
6165 if (force || execreg_lastc == NUL) | |
6166 execreg_lastc = str[-1]; | |
6167 } | |
6168 | |
7 | 6169 size = 0; |
6170 limit = 100; /* Optimized for registers containing <= 100 lines */ | |
6171 if (do_it) | |
6172 { | |
6462 | 6173 /* |
6174 * Build the new register in array[]. | |
6175 * y_array is kept as-is until done. | |
6176 * The "do_it" flag is reset when something is wrong, in which case | |
6177 * array[] needs to be freed. | |
6178 */ | |
7 | 6179 if (set_prev) |
6180 y_previous = y_current; | |
6462 | 6181 array = (char_u **)alloc((unsigned)(limit * sizeof(char_u *))); |
1893 | 6182 str = skipwhite(skiptowhite(str)); |
7 | 6183 if (STRNCMP(str, "CHAR", 4) == 0) |
6462 | 6184 new_type = MCHAR; |
7 | 6185 else if (STRNCMP(str, "BLOCK", 5) == 0) |
6462 | 6186 new_type = MBLOCK; |
7 | 6187 else |
6462 | 6188 new_type = MLINE; |
7 | 6189 /* get the block width; if it's missing we get a zero, which is OK */ |
6190 str = skipwhite(skiptowhite(str)); | |
6462 | 6191 new_width = getdigits(&str); |
7 | 6192 } |
6193 | |
6194 while (!(eof = viminfo_readline(virp)) | |
6195 && (virp->vir_line[0] == TAB || virp->vir_line[0] == '<')) | |
6196 { | |
6197 if (do_it) | |
6198 { | |
6462 | 6199 if (size == limit) |
7 | 6200 { |
6462 | 6201 char_u **new_array = (char_u **) |
7 | 6202 alloc((unsigned)(limit * 2 * sizeof(char_u *))); |
6462 | 6203 |
6204 if (new_array == NULL) | |
6205 { | |
6206 do_it = FALSE; | |
6207 break; | |
6208 } | |
7 | 6209 for (i = 0; i < limit; i++) |
6462 | 6210 new_array[i] = array[i]; |
7 | 6211 vim_free(array); |
6462 | 6212 array = new_array; |
7 | 6213 limit *= 2; |
6214 } | |
6215 str = viminfo_readstring(virp, 1, TRUE); | |
6216 if (str != NULL) | |
6217 array[size++] = str; | |
6218 else | |
6462 | 6219 /* error, don't store the result */ |
7 | 6220 do_it = FALSE; |
6221 } | |
6222 } | |
6508 | 6223 |
7 | 6224 if (do_it) |
6225 { | |
6462 | 6226 /* free y_array[] */ |
6227 for (i = 0; i < y_current->y_size; i++) | |
6228 vim_free(y_current->y_array[i]); | |
6229 vim_free(y_current->y_array); | |
6230 | |
6231 y_current->y_type = new_type; | |
6232 y_current->y_width = new_width; | |
6233 y_current->y_size = size; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6234 y_current->y_time_set = 0; |
7 | 6235 if (size == 0) |
6236 { | |
6237 y_current->y_array = NULL; | |
6238 } | |
6462 | 6239 else |
7 | 6240 { |
6462 | 6241 /* Move the lines from array[] to y_array[]. */ |
7 | 6242 y_current->y_array = |
6243 (char_u **)alloc((unsigned)(size * sizeof(char_u *))); | |
6244 for (i = 0; i < size; i++) | |
6462 | 6245 { |
6246 if (y_current->y_array == NULL) | |
6247 vim_free(array[i]); | |
6248 else | |
6249 y_current->y_array[i] = array[i]; | |
6250 } | |
7 | 6251 } |
6462 | 6252 } |
6253 else | |
6254 { | |
6255 /* Free array[] if it was filled. */ | |
6256 for (i = 0; i < size; i++) | |
6257 vim_free(array[i]); | |
6258 } | |
6259 vim_free(array); | |
6260 | |
7 | 6261 return eof; |
6262 } | |
6263 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6264 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6265 * 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
|
6266 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6267 void |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6268 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
|
6269 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6270 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
|
6271 int flags; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6272 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6273 int type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6274 int linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6275 int width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6276 time_t timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6277 yankreg_T *y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6278 int i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6279 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6280 /* Check the format: |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6281 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6282 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6283 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6284 if (values->ga_len < 6 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6285 || vp[0].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6286 || vp[1].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6287 || vp[2].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6288 || vp[3].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6289 || vp[4].bv_type != BVAL_NR |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6290 || vp[5].bv_type != BVAL_NR) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6291 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6292 flags = vp[0].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6293 name = vp[1].bv_nr; |
9307
eb52a2670c96
commit https://github.com/vim/vim/commit/67e3720a9ddd8a9d2e8344358c28fa1f4196db0d
Christian Brabandt <cb@256bit.org>
parents:
9282
diff
changeset
|
6294 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
|
6295 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6296 type = vp[2].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6297 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
|
6298 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6299 linecount = vp[3].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6300 if (values->ga_len < 6 + linecount) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6301 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6302 width = vp[4].bv_nr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6303 if (width < 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6304 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6305 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6306 if (y_read_regs != NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6307 /* 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
|
6308 * 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
|
6309 y_ptr = &y_read_regs[name]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6310 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6311 y_ptr = &y_regs[name]; |
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 /* 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
|
6314 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
|
6315 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
|
6316 && (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
|
6317 return; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6318 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6319 if (y_ptr->y_array != NULL) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
6320 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
|
6321 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
|
6322 vim_free(y_ptr->y_array); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6323 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6324 if (y_read_regs == NULL) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6325 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6326 if (flags & REG_PREVIOUS) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6327 y_previous = y_ptr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6328 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
|
6329 execreg_lastc = get_register_name(name); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6330 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6331 y_ptr->y_type = type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6332 y_ptr->y_width = width; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6333 y_ptr->y_size = linecount; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6334 y_ptr->y_time_set = timestamp; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6335 if (linecount == 0) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6336 y_ptr->y_array = NULL; |
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 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6339 y_ptr->y_array = |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6340 (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
|
6341 for (i = 0; i < linecount; i++) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6342 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6343 if (vp[i + 6].bv_allocated) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6344 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6345 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
|
6346 vp[i + 6].bv_string = NULL; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6347 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6348 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6349 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
|
6350 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6351 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6352 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6353 |
7 | 6354 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6355 write_viminfo_registers(FILE *fp) |
7 | 6356 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6357 int i, j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6358 char_u *type; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6359 char_u c; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6360 int num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6361 int max_num_lines; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6362 int max_kbyte; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6363 long len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6364 yankreg_T *y_ptr; |
7 | 6365 |
2278
0b3be97064e5
Various small fixes from Dominique Pelle.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6366 fputs(_("\n# Registers:\n"), fp); |
7 | 6367 |
6368 /* Get '<' value, use old '"' value if '<' is not found. */ | |
6369 max_num_lines = get_viminfo_parameter('<'); | |
6370 if (max_num_lines < 0) | |
6371 max_num_lines = get_viminfo_parameter('"'); | |
6372 if (max_num_lines == 0) | |
6373 return; | |
6374 max_kbyte = get_viminfo_parameter('s'); | |
6375 if (max_kbyte == 0) | |
6376 return; | |
1893 | 6377 |
7 | 6378 for (i = 0; i < NUM_REGISTERS; i++) |
6379 { | |
6380 #ifdef FEAT_CLIPBOARD | |
6381 /* Skip '*'/'+' register, we don't want them back next time */ | |
6382 if (i == STAR_REGISTER || i == PLUS_REGISTER) | |
6383 continue; | |
6384 #endif | |
6385 #ifdef FEAT_DND | |
6386 /* Neither do we want the '~' register */ | |
6387 if (i == TILDE_REGISTER) | |
6388 continue; | |
6389 #endif | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6390 /* 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
|
6391 * viminfo if it's newer. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6392 if (y_read_regs != NULL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6393 && 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
|
6394 && (y_regs[i].y_array == NULL || |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6395 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
|
6396 y_ptr = &y_read_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6397 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
|
6398 continue; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6399 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6400 y_ptr = &y_regs[i]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6401 |
55 | 6402 /* Skip empty registers. */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6403 num_lines = y_ptr->y_size; |
55 | 6404 if (num_lines == 0 |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6405 || (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
|
6406 && *y_ptr->y_array[0] == NUL)) |
55 | 6407 continue; |
6408 | |
7 | 6409 if (max_kbyte > 0) |
6410 { | |
6411 /* Skip register if there is more text than the maximum size. */ | |
6412 len = 0; | |
6413 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
|
6414 len += (long)STRLEN(y_ptr->y_array[j]) + 1L; |
7 | 6415 if (len > (long)max_kbyte * 1024L) |
6416 continue; | |
6417 } | |
6418 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6419 switch (y_ptr->y_type) |
7 | 6420 { |
6421 case MLINE: | |
6422 type = (char_u *)"LINE"; | |
6423 break; | |
6424 case MCHAR: | |
6425 type = (char_u *)"CHAR"; | |
6426 break; | |
6427 case MBLOCK: | |
6428 type = (char_u *)"BLOCK"; | |
6429 break; | |
6430 default: | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6431 semsg(_("E574: Unknown register type %d"), y_ptr->y_type); |
7 | 6432 type = (char_u *)"LINE"; |
6433 break; | |
6434 } | |
6435 if (y_previous == &y_regs[i]) | |
6436 fprintf(fp, "\""); | |
6437 c = get_register_name(i); | |
1893 | 6438 fprintf(fp, "\"%c", c); |
6439 if (c == execreg_lastc) | |
6440 fprintf(fp, "@"); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6441 fprintf(fp, "\t%s\t%d\n", type, (int)y_ptr->y_width); |
7 | 6442 |
6443 /* If max_num_lines < 0, then we save ALL the lines in the register */ | |
6444 if (max_num_lines > 0 && num_lines > max_num_lines) | |
6445 num_lines = max_num_lines; | |
6446 for (j = 0; j < num_lines; j++) | |
6447 { | |
6448 putc('\t', fp); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6449 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
|
6450 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6451 |
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 int flags = 0; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6454 int remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6455 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6456 /* 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
|
6457 * |{bartype},{flags},{name},{type}, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6458 * {linecount},{width},{timestamp},"line1","line2" |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6459 * 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
|
6460 * REG_EXEC - used for @@ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6461 */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6462 if (y_previous == &y_regs[i]) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6463 flags |= REG_PREVIOUS; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6464 if (c == execreg_lastc) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6465 flags |= REG_EXEC; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6466 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
|
6467 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
|
6468 (long)y_ptr->y_time_set); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6469 /* 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
|
6470 remaining = LSIZE - 71; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6471 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
|
6472 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6473 putc(',', fp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6474 --remaining; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6475 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
|
6476 remaining); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6477 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6478 putc('\n', fp); |
7 | 6479 } |
6480 } | |
6481 } | |
6482 #endif /* FEAT_VIMINFO */ | |
6483 | |
6484 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
6485 /* | |
6486 * SELECTION / PRIMARY ('*') | |
6487 * | |
6488 * Text selection stuff that uses the GUI selection register '*'. When using a | |
6489 * GUI this may be text from another window, otherwise it is the last text we | |
6490 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
6491 * button performs the paste, otherwise you will need to do <"*p>. " | |
6492 * If not under X, it is synonymous with the clipboard register '+'. | |
6493 * | |
6494 * X CLIPBOARD ('+') | |
6495 * | |
6496 * Text selection stuff that uses the GUI clipboard register '+'. | |
6497 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
6498 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
6499 * otherwise you will need to do <"+p>. " | |
6500 * If not under X, it is synonymous with the selection register '*'. | |
6501 */ | |
6502 | |
6503 /* | |
6504 * 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
|
6505 * so that the text is still available after Vim has exited. X selections |
7 | 6506 * only exist while the owning application exists, so we write to the |
6507 * permanent (while X runs) store CUT_BUFFER0. | |
6508 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
6509 * 'permanent' of the two), otherwise the PRIMARY one. | |
6510 * For now, use a hard-coded sanity limit of 1Mb of data. | |
6511 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
6512 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 6513 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6514 x11_export_final_selection(void) |
7 | 6515 { |
6516 Display *dpy; | |
6517 char_u *str = NULL; | |
6518 long_u len = 0; | |
6519 int motion_type = -1; | |
6520 | |
6521 # ifdef FEAT_GUI | |
6522 if (gui.in_use) | |
6523 dpy = X_DISPLAY; | |
6524 else | |
6525 # endif | |
6526 # ifdef FEAT_XCLIPBOARD | |
6527 dpy = xterm_dpy; | |
6528 # else | |
6529 return; | |
6530 # endif | |
6531 | |
6532 /* Get selection to export */ | |
6533 if (clip_plus.owned) | |
6534 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6535 else if (clip_star.owned) | |
6536 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6537 | |
6538 /* Check it's OK */ | |
6539 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6540 && len < 1024*1024 && len > 0) | |
6541 { | |
1924 | 6542 #ifdef FEAT_MBYTE |
4201 | 6543 int ok = TRUE; |
6544 | |
1924 | 6545 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6546 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6547 * encoding conversion usually doesn't work, so keep the text as-is. | |
6548 */ | |
6549 if (has_mbyte) | |
6550 { | |
6551 vimconv_T vc; | |
6552 | |
6553 vc.vc_type = CONV_NONE; | |
6554 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6555 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6556 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6557 char_u *conv_str; |
2007 | 6558 |
4201 | 6559 vc.vc_fail = TRUE; |
2007 | 6560 conv_str = string_convert(&vc, str, &intlen); |
6561 len = intlen; | |
1924 | 6562 if (conv_str != NULL) |
6563 { | |
6564 vim_free(str); | |
6565 str = conv_str; | |
6566 } | |
4201 | 6567 else |
6568 { | |
6569 ok = FALSE; | |
6570 } | |
1924 | 6571 convert_setup(&vc, NULL, NULL); |
6572 } | |
4201 | 6573 else |
6574 { | |
6575 ok = FALSE; | |
6576 } | |
1924 | 6577 } |
4201 | 6578 |
6579 /* Do not store the string if conversion failed. Better to use any | |
6580 * other selection than garbled text. */ | |
6581 if (ok) | |
6582 #endif | |
6583 { | |
6584 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6585 XFlush(dpy); | |
6586 } | |
7 | 6587 } |
6588 | |
6589 vim_free(str); | |
6590 } | |
6591 #endif | |
6592 | |
6593 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6594 clip_free_selection(VimClipboard *cbd) |
7 | 6595 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6596 yankreg_T *y_ptr = y_current; |
7 | 6597 |
6598 if (cbd == &clip_plus) | |
6599 y_current = &y_regs[PLUS_REGISTER]; | |
6600 else | |
6601 y_current = &y_regs[STAR_REGISTER]; | |
6602 free_yank_all(); | |
6603 y_current->y_size = 0; | |
6604 y_current = y_ptr; | |
6605 } | |
6606 | |
6607 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
6608 * Get the selected text and put it in register '*' or '+'. |
7 | 6609 */ |
6610 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6611 clip_get_selection(VimClipboard *cbd) |
7 | 6612 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6613 yankreg_T *old_y_previous, *old_y_current; |
7 | 6614 pos_T old_cursor; |
6615 pos_T old_visual; | |
6616 int old_visual_mode; | |
6617 colnr_T old_curswant; | |
6618 int old_set_curswant; | |
6619 pos_T old_op_start, old_op_end; | |
6620 oparg_T oa; | |
6621 cmdarg_T ca; | |
6622 | |
6623 if (cbd->owned) | |
6624 { | |
6625 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6626 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6627 return; | |
6628 | |
6629 /* Get the text between clip_star.start & clip_star.end */ | |
6630 old_y_previous = y_previous; | |
6631 old_y_current = y_current; | |
6632 old_cursor = curwin->w_cursor; | |
6633 old_curswant = curwin->w_curswant; | |
6634 old_set_curswant = curwin->w_set_curswant; | |
6635 old_op_start = curbuf->b_op_start; | |
6636 old_op_end = curbuf->b_op_end; | |
6637 old_visual = VIsual; | |
6638 old_visual_mode = VIsual_mode; | |
6639 clear_oparg(&oa); | |
6640 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6641 oa.op_type = OP_YANK; | |
6642 vim_memset(&ca, 0, sizeof(ca)); | |
6643 ca.oap = &oa; | |
6644 ca.cmdchar = 'y'; | |
6645 ca.count1 = 1; | |
6646 ca.retval = CA_NO_ADJ_OP_END; | |
6647 do_pending_operator(&ca, 0, TRUE); | |
6648 y_previous = old_y_previous; | |
6649 y_current = old_y_current; | |
6650 curwin->w_cursor = old_cursor; | |
688 | 6651 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6652 curwin->w_curswant = old_curswant; |
6653 curwin->w_set_curswant = old_set_curswant; | |
6654 curbuf->b_op_start = old_op_start; | |
6655 curbuf->b_op_end = old_op_end; | |
6656 VIsual = old_visual; | |
6657 VIsual_mode = old_visual_mode; | |
6658 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6659 else if (!is_clipboard_needs_update()) |
7 | 6660 { |
6661 clip_free_selection(cbd); | |
6662 | |
6663 /* Try to get selected text from another window */ | |
6664 clip_gen_request_selection(cbd); | |
6665 } | |
6666 } | |
6667 | |
2896 | 6668 /* |
6669 * Convert from the GUI selection string into the '*'/'+' register. | |
6670 */ | |
7 | 6671 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6672 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6673 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6674 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6675 long len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6676 VimClipboard *cbd) |
7 | 6677 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6678 yankreg_T *y_ptr; |
7 | 6679 |
6680 if (cbd == &clip_plus) | |
6681 y_ptr = &y_regs[PLUS_REGISTER]; | |
6682 else | |
6683 y_ptr = &y_regs[STAR_REGISTER]; | |
6684 | |
6685 clip_free_selection(cbd); | |
6686 | |
5798 | 6687 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6688 } |
6689 | |
6690 /* | |
6691 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6692 * with length *len. | |
6693 * Returns the motion type, or -1 for failure. | |
6694 */ | |
6695 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6696 clip_convert_selection(char_u **str, long_u *len, VimClipboard *cbd) |
7 | 6697 { |
6698 char_u *p; | |
6699 int lnum; | |
6700 int i, j; | |
6701 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6702 yankreg_T *y_ptr; |
7 | 6703 |
6704 if (cbd == &clip_plus) | |
6705 y_ptr = &y_regs[PLUS_REGISTER]; | |
6706 else | |
6707 y_ptr = &y_regs[STAR_REGISTER]; | |
6708 | |
6709 #ifdef USE_CRNL | |
6710 eolsize = 2; | |
6711 #else | |
6712 eolsize = 1; | |
6713 #endif | |
6714 | |
6715 *str = NULL; | |
6716 *len = 0; | |
6717 if (y_ptr->y_array == NULL) | |
6718 return -1; | |
6719 | |
6720 for (i = 0; i < y_ptr->y_size; i++) | |
6721 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6722 | |
6723 /* | |
6724 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6725 */ | |
6726 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6727 *len -= eolsize; | |
6728 | |
6729 p = *str = lalloc(*len + 1, TRUE); /* add one to avoid zero */ | |
6730 if (p == NULL) | |
6731 return -1; | |
6732 lnum = 0; | |
6733 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6734 { | |
6735 if (y_ptr->y_array[lnum][j] == '\n') | |
6736 p[i] = NUL; | |
6737 else if (y_ptr->y_array[lnum][j] == NUL) | |
6738 { | |
6739 #ifdef USE_CRNL | |
6740 p[i++] = '\r'; | |
6741 #endif | |
6742 #ifdef USE_CR | |
6743 p[i] = '\r'; | |
6744 #else | |
6745 p[i] = '\n'; | |
6746 #endif | |
6747 lnum++; | |
6748 j = -1; | |
6749 } | |
6750 else | |
6751 p[i] = y_ptr->y_array[lnum][j]; | |
6752 } | |
6753 return y_ptr->y_type; | |
6754 } | |
6755 | |
6756 | |
6757 /* | |
6758 * If we have written to a clipboard register, send the text to the clipboard. | |
6759 */ | |
6760 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6761 may_set_selection(void) |
7 | 6762 { |
6763 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6764 { | |
6765 clip_own_selection(&clip_star); | |
6766 clip_gen_set_selection(&clip_star); | |
6767 } | |
6768 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6769 { | |
6770 clip_own_selection(&clip_plus); | |
6771 clip_gen_set_selection(&clip_plus); | |
6772 } | |
6773 } | |
6774 | |
6775 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6776 | |
6777 | |
6778 #if defined(FEAT_DND) || defined(PROTO) | |
6779 /* | |
6780 * Replace the contents of the '~' register with str. | |
6781 */ | |
6782 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6783 dnd_yank_drag_data(char_u *str, long len) |
7 | 6784 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6785 yankreg_T *curr; |
7 | 6786 |
6787 curr = y_current; | |
6788 y_current = &y_regs[TILDE_REGISTER]; | |
6789 free_yank_all(); | |
5798 | 6790 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6791 y_current = curr; |
6792 } | |
6793 #endif | |
6794 | |
6795 | |
6796 #if defined(FEAT_EVAL) || defined(PROTO) | |
6797 /* | |
6798 * Return the type of a register. | |
6799 * Used for getregtype() | |
6800 * Returns MAUTO for error. | |
6801 */ | |
6802 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6803 get_reg_type(int regname, long *reglen) |
7 | 6804 { |
6805 switch (regname) | |
6806 { | |
6807 case '%': /* file name */ | |
6808 case '#': /* alternate file name */ | |
6809 case '=': /* expression */ | |
6810 case ':': /* last command line */ | |
6811 case '/': /* last search-pattern */ | |
6812 case '.': /* last inserted text */ | |
6813 #ifdef FEAT_SEARCHPATH | |
6814 case Ctrl_F: /* Filename under cursor */ | |
6815 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6816 #endif | |
6817 case Ctrl_W: /* word under cursor */ | |
6818 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6819 case '_': /* black hole: always empty */ | |
6820 return MCHAR; | |
6821 } | |
6822 | |
6823 #ifdef FEAT_CLIPBOARD | |
6824 regname = may_get_selection(regname); | |
6825 #endif | |
6826 | |
5596 | 6827 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
|
6828 return MAUTO; |
5596 | 6829 |
7 | 6830 get_yank_register(regname, FALSE); |
6831 | |
6832 if (y_current->y_array != NULL) | |
6833 { | |
6834 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6835 *reglen = y_current->y_width; | |
6836 return y_current->y_type; | |
6837 } | |
6838 return MAUTO; | |
6839 } | |
6840 | |
5796 | 6841 /* |
6842 * When "flags" has GREG_LIST return a list with text "s". | |
6843 * Otherwise just return "s". | |
6844 */ | |
6845 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6846 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6847 { |
6848 if (flags & GREG_LIST) | |
6849 { | |
6850 list_T *list = list_alloc(); | |
6851 | |
6852 if (list != NULL) | |
6853 { | |
6854 if (list_append_string(list, NULL, -1) == FAIL) | |
6855 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6856 list_free(list); |
5796 | 6857 return NULL; |
6858 } | |
6859 list->lv_first->li_tv.vval.v_string = s; | |
6860 } | |
6861 return (char_u *)list; | |
6862 } | |
6863 return s; | |
6864 } | |
6865 | |
7 | 6866 /* |
6867 * Return the contents of a register as a single allocated string. | |
6868 * Used for "@r" in expressions and for getreg(). | |
6869 * Returns NULL for error. | |
5796 | 6870 * Flags: |
6871 * GREG_NO_EXPR Do not allow expression register | |
6872 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6873 * not the result of its evaluation. | |
6874 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6875 */ |
6876 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6877 get_reg_contents(int regname, int flags) |
7 | 6878 { |
6879 long i; | |
6880 char_u *retval; | |
6881 int allocated; | |
6882 long len; | |
6883 | |
6884 /* Don't allow using an expression register inside an expression */ | |
6885 if (regname == '=') | |
6886 { | |
5796 | 6887 if (flags & GREG_NO_EXPR) |
6888 return NULL; | |
6889 if (flags & GREG_EXPR_SRC) | |
6890 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6891 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6892 } |
6893 | |
6894 if (regname == '@') /* "@@" is used for unnamed register */ | |
6895 regname = '"'; | |
6896 | |
6897 /* check for valid regname */ | |
6898 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6899 return NULL; | |
6900 | |
6901 #ifdef FEAT_CLIPBOARD | |
6902 regname = may_get_selection(regname); | |
6903 #endif | |
6904 | |
6905 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6906 { | |
6907 if (retval == NULL) | |
6908 return NULL; | |
5796 | 6909 if (allocated) |
6910 return getreg_wrap_one_line(retval, flags); | |
6911 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6912 } |
6913 | |
6914 get_yank_register(regname, FALSE); | |
6915 if (y_current->y_array == NULL) | |
6916 return NULL; | |
6917 | |
5796 | 6918 if (flags & GREG_LIST) |
6919 { | |
6920 list_T *list = list_alloc(); | |
6921 int error = FALSE; | |
6922 | |
6923 if (list == NULL) | |
6924 return NULL; | |
6925 for (i = 0; i < y_current->y_size; ++i) | |
6926 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6927 error = TRUE; | |
6928 if (error) | |
6929 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6930 list_free(list); |
5796 | 6931 return NULL; |
6932 } | |
6933 return (char_u *)list; | |
6934 } | |
6935 | |
7 | 6936 /* |
6937 * Compute length of resulting string. | |
6938 */ | |
6939 len = 0; | |
6940 for (i = 0; i < y_current->y_size; ++i) | |
6941 { | |
6942 len += (long)STRLEN(y_current->y_array[i]); | |
6943 /* | |
6944 * Insert a newline between lines and after last line if | |
6945 * y_type is MLINE. | |
6946 */ | |
6947 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6948 ++len; | |
6949 } | |
6950 | |
6951 retval = lalloc(len + 1, TRUE); | |
6952 | |
6953 /* | |
6954 * Copy the lines of the yank register into the string. | |
6955 */ | |
6956 if (retval != NULL) | |
6957 { | |
6958 len = 0; | |
6959 for (i = 0; i < y_current->y_size; ++i) | |
6960 { | |
6961 STRCPY(retval + len, y_current->y_array[i]); | |
6962 len += (long)STRLEN(retval + len); | |
6963 | |
6964 /* | |
6965 * Insert a NL between lines and after the last line if y_type is | |
6966 * MLINE. | |
6967 */ | |
6968 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6969 retval[len++] = '\n'; | |
6970 } | |
6971 retval[len] = NUL; | |
6972 } | |
6973 | |
6974 return retval; | |
6975 } | |
6976 | |
5798 | 6977 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6978 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6979 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6980 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6981 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6982 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6983 int *yank_type UNUSED) |
5798 | 6984 { |
6985 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6986 { | |
6987 emsg_invreg(name); | |
6988 return FAIL; | |
6989 } | |
6990 | |
6991 /* Don't want to change the current (unnamed) register */ | |
6992 *old_y_previous = y_previous; | |
6993 *old_y_current = y_current; | |
6994 | |
6995 get_yank_register(name, TRUE); | |
6996 if (!y_append && !must_append) | |
6997 free_yank_all(); | |
6998 return OK; | |
6999 } | |
7000 | |
7001 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7002 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7003 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7004 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7005 yankreg_T *old_y_current) |
5798 | 7006 { |
7007 # ifdef FEAT_CLIPBOARD | |
7008 /* Send text of clipboard register to the clipboard. */ | |
7009 may_set_selection(); | |
7010 # endif | |
7011 | |
7012 /* ':let @" = "val"' should change the meaning of the "" register */ | |
7013 if (name != '"') | |
7014 y_previous = old_y_previous; | |
7015 y_current = old_y_current; | |
7016 } | |
7017 | |
7 | 7018 /* |
7019 * Store string "str" in register "name". | |
7020 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
7021 * If "must_append" is TRUE, always append to the register. Otherwise append | |
7022 * if "name" is an uppercase letter. | |
7023 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
7024 * Careful: 'str' is modified, you may have to use a copy! | |
7025 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
7026 */ | |
7027 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7028 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7029 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7030 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7031 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7032 int must_append) |
7 | 7033 { |
7034 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
7035 } | |
7036 | |
7037 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7038 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7039 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7040 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7041 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7042 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7043 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7044 long block_len) |
5798 | 7045 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7046 yankreg_T *old_y_previous, *old_y_current; |
5798 | 7047 |
7048 if (name == '/' | |
7049 #ifdef FEAT_EVAL | |
7050 || name == '=' | |
7051 #endif | |
7052 ) | |
7053 { | |
7054 char_u *s; | |
7055 | |
7056 if (strings[0] == NULL) | |
7057 s = (char_u *)""; | |
7058 else if (strings[1] != NULL) | |
7059 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
7060 emsg(_("E883: search pattern and expression register may not " |
5798 | 7061 "contain two or more lines")); |
7062 return; | |
7063 } | |
7064 else | |
7065 s = strings[0]; | |
7066 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
7067 return; | |
7068 } | |
7069 | |
7070 if (name == '_') /* black hole: nothing to do */ | |
7071 return; | |
7072 | |
7073 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
7074 &yank_type) == FAIL) | |
7075 return; | |
7076 | |
7077 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
7078 | |
7079 finish_write_reg(name, old_y_previous, old_y_current); | |
7080 } | |
7081 | |
7082 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7083 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7084 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7085 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7086 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7087 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7088 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7089 long block_len) |
7 | 7090 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7091 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
|
7092 long len; |
7 | 7093 |
336 | 7094 if (maxlen >= 0) |
7095 len = maxlen; | |
7096 else | |
7097 len = (long)STRLEN(str); | |
7098 | |
7 | 7099 /* Special case: '/' search pattern */ |
7100 if (name == '/') | |
7101 { | |
7102 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
7103 return; | |
7104 } | |
7105 | |
6557 | 7106 if (name == '#') |
7107 { | |
7108 buf_T *buf; | |
7109 | |
7110 if (VIM_ISDIGIT(*str)) | |
7111 { | |
7112 int num = atoi((char *)str); | |
7113 | |
7114 buf = buflist_findnr(num); | |
7115 if (buf == NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
7116 semsg(_(e_nobufnr), (long)num); |
6557 | 7117 } |
7118 else | |
7119 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
7120 TRUE, FALSE, FALSE)); | |
7121 if (buf == NULL) | |
7122 return; | |
7123 curwin->w_alt_fnum = buf->b_fnum; | |
7124 return; | |
7125 } | |
7126 | |
336 | 7127 #ifdef FEAT_EVAL |
7128 if (name == '=') | |
7129 { | |
7130 char_u *p, *s; | |
7131 | |
7132 p = vim_strnsave(str, (int)len); | |
7133 if (p == NULL) | |
7134 return; | |
7135 if (must_append) | |
7136 { | |
7137 s = concat_str(get_expr_line_src(), p); | |
7138 vim_free(p); | |
7139 p = s; | |
7140 } | |
7141 set_expr_line(p); | |
7142 return; | |
7143 } | |
7144 #endif | |
7145 | |
7 | 7146 if (name == '_') /* black hole: nothing to do */ |
7147 return; | |
7148 | |
5798 | 7149 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
7150 &yank_type) == FAIL) | |
7151 return; | |
7152 | |
7153 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
7154 | |
7155 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 7156 } |
7157 #endif /* FEAT_EVAL */ | |
7158 | |
7159 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
7160 /* | |
7161 * Put a string into a register. When the register is not empty, the string | |
7162 * is appended. | |
7163 */ | |
7164 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7165 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7166 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
|
7167 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
|
7168 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
|
7169 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7170 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7171 int str_list) /* TRUE if str is char_u ** */ |
7 | 7172 { |
2896 | 7173 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 7174 int lnum; |
7175 long start; | |
7176 long i; | |
7177 int extra; | |
7178 int newlines; /* number of lines added */ | |
7179 int extraline = 0; /* extra line at the end */ | |
7180 int append = FALSE; /* append to last line in register */ | |
7181 char_u *s; | |
5798 | 7182 char_u **ss; |
7 | 7183 char_u **pp; |
7184 long maxlen; | |
7185 | |
2000 | 7186 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 7187 y_ptr->y_size = 0; |
7188 | |
2896 | 7189 if (yank_type == MAUTO) |
5798 | 7190 type = ((str_list || (len > 0 && (str[len - 1] == NL |
7191 || str[len - 1] == CAR))) | |
2896 | 7192 ? MLINE : MCHAR); |
7193 else | |
7194 type = yank_type; | |
7195 | |
7 | 7196 /* |
7197 * Count the number of lines within the string | |
7198 */ | |
7199 newlines = 0; | |
5798 | 7200 if (str_list) |
7201 { | |
7202 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 7203 ++newlines; |
5798 | 7204 } |
7205 else | |
7206 { | |
7207 for (i = 0; i < len; i++) | |
7208 if (str[i] == '\n') | |
7209 ++newlines; | |
7210 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
7211 { | |
7212 extraline = 1; | |
7213 ++newlines; /* count extra newline at the end */ | |
7214 } | |
7215 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
7216 { | |
7217 append = TRUE; | |
7218 --newlines; /* uncount newline when appending first line */ | |
7219 } | |
7 | 7220 } |
7221 | |
6807 | 7222 /* Without any lines make the register empty. */ |
7223 if (y_ptr->y_size + newlines == 0) | |
7224 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
7225 VIM_CLEAR(y_ptr->y_array); |
6807 | 7226 return; |
7227 } | |
7228 | |
7 | 7229 /* |
7230 * Allocate an array to hold the pointers to the new register lines. | |
7231 * If the register was not empty, move the existing lines to the new array. | |
7232 */ | |
7233 pp = (char_u **)lalloc_clear((y_ptr->y_size + newlines) | |
7234 * sizeof(char_u *), TRUE); | |
7235 if (pp == NULL) /* out of memory */ | |
7236 return; | |
7237 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
7238 pp[lnum] = y_ptr->y_array[lnum]; | |
7239 vim_free(y_ptr->y_array); | |
7240 y_ptr->y_array = pp; | |
7241 maxlen = 0; | |
7242 | |
7243 /* | |
7244 * Find the end of each line and save it into the array. | |
7245 */ | |
5798 | 7246 if (str_list) |
7247 { | |
7248 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 7249 { |
5856 | 7250 i = (long)STRLEN(*ss); |
5798 | 7251 pp[lnum] = vim_strnsave(*ss, i); |
7252 if (i > maxlen) | |
7253 maxlen = i; | |
7 | 7254 } |
5798 | 7255 } |
7256 else | |
7257 { | |
7258 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 7259 { |
5798 | 7260 for (i = start; i < len; ++i) /* find the end of the line */ |
7261 if (str[i] == '\n') | |
7262 break; | |
7263 i -= start; /* i is now length of line */ | |
7264 if (i > maxlen) | |
7265 maxlen = i; | |
7266 if (append) | |
7267 { | |
7268 --lnum; | |
7269 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
7270 } | |
7271 else | |
7272 extra = 0; | |
7273 s = alloc((unsigned)(i + extra + 1)); | |
7274 if (s == NULL) | |
7275 break; | |
7276 if (extra) | |
7277 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
7278 if (append) | |
7279 vim_free(y_ptr->y_array[lnum]); | |
7280 if (i) | |
7281 mch_memmove(s + extra, str + start, (size_t)i); | |
7282 extra += i; | |
7283 s[extra] = NUL; | |
7284 y_ptr->y_array[lnum++] = s; | |
7285 while (--extra >= 0) | |
7286 { | |
7287 if (*s == NUL) | |
7288 *s = '\n'; /* replace NUL with newline */ | |
7289 ++s; | |
7290 } | |
7291 append = FALSE; /* only first line is appended */ | |
7 | 7292 } |
7293 } | |
7294 y_ptr->y_type = type; | |
7295 y_ptr->y_size = lnum; | |
7296 if (type == MBLOCK) | |
7297 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
7298 else | |
7299 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7300 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
7301 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
|
7302 #endif |
7 | 7303 } |
7304 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
7305 | |
7306 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7307 clear_oparg(oparg_T *oap) |
7 | 7308 { |
7309 vim_memset(oap, 0, sizeof(oparg_T)); | |
7310 } | |
7311 | |
7312 /* | |
161 | 7313 * Count the number of bytes, characters and "words" in a line. |
7 | 7314 * |
7315 * "Words" are counted by looking for boundaries between non-space and | |
7316 * space characters. (it seems to produce results that match 'wc'.) | |
7317 * | |
161 | 7318 * Return value is byte count; word count for the line is added to "*wc". |
7319 * Char count is added to "*cc". | |
7 | 7320 * |
7321 * The function will only examine the first "limit" characters in the | |
7322 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
7323 * case, eol_size will be added to the character count to account for | |
7324 * the size of the EOL character. | |
7325 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7326 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7327 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7328 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7329 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7330 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7331 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7332 int eol_size) |
7 | 7333 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7334 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7335 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7336 varnumber_T chars = 0; |
7 | 7337 int is_word = 0; |
7338 | |
3626 | 7339 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 7340 { |
7341 if (is_word) | |
7342 { | |
7343 if (vim_isspace(line[i])) | |
7344 { | |
7345 words++; | |
7346 is_word = 0; | |
7347 } | |
7348 } | |
7349 else if (!vim_isspace(line[i])) | |
7350 is_word = 1; | |
161 | 7351 ++chars; |
7352 #ifdef FEAT_MBYTE | |
474 | 7353 i += (*mb_ptr2len)(line + i); |
161 | 7354 #else |
7355 ++i; | |
7356 #endif | |
7 | 7357 } |
7358 | |
7359 if (is_word) | |
7360 words++; | |
7361 *wc += words; | |
7362 | |
7363 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 7364 if (i < limit && line[i] == NUL) |
161 | 7365 { |
7 | 7366 i += eol_size; |
161 | 7367 chars += eol_size; |
7368 } | |
7369 *cc += chars; | |
7 | 7370 return i; |
7371 } | |
7372 | |
7373 /* | |
7374 * Give some info about the position of the cursor (for "g CTRL-G"). | |
7375 * In Visual mode, give some info about the selected region. (In this case, | |
7376 * 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
|
7377 * When "dict" is not NULL store the info there instead of showing it. |
7 | 7378 */ |
7379 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
7380 cursor_pos_info(dict_T *dict) |
7 | 7381 { |
7382 char_u *p; | |
274 | 7383 char_u buf1[50]; |
7384 char_u buf2[40]; | |
7 | 7385 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7386 varnumber_T byte_count = 0; |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7387 #ifdef FEAT_MBYTE |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7388 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7389 #endif |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7390 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7391 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7392 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7393 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7394 varnumber_T word_count_cursor = 0; |
7 | 7395 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7396 varnumber_T last_check = 100000L; |
7 | 7397 long line_count_selected = 0; |
7398 pos_T min_pos, max_pos; | |
7399 oparg_T oparg; | |
7400 struct block_def bd; | |
7401 | |
7402 /* | |
7403 * Compute the length of the file in characters. | |
7404 */ | |
7405 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
7406 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7407 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7408 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
7409 msg(_(no_lines_msg)); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7410 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7411 } |
7 | 7412 } |
7413 else | |
7414 { | |
7415 if (get_fileformat(curbuf) == EOL_DOS) | |
7416 eol_size = 2; | |
7417 else | |
7418 eol_size = 1; | |
7419 | |
7420 if (VIsual_active) | |
7421 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
7422 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 7423 { |
7424 min_pos = VIsual; | |
7425 max_pos = curwin->w_cursor; | |
7426 } | |
7427 else | |
7428 { | |
7429 min_pos = curwin->w_cursor; | |
7430 max_pos = VIsual; | |
7431 } | |
7432 if (*p_sel == 'e' && max_pos.col > 0) | |
7433 --max_pos.col; | |
7434 | |
7435 if (VIsual_mode == Ctrl_V) | |
7436 { | |
1866 | 7437 #ifdef FEAT_LINEBREAK |
7438 char_u * saved_sbr = p_sbr; | |
7439 | |
7440 /* Make 'sbr' empty for a moment to get the correct size. */ | |
7441 p_sbr = empty_option; | |
7442 #endif | |
7 | 7443 oparg.is_VIsual = 1; |
7444 oparg.block_mode = TRUE; | |
7445 oparg.op_type = OP_NOP; | |
7446 getvcols(curwin, &min_pos, &max_pos, | |
688 | 7447 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 7448 #ifdef FEAT_LINEBREAK |
7449 p_sbr = saved_sbr; | |
7450 #endif | |
688 | 7451 if (curwin->w_curswant == MAXCOL) |
7452 oparg.end_vcol = MAXCOL; | |
7 | 7453 /* Swap the start, end vcol if needed */ |
7454 if (oparg.end_vcol < oparg.start_vcol) | |
7455 { | |
7456 oparg.end_vcol += oparg.start_vcol; | |
7457 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
7458 oparg.end_vcol -= oparg.start_vcol; | |
7459 } | |
7460 } | |
7461 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
7462 } | |
7463 | |
7464 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
7465 { | |
7466 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 7467 if (byte_count > last_check) |
7 | 7468 { |
7469 ui_breakcheck(); | |
7470 if (got_int) | |
7471 return; | |
161 | 7472 last_check = byte_count + 100000L; |
7 | 7473 } |
7474 | |
7475 /* Do extra processing for VIsual mode. */ | |
7476 if (VIsual_active | |
7477 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
7478 { | |
45 | 7479 char_u *s = NULL; |
7480 long len = 0L; | |
7481 | |
7 | 7482 switch (VIsual_mode) |
7483 { | |
7484 case Ctrl_V: | |
5735 | 7485 #ifdef FEAT_VIRTUALEDIT |
7 | 7486 virtual_op = virtual_active(); |
5735 | 7487 #endif |
7 | 7488 block_prep(&oparg, &bd, lnum, 0); |
5735 | 7489 #ifdef FEAT_VIRTUALEDIT |
7 | 7490 virtual_op = MAYBE; |
5735 | 7491 #endif |
45 | 7492 s = bd.textstart; |
7493 len = (long)bd.textlen; | |
7 | 7494 break; |
7495 case 'V': | |
45 | 7496 s = ml_get(lnum); |
7497 len = MAXCOL; | |
7 | 7498 break; |
7499 case 'v': | |
7500 { | |
7501 colnr_T start_col = (lnum == min_pos.lnum) | |
7502 ? min_pos.col : 0; | |
7503 colnr_T end_col = (lnum == max_pos.lnum) | |
7504 ? max_pos.col - start_col + 1 : MAXCOL; | |
7505 | |
45 | 7506 s = ml_get(lnum) + start_col; |
7507 len = end_col; | |
7 | 7508 } |
7509 break; | |
7510 } | |
45 | 7511 if (s != NULL) |
7512 { | |
161 | 7513 byte_count_cursor += line_count_info(s, &word_count_cursor, |
7514 &char_count_cursor, len, eol_size); | |
45 | 7515 if (lnum == curbuf->b_ml.ml_line_count |
7516 && !curbuf->b_p_eol | |
6933 | 7517 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 7518 && (long)STRLEN(s) < len) |
161 | 7519 byte_count_cursor -= eol_size; |
45 | 7520 } |
7 | 7521 } |
7522 else | |
7523 { | |
7524 /* In non-visual mode, check for the line the cursor is on */ | |
7525 if (lnum == curwin->w_cursor.lnum) | |
7526 { | |
7527 word_count_cursor += word_count; | |
161 | 7528 char_count_cursor += char_count; |
7529 byte_count_cursor = byte_count + | |
7530 line_count_info(ml_get(lnum), | |
7531 &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
|
7532 (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
|
7533 eol_size); |
7 | 7534 } |
7535 } | |
7536 /* Add to the running totals */ | |
161 | 7537 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
|
7538 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7539 eol_size); |
7 | 7540 } |
7541 | |
7542 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7543 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7544 byte_count -= eol_size; |
7 | 7545 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7546 if (dict == NULL) |
7 | 7547 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7548 if (VIsual_active) |
7 | 7549 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7550 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
|
7551 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7552 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
|
7553 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7554 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
|
7555 (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
|
7556 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7557 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7558 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7559 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7560 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
|
7561 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7562 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7563 _("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
|
7564 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7565 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7566 (long_long_T)word_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7567 (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7568 (long_long_T)byte_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7569 (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7570 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7571 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7572 _("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
|
7573 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7574 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7575 (long_long_T)word_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7576 (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7577 (long_long_T)char_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7578 (long_long_T)char_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7579 (long_long_T)byte_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7580 (long_long_T)byte_count); |
7 | 7581 } |
7582 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7583 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7584 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7585 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7586 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
|
7587 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7588 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
|
7589 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7590 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7591 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
|
7592 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7593 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7594 _("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
|
7595 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7596 (long)curwin->w_cursor.lnum, |
7 | 7597 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7598 (long_long_T)word_count_cursor, (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7599 (long_long_T)byte_count_cursor, (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7600 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7601 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7602 _("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
|
7603 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7604 (long)curwin->w_cursor.lnum, |
161 | 7605 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7606 (long_long_T)word_count_cursor, (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7607 (long_long_T)char_count_cursor, (long_long_T)char_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7608 (long_long_T)byte_count_cursor, (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7609 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7610 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7611 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7612 #ifdef FEAT_MBYTE |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7613 bom_count = bomb_size(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7614 if (bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7615 vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7616 _("(+%lld for BOM)"), (long_long_T)bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7617 #endif |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7618 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7619 { |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7620 /* 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
|
7621 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7622 p_shm = (char_u *)""; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
7623 msg((char *)IObuff); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7624 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7625 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7626 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7627 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7628 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7629 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7630 dict_add_number(dict, "words", word_count); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7631 dict_add_number(dict, "chars", char_count); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7632 dict_add_number(dict, "bytes", byte_count |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7633 # ifdef FEAT_MBYTE |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7634 + bom_count |
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7635 # endif |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7636 ); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7637 dict_add_number(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7638 byte_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7639 dict_add_number(dict, VIsual_active ? "visual_chars" : "cursor_chars", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7640 char_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7641 dict_add_number(dict, VIsual_active ? "visual_words" : "cursor_words", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7642 word_count_cursor); |
7 | 7643 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7644 #endif |
7 | 7645 } |