annotate src/register.c @ 20824:b8ca32dcfabb v8.2.0964

patch 8.2.0964: TextYankPost does not provide info about Visual selection Commit: https://github.com/vim/vim/commit/37d1673ce007c46ec2338f3236ae1b7b0324bd25 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Jun 12 22:09:01 2020 +0200 patch 8.2.0964: TextYankPost does not provide info about Visual selection Problem: TextYankPost does not provide info about Visual selection. Solution: Add the 'visual' key in v:event. (closes https://github.com/vim/vim/issues/6249)
author Bram Moolenaar <Bram@vim.org>
date Fri, 12 Jun 2020 22:15:04 +0200
parents a672feb8fc4f
children 9064044fd4f6
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
20824
b8ca32dcfabb patch 8.2.0964: TextYankPost does not provide info about Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 20743
diff changeset
931 dict_add_bool(v_event, "visual", oap->is_VIsual);
b8ca32dcfabb patch 8.2.0964: TextYankPost does not provide info about Visual selection
Bram Moolenaar <Bram@vim.org>
parents: 20743
diff changeset
932
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 // 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
934 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
935
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 recursive = TRUE;
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 19774
diff changeset
937 textwinlock++;
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf);
20229
06a1dd50463e patch 8.2.0670: cannot change window when evaluating 'completefunc'
Bram Moolenaar <Bram@vim.org>
parents: 19774
diff changeset
939 textwinlock--;
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940 recursive = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 // 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
943 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
944 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
945 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947
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 * 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
950 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952 init_yank(void)
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 int i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 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
957 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
958 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 #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
961 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 clear_registers(void)
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 int 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 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
967 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 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
969 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
970 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 }
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 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 * 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
977 * 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
978 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 free_yank(long n)
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 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
983 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 long i;
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 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
987 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 #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
989 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
990 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 // 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
992 // 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
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 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
995 --no_wait_return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 msg_didout = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 msg_col = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 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
1001 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 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
1003 #ifdef AMIGA
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 if (n >= 1000)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 msg("");
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 19524
diff changeset
1010 void
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 free_yank_all(void)
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 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
1014 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 * 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
1018 * 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
1019 * 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
1020 * 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
1021 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 * 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
1023 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 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
1026 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 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
1028 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
1029 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
1030 char_u **new_ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 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
1032 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 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
1034 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
1035 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
1036 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 char_u *pnew;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 struct block_def bd;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 #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
1040 int did_star = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 // 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
1044 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
1045 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 beep_flush();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 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
1050 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 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
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 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
1056 oap->regname = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 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
1060 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
1061
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 curr = y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 // append to existing contents
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 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
1065 y_current = &newreg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 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
1068
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 // 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
1070 // 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
1071 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
1072 && oap->start.col == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 && !oap->inclusive
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 && (!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
1075 && !oap->block_mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 && oap->end.col == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 && yanklines > 1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 yanktype = MLINE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 --yankendlnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 --yanklines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 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
1085 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
1086 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
1087 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
1088 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
1089 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 y_current = curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 #ifdef FEAT_VIMINFO
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 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
1095 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 y_idx = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 lnum = oap->start.lnum;
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 if (oap->block_mode)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 // Visual block mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 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
1104 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
1105
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 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
1107 y_current->y_width--;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 }
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 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
1111 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 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
1113 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 case MBLOCK:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 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
1116 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
1117 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 case MLINE:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 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
1122 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
1123 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 break;
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 case MCHAR:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 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
1129 int is_oneChar = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 colnr_T cs, ce;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 p = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 bd.startspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 bd.endspaces = 0;
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 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
1137 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 startcol = oap->start.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 if (virtual_op)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 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
1142 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
1143 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 // 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
1145 // double-count it.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 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
1147 - oap->start.coladd;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 startcol++;
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 }
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 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
1154 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 endcol = oap->end.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156 if (virtual_op)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 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
1159 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
1160 // 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
1161 // 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
1162 // of multi-byte char.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 && (*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
1164 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 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
1166 && 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
1167 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 // 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
1169 is_oneChar = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 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
1171 - 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
1172 endcol = startcol;
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 + oap->inclusive;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 endcol -= oap->inclusive;
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 if (endcol == MAXCOL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 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
1185 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
1186 bd.textlen = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 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
1189 bd.textstart = p + startcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 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
1191 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 break;
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 // NOTREACHED
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 }
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 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
1199 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 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
1201 if (new_ptr == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 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
1204 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
1205 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
1206 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
1207 #ifdef FEAT_VIMINFO
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 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
1209 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 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
1212 curr->y_type = MLINE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 // 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
1215 // 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
1216 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
1217 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 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
1219 + 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
1220 if (pnew == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 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
1223 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 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
1226 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
1227 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
1228 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
1229 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
1230 y_idx = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 y_idx = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 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
1235 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
1236 curr->y_size = j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 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
1238 y_current = curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 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
1241 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
1242 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
1243 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 if (yanktype == MCHAR
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 && !oap->block_mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 && yanklines == 1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 yanklines = 0;
18498
9e6d5a4abb1c patch 8.1.2243: typos in comments
Bram Moolenaar <Bram@vim.org>
parents: 18454
diff changeset
1248 // 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
1249 if (yanklines > p_report)
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 char namebuf[100];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 if (oap->regname == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 *namebuf = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 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
1257 _(" into \"%c"), oap->regname);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 // 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
1260 update_topline_redraw();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 if (oap->block_mode)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 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
1264 "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
1265 yanklines, namebuf);
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 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
1270 "%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
1271 yanklines, namebuf);
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 }
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 if (!cmdmod.lockmarks)
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 {
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1278 // Set "'[" and "']" marks.
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1279 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
1280 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
1281 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
1282 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1283 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
1284 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
1285 }
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 // 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
1290 // 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
1291 // to the '*' register.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 if (clip_star.available
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 && (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
1294 || (!deleting && oap->regname == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 && ((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
1296 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 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
1298 // 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
1299 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
1300
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 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
1302 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
1303 # ifdef FEAT_X11
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 did_star = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 # ifdef FEAT_X11
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 // 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
1310 // 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
1311 if (clip_plus.available
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 && (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
1313 || (!deleting && oap->regname == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 && ((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
1315 CLIP_UNNAMED_PLUS))))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 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
1318 // 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
1319 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
1320
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 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
1322 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
1323 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
1324 && !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
1325 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 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
1327 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
1328 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
1329 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 #if defined(FEAT_EVAL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 if (!deleting && has_textyankpost())
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 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
1337 #endif
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 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 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
1342 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
1343 y_current = curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 static int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 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
1349 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350 char_u *pnew;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 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
1353 == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 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
1356 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
1357 pnew += bd->startspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 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
1359 pnew += bd->textlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 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
1361 pnew += bd->endspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 *pnew = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 }
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 #ifdef FEAT_CLIPBOARD
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 * 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
1369 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 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
1372 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 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
1374 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 y_current = reg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 *y_current = *curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 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
1380 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
1381 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
1382 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
1383 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 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
1385 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
1386 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 free_yank(j);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 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
1389 break;
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 y_current = curr;
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 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 * 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
1397 * 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
1398 * "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
1399 * 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
1400 * 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
1401 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 do_put(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 int regname,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 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
1406 long count,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 int flags)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 char_u *ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 char_u *newp, *oldp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 int yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 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
1413 linenr_T lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 colnr_T col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 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
1416 int y_type;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 long y_size;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 int oldlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 long y_width = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 colnr_T vcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 int delcount;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 int incr = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 struct block_def bd;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 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
1426 long nr_lines = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 pos_T new_cursor;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 int indent;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 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
1430 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
1431 int first_indent = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 int lendiff = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 pos_T old_pos;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 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
1435 int allocated = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 long cnt;
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
1437 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
1438 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
1439
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 // 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
1442 adjust_clip_reg(&regname);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 (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
1444 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 if (flags & PUT_FIXINDENT)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 orig_indent = get_indent();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 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
1450 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
1451
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 // 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
1453 // special characters (newlines, etc.).
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 if (regname == '.')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456 if (VIsual_active)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 stuffcharReadbuff(VIsual_mode);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 (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
1459 (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
1460 // 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
1461 // 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
1462 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
1463 stuffcharReadbuff('l');
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 // 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
1468 // ':' (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
1469 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
1470 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 if (insert_string == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 // 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
1476 // 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
1477 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
1478 goto end;
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 if (insert_string != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 y_type = MCHAR;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 if (regname == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 // 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
1487 // characters.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 // 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
1489 for (;;)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 y_size = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 ptr = insert_string;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 while (ptr != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 if (y_array != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 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
1497 ++y_size;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 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
1499 if (ptr != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 if (y_array != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 *ptr = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 ++ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 // 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
1505 if (*ptr == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 y_type = MLINE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 break;
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 if (y_array != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 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
1515 if (y_array == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 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
1523 y_array = &insert_string;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 }
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 else
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 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
1529
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 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
1531 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
1532 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
1533 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
1534 }
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 (y_type == MLINE)
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 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
1539 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 // "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
1543 // between.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 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
1545 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 p = ml_get_cursor();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 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
1548 MB_PTR_ADV(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 ptr = vim_strsave(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 if (ptr == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 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
1553 vim_free(ptr);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 oldp = ml_get_curline();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 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
1557 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
1558 MB_PTR_ADV(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 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
1560 if (ptr == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 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
1563 ++nr_lines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 dir = 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 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
1567 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 // 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
1569 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
1570 dir = FORWARD;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 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
1573 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
1574 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 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
1577 y_type = MLINE;
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 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
1580 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 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
1582 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
1583 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 }
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 if (y_type == MBLOCK)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 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
1589 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
1590 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
1591 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
1592 goto end;
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 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
1595 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 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
1597 #ifdef FEAT_FOLDING
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 // 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
1599 // u_save() uses it.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 if (dir == BACKWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 (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
1602 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 (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
1604 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 if (dir == FORWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 ++lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 // 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
1608 // 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
1609 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
1610 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 #ifdef FEAT_FOLDING
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 if (dir == FORWARD)
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 - 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 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
1616 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
1617 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 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
1620 goto end;
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 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
1623
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 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
1625 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 if (gchar_cursor() == TAB)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 {
18771
50fde4e20790 patch 8.1.2375: no suffucient testing for registers
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
1628 int viscol = getviscol();
50fde4e20790 patch 8.1.2375: no suffucient testing for registers
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
1629 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
1630
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 // 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
1632 // 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
1633 if (dir == FORWARD ?
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 #ifdef FEAT_VARTABS
18771
50fde4e20790 patch 8.1.2375: no suffucient testing for registers
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
1635 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
1636 #else
50fde4e20790 patch 8.1.2375: no suffucient testing for registers
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
1637 ts - (viscol % ts) != 1
50fde4e20790 patch 8.1.2375: no suffucient testing for registers
Bram Moolenaar <Bram@vim.org>
parents: 18619
diff changeset
1638 #endif
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 : 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
1640 coladvance_force(viscol);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 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
1643 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 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
1645 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
1646 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 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
1649 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
1650
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 // Block mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 if (y_type == MBLOCK)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 int c = gchar_cursor();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 colnr_T endcol2 = 0;
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 (dir == FORWARD && c != NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 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
1660 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
1661 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 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
1663
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 if (has_mbyte)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 // 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
1666 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
1667 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 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
1669 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 ++col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 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
1674
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 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
1676 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
1677 && (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
1678 || 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
1679 {
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 ++col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 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
1683 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 if (c == TAB)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 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
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 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
1689 curwin->w_cursor.col++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 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
1693 bd.textcol = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 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
1695 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 int spaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 char shortline;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 bd.startspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 bd.endspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 vcol = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 delcount = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 // add a new line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 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
1706 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 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
1708 (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
1709 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 ++nr_lines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 // 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
1713 oldp = ml_get_curline();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 oldlen = (int)STRLEN(oldp);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 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
1716 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 // 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
1718 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
1719 vcol += incr;
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 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
1722
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 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
1724
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 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
1726 bd.startspaces = col - vcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 else if (vcol > col)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 bd.endspaces = vcol - col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 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
1731 --bd.textcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 delcount = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 if (has_mbyte)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 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
1735 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
1736 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 // 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
1738 // 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
1739 // block, causing misalignment.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 delcount = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 bd.endspaces = 0;
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 }
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 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
1746
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 // 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
1748 spaces = y_width + 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 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
1750 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
1751 if (spaces < 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 spaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 // insert the new text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 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
1756 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
1757 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 // 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
1760 ptr = newp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 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
1762 ptr += bd.textcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 // 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
1764 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
1765 ptr += bd.startspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 // insert the new text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 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
1768 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 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
1770 ptr += yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 // 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
1773 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
1774 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 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
1776 ptr += spaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 // 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
1780 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
1781 ptr += bd.endspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 // 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
1783 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
1784 (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
1785 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
1786
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 ++curwin->w_cursor.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 if (i == 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 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
1790 }
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 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
1793
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 // Set '[ mark.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 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
1796 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
1797
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 // adjust '] mark
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.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
1800 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
1801 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
1802 if (flags & PUT_CURSEND)
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 colnr_T len;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 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
1807 curwin->w_cursor.col++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 // 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
1810 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
1811 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
1812 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
1813 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 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
1816 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 // Character or Line mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 if (y_type == MCHAR)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 // 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
1823 // char
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 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
1825 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826 if (has_mbyte)
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 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
1829
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 // 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
1831 col += bytelen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 if (yanklen)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 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
1835 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
1836 }
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 ++col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 if (yanklen)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 ++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
1845 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 }
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 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
1849 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 // 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
1851 else if (dir == BACKWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852 --lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 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
1854
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 // 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
1856 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
1857 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 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
1859
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 if (VIsual_active)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861 {
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_end.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 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
1864 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
1865 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 do {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 totlen = count * yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 if (totlen > 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 oldp = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 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
1873 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 lnum++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 continue;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 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
1878 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 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
1880 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
1881 ptr = newp + col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 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
1883 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 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
1885 ptr += yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887 STRMOVE(ptr, oldp + col);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 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
1889 // 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
1890 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
1891 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 // 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
1893 changed_cline_bef_curs();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 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
1895 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 if (VIsual_active)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 lnum++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 } 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
1900
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 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
1902 lnum--;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 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
1905 // 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
1906 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
1907 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 changed_bytes(lnum, col);
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 // 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
1913 // line in two.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 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
1915 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 i = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 if (y_type == MCHAR)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 // 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
1920 // 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
1921 // 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
1922 lnum = new_cursor.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 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
1924 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
1925 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
1926 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 goto error;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 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
1929 STRCAT(newp, ptr);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 // insert second line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 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
1932 vim_free(newp);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 oldp = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 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
1936 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 goto error;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 // 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
1939 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
1940 // append to first line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 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
1942 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
1943
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 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
1945 i = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946 }
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 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
1949 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 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
1951 && 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
1952 == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953 goto error;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 lnum++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 ++nr_lines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 if (flags & PUT_FIXINDENT)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 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
1959 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
1960 ptr = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 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
1962 lendiff = (int)STRLEN(ptr);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 #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
1964 if (*ptr == '#' && preprocs_left())
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 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
1966 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 if (*ptr == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 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
1970 else if (first_indent)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 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
1973 indent = orig_indent;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 first_indent = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 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
1977 indent = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 (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
1979 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
1980 // 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
1981 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
1982 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
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 error:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 // Adjust marks.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 if (y_type == MLINE)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 {
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.col = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 if (dir == FORWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 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
1994 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 // 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
1996 // 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
1997 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
1998 < 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
1999 #ifdef FEAT_DIFF
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 || curwin->w_p_diff
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 )
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 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
2004 (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
2005
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 // 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
2007 if (y_type == MCHAR)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 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
2009 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
2010 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 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
2012 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
2013
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 // 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
2015 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
2016 // 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
2017 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
2018 if (col > 1)
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 = col - 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 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
2022
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 if (flags & PUT_CURSLINE)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 // ":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
2026 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
2027 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
2028 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 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
2030 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2031 // 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
2032 if (y_type == MLINE)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 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
2035 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
2036 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 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
2038 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
2039 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 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
2043 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
2044 }
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 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
2047 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 // 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
2049 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
2050 if (dir == FORWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 ++curwin->w_cursor.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 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
2053 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 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
2055 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
2056 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 msgmore(nr_lines);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 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
2061
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 end:
18619
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
2063 if (cmdmod.lockmarks)
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
2064 {
788d76db02ac patch 8.1.2302: :lockmarks does not work for '[ and ']
Bram Moolenaar <Bram@vim.org>
parents: 18498
diff changeset
2065 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
2066 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
2067 }
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 if (allocated)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 vim_free(insert_string);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 if (regname == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 vim_free(y_array);
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 VIsual_active = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 // 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
2076 adjust_cursor_eol();
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
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 * 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
2081 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 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
2084 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 if (num == -1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 return '"';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 else if (num < 10)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 return num + '0';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 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
2090 return '-';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 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
2093 return '*';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 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
2095 return '+';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2096 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 #ifdef EBCDIC
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 int i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 // EBCDIC is really braindead ...
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 i = 'a' + (num - 10);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 if (i > 'i')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 i += 7;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 if (i > 'r')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 i += 8;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 return i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 #else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 return num + 'a' - 10;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 #endif
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 /*
20743
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2116 * Return the index of the register "" points to.
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2117 */
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2118 int
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2119 get_unname_register()
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2120 {
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2121 return y_previous == NULL ? -1 : y_previous - &y_regs[0];
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2122 }
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2123
a672feb8fc4f patch 8.2.0924: cannot save and restore a register properly
Bram Moolenaar <Bram@vim.org>
parents: 20229
diff changeset
2124 /*
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 * ":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
2126 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128 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
2129 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 int i, n;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 yankreg_T *yb;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 int name;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 int attr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 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
2137 int clen;
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2138 int type;
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 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
2141 arg = NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 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
2143
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 // 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
2145 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
2146 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
2147 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 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
2149 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
2150 {
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2151 case MLINE: type = 'l'; break;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2152 case MCHAR: type = 'c'; break;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2153 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
2154 }
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 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
2156 #ifdef ONE_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 // 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
2158 && (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
2159 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 )
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 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
2162
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 // 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
2165 // 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
2166 // of the clipboard.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 adjust_clip_reg(&name);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 (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
2169 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 if (i == -1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 if (y_previous != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 yb = y_previous;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 yb = &(y_regs[0]);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 yb = &(y_regs[i]);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182 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
2183 || (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
2184 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
2185 // pointer can be freed
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 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
2189 {
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2190 int do_show = FALSE;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2191
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2192 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
2193 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
2194
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2195 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
2196 {
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2197 msg_putchar('\n');
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2198 msg_puts(" ");
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2199 msg_putchar(type);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2200 msg_puts(" ");
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2201 msg_putchar('"');
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2202 msg_putchar(name);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2203 msg_puts(" ");
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2205 n = (int)Columns - 11;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2206 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
2207 {
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2208 if (j)
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 msg_puts_attr("^J", attr);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2211 n -= 2;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2212 }
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2213 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
2214 ++p)
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2215 {
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2216 clen = (*mb_ptr2len)(p);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2217 msg_outtrans_len(p, clen);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2218 p += clen - 1;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2219 }
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2220 }
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2221 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
2222 msg_puts_attr("^J", attr);
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2223 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
2224 }
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2225 ui_breakcheck();
18164
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2228
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2229 // display last inserted text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230 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
2231 && (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
2232 && !message_filtered(p))
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2233 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2234 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
2235 dis_msg(p, TRUE);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2236 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2237
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2238 // display last command line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2239 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
2240 && !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
2241 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2242 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
2243 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
2244 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2245
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2246 // display current file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2247 if (curbuf->b_fname != NULL
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2248 && (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
2249 && !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
2250 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2251 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
2252 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
2253 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2254
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2255 // display alternate file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 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
2257 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2258 char_u *fname;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 linenr_T dummy;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2260
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2261 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
2262 && !message_filtered(fname))
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2264 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
2265 dis_msg(fname, FALSE);
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2268
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2269 // display last search pattern
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2270 if (last_search_pat() != NULL
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2271 && (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
2272 && !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
2273 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2274 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
2275 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
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 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2279 // display last used expression
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280 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
2281 && !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
2282 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2283 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
2284 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
2285 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2287 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2288
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 * 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
2291 * 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
2292 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2293 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294 dis_msg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 char_u *p,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 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
2297 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2298 int n;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2299 int l;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2300
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2301 n = (int)Columns - 6;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2302 while (*p != NUL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303 && !(*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
2304 && (n -= ptr2cells(p)) >= 0)
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 (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
2307 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2308 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
2309 p += l;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2310 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2311 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 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
2313 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2314 ui_breakcheck();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2315 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2316
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2317 #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
2318 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 * 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
2320 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 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
2323 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 yankreg_T *curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326 curr = y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 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
2328 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 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
2330 y_current = curr;
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 #endif
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2335 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 * 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
2337 * Used for getregtype()
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 * Returns MAUTO for error.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2339 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 char_u
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 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
2342 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2343 switch (regname)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 case '%': // file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 case '#': // alternate file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 case '=': // expression
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348 case ':': // last command line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 case '/': // last search-pattern
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 case '.': // last inserted text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 # ifdef FEAT_SEARCHPATH
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 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
2353 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
2354 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2355 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
2356 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
2357 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
2358 return MCHAR;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 }
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 # ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2362 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
2363 # endif
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 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
2366 return MAUTO;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 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
2369
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 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
2371 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 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
2373 *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
2374 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
2375 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 return MAUTO;
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
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2379 #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
2380 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 * 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
2382 * Otherwise just return "s".
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 static char_u *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 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
2386 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 if (flags & GREG_LIST)
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 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
2390
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 if (list != NULL)
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 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
2394 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 list_free(list);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 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
2399 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2400 return (char_u *)list;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2401 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 return s;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405 /*
19524
4a6a412e4565 patch 8.2.0319: file missing in distribution, comments outdated
Bram Moolenaar <Bram@vim.org>
parents: 19195
diff changeset
2406 * 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
2407 * 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
2408 * Returns NULL for error.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 * Flags:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 * 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
2411 * 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
2412 * 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
2413 * 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
2414 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 char_u *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 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
2417 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 char_u *retval;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 int allocated;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 long len;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 // 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
2424 if (regname == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 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
2427 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 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
2429 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
2430 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
2431 }
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 (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
2434 regname = '"';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 // check for valid regname
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 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
2438 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440 # ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 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
2442 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 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
2445 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 if (retval == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 if (allocated)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 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
2450 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
2451 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 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
2454 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
2455 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 if (flags & GREG_LIST)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459 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
2460 int error = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 if (list == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 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
2465 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
2466 error = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 if (error)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 list_free(list);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2472 return (char_u *)list;
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 // 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
2476 len = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477 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
2478 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 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
2480 // 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
2481 // y_type is MLINE.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 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
2483 ++len;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 }
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 retval = alloc(len + 1);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2487
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2488 // 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
2489 if (retval != NULL)
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 len = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 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
2493 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 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
2495 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
2496
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 // 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
2498 // MLINE.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 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
2500 retval[len++] = '\n';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 retval[len] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 }
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 return retval;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2508 static int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 init_write_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 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
2512 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
2513 int must_append,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 int *yank_type UNUSED)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 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
2517 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 emsg_invreg(name);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519 return FAIL;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2522 // 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
2523 *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
2524 *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
2525
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2526 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
2527 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
2528 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 }
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 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 finish_write_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2534 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 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
2536 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
2537 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2538 # ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539 // 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
2540 may_set_selection();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 // ':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
2544 if (name != '"')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545 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
2546 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
2547 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2548
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 * 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
2551 * "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
2552 * 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
2553 * 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
2554 * 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
2555 * 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
2556 * 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
2557 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 write_reg_contents(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 char_u *str,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2562 int maxlen,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2563 int must_append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2564 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 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
2566 }
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 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 write_reg_contents_lst(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 char_u **strings,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572 int maxlen UNUSED,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 int must_append,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 int yank_type,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2575 long block_len)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577 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
2578
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 if (name == '/' || name == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581 char_u *s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 if (strings[0] == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584 s = (char_u *)"";
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 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
2586 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 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
2588 "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
2589 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 s = strings[0];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 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
2594 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 }
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 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
2598 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2600 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
2601 &yank_type) == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2603
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2604 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
2605
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 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
2607 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2608
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610 write_reg_contents_ex(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 char_u *str,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 int maxlen,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614 int must_append,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 int yank_type,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616 long block_len)
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 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
2619 long len;
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 if (maxlen >= 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 len = maxlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2623 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624 len = (long)STRLEN(str);
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 // Special case: '/' search pattern
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 if (name == '/')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2628 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2629 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
2630 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2631 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2632
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2633 if (name == '#')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2634 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2635 buf_T *buf;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2636
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2637 if (VIM_ISDIGIT(*str))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2639 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
2640
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2641 buf = buflist_findnr(num);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2642 if (buf == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2643 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
2644 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2645 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646 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
2647 TRUE, FALSE, FALSE));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648 if (buf == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2649 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2650 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
2651 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2653
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2654 if (name == '=')
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 char_u *p, *s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2657
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2658 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
2659 if (p == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2660 return;
18838
8dabdfc7c799 patch 8.1.2406: leaking memory in test_paste and test_registers
Bram Moolenaar <Bram@vim.org>
parents: 18771
diff changeset
2661 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
2662 {
18838
8dabdfc7c799 patch 8.1.2406: leaking memory in test_paste and test_registers
Bram Moolenaar <Bram@vim.org>
parents: 18771
diff changeset
2663 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
2664 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2665 p = s;
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 set_expr_line(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2668 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2669 }
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 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
2672 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2673
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2674 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
2675 &yank_type) == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2676 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2677
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2678 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
2679
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2680 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
2681 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2682 #endif // FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2683
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2684 #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
2685 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686 * 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
2687 * is appended.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2688 */
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 19524
diff changeset
2689 void
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 str_to_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2691 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
2692 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
2693 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
2694 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
2695 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
2696 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
2697 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698 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
2699 int lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 long start;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2701 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2702 int extra;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2703 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
2704 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
2705 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
2706 char_u *s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2707 char_u **ss;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2708 char_u **pp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2709 long maxlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2710
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2711 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
2712 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
2713
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2714 if (yank_type == MAUTO)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 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
2716 || str[len - 1] == CAR)))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717 ? MLINE : MCHAR);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2718 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2719 type = yank_type;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 // 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
2722 newlines = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2723 if (str_list)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 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
2726 ++newlines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2727 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2728 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2729 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2730 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
2731 if (str[i] == '\n')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 ++newlines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733 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
2734 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 extraline = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 ++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
2737 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2738 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
2739 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740 append = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2741 --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
2742 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2744
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2745 // 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
2746 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
2747 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748 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
2749 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2750 }
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 // 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
2753 // 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
2754 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
2755 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
2756 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2757 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
2758 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
2759 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
2760 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
2761 maxlen = 0;
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 // 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
2764 if (str_list)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766 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
2767 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 i = (long)STRLEN(*ss);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769 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
2770 if (i > maxlen)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2771 maxlen = i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2772 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2773 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2774 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2776 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
2777 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778 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
2779 if (str[i] == '\n')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781 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
2782 if (i > maxlen)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 maxlen = i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2784 if (append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 --lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787 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
2788 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2789 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2790 extra = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2791 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
2792 if (s == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2793 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2794 if (extra)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2795 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
2796 if (append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 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
2798 if (i)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2799 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
2800 extra += i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 s[extra] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802 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
2803 while (--extra >= 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2804 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2805 if (*s == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 *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
2807 ++s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2809 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
2810 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2811 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 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
2813 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
2814 if (type == MBLOCK)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 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
2816 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 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
2818 # ifdef FEAT_VIMINFO
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 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
2820 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 #endif // FEAT_CLIPBOARD || FEAT_EVAL || PROTO