annotate src/register.c @ 18478:94223687df0e

Added tag v8.1.2233 for changeset e93cab5d0f0f27fad7882f1f412927df055b090d
author Bram Moolenaar <Bram@vim.org>
date Tue, 29 Oct 2019 04:30:05 +0100
parents b912277e3877
children 9e6d5a4abb1c
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 void free_yank_all(void);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 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
37 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 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
39 static void may_set_selection(void);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 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
42 #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
43 static void str_to_reg(yankreg_T *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 #endif
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 yankreg_T *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 get_y_regs(void)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 return y_regs;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 yankreg_T *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 get_y_current(void)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 return y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 }
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 yankreg_T *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 get_y_previous(void)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 return y_previous;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 }
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 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 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
66 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 y_previous = yreg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 #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
71 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 * 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
73 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 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
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 * 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
78 * 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
79 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 get_expr_register(void)
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 char_u *new_line;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 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
86 if (new_line == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 return NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 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
89 vim_free(new_line);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 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
92 return '=';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 * 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
97 * 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
98 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 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
101 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 vim_free(expr_line);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 expr_line = new_line;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 }
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 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 * 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
108 * 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
109 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 char_u *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 get_expr_line(void)
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 char_u *expr_copy;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 char_u *rv;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 static int nested = 0;
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 if (expr_line == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 return NULL;
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 // 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
121 // changed.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 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
123 if (expr_copy == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 // 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
127 // 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
128 if (nested >= 10)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 return expr_copy;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 ++nested;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 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
133 --nested;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 vim_free(expr_copy);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 return rv;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 }
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 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 * 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
140 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 static char_u *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 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
143 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 if (expr_line == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 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
147 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 #endif // FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149
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 * 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
152 * 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
153 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 valid_yank_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 int regname,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 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
158 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159 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
160 || (!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
161 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 "/.%:="
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 #else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 "/.%:"
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 , regname) != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 || regname == '#'
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 || regname == '"'
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 || regname == '-'
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 || regname == '_'
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 || regname == '*'
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 || regname == '+'
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 #ifdef FEAT_DND
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 || (!writing && regname == '~')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 )
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 return FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 * 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
185 * Cannot handle the '_' register.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 * 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
187 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 * 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
189 * 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
190 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 * 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
192 * clipboard).
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 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
196 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 int i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 int ret = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 y_append = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 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
202 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
203 y_current = y_previous;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 return ret;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 i = regname;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 if (VIM_ISDIGIT(i))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 i -= '0';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 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
210 i = CharOrdLow(i) + 10;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 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
212 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213 i = CharOrdUp(i) + 10;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 y_append = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 else if (regname == '-')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 i = DELETION_REGISTER;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 // 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
220 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
221 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 i = STAR_REGISTER;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 ret = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 // 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
226 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
227 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 i = PLUS_REGISTER;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 ret = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 #ifdef FEAT_DND
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 else if (!writing && regname == '~')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 i = TILDE_REGISTER;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236 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
237 i = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 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
239 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
240 y_previous = y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 return ret;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 * When "regname" is a clipboard register, obtain the selection. If it's not
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 * available return zero, otherwise return "regname".
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 may_get_selection(int regname)
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 if (regname == '*')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 if (!clip_star.available)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 regname = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 clip_get_selection(&clip_star);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 else if (regname == '+')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 if (!clip_plus.available)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 regname = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264 clip_get_selection(&clip_plus);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 return regname;
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 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 * 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
272 * 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
273 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 void *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 get_register(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 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
278 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 yankreg_T *reg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 int i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 // 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
284 // selection too.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 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
286 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 if (clip_isautosel_star())
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 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
289 may_get_selection(name);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 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
292 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 if (clip_isautosel_plus())
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 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
295 may_get_selection(name);
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 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 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
300 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
301 if (reg != NULL)
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 *reg = *y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 if (copy)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 // 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
307 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
308 reg->y_array = NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 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
311 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
312 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 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
314 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
315 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 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
319 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 return (void *)reg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 * 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
325 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 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
328 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 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
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 *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
332 vim_free(reg);
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 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 // 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
336 may_set_selection();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337 #endif
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 #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
341 || defined(PROTO)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 free_register(void *reg)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 yankreg_T tmp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 tmp = *y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 *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
349 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 vim_free(reg);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 *y_current = tmp;
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 #endif
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 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 * 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
357 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359 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
360 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 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
362 return FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 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
364 return FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 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
366 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
367 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368
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 * 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
371 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 * 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
373 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 do_record(int c)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 static int regname;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 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
380 int retval;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 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
383 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 // 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
385 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
386 retval = FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 reg_recording = c;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 showmode();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 regname = c;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 retval = OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 else // stop recording
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 // 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
398 // 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
399 // 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
400 reg_recording = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 msg("");
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 p = get_recorded();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 if (p == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 retval = FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 // 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
408 vim_unescape_csi(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 // 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
411 // 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
412 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
413 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
414
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 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
416
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 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
418 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
419 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 return retval;
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
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 * 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
426 * 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
427 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 * 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
429 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 static int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 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
432 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 char_u *lp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 char_u **pp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 // 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
437 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
438 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 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
443 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 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
448 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
449 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 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
451 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
452 if (lp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 STRCPY(lp, *pp);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 STRCAT(lp, p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 vim_free(*pp);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 *pp = lp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 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
467 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471 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
472 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
473 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
474 #ifdef FEAT_VIMINFO
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 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
476 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 }
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 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
482
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 get_execreg_lastc(void)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 return execreg_lastc;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 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
491 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 execreg_lastc = lastc;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494
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 * 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
497 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 * 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
499 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 do_execreg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 int regname,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 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
504 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
505 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
506 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 int retval = OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 int remap;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 // repeat previous one
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 if (regname == '@')
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 if (execreg_lastc == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 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
518 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520 regname = execreg_lastc;
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 // check for valid regname
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 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
524 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 emsg_invreg(regname);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 execreg_lastc = regname;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 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
532 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 // 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
535 if (regname == '_')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 return OK;
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 // use last command line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 if (regname == ':')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541 if (last_cmdline == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 emsg(_(e_nolastcmd));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 // 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
547 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
548 // 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
549 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
550 (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
551 "\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
552 "\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
553 "\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
554 Ctrl_V, FALSE);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 if (p != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 // 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
558 // 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
559 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
560 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
561 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 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
563 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 else if (regname == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 p = get_expr_line();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 if (p == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 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
573 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 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
577 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 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
579 if (p == NULL)
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 emsg(_(e_noinstext));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 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
585 vim_free(p);
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 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
590 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
591 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 // Disallow remaping for ":@r".
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 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
595
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596 // 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
597 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
598 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
599 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 char_u *escaped;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 // 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
603 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
604 || addcr)
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 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
607 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 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
610 if (escaped == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 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
613 vim_free(escaped);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 if (retval == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 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
617 == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 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
621 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 return retval;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 }
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 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 * 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
627 * 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
628 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 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
631 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 char_u buf[3];
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 if (restart_edit != NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 if (restart_edit == 'V')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 buf[0] = 'g';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 buf[1] = 'R';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 buf[2] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 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
645 buf[1] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 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
648 restart_edit = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651
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 * 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
654 * executed again.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 * 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
656 * no remapping.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 static int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 put_in_typebuf(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 char_u *s,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 int esc,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 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
663 int silent)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 int retval = OK;
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 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
668 if (colon)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 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
670 if (retval == OK)
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 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 if (esc)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 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
676 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 p = s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 if (p == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 retval = FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 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
682 0, TRUE, silent);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 if (esc)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 if (colon && retval == OK)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 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
688 return retval;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 * 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
693 * 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
694 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 * 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
696 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 insert_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 int regname,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 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
701 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 int retval = OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 char_u *arg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 int allocated;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 int literally = literally_arg;
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 // 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
709 // 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
710 // 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
711 ui_breakcheck();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 if (got_int)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 // check for valid regname
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 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
717 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720 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
721 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 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
724 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
725 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
726 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 if (arg == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 stuffescaped(arg, literally);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 if (allocated)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 vim_free(arg);
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 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
734 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 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
736 literally = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 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
738 retval = FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 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
742 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 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
744 // 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
745 // y_type is MLINE.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 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
747 stuffcharReadbuff('\n');
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 return retval;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 * 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
757 * value in "argp".
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 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 get_spec_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 int regname,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 char_u **argp,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 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
764 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
765 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 int cnt;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 *argp = NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 *allocated = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770 switch (regname)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 case '%': // file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 if (errmsg)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 *argp = curbuf->b_fname;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 case '#': // alternate file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 *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
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 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 case '=': // result of expression
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 *argp = get_expr_line();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 *allocated = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 #endif
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 case ':': // last command line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 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
791 emsg(_(e_nolastcmd));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 *argp = last_cmdline;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 case '/': // last search-pattern
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 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
797 emsg(_(e_noprevre));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 *argp = last_search_pat();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 case '.': // last inserted text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 *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
803 *allocated = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 if (*argp == NULL && errmsg)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 emsg(_(e_noinstext));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 #ifdef FEAT_SEARCHPATH
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 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
810 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
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 *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
814 | (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
815 *allocated = TRUE;
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 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 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
820 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
821 if (!errmsg)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 return FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 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
824 ? (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
825 *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
826 *allocated = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 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
830 if (!errmsg)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 return FALSE;
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 *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
834 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
835 return TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 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
838 *argp = (char_u *)"";
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 return TRUE;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 return FALSE;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 * 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
847 * 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
848 * 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
849 * 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
850 * 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
851 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 * 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
853 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 cmdline_paste_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 int regname,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 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
858 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
859 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 int literally = literally_arg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 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
864 literally = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 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
866 return FAIL;
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 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
869 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 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
871
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 // 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
873 // 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
874 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
875 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
876
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 // 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
878 // lines and gets bored.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 ui_breakcheck();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 if (got_int)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 return OK;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 * Adjust the register name pointed to with "rp" for the clipboard being
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 * used always and the clipboard being available.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 adjust_clip_reg(int *rp)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 // If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard',
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 // use '*' or '+' reg, respectively. "unnamedplus" prevails.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 if (clip_unnamed != 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available)
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 ? '+' : '*';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 if (!clip_star.available && *rp == '*')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 *rp = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 if (!clip_plus.available && *rp == '+')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 *rp = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911
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 * 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
914 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 shift_delete_registers()
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 int n;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 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
921 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
922 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
923 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
924 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
925 if (!y_append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 y_previous = y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 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
928 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 #if defined(FEAT_EVAL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932 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
933 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 static int recursive = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 dict_T *v_event;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 list_T *list;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 int n;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 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
939 long reglen = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 if (recursive)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 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
945
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 list = list_alloc();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 if (list == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 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
950 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
951 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
952 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
953
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 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
955 buf[1] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 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
957
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 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
959 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
960 buf[2] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 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
962
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 buf[0] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 buf[1] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 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
966 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 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
968 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
969 case MBLOCK:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 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
971 reglen + 1);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 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
975
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 // 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
977 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
978
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 recursive = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 textlock++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982 textlock--;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 recursive = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 // 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
986 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
987 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
988 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 #endif
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 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 * 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
993 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 init_yank(void)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 int i;
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 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
1000 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
1001 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 #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
1004 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 clear_registers(void)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 int i;
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 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
1010 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 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
1012 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
1013 free_yank_all();
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 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 * 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
1020 * 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
1021 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 free_yank(long n)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 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
1026 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 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
1030 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 #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
1032 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
1033 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 // 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
1035 // 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
1036 ++no_wait_return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 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
1038 --no_wait_return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 msg_didout = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 msg_col = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 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
1044 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 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
1046 #ifdef AMIGA
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 if (n >= 1000)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 msg("");
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 }
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 free_yank_all(void)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 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
1057 }
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 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 * 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
1061 * 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
1062 * 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
1063 * 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
1064 *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 * 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
1066 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 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
1069 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 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
1071 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
1072 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
1073 char_u **new_ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 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
1075 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 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
1077 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
1078 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
1079 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 char_u *pnew;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 struct block_def bd;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 #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
1083 int did_star = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 // 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
1087 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
1088 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 beep_flush();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 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
1093 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 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
1097 oap->regname = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 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
1099 oap->regname = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 #endif
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 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
1103 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
1104
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 curr = y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 // append to existing contents
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 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
1108 y_current = &newreg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 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
1111
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 // 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
1113 // 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
1114 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
1115 && oap->start.col == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 && !oap->inclusive
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 && (!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
1118 && !oap->block_mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 && oap->end.col == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 && yanklines > 1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 yanktype = MLINE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 --yankendlnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 --yanklines;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 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
1128 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
1129 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
1130 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
1131 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
1132 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 y_current = curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 return FAIL;
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 #ifdef FEAT_VIMINFO
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 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
1138 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 y_idx = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 lnum = oap->start.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 if (oap->block_mode)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 // Visual block mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 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
1147 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
1148
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 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
1150 y_current->y_width--;
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 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
1154 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 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
1156 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 case MBLOCK:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 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
1159 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
1160 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 case MLINE:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 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
1165 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
1166 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 case MCHAR:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 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
1172 int is_oneChar = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 colnr_T cs, ce;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 p = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 bd.startspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 bd.endspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 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
1180 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 startcol = oap->start.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 if (virtual_op)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 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
1185 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
1186 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 // 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
1188 // double-count it.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 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
1190 - oap->start.coladd;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 startcol++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 if (lnum == oap->end.lnum)
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 endcol = oap->end.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 if (virtual_op)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 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
1202 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
1203 // 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
1204 // 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
1205 // of multi-byte char.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 && (*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
1207 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 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
1209 && 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
1210 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 // 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
1212 is_oneChar = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 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
1214 - 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
1215 endcol = startcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 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
1220 + oap->inclusive;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 endcol -= oap->inclusive;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 }
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 if (endcol == MAXCOL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 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
1228 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
1229 bd.textlen = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 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
1232 bd.textstart = p + startcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 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
1234 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 // NOTREACHED
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 }
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 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
1242 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 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
1244 if (new_ptr == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 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
1247 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
1248 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
1249 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
1250 #ifdef FEAT_VIMINFO
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 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
1252 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 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
1255 curr->y_type = MLINE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 // 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
1258 // 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
1259 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
1260 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 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
1262 + 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
1263 if (pnew == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 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
1266 goto fail;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 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
1269 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
1270 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
1271 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
1272 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
1273 y_idx = 1;
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 y_idx = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 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
1278 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
1279 curr->y_size = j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 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
1281 y_current = curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 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
1284 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
1285 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
1286 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 if (yanktype == MCHAR
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 && !oap->block_mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 && yanklines == 1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 yanklines = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 // Some versions of Vi use ">=" here, some don't...
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 if (yanklines > p_report)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 char namebuf[100];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 if (oap->regname == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 *namebuf = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 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
1300 _(" into \"%c"), oap->regname);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 // 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
1303 update_topline_redraw();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 if (oap->block_mode)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 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
1307 "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
1308 yanklines, namebuf);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 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
1313 "%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
1314 yanklines, namebuf);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 }
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 // Set "'[" and "']" marks.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 curbuf->b_op_start = oap->start;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 curbuf->b_op_end = oap->end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 if (yanktype == MLINE && !oap->block_mode)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 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
1325 curbuf->b_op_end.col = MAXCOL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 // 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
1330 // 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
1331 // to the '*' register.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 if (clip_star.available
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 && (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
1334 || (!deleting && oap->regname == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 && ((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
1336 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 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
1338 // 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
1339 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
1340
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 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
1342 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
1343 # ifdef FEAT_X11
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 did_star = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 # endif
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 # ifdef FEAT_X11
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 // 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
1350 // 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
1351 if (clip_plus.available
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 && (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
1353 || (!deleting && oap->regname == 0
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 && ((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
1355 CLIP_UNNAMED_PLUS))))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 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
1358 // 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
1359 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
1360
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 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
1362 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
1363 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
1364 && !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
1365 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 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
1367 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
1368 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
1369 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 #if defined(FEAT_EVAL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 if (!deleting && has_textyankpost())
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376 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
1377 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 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
1382 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
1383 y_current = curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 }
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 static int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 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
1389 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 char_u *pnew;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 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
1393 == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 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
1396 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
1397 pnew += bd->startspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 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
1399 pnew += bd->textlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 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
1401 pnew += bd->endspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 *pnew = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 * 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
1409 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 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
1412 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 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
1414 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416 y_current = reg;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 *y_current = *curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 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
1420 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
1421 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
1422 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
1423 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 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
1425 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
1426 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 free_yank(j);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 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
1429 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 y_current = curr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 * 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
1437 * 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
1438 * "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
1439 * 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
1440 * 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
1441 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 do_put(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 int regname,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 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
1446 long count,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 int flags)
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 char_u *ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 char_u *newp, *oldp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 int yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 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
1453 linenr_T lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 colnr_T col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 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
1456 int y_type;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 long y_size;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 int oldlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 long y_width = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460 colnr_T vcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 int delcount;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 int incr = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464 struct block_def bd;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 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
1466 long nr_lines = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 pos_T new_cursor;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 int indent;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 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
1470 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
1471 int first_indent = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 int lendiff = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 pos_T old_pos;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 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
1475 int allocated = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 long cnt;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 // 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
1480 adjust_clip_reg(&regname);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 (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
1482 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 if (flags & PUT_FIXINDENT)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 orig_indent = get_indent();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 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
1488 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
1489
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 // 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
1491 // special characters (newlines, etc.).
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 if (regname == '.')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 if (VIsual_active)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 stuffcharReadbuff(VIsual_mode);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 (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
1497 (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
1498 // 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
1499 // 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
1500 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
1501 stuffcharReadbuff('l');
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 // 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
1506 // ':' (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
1507 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
1508 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 if (insert_string == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 return;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 // 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
1514 // 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
1515 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
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 if (insert_string != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 y_type = MCHAR;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 if (regname == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 // 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
1525 // characters.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 // 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
1527 for (;;)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 y_size = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 ptr = insert_string;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 while (ptr != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533 if (y_array != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 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
1535 ++y_size;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 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
1537 if (ptr != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 if (y_array != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 *ptr = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 ++ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 // 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
1543 if (*ptr == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 y_type = MLINE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 if (y_array != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 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
1553 if (y_array == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 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
1561 y_array = &insert_string;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 else
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 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
1567
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568 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
1569 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
1570 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
1571 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
1572 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 if (y_type == MLINE)
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_SPLIT)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 // "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
1581 // between.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 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
1583 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 p = ml_get_cursor();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 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
1586 MB_PTR_ADV(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 ptr = vim_strsave(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 if (ptr == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 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
1591 vim_free(ptr);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 oldp = ml_get_curline();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 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
1595 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
1596 MB_PTR_ADV(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 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
1598 if (ptr == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 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
1601 ++nr_lines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 dir = FORWARD;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 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
1605 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 // 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
1607 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
1608 dir = FORWARD;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 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
1611 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
1612 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614 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
1615 y_type = MLINE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 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
1618 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619 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
1620 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
1621 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 }
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 (y_type == MBLOCK)
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 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
1627 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
1628 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
1629 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
1630 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 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
1633 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 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
1635 #ifdef FEAT_FOLDING
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 // 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
1637 // u_save() uses it.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 if (dir == BACKWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639 (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
1640 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 (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
1642 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 if (dir == FORWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 ++lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 // 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
1646 // 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
1647 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
1648 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 #ifdef FEAT_FOLDING
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 if (dir == FORWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 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
1652 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 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
1654 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
1655 #endif
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 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
1658 goto end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 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
1661
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 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
1663 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 if (gchar_cursor() == TAB)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 // 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
1667 // tab or "P" on the first position.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 #ifdef FEAT_VARTABS
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 int viscol = getviscol();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 if (dir == FORWARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 ? tabstop_padding(viscol, curbuf->b_p_ts,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 curbuf->b_p_vts_array) != 1
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 : 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
1674 coladvance_force(viscol);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 #else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 if (dir == FORWARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 : 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
1679 coladvance_force(getviscol());
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 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
1683 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 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
1685 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
1686 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 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
1689 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
1690
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691 // Block mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 if (y_type == MBLOCK)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 int c = gchar_cursor();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 colnr_T endcol2 = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 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
1698 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 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
1700 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
1701 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 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
1703
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 if (has_mbyte)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 // 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
1706 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
1707 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 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
1709 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 ++col;
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 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
1714
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 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
1716 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
1717 && (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
1718 || 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
1719 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 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
1721 ++col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 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
1723 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 if (c == TAB)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 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
1727 curwin->w_cursor.col--;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 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
1729 curwin->w_cursor.col++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 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
1733 bd.textcol = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734 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
1735 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 int spaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 char shortline;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 bd.startspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 bd.endspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 vcol = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 delcount = 0;
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 // add a new line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 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
1746 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 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
1748 (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
1749 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 ++nr_lines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 // 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
1753 oldp = ml_get_curline();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 oldlen = (int)STRLEN(oldp);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 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
1756 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 // 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
1758 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
1759 vcol += incr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 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
1762
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 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
1764
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 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
1766 bd.startspaces = col - vcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 else if (vcol > col)
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 bd.endspaces = vcol - col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 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
1771 --bd.textcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 delcount = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 if (has_mbyte)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774 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
1775 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
1776 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 // 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
1778 // 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
1779 // block, causing misalignment.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 delcount = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781 bd.endspaces = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 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
1786
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787 // 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
1788 spaces = y_width + 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 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
1790 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
1791 if (spaces < 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 spaces = 0;
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 // insert the new text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 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
1796 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
1797 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 // 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
1800 ptr = newp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 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
1802 ptr += bd.textcol;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 // 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
1804 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
1805 ptr += bd.startspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 // insert the new text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 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
1808 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 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
1810 ptr += yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 // 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
1813 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
1814 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 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
1816 ptr += spaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 }
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 // 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
1820 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
1821 ptr += bd.endspaces;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 // 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
1823 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
1824 (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
1825 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
1826
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 ++curwin->w_cursor.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 if (i == 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 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
1830 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 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
1833
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 // Set '[ mark.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 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
1836 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
1837
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 // adjust '] mark
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 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
1840 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
1841 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
1842 if (flags & PUT_CURSEND)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 colnr_T len;
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 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
1847 curwin->w_cursor.col++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 // 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
1850 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
1851 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
1852 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
1853 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 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
1856 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 // Character or Line mode
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 if (y_type == MCHAR)
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 // 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
1863 // char
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 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
1865 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 if (has_mbyte)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 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
1869
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 // 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
1871 col += bytelen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 if (yanklen)
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 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
1875 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
1876 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 ++col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 if (yanklen)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 ++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
1885 }
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 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
1889 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 // 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
1891 else if (dir == BACKWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 --lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 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
1894
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 // 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
1896 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
1897 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 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
1899
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 if (VIsual_active)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 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
1903 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
1904 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
1905 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 do {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 totlen = count * yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 if (totlen > 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 oldp = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 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
1913 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 lnum++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 continue;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 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
1918 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 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
1920 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
1921 ptr = newp + col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 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
1923 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 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
1925 ptr += yanklen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 STRMOVE(ptr, oldp + col);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 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
1929 // 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
1930 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
1931 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 // 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
1933 changed_cline_bef_curs();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934 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
1935 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 if (VIsual_active)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 lnum++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 } 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
1940
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 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
1942 lnum--;
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 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
1945 // 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
1946 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
1947 ++curwin->w_cursor.col;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 changed_bytes(lnum, col);
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 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 // 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
1953 // line in two.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 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
1955 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 i = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 if (y_type == MCHAR)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959 // 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
1960 // 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
1961 // 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
1962 lnum = new_cursor.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 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
1964 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
1965 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
1966 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 goto error;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 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
1969 STRCAT(newp, ptr);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 // insert second line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 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
1972 vim_free(newp);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 oldp = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 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
1976 if (newp == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 goto error;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 // 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
1979 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
1980 // append to first line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 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
1982 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
1983
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 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
1985 i = 1;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 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
1989 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 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
1991 && 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
1992 == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 goto error;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 lnum++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 ++nr_lines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 if (flags & PUT_FIXINDENT)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 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
1999 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
2000 ptr = ml_get(lnum);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 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
2002 lendiff = (int)STRLEN(ptr);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 #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
2004 if (*ptr == '#' && preprocs_left())
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 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
2006 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 if (*ptr == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 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
2010 else if (first_indent)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 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
2013 indent = orig_indent;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 first_indent = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 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
2017 indent = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 (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
2019 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
2020 // 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
2021 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
2022 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
2023 }
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 error:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 // Adjust marks.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 if (y_type == MLINE)
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 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
2032 if (dir == FORWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2033 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
2034 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 // 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
2036 // 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
2037 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
2038 < 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
2039 #ifdef FEAT_DIFF
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 || curwin->w_p_diff
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 )
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 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
2044 (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
2045
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 // 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
2047 if (y_type == MCHAR)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 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
2049 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
2050 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 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
2052 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
2053
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2054 // 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
2055 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
2056 // 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
2057 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
2058 if (col > 1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 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
2060 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 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
2062
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 if (flags & PUT_CURSLINE)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2065 // ":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
2066 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
2067 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
2068 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 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
2070 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071 // 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
2072 if (y_type == MLINE)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 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
2075 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
2076 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 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
2078 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
2079 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 else
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 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
2083 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
2084 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 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
2087 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088 // 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
2089 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
2090 if (dir == FORWARD)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 ++curwin->w_cursor.lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 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
2093 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 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
2095 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
2096 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 }
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 msgmore(nr_lines);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 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
2101
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 end:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 if (allocated)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 vim_free(insert_string);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 if (regname == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 vim_free(y_array);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 VIsual_active = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 // 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
2111 adjust_cursor_eol();
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 * 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
2116 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 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
2119 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 if (num == -1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 return '"';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 else if (num < 10)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123 return num + '0';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 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
2125 return '-';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 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
2128 return '*';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 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
2130 return '+';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 #ifdef EBCDIC
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135 int i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 // EBCDIC is really braindead ...
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 i = 'a' + (num - 10);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 if (i > 'i')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 i += 7;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 if (i > 'r')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 i += 8;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 return i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 #else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 return num + 'a' - 10;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 #endif
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 * ":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
2152 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 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
2155 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 int i, n;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 long j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 yankreg_T *yb;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 int name;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 int attr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 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
2163 int clen;
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2164 int type;
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 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
2167 arg = NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 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
2169
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 // 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
2171 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
2172 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
2173 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 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
2175 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
2176 {
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2177 case MLINE: type = 'l'; break;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2178 case MCHAR: type = 'c'; break;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2179 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
2180 }
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 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
2182 #ifdef ONE_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 // 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
2184 && (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
2185 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 )
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 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
2188
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 #ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 // 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
2191 // 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
2192 // of the clipboard.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 adjust_clip_reg(&name);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 (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
2195 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 if (i == -1)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 if (y_previous != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 yb = y_previous;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202 yb = &(y_regs[0]);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205 yb = &(y_regs[i]);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 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
2209 || (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
2210 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
2211 // pointer can be freed
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 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
2215 {
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2216 int do_show = FALSE;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2217
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2218 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
2219 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
2220
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2221 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
2222 {
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2223 msg_putchar('\n');
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2224 msg_puts(" ");
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2225 msg_putchar(type);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2226 msg_puts(" ");
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2227 msg_putchar('"');
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2228 msg_putchar(name);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2229 msg_puts(" ");
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2230
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2231 n = (int)Columns - 11;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2232 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
2233 {
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2234 if (j)
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2235 {
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2236 msg_puts_attr("^J", attr);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2237 n -= 2;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2238 }
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2239 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
2240 ++p)
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2241 {
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2242 clen = (*mb_ptr2len)(p);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2243 msg_outtrans_len(p, clen);
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2244 p += clen - 1;
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2245 }
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2246 }
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2247 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
2248 msg_puts_attr("^J", attr);
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2249 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
2250 }
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2251 ui_breakcheck();
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2252 }
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 last inserted text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2256 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
2257 && (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
2258 && !message_filtered(p))
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2259 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2260 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
2261 dis_msg(p, TRUE);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2262 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2263
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2264 // display last command line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2265 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
2266 && !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
2267 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2268 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
2269 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
2270 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2271
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2272 // display current file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2273 if (curbuf->b_fname != NULL
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2274 && (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
2275 && !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
2276 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2277 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
2278 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
2279 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2280
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2281 // display alternate file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2282 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
2283 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2284 char_u *fname;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2285 linenr_T dummy;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2286
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2287 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
2288 && !message_filtered(fname))
18164
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2289 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2290 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
2291 dis_msg(fname, FALSE);
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 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2294
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2295 // display last search pattern
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2296 if (last_search_pat() != NULL
18454
b912277e3877 patch 8.1.2221: cannot filter :disp output
Bram Moolenaar <Bram@vim.org>
parents: 18436
diff changeset
2297 && (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
2298 && !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
2299 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2300 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
2301 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
2302 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2303
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2304 #ifdef FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2305 // display last used expression
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2306 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
2307 && !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
2308 {
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2309 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
2310 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
2311 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2312 #endif
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
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 * 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
2317 * 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
2318 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2319 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2320 dis_msg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2321 char_u *p,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2322 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
2323 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2324 int n;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2325 int l;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2326
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2327 n = (int)Columns - 6;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2328 while (*p != NUL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2329 && !(*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
2330 && (n -= ptr2cells(p)) >= 0)
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 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
2333 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2334 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
2335 p += l;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2336 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2337 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2338 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
2339 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2340 ui_breakcheck();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2341 }
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 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2344 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2345 clip_free_selection(Clipboard_T *cbd)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2346 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2347 yankreg_T *y_ptr = y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2348
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2349 if (cbd == &clip_plus)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2350 y_current = &y_regs[PLUS_REGISTER];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2351 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2352 y_current = &y_regs[STAR_REGISTER];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2353 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2354 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
2355 y_current = y_ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2356 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2357
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2358 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2359 * Get the selected text and put it in register '*' or '+'.
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 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2362 clip_get_selection(Clipboard_T *cbd)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2363 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2364 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
2365 pos_T old_cursor;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2366 pos_T old_visual;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2367 int old_visual_mode;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2368 colnr_T old_curswant;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2369 int old_set_curswant;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2370 pos_T old_op_start, old_op_end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2371 oparg_T oa;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2372 cmdarg_T ca;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2373
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2374 if (cbd->owned)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2375 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2376 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2377 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2378 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2379
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2380 // Get the text between clip_star.start & clip_star.end
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2381 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
2382 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
2383 old_cursor = curwin->w_cursor;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2384 old_curswant = curwin->w_curswant;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2385 old_set_curswant = curwin->w_set_curswant;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2386 old_op_start = curbuf->b_op_start;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2387 old_op_end = curbuf->b_op_end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2388 old_visual = VIsual;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2389 old_visual_mode = VIsual_mode;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2390 clear_oparg(&oa);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2391 oa.regname = (cbd == &clip_plus ? '+' : '*');
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2392 oa.op_type = OP_YANK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2393 vim_memset(&ca, 0, sizeof(ca));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2394 ca.oap = &oa;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2395 ca.cmdchar = 'y';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2396 ca.count1 = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2397 ca.retval = CA_NO_ADJ_OP_END;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2398 do_pending_operator(&ca, 0, TRUE);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2399 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
2400 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
2401 curwin->w_cursor = old_cursor;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2402 changed_cline_bef_curs(); // need to update w_virtcol et al
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2403 curwin->w_curswant = old_curswant;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2404 curwin->w_set_curswant = old_set_curswant;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2405 curbuf->b_op_start = old_op_start;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2406 curbuf->b_op_end = old_op_end;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2407 VIsual = old_visual;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2408 VIsual_mode = old_visual_mode;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2409 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2410 else if (!is_clipboard_needs_update())
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2411 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 clip_free_selection(cbd);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 // Try to get selected text from another window
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 clip_gen_request_selection(cbd);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 }
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2419 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2420 * Convert from the GUI selection string into the '*'/'+' register.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2421 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2422 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2423 clip_yank_selection(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 int type,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2425 char_u *str,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2426 long len,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 Clipboard_T *cbd)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 yankreg_T *y_ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 if (cbd == &clip_plus)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 y_ptr = &y_regs[PLUS_REGISTER];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 y_ptr = &y_regs[STAR_REGISTER];
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 clip_free_selection(cbd);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 str_to_reg(y_ptr, type, str, len, 0L, FALSE);
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 * Convert the '*'/'+' register into a GUI selection string returned in *str
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 * with length *len.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 * Returns the motion type, or -1 for failure.
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 int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 char_u *p;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2450 int lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2451 int i, j;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2452 int_u eolsize;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2453 yankreg_T *y_ptr;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2454
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2455 if (cbd == &clip_plus)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2456 y_ptr = &y_regs[PLUS_REGISTER];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2457 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2458 y_ptr = &y_regs[STAR_REGISTER];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2459
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2460 # ifdef USE_CRNL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2461 eolsize = 2;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2462 # else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2463 eolsize = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2464 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2465
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2466 *str = NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2467 *len = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2468 if (y_ptr->y_array == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2469 return -1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2470
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2471 for (i = 0; i < y_ptr->y_size; i++)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2472 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize;
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 // Don't want newline character at end of last line if we're in MCHAR mode.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 if (y_ptr->y_type == MCHAR && *len >= eolsize)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2476 *len -= eolsize;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2477
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2478 p = *str = alloc(*len + 1); // add one to avoid zero
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 if (p == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 return -1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481 lnum = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2482 for (i = 0, j = 0; i < (int)*len; i++, j++)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2483 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2484 if (y_ptr->y_array[lnum][j] == '\n')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2485 p[i] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2486 else if (y_ptr->y_array[lnum][j] == NUL)
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 # ifdef USE_CRNL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2489 p[i++] = '\r';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2490 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2491 p[i] = '\n';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2492 lnum++;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2493 j = -1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2494 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2495 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 p[i] = y_ptr->y_array[lnum][j];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2498 return y_ptr->y_type;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2499 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500
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 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 * If we have written to a clipboard register, send the text to the clipboard.
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 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2506 may_set_selection(void)
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 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2509 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510 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
2511 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
2512 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2515 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
2516 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
2517 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2518 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2519
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2520 #endif // FEAT_CLIPBOARD || PROTO
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2523 #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
2524 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2525 * 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
2526 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2527 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2528 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
2529 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 yankreg_T *curr;
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 curr = y_current;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2533 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
2534 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 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
2536 y_current = curr;
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 #endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2539
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2540
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2541 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2542 * 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
2543 * Used for getregtype()
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544 * Returns MAUTO for error.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2546 char_u
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2547 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
2548 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 switch (regname)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2550 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 case '%': // file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 case '#': // alternate file name
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2553 case '=': // expression
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 case ':': // last command line
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 case '/': // last search-pattern
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 case '.': // last inserted text
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 # ifdef FEAT_SEARCHPATH
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558 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
2559 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
2560 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2561 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
2562 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
2563 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
2564 return MCHAR;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2565 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2566
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 # ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568 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
2569 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 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
2572 return MAUTO;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2574 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
2575
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 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
2577 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 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
2579 *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
2580 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
2581 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 return MAUTO;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2583 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584
18436
6ec1bfb4690b patch 8.1.2212: cannot see the selection type in :reg output
Bram Moolenaar <Bram@vim.org>
parents: 18354
diff changeset
2585 #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
2586 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 * 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
2588 * Otherwise just return "s".
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 static char_u *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 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
2592 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 if (flags & GREG_LIST)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2594 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2595 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
2596
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 if (list != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2598 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2599 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
2600 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 list_free(list);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2602 return NULL;
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 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
2605 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2606 return (char_u *)list;
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 return s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2609 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2610
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2611 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2612 * Return the contents of a register as a single allocated string.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 * 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
2614 * Returns NULL for error.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 * Flags:
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616 * 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
2617 * 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
2618 * not the result of its evaluation.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619 * GREG_LIST Return a list of lines in place of a single string.
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 char_u *
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2622 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
2623 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 char_u *retval;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626 int allocated;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 long len;
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 // 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
2630 if (regname == '=')
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 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
2633 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2634 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
2635 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
2636 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
2637 }
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 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
2640 regname = '"';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2641
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2642 // check for valid regname
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2643 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
2644 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2645
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2646 # ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2647 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
2648 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2649
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2650 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
2651 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2652 if (retval == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2653 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2654 if (allocated)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2655 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
2656 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
2657 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2658
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2659 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
2660 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
2661 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2662
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2663 if (flags & GREG_LIST)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2664 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2665 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
2666 int error = FALSE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2667
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2668 if (list == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2669 return NULL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2670 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
2671 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
2672 error = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2673 if (error)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2674 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2675 list_free(list);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2676 return NULL;
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 return (char_u *)list;
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
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2681 // 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
2682 len = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2683 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
2684 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2685 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
2686 // 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
2687 // y_type is MLINE.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2688 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
2689 ++len;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2690 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2691
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2692 retval = alloc(len + 1);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2693
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2694 // 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
2695 if (retval != NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2696 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2697 len = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2698 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
2699 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2700 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
2701 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
2702
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2703 // 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
2704 // MLINE.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2705 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
2706 retval[len++] = '\n';
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2707 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2708 retval[len] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2709 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2710
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2711 return retval;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2712 }
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 static int
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 init_write_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2716 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717 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
2718 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
2719 int must_append,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 int *yank_type UNUSED)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2722 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
2723 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2724 emsg_invreg(name);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2725 return FAIL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2726 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2727
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2728 // 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
2729 *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
2730 *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
2731
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2732 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
2733 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
2734 free_yank_all();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2735 return OK;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2737
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2738 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 finish_write_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2741 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
2742 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
2743 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2744 # ifdef FEAT_CLIPBOARD
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2745 // 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
2746 may_set_selection();
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2747 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2749 // ':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
2750 if (name != '"')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2751 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
2752 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
2753 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2754
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2755 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2756 * 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
2757 * "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
2758 * 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
2759 * 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
2760 * 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
2761 * 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
2762 * 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
2763 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765 write_reg_contents(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2766 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2767 char_u *str,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2768 int maxlen,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2769 int must_append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2770 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2771 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
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 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2775 write_reg_contents_lst(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2776 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2777 char_u **strings,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2778 int maxlen UNUSED,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2779 int must_append,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2780 int yank_type,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2781 long block_len)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2782 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2783 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
2784
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2785 if (name == '/' || name == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2786 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2787 char_u *s;
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 if (strings[0] == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2790 s = (char_u *)"";
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2791 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
2792 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2793 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
2794 "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
2795 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2796 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2797 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2798 s = strings[0];
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2799 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
2800 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2802
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2803 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
2804 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2805
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2806 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
2807 &yank_type) == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2808 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2809
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2810 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
2811
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2812 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
2813 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2814
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2815 void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2816 write_reg_contents_ex(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2817 int name,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2818 char_u *str,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2819 int maxlen,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2820 int must_append,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2821 int yank_type,
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2822 long block_len)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2823 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2824 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
2825 long len;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2826
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2827 if (maxlen >= 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2828 len = maxlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2829 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2830 len = (long)STRLEN(str);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2831
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2832 // Special case: '/' search pattern
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2833 if (name == '/')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2834 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2835 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
2836 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2837 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2838
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2839 if (name == '#')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2840 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2841 buf_T *buf;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2842
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2843 if (VIM_ISDIGIT(*str))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2844 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2845 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
2846
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2847 buf = buflist_findnr(num);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2848 if (buf == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2849 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
2850 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2851 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2852 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
2853 TRUE, FALSE, FALSE));
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2854 if (buf == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2855 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2856 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
2857 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2858 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 if (name == '=')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2861 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2862 char_u *p, *s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2863
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 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
2865 if (p == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2867 if (must_append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2868 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 s = concat_str(get_expr_line_src(), p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 vim_free(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2871 p = s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2872 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2873 set_expr_line(p);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2874 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2875 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2876
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2877 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
2878 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2879
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2880 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
2881 &yank_type) == FAIL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2882 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2883
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2884 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
2885
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2886 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
2887 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2888 #endif // FEAT_EVAL
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2889
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890 #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
2891 /*
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 * 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
2893 * is appended.
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2894 */
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 static void
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2896 str_to_reg(
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897 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
2898 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
2899 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
2900 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
2901 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
2902 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
2903 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904 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
2905 int lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2906 long start;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907 long i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 int extra;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2909 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
2910 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
2911 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
2912 char_u *s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 char_u **ss;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 char_u **pp;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2915 long maxlen;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 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
2918 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
2919
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2920 if (yank_type == MAUTO)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 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
2922 || str[len - 1] == CAR)))
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923 ? MLINE : MCHAR);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2924 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2925 type = yank_type;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2926
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2927 // 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
2928 newlines = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2929 if (str_list)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2930 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2931 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
2932 ++newlines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2933 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2934 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2935 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2936 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
2937 if (str[i] == '\n')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2938 ++newlines;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2939 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
2940 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2941 extraline = 1;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2942 ++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
2943 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2944 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
2945 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2946 append = TRUE;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2947 --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
2948 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2949 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2950
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2951 // 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
2952 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
2953 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2954 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
2955 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2956 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2957
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2958 // 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
2959 // 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
2960 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
2961 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
2962 return;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2963 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
2964 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
2965 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
2966 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
2967 maxlen = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 // 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
2970 if (str_list)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2971 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972 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
2973 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 i = (long)STRLEN(*ss);
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2975 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
2976 if (i > maxlen)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 maxlen = i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2979 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2982 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
2983 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 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
2985 if (str[i] == '\n')
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 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
2988 if (i > maxlen)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989 maxlen = i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 if (append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2991 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2992 --lnum;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2993 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
2994 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2995 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2996 extra = 0;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2997 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
2998 if (s == NULL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2999 break;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3000 if (extra)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3001 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
3002 if (append)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 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
3004 if (i)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005 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
3006 extra += i;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3007 s[extra] = NUL;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3008 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
3009 while (--extra >= 0)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3010 {
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3011 if (*s == NUL)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3012 *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
3013 ++s;
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3014 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3015 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
3016 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3017 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3018 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
3019 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
3020 if (type == MBLOCK)
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3021 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
3022 else
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3023 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
3024 # ifdef FEAT_VIMINFO
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3025 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
3026 # endif
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3027 }
f57481564f2c patch 8.1.2077: the ops.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3028 #endif // FEAT_CLIPBOARD || FEAT_EVAL || PROTO