annotate src/register.c @ 19774:00a1b89256ea v8.2.0443

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