Mercurial > vim
annotate src/register.c @ 32669:448aef880252
normalize line endings
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 26 Jun 2023 09:54:34 +0200 |
parents | c8b28054caec |
children | 695b50472e85 |
rev | line source |
---|---|
32669
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3 * VIM - Vi IMproved by Bram Moolenaar |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
4 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
5 * Do ":help uganda" in Vim to read copying and usage conditions. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
6 * Do ":help credits" in Vim to see a list of people who contributed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
7 * See README.txt for an overview of the Vim source code. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
8 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
9 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
10 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
11 * register.c: functions for managing registers |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
12 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
13 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
14 #include "vim.h" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
15 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
16 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
17 * Registers: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
18 * 0 = unnamed register, for normal yanks and puts |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
19 * 1..9 = registers '1' to '9', for deletes |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
20 * 10..35 = registers 'a' to 'z' ('A' to 'Z' for appending) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
21 * 36 = delete register '-' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
22 * 37 = Selection register '*'. Only if FEAT_CLIPBOARD defined |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
23 * 38 = Clipboard register '+'. Only if FEAT_CLIPBOARD and FEAT_X11 defined |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
24 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
25 static yankreg_T y_regs[NUM_REGISTERS]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
26 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
27 static yankreg_T *y_current; // ptr to current yankreg |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
28 static int y_append; // TRUE when appending |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
29 static yankreg_T *y_previous = NULL; // ptr to last written yankreg |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
30 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
31 static int stuff_yank(int, char_u *); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
32 static void put_reedit_in_typebuf(int silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
33 static int put_in_typebuf(char_u *s, int esc, int colon, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
34 int silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
35 static int yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
36 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
37 static void copy_yank_reg(yankreg_T *reg); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
38 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
39 static void dis_msg(char_u *p, int skip_esc); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
40 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
41 #if defined(FEAT_VIMINFO) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
42 yankreg_T * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
43 get_y_regs(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
44 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
45 return y_regs; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
46 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
47 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
48 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
49 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
50 yankreg_T * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
51 get_y_register(int reg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
52 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
53 return &y_regs[reg]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
54 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
55 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
56 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
57 yankreg_T * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
58 get_y_current(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
59 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
60 return y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
61 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
62 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
63 yankreg_T * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
64 get_y_previous(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
65 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
66 return y_previous; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
67 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
68 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
69 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
70 set_y_current(yankreg_T *yreg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
71 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
72 y_current = yreg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
73 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
74 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
75 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
76 set_y_previous(yankreg_T *yreg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
77 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
78 y_previous = yreg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
79 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
80 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
81 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
82 reset_y_append(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
83 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
84 y_append = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
85 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
86 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
87 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
88 #if defined(FEAT_EVAL) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
89 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
90 * Keep the last expression line here, for repeating. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
91 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
92 static char_u *expr_line = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
93 static exarg_T *expr_eap = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
94 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
95 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
96 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
97 * Returns '=' when OK, NUL otherwise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
98 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
99 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
100 get_expr_register(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
101 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
102 char_u *new_line; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
103 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
104 new_line = getcmdline('=', 0L, 0, 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
105 if (new_line == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
106 return NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
107 if (*new_line == NUL) // use previous line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
108 vim_free(new_line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
109 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
110 set_expr_line(new_line, NULL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
111 return '='; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
112 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
113 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
114 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
115 * Set the expression for the '=' register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
116 * Argument must be an allocated string. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
117 * "eap" may be used if the next line needs to be checked when evaluating the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
118 * expression. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
119 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
120 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
121 set_expr_line(char_u *new_line, exarg_T *eap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
122 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
123 vim_free(expr_line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
124 expr_line = new_line; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
125 expr_eap = eap; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
126 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
127 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
128 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
129 * Get the result of the '=' register expression. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
130 * Returns a pointer to allocated memory, or NULL for failure. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
131 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
132 char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
133 get_expr_line(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
134 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
135 char_u *expr_copy; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
136 char_u *rv; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
137 static int nested = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
138 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
139 if (expr_line == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
140 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
141 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
142 // Make a copy of the expression, because evaluating it may cause it to be |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
143 // changed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
144 expr_copy = vim_strsave(expr_line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
145 if (expr_copy == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
146 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
147 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
148 // When we are invoked recursively limit the evaluation to 10 levels. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
149 // Then return the string as-is. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
150 if (nested >= 10) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
151 return expr_copy; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
152 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
153 ++nested; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
154 rv = eval_to_string_eap(expr_copy, TRUE, expr_eap, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
155 --nested; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
156 vim_free(expr_copy); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
157 return rv; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
158 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
159 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
160 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
161 * Get the '=' register expression itself, without evaluating it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
162 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
163 static char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
164 get_expr_line_src(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
165 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
166 if (expr_line == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
167 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
168 return vim_strsave(expr_line); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
169 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
170 #endif // FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
171 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
172 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
173 * Check if 'regname' is a valid name of a yank register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
174 * Note: There is no check for 0 (default register), caller should do this |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
175 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
176 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
177 valid_yank_reg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
178 int regname, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
179 int writing) // if TRUE check for writable registers |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
180 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
181 if ( (regname > 0 && ASCII_ISALNUM(regname)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
182 || (!writing && vim_strchr((char_u *) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
183 #ifdef FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
184 "/.%:=" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
185 #else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
186 "/.%:" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
187 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
188 , regname) != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
189 || regname == '#' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
190 || regname == '"' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
191 || regname == '-' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
192 || regname == '_' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
193 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
194 || regname == '*' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
195 || regname == '+' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
196 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
197 #ifdef FEAT_DND |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
198 || (!writing && regname == '~') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
199 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
200 ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
201 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
202 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
203 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
204 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
205 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
206 * Set y_current and y_append, according to the value of "regname". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
207 * Cannot handle the '_' register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
208 * Must only be called with a valid register name! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
209 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
210 * If regname is 0 and writing, use register 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
211 * If regname is 0 and reading, use previous register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
212 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
213 * Return TRUE when the register should be inserted literally (selection or |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
214 * clipboard). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
215 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
216 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
217 get_yank_register(int regname, int writing) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
218 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
219 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
220 int ret = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
221 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
222 y_append = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
223 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
224 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
225 y_current = y_previous; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
226 return ret; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
227 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
228 i = regname; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
229 if (VIM_ISDIGIT(i)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
230 i -= '0'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
231 else if (ASCII_ISLOWER(i)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
232 i = CharOrdLow(i) + 10; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
233 else if (ASCII_ISUPPER(i)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
234 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
235 i = CharOrdUp(i) + 10; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
236 y_append = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
237 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
238 else if (regname == '-') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
239 i = DELETION_REGISTER; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
240 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
241 // When selection is not available, use register 0 instead of '*' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
242 else if (clip_star.available && regname == '*') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
243 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
244 i = STAR_REGISTER; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
245 ret = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
246 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
247 // When clipboard is not available, use register 0 instead of '+' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
248 else if (clip_plus.available && regname == '+') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
249 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
250 i = PLUS_REGISTER; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
251 ret = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
252 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
253 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
254 #ifdef FEAT_DND |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
255 else if (!writing && regname == '~') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
256 i = TILDE_REGISTER; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
257 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
258 else // not 0-9, a-z, A-Z or '-': use register 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
259 i = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
260 y_current = &(y_regs[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
261 if (writing) // remember the register we write into for do_put() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
262 y_previous = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
263 return ret; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
264 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
265 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
266 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
267 * Obtain the contents of a "normal" register. The register is made empty. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
268 * The returned pointer has allocated memory, use put_register() later. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
269 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
270 void * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
271 get_register( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
272 int name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
273 int copy) // make a copy, if FALSE make register empty. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
274 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
275 yankreg_T *reg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
276 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
277 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
278 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
279 // When Visual area changed, may have to update selection. Obtain the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
280 // selection too. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
281 if (name == '*' && clip_star.available) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
282 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
283 if (clip_isautosel_star()) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
284 clip_update_selection(&clip_star); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
285 may_get_selection(name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
286 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
287 if (name == '+' && clip_plus.available) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
288 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
289 if (clip_isautosel_plus()) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
290 clip_update_selection(&clip_plus); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
291 may_get_selection(name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
292 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
293 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
294 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
295 get_yank_register(name, 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
296 reg = ALLOC_ONE(yankreg_T); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
297 if (reg == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
298 return (void *)NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
299 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
300 *reg = *y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
301 if (copy) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
302 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
303 // If we run out of memory some or all of the lines are empty. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
304 if (reg->y_size == 0 || y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
305 reg->y_array = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
306 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
307 reg->y_array = ALLOC_MULT(char_u *, reg->y_size); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
308 if (reg->y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
309 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
310 for (i = 0; i < reg->y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
311 reg->y_array[i] = vim_strsave(y_current->y_array[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
312 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
313 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
314 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
315 y_current->y_array = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
316 return (void *)reg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
317 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
318 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
319 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
320 * Put "reg" into register "name". Free any previous contents and "reg". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
321 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
322 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
323 put_register(int name, void *reg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
324 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
325 get_yank_register(name, 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
326 free_yank_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
327 *y_current = *(yankreg_T *)reg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
328 vim_free(reg); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
329 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
330 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
331 // Send text written to clipboard register to the clipboard. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
332 may_set_selection(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
333 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
334 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
335 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
336 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
337 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
338 free_register(void *reg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
339 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
340 yankreg_T tmp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
341 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
342 tmp = *y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
343 *y_current = *(yankreg_T *)reg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
344 free_yank_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
345 vim_free(reg); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
346 *y_current = tmp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
347 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
348 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
349 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
350 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
351 * return TRUE if the current yank register has type MLINE |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
352 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
353 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
354 yank_register_mline(int regname) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
355 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
356 if (regname != 0 && !valid_yank_reg(regname, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
357 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
358 if (regname == '_') // black hole is always empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
359 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
360 get_yank_register(regname, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
361 return (y_current->y_type == MLINE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
362 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
363 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
364 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
365 * Start or stop recording into a yank register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
366 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
367 * Return FAIL for failure, OK otherwise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
368 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
369 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
370 do_record(int c) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
371 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
372 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
373 static int regname; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
374 yankreg_T *old_y_previous, *old_y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
375 int retval; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
376 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
377 if (reg_recording == 0) // start recording |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
378 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
379 // registers 0-9, a-z and " are allowed |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
380 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
381 retval = FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
382 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
383 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
384 reg_recording = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
385 showmode(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
386 regname = c; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
387 retval = OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
388 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
389 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
390 else // stop recording |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
391 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
392 // Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
393 // needs to be removed again to put it in a register. exec_reg then |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
394 // adds the escaping back later. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
395 reg_recording = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
396 msg(""); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
397 p = get_recorded(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
398 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
399 retval = FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
400 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
401 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
402 // Remove escaping for CSI and K_SPECIAL in multi-byte chars. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
403 vim_unescape_csi(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
404 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
405 // We don't want to change the default register here, so save and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
406 // restore the current register name. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
407 old_y_previous = y_previous; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
408 old_y_current = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
409 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
410 retval = stuff_yank(regname, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
411 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
412 y_previous = old_y_previous; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
413 y_current = old_y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
414 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
415 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
416 return retval; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
417 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
418 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
419 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
420 * Stuff string "p" into yank register "regname" as a single line (append if |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
421 * uppercase). "p" must have been alloced. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
422 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
423 * return FAIL for failure, OK otherwise |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
424 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
425 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
426 stuff_yank(int regname, char_u *p) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
427 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
428 char_u *lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
429 char_u **pp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
430 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
431 // check for read-only register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
432 if (regname != 0 && !valid_yank_reg(regname, TRUE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
433 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
434 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
435 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
436 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
437 if (regname == '_') // black hole: don't do anything |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
438 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
439 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
440 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
441 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
442 get_yank_register(regname, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
443 if (y_append && y_current->y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
444 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
445 pp = &(y_current->y_array[y_current->y_size - 1]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
446 lp = alloc(STRLEN(*pp) + STRLEN(p) + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
447 if (lp == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
448 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
449 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
450 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
451 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
452 STRCPY(lp, *pp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
453 STRCAT(lp, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
454 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
455 vim_free(*pp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
456 *pp = lp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
457 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
458 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
459 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
460 free_yank_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
461 if ((y_current->y_array = ALLOC_ONE(char_u *)) == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
462 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
463 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
464 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
465 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
466 y_current->y_array[0] = p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
467 y_current->y_size = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
468 y_current->y_type = MCHAR; // used to be MLINE, why? |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
469 #ifdef FEAT_VIMINFO |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
470 y_current->y_time_set = vim_time(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
471 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
472 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
473 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
474 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
475 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
476 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
477 * Last executed register (@ command) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
478 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
479 static int execreg_lastc = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
480 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
481 #if defined(FEAT_VIMINFO) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
482 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
483 get_execreg_lastc(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
484 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
485 return execreg_lastc; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
486 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
487 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
488 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
489 set_execreg_lastc(int lastc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
490 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
491 execreg_lastc = lastc; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
492 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
493 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
494 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
495 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
496 * When executing a register as a series of ex-commands, if the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
497 * line-continuation character is used for a line, then join it with one or |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
498 * more previous lines. Note that lines are processed backwards starting from |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
499 * the last line in the register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
500 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
501 * Arguments: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
502 * lines - list of lines in the register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
503 * idx - index of the line starting with \ or "\. Join this line with all the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
504 * immediate predecessor lines that start with a \ and the first line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
505 * that doesn't start with a \. Lines that start with a comment "\ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
506 * character are ignored. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
507 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
508 * Returns the concatenated line. The index of the line that should be |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
509 * processed next is returned in idx. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
510 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
511 static char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
512 execreg_line_continuation(char_u **lines, long *idx) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
513 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
514 garray_T ga; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
515 long i = *idx; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
516 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
517 int cmd_start; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
518 int cmd_end = i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
519 int j; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
520 char_u *str; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
521 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
522 ga_init2(&ga, sizeof(char_u), 400); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
523 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
524 // search backwards to find the first line of this command. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
525 // Any line not starting with \ or "\ is the start of the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
526 // command. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
527 while (--i > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
528 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
529 p = skipwhite(lines[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
530 if (*p != '\\' && (p[0] != '"' || p[1] != '\\' || p[2] != ' ')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
531 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
532 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
533 cmd_start = i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
534 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
535 // join all the lines |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
536 ga_concat(&ga, lines[cmd_start]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
537 for (j = cmd_start + 1; j <= cmd_end; j++) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
538 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
539 p = skipwhite(lines[j]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
540 if (*p == '\\') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
541 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
542 // Adjust the growsize to the current length to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
543 // speed up concatenating many lines. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
544 if (ga.ga_len > 400) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
545 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
546 if (ga.ga_len > 8000) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
547 ga.ga_growsize = 8000; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
548 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
549 ga.ga_growsize = ga.ga_len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
550 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
551 ga_concat(&ga, p + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
552 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
553 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
554 ga_append(&ga, NUL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
555 str = vim_strsave(ga.ga_data); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
556 ga_clear(&ga); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
557 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
558 *idx = i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
559 return str; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
560 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
561 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
562 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
563 * Execute a yank register: copy it into the stuff buffer. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
564 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
565 * Return FAIL for failure, OK otherwise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
566 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
567 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
568 do_execreg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
569 int regname, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
570 int colon, // insert ':' before each line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
571 int addcr, // always add '\n' to end of line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
572 int silent) // set "silent" flag in typeahead buffer |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
573 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
574 long i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
575 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
576 int retval = OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
577 int remap; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
578 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
579 // repeat previous one |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
580 if (regname == '@') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
581 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
582 if (execreg_lastc == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
583 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
584 emsg(_(e_no_previously_used_register)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
585 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
586 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
587 regname = execreg_lastc; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
588 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
589 // check for valid regname |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
590 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
591 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
592 emsg_invreg(regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
593 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
594 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
595 execreg_lastc = regname; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
596 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
597 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
598 regname = may_get_selection(regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
599 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
600 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
601 // black hole: don't stuff anything |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
602 if (regname == '_') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
603 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
604 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
605 // use last command line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
606 if (regname == ':') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
607 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
608 if (last_cmdline == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
609 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
610 emsg(_(e_no_previous_command_line)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
611 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
612 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
613 // don't keep the cmdline containing @: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
614 VIM_CLEAR(new_last_cmdline); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
615 // Escape all control characters with a CTRL-V |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
616 p = vim_strsave_escaped_ext(last_cmdline, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
617 (char_u *)"\001\002\003\004\005\006\007" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
618 "\010\011\012\013\014\015\016\017" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
619 "\020\021\022\023\024\025\026\027" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
620 "\030\031\032\033\034\035\036\037", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
621 Ctrl_V, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
622 if (p != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
623 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
624 // When in Visual mode "'<,'>" will be prepended to the command. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
625 // Remove it when it's already there. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
626 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
627 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
628 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
629 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
630 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
631 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
632 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
633 #ifdef FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
634 else if (regname == '=') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
635 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
636 p = get_expr_line(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
637 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
638 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
639 retval = put_in_typebuf(p, TRUE, colon, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
640 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
641 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
642 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
643 else if (regname == '.') // use last inserted text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
644 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
645 p = get_last_insert_save(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
646 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
647 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
648 emsg(_(e_no_inserted_text_yet)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
649 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
650 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
651 retval = put_in_typebuf(p, FALSE, colon, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
652 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
653 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
654 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
655 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
656 get_yank_register(regname, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
657 if (y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
658 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
659 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
660 // Disallow remapping for ":@r". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
661 remap = colon ? REMAP_NONE : REMAP_YES; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
662 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
663 // Insert lines into typeahead buffer, from last one to first one. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
664 put_reedit_in_typebuf(silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
665 for (i = y_current->y_size; --i >= 0; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
666 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
667 char_u *escaped; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
668 char_u *str; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
669 int free_str = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
670 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
671 // insert NL between lines and after last line if type is MLINE |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
672 if (y_current->y_type == MLINE || i < y_current->y_size - 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
673 || addcr) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
674 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
675 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
676 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
677 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
678 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
679 // Handle line-continuation for :@<register> |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
680 str = y_current->y_array[i]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
681 if (colon && i > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
682 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
683 p = skipwhite(str); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
684 if (*p == '\\' || (p[0] == '"' && p[1] == '\\' && p[2] == ' ')) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
685 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
686 str = execreg_line_continuation(y_current->y_array, &i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
687 if (str == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
688 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
689 free_str = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
690 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
691 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
692 escaped = vim_strsave_escape_csi(str); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
693 if (free_str) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
694 vim_free(str); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
695 if (escaped == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
696 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
697 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
698 vim_free(escaped); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
699 if (retval == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
700 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
701 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
702 == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
703 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
704 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
705 reg_executing = regname == 0 ? '"' : regname; // disable "q" command |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
706 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
707 return retval; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
708 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
709 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
710 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
711 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
712 * used only after other typeahead has been processed. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
713 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
714 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
715 put_reedit_in_typebuf(int silent) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
716 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
717 char_u buf[3]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
718 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
719 if (restart_edit == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
720 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
721 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
722 if (restart_edit == 'V') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
723 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
724 buf[0] = 'g'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
725 buf[1] = 'R'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
726 buf[2] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
727 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
728 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
729 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
730 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
731 buf[1] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
732 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
733 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
734 restart_edit = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
735 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
736 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
737 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
738 * Insert register contents "s" into the typeahead buffer, so that it will be |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
739 * executed again. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
740 * When "esc" is TRUE it is to be taken literally: Escape CSI characters and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
741 * no remapping. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
742 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
743 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
744 put_in_typebuf( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
745 char_u *s, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
746 int esc, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
747 int colon, // add ':' before the line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
748 int silent) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
749 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
750 int retval = OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
751 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
752 put_reedit_in_typebuf(silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
753 if (colon) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
754 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
755 if (retval == OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
756 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
757 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
758 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
759 if (esc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
760 p = vim_strsave_escape_csi(s); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
761 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
762 p = s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
763 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
764 retval = FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
765 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
766 retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
767 0, TRUE, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
768 if (esc) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
769 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
770 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
771 if (colon && retval == OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
772 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
773 return retval; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
774 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
775 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
776 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
777 * Insert a yank register: copy it into the Read buffer. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
778 * Used by CTRL-R command and middle mouse button in insert mode. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
779 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
780 * return FAIL for failure, OK otherwise |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
781 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
782 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
783 insert_reg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
784 int regname, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
785 int literally_arg) // insert literally, not as if typed |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
786 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
787 long i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
788 int retval = OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
789 char_u *arg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
790 int allocated; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
791 int literally = literally_arg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
792 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
793 // It is possible to get into an endless loop by having CTRL-R a in |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
794 // register a and then, in insert mode, doing CTRL-R a. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
795 // If you hit CTRL-C, the loop will be broken here. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
796 ui_breakcheck(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
797 if (got_int) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
798 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
799 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
800 // check for valid regname |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
801 if (regname != NUL && !valid_yank_reg(regname, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
802 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
803 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
804 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
805 regname = may_get_selection(regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
806 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
807 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
808 if (regname == '.') // insert last inserted text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
809 retval = stuff_inserted(NUL, 1L, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
810 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
811 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
812 if (arg == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
813 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
814 stuffescaped(arg, literally); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
815 if (allocated) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
816 vim_free(arg); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
817 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
818 else // name or number register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
819 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
820 if (get_yank_register(regname, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
821 literally = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
822 if (y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
823 retval = FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
824 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
825 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
826 for (i = 0; i < y_current->y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
827 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
828 if (regname == '-') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
829 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
830 AppendCharToRedobuff(Ctrl_R); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
831 AppendCharToRedobuff(regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
832 do_put(regname, NULL, BACKWARD, 1L, PUT_CURSEND); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
833 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
834 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
835 stuffescaped(y_current->y_array[i], literally); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
836 // Insert a newline between lines and after last line if |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
837 // y_type is MLINE. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
838 if (y_current->y_type == MLINE || i < y_current->y_size - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
839 stuffcharReadbuff('\n'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
840 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
841 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
842 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
843 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
844 return retval; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
845 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
846 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
847 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
848 * If "regname" is a special register, return TRUE and store a pointer to its |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
849 * value in "argp". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
850 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
851 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
852 get_spec_reg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
853 int regname, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
854 char_u **argp, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
855 int *allocated, // return: TRUE when value was allocated |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
856 int errmsg) // give error message when failing |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
857 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
858 int cnt; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
859 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
860 *argp = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
861 *allocated = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
862 switch (regname) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
863 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
864 case '%': // file name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
865 if (errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
866 check_fname(); // will give emsg if not set |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
867 *argp = curbuf->b_fname; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
868 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
869 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
870 case '#': // alternate file name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
871 *argp = getaltfname(errmsg); // may give emsg if not set |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
872 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
873 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
874 #ifdef FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
875 case '=': // result of expression |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
876 *argp = get_expr_line(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
877 *allocated = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
878 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
879 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
880 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
881 case ':': // last command line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
882 if (last_cmdline == NULL && errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
883 emsg(_(e_no_previous_command_line)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
884 *argp = last_cmdline; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
885 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
886 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
887 case '/': // last search-pattern |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
888 if (last_search_pat() == NULL && errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
889 emsg(_(e_no_previous_regular_expression)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
890 *argp = last_search_pat(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
891 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
892 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
893 case '.': // last inserted text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
894 *argp = get_last_insert_save(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
895 *allocated = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
896 if (*argp == NULL && errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
897 emsg(_(e_no_inserted_text_yet)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
898 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
899 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
900 case Ctrl_F: // Filename under cursor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
901 case Ctrl_P: // Path under cursor, expand via "path" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
902 if (!errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
903 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
904 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
905 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
906 *allocated = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
907 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
908 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
909 case Ctrl_W: // word under cursor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
910 case Ctrl_A: // WORD (mnemonic All) under cursor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
911 if (!errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
912 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
913 cnt = find_ident_under_cursor(argp, regname == Ctrl_W |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
914 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
915 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
916 *allocated = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
917 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
918 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
919 case Ctrl_L: // Line under cursor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
920 if (!errmsg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
921 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
922 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
923 *argp = ml_get_buf(curwin->w_buffer, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
924 curwin->w_cursor.lnum, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
925 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
926 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
927 case '_': // black hole: always empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
928 *argp = (char_u *)""; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
929 return TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
930 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
931 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
932 return FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
933 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
934 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
935 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
936 * Paste a yank register into the command line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
937 * Only for non-special registers. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
938 * Used by CTRL-R command in command-line mode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
939 * insert_reg() can't be used here, because special characters from the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
940 * register contents will be interpreted as commands. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
941 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
942 * return FAIL for failure, OK otherwise |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
943 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
944 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
945 cmdline_paste_reg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
946 int regname, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
947 int literally_arg, // Insert text literally instead of "as typed" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
948 int remcr) // don't add CR characters |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
949 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
950 long i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
951 int literally = literally_arg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
952 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
953 if (get_yank_register(regname, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
954 literally = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
955 if (y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
956 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
957 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
958 for (i = 0; i < y_current->y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
959 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
960 cmdline_paste_str(y_current->y_array[i], literally); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
961 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
962 // Insert ^M between lines and after last line if type is MLINE. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
963 // Don't do this when "remcr" is TRUE. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
964 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
965 cmdline_paste_str((char_u *)"\r", literally); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
966 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
967 // Check for CTRL-C, in case someone tries to paste a few thousand |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
968 // lines and gets bored. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
969 ui_breakcheck(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
970 if (got_int) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
971 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
972 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
973 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
974 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
975 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
976 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
977 * Shift the delete registers: "9 is cleared, "8 becomes "9, etc. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
978 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
979 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
980 shift_delete_registers(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
981 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
982 int n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
983 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
984 y_current = &y_regs[9]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
985 free_yank_all(); // free register nine |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
986 for (n = 9; n > 1; --n) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
987 y_regs[n] = y_regs[n - 1]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
988 y_current = &y_regs[1]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
989 if (!y_append) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
990 y_previous = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
991 y_regs[1].y_array = NULL; // set register one to empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
992 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
993 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
994 #if defined(FEAT_EVAL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
995 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
996 yank_do_autocmd(oparg_T *oap, yankreg_T *reg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
997 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
998 static int recursive = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
999 dict_T *v_event; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1000 list_T *list; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1001 int n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1002 char_u buf[NUMBUFLEN + 2]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1003 long reglen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1004 save_v_event_T save_v_event; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1005 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1006 if (recursive) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1007 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1008 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1009 v_event = get_v_event(&save_v_event); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1010 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1011 list = list_alloc(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1012 if (list == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1013 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1014 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1015 // yanked text contents |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1016 for (n = 0; n < reg->y_size; n++) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1017 list_append_string(list, reg->y_array[n], -1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1018 list->lv_lock = VAR_FIXED; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1019 (void)dict_add_list(v_event, "regcontents", list); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1020 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1021 // register name or empty string for unnamed operation |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1022 buf[0] = (char_u)oap->regname; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1023 buf[1] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1024 (void)dict_add_string(v_event, "regname", buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1025 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1026 // motion type: inclusive or exclusive |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1027 (void)dict_add_bool(v_event, "inclusive", oap->inclusive); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1028 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1029 // kind of operation (yank, delete, change) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1030 buf[0] = get_op_char(oap->op_type); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1031 buf[1] = get_extra_op_char(oap->op_type); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1032 buf[2] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1033 (void)dict_add_string(v_event, "operator", buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1034 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1035 // register type |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1036 buf[0] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1037 buf[1] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1038 switch (get_reg_type(oap->regname, ®len)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1039 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1040 case MLINE: buf[0] = 'V'; break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1041 case MCHAR: buf[0] = 'v'; break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1042 case MBLOCK: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1043 vim_snprintf((char *)buf, sizeof(buf), "%c%ld", Ctrl_V, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1044 reglen + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1045 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1046 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1047 (void)dict_add_string(v_event, "regtype", buf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1048 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1049 // selection type - visual or not |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1050 (void)dict_add_bool(v_event, "visual", oap->is_VIsual); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1051 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1052 // Lock the dictionary and its keys |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1053 dict_set_items_ro(v_event); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1054 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1055 recursive = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1056 textlock++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1057 apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1058 textlock--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1059 recursive = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1060 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1061 // Empty the dictionary, v:event is still valid |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1062 restore_v_event(v_event, &save_v_event); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1063 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1064 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1065 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1066 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1067 * set all the yank registers to empty (called from main()) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1068 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1069 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1070 init_yank(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1071 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1072 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1073 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1074 for (i = 0; i < NUM_REGISTERS; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1075 y_regs[i].y_array = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1076 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1077 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1078 #if defined(EXITFREE) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1079 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1080 clear_registers(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1081 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1082 int i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1083 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1084 for (i = 0; i < NUM_REGISTERS; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1085 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1086 y_current = &y_regs[i]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1087 if (y_current->y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1088 free_yank_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1089 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1090 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1091 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1092 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1093 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1094 * Free "n" lines from the current yank register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1095 * Called for normal freeing and in case of error. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1096 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1097 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1098 free_yank(long n) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1099 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1100 if (y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1101 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1102 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1103 long i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1104 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1105 for (i = n; --i >= 0; ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1106 vim_free(y_current->y_array[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1107 VIM_CLEAR(y_current->y_array); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1108 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1109 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1110 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1111 free_yank_all(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1112 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1113 free_yank(y_current->y_size); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1114 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1115 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1116 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1117 * Yank the text between "oap->start" and "oap->end" into a yank register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1118 * If we are to append (uppercase register), we first yank into a new yank |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1119 * register and then concatenate the old and the new one (so we keep the old |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1120 * one in case of out-of-memory). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1121 * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1122 * Return FAIL for failure, OK otherwise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1123 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1124 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1125 op_yank(oparg_T *oap, int deleting, int mess) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1126 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1127 long y_idx; // index in y_array[] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1128 yankreg_T *curr; // copy of y_current |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1129 yankreg_T newreg; // new yank register when appending |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1130 char_u **new_ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1131 linenr_T lnum; // current line number |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1132 long j; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1133 int yanktype = oap->motion_type; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1134 long yanklines = oap->line_count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1135 linenr_T yankendlnum = oap->end.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1136 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1137 char_u *pnew; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1138 struct block_def bd; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1139 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1140 int did_star = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1141 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1142 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1143 // check for read-only register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1144 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1145 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1146 beep_flush(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1147 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1148 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1149 if (oap->regname == '_') // black hole: nothing to do |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1150 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1151 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1152 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1153 if (!clip_star.available && oap->regname == '*') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1154 oap->regname = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1155 else if (!clip_plus.available && oap->regname == '+') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1156 oap->regname = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1157 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1158 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1159 if (!deleting) // op_delete() already set y_current |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1160 get_yank_register(oap->regname, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1161 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1162 curr = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1163 // append to existing contents |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1164 if (y_append && y_current->y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1165 y_current = &newreg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1166 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1167 free_yank_all(); // free previously yanked lines |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1168 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1169 // If the cursor was in column 1 before and after the movement, and the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1170 // operator is not inclusive, the yank is always linewise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1171 if ( oap->motion_type == MCHAR |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1172 && oap->start.col == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1173 && !oap->inclusive |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1174 && (!oap->is_VIsual || *p_sel == 'o') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1175 && !oap->block_mode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1176 && oap->end.col == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1177 && yanklines > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1178 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1179 yanktype = MLINE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1180 --yankendlnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1181 --yanklines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1182 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1183 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1184 y_current->y_size = yanklines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1185 y_current->y_type = yanktype; // set the yank register type |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1186 y_current->y_width = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1187 y_current->y_array = lalloc_clear(sizeof(char_u *) * yanklines, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1188 if (y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1189 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1190 y_current = curr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1191 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1192 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1193 #ifdef FEAT_VIMINFO |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1194 y_current->y_time_set = vim_time(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1195 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1196 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1197 y_idx = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1198 lnum = oap->start.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1199 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1200 if (oap->block_mode) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1201 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1202 // Visual block mode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1203 y_current->y_type = MBLOCK; // set the yank register type |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1204 y_current->y_width = oap->end_vcol - oap->start_vcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1205 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1206 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1207 y_current->y_width--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1208 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1209 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1210 for ( ; lnum <= yankendlnum; lnum++, y_idx++) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1211 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1212 switch (y_current->y_type) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1213 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1214 case MBLOCK: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1215 block_prep(oap, &bd, lnum, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1216 if (yank_copy_line(&bd, y_idx, oap->excl_tr_ws) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1217 goto fail; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1218 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1219 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1220 case MLINE: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1221 if ((y_current->y_array[y_idx] = |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1222 vim_strsave(ml_get(lnum))) == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1223 goto fail; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1224 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1225 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1226 case MCHAR: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1227 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1228 colnr_T startcol = 0, endcol = MAXCOL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1229 int is_oneChar = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1230 colnr_T cs, ce; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1231 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1232 p = ml_get(lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1233 bd.startspaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1234 bd.endspaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1235 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1236 if (lnum == oap->start.lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1237 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1238 startcol = oap->start.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1239 if (virtual_op) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1240 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1241 getvcol(curwin, &oap->start, &cs, NULL, &ce); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1242 if (ce != cs && oap->start.coladd > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1243 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1244 // Part of a tab selected -- but don't |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1245 // double-count it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1246 bd.startspaces = (ce - cs + 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1247 - oap->start.coladd; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1248 if (bd.startspaces < 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1249 bd.startspaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1250 startcol++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1251 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1252 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1253 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1254 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1255 if (lnum == oap->end.lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1256 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1257 endcol = oap->end.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1258 if (virtual_op) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1259 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1260 getvcol(curwin, &oap->end, &cs, NULL, &ce); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1261 if (p[endcol] == NUL || (cs + oap->end.coladd < ce |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1262 // Don't add space for double-wide |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1263 // char; endcol will be on last byte |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1264 // of multi-byte char. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1265 && (*mb_head_off)(p, p + endcol) == 0)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1266 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1267 if (oap->start.lnum == oap->end.lnum |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1268 && oap->start.col == oap->end.col) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1269 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1270 // Special case: inside a single char |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1271 is_oneChar = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1272 bd.startspaces = oap->end.coladd |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1273 - oap->start.coladd + oap->inclusive; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1274 endcol = startcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1275 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1276 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1277 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1278 bd.endspaces = oap->end.coladd |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1279 + oap->inclusive; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1280 endcol -= oap->inclusive; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1281 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1282 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1283 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1284 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1285 if (endcol == MAXCOL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1286 endcol = (colnr_T)STRLEN(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1287 if (startcol > endcol || is_oneChar) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1288 bd.textlen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1289 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1290 bd.textlen = endcol - startcol + oap->inclusive; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1291 bd.textstart = p + startcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1292 if (yank_copy_line(&bd, y_idx, FALSE) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1293 goto fail; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1294 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1295 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1296 // NOTREACHED |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1297 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1298 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1299 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1300 if (curr != y_current) // append the new block to the old block |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1301 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1302 new_ptr = ALLOC_MULT(char_u *, curr->y_size + y_current->y_size); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1303 if (new_ptr == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1304 goto fail; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1305 for (j = 0; j < curr->y_size; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1306 new_ptr[j] = curr->y_array[j]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1307 vim_free(curr->y_array); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1308 curr->y_array = new_ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1309 #ifdef FEAT_VIMINFO |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1310 curr->y_time_set = vim_time(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1311 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1312 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1313 if (yanktype == MLINE) // MLINE overrides MCHAR and MBLOCK |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1314 curr->y_type = MLINE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1315 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1316 // Concatenate the last line of the old block with the first line of |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1317 // the new block, unless being Vi compatible. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1318 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1319 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1320 pnew = alloc(STRLEN(curr->y_array[curr->y_size - 1]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1321 + STRLEN(y_current->y_array[0]) + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1322 if (pnew == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1323 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1324 y_idx = y_current->y_size - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1325 goto fail; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1326 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1327 STRCPY(pnew, curr->y_array[--j]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1328 STRCAT(pnew, y_current->y_array[0]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1329 vim_free(curr->y_array[j]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1330 vim_free(y_current->y_array[0]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1331 curr->y_array[j++] = pnew; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1332 y_idx = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1333 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1334 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1335 y_idx = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1336 while (y_idx < y_current->y_size) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1337 curr->y_array[j++] = y_current->y_array[y_idx++]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1338 curr->y_size = j; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1339 vim_free(y_current->y_array); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1340 y_current = curr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1341 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1342 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1343 if (mess) // Display message about yank? |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1344 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1345 if (yanktype == MCHAR |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1346 && !oap->block_mode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1347 && yanklines == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1348 yanklines = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1349 // Some versions of Vi use ">=" here, some don't... |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1350 if (yanklines > p_report) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1351 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1352 char namebuf[100]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1353 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1354 if (oap->regname == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1355 *namebuf = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1356 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1357 vim_snprintf(namebuf, sizeof(namebuf), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1358 _(" into \"%c"), oap->regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1359 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1360 // redisplay now, so message is not deleted |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1361 update_topline_redraw(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1362 if (oap->block_mode) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1363 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1364 smsg(NGETTEXT("block of %ld line yanked%s", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1365 "block of %ld lines yanked%s", yanklines), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1366 yanklines, namebuf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1367 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1368 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1369 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1370 smsg(NGETTEXT("%ld line yanked%s", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1371 "%ld lines yanked%s", yanklines), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1372 yanklines, namebuf); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1373 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1374 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1375 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1376 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1377 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1378 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1379 // Set "'[" and "']" marks. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1380 curbuf->b_op_start = oap->start; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1381 curbuf->b_op_end = oap->end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1382 if (yanktype == MLINE && !oap->block_mode) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1383 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1384 curbuf->b_op_start.col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1385 curbuf->b_op_end.col = MAXCOL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1386 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1387 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1388 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1389 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1390 // If we were yanking to the '*' register, send result to clipboard. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1391 // If no register was specified, and "unnamed" in 'clipboard', make a copy |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1392 // to the '*' register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1393 if (clip_star.available |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1394 && (curr == &(y_regs[STAR_REGISTER]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1395 || (!deleting && oap->regname == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1396 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1397 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1398 if (curr != &(y_regs[STAR_REGISTER])) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1399 // Copy the text from register 0 to the clipboard register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1400 copy_yank_reg(&(y_regs[STAR_REGISTER])); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1401 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1402 clip_own_selection(&clip_star); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1403 clip_gen_set_selection(&clip_star); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1404 # ifdef FEAT_X11 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1405 did_star = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1406 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1407 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1408 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1409 # ifdef FEAT_X11 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1410 // If we were yanking to the '+' register, send result to selection. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1411 // Also copy to the '*' register, in case auto-select is off. But not when |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1412 // 'clipboard' has "unnamedplus" and not "unnamed"; and not when |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1413 // deleting and both "unnamedplus" and "unnamed". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1414 if (clip_plus.available |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1415 && (curr == &(y_regs[PLUS_REGISTER]) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1416 || (!deleting && oap->regname == 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1417 && ((clip_unnamed | clip_unnamed_saved) & |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1418 CLIP_UNNAMED_PLUS)))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1419 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1420 if (curr != &(y_regs[PLUS_REGISTER])) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1421 // Copy the text from register 0 to the clipboard register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1422 copy_yank_reg(&(y_regs[PLUS_REGISTER])); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1423 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1424 clip_own_selection(&clip_plus); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1425 clip_gen_set_selection(&clip_plus); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1426 if (!clip_isautosel_star() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1427 && !clip_isautosel_plus() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1428 && !((clip_unnamed | clip_unnamed_saved) == CLIP_UNNAMED_PLUS) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1429 && !(deleting && (clip_unnamed | clip_unnamed_saved) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1430 == (CLIP_UNNAMED | CLIP_UNNAMED_PLUS)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1431 && !did_star |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1432 && curr == &(y_regs[PLUS_REGISTER])) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1433 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1434 copy_yank_reg(&(y_regs[STAR_REGISTER])); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1435 clip_own_selection(&clip_star); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1436 clip_gen_set_selection(&clip_star); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1437 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1438 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1439 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1440 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1441 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1442 #if defined(FEAT_EVAL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1443 if (!deleting && has_textyankpost()) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1444 yank_do_autocmd(oap, y_current); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1445 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1446 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1447 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1448 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1449 fail: // free the allocated lines |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1450 free_yank(y_idx + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1451 y_current = curr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1452 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1453 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1454 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1455 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1456 * Copy a block range into a register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1457 * If "exclude_trailing_space" is set, do not copy trailing whitespaces. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1458 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1459 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1460 yank_copy_line(struct block_def *bd, long y_idx, int exclude_trailing_space) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1461 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1462 char_u *pnew; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1463 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1464 if (exclude_trailing_space) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1465 bd->endspaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1466 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1467 == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1468 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1469 y_current->y_array[y_idx] = pnew; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1470 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1471 pnew += bd->startspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1472 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1473 pnew += bd->textlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1474 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1475 pnew += bd->endspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1476 if (exclude_trailing_space) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1477 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1478 int s = bd->textlen + bd->endspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1479 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1480 while (s > 0 && VIM_ISWHITE(*(bd->textstart + s - 1))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1481 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1482 s = s - (*mb_head_off)(bd->textstart, bd->textstart + s - 1) - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1483 pnew--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1484 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1485 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1486 *pnew = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1487 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1488 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1489 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1490 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1491 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1492 * Make a copy of the y_current register to register "reg". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1493 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1494 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1495 copy_yank_reg(yankreg_T *reg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1496 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1497 yankreg_T *curr = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1498 long j; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1499 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1500 y_current = reg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1501 free_yank_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1502 *y_current = *curr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1503 y_current->y_array = lalloc_clear( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1504 sizeof(char_u *) * y_current->y_size, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1505 if (y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1506 y_current->y_size = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1507 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1508 for (j = 0; j < y_current->y_size; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1509 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1510 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1511 free_yank(j); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1512 y_current->y_size = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1513 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1514 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1515 y_current = curr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1516 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1517 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1518 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1519 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1520 * Put contents of register "regname" into the text. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1521 * Caller must check "regname" to be valid! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1522 * "flags": PUT_FIXINDENT make indent look nice |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1523 * PUT_CURSEND leave cursor after end of new text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1524 * PUT_LINE force linewise put (":put") |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1525 * PUT_BLOCK_INNER in block mode, do not add trailing spaces |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1526 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1527 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1528 do_put( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1529 int regname, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1530 char_u *expr_result, // result for regname "=" when compiled |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1531 int dir, // BACKWARD for 'P', FORWARD for 'p' |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1532 long count, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1533 int flags) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1534 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1535 char_u *ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1536 char_u *newp, *oldp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1537 int yanklen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1538 int totlen = 0; // init for gcc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1539 linenr_T lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1540 colnr_T col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1541 long i; // index in y_array[] |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1542 int y_type; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1543 long y_size; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1544 int oldlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1545 long y_width = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1546 colnr_T vcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1547 int delcount; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1548 int incr = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1549 long j; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1550 struct block_def bd; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1551 char_u **y_array = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1552 yankreg_T *y_current_used = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1553 long nr_lines = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1554 pos_T new_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1555 int indent; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1556 int orig_indent = 0; // init for gcc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1557 int indent_diff = 0; // init for gcc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1558 int first_indent = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1559 int lendiff = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1560 pos_T old_pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1561 char_u *insert_string = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1562 int allocated = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1563 long cnt; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1564 pos_T orig_start = curbuf->b_op_start; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1565 pos_T orig_end = curbuf->b_op_end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1566 unsigned int cur_ve_flags = get_ve_flags(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1567 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1568 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1569 // Adjust register name for "unnamed" in 'clipboard'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1570 adjust_clip_reg(®name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1571 (void)may_get_selection(regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1572 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1573 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1574 if (flags & PUT_FIXINDENT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1575 orig_indent = get_indent(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1576 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1577 curbuf->b_op_start = curwin->w_cursor; // default for '[ mark |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1578 curbuf->b_op_end = curwin->w_cursor; // default for '] mark |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1579 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1580 // Using inserted text works differently, because the register includes |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1581 // special characters (newlines, etc.). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1582 if (regname == '.') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1583 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1584 if (VIsual_active) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1585 stuffcharReadbuff(VIsual_mode); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1586 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1587 (count == -1 ? 'O' : 'i')), count, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1588 // Putting the text is done later, so can't really move the cursor to |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1589 // the next character. Use "l" to simulate it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1590 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1591 stuffcharReadbuff('l'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1592 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1593 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1594 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1595 // For special registers '%' (file name), '#' (alternate file name) and |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1596 // ':' (last command line), etc. we have to create a fake yank register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1597 // For compiled code "expr_result" holds the expression result. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1598 if (regname == '=' && expr_result != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1599 insert_string = expr_result; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1600 else if (get_spec_reg(regname, &insert_string, &allocated, TRUE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1601 && insert_string == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1602 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1603 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1604 // Autocommands may be executed when saving lines for undo. This might |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1605 // make "y_array" invalid, so we start undo now to avoid that. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1606 if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1607 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1608 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1609 if (insert_string != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1610 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1611 y_type = MCHAR; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1612 #ifdef FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1613 if (regname == '=') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1614 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1615 // For the = register we need to split the string at NL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1616 // characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1617 // Loop twice: count the number of lines and save them. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1618 for (;;) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1619 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1620 y_size = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1621 ptr = insert_string; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1622 while (ptr != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1623 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1624 if (y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1625 y_array[y_size] = ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1626 ++y_size; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1627 ptr = vim_strchr(ptr, '\n'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1628 if (ptr != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1629 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1630 if (y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1631 *ptr = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1632 ++ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1633 // A trailing '\n' makes the register linewise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1634 if (*ptr == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1635 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1636 y_type = MLINE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1637 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1638 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1639 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1640 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1641 if (y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1642 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1643 y_array = ALLOC_MULT(char_u *, y_size); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1644 if (y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1645 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1646 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1647 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1648 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1649 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1650 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1651 y_size = 1; // use fake one-line yank register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1652 y_array = &insert_string; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1653 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1654 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1655 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1656 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1657 get_yank_register(regname, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1658 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1659 y_type = y_current->y_type; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1660 y_width = y_current->y_width; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1661 y_size = y_current->y_size; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1662 y_array = y_current->y_array; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1663 y_current_used = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1664 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1665 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1666 if (y_type == MLINE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1667 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1668 if (flags & PUT_LINE_SPLIT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1669 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1670 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1671 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1672 // "p" or "P" in Visual mode: split the lines to put the text in |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1673 // between. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1674 if (u_save_cursor() == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1675 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1676 p = ml_get_cursor(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1677 if (dir == FORWARD && *p != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1678 MB_PTR_ADV(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1679 ptr = vim_strsave(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1680 if (ptr == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1681 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1682 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1683 vim_free(ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1684 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1685 oldp = ml_get_curline(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1686 p = oldp + curwin->w_cursor.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1687 if (dir == FORWARD && *p != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1688 MB_PTR_ADV(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1689 ptr = vim_strnsave(oldp, p - oldp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1690 if (ptr == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1691 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1692 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1693 ++nr_lines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1694 dir = FORWARD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1695 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1696 if (flags & PUT_LINE_FORWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1697 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1698 // Must be "p" for a Visual block, put lines below the block. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1699 curwin->w_cursor = curbuf->b_visual.vi_end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1700 dir = FORWARD; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1701 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1702 curbuf->b_op_start = curwin->w_cursor; // default for '[ mark |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1703 curbuf->b_op_end = curwin->w_cursor; // default for '] mark |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1704 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1705 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1706 if (flags & PUT_LINE) // :put command or "p" in Visual line mode. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1707 y_type = MLINE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1708 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1709 if (y_size == 0 || y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1710 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1711 semsg(_(e_nothing_in_register_str), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1712 regname == 0 ? (char_u *)"\"" : transchar(regname)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1713 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1714 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1715 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1716 if (y_type == MBLOCK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1717 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1718 lnum = curwin->w_cursor.lnum + y_size + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1719 if (lnum > curbuf->b_ml.ml_line_count) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1720 lnum = curbuf->b_ml.ml_line_count + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1721 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1722 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1723 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1724 else if (y_type == MLINE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1725 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1726 lnum = curwin->w_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1727 #ifdef FEAT_FOLDING |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1728 // Correct line number for closed fold. Don't move the cursor yet, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1729 // u_save() uses it. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1730 if (dir == BACKWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1731 (void)hasFolding(lnum, &lnum, NULL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1732 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1733 (void)hasFolding(lnum, NULL, &lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1734 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1735 if (dir == FORWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1736 ++lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1737 // In an empty buffer the empty line is going to be replaced, include |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1738 // it in the saved lines. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1739 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1740 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1741 #ifdef FEAT_FOLDING |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1742 if (dir == FORWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1743 curwin->w_cursor.lnum = lnum - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1744 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1745 curwin->w_cursor.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1746 curbuf->b_op_start = curwin->w_cursor; // for mark_adjust() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1747 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1748 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1749 else if (u_save_cursor() == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1750 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1751 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1752 yanklen = (int)STRLEN(y_array[0]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1753 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1754 if (cur_ve_flags == VE_ALL && y_type == MCHAR) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1755 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1756 if (gchar_cursor() == TAB) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1757 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1758 int viscol = getviscol(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1759 int ts = curbuf->b_p_ts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1760 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1761 // Don't need to insert spaces when "p" on the last position of a |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1762 // tab or "P" on the first position. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1763 if (dir == FORWARD ? |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1764 #ifdef FEAT_VARTABS |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1765 tabstop_padding(viscol, ts, curbuf->b_p_vts_array) != 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1766 #else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1767 ts - (viscol % ts) != 1 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1768 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1769 : curwin->w_cursor.coladd > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1770 coladvance_force(viscol); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1771 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1772 curwin->w_cursor.coladd = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1773 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1774 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1775 coladvance_force(getviscol() + (dir == FORWARD)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1776 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1777 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1778 lnum = curwin->w_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1779 col = curwin->w_cursor.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1780 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1781 // Block mode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1782 if (y_type == MBLOCK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1783 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1784 int c = gchar_cursor(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1785 colnr_T endcol2 = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1786 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1787 if (dir == FORWARD && c != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1788 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1789 if (cur_ve_flags == VE_ALL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1790 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1791 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1792 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1793 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1794 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1795 // move to start of next multi-byte character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1796 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1797 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1798 if (c != TAB || cur_ve_flags != VE_ALL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1799 ++curwin->w_cursor.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1800 ++col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1801 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1802 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1803 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1804 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1805 col += curwin->w_cursor.coladd; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1806 if (cur_ve_flags == VE_ALL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1807 && (curwin->w_cursor.coladd > 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1808 || endcol2 == curwin->w_cursor.col)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1809 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1810 if (dir == FORWARD && c == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1811 ++col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1812 if (dir != FORWARD && c != NUL && curwin->w_cursor.coladd > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1813 ++curwin->w_cursor.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1814 if (c == TAB) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1815 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1816 if (dir == BACKWARD && curwin->w_cursor.col) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1817 curwin->w_cursor.col--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1818 if (dir == FORWARD && col - 1 == endcol2) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1819 curwin->w_cursor.col++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1820 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1821 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1822 curwin->w_cursor.coladd = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1823 bd.textcol = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1824 for (i = 0; i < y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1825 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1826 int spaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1827 char shortline; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1828 chartabsize_T cts; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1829 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1830 bd.startspaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1831 bd.endspaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1832 vcol = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1833 delcount = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1834 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1835 // add a new line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1836 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1837 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1838 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1839 (colnr_T)1, FALSE) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1840 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1841 ++nr_lines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1842 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1843 // get the old line and advance to the position to insert at |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1844 oldp = ml_get_curline(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1845 oldlen = (int)STRLEN(oldp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1846 init_chartabsize_arg(&cts, curwin, curwin->w_cursor.lnum, 0, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1847 oldp, oldp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1848 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1849 while (cts.cts_vcol < col && *cts.cts_ptr != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1850 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1851 // Count a tab for what it's worth (if list mode not on) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1852 incr = lbr_chartabsize_adv(&cts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1853 cts.cts_vcol += incr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1854 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1855 vcol = cts.cts_vcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1856 ptr = cts.cts_ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1857 bd.textcol = (colnr_T)(ptr - oldp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1858 clear_chartabsize_arg(&cts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1859 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1860 shortline = (vcol < col) || (vcol == col && !*ptr) ; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1861 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1862 if (vcol < col) // line too short, pad with spaces |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1863 bd.startspaces = col - vcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1864 else if (vcol > col) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1865 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1866 bd.endspaces = vcol - col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1867 bd.startspaces = incr - bd.endspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1868 --bd.textcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1869 delcount = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1870 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1871 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1872 if (oldp[bd.textcol] != TAB) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1873 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1874 // Only a Tab can be split into spaces. Other |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1875 // characters will have to be moved to after the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1876 // block, causing misalignment. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1877 delcount = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1878 bd.endspaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1879 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1880 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1881 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1882 yanklen = (int)STRLEN(y_array[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1883 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1884 if ((flags & PUT_BLOCK_INNER) == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1885 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1886 // calculate number of spaces required to fill right side of |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1887 // block |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1888 spaces = y_width + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1889 init_chartabsize_arg(&cts, curwin, 0, 0, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1890 y_array[i], y_array[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1891 for (j = 0; j < yanklen; j++) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1892 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1893 spaces -= lbr_chartabsize(&cts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1894 ++cts.cts_ptr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1895 cts.cts_vcol = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1896 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1897 clear_chartabsize_arg(&cts); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1898 if (spaces < 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1899 spaces = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1900 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1901 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1902 // Insert the new text. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1903 // First check for multiplication overflow. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1904 if (yanklen + spaces != 0 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1905 && count > ((INT_MAX - (bd.startspaces + bd.endspaces)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1906 / (yanklen + spaces))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1907 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1908 emsg(_(e_resulting_text_too_long)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1909 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1910 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1911 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1912 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1913 newp = alloc(totlen + oldlen + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1914 if (newp == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1915 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1916 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1917 // copy part up to cursor to new line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1918 ptr = newp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1919 mch_memmove(ptr, oldp, (size_t)bd.textcol); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1920 ptr += bd.textcol; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1921 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1922 // may insert some spaces before the new text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1923 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1924 ptr += bd.startspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1925 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1926 // insert the new text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1927 for (j = 0; j < count; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1928 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1929 mch_memmove(ptr, y_array[i], (size_t)yanklen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1930 ptr += yanklen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1931 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1932 // insert block's trailing spaces only if there's text behind |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1933 if ((j < count - 1 || !shortline) && spaces > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1934 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1935 vim_memset(ptr, ' ', (size_t)spaces); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1936 ptr += spaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1937 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1938 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1939 totlen -= spaces; // didn't use these spaces |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1940 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1941 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1942 // may insert some spaces after the new text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1943 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1944 ptr += bd.endspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1945 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1946 // move the text after the cursor to the end of the line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1947 mch_memmove(ptr, oldp + bd.textcol + delcount, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1948 (size_t)(oldlen - bd.textcol - delcount + 1)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1949 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1950 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1951 ++curwin->w_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1952 if (i == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1953 curwin->w_cursor.col += bd.startspaces; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1954 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1955 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1956 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1957 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1958 // Set '[ mark. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1959 curbuf->b_op_start = curwin->w_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1960 curbuf->b_op_start.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1961 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1962 // adjust '] mark |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1963 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1964 curbuf->b_op_end.col = bd.textcol + totlen - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1965 if (curbuf->b_op_end.col < 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1966 curbuf->b_op_end.col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1967 curbuf->b_op_end.coladd = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1968 if (flags & PUT_CURSEND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1969 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1970 colnr_T len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1971 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1972 curwin->w_cursor = curbuf->b_op_end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1973 curwin->w_cursor.col++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1974 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1975 // in Insert mode we might be after the NUL, correct for that |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1976 len = (colnr_T)STRLEN(ml_get_curline()); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1977 if (curwin->w_cursor.col > len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1978 curwin->w_cursor.col = len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1979 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1980 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1981 curwin->w_cursor.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1982 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1983 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1984 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1985 // Character or Line mode |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1986 if (y_type == MCHAR) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1987 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1988 // if type is MCHAR, FORWARD is the same as BACKWARD on the next |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1989 // char |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1990 if (dir == FORWARD && gchar_cursor() != NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1991 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1992 if (has_mbyte) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1993 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1994 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1995 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1996 // put it on the next of the multi-byte character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1997 col += bytelen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1998 if (yanklen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
1999 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2000 curwin->w_cursor.col += bytelen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2001 curbuf->b_op_end.col += bytelen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2002 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2003 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2004 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2005 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2006 ++col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2007 if (yanklen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2008 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2009 ++curwin->w_cursor.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2010 ++curbuf->b_op_end.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2011 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2012 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2013 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2014 curbuf->b_op_start = curwin->w_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2015 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2016 // Line mode: BACKWARD is the same as FORWARD on the previous line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2017 else if (dir == BACKWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2018 --lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2019 new_cursor = curwin->w_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2020 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2021 // simple case: insert into one line at a time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2022 if (y_type == MCHAR && y_size == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2023 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2024 linenr_T end_lnum = 0; // init for gcc |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2025 linenr_T start_lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2026 int first_byte_off = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2027 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2028 if (VIsual_active) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2029 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2030 end_lnum = curbuf->b_visual.vi_end.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2031 if (end_lnum < curbuf->b_visual.vi_start.lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2032 end_lnum = curbuf->b_visual.vi_start.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2033 if (end_lnum > start_lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2034 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2035 pos_T pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2036 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2037 // "col" is valid for the first line, in following lines |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2038 // the virtual column needs to be used. Matters for |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2039 // multi-byte characters. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2040 pos.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2041 pos.col = col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2042 pos.coladd = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2043 getvcol(curwin, &pos, NULL, &vcol, NULL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2044 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2045 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2046 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2047 if (count == 0 || yanklen == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2048 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2049 if (VIsual_active) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2050 lnum = end_lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2051 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2052 else if (count > INT_MAX / yanklen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2053 // multiplication overflow |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2054 emsg(_(e_resulting_text_too_long)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2055 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2056 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2057 totlen = count * yanklen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2058 do { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2059 oldp = ml_get(lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2060 oldlen = (int)STRLEN(oldp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2061 if (lnum > start_lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2062 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2063 pos_T pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2064 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2065 pos.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2066 if (getvpos(&pos, vcol) == OK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2067 col = pos.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2068 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2069 col = MAXCOL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2070 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2071 if (VIsual_active && col > oldlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2072 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2073 lnum++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2074 continue; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2075 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2076 newp = alloc(totlen + oldlen + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2077 if (newp == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2078 goto end; // alloc() gave an error message |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2079 mch_memmove(newp, oldp, (size_t)col); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2080 ptr = newp + col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2081 for (i = 0; i < count; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2082 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2083 mch_memmove(ptr, y_array[0], (size_t)yanklen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2084 ptr += yanklen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2085 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2086 STRMOVE(ptr, oldp + col); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2087 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2088 // compute the byte offset for the last character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2089 first_byte_off = mb_head_off(newp, ptr - 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2090 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2091 // Note: this may free "newp" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2092 ml_replace(lnum, newp, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2093 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2094 inserted_bytes(lnum, col, totlen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2095 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2096 // Place cursor on last putted char. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2097 if (lnum == curwin->w_cursor.lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2098 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2099 // make sure curwin->w_virtcol is updated |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2100 changed_cline_bef_curs(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2101 invalidate_botline(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2102 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2103 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2104 if (VIsual_active) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2105 lnum++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2106 } while (VIsual_active && lnum <= end_lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2107 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2108 if (VIsual_active) // reset lnum to the last visual line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2109 lnum--; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2110 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2111 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2112 // put '] at the first byte of the last character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2113 curbuf->b_op_end = curwin->w_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2114 curbuf->b_op_end.col -= first_byte_off; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2115 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2116 // For "CTRL-O p" in Insert mode, put cursor after last char |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2117 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2118 ++curwin->w_cursor.col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2119 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2120 curwin->w_cursor.col -= first_byte_off; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2121 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2122 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2123 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2124 linenr_T new_lnum = new_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2125 size_t len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2126 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2127 // Insert at least one line. When y_type is MCHAR, break the first |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2128 // line in two. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2129 for (cnt = 1; cnt <= count; ++cnt) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2130 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2131 i = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2132 if (y_type == MCHAR) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2133 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2134 // Split the current line in two at the insert position. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2135 // First insert y_array[size - 1] in front of second line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2136 // Then append y_array[0] to first line. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2137 lnum = new_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2138 ptr = ml_get(lnum) + col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2139 totlen = (int)STRLEN(y_array[y_size - 1]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2140 newp = alloc(STRLEN(ptr) + totlen + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2141 if (newp == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2142 goto error; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2143 STRCPY(newp, y_array[y_size - 1]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2144 STRCAT(newp, ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2145 // insert second line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2146 ml_append(lnum, newp, (colnr_T)0, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2147 ++new_lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2148 vim_free(newp); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2149 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2150 oldp = ml_get(lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2151 newp = alloc(col + yanklen + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2152 if (newp == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2153 goto error; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2154 // copy first part of line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2155 mch_memmove(newp, oldp, (size_t)col); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2156 // append to first line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2157 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2158 ml_replace(lnum, newp, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2159 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2160 curwin->w_cursor.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2161 i = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2162 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2163 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2164 for (; i < y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2165 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2166 if (y_type != MCHAR || i < y_size - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2167 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2168 if (ml_append(lnum, y_array[i], (colnr_T)0, FALSE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2169 == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2170 goto error; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2171 new_lnum++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2172 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2173 lnum++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2174 ++nr_lines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2175 if (flags & PUT_FIXINDENT) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2176 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2177 old_pos = curwin->w_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2178 curwin->w_cursor.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2179 ptr = ml_get(lnum); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2180 if (cnt == count && i == y_size - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2181 lendiff = (int)STRLEN(ptr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2182 if (*ptr == '#' && preprocs_left()) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2183 indent = 0; // Leave # lines at start |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2184 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2185 if (*ptr == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2186 indent = 0; // Ignore empty lines |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2187 else if (first_indent) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2188 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2189 indent_diff = orig_indent - get_indent(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2190 indent = orig_indent; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2191 first_indent = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2192 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2193 else if ((indent = get_indent() + indent_diff) < 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2194 indent = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2195 (void)set_indent(indent, 0); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2196 curwin->w_cursor = old_pos; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2197 // remember how many chars were removed |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2198 if (cnt == count && i == y_size - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2199 lendiff -= (int)STRLEN(ml_get(lnum)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2200 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2201 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2202 if (cnt == 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2203 new_lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2204 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2205 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2206 error: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2207 // Adjust marks. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2208 if (y_type == MLINE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2209 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2210 curbuf->b_op_start.col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2211 if (dir == FORWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2212 curbuf->b_op_start.lnum++; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2213 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2214 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2215 (linenr_T)MAXLNUM, nr_lines, 0L); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2216 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2217 // note changed text for displaying and folding |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2218 if (y_type == MCHAR) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2219 changed_lines(curwin->w_cursor.lnum, col, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2220 curwin->w_cursor.lnum + 1, nr_lines); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2221 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2222 changed_lines(curbuf->b_op_start.lnum, 0, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2223 curbuf->b_op_start.lnum, nr_lines); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2224 if (y_current_used != NULL && (y_current_used != y_current |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2225 || y_current->y_array != y_array)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2226 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2227 // Something invoked through changed_lines() has changed the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2228 // yank buffer, e.g. a GUI clipboard callback. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2229 emsg(_(e_yank_register_changed_while_using_it)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2230 goto end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2231 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2232 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2233 // Put the '] mark on the first byte of the last inserted character. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2234 // Correct the length for change in indent. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2235 curbuf->b_op_end.lnum = new_lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2236 len = STRLEN(y_array[y_size - 1]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2237 col = (colnr_T)len - lendiff; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2238 if (col > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2239 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2240 curbuf->b_op_end.col = col - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2241 if (len > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2242 curbuf->b_op_end.col -= mb_head_off(y_array[y_size - 1], |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2243 y_array[y_size - 1] + len - 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2244 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2245 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2246 curbuf->b_op_end.col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2247 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2248 if (flags & PUT_CURSLINE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2249 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2250 // ":put": put cursor on last inserted line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2251 curwin->w_cursor.lnum = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2252 beginline(BL_WHITE | BL_FIX); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2253 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2254 else if (flags & PUT_CURSEND) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2255 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2256 // put cursor after inserted text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2257 if (y_type == MLINE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2258 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2259 if (lnum >= curbuf->b_ml.ml_line_count) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2260 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2261 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2262 curwin->w_cursor.lnum = lnum + 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2263 curwin->w_cursor.col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2264 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2265 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2266 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2267 curwin->w_cursor.lnum = new_lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2268 curwin->w_cursor.col = col; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2269 curbuf->b_op_end = curwin->w_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2270 if (col > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2271 curbuf->b_op_end.col = col - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2272 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2273 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2274 else if (y_type == MLINE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2275 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2276 // put cursor on first non-blank in first inserted line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2277 curwin->w_cursor.col = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2278 if (dir == FORWARD) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2279 ++curwin->w_cursor.lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2280 beginline(BL_WHITE | BL_FIX); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2281 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2282 else // put cursor on first inserted character |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2283 curwin->w_cursor = new_cursor; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2284 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2285 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2286 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2287 msgmore(nr_lines); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2288 curwin->w_set_curswant = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2289 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2290 // Make sure the cursor is not after the NUL. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2291 int len = (int)STRLEN(ml_get_curline()); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2292 if (curwin->w_cursor.col > len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2293 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2294 if (cur_ve_flags == VE_ALL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2295 curwin->w_cursor.coladd = curwin->w_cursor.col - len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2296 curwin->w_cursor.col = len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2297 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2298 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2299 end: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2300 if (cmdmod.cmod_flags & CMOD_LOCKMARKS) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2301 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2302 curbuf->b_op_start = orig_start; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2303 curbuf->b_op_end = orig_end; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2304 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2305 if (allocated) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2306 vim_free(insert_string); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2307 if (regname == '=') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2308 vim_free(y_array); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2309 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2310 VIsual_active = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2311 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2312 // If the cursor is past the end of the line put it at the end. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2313 adjust_cursor_eol(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2314 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2315 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2316 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2317 * Return the character name of the register with the given number. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2318 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2319 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2320 get_register_name(int num) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2321 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2322 if (num == -1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2323 return '"'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2324 else if (num < 10) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2325 return num + '0'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2326 else if (num == DELETION_REGISTER) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2327 return '-'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2328 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2329 else if (num == STAR_REGISTER) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2330 return '*'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2331 else if (num == PLUS_REGISTER) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2332 return '+'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2333 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2334 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2335 return num + 'a' - 10; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2336 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2337 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2338 #if defined(FEAT_EVAL) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2339 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2340 * Return the index of the register "" points to. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2341 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2342 int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2343 get_unname_register(void) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2344 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2345 return y_previous == NULL ? -1 : y_previous - &y_regs[0]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2346 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2347 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2348 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2349 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2350 * ":dis" and ":registers": Display the contents of the yank registers. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2351 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2352 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2353 ex_display(exarg_T *eap) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2354 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2355 int i, n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2356 long j; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2357 char_u *p; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2358 yankreg_T *yb; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2359 int name; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2360 int attr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2361 char_u *arg = eap->arg; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2362 int clen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2363 int type; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2364 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2365 if (arg != NULL && *arg == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2366 arg = NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2367 attr = HL_ATTR(HLF_8); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2368 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2369 // Highlight title |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2370 msg_puts_title(_("\nType Name Content")); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2371 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2372 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2373 name = get_register_name(i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2374 switch (get_reg_type(name, NULL)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2375 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2376 case MLINE: type = 'l'; break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2377 case MCHAR: type = 'c'; break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2378 default: type = 'b'; break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2379 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2380 if (arg != NULL && vim_strchr(arg, name) == NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2381 #ifdef ONE_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2382 // Star register and plus register contain the same thing. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2383 && (name != '*' || vim_strchr(arg, '+') == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2384 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2385 ) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2386 continue; // did not ask for this register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2387 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2388 #ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2389 // Adjust register name for "unnamed" in 'clipboard'. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2390 // When it's a clipboard register, fill it with the current contents |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2391 // of the clipboard. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2392 adjust_clip_reg(&name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2393 (void)may_get_selection(name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2394 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2395 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2396 if (i == -1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2397 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2398 if (y_previous != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2399 yb = y_previous; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2400 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2401 yb = &(y_regs[0]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2402 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2403 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2404 yb = &(y_regs[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2405 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2406 #ifdef FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2407 if (name == MB_TOLOWER(redir_reg) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2408 || (redir_reg == '"' && yb == y_previous)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2409 continue; // do not list register being written to, the |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2410 // pointer can be freed |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2411 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2412 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2413 if (yb->y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2414 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2415 int do_show = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2416 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2417 for (j = 0; !do_show && j < yb->y_size; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2418 do_show = !message_filtered(yb->y_array[j]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2419 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2420 if (do_show || yb->y_size == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2421 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2422 msg_putchar('\n'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2423 msg_puts(" "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2424 msg_putchar(type); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2425 msg_puts(" "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2426 msg_putchar('"'); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2427 msg_putchar(name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2428 msg_puts(" "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2429 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2430 n = (int)Columns - 11; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2431 for (j = 0; j < yb->y_size && n > 1; ++j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2432 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2433 if (j) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2434 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2435 msg_puts_attr("^J", attr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2436 n -= 2; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2437 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2438 for (p = yb->y_array[j]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2439 *p != NUL && (n -= ptr2cells(p)) >= 0; ++p) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2440 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2441 clen = (*mb_ptr2len)(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2442 msg_outtrans_len(p, clen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2443 p += clen - 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2444 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2445 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2446 if (n > 1 && yb->y_type == MLINE) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2447 msg_puts_attr("^J", attr); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2448 out_flush(); // show one line at a time |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2449 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2450 ui_breakcheck(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2451 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2452 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2453 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2454 // display last inserted text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2455 if ((p = get_last_insert()) != NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2456 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2457 && !message_filtered(p)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2458 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2459 msg_puts("\n c \". "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2460 dis_msg(p, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2461 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2462 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2463 // display last command line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2464 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2465 && !got_int && !message_filtered(last_cmdline)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2466 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2467 msg_puts("\n c \": "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2468 dis_msg(last_cmdline, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2469 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2470 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2471 // display current file name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2472 if (curbuf->b_fname != NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2473 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2474 && !message_filtered(curbuf->b_fname)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2475 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2476 msg_puts("\n c \"% "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2477 dis_msg(curbuf->b_fname, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2478 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2479 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2480 // display alternate file name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2481 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2482 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2483 char_u *fname; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2484 linenr_T dummy; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2485 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2486 if (buflist_name_nr(0, &fname, &dummy) != FAIL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2487 && !message_filtered(fname)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2488 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2489 msg_puts("\n c \"# "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2490 dis_msg(fname, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2491 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2492 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2493 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2494 // display last search pattern |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2495 if (last_search_pat() != NULL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2496 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2497 && !message_filtered(last_search_pat())) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2498 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2499 msg_puts("\n c \"/ "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2500 dis_msg(last_search_pat(), FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2501 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2502 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2503 #ifdef FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2504 // display last used expression |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2505 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2506 && !got_int && !message_filtered(expr_line)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2507 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2508 msg_puts("\n c \"= "); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2509 dis_msg(expr_line, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2510 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2511 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2512 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2513 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2514 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2515 * display a string for do_dis() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2516 * truncate at end of screen line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2517 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2518 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2519 dis_msg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2520 char_u *p, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2521 int skip_esc) // if TRUE, ignore trailing ESC |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2522 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2523 int n; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2524 int l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2525 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2526 n = (int)Columns - 6; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2527 while (*p != NUL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2528 && !(*p == ESC && skip_esc && *(p + 1) == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2529 && (n -= ptr2cells(p)) >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2530 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2531 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2532 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2533 msg_outtrans_len(p, l); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2534 p += l; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2535 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2536 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2537 msg_outtrans_len(p++, 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2538 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2539 ui_breakcheck(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2540 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2541 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2542 #if defined(FEAT_DND) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2543 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2544 * Replace the contents of the '~' register with str. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2545 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2546 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2547 dnd_yank_drag_data(char_u *str, long len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2548 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2549 yankreg_T *curr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2550 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2551 curr = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2552 y_current = &y_regs[TILDE_REGISTER]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2553 free_yank_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2554 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2555 y_current = curr; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2556 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2557 #endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2558 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2559 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2560 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2561 * Return the type of a register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2562 * Used for getregtype() |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2563 * Returns MAUTO for error. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2564 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2565 char_u |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2566 get_reg_type(int regname, long *reglen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2567 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2568 switch (regname) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2569 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2570 case '%': // file name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2571 case '#': // alternate file name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2572 case '=': // expression |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2573 case ':': // last command line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2574 case '/': // last search-pattern |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2575 case '.': // last inserted text |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2576 case Ctrl_F: // Filename under cursor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2577 case Ctrl_P: // Path under cursor, expand via "path" |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2578 case Ctrl_W: // word under cursor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2579 case Ctrl_A: // WORD (mnemonic All) under cursor |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2580 case '_': // black hole: always empty |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2581 return MCHAR; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2582 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2583 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2584 # ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2585 regname = may_get_selection(regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2586 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2587 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2588 if (regname != NUL && !valid_yank_reg(regname, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2589 return MAUTO; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2590 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2591 get_yank_register(regname, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2592 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2593 if (y_current->y_array != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2594 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2595 if (reglen != NULL && y_current->y_type == MBLOCK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2596 *reglen = y_current->y_width; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2597 return y_current->y_type; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2598 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2599 return MAUTO; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2600 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2601 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2602 #if defined(FEAT_EVAL) || defined(PROTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2603 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2604 * When "flags" has GREG_LIST return a list with text "s". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2605 * Otherwise just return "s". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2606 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2607 static char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2608 getreg_wrap_one_line(char_u *s, int flags) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2609 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2610 if (flags & GREG_LIST) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2611 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2612 list_T *list = list_alloc(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2613 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2614 if (list != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2615 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2616 if (list_append_string(list, NULL, -1) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2617 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2618 list_free(list); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2619 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2620 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2621 list->lv_first->li_tv.vval.v_string = s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2622 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2623 return (char_u *)list; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2624 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2625 return s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2626 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2627 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2628 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2629 * Return the contents of a register as a single allocated string or as a list. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2630 * Used for "@r" in expressions and for getreg(). |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2631 * Returns NULL for error. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2632 * Flags: |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2633 * GREG_NO_EXPR Do not allow expression register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2634 * GREG_EXPR_SRC For the expression register: return expression itself, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2635 * not the result of its evaluation. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2636 * GREG_LIST Return a list of lines instead of a single string. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2637 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2638 char_u * |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2639 get_reg_contents(int regname, int flags) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2640 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2641 long i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2642 char_u *retval; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2643 int allocated; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2644 long len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2645 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2646 // Don't allow using an expression register inside an expression |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2647 if (regname == '=') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2648 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2649 if (flags & GREG_NO_EXPR) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2650 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2651 if (flags & GREG_EXPR_SRC) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2652 return getreg_wrap_one_line(get_expr_line_src(), flags); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2653 return getreg_wrap_one_line(get_expr_line(), flags); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2654 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2655 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2656 if (regname == '@') // "@@" is used for unnamed register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2657 regname = '"'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2658 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2659 // check for valid regname |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2660 if (regname != NUL && !valid_yank_reg(regname, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2661 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2662 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2663 # ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2664 regname = may_get_selection(regname); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2665 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2666 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2667 if (get_spec_reg(regname, &retval, &allocated, FALSE)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2668 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2669 if (retval == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2670 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2671 if (allocated) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2672 return getreg_wrap_one_line(retval, flags); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2673 return getreg_wrap_one_line(vim_strsave(retval), flags); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2674 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2675 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2676 get_yank_register(regname, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2677 if (y_current->y_array == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2678 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2679 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2680 if (flags & GREG_LIST) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2681 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2682 list_T *list = list_alloc(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2683 int error = FALSE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2684 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2685 if (list == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2686 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2687 for (i = 0; i < y_current->y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2688 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2689 error = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2690 if (error) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2691 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2692 list_free(list); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2693 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2694 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2695 return (char_u *)list; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2696 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2697 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2698 // Compute length of resulting string. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2699 len = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2700 for (i = 0; i < y_current->y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2701 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2702 len += (long)STRLEN(y_current->y_array[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2703 // Insert a newline between lines and after last line if |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2704 // y_type is MLINE. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2705 if (y_current->y_type == MLINE || i < y_current->y_size - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2706 ++len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2707 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2708 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2709 retval = alloc(len + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2710 if (retval == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2711 return NULL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2712 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2713 // Copy the lines of the yank register into the string. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2714 len = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2715 for (i = 0; i < y_current->y_size; ++i) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2716 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2717 STRCPY(retval + len, y_current->y_array[i]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2718 len += (long)STRLEN(retval + len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2719 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2720 // Insert a NL between lines and after the last line if y_type is |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2721 // MLINE. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2722 if (y_current->y_type == MLINE || i < y_current->y_size - 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2723 retval[len++] = '\n'; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2724 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2725 retval[len] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2726 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2727 return retval; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2728 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2729 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2730 static int |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2731 init_write_reg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2732 int name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2733 yankreg_T **old_y_previous, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2734 yankreg_T **old_y_current, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2735 int must_append, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2736 int *yank_type UNUSED) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2737 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2738 if (!valid_yank_reg(name, TRUE)) // check for valid reg name |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2739 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2740 emsg_invreg(name); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2741 return FAIL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2742 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2743 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2744 // Don't want to change the current (unnamed) register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2745 *old_y_previous = y_previous; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2746 *old_y_current = y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2747 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2748 get_yank_register(name, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2749 if (!y_append && !must_append) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2750 free_yank_all(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2751 return OK; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2752 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2753 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2754 static void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2755 finish_write_reg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2756 int name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2757 yankreg_T *old_y_previous, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2758 yankreg_T *old_y_current) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2759 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2760 # ifdef FEAT_CLIPBOARD |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2761 // Send text of clipboard register to the clipboard. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2762 may_set_selection(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2763 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2764 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2765 // ':let @" = "val"' should change the meaning of the "" register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2766 if (name != '"') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2767 y_previous = old_y_previous; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2768 y_current = old_y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2769 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2770 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2771 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2772 * Store string "str" in register "name". |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2773 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2774 * If "must_append" is TRUE, always append to the register. Otherwise append |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2775 * if "name" is an uppercase letter. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2776 * Note: "maxlen" and "must_append" don't work for the "/" register. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2777 * Careful: 'str' is modified, you may have to use a copy! |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2778 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2779 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2780 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2781 write_reg_contents( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2782 int name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2783 char_u *str, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2784 int maxlen, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2785 int must_append) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2786 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2787 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2788 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2789 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2790 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2791 write_reg_contents_lst( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2792 int name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2793 char_u **strings, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2794 int maxlen UNUSED, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2795 int must_append, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2796 int yank_type, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2797 long block_len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2798 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2799 yankreg_T *old_y_previous, *old_y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2800 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2801 if (name == '/' || name == '=') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2802 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2803 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2804 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2805 if (strings[0] == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2806 s = (char_u *)""; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2807 else if (strings[1] != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2808 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2809 emsg(_(e_search_pattern_and_expression_register_may_not_contain_two_or_more_lines)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2810 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2811 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2812 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2813 s = strings[0]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2814 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2815 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2816 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2817 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2818 if (name == '_') // black hole: nothing to do |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2819 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2820 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2821 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2822 &yank_type) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2823 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2824 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2825 str_to_reg(y_current, yank_type, (char_u *)strings, -1, block_len, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2826 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2827 finish_write_reg(name, old_y_previous, old_y_current); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2828 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2829 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2830 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2831 write_reg_contents_ex( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2832 int name, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2833 char_u *str, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2834 int maxlen, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2835 int must_append, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2836 int yank_type, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2837 long block_len) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2838 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2839 yankreg_T *old_y_previous, *old_y_current; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2840 long len; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2841 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2842 if (maxlen >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2843 len = maxlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2844 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2845 len = (long)STRLEN(str); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2846 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2847 // Special case: '/' search pattern |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2848 if (name == '/') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2849 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2850 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2851 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2852 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2853 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2854 if (name == '#') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2855 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2856 buf_T *buf; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2857 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2858 if (VIM_ISDIGIT(*str)) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2859 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2860 int num = atoi((char *)str); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2861 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2862 buf = buflist_findnr(num); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2863 if (buf == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2864 semsg(_(e_buffer_nr_does_not_exist), (long)num); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2865 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2866 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2867 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2868 TRUE, FALSE, FALSE)); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2869 if (buf == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2870 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2871 curwin->w_alt_fnum = buf->b_fnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2872 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2873 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2874 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2875 if (name == '=') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2876 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2877 char_u *p, *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2878 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2879 p = vim_strnsave(str, len); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2880 if (p == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2881 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2882 if (must_append && expr_line != NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2883 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2884 s = concat_str(expr_line, p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2885 vim_free(p); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2886 p = s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2887 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2888 set_expr_line(p, NULL); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2889 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2890 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2891 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2892 if (name == '_') // black hole: nothing to do |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2893 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2894 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2895 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2896 &yank_type) == FAIL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2897 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2898 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2899 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2900 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2901 finish_write_reg(name, old_y_previous, old_y_current); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2902 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2903 #endif // FEAT_EVAL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2904 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2905 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2906 /* |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2907 * Put a string into a register. When the register is not empty, the string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2908 * is appended. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2909 */ |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2910 void |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2911 str_to_reg( |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2912 yankreg_T *y_ptr, // pointer to yank register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2913 int yank_type, // MCHAR, MLINE, MBLOCK, MAUTO |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2914 char_u *str, // string to put in register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2915 long len, // length of string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2916 long blocklen, // width of Visual block |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2917 int str_list) // TRUE if str is char_u ** |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2918 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2919 int type; // MCHAR, MLINE or MBLOCK |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2920 int lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2921 long start; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2922 long i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2923 int extra; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2924 int newlines; // number of lines added |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2925 int extraline = 0; // extra line at the end |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2926 int append = FALSE; // append to last line in register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2927 char_u *s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2928 char_u **ss; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2929 char_u **pp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2930 long maxlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2931 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2932 if (y_ptr->y_array == NULL) // NULL means empty register |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2933 y_ptr->y_size = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2934 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2935 if (yank_type == MAUTO) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2936 type = ((str_list || (len > 0 && (str[len - 1] == NL |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2937 || str[len - 1] == CAR))) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2938 ? MLINE : MCHAR); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2939 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2940 type = yank_type; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2941 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2942 // Count the number of lines within the string |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2943 newlines = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2944 if (str_list) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2945 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2946 for (ss = (char_u **) str; *ss != NULL; ++ss) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2947 ++newlines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2948 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2949 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2950 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2951 for (i = 0; i < len; i++) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2952 if (str[i] == '\n') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2953 ++newlines; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2954 if (type == MCHAR || len == 0 || str[len - 1] != '\n') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2955 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2956 extraline = 1; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2957 ++newlines; // count extra newline at the end |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2958 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2959 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2960 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2961 append = TRUE; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2962 --newlines; // uncount newline when appending first line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2963 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2964 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2965 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2966 // Without any lines make the register empty. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2967 if (y_ptr->y_size + newlines == 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2968 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2969 VIM_CLEAR(y_ptr->y_array); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2970 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2971 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2972 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2973 // Allocate an array to hold the pointers to the new register lines. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2974 // If the register was not empty, move the existing lines to the new array. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2975 pp = lalloc_clear((y_ptr->y_size + newlines) * sizeof(char_u *), TRUE); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2976 if (pp == NULL) // out of memory |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2977 return; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2978 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2979 pp[lnum] = y_ptr->y_array[lnum]; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2980 vim_free(y_ptr->y_array); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2981 y_ptr->y_array = pp; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2982 maxlen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2983 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2984 // Find the end of each line and save it into the array. |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2985 if (str_list) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2986 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2987 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2988 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2989 pp[lnum] = vim_strsave(*ss); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2990 if (type == MBLOCK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2991 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2992 int charlen = mb_string2cells(*ss, -1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2993 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2994 if (charlen > maxlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2995 maxlen = charlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2996 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2997 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2998 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
2999 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3000 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3001 for (start = 0; start < len + extraline; start += i + 1) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3002 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3003 int charlen = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3004 |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3005 for (i = start; i < len; ++i) // find the end of the line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3006 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3007 if (str[i] == '\n') |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3008 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3009 if (type == MBLOCK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3010 charlen += mb_ptr2cells_len(str + i, len - i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3011 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3012 i -= start; // i is now length of line |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3013 if (charlen > maxlen) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3014 maxlen = charlen; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3015 if (append) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3016 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3017 --lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3018 extra = (int)STRLEN(y_ptr->y_array[lnum]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3019 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3020 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3021 extra = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3022 s = alloc(i + extra + 1); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3023 if (s == NULL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3024 break; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3025 if (extra) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3026 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3027 if (append) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3028 vim_free(y_ptr->y_array[lnum]); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3029 if (i > 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3030 mch_memmove(s + extra, str + start, (size_t)i); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3031 extra += i; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3032 s[extra] = NUL; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3033 y_ptr->y_array[lnum++] = s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3034 while (--extra >= 0) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3035 { |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3036 if (*s == NUL) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3037 *s = '\n'; // replace NUL with newline |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3038 ++s; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3039 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3040 append = FALSE; // only first line is appended |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3041 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3042 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3043 y_ptr->y_type = type; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3044 y_ptr->y_size = lnum; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3045 if (type == MBLOCK) |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3046 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3047 else |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3048 y_ptr->y_width = 0; |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3049 # ifdef FEAT_VIMINFO |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3050 y_ptr->y_time_set = vim_time(); |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3051 # endif |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3052 } |
448aef880252
normalize line endings
Christian Brabandt <cb@256bit.org>
parents:
32531
diff
changeset
|
3053 #endif // FEAT_CLIPBOARD || FEAT_EVAL || PROTO |