Mercurial > vim
annotate src/ops.c @ 18149:275fec3af04a
Added tag v8.1.2069 for changeset f7d9f8fe70be8a2c1d0262e0cb0606d95bb8588c
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Sep 2019 23:30:04 +0200 |
parents | df5778d73320 |
children | f57481564f2c |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9834
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ops.c: implementation of various operators: op_shift, op_delete, op_tilde, | |
12 * op_change, op_yank, do_put, do_join | |
13 */ | |
14 | |
15 #include "vim.h" | |
16 | |
17 /* | |
18 * Number of registers. | |
19 * 0 = unnamed register, for normal yanks and puts | |
20 * 1..9 = registers '1' to '9', for deletes | |
21 * 10..35 = registers 'a' to 'z' | |
22 * 36 = delete register '-' | |
23 * 37 = Selection register '*'. Only if FEAT_CLIPBOARD defined | |
24 * 38 = Clipboard register '+'. Only if FEAT_CLIPBOARD and FEAT_X11 defined | |
25 */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
26 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
27 static yankreg_T y_regs[NUM_REGISTERS]; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
28 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
29 static yankreg_T *y_current; /* ptr to current yankreg */ |
7 | 30 static int y_append; /* TRUE when appending */ |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
31 static yankreg_T *y_previous = NULL; /* ptr to last written yankreg */ |
7 | 32 |
33 /* | |
34 * structure used by block_prep, op_delete and op_yank for blockwise operators | |
35 * also op_change, op_shift, op_insert, op_replace - AKelly | |
36 */ | |
37 struct block_def | |
38 { | |
1839 | 39 int startspaces; /* 'extra' cols before first char */ |
40 int endspaces; /* 'extra' cols after last char */ | |
7 | 41 int textlen; /* chars in block */ |
1839 | 42 char_u *textstart; /* pointer to 1st char (partially) in block */ |
43 colnr_T textcol; /* index of chars (partially) in block */ | |
7 | 44 colnr_T start_vcol; /* start col of 1st char wholly inside block */ |
45 colnr_T end_vcol; /* start col of 1st char wholly after block */ | |
46 int is_short; /* TRUE if line is too short to fit in block */ | |
47 int is_MAX; /* TRUE if curswant==MAXCOL when starting */ | |
48 int is_oneChar; /* TRUE if block within one character */ | |
49 int pre_whitesp; /* screen cols of ws before block */ | |
50 int pre_whitesp_c; /* chars of ws before block */ | |
51 colnr_T end_char_vcols; /* number of vcols of post-block char */ | |
52 colnr_T start_char_vcols; /* number of vcols of pre-block char */ | |
53 }; | |
54 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
55 static void shift_block(oparg_T *oap, int amount); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
56 static int stuff_yank(int, char_u *); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
57 static void put_reedit_in_typebuf(int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
58 static int put_in_typebuf(char_u *s, int esc, int colon, |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
59 int silent); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
60 static void stuffescaped(char_u *arg, int literally); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
61 static void mb_adjust_opend(oparg_T *oap); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
62 static void free_yank_all(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
63 static int yank_copy_line(struct block_def *bd, long y_idx); |
7 | 64 #ifdef FEAT_CLIPBOARD |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
65 static void copy_yank_reg(yankreg_T *reg); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
66 static void may_set_selection(void); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
67 #endif |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
68 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
69 static int preprocs_left(void); |
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
70 #endif |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
71 static void dis_msg(char_u *p, int skip_esc); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
72 static void block_prep(oparg_T *oap, struct block_def *, linenr_T, int); |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
73 static int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1); |
7 | 74 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
75 static void str_to_reg(yankreg_T *y_ptr, int yank_type, char_u *str, long len, long blocklen, int str_list); |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
76 #endif |
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
77 static int ends_in_white(linenr_T lnum); |
7 | 78 #ifdef FEAT_COMMENTS |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
79 static int fmt_check_par(linenr_T, int *, char_u **, int do_comments); |
7 | 80 #else |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
81 static int fmt_check_par(linenr_T); |
7 | 82 #endif |
83 | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
84 // Flags for third item in "opchars". |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
85 #define OPF_LINES 1 // operator always works on lines |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
86 #define OPF_CHANGE 2 // operator changes text |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
87 |
7 | 88 /* |
89 * The names of operators. | |
90 * IMPORTANT: Index must correspond with defines in vim.h!!! | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
91 * The third field holds OPF_ flags. |
7 | 92 */ |
93 static char opchars[][3] = | |
94 { | |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
95 {NUL, NUL, 0}, // OP_NOP |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
96 {'d', NUL, OPF_CHANGE}, // OP_DELETE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
97 {'y', NUL, 0}, // OP_YANK |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
98 {'c', NUL, OPF_CHANGE}, // OP_CHANGE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
99 {'<', NUL, OPF_LINES | OPF_CHANGE}, // OP_LSHIFT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
100 {'>', NUL, OPF_LINES | OPF_CHANGE}, // OP_RSHIFT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
101 {'!', NUL, OPF_LINES | OPF_CHANGE}, // OP_FILTER |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
102 {'g', '~', OPF_CHANGE}, // OP_TILDE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
103 {'=', NUL, OPF_LINES | OPF_CHANGE}, // OP_INDENT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
104 {'g', 'q', OPF_LINES | OPF_CHANGE}, // OP_FORMAT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
105 {':', NUL, OPF_LINES}, // OP_COLON |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
106 {'g', 'U', OPF_CHANGE}, // OP_UPPER |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
107 {'g', 'u', OPF_CHANGE}, // OP_LOWER |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
108 {'J', NUL, OPF_LINES | OPF_CHANGE}, // DO_JOIN |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
109 {'g', 'J', OPF_LINES | OPF_CHANGE}, // DO_JOIN_NS |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
110 {'g', '?', OPF_CHANGE}, // OP_ROT13 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
111 {'r', NUL, OPF_CHANGE}, // OP_REPLACE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
112 {'I', NUL, OPF_CHANGE}, // OP_INSERT |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
113 {'A', NUL, OPF_CHANGE}, // OP_APPEND |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
114 {'z', 'f', OPF_LINES}, // OP_FOLD |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
115 {'z', 'o', OPF_LINES}, // OP_FOLDOPEN |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
116 {'z', 'O', OPF_LINES}, // OP_FOLDOPENREC |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
117 {'z', 'c', OPF_LINES}, // OP_FOLDCLOSE |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
118 {'z', 'C', OPF_LINES}, // OP_FOLDCLOSEREC |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
119 {'z', 'd', OPF_LINES}, // OP_FOLDDEL |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
120 {'z', 'D', OPF_LINES}, // OP_FOLDDELREC |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
121 {'g', 'w', OPF_LINES | OPF_CHANGE}, // OP_FORMAT2 |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
122 {'g', '@', OPF_CHANGE}, // OP_FUNCTION |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
123 {Ctrl_A, NUL, OPF_CHANGE}, // OP_NR_ADD |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
124 {Ctrl_X, NUL, OPF_CHANGE}, // OP_NR_SUB |
7 | 125 }; |
126 | |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
127 yankreg_T * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
128 get_y_regs(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
129 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
130 return y_regs; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
131 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
132 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
133 yankreg_T * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
134 get_y_current(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
135 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
136 return y_current; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
137 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
138 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
139 yankreg_T * |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
140 get_y_previous(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
141 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
142 return y_previous; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
143 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
144 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
145 void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
146 set_y_previous(yankreg_T *yreg) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
147 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
148 y_previous = yreg; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
149 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
150 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
151 |
7 | 152 /* |
153 * Translate a command name into an operator type. | |
154 * Must only be called with a valid operator name! | |
155 */ | |
156 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
157 get_op_type(int char1, int char2) |
7 | 158 { |
159 int i; | |
160 | |
161 if (char1 == 'r') /* ignore second character */ | |
162 return OP_REPLACE; | |
163 if (char1 == '~') /* when tilde is an operator */ | |
164 return OP_TILDE; | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
165 if (char1 == 'g' && char2 == Ctrl_A) /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
166 return OP_NR_ADD; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
167 if (char1 == 'g' && char2 == Ctrl_X) /* subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
168 return OP_NR_SUB; |
7 | 169 for (i = 0; ; ++i) |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
170 { |
7 | 171 if (opchars[i][0] == char1 && opchars[i][1] == char2) |
172 break; | |
13072
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
173 if (i == (int)(sizeof(opchars) / sizeof(char [3]) - 1)) |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
174 { |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
175 internal_error("get_op_type()"); |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
176 break; |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
177 } |
50aa6da392ce
patch 8.0.1411: reading invalid memory with CTRL-W :
Christian Brabandt <cb@256bit.org>
parents:
13047
diff
changeset
|
178 } |
7 | 179 return i; |
180 } | |
181 | |
182 /* | |
183 * Return TRUE if operator "op" always works on whole lines. | |
184 */ | |
185 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
186 op_on_lines(int op) |
7 | 187 { |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
188 return opchars[op][2] & OPF_LINES; |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
189 } |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
190 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
191 #if defined(FEAT_JOB_CHANNEL) || defined(PROTO) |
14019
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
192 /* |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
193 * Return TRUE if operator "op" changes text. |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
194 */ |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
195 int |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
196 op_is_change(int op) |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
197 { |
dc67449d648c
patch 8.1.0027: difficult to make a plugin that feeds a line to a job
Christian Brabandt <cb@256bit.org>
parents:
14004
diff
changeset
|
198 return opchars[op][2] & OPF_CHANGE; |
7 | 199 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
200 #endif |
7 | 201 |
202 /* | |
203 * Get first operator command character. | |
204 * Returns 'g' or 'z' if there is another command character. | |
205 */ | |
206 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
207 get_op_char(int optype) |
7 | 208 { |
209 return opchars[optype][0]; | |
210 } | |
211 | |
212 /* | |
213 * Get second operator command character. | |
214 */ | |
215 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
216 get_extra_op_char(int optype) |
7 | 217 { |
218 return opchars[optype][1]; | |
219 } | |
220 | |
221 /* | |
222 * op_shift - handle a shift operation | |
223 */ | |
224 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
225 op_shift(oparg_T *oap, int curs_top, int amount) |
7 | 226 { |
227 long i; | |
228 int first_char; | |
229 int block_col = 0; | |
230 | |
231 if (u_save((linenr_T)(oap->start.lnum - 1), | |
232 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
233 return; | |
234 | |
235 if (oap->block_mode) | |
236 block_col = curwin->w_cursor.col; | |
237 | |
238 for (i = oap->line_count; --i >= 0; ) | |
239 { | |
240 first_char = *ml_get_curline(); | |
241 if (first_char == NUL) /* empty line */ | |
242 curwin->w_cursor.col = 0; | |
243 else if (oap->block_mode) | |
244 shift_block(oap, amount); | |
245 else | |
246 /* Move the line right if it doesn't start with '#', 'smartindent' | |
247 * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. */ | |
248 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
249 if (first_char != '#' || !preprocs_left()) | |
250 #endif | |
1516 | 251 shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE); |
7 | 252 ++curwin->w_cursor.lnum; |
253 } | |
254 | |
255 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
256 if (oap->block_mode) | |
257 { | |
258 curwin->w_cursor.lnum = oap->start.lnum; | |
259 curwin->w_cursor.col = block_col; | |
260 } | |
5735 | 261 else if (curs_top) /* put cursor on first line, for ">>" */ |
7 | 262 { |
263 curwin->w_cursor.lnum = oap->start.lnum; | |
264 beginline(BL_SOL | BL_FIX); /* shift_line() may have set cursor.col */ | |
265 } | |
266 else | |
267 --curwin->w_cursor.lnum; /* put cursor on last line, for ":>" */ | |
268 | |
10486
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
269 #ifdef FEAT_FOLDING |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
270 /* The cursor line is not in a closed fold */ |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
271 foldOpenCursor(); |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
272 #endif |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
273 |
99896ee0cac5
commit https://github.com/vim/vim/commit/54b2bfa399017ebae76ed62f21578261d1b55c1f
Christian Brabandt <cb@256bit.org>
parents:
10104
diff
changeset
|
274 |
7 | 275 if (oap->line_count > p_report) |
276 { | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
277 char *op; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
278 char *msg_line_single; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
279 char *msg_line_plural; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
280 |
7 | 281 if (oap->op_type == OP_RSHIFT) |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
282 op = ">"; |
7 | 283 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
284 op = "<"; |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
285 msg_line_single = NGETTEXT("%ld line %sed %d time", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
286 "%ld line %sed %d times", amount); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
287 msg_line_plural = NGETTEXT("%ld lines %sed %d time", |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
288 "%ld lines %sed %d times", amount); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
289 vim_snprintf((char *)IObuff, IOSIZE, |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
290 NGETTEXT(msg_line_single, msg_line_plural, oap->line_count), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
291 oap->line_count, op, amount); |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
292 msg((char *)IObuff); |
7 | 293 } |
294 | |
295 /* | |
296 * Set "'[" and "']" marks. | |
297 */ | |
298 curbuf->b_op_start = oap->start; | |
299 curbuf->b_op_end.lnum = oap->end.lnum; | |
300 curbuf->b_op_end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
301 if (curbuf->b_op_end.col > 0) | |
302 --curbuf->b_op_end.col; | |
303 } | |
304 | |
305 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
306 * Shift the current line one shiftwidth left (if left != 0) or right |
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
307 * leaves cursor on first blank in the line. |
7 | 308 */ |
309 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
310 shift_line( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
311 int left, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
312 int round, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
313 int amount, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
314 int call_changed_bytes) /* call changed_bytes() */ |
7 | 315 { |
316 int count; | |
317 int i, j; | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
318 int sw_val = (int)get_sw_value_indent(curbuf); |
7 | 319 |
320 count = get_indent(); /* get current indent */ | |
321 | |
322 if (round) /* round off indent */ | |
323 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
324 i = count / sw_val; /* number of p_sw rounded down */ |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
325 j = count % sw_val; /* extra spaces */ |
7 | 326 if (j && left) /* first remove extra spaces */ |
327 --amount; | |
328 if (left) | |
329 { | |
330 i -= amount; | |
331 if (i < 0) | |
332 i = 0; | |
333 } | |
334 else | |
335 i += amount; | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
336 count = i * sw_val; |
7 | 337 } |
338 else /* original vi indent */ | |
339 { | |
340 if (left) | |
341 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
342 count -= sw_val * amount; |
7 | 343 if (count < 0) |
344 count = 0; | |
345 } | |
346 else | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
347 count += sw_val * amount; |
7 | 348 } |
349 | |
350 /* Set new indent */ | |
351 if (State & VREPLACE_FLAG) | |
1516 | 352 change_indent(INDENT_SET, count, FALSE, NUL, call_changed_bytes); |
7 | 353 else |
1516 | 354 (void)set_indent(count, call_changed_bytes ? SIN_CHANGED : 0); |
7 | 355 } |
356 | |
357 /* | |
358 * Shift one line of the current block one shiftwidth right or left. | |
359 * Leaves cursor on first character in block. | |
360 */ | |
361 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
362 shift_block(oparg_T *oap, int amount) |
7 | 363 { |
364 int left = (oap->op_type == OP_LSHIFT); | |
365 int oldstate = State; | |
1839 | 366 int total; |
367 char_u *newp, *oldp; | |
7 | 368 int oldcol = curwin->w_cursor.col; |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
369 int sw_val = (int)get_sw_value_indent(curbuf); |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
370 int ts_val = (int)curbuf->b_p_ts; |
7 | 371 struct block_def bd; |
372 int incr; | |
1839 | 373 colnr_T ws_vcol; |
7 | 374 int i = 0, j = 0; |
375 int len; | |
376 #ifdef FEAT_RIGHTLEFT | |
377 int old_p_ri = p_ri; | |
378 | |
4352 | 379 p_ri = 0; /* don't want revins in indent */ |
7 | 380 #endif |
381 | |
382 State = INSERT; /* don't want REPLACE for State */ | |
383 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); | |
384 if (bd.is_short) | |
385 return; | |
386 | |
387 /* total is number of screen columns to be inserted/removed */ | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
388 total = (int)((unsigned)amount * (unsigned)sw_val); |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
389 if ((total / sw_val) != amount) |
11997
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
390 return; /* multiplication overflow */ |
66b677c77467
patch 8.0.0879: crash when shifting with huge number
Christian Brabandt <cb@256bit.org>
parents:
11688
diff
changeset
|
391 |
7 | 392 oldp = ml_get_curline(); |
393 | |
394 if (!left) | |
395 { | |
396 /* | |
397 * 1. Get start vcol | |
398 * 2. Total ws vcols | |
399 * 3. Divvy into TABs & spp | |
400 * 4. Construct new string | |
401 */ | |
402 total += bd.pre_whitesp; /* all virtual WS upto & incl a split TAB */ | |
403 ws_vcol = bd.start_vcol - bd.pre_whitesp; | |
404 if (bd.startspaces) | |
405 { | |
406 if (has_mbyte) | |
8399
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
407 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
408 if ((*mb_ptr2len)(bd.textstart) == 1) |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
409 ++bd.textstart; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
410 else |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
411 { |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
412 ws_vcol = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
413 bd.startspaces = 0; |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
414 } |
7d1c42e3ce11
commit https://github.com/vim/vim/commit/20b4f463f4ab50fa9bcc9838aa94101fa5698125
Christian Brabandt <cb@256bit.org>
parents:
7829
diff
changeset
|
415 } |
1995 | 416 else |
417 ++bd.textstart; | |
7 | 418 } |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
419 for ( ; VIM_ISWHITE(*bd.textstart); ) |
7 | 420 { |
5995 | 421 /* TODO: is passing bd.textstart for start of the line OK? */ |
422 incr = lbr_chartabsize_adv(bd.textstart, &bd.textstart, | |
423 (colnr_T)(bd.start_vcol)); | |
7 | 424 total += incr; |
425 bd.start_vcol += incr; | |
426 } | |
427 /* OK, now total=all the VWS reqd, and textstart points at the 1st | |
428 * non-ws char in the block. */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
429 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
430 if (!curbuf->b_p_et) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
431 tabstop_fromto(ws_vcol, ws_vcol + total, |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
432 ts_val, curbuf->b_p_vts_array, &i, &j); |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
433 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
434 j = total; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
435 #else |
7 | 436 if (!curbuf->b_p_et) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
437 i = ((ws_vcol % ts_val) + total) / ts_val; /* number of tabs */ |
7 | 438 if (i) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
439 j = ((ws_vcol % ts_val) + total) % ts_val; /* number of spp */ |
7 | 440 else |
441 j = total; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
442 #endif |
7 | 443 /* if we're splitting a TAB, allow for it */ |
444 bd.textcol -= bd.pre_whitesp_c - (bd.startspaces != 0); | |
445 len = (int)STRLEN(bd.textstart) + 1; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
446 newp = alloc(bd.textcol + i + j + len); |
7 | 447 if (newp == NULL) |
448 return; | |
449 vim_memset(newp, NUL, (size_t)(bd.textcol + i + j + len)); | |
450 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
6929 | 451 vim_memset(newp + bd.textcol, TAB, (size_t)i); |
452 vim_memset(newp + bd.textcol + i, ' ', (size_t)j); | |
7 | 453 /* the end */ |
454 mch_memmove(newp + bd.textcol + i + j, bd.textstart, (size_t)len); | |
455 } | |
456 else /* left */ | |
457 { | |
1839 | 458 colnr_T destination_col; /* column to which text in block will |
459 be shifted */ | |
460 char_u *verbatim_copy_end; /* end of the part of the line which is | |
461 copied verbatim */ | |
462 colnr_T verbatim_copy_width;/* the (displayed) width of this part | |
463 of line */ | |
464 unsigned fill; /* nr of spaces that replace a TAB */ | |
465 unsigned new_line_len; /* the length of the line after the | |
466 block shift */ | |
467 size_t block_space_width; | |
468 size_t shift_amount; | |
469 char_u *non_white = bd.textstart; | |
470 colnr_T non_white_col; | |
471 | |
472 /* | |
473 * Firstly, let's find the first non-whitespace character that is | |
474 * displayed after the block's start column and the character's column | |
475 * number. Also, let's calculate the width of all the whitespace | |
476 * characters that are displayed in the block and precede the searched | |
477 * non-whitespace character. | |
478 */ | |
479 | |
480 /* If "bd.startspaces" is set, "bd.textstart" points to the character, | |
481 * the part of which is displayed at the block's beginning. Let's start | |
482 * searching from the next character. */ | |
483 if (bd.startspaces) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
484 MB_PTR_ADV(non_white); |
1839 | 485 |
486 /* The character's column is in "bd.start_vcol". */ | |
487 non_white_col = bd.start_vcol; | |
488 | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
489 while (VIM_ISWHITE(*non_white)) |
7 | 490 { |
5995 | 491 incr = lbr_chartabsize_adv(bd.textstart, &non_white, non_white_col); |
1839 | 492 non_white_col += incr; |
7 | 493 } |
1839 | 494 |
495 block_space_width = non_white_col - oap->start_vcol; | |
496 /* We will shift by "total" or "block_space_width", whichever is less. | |
497 */ | |
1860 | 498 shift_amount = (block_space_width < (size_t)total |
499 ? block_space_width : (size_t)total); | |
1839 | 500 |
501 /* The column to which we will shift the text. */ | |
1860 | 502 destination_col = (colnr_T)(non_white_col - shift_amount); |
1839 | 503 |
504 /* Now let's find out how much of the beginning of the line we can | |
505 * reuse without modification. */ | |
506 verbatim_copy_end = bd.textstart; | |
507 verbatim_copy_width = bd.start_vcol; | |
508 | |
509 /* If "bd.startspaces" is set, "bd.textstart" points to the character | |
510 * preceding the block. We have to subtract its width to obtain its | |
511 * column number. */ | |
512 if (bd.startspaces) | |
513 verbatim_copy_width -= bd.start_char_vcols; | |
514 while (verbatim_copy_width < destination_col) | |
7 | 515 { |
5995 | 516 char_u *line = verbatim_copy_end; |
517 | |
518 /* TODO: is passing verbatim_copy_end for start of the line OK? */ | |
519 incr = lbr_chartabsize(line, verbatim_copy_end, | |
520 verbatim_copy_width); | |
1839 | 521 if (verbatim_copy_width + incr > destination_col) |
522 break; | |
523 verbatim_copy_width += incr; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
524 MB_PTR_ADV(verbatim_copy_end); |
7 | 525 } |
526 | |
1839 | 527 /* If "destination_col" is different from the width of the initial |
528 * part of the line that will be copied, it means we encountered a tab | |
529 * character, which we will have to partly replace with spaces. */ | |
530 fill = destination_col - verbatim_copy_width; | |
531 | |
532 /* The replacement line will consist of: | |
533 * - the beginning of the original line up to "verbatim_copy_end", | |
534 * - "fill" number of spaces, | |
535 * - the rest of the line, pointed to by non_white. */ | |
536 new_line_len = (unsigned)(verbatim_copy_end - oldp) | |
537 + fill | |
538 + (unsigned)STRLEN(non_white) + 1; | |
539 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
540 newp = alloc(new_line_len); |
7 | 541 if (newp == NULL) |
542 return; | |
1839 | 543 mch_memmove(newp, oldp, (size_t)(verbatim_copy_end - oldp)); |
6929 | 544 vim_memset(newp + (verbatim_copy_end - oldp), ' ', (size_t)fill); |
1839 | 545 STRMOVE(newp + (verbatim_copy_end - oldp) + fill, non_white); |
7 | 546 } |
547 /* replace the line */ | |
548 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
549 changed_bytes(curwin->w_cursor.lnum, (colnr_T)bd.textcol); | |
550 State = oldstate; | |
551 curwin->w_cursor.col = oldcol; | |
552 #ifdef FEAT_RIGHTLEFT | |
553 p_ri = old_p_ri; | |
554 #endif | |
555 } | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
556 |
7 | 557 /* |
558 * Insert string "s" (b_insert ? before : after) block :AKelly | |
559 * Caller must prepare for undo. | |
560 */ | |
561 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
562 block_insert( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
563 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
564 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
565 int b_insert, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
566 struct block_def *bdp) |
7 | 567 { |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
568 int ts_val; |
7 | 569 int count = 0; /* extra spaces to replace a cut TAB */ |
570 int spaces = 0; /* non-zero if cutting a TAB */ | |
571 colnr_T offset; /* pointer along new line */ | |
572 unsigned s_len; /* STRLEN(s) */ | |
573 char_u *newp, *oldp; /* new, old lines */ | |
574 linenr_T lnum; /* loop var */ | |
575 int oldstate = State; | |
576 | |
577 State = INSERT; /* don't want REPLACE for State */ | |
578 s_len = (unsigned)STRLEN(s); | |
579 | |
580 for (lnum = oap->start.lnum + 1; lnum <= oap->end.lnum; lnum++) | |
581 { | |
582 block_prep(oap, bdp, lnum, TRUE); | |
583 if (bdp->is_short && b_insert) | |
584 continue; /* OP_INSERT, line ends before block start */ | |
585 | |
586 oldp = ml_get(lnum); | |
587 | |
588 if (b_insert) | |
589 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
590 ts_val = bdp->start_char_vcols; |
7 | 591 spaces = bdp->startspaces; |
592 if (spaces != 0) | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
593 count = ts_val - 1; /* we're cutting a TAB */ |
7 | 594 offset = bdp->textcol; |
595 } | |
596 else /* append */ | |
597 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
598 ts_val = bdp->end_char_vcols; |
7 | 599 if (!bdp->is_short) /* spaces = padding after block */ |
600 { | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
601 spaces = (bdp->endspaces ? ts_val - bdp->endspaces : 0); |
7 | 602 if (spaces != 0) |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
603 count = ts_val - 1; /* we're cutting a TAB */ |
7 | 604 offset = bdp->textcol + bdp->textlen - (spaces != 0); |
605 } | |
606 else /* spaces = padding to block edge */ | |
607 { | |
608 /* if $ used, just append to EOL (ie spaces==0) */ | |
609 if (!bdp->is_MAX) | |
610 spaces = (oap->end_vcol - bdp->end_vcol) + 1; | |
611 count = spaces; | |
612 offset = bdp->textcol + bdp->textlen; | |
613 } | |
614 } | |
615 | |
6140 | 616 if (has_mbyte && spaces > 0) |
617 { | |
6460 | 618 int off; |
619 | |
6140 | 620 /* Avoid starting halfway a multi-byte character. */ |
621 if (b_insert) | |
622 { | |
6460 | 623 off = (*mb_head_off)(oldp, oldp + offset + spaces); |
6140 | 624 } |
625 else | |
626 { | |
6460 | 627 off = (*mb_off_next)(oldp, oldp + offset); |
6140 | 628 offset += off; |
629 } | |
6460 | 630 spaces -= off; |
631 count -= off; | |
6140 | 632 } |
633 | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
634 newp = alloc(STRLEN(oldp) + s_len + count + 1); |
7 | 635 if (newp == NULL) |
636 continue; | |
637 | |
638 /* copy up to shifted part */ | |
639 mch_memmove(newp, oldp, (size_t)(offset)); | |
640 oldp += offset; | |
641 | |
642 /* insert pre-padding */ | |
6929 | 643 vim_memset(newp + offset, ' ', (size_t)spaces); |
7 | 644 |
645 /* copy the new text */ | |
646 mch_memmove(newp + offset + spaces, s, (size_t)s_len); | |
647 offset += s_len; | |
648 | |
649 if (spaces && !bdp->is_short) | |
650 { | |
651 /* insert post-padding */ | |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
652 vim_memset(newp + offset + spaces, ' ', (size_t)(ts_val - spaces)); |
7 | 653 /* We're splitting a TAB, don't copy it. */ |
654 oldp++; | |
655 /* We allowed for that TAB, remember this now */ | |
656 count++; | |
657 } | |
658 | |
659 if (spaces > 0) | |
660 offset += count; | |
1622 | 661 STRMOVE(newp + offset, oldp); |
7 | 662 |
663 ml_replace(lnum, newp, FALSE); | |
664 | |
665 if (lnum == oap->end.lnum) | |
666 { | |
667 /* Set "']" mark to the end of the block instead of the end of | |
668 * the insert in the first line. */ | |
669 curbuf->b_op_end.lnum = oap->end.lnum; | |
670 curbuf->b_op_end.col = offset; | |
671 } | |
672 } /* for all lnum */ | |
673 | |
674 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
675 | |
676 State = oldstate; | |
677 } | |
678 | |
679 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) || defined(PROTO) | |
680 /* | |
681 * op_reindent - handle reindenting a block of lines. | |
682 */ | |
683 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
684 op_reindent(oparg_T *oap, int (*how)(void)) |
7 | 685 { |
686 long i; | |
687 char_u *l; | |
6971 | 688 int amount; |
7 | 689 linenr_T first_changed = 0; |
690 linenr_T last_changed = 0; | |
691 linenr_T start_lnum = curwin->w_cursor.lnum; | |
692 | |
216 | 693 /* Don't even try when 'modifiable' is off. */ |
694 if (!curbuf->b_p_ma) | |
695 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
696 emsg(_(e_modifiable)); |
216 | 697 return; |
698 } | |
699 | |
7 | 700 for (i = oap->line_count; --i >= 0 && !got_int; ) |
701 { | |
702 /* it's a slow thing to do, so give feedback so there's no worry that | |
703 * the computer's just hung. */ | |
704 | |
705 if (i > 1 | |
706 && (i % 50 == 0 || i == oap->line_count - 1) | |
707 && oap->line_count > p_report) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
708 smsg(_("%ld lines to indent... "), i); |
7 | 709 |
710 /* | |
711 * Be vi-compatible: For lisp indenting the first line is not | |
712 * indented, unless there is only one line. | |
713 */ | |
714 #ifdef FEAT_LISP | |
715 if (i != oap->line_count - 1 || oap->line_count == 1 | |
716 || how != get_lisp_indent) | |
717 #endif | |
718 { | |
719 l = skipwhite(ml_get_curline()); | |
720 if (*l == NUL) /* empty or blank line */ | |
6971 | 721 amount = 0; |
7 | 722 else |
6971 | 723 amount = how(); /* get the indent for this line */ |
724 | |
725 if (amount >= 0 && set_indent(amount, SIN_UNDO)) | |
7 | 726 { |
727 /* did change the indent, call changed_lines() later */ | |
728 if (first_changed == 0) | |
729 first_changed = curwin->w_cursor.lnum; | |
730 last_changed = curwin->w_cursor.lnum; | |
731 } | |
732 } | |
733 ++curwin->w_cursor.lnum; | |
1550 | 734 curwin->w_cursor.col = 0; /* make sure it's valid */ |
7 | 735 } |
736 | |
737 /* put cursor on first non-blank of indented line */ | |
738 curwin->w_cursor.lnum = start_lnum; | |
739 beginline(BL_SOL | BL_FIX); | |
740 | |
741 /* Mark changed lines so that they will be redrawn. When Visual | |
742 * highlighting was present, need to continue until the last line. When | |
743 * there is no change still need to remove the Visual highlighting. */ | |
744 if (last_changed != 0) | |
745 changed_lines(first_changed, 0, | |
746 oap->is_VIsual ? start_lnum + oap->line_count : | |
747 last_changed + 1, 0L); | |
748 else if (oap->is_VIsual) | |
749 redraw_curbuf_later(INVERTED); | |
750 | |
751 if (oap->line_count > p_report) | |
752 { | |
753 i = oap->line_count - (i + 1); | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
754 smsg(NGETTEXT("%ld line indented ", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
755 "%ld lines indented ", i), i); |
7 | 756 } |
757 /* set '[ and '] marks */ | |
758 curbuf->b_op_start = oap->start; | |
759 curbuf->b_op_end = oap->end; | |
760 } | |
761 #endif /* defined(FEAT_LISP) || defined(FEAT_CINDENT) */ | |
762 | |
763 #if defined(FEAT_EVAL) || defined(PROTO) | |
764 /* | |
765 * Keep the last expression line here, for repeating. | |
766 */ | |
767 static char_u *expr_line = NULL; | |
768 | |
769 /* | |
770 * Get an expression for the "\"=expr1" or "CTRL-R =expr1" | |
771 * Returns '=' when OK, NUL otherwise. | |
772 */ | |
773 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
774 get_expr_register(void) |
7 | 775 { |
776 char_u *new_line; | |
777 | |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17063
diff
changeset
|
778 new_line = getcmdline('=', 0L, 0, TRUE); |
7 | 779 if (new_line == NULL) |
780 return NUL; | |
781 if (*new_line == NUL) /* use previous line */ | |
782 vim_free(new_line); | |
783 else | |
784 set_expr_line(new_line); | |
785 return '='; | |
786 } | |
787 | |
788 /* | |
789 * Set the expression for the '=' register. | |
790 * Argument must be an allocated string. | |
791 */ | |
792 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
793 set_expr_line(char_u *new_line) |
7 | 794 { |
795 vim_free(expr_line); | |
796 expr_line = new_line; | |
797 } | |
798 | |
799 /* | |
800 * Get the result of the '=' register expression. | |
801 * Returns a pointer to allocated memory, or NULL for failure. | |
802 */ | |
803 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
804 get_expr_line(void) |
7 | 805 { |
806 char_u *expr_copy; | |
807 char_u *rv; | |
994 | 808 static int nested = 0; |
7 | 809 |
810 if (expr_line == NULL) | |
811 return NULL; | |
812 | |
813 /* Make a copy of the expression, because evaluating it may cause it to be | |
814 * changed. */ | |
815 expr_copy = vim_strsave(expr_line); | |
816 if (expr_copy == NULL) | |
817 return NULL; | |
818 | |
994 | 819 /* When we are invoked recursively limit the evaluation to 10 levels. |
820 * Then return the string as-is. */ | |
821 if (nested >= 10) | |
822 return expr_copy; | |
823 | |
824 ++nested; | |
714 | 825 rv = eval_to_string(expr_copy, NULL, TRUE); |
994 | 826 --nested; |
7 | 827 vim_free(expr_copy); |
828 return rv; | |
829 } | |
283 | 830 |
831 /* | |
832 * Get the '=' register expression itself, without evaluating it. | |
833 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
834 static char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
835 get_expr_line_src(void) |
283 | 836 { |
837 if (expr_line == NULL) | |
838 return NULL; | |
839 return vim_strsave(expr_line); | |
840 } | |
7 | 841 #endif /* FEAT_EVAL */ |
842 | |
843 /* | |
844 * Check if 'regname' is a valid name of a yank register. | |
845 * Note: There is no check for 0 (default register), caller should do this | |
846 */ | |
847 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
848 valid_yank_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
849 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
850 int writing) /* if TRUE check for writable registers */ |
7 | 851 { |
852 if ( (regname > 0 && ASCII_ISALNUM(regname)) | |
853 || (!writing && vim_strchr((char_u *) | |
854 #ifdef FEAT_EVAL | |
6557 | 855 "/.%:=" |
7 | 856 #else |
6557 | 857 "/.%:" |
7 | 858 #endif |
859 , regname) != NULL) | |
6557 | 860 || regname == '#' |
7 | 861 || regname == '"' |
862 || regname == '-' | |
863 || regname == '_' | |
864 #ifdef FEAT_CLIPBOARD | |
865 || regname == '*' | |
866 || regname == '+' | |
867 #endif | |
868 #ifdef FEAT_DND | |
869 || (!writing && regname == '~') | |
870 #endif | |
871 ) | |
872 return TRUE; | |
873 return FALSE; | |
874 } | |
875 | |
876 /* | |
877 * Set y_current and y_append, according to the value of "regname". | |
878 * Cannot handle the '_' register. | |
140 | 879 * Must only be called with a valid register name! |
7 | 880 * |
881 * If regname is 0 and writing, use register 0 | |
882 * If regname is 0 and reading, use previous register | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
883 * |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
884 * Return TRUE when the register should be inserted literally (selection or |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
885 * clipboard). |
7 | 886 */ |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
887 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
888 get_yank_register(int regname, int writing) |
7 | 889 { |
890 int i; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
891 int ret = FALSE; |
7 | 892 |
893 y_append = FALSE; | |
894 if ((regname == 0 || regname == '"') && !writing && y_previous != NULL) | |
895 { | |
896 y_current = y_previous; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
897 return ret; |
7 | 898 } |
899 i = regname; | |
900 if (VIM_ISDIGIT(i)) | |
901 i -= '0'; | |
902 else if (ASCII_ISLOWER(i)) | |
903 i = CharOrdLow(i) + 10; | |
904 else if (ASCII_ISUPPER(i)) | |
905 { | |
906 i = CharOrdUp(i) + 10; | |
907 y_append = TRUE; | |
908 } | |
909 else if (regname == '-') | |
910 i = DELETION_REGISTER; | |
911 #ifdef FEAT_CLIPBOARD | |
912 /* When selection is not available, use register 0 instead of '*' */ | |
913 else if (clip_star.available && regname == '*') | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
914 { |
7 | 915 i = STAR_REGISTER; |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
916 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
917 } |
7 | 918 /* When clipboard is not available, use register 0 instead of '+' */ |
919 else if (clip_plus.available && regname == '+') | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
920 { |
7 | 921 i = PLUS_REGISTER; |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
922 ret = TRUE; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
923 } |
7 | 924 #endif |
925 #ifdef FEAT_DND | |
926 else if (!writing && regname == '~') | |
927 i = TILDE_REGISTER; | |
928 #endif | |
929 else /* not 0-9, a-z, A-Z or '-': use register 0 */ | |
930 i = 0; | |
931 y_current = &(y_regs[i]); | |
932 if (writing) /* remember the register we write into for do_put() */ | |
933 y_previous = y_current; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
934 return ret; |
7 | 935 } |
936 | |
15 | 937 #if defined(FEAT_CLIPBOARD) || defined(PROTO) |
7 | 938 /* |
939 * When "regname" is a clipboard register, obtain the selection. If it's not | |
940 * available return zero, otherwise return "regname". | |
941 */ | |
15 | 942 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
943 may_get_selection(int regname) |
7 | 944 { |
945 if (regname == '*') | |
946 { | |
947 if (!clip_star.available) | |
948 regname = 0; | |
949 else | |
950 clip_get_selection(&clip_star); | |
951 } | |
952 else if (regname == '+') | |
953 { | |
954 if (!clip_plus.available) | |
955 regname = 0; | |
956 else | |
957 clip_get_selection(&clip_plus); | |
958 } | |
959 return regname; | |
960 } | |
961 #endif | |
962 | |
963 /* | |
964 * Obtain the contents of a "normal" register. The register is made empty. | |
965 * The returned pointer has allocated memory, use put_register() later. | |
966 */ | |
967 void * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
968 get_register( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
969 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
970 int copy) /* make a copy, if FALSE make register empty. */ |
7 | 971 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
972 yankreg_T *reg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
973 int i; |
7 | 974 |
975 #ifdef FEAT_CLIPBOARD | |
976 /* When Visual area changed, may have to update selection. Obtain the | |
977 * selection too. */ | |
1435 | 978 if (name == '*' && clip_star.available) |
7 | 979 { |
3674 | 980 if (clip_isautosel_star()) |
981 clip_update_selection(&clip_star); | |
982 may_get_selection(name); | |
983 } | |
984 if (name == '+' && clip_plus.available) | |
985 { | |
986 if (clip_isautosel_plus()) | |
987 clip_update_selection(&clip_plus); | |
7 | 988 may_get_selection(name); |
989 } | |
990 #endif | |
991 | |
992 get_yank_register(name, 0); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
993 reg = ALLOC_ONE(yankreg_T); |
7 | 994 if (reg != NULL) |
995 { | |
996 *reg = *y_current; | |
997 if (copy) | |
998 { | |
999 /* If we run out of memory some or all of the lines are empty. */ | |
1000 if (reg->y_size == 0) | |
1001 reg->y_array = NULL; | |
1002 else | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1003 reg->y_array = ALLOC_MULT(char_u *, reg->y_size); |
7 | 1004 if (reg->y_array != NULL) |
1005 { | |
1006 for (i = 0; i < reg->y_size; ++i) | |
1007 reg->y_array[i] = vim_strsave(y_current->y_array[i]); | |
1008 } | |
1009 } | |
1010 else | |
1011 y_current->y_array = NULL; | |
1012 } | |
1013 return (void *)reg; | |
1014 } | |
1015 | |
1016 /* | |
1451 | 1017 * Put "reg" into register "name". Free any previous contents and "reg". |
7 | 1018 */ |
1019 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1020 put_register(int name, void *reg) |
7 | 1021 { |
1022 get_yank_register(name, 0); | |
1023 free_yank_all(); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1024 *y_current = *(yankreg_T *)reg; |
1451 | 1025 vim_free(reg); |
7 | 1026 |
5735 | 1027 #ifdef FEAT_CLIPBOARD |
7 | 1028 /* Send text written to clipboard register to the clipboard. */ |
1029 may_set_selection(); | |
5735 | 1030 #endif |
7 | 1031 } |
4209 | 1032 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1033 #if (defined(FEAT_CLIPBOARD) && defined(FEAT_X11) && defined(USE_SYSTEM)) \ |
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1034 || defined(PROTO) |
4209 | 1035 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1036 free_register(void *reg) |
4209 | 1037 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1038 yankreg_T tmp; |
4209 | 1039 |
1040 tmp = *y_current; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1041 *y_current = *(yankreg_T *)reg; |
4209 | 1042 free_yank_all(); |
1043 vim_free(reg); | |
1044 *y_current = tmp; | |
1045 } | |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1046 #endif |
7 | 1047 |
1048 #if defined(FEAT_MOUSE) || defined(PROTO) | |
1049 /* | |
1050 * return TRUE if the current yank register has type MLINE | |
1051 */ | |
1052 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1053 yank_register_mline(int regname) |
7 | 1054 { |
1055 if (regname != 0 && !valid_yank_reg(regname, FALSE)) | |
1056 return FALSE; | |
1057 if (regname == '_') /* black hole is always empty */ | |
1058 return FALSE; | |
1059 get_yank_register(regname, FALSE); | |
1060 return (y_current->y_type == MLINE); | |
1061 } | |
1062 #endif | |
1063 | |
1064 /* | |
1157 | 1065 * Start or stop recording into a yank register. |
7 | 1066 * |
1157 | 1067 * Return FAIL for failure, OK otherwise. |
7 | 1068 */ |
1069 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1070 do_record(int c) |
7 | 1071 { |
1157 | 1072 char_u *p; |
1073 static int regname; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1074 yankreg_T *old_y_previous, *old_y_current; |
1157 | 1075 int retval; |
7 | 1076 |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1077 if (reg_recording == 0) /* start recording */ |
7 | 1078 { |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
1079 /* registers 0-9, a-z and " are allowed */ |
7 | 1080 if (c < 0 || (!ASCII_ISALNUM(c) && c != '"')) |
1081 retval = FAIL; | |
1082 else | |
1083 { | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1084 reg_recording = c; |
7 | 1085 showmode(); |
1086 regname = c; | |
1087 retval = OK; | |
1088 } | |
1089 } | |
1090 else /* stop recording */ | |
1091 { | |
1092 /* | |
1157 | 1093 * Get the recorded key hits. K_SPECIAL and CSI will be escaped, this |
1094 * needs to be removed again to put it in a register. exec_reg then | |
1095 * adds the escaping back later. | |
7 | 1096 */ |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1097 reg_recording = 0; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
1098 msg(""); |
7 | 1099 p = get_recorded(); |
1100 if (p == NULL) | |
1101 retval = FAIL; | |
1102 else | |
1103 { | |
1081 | 1104 /* Remove escaping for CSI and K_SPECIAL in multi-byte chars. */ |
1105 vim_unescape_csi(p); | |
1106 | |
7 | 1107 /* |
1108 * We don't want to change the default register here, so save and | |
1109 * restore the current register name. | |
1110 */ | |
1111 old_y_previous = y_previous; | |
1112 old_y_current = y_current; | |
1113 | |
1114 retval = stuff_yank(regname, p); | |
1115 | |
1116 y_previous = old_y_previous; | |
1117 y_current = old_y_current; | |
1118 } | |
1119 } | |
1120 return retval; | |
1121 } | |
1122 | |
1123 /* | |
1124 * Stuff string "p" into yank register "regname" as a single line (append if | |
1125 * uppercase). "p" must have been alloced. | |
1126 * | |
1127 * return FAIL for failure, OK otherwise | |
1128 */ | |
1129 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1130 stuff_yank(int regname, char_u *p) |
7 | 1131 { |
1132 char_u *lp; | |
1133 char_u **pp; | |
1134 | |
1135 /* check for read-only register */ | |
1136 if (regname != 0 && !valid_yank_reg(regname, TRUE)) | |
1137 { | |
1138 vim_free(p); | |
1139 return FAIL; | |
1140 } | |
1141 if (regname == '_') /* black hole: don't do anything */ | |
1142 { | |
1143 vim_free(p); | |
1144 return OK; | |
1145 } | |
1146 get_yank_register(regname, TRUE); | |
1147 if (y_append && y_current->y_array != NULL) | |
1148 { | |
1149 pp = &(y_current->y_array[y_current->y_size - 1]); | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
1150 lp = alloc(STRLEN(*pp) + STRLEN(p) + 1); |
7 | 1151 if (lp == NULL) |
1152 { | |
1153 vim_free(p); | |
1154 return FAIL; | |
1155 } | |
1156 STRCPY(lp, *pp); | |
1157 STRCAT(lp, p); | |
1158 vim_free(p); | |
1159 vim_free(*pp); | |
1160 *pp = lp; | |
1161 } | |
1162 else | |
1163 { | |
1164 free_yank_all(); | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
1165 if ((y_current->y_array = ALLOC_ONE(char_u *)) == NULL) |
7 | 1166 { |
1167 vim_free(p); | |
1168 return FAIL; | |
1169 } | |
1170 y_current->y_array[0] = p; | |
1171 y_current->y_size = 1; | |
1172 y_current->y_type = MCHAR; /* used to be MLINE, why? */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1173 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1174 y_current->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
1175 #endif |
7 | 1176 } |
1177 return OK; | |
1178 } | |
1179 | |
1893 | 1180 static int execreg_lastc = NUL; |
1181 | |
17476
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1182 int |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1183 get_execreg_lastc(void) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1184 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1185 return execreg_lastc; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1186 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1187 |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1188 void |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1189 set_execreg_lastc(int lastc) |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1190 { |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1191 execreg_lastc = lastc; |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1192 } |
d4b2a212fa2f
patch 8.1.1736: viminfo support is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
1193 |
7 | 1194 /* |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1195 * Execute a yank register: copy it into the stuff buffer. |
7 | 1196 * |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
1197 * Return FAIL for failure, OK otherwise. |
7 | 1198 */ |
1199 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1200 do_execreg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1201 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1202 int colon, /* insert ':' before each line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1203 int addcr, /* always add '\n' to end of line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1204 int silent) /* set "silent" flag in typeahead buffer */ |
7 | 1205 { |
1206 long i; | |
1207 char_u *p; | |
1208 int retval = OK; | |
1209 int remap; | |
1210 | |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1211 // repeat previous one |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1212 if (regname == '@') |
168 | 1213 { |
1893 | 1214 if (execreg_lastc == NUL) |
168 | 1215 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1216 emsg(_("E748: No previously used register")); |
168 | 1217 return FAIL; |
1218 } | |
1893 | 1219 regname = execreg_lastc; |
168 | 1220 } |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1221 // check for valid regname |
7 | 1222 if (regname == '%' || regname == '#' || !valid_yank_reg(regname, FALSE)) |
168 | 1223 { |
1224 emsg_invreg(regname); | |
7 | 1225 return FAIL; |
168 | 1226 } |
1893 | 1227 execreg_lastc = regname; |
7 | 1228 |
1229 #ifdef FEAT_CLIPBOARD | |
1230 regname = may_get_selection(regname); | |
1231 #endif | |
1232 | |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1233 // black hole: don't stuff anything |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1234 if (regname == '_') |
7 | 1235 return OK; |
1236 | |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1237 // use last command line |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
1238 if (regname == ':') |
7 | 1239 { |
1240 if (last_cmdline == NULL) | |
1241 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1242 emsg(_(e_nolastcmd)); |
7 | 1243 return FAIL; |
1244 } | |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1245 // don't keep the cmdline containing @: |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1246 VIM_CLEAR(new_last_cmdline); |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1247 // Escape all control characters with a CTRL-V |
16 | 1248 p = vim_strsave_escaped_ext(last_cmdline, |
15989
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1249 (char_u *)"\001\002\003\004\005\006\007" |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1250 "\010\011\012\013\014\015\016\017" |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1251 "\020\021\022\023\024\025\026\027" |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1252 "\030\031\032\033\034\035\036\037", |
a14d8b4ef2b0
patch 8.1.1000: indenting is off
Bram Moolenaar <Bram@vim.org>
parents:
15987
diff
changeset
|
1253 Ctrl_V, FALSE); |
16 | 1254 if (p != NULL) |
480 | 1255 { |
1256 /* When in Visual mode "'<,'>" will be prepended to the command. | |
1257 * Remove it when it's already there. */ | |
1258 if (VIsual_active && STRNCMP(p, "'<,'>", 5) == 0) | |
1077 | 1259 retval = put_in_typebuf(p + 5, TRUE, TRUE, silent); |
480 | 1260 else |
1077 | 1261 retval = put_in_typebuf(p, TRUE, TRUE, silent); |
480 | 1262 } |
16 | 1263 vim_free(p); |
7 | 1264 } |
1265 #ifdef FEAT_EVAL | |
1266 else if (regname == '=') | |
1267 { | |
1268 p = get_expr_line(); | |
1269 if (p == NULL) | |
1270 return FAIL; | |
1077 | 1271 retval = put_in_typebuf(p, TRUE, colon, silent); |
7 | 1272 vim_free(p); |
1273 } | |
1274 #endif | |
1275 else if (regname == '.') /* use last inserted text */ | |
1276 { | |
1277 p = get_last_insert_save(); | |
1278 if (p == NULL) | |
1279 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1280 emsg(_(e_noinstext)); |
7 | 1281 return FAIL; |
1282 } | |
1077 | 1283 retval = put_in_typebuf(p, FALSE, colon, silent); |
7 | 1284 vim_free(p); |
1285 } | |
1286 else | |
1287 { | |
1288 get_yank_register(regname, FALSE); | |
1289 if (y_current->y_array == NULL) | |
1290 return FAIL; | |
1291 | |
1292 /* Disallow remaping for ":@r". */ | |
1293 remap = colon ? REMAP_NONE : REMAP_YES; | |
1294 | |
1295 /* | |
1296 * Insert lines into typeahead buffer, from last one to first one. | |
1297 */ | |
1034 | 1298 put_reedit_in_typebuf(silent); |
7 | 1299 for (i = y_current->y_size; --i >= 0; ) |
1300 { | |
1077 | 1301 char_u *escaped; |
1302 | |
7 | 1303 /* insert NL between lines and after last line if type is MLINE */ |
1304 if (y_current->y_type == MLINE || i < y_current->y_size - 1 | |
1305 || addcr) | |
1306 { | |
1034 | 1307 if (ins_typebuf((char_u *)"\n", remap, 0, TRUE, silent) == FAIL) |
7 | 1308 return FAIL; |
1309 } | |
1077 | 1310 escaped = vim_strsave_escape_csi(y_current->y_array[i]); |
1311 if (escaped == NULL) | |
1312 return FAIL; | |
1313 retval = ins_typebuf(escaped, remap, 0, TRUE, silent); | |
1314 vim_free(escaped); | |
1315 if (retval == FAIL) | |
7 | 1316 return FAIL; |
1034 | 1317 if (colon && ins_typebuf((char_u *)":", remap, 0, TRUE, silent) |
7 | 1318 == FAIL) |
1319 return FAIL; | |
1320 } | |
14004
e124262d435e
patch 8.1.0020: cannot tell whether a register is executing or recording
Christian Brabandt <cb@256bit.org>
parents:
13831
diff
changeset
|
1321 reg_executing = regname == 0 ? '"' : regname; // disable "q" command |
7 | 1322 } |
1323 return retval; | |
1324 } | |
1325 | |
1326 /* | |
1327 * If "restart_edit" is not zero, put it in the typeahead buffer, so that it's | |
1328 * used only after other typeahead has been processed. | |
1329 */ | |
1330 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1331 put_reedit_in_typebuf(int silent) |
7 | 1332 { |
1333 char_u buf[3]; | |
1334 | |
1335 if (restart_edit != NUL) | |
1336 { | |
1337 if (restart_edit == 'V') | |
1338 { | |
1339 buf[0] = 'g'; | |
1340 buf[1] = 'R'; | |
1341 buf[2] = NUL; | |
1342 } | |
1343 else | |
1344 { | |
1345 buf[0] = restart_edit == 'I' ? 'i' : restart_edit; | |
1346 buf[1] = NUL; | |
1347 } | |
1034 | 1348 if (ins_typebuf(buf, REMAP_NONE, 0, TRUE, silent) == OK) |
7 | 1349 restart_edit = NUL; |
1350 } | |
1351 } | |
1352 | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1353 /* |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1354 * Insert register contents "s" into the typeahead buffer, so that it will be |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1355 * executed again. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1356 * When "esc" is TRUE it is to be taken literally: Escape CSI characters and |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1357 * no remapping. |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1358 */ |
7 | 1359 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1360 put_in_typebuf( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1361 char_u *s, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1362 int esc, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1363 int colon, /* add ':' before the line */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1364 int silent) |
7 | 1365 { |
1366 int retval = OK; | |
1367 | |
1034 | 1368 put_reedit_in_typebuf(silent); |
7 | 1369 if (colon) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1370 retval = ins_typebuf((char_u *)"\n", REMAP_NONE, 0, TRUE, silent); |
7 | 1371 if (retval == OK) |
1077 | 1372 { |
1373 char_u *p; | |
1374 | |
1375 if (esc) | |
1376 p = vim_strsave_escape_csi(s); | |
1377 else | |
1378 p = s; | |
1379 if (p == NULL) | |
1380 retval = FAIL; | |
1381 else | |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1382 retval = ins_typebuf(p, esc ? REMAP_NONE : REMAP_YES, |
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1383 0, TRUE, silent); |
1077 | 1384 if (esc) |
1385 vim_free(p); | |
1386 } | |
7 | 1387 if (colon && retval == OK) |
2061
2f6e519726f1
updated for version 7.2.346
Bram Moolenaar <bram@zimbu.org>
parents:
2047
diff
changeset
|
1388 retval = ins_typebuf((char_u *)":", REMAP_NONE, 0, TRUE, silent); |
7 | 1389 return retval; |
1390 } | |
1391 | |
1392 /* | |
1393 * Insert a yank register: copy it into the Read buffer. | |
1394 * Used by CTRL-R command and middle mouse button in insert mode. | |
1395 * | |
1396 * return FAIL for failure, OK otherwise | |
1397 */ | |
1398 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1399 insert_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1400 int regname, |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1401 int literally_arg) /* insert literally, not as if typed */ |
7 | 1402 { |
1403 long i; | |
1404 int retval = OK; | |
1405 char_u *arg; | |
1406 int allocated; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1407 int literally = literally_arg; |
7 | 1408 |
1409 /* | |
1410 * It is possible to get into an endless loop by having CTRL-R a in | |
1411 * register a and then, in insert mode, doing CTRL-R a. | |
1412 * If you hit CTRL-C, the loop will be broken here. | |
1413 */ | |
1414 ui_breakcheck(); | |
1415 if (got_int) | |
1416 return FAIL; | |
1417 | |
1418 /* check for valid regname */ | |
1419 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
1420 return FAIL; | |
1421 | |
1422 #ifdef FEAT_CLIPBOARD | |
1423 regname = may_get_selection(regname); | |
1424 #endif | |
1425 | |
1426 if (regname == '.') /* insert last inserted text */ | |
1427 retval = stuff_inserted(NUL, 1L, TRUE); | |
1428 else if (get_spec_reg(regname, &arg, &allocated, TRUE)) | |
1429 { | |
1430 if (arg == NULL) | |
1431 return FAIL; | |
1432 stuffescaped(arg, literally); | |
1433 if (allocated) | |
1434 vim_free(arg); | |
1435 } | |
1436 else /* name or number register */ | |
1437 { | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1438 if (get_yank_register(regname, FALSE)) |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1439 literally = TRUE; |
7 | 1440 if (y_current->y_array == NULL) |
1441 retval = FAIL; | |
1442 else | |
1443 { | |
1444 for (i = 0; i < y_current->y_size; ++i) | |
1445 { | |
1446 stuffescaped(y_current->y_array[i], literally); | |
1447 /* | |
1448 * Insert a newline between lines and after last line if | |
1449 * y_type is MLINE. | |
1450 */ | |
1451 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
1452 stuffcharReadbuff('\n'); | |
1453 } | |
1454 } | |
1455 } | |
1456 | |
1457 return retval; | |
1458 } | |
1459 | |
1460 /* | |
1461 * Stuff a string into the typeahead buffer, such that edit() will insert it | |
1462 * literally ("literally" TRUE) or interpret is as typed characters. | |
1463 */ | |
1464 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1465 stuffescaped(char_u *arg, int literally) |
7 | 1466 { |
1467 int c; | |
1468 char_u *start; | |
1469 | |
1470 while (*arg != NUL) | |
1471 { | |
1472 /* Stuff a sequence of normal ASCII characters, that's fast. Also | |
1473 * stuff K_SPECIAL to get the effect of a special key when "literally" | |
1474 * is TRUE. */ | |
1475 start = arg; | |
1476 while ((*arg >= ' ' | |
1477 #ifndef EBCDIC | |
1478 && *arg < DEL /* EBCDIC: chars above space are normal */ | |
1479 #endif | |
1480 ) | |
1481 || (*arg == K_SPECIAL && !literally)) | |
1482 ++arg; | |
1483 if (arg > start) | |
1484 stuffReadbuffLen(start, (long)(arg - start)); | |
1485 | |
1486 /* stuff a single special character */ | |
1487 if (*arg != NUL) | |
1488 { | |
1489 if (has_mbyte) | |
2446
348f64c129df
Fixed: CTRL-R in Insert mode doesn't insert composing characters.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
1490 c = mb_cptr2char_adv(&arg); |
7 | 1491 else |
1492 c = *arg++; | |
1493 if (literally && ((c < ' ' && c != TAB) || c == DEL)) | |
1494 stuffcharReadbuff(Ctrl_V); | |
1495 stuffcharReadbuff(c); | |
1496 } | |
1497 } | |
1498 } | |
1499 | |
1500 /* | |
1157 | 1501 * If "regname" is a special register, return TRUE and store a pointer to its |
1502 * value in "argp". | |
7 | 1503 */ |
15 | 1504 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1505 get_spec_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1506 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1507 char_u **argp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1508 int *allocated, /* return: TRUE when value was allocated */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1509 int errmsg) /* give error message when failing */ |
7 | 1510 { |
1511 int cnt; | |
1512 | |
1513 *argp = NULL; | |
1514 *allocated = FALSE; | |
1515 switch (regname) | |
1516 { | |
1517 case '%': /* file name */ | |
1518 if (errmsg) | |
1519 check_fname(); /* will give emsg if not set */ | |
1520 *argp = curbuf->b_fname; | |
1521 return TRUE; | |
1522 | |
1523 case '#': /* alternate file name */ | |
1524 *argp = getaltfname(errmsg); /* may give emsg if not set */ | |
1525 return TRUE; | |
1526 | |
1527 #ifdef FEAT_EVAL | |
1528 case '=': /* result of expression */ | |
1529 *argp = get_expr_line(); | |
1530 *allocated = TRUE; | |
1531 return TRUE; | |
1532 #endif | |
1533 | |
1534 case ':': /* last command line */ | |
1535 if (last_cmdline == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1536 emsg(_(e_nolastcmd)); |
7 | 1537 *argp = last_cmdline; |
1538 return TRUE; | |
1539 | |
1540 case '/': /* last search-pattern */ | |
1541 if (last_search_pat() == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1542 emsg(_(e_noprevre)); |
7 | 1543 *argp = last_search_pat(); |
1544 return TRUE; | |
1545 | |
1546 case '.': /* last inserted text */ | |
1547 *argp = get_last_insert_save(); | |
1548 *allocated = TRUE; | |
1549 if (*argp == NULL && errmsg) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1550 emsg(_(e_noinstext)); |
7 | 1551 return TRUE; |
1552 | |
1553 #ifdef FEAT_SEARCHPATH | |
1554 case Ctrl_F: /* Filename under cursor */ | |
1555 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
1556 if (!errmsg) | |
1557 return FALSE; | |
1558 *argp = file_name_at_cursor(FNAME_MESS | FNAME_HYP | |
681 | 1559 | (regname == Ctrl_P ? FNAME_EXP : 0), 1L, NULL); |
7 | 1560 *allocated = TRUE; |
1561 return TRUE; | |
1562 #endif | |
1563 | |
1564 case Ctrl_W: /* word under cursor */ | |
1565 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
1566 if (!errmsg) | |
1567 return FALSE; | |
1568 cnt = find_ident_under_cursor(argp, regname == Ctrl_W | |
1569 ? (FIND_IDENT|FIND_STRING) : FIND_STRING); | |
1570 *argp = cnt ? vim_strnsave(*argp, cnt) : NULL; | |
1571 *allocated = TRUE; | |
1572 return TRUE; | |
1573 | |
13831
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1574 case Ctrl_L: /* Line under cursor */ |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1575 if (!errmsg) |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1576 return FALSE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1577 |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1578 *argp = ml_get_buf(curwin->w_buffer, |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1579 curwin->w_cursor.lnum, FALSE); |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1580 return TRUE; |
1f95ec5de238
patch 8.0.1787: cannot insert the whole cursor line
Christian Brabandt <cb@256bit.org>
parents:
13814
diff
changeset
|
1581 |
7 | 1582 case '_': /* black hole: always empty */ |
1583 *argp = (char_u *)""; | |
1584 return TRUE; | |
1585 } | |
1586 | |
1587 return FALSE; | |
1588 } | |
1589 | |
1590 /* | |
15 | 1591 * Paste a yank register into the command line. |
1592 * Only for non-special registers. | |
1593 * Used by CTRL-R command in command-line mode | |
7 | 1594 * insert_reg() can't be used here, because special characters from the |
1595 * register contents will be interpreted as commands. | |
1596 * | |
1597 * return FAIL for failure, OK otherwise | |
1598 */ | |
1599 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1600 cmdline_paste_reg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1601 int regname, |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1602 int literally_arg, /* Insert text literally instead of "as typed" */ |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1603 int remcr) /* don't add CR characters */ |
7 | 1604 { |
1605 long i; | |
13425
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1606 int literally = literally_arg; |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1607 |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1608 if (get_yank_register(regname, FALSE)) |
bb789ed5113a
patch 8.0.1587: inserting from the clipboard doesn't work literally
Christian Brabandt <cb@256bit.org>
parents:
13380
diff
changeset
|
1609 literally = TRUE; |
7 | 1610 if (y_current->y_array == NULL) |
1611 return FAIL; | |
1612 | |
1613 for (i = 0; i < y_current->y_size; ++i) | |
1614 { | |
1615 cmdline_paste_str(y_current->y_array[i], literally); | |
1616 | |
1015 | 1617 /* Insert ^M between lines and after last line if type is MLINE. |
7336
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
1618 * Don't do this when "remcr" is TRUE. */ |
4c5f53a60543
commit https://github.com/vim/vim/commit/6f62fed349bf829da2adb02619dc9acba13c8ab6
Christian Brabandt <cb@256bit.org>
parents:
7233
diff
changeset
|
1619 if ((y_current->y_type == MLINE || i < y_current->y_size - 1) && !remcr) |
7 | 1620 cmdline_paste_str((char_u *)"\r", literally); |
1621 | |
1622 /* Check for CTRL-C, in case someone tries to paste a few thousand | |
1623 * lines and gets bored. */ | |
1624 ui_breakcheck(); | |
1625 if (got_int) | |
1626 return FAIL; | |
1627 } | |
1628 return OK; | |
1629 } | |
1630 | |
1631 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
1632 /* | |
1633 * Adjust the register name pointed to with "rp" for the clipboard being | |
1634 * used always and the clipboard being available. | |
1635 */ | |
1636 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1637 adjust_clip_reg(int *rp) |
7 | 1638 { |
2654 | 1639 /* If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard', |
1640 * use '*' or '+' reg, respectively. "unnamedplus" prevails. */ | |
6116 | 1641 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0)) |
1642 { | |
1643 if (clip_unnamed != 0) | |
1644 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
2654 | 1645 ? '+' : '*'; |
6116 | 1646 else |
1647 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS) && clip_plus.available) | |
1648 ? '+' : '*'; | |
1649 } | |
7 | 1650 if (!clip_star.available && *rp == '*') |
1651 *rp = 0; | |
1652 if (!clip_plus.available && *rp == '+') | |
1653 *rp = 0; | |
1654 } | |
1655 #endif | |
1656 | |
1657 /* | |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1658 * Shift the delete registers: "9 is cleared, "8 becomes "9, etc. |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1659 */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1660 void |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1661 shift_delete_registers() |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1662 { |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1663 int n; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1664 |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1665 y_current = &y_regs[9]; |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1666 free_yank_all(); /* free register nine */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1667 for (n = 9; n > 1; --n) |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1668 y_regs[n] = y_regs[n - 1]; |
11597
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1669 y_current = &y_regs[1]; |
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1670 if (!y_append) |
72b20190dce6
patch 8.0.0681: unnamed register only contains the last deleted text
Christian Brabandt <cb@256bit.org>
parents:
11273
diff
changeset
|
1671 y_previous = y_current; |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1672 y_regs[1].y_array = NULL; /* set register one to empty */ |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1673 } |
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1674 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1675 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1676 static void |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1677 yank_do_autocmd(oparg_T *oap, yankreg_T *reg) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1678 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1679 static int recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1680 dict_T *v_event; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1681 list_T *list; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1682 int n; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1683 char_u buf[NUMBUFLEN + 2]; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1684 long reglen = 0; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1685 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1686 if (recursive) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1687 return; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1688 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1689 v_event = get_vim_var_dict(VV_EVENT); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1690 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1691 list = list_alloc(); |
13254
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1692 if (list == NULL) |
88cc06dc1a50
patch 8.0.1501: out-of-memory situation not correctly handled
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1693 return; |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1694 for (n = 0; n < reg->y_size; n++) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1695 list_append_string(list, reg->y_array[n], -1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1696 list->lv_lock = VAR_FIXED; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1697 dict_add_list(v_event, "regcontents", list); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1698 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1699 buf[0] = (char_u)oap->regname; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1700 buf[1] = NUL; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1701 dict_add_string(v_event, "regname", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1702 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1703 buf[0] = get_op_char(oap->op_type); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1704 buf[1] = get_extra_op_char(oap->op_type); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1705 buf[2] = NUL; |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1706 dict_add_string(v_event, "operator", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1707 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1708 buf[0] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1709 buf[1] = NUL; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1710 switch (get_reg_type(oap->regname, ®len)) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1711 { |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1712 case MLINE: buf[0] = 'V'; break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1713 case MCHAR: buf[0] = 'v'; break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1714 case MBLOCK: |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1715 vim_snprintf((char *)buf, sizeof(buf), "%c%ld", Ctrl_V, |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1716 reglen + 1); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1717 break; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1718 } |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
1719 dict_add_string(v_event, "regtype", buf); |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1720 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1721 /* Lock the dictionary and its keys */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1722 dict_set_items_ro(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1723 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1724 recursive = TRUE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1725 textlock++; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1726 apply_autocmds(EVENT_TEXTYANKPOST, NULL, NULL, FALSE, curbuf); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1727 textlock--; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1728 recursive = FALSE; |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1729 |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1730 /* Empty the dictionary, v:event is still valid */ |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1731 dict_free_contents(v_event); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1732 hash_init(&v_event->dv_hashtab); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1733 } |
13047
669c4f75a69e
patch 8.0.1399: warnings and errors when building tiny version
Christian Brabandt <cb@256bit.org>
parents:
13037
diff
changeset
|
1734 #endif |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1735 |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1736 /* |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1737 * Handle a delete operation. |
7 | 1738 * |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1739 * Return FAIL if undo failed, OK otherwise. |
7 | 1740 */ |
1741 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
1742 op_delete(oparg_T *oap) |
7 | 1743 { |
1744 int n; | |
1745 linenr_T lnum; | |
1746 char_u *ptr; | |
1747 char_u *newp, *oldp; | |
1748 struct block_def bd; | |
1749 linenr_T old_lcount = curbuf->b_ml.ml_line_count; | |
1750 int did_yank = FALSE; | |
1751 | |
1752 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */ | |
1753 return OK; | |
1754 | |
1755 /* Nothing to delete, return here. Do prepare undo, for op_change(). */ | |
1756 if (oap->empty) | |
1757 return u_save_cursor(); | |
1758 | |
1759 if (!curbuf->b_p_ma) | |
1760 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1761 emsg(_(e_modifiable)); |
7 | 1762 return FAIL; |
1763 } | |
1764 | |
1765 #ifdef FEAT_CLIPBOARD | |
1766 adjust_clip_reg(&oap->regname); | |
1767 #endif | |
1768 | |
1769 if (has_mbyte) | |
1770 mb_adjust_opend(oap); | |
1771 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1772 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1773 * Imitate the strange Vi behaviour: If the delete spans more than one |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1774 * line and motion_type == MCHAR and the result is a blank line, make the |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1775 * delete linewise. Don't do this for the change command or Visual mode. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1776 */ |
7 | 1777 if ( oap->motion_type == MCHAR |
1778 && !oap->is_VIsual | |
50 | 1779 && !oap->block_mode |
7 | 1780 && oap->line_count > 1 |
3254 | 1781 && oap->motion_force == NUL |
7 | 1782 && oap->op_type == OP_DELETE) |
1783 { | |
2957 | 1784 ptr = ml_get(oap->end.lnum) + oap->end.col; |
1785 if (*ptr != NUL) | |
1786 ptr += oap->inclusive; | |
7 | 1787 ptr = skipwhite(ptr); |
1788 if (*ptr == NUL && inindent(0)) | |
1789 oap->motion_type = MLINE; | |
1790 } | |
1791 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1792 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1793 * Check for trying to delete (e.g. "D") in an empty line. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1794 * Note: For the change operator it is ok. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1795 */ |
7 | 1796 if ( oap->motion_type == MCHAR |
1797 && oap->line_count == 1 | |
1798 && oap->op_type == OP_DELETE | |
1799 && *ml_get(oap->start.lnum) == NUL) | |
1800 { | |
1801 /* | |
446 | 1802 * It's an error to operate on an empty region, when 'E' included in |
7 | 1803 * 'cpoptions' (Vi compatible). |
1804 */ | |
446 | 1805 if (virtual_op) |
1806 /* Virtual editing: Nothing gets deleted, but we set the '[ and '] | |
1807 * marks as if it happened. */ | |
1808 goto setmarks; | |
7 | 1809 if (vim_strchr(p_cpo, CPO_EMPTYREGION) != NULL) |
1810 beep_flush(); | |
1811 return OK; | |
1812 } | |
1813 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1814 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1815 * Do a yank of whatever we're about to delete. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1816 * If a yank register was specified, put the deleted text into that |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1817 * register. For the black hole register '_' don't yank anything. |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1818 */ |
7 | 1819 if (oap->regname != '_') |
1820 { | |
1821 if (oap->regname != 0) | |
1822 { | |
1823 /* check for read-only register */ | |
1824 if (!valid_yank_reg(oap->regname, TRUE)) | |
1825 { | |
1826 beep_flush(); | |
1827 return OK; | |
1828 } | |
1829 get_yank_register(oap->regname, TRUE); /* yank into specif'd reg. */ | |
1830 if (op_yank(oap, TRUE, FALSE) == OK) /* yank without message */ | |
1831 did_yank = TRUE; | |
1832 } | |
1833 | |
1834 /* | |
1835 * Put deleted text into register 1 and shift number registers if the | |
15987
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
1836 * delete contains a line break, or when using a specific operator (Vi |
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
1837 * compatible) |
3782 | 1838 * Use the register name from before adjust_clip_reg() may have |
1839 * changed it. | |
7 | 1840 */ |
15987
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
1841 if (oap->motion_type == MLINE || oap->line_count > 1 |
29de75f53b1a
patch 8.1.0999: use register one too often and not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
15967
diff
changeset
|
1842 || oap->use_reg_one) |
7 | 1843 { |
10827
e366b968bf08
patch 8.0.0303: bracketed paste does not work in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10803
diff
changeset
|
1844 shift_delete_registers(); |
7 | 1845 if (op_yank(oap, TRUE, FALSE) == OK) |
1846 did_yank = TRUE; | |
1847 } | |
1848 | |
3468 | 1849 /* Yank into small delete register when no named register specified |
1850 * and the delete is within one line. */ | |
1851 if (( | |
1852 #ifdef FEAT_CLIPBOARD | |
3584 | 1853 ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') || |
1854 ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') || | |
3468 | 1855 #endif |
1856 oap->regname == 0) && oap->motion_type != MLINE | |
7 | 1857 && oap->line_count == 1) |
1858 { | |
1859 oap->regname = '-'; | |
1860 get_yank_register(oap->regname, TRUE); | |
1861 if (op_yank(oap, TRUE, FALSE) == OK) | |
1862 did_yank = TRUE; | |
1863 oap->regname = 0; | |
1864 } | |
1865 | |
1866 /* | |
1867 * If there's too much stuff to fit in the yank register, then get a | |
1868 * confirmation before doing the delete. This is crude, but simple. | |
1869 * And it avoids doing a delete of something we can't put back if we | |
1870 * want. | |
1871 */ | |
1872 if (!did_yank) | |
1873 { | |
1874 int msg_silent_save = msg_silent; | |
1875 | |
1876 msg_silent = 0; /* must display the prompt */ | |
1877 n = ask_yesno((char_u *)_("cannot yank; delete anyway"), TRUE); | |
1878 msg_silent = msg_silent_save; | |
1879 if (n != 'y') | |
1880 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
1881 emsg(_(e_abort)); |
7 | 1882 return FAIL; |
1883 } | |
1884 } | |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1885 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
1886 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1887 if (did_yank && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1888 yank_do_autocmd(oap, y_current); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
1889 #endif |
7 | 1890 } |
1891 | |
2289
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1892 /* |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1893 * block mode delete |
3331756e4232
Make synstack() work on the character just after the end of the line.
Bram Moolenaar <bram@vim.org>
parents:
2278
diff
changeset
|
1894 */ |
7 | 1895 if (oap->block_mode) |
1896 { | |
1897 if (u_save((linenr_T)(oap->start.lnum - 1), | |
1898 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
1899 return FAIL; | |
1900 | |
1901 for (lnum = curwin->w_cursor.lnum; lnum <= oap->end.lnum; ++lnum) | |
1902 { | |
1903 block_prep(oap, &bd, lnum, TRUE); | |
1904 if (bd.textlen == 0) /* nothing to delete */ | |
1905 continue; | |
1906 | |
1907 /* Adjust cursor position for tab replaced by spaces and 'lbr'. */ | |
1908 if (lnum == curwin->w_cursor.lnum) | |
1909 { | |
1910 curwin->w_cursor.col = bd.textcol + bd.startspaces; | |
1911 curwin->w_cursor.coladd = 0; | |
1912 } | |
1913 | |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
1914 // "n" == number of chars deleted |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
1915 // If we delete a TAB, it may be replaced by several characters. |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
1916 // Thus the number of characters may increase! |
7 | 1917 n = bd.textlen - bd.startspaces - bd.endspaces; |
1918 oldp = ml_get(lnum); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
1919 newp = alloc(STRLEN(oldp) + 1 - n); |
7 | 1920 if (newp == NULL) |
1921 continue; | |
1922 /* copy up to deleted part */ | |
1923 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
1924 /* insert spaces */ | |
6929 | 1925 vim_memset(newp + bd.textcol, ' ', |
7 | 1926 (size_t)(bd.startspaces + bd.endspaces)); |
1927 /* copy the part after the deleted part */ | |
1928 oldp += bd.textcol + bd.textlen; | |
1622 | 1929 STRMOVE(newp + bd.textcol + bd.startspaces + bd.endspaces, oldp); |
7 | 1930 /* replace the line */ |
1931 ml_replace(lnum, newp, FALSE); | |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
1932 |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
1933 #ifdef FEAT_TEXT_PROP |
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
1934 if (curbuf->b_has_textprop && n != 0) |
16714
ba592f30c082
patch 8.1.1359: text property wrong after :substitute with backslash
Bram Moolenaar <Bram@vim.org>
parents:
16706
diff
changeset
|
1935 adjust_prop_columns(lnum, bd.textcol, -n, 0); |
16682
7847d281cbbf
patch 8.1.1343: text properties not adjusted for Visual block mode delete
Bram Moolenaar <Bram@vim.org>
parents:
16680
diff
changeset
|
1936 #endif |
7 | 1937 } |
1938 | |
1939 check_cursor_col(); | |
1940 changed_lines(curwin->w_cursor.lnum, curwin->w_cursor.col, | |
1941 oap->end.lnum + 1, 0L); | |
1942 oap->line_count = 0; /* no lines deleted */ | |
1943 } | |
5735 | 1944 else if (oap->motion_type == MLINE) |
7 | 1945 { |
1946 if (oap->op_type == OP_CHANGE) | |
1947 { | |
1948 /* Delete the lines except the first one. Temporarily move the | |
1949 * cursor to the next line. Save the current line number, if the | |
1950 * last line is deleted it may be changed. | |
1951 */ | |
1952 if (oap->line_count > 1) | |
1953 { | |
1954 lnum = curwin->w_cursor.lnum; | |
1955 ++curwin->w_cursor.lnum; | |
1956 del_lines((long)(oap->line_count - 1), TRUE); | |
1957 curwin->w_cursor.lnum = lnum; | |
1958 } | |
1959 if (u_save_cursor() == FAIL) | |
1960 return FAIL; | |
1961 if (curbuf->b_p_ai) /* don't delete indent */ | |
1962 { | |
1963 beginline(BL_WHITE); /* cursor on first non-white */ | |
1964 did_ai = TRUE; /* delete the indent when ESC hit */ | |
1965 ai_col = curwin->w_cursor.col; | |
1966 } | |
1967 else | |
1968 beginline(0); /* cursor in column 0 */ | |
1969 truncate_line(FALSE); /* delete the rest of the line */ | |
1970 /* leave cursor past last char in line */ | |
1971 if (oap->line_count > 1) | |
1972 u_clearline(); /* "U" command not possible after "2cc" */ | |
1973 } | |
1974 else | |
1975 { | |
1976 del_lines(oap->line_count, TRUE); | |
1977 beginline(BL_WHITE | BL_FIX); | |
1978 u_clearline(); /* "U" command not possible after "dd" */ | |
1979 } | |
1980 } | |
1981 else | |
1982 { | |
1983 if (virtual_op) | |
1984 { | |
1985 int endcol = 0; | |
1986 | |
1987 /* For virtualedit: break the tabs that are partly included. */ | |
1988 if (gchar_pos(&oap->start) == '\t') | |
1989 { | |
1990 if (u_save_cursor() == FAIL) /* save first line for undo */ | |
1991 return FAIL; | |
1992 if (oap->line_count == 1) | |
1993 endcol = getviscol2(oap->end.col, oap->end.coladd); | |
1994 coladvance_force(getviscol2(oap->start.col, oap->start.coladd)); | |
1995 oap->start = curwin->w_cursor; | |
1996 if (oap->line_count == 1) | |
1997 { | |
1998 coladvance(endcol); | |
1999 oap->end.col = curwin->w_cursor.col; | |
2000 oap->end.coladd = curwin->w_cursor.coladd; | |
2001 curwin->w_cursor = oap->start; | |
2002 } | |
2003 } | |
2004 | |
2005 /* Break a tab only when it's included in the area. */ | |
2006 if (gchar_pos(&oap->end) == '\t' | |
2007 && (int)oap->end.coladd < oap->inclusive) | |
2008 { | |
2009 /* save last line for undo */ | |
2010 if (u_save((linenr_T)(oap->end.lnum - 1), | |
2011 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2012 return FAIL; | |
2013 curwin->w_cursor = oap->end; | |
2014 coladvance_force(getviscol2(oap->end.col, oap->end.coladd)); | |
2015 oap->end = curwin->w_cursor; | |
2016 curwin->w_cursor = oap->start; | |
2017 } | |
2018 } | |
2019 | |
2020 if (oap->line_count == 1) /* delete characters within one line */ | |
2021 { | |
2022 if (u_save_cursor() == FAIL) /* save line for undo */ | |
2023 return FAIL; | |
2024 | |
2025 /* if 'cpoptions' contains '$', display '$' at end of change */ | |
5735 | 2026 if ( vim_strchr(p_cpo, CPO_DOLLAR) != NULL |
7 | 2027 && oap->op_type == OP_CHANGE |
2028 && oap->end.lnum == curwin->w_cursor.lnum | |
5735 | 2029 && !oap->is_VIsual) |
7 | 2030 display_dollar(oap->end.col - !oap->inclusive); |
2031 | |
2032 n = oap->end.col - oap->start.col + 1 - !oap->inclusive; | |
2033 | |
2034 if (virtual_op) | |
2035 { | |
2036 /* fix up things for virtualedit-delete: | |
2037 * break the tabs which are going to get in our way | |
2038 */ | |
2039 char_u *curline = ml_get_curline(); | |
2040 int len = (int)STRLEN(curline); | |
2041 | |
2042 if (oap->end.coladd != 0 | |
2043 && (int)oap->end.col >= len - 1 | |
2044 && !(oap->start.coladd && (int)oap->end.col >= len - 1)) | |
2045 n++; | |
2046 /* Delete at least one char (e.g, when on a control char). */ | |
2047 if (n == 0 && oap->start.coladd != oap->end.coladd) | |
2048 n = 1; | |
2049 | |
2050 /* When deleted a char in the line, reset coladd. */ | |
2051 if (gchar_cursor() != NUL) | |
2052 curwin->w_cursor.coladd = 0; | |
2053 } | |
6826 | 2054 (void)del_bytes((long)n, !virtual_op, |
2055 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
7 | 2056 } |
2057 else /* delete characters between lines */ | |
2058 { | |
2059 pos_T curpos; | |
2060 | |
2061 /* save deleted and changed lines for undo */ | |
2062 if (u_save((linenr_T)(curwin->w_cursor.lnum - 1), | |
2063 (linenr_T)(curwin->w_cursor.lnum + oap->line_count)) == FAIL) | |
2064 return FAIL; | |
2065 | |
2066 truncate_line(TRUE); /* delete from cursor to end of line */ | |
2067 | |
2068 curpos = curwin->w_cursor; /* remember curwin->w_cursor */ | |
2069 ++curwin->w_cursor.lnum; | |
2070 del_lines((long)(oap->line_count - 2), FALSE); | |
2071 | |
6826 | 2072 /* delete from start of line until op_end */ |
2957 | 2073 n = (oap->end.col + 1 - !oap->inclusive); |
6826 | 2074 curwin->w_cursor.col = 0; |
2075 (void)del_bytes((long)n, !virtual_op, | |
2076 oap->op_type == OP_DELETE && !oap->is_VIsual); | |
2077 curwin->w_cursor = curpos; /* restore curwin->w_cursor */ | |
2078 (void)do_join(2, FALSE, FALSE, FALSE, FALSE); | |
7 | 2079 } |
2080 } | |
2081 | |
2082 msgmore(curbuf->b_ml.ml_line_count - old_lcount); | |
2083 | |
446 | 2084 setmarks: |
7 | 2085 if (oap->block_mode) |
2086 { | |
2087 curbuf->b_op_end.lnum = oap->end.lnum; | |
2088 curbuf->b_op_end.col = oap->start.col; | |
2089 } | |
2090 else | |
2091 curbuf->b_op_end = oap->start; | |
2092 curbuf->b_op_start = oap->start; | |
2093 | |
2094 return OK; | |
2095 } | |
2096 | |
2097 /* | |
2098 * Adjust end of operating area for ending on a multi-byte character. | |
2099 * Used for deletion. | |
2100 */ | |
2101 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2102 mb_adjust_opend(oparg_T *oap) |
7 | 2103 { |
2104 char_u *p; | |
2105 | |
2106 if (oap->inclusive) | |
2107 { | |
2108 p = ml_get(oap->end.lnum); | |
2109 oap->end.col += mb_tail_off(p, p + oap->end.col); | |
2110 } | |
2111 } | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
2112 |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2113 /* |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2114 * Replace the character under the cursor with "c". |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2115 * This takes care of multi-byte characters. |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2116 */ |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2117 static void |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2118 replace_character(int c) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2119 { |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2120 int n = State; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2121 |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2122 State = REPLACE; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2123 ins_char(c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2124 State = n; |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2125 /* Backup to the replaced character. */ |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2126 dec_cursor(); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2127 } |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
2128 |
7 | 2129 /* |
2130 * Replace a whole area with one character. | |
2131 */ | |
2132 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2133 op_replace(oparg_T *oap, int c) |
7 | 2134 { |
2135 int n, numc; | |
2136 int num_chars; | |
2137 char_u *newp, *oldp; | |
2138 size_t oldlen; | |
2139 struct block_def bd; | |
5428 | 2140 char_u *after_p = NULL; |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2141 int had_ctrl_v_cr = FALSE; |
7 | 2142 |
2143 if ((curbuf->b_ml.ml_flags & ML_EMPTY ) || oap->empty) | |
2144 return OK; /* nothing to do */ | |
2145 | |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2146 if (c == REPLACE_CR_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2147 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2148 had_ctrl_v_cr = TRUE; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2149 c = CAR; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2150 } |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2151 else if (c == REPLACE_NL_NCHAR) |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2152 { |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2153 had_ctrl_v_cr = TRUE; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2154 c = NL; |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2155 } |
5428 | 2156 |
7 | 2157 if (has_mbyte) |
2158 mb_adjust_opend(oap); | |
2159 | |
2160 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2161 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2162 return FAIL; | |
2163 | |
2164 /* | |
2165 * block mode replace | |
2166 */ | |
2167 if (oap->block_mode) | |
2168 { | |
2169 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2170 for ( ; curwin->w_cursor.lnum <= oap->end.lnum; ++curwin->w_cursor.lnum) | |
2171 { | |
1982 | 2172 curwin->w_cursor.col = 0; /* make sure cursor position is valid */ |
7 | 2173 block_prep(oap, &bd, curwin->w_cursor.lnum, TRUE); |
2174 if (bd.textlen == 0 && (!virtual_op || bd.is_MAX)) | |
2175 continue; /* nothing to replace */ | |
2176 | |
2177 /* n == number of extra chars required | |
2178 * If we split a TAB, it may be replaced by several characters. | |
2179 * Thus the number of characters may increase! | |
2180 */ | |
2181 /* If the range starts in virtual space, count the initial | |
2182 * coladd offset as part of "startspaces" */ | |
2183 if (virtual_op && bd.is_short && *bd.textstart == NUL) | |
2184 { | |
2185 pos_T vpos; | |
2186 | |
1982 | 2187 vpos.lnum = curwin->w_cursor.lnum; |
7 | 2188 getvpos(&vpos, oap->start_vcol); |
2189 bd.startspaces += vpos.coladd; | |
2190 n = bd.startspaces; | |
2191 } | |
2192 else | |
2193 /* allow for pre spaces */ | |
2194 n = (bd.startspaces ? bd.start_char_vcols - 1 : 0); | |
2195 | |
2196 /* allow for post spp */ | |
2197 n += (bd.endspaces | |
2198 && !bd.is_oneChar | |
2199 && bd.end_char_vcols > 0) ? bd.end_char_vcols - 1 : 0; | |
2200 /* Figure out how many characters to replace. */ | |
2201 numc = oap->end_vcol - oap->start_vcol + 1; | |
2202 if (bd.is_short && (!virtual_op || bd.is_MAX)) | |
2203 numc -= (oap->end_vcol - bd.end_vcol) + 1; | |
2204 | |
2205 /* A double-wide character can be replaced only up to half the | |
2206 * times. */ | |
2207 if ((*mb_char2cells)(c) > 1) | |
2208 { | |
2209 if ((numc & 1) && !bd.is_short) | |
2210 { | |
2211 ++bd.endspaces; | |
2212 ++n; | |
2213 } | |
2214 numc = numc / 2; | |
2215 } | |
2216 | |
2217 /* Compute bytes needed, move character count to num_chars. */ | |
2218 num_chars = numc; | |
2219 numc *= (*mb_char2len)(c); | |
2220 /* oldlen includes textlen, so don't double count */ | |
2221 n += numc - bd.textlen; | |
2222 | |
2223 oldp = ml_get_curline(); | |
2224 oldlen = STRLEN(oldp); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
2225 newp = alloc(oldlen + 1 + n); |
7 | 2226 if (newp == NULL) |
2227 continue; | |
2228 vim_memset(newp, NUL, (size_t)(oldlen + 1 + n)); | |
2229 /* copy up to deleted part */ | |
2230 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2231 oldp += bd.textcol + bd.textlen; | |
2232 /* insert pre-spaces */ | |
6929 | 2233 vim_memset(newp + bd.textcol, ' ', (size_t)bd.startspaces); |
7 | 2234 /* insert replacement chars CHECK FOR ALLOCATED SPACE */ |
13202
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2235 /* REPLACE_CR_NCHAR/REPLACE_NL_NCHAR is used for entering CR |
2941a86f8aaa
patch 8.0.1475: invalid memory access in read_redo()
Christian Brabandt <cb@256bit.org>
parents:
13072
diff
changeset
|
2236 * literally. */ |
5428 | 2237 if (had_ctrl_v_cr || (c != '\r' && c != '\n')) |
7 | 2238 { |
5428 | 2239 if (has_mbyte) |
2240 { | |
2241 n = (int)STRLEN(newp); | |
2242 while (--num_chars >= 0) | |
2243 n += (*mb_char2bytes)(c, newp + n); | |
2244 } | |
2245 else | |
6929 | 2246 vim_memset(newp + STRLEN(newp), c, (size_t)numc); |
5428 | 2247 if (!bd.is_short) |
2248 { | |
2249 /* insert post-spaces */ | |
6929 | 2250 vim_memset(newp + STRLEN(newp), ' ', (size_t)bd.endspaces); |
5428 | 2251 /* copy the part after the changed part */ |
2252 STRMOVE(newp + STRLEN(newp), oldp); | |
2253 } | |
7 | 2254 } |
2255 else | |
2256 { | |
5428 | 2257 /* Replacing with \r or \n means splitting the line. */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
2258 after_p = alloc(oldlen + 1 + n - STRLEN(newp)); |
5428 | 2259 if (after_p != NULL) |
2260 STRMOVE(after_p, oldp); | |
7 | 2261 } |
2262 /* replace the line */ | |
2263 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
5428 | 2264 if (after_p != NULL) |
2265 { | |
2266 ml_append(curwin->w_cursor.lnum++, after_p, 0, FALSE); | |
2267 appended_lines_mark(curwin->w_cursor.lnum, 1L); | |
2268 oap->end.lnum++; | |
2269 vim_free(after_p); | |
2270 } | |
7 | 2271 } |
2272 } | |
2273 else | |
2274 { | |
2275 /* | |
2276 * MCHAR and MLINE motion replace. | |
2277 */ | |
2278 if (oap->motion_type == MLINE) | |
2279 { | |
2280 oap->start.col = 0; | |
2281 curwin->w_cursor.col = 0; | |
2282 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2283 if (oap->end.col) | |
2284 --oap->end.col; | |
2285 } | |
2286 else if (!oap->inclusive) | |
2287 dec(&(oap->end)); | |
2288 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2289 while (LTOREQ_POS(curwin->w_cursor, oap->end)) |
7 | 2290 { |
2291 n = gchar_cursor(); | |
2292 if (n != NUL) | |
2293 { | |
2294 if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) | |
2295 { | |
2296 /* This is slow, but it handles replacing a single-byte | |
2297 * with a multi-byte and the other way around. */ | |
4203 | 2298 if (curwin->w_cursor.lnum == oap->end.lnum) |
2299 oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2300 replace_character(c); |
7 | 2301 } |
2302 else | |
2303 { | |
2304 if (n == TAB) | |
2305 { | |
2306 int end_vcol = 0; | |
2307 | |
2308 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2309 { | |
2310 /* oap->end has to be recalculated when | |
2311 * the tab breaks */ | |
2312 end_vcol = getviscol2(oap->end.col, | |
2313 oap->end.coladd); | |
2314 } | |
2315 coladvance_force(getviscol()); | |
2316 if (curwin->w_cursor.lnum == oap->end.lnum) | |
2317 getvpos(&oap->end, end_vcol); | |
2318 } | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2319 PBYTE(curwin->w_cursor, c); |
7 | 2320 } |
2321 } | |
2322 else if (virtual_op && curwin->w_cursor.lnum == oap->end.lnum) | |
2323 { | |
2324 int virtcols = oap->end.coladd; | |
2325 | |
2326 if (curwin->w_cursor.lnum == oap->start.lnum | |
2327 && oap->start.col == oap->end.col && oap->start.coladd) | |
2328 virtcols -= oap->start.coladd; | |
2329 | |
2330 /* oap->end has been trimmed so it's effectively inclusive; | |
2331 * as a result an extra +1 must be counted so we don't | |
2332 * trample the NUL byte. */ | |
2333 coladvance_force(getviscol2(oap->end.col, oap->end.coladd) + 1); | |
2334 curwin->w_cursor.col -= (virtcols + 1); | |
2335 for (; virtcols >= 0; virtcols--) | |
2336 { | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2337 if ((*mb_char2len)(c) > 1) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2338 replace_character(c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2339 else |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2340 PBYTE(curwin->w_cursor, c); |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2341 if (inc(&curwin->w_cursor) == -1) |
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2342 break; |
7 | 2343 } |
2344 } | |
2345 | |
2346 /* Advance to next character, stop at the end of the file. */ | |
2347 if (inc_cursor() == -1) | |
2348 break; | |
2349 } | |
2350 } | |
2351 | |
2352 curwin->w_cursor = oap->start; | |
2353 check_cursor(); | |
2354 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, 0L); | |
2355 | |
2356 /* Set "'[" and "']" marks. */ | |
2357 curbuf->b_op_start = oap->start; | |
2358 curbuf->b_op_end = oap->end; | |
2359 | |
2360 return OK; | |
2361 } | |
2362 | |
7805
0b6c37dd858d
commit https://github.com/vim/vim/commit/baaa7e9ec7398a813e21285c272fa99792642077
Christian Brabandt <cb@256bit.org>
parents:
7576
diff
changeset
|
2363 static int swapchars(int op_type, pos_T *pos, int length); |
1525 | 2364 |
7 | 2365 /* |
2366 * Handle the (non-standard vi) tilde operator. Also for "gu", "gU" and "g?". | |
2367 */ | |
2368 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2369 op_tilde(oparg_T *oap) |
7 | 2370 { |
2371 pos_T pos; | |
2372 struct block_def bd; | |
1528 | 2373 int did_change = FALSE; |
7 | 2374 |
2375 if (u_save((linenr_T)(oap->start.lnum - 1), | |
2376 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
2377 return; | |
2378 | |
2379 pos = oap->start; | |
2380 if (oap->block_mode) /* Visual block mode */ | |
2381 { | |
2382 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) | |
2383 { | |
1766 | 2384 int one_change; |
2385 | |
7 | 2386 block_prep(oap, &bd, pos.lnum, FALSE); |
2387 pos.col = bd.textcol; | |
1766 | 2388 one_change = swapchars(oap->op_type, &pos, bd.textlen); |
2389 did_change |= one_change; | |
1525 | 2390 |
5735 | 2391 #ifdef FEAT_NETBEANS_INTG |
2210 | 2392 if (netbeans_active() && one_change) |
7 | 2393 { |
2394 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2395 | |
33 | 2396 netbeans_removed(curbuf, pos.lnum, bd.textcol, |
2397 (long)bd.textlen); | |
7 | 2398 netbeans_inserted(curbuf, pos.lnum, bd.textcol, |
2210 | 2399 &ptr[bd.textcol], bd.textlen); |
7 | 2400 } |
5735 | 2401 #endif |
7 | 2402 } |
2403 if (did_change) | |
2404 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); | |
2405 } | |
2406 else /* not block mode */ | |
2407 { | |
2408 if (oap->motion_type == MLINE) | |
2409 { | |
2410 oap->start.col = 0; | |
2411 pos.col = 0; | |
2412 oap->end.col = (colnr_T)STRLEN(ml_get(oap->end.lnum)); | |
2413 if (oap->end.col) | |
2414 --oap->end.col; | |
2415 } | |
2416 else if (!oap->inclusive) | |
2417 dec(&(oap->end)); | |
2418 | |
1528 | 2419 if (pos.lnum == oap->end.lnum) |
2420 did_change = swapchars(oap->op_type, &pos, | |
2421 oap->end.col - pos.col + 1); | |
2422 else | |
2423 for (;;) | |
2424 { | |
2425 did_change |= swapchars(oap->op_type, &pos, | |
2426 pos.lnum == oap->end.lnum ? oap->end.col + 1: | |
2427 (int)STRLEN(ml_get_pos(&pos))); | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2428 if (LTOREQ_POS(oap->end, pos) || inc(&pos) == -1) |
1528 | 2429 break; |
2430 } | |
7 | 2431 if (did_change) |
2432 { | |
2433 changed_lines(oap->start.lnum, oap->start.col, oap->end.lnum + 1, | |
2434 0L); | |
2435 #ifdef FEAT_NETBEANS_INTG | |
2210 | 2436 if (netbeans_active() && did_change) |
7 | 2437 { |
2438 char_u *ptr; | |
2439 int count; | |
2440 | |
2441 pos = oap->start; | |
2442 while (pos.lnum < oap->end.lnum) | |
2443 { | |
2444 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
835 | 2445 count = (int)STRLEN(ptr) - pos.col; |
33 | 2446 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2447 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2448 &ptr[pos.col], count); |
7 | 2449 pos.col = 0; |
2450 pos.lnum++; | |
2451 } | |
2452 ptr = ml_get_buf(curbuf, pos.lnum, FALSE); | |
2453 count = oap->end.col - pos.col + 1; | |
33 | 2454 netbeans_removed(curbuf, pos.lnum, pos.col, (long)count); |
7 | 2455 netbeans_inserted(curbuf, pos.lnum, pos.col, |
2210 | 2456 &ptr[pos.col], count); |
7 | 2457 } |
2458 #endif | |
2459 } | |
2460 } | |
2461 | |
2462 if (!did_change && oap->is_VIsual) | |
2463 /* No change: need to remove the Visual selection */ | |
2464 redraw_curbuf_later(INVERTED); | |
2465 | |
2466 /* | |
2467 * Set '[ and '] marks. | |
2468 */ | |
2469 curbuf->b_op_start = oap->start; | |
2470 curbuf->b_op_end = oap->end; | |
2471 | |
2472 if (oap->line_count > p_report) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
2473 smsg(NGETTEXT("%ld line changed", "%ld lines changed", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
2474 oap->line_count), oap->line_count); |
7 | 2475 } |
2476 | |
2477 /* | |
1525 | 2478 * Invoke swapchar() on "length" bytes at position "pos". |
2479 * "pos" is advanced to just after the changed characters. | |
2480 * "length" is rounded up to include the whole last multi-byte character. | |
2481 * Also works correctly when the number of bytes changes. | |
2482 * Returns TRUE if some character was changed. | |
2483 */ | |
2484 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2485 swapchars(int op_type, pos_T *pos, int length) |
1525 | 2486 { |
2487 int todo; | |
2488 int did_change = 0; | |
2489 | |
2490 for (todo = length; todo > 0; --todo) | |
2491 { | |
2492 if (has_mbyte) | |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2493 { |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2494 int len = (*mb_ptr2len)(ml_get_pos(pos)); |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2495 |
1525 | 2496 /* we're counting bytes, not characters */ |
5288
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2497 if (len > 0) |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2498 todo -= len - 1; |
46cf49cc9289
updated for version 7.4b.020
Bram Moolenaar <bram@vim.org>
parents:
5245
diff
changeset
|
2499 } |
1525 | 2500 did_change |= swapchar(op_type, pos); |
2501 if (inc(pos) == -1) /* at end of file */ | |
2502 break; | |
2503 } | |
2504 return did_change; | |
2505 } | |
2506 | |
2507 /* | |
7 | 2508 * If op_type == OP_UPPER: make uppercase, |
2509 * if op_type == OP_LOWER: make lowercase, | |
2510 * if op_type == OP_ROT13: do rot13 encoding, | |
2511 * else swap case of character at 'pos' | |
2512 * returns TRUE when something actually changed. | |
2513 */ | |
2514 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2515 swapchar(int op_type, pos_T *pos) |
7 | 2516 { |
2517 int c; | |
2518 int nc; | |
2519 | |
2520 c = gchar_pos(pos); | |
2521 | |
2522 /* Only do rot13 encoding for ASCII characters. */ | |
2523 if (c >= 0x80 && op_type == OP_ROT13) | |
2524 return FALSE; | |
2525 | |
1525 | 2526 if (op_type == OP_UPPER && c == 0xdf |
2527 && (enc_latin1like || STRCMP(p_enc, "iso-8859-2") == 0)) | |
493 | 2528 { |
2529 pos_T sp = curwin->w_cursor; | |
2530 | |
2531 /* Special handling of German sharp s: change to "SS". */ | |
2532 curwin->w_cursor = *pos; | |
2533 del_char(FALSE); | |
2534 ins_char('S'); | |
2535 ins_char('S'); | |
2536 curwin->w_cursor = sp; | |
2537 inc(pos); | |
2538 } | |
2539 | |
7 | 2540 if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ |
2541 return FALSE; | |
2542 nc = c; | |
2543 if (MB_ISLOWER(c)) | |
2544 { | |
2545 if (op_type == OP_ROT13) | |
2546 nc = ROT13(c, 'a'); | |
2547 else if (op_type != OP_LOWER) | |
2548 nc = MB_TOUPPER(c); | |
2549 } | |
2550 else if (MB_ISUPPER(c)) | |
2551 { | |
2552 if (op_type == OP_ROT13) | |
2553 nc = ROT13(c, 'A'); | |
2554 else if (op_type != OP_UPPER) | |
2555 nc = MB_TOLOWER(c); | |
2556 } | |
2557 if (nc != c) | |
2558 { | |
2559 if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) | |
2560 { | |
2561 pos_T sp = curwin->w_cursor; | |
2562 | |
2563 curwin->w_cursor = *pos; | |
2451
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2564 /* don't use del_char(), it also removes composing chars */ |
0b8612c2814d
Fix: changing case of a character removed combining characters.
Bram Moolenaar <bram@vim.org>
parents:
2446
diff
changeset
|
2565 del_bytes(utf_ptr2len(ml_get_cursor()), FALSE, FALSE); |
7 | 2566 ins_char(nc); |
2567 curwin->w_cursor = sp; | |
2568 } | |
2569 else | |
14216
12bdbf9f7e20
patch 8.1.0125: virtual edit replace with multi-byte fails at end of line
Christian Brabandt <cb@256bit.org>
parents:
14202
diff
changeset
|
2570 PBYTE(*pos, nc); |
7 | 2571 return TRUE; |
2572 } | |
2573 return FALSE; | |
2574 } | |
2575 | |
2576 /* | |
2577 * op_insert - Insert and append operators for Visual mode. | |
2578 */ | |
2579 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2580 op_insert(oparg_T *oap, long count1) |
7 | 2581 { |
2582 long ins_len, pre_textlen = 0; | |
2583 char_u *firstline, *ins_text; | |
12329
0b10cff73322
patch 8.0.1044: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12327
diff
changeset
|
2584 colnr_T ind_pre = 0, ind_post; |
7 | 2585 struct block_def bd; |
2586 int i; | |
6579 | 2587 pos_T t1; |
7 | 2588 |
2589 /* edit() changes this - record it for OP_APPEND */ | |
2590 bd.is_MAX = (curwin->w_curswant == MAXCOL); | |
2591 | |
2592 /* vis block is still marked. Get rid of it now. */ | |
2593 curwin->w_cursor.lnum = oap->start.lnum; | |
2594 update_screen(INVERTED); | |
2595 | |
2596 if (oap->block_mode) | |
2597 { | |
2598 /* When 'virtualedit' is used, need to insert the extra spaces before | |
2599 * doing block_prep(). When only "block" is used, virtual edit is | |
2600 * already disabled, but still need it when calling | |
2601 * coladvance_force(). */ | |
2602 if (curwin->w_cursor.coladd > 0) | |
2603 { | |
2604 int old_ve_flags = ve_flags; | |
2605 | |
2606 ve_flags = VE_ALL; | |
2607 if (u_save_cursor() == FAIL) | |
2608 return; | |
2609 coladvance_force(oap->op_type == OP_APPEND | |
2610 ? oap->end_vcol + 1 : getviscol()); | |
2611 if (oap->op_type == OP_APPEND) | |
2612 --curwin->w_cursor.col; | |
2613 ve_flags = old_ve_flags; | |
2614 } | |
2615 /* Get the info about the block before entering the text */ | |
2616 block_prep(oap, &bd, oap->start.lnum, TRUE); | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2617 /* Get indent information */ |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2618 ind_pre = (colnr_T)getwhitecols_curline(); |
7 | 2619 firstline = ml_get(oap->start.lnum) + bd.textcol; |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2620 |
7 | 2621 if (oap->op_type == OP_APPEND) |
2622 firstline += bd.textlen; | |
2623 pre_textlen = (long)STRLEN(firstline); | |
2624 } | |
2625 | |
2626 if (oap->op_type == OP_APPEND) | |
2627 { | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2628 if (oap->block_mode && curwin->w_cursor.coladd == 0) |
7 | 2629 { |
2630 /* Move the cursor to the character right of the block. */ | |
2631 curwin->w_set_curswant = TRUE; | |
2632 while (*ml_get_cursor() != NUL | |
2633 && (curwin->w_cursor.col < bd.textcol + bd.textlen)) | |
2634 ++curwin->w_cursor.col; | |
2635 if (bd.is_short && !bd.is_MAX) | |
2636 { | |
2637 /* First line was too short, make it longer and adjust the | |
2638 * values in "bd". */ | |
2639 if (u_save_cursor() == FAIL) | |
2640 return; | |
2641 for (i = 0; i < bd.endspaces; ++i) | |
2642 ins_char(' '); | |
2643 bd.textlen += bd.endspaces; | |
2644 } | |
2645 } | |
2646 else | |
2647 { | |
2648 curwin->w_cursor = oap->end; | |
893 | 2649 check_cursor_col(); |
7 | 2650 |
2651 /* Works just like an 'i'nsert on the next character. */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2652 if (!LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2653 && oap->start_vcol != oap->end_vcol) |
2654 inc_cursor(); | |
2655 } | |
2656 } | |
2657 | |
6579 | 2658 t1 = oap->start; |
10803
065da86ca6d2
patch 8.0.0291: Visual block insertion does not insert in all lines
Christian Brabandt <cb@256bit.org>
parents:
10785
diff
changeset
|
2659 (void)edit(NUL, FALSE, (linenr_T)count1); |
7 | 2660 |
6579 | 2661 /* When a tab was inserted, and the characters in front of the tab |
2662 * have been converted to a tab as well, the column of the cursor | |
2663 * might have actually been reduced, so need to adjust here. */ | |
2664 if (t1.lnum == curbuf->b_op_start_orig.lnum | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2665 && LT_POS(curbuf->b_op_start_orig, t1)) |
6579 | 2666 oap->start = curbuf->b_op_start_orig; |
2667 | |
1477 | 2668 /* If user has moved off this line, we don't know what to do, so do |
2669 * nothing. | |
2670 * Also don't repeat the insert when Insert mode ended with CTRL-C. */ | |
2671 if (curwin->w_cursor.lnum != oap->start.lnum || got_int) | |
7 | 2672 return; |
2673 | |
2674 if (oap->block_mode) | |
2675 { | |
2676 struct block_def bd2; | |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
2677 int did_indent = FALSE; |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2678 size_t len; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2679 int add; |
7 | 2680 |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2681 /* If indent kicked in, the firstline might have changed |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2682 * but only do that, if the indent actually increased. */ |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2683 ind_post = (colnr_T)getwhitecols_curline(); |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2684 if (curbuf->b_op_start.col > ind_pre && ind_post > ind_pre) |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2685 { |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2686 bd.textcol += ind_post - ind_pre; |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2687 bd.start_vcol += ind_post - ind_pre; |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
2688 did_indent = TRUE; |
12327
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2689 } |
17ed65e87db1
patch 8.0.1043: warning for uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
12323
diff
changeset
|
2690 |
5471 | 2691 /* The user may have moved the cursor before inserting something, try |
13620
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
2692 * to adjust the block for that. But only do it, if the difference |
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
2693 * does not come from indent kicking in. */ |
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
2694 if (oap->start.lnum == curbuf->b_op_start_orig.lnum |
4faf77b96432
patch 8.0.1682: auto indenting breaks inserting a block
Christian Brabandt <cb@256bit.org>
parents:
13614
diff
changeset
|
2695 && !bd.is_MAX && !did_indent) |
5471 | 2696 { |
2697 if (oap->op_type == OP_INSERT | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2698 && oap->start.col + oap->start.coladd |
5730 | 2699 != curbuf->b_op_start_orig.col |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2700 + curbuf->b_op_start_orig.coladd) |
5471 | 2701 { |
6579 | 2702 int t = getviscol2(curbuf->b_op_start_orig.col, |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2703 curbuf->b_op_start_orig.coladd); |
5680 | 2704 oap->start.col = curbuf->b_op_start_orig.col; |
6579 | 2705 pre_textlen -= t - oap->start_vcol; |
2706 oap->start_vcol = t; | |
5471 | 2707 } |
2708 else if (oap->op_type == OP_APPEND | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2709 && oap->end.col + oap->end.coladd |
5730 | 2710 >= curbuf->b_op_start_orig.col |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2711 + curbuf->b_op_start_orig.coladd) |
5471 | 2712 { |
6579 | 2713 int t = getviscol2(curbuf->b_op_start_orig.col, |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
2714 curbuf->b_op_start_orig.coladd); |
5680 | 2715 oap->start.col = curbuf->b_op_start_orig.col; |
5471 | 2716 /* reset pre_textlen to the value of OP_INSERT */ |
2717 pre_textlen += bd.textlen; | |
6579 | 2718 pre_textlen -= t - oap->start_vcol; |
2719 oap->start_vcol = t; | |
5471 | 2720 oap->op_type = OP_INSERT; |
2721 } | |
2722 } | |
2723 | |
7 | 2724 /* |
2725 * Spaces and tabs in the indent may have changed to other spaces and | |
1392 | 2726 * tabs. Get the starting column again and correct the length. |
7 | 2727 * Don't do this when "$" used, end-of-line will have changed. |
2728 */ | |
2729 block_prep(oap, &bd2, oap->start.lnum, TRUE); | |
2730 if (!bd.is_MAX || bd2.textlen < bd.textlen) | |
2731 { | |
2732 if (oap->op_type == OP_APPEND) | |
2733 { | |
2734 pre_textlen += bd2.textlen - bd.textlen; | |
2735 if (bd2.endspaces) | |
2736 --bd2.textlen; | |
2737 } | |
2738 bd.textcol = bd2.textcol; | |
2739 bd.textlen = bd2.textlen; | |
2740 } | |
2741 | |
2742 /* | |
2743 * Subsequent calls to ml_get() flush the firstline data - take a | |
2744 * copy of the required string. | |
2745 */ | |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2746 firstline = ml_get(oap->start.lnum); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2747 len = STRLEN(firstline); |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2748 add = bd.textcol; |
7 | 2749 if (oap->op_type == OP_APPEND) |
13814
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2750 add += bd.textlen; |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2751 if ((size_t)add > len) |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2752 firstline += len; // short line, point to the NUL |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2753 else |
7ed76dcf0d94
patch 8.0.1779: deleting in a block selection causes problems
Christian Brabandt <cb@256bit.org>
parents:
13620
diff
changeset
|
2754 firstline += add; |
3421 | 2755 if (pre_textlen >= 0 |
2756 && (ins_len = (long)STRLEN(firstline) - pre_textlen) > 0) | |
7 | 2757 { |
2758 ins_text = vim_strnsave(firstline, (int)ins_len); | |
2759 if (ins_text != NULL) | |
2760 { | |
2761 /* block handled here */ | |
2762 if (u_save(oap->start.lnum, | |
2763 (linenr_T)(oap->end.lnum + 1)) == OK) | |
2764 block_insert(oap, ins_text, (oap->op_type == OP_INSERT), | |
2765 &bd); | |
2766 | |
2767 curwin->w_cursor.col = oap->start.col; | |
2768 check_cursor(); | |
2769 vim_free(ins_text); | |
2770 } | |
2771 } | |
2772 } | |
2773 } | |
2774 | |
2775 /* | |
2776 * op_change - handle a change operation | |
2777 * | |
2778 * return TRUE if edit() returns because of a CTRL-O command | |
2779 */ | |
2780 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2781 op_change(oparg_T *oap) |
7 | 2782 { |
2783 colnr_T l; | |
2784 int retval; | |
2785 long offset; | |
2786 linenr_T linenr; | |
1392 | 2787 long ins_len; |
2788 long pre_textlen = 0; | |
2789 long pre_indent = 0; | |
7 | 2790 char_u *firstline; |
2791 char_u *ins_text, *newp, *oldp; | |
2792 struct block_def bd; | |
2793 | |
2794 l = oap->start.col; | |
2795 if (oap->motion_type == MLINE) | |
2796 { | |
2797 l = 0; | |
2798 #ifdef FEAT_SMARTINDENT | |
2799 if (!p_paste && curbuf->b_p_si | |
2800 # ifdef FEAT_CINDENT | |
2801 && !curbuf->b_p_cin | |
2802 # endif | |
2803 ) | |
2804 can_si = TRUE; /* It's like opening a new line, do si */ | |
2805 #endif | |
2806 } | |
2807 | |
2808 /* First delete the text in the region. In an empty buffer only need to | |
2809 * save for undo */ | |
2810 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
2811 { | |
2812 if (u_save_cursor() == FAIL) | |
2813 return FALSE; | |
2814 } | |
2815 else if (op_delete(oap) == FAIL) | |
2816 return FALSE; | |
2817 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
2818 if ((l > curwin->w_cursor.col) && !LINEEMPTY(curwin->w_cursor.lnum) |
7 | 2819 && !virtual_op) |
2820 inc_cursor(); | |
2821 | |
2822 /* check for still on same line (<CR> in inserted text meaningless) */ | |
2823 /* skip blank lines too */ | |
2824 if (oap->block_mode) | |
2825 { | |
2826 /* Add spaces before getting the current line length. */ | |
2827 if (virtual_op && (curwin->w_cursor.coladd > 0 | |
2828 || gchar_cursor() == NUL)) | |
2829 coladvance_force(getviscol()); | |
1392 | 2830 firstline = ml_get(oap->start.lnum); |
2831 pre_textlen = (long)STRLEN(firstline); | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2832 pre_indent = (long)getwhitecols(firstline); |
7 | 2833 bd.textcol = curwin->w_cursor.col; |
2834 } | |
2835 | |
2836 #if defined(FEAT_LISP) || defined(FEAT_CINDENT) | |
2837 if (oap->motion_type == MLINE) | |
2838 fix_indent(); | |
2839 #endif | |
2840 | |
2841 retval = edit(NUL, FALSE, (linenr_T)1); | |
2842 | |
2843 /* | |
39 | 2844 * In Visual block mode, handle copying the new text to all lines of the |
7 | 2845 * block. |
1477 | 2846 * Don't repeat the insert when Insert mode ended with CTRL-C. |
7 | 2847 */ |
1477 | 2848 if (oap->block_mode && oap->start.lnum != oap->end.lnum && !got_int) |
7 | 2849 { |
1392 | 2850 /* Auto-indenting may have changed the indent. If the cursor was past |
2851 * the indent, exclude that indent change from the inserted text. */ | |
7 | 2852 firstline = ml_get(oap->start.lnum); |
1403 | 2853 if (bd.textcol > (colnr_T)pre_indent) |
7 | 2854 { |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
2855 long new_indent = (long)getwhitecols(firstline); |
1392 | 2856 |
2857 pre_textlen += new_indent - pre_indent; | |
2858 bd.textcol += new_indent - pre_indent; | |
2859 } | |
2860 | |
2861 ins_len = (long)STRLEN(firstline) - pre_textlen; | |
2862 if (ins_len > 0) | |
2863 { | |
2864 /* Subsequent calls to ml_get() flush the firstline data - take a | |
2865 * copy of the inserted text. */ | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
2866 if ((ins_text = alloc(ins_len + 1)) != NULL) |
7 | 2867 { |
419 | 2868 vim_strncpy(ins_text, firstline + bd.textcol, (size_t)ins_len); |
7 | 2869 for (linenr = oap->start.lnum + 1; linenr <= oap->end.lnum; |
2870 linenr++) | |
2871 { | |
2872 block_prep(oap, &bd, linenr, TRUE); | |
2873 if (!bd.is_short || virtual_op) | |
2874 { | |
2875 pos_T vpos; | |
2876 | |
2877 /* If the block starts in virtual space, count the | |
2878 * initial coladd offset as part of "startspaces" */ | |
2879 if (bd.is_short) | |
2880 { | |
1982 | 2881 vpos.lnum = linenr; |
7 | 2882 (void)getvpos(&vpos, oap->start_vcol); |
2883 } | |
2884 else | |
2885 vpos.coladd = 0; | |
2886 oldp = ml_get(linenr); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
2887 newp = alloc(STRLEN(oldp) + vpos.coladd + ins_len + 1); |
7 | 2888 if (newp == NULL) |
2889 continue; | |
2890 /* copy up to block start */ | |
2891 mch_memmove(newp, oldp, (size_t)bd.textcol); | |
2892 offset = bd.textcol; | |
6929 | 2893 vim_memset(newp + offset, ' ', (size_t)vpos.coladd); |
7 | 2894 offset += vpos.coladd; |
2895 mch_memmove(newp + offset, ins_text, (size_t)ins_len); | |
2896 offset += ins_len; | |
2897 oldp += bd.textcol; | |
1622 | 2898 STRMOVE(newp + offset, oldp); |
7 | 2899 ml_replace(linenr, newp, FALSE); |
2900 } | |
2901 } | |
2902 check_cursor(); | |
2903 | |
2904 changed_lines(oap->start.lnum + 1, 0, oap->end.lnum + 1, 0L); | |
2905 } | |
2906 vim_free(ins_text); | |
2907 } | |
2908 } | |
2909 | |
2910 return retval; | |
2911 } | |
2912 | |
2913 /* | |
2914 * set all the yank registers to empty (called from main()) | |
2915 */ | |
2916 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2917 init_yank(void) |
7 | 2918 { |
2919 int i; | |
2920 | |
2921 for (i = 0; i < NUM_REGISTERS; ++i) | |
2922 y_regs[i].y_array = NULL; | |
2923 } | |
2924 | |
356 | 2925 #if defined(EXITFREE) || defined(PROTO) |
2926 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2927 clear_registers(void) |
356 | 2928 { |
2929 int i; | |
2930 | |
2931 for (i = 0; i < NUM_REGISTERS; ++i) | |
2932 { | |
2933 y_current = &y_regs[i]; | |
2934 if (y_current->y_array != NULL) | |
2935 free_yank_all(); | |
2936 } | |
2937 } | |
2938 #endif | |
2939 | |
7 | 2940 /* |
2941 * Free "n" lines from the current yank register. | |
2942 * Called for normal freeing and in case of error. | |
2943 */ | |
2944 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2945 free_yank(long n) |
7 | 2946 { |
2947 if (y_current->y_array != NULL) | |
2948 { | |
2949 long i; | |
2950 | |
2951 for (i = n; --i >= 0; ) | |
2952 { | |
2953 #ifdef AMIGA /* only for very slow machines */ | |
2954 if ((i & 1023) == 1023) /* this may take a while */ | |
2955 { | |
2956 /* | |
2957 * This message should never cause a hit-return message. | |
2958 * Overwrite this message with any next message. | |
2959 */ | |
2960 ++no_wait_return; | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
2961 smsg(_("freeing %ld lines"), i + 1); |
7 | 2962 --no_wait_return; |
2963 msg_didout = FALSE; | |
2964 msg_col = 0; | |
2965 } | |
2966 #endif | |
2967 vim_free(y_current->y_array[i]); | |
2968 } | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
2969 VIM_CLEAR(y_current->y_array); |
7 | 2970 #ifdef AMIGA |
2971 if (n >= 1000) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
2972 msg(""); |
7 | 2973 #endif |
2974 } | |
2975 } | |
2976 | |
2977 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2978 free_yank_all(void) |
7 | 2979 { |
2980 free_yank(y_current->y_size); | |
2981 } | |
2982 | |
2983 /* | |
2984 * Yank the text between "oap->start" and "oap->end" into a yank register. | |
2985 * If we are to append (uppercase register), we first yank into a new yank | |
2986 * register and then concatenate the old and the new one (so we keep the old | |
2987 * one in case of out-of-memory). | |
2988 * | |
5245
8c6615a30951
updated for version 7.4a.047
Bram Moolenaar <bram@vim.org>
parents:
5182
diff
changeset
|
2989 * Return FAIL for failure, OK otherwise. |
7 | 2990 */ |
2991 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
2992 op_yank(oparg_T *oap, int deleting, int mess) |
7 | 2993 { |
2994 long y_idx; /* index in y_array[] */ | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2995 yankreg_T *curr; /* copy of y_current */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
2996 yankreg_T newreg; /* new yank register when appending */ |
7 | 2997 char_u **new_ptr; |
2998 linenr_T lnum; /* current line number */ | |
2999 long j; | |
3000 int yanktype = oap->motion_type; | |
3001 long yanklines = oap->line_count; | |
3002 linenr_T yankendlnum = oap->end.lnum; | |
3003 char_u *p; | |
3004 char_u *pnew; | |
3005 struct block_def bd; | |
2658 | 3006 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
2654 | 3007 int did_star = FALSE; |
2658 | 3008 #endif |
7 | 3009 |
3010 /* check for read-only register */ | |
3011 if (oap->regname != 0 && !valid_yank_reg(oap->regname, TRUE)) | |
3012 { | |
3013 beep_flush(); | |
3014 return FAIL; | |
3015 } | |
3016 if (oap->regname == '_') /* black hole: nothing to do */ | |
3017 return OK; | |
3018 | |
3019 #ifdef FEAT_CLIPBOARD | |
3020 if (!clip_star.available && oap->regname == '*') | |
3021 oap->regname = 0; | |
3022 else if (!clip_plus.available && oap->regname == '+') | |
3023 oap->regname = 0; | |
3024 #endif | |
3025 | |
3026 if (!deleting) /* op_delete() already set y_current */ | |
3027 get_yank_register(oap->regname, TRUE); | |
3028 | |
3029 curr = y_current; | |
3030 /* append to existing contents */ | |
3031 if (y_append && y_current->y_array != NULL) | |
3032 y_current = &newreg; | |
3033 else | |
3034 free_yank_all(); /* free previously yanked lines */ | |
3035 | |
593 | 3036 /* |
3037 * If the cursor was in column 1 before and after the movement, and the | |
3038 * operator is not inclusive, the yank is always linewise. | |
3039 */ | |
7 | 3040 if ( oap->motion_type == MCHAR |
3041 && oap->start.col == 0 | |
3042 && !oap->inclusive | |
3043 && (!oap->is_VIsual || *p_sel == 'o') | |
50 | 3044 && !oap->block_mode |
7 | 3045 && oap->end.col == 0 |
3046 && yanklines > 1) | |
3047 { | |
3048 yanktype = MLINE; | |
3049 --yankendlnum; | |
3050 --yanklines; | |
3051 } | |
3052 | |
3053 y_current->y_size = yanklines; | |
3054 y_current->y_type = yanktype; /* set the yank register type */ | |
3055 y_current->y_width = 0; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3056 y_current->y_array = lalloc_clear(sizeof(char_u *) * yanklines, TRUE); |
7 | 3057 if (y_current->y_array == NULL) |
3058 { | |
3059 y_current = curr; | |
3060 return FAIL; | |
3061 } | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3062 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3063 y_current->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3064 #endif |
7 | 3065 |
3066 y_idx = 0; | |
3067 lnum = oap->start.lnum; | |
3068 | |
3069 if (oap->block_mode) | |
3070 { | |
3071 /* Visual block mode */ | |
3072 y_current->y_type = MBLOCK; /* set the yank register type */ | |
3073 y_current->y_width = oap->end_vcol - oap->start_vcol; | |
3074 | |
3075 if (curwin->w_curswant == MAXCOL && y_current->y_width > 0) | |
3076 y_current->y_width--; | |
3077 } | |
3078 | |
3079 for ( ; lnum <= yankendlnum; lnum++, y_idx++) | |
3080 { | |
3081 switch (y_current->y_type) | |
3082 { | |
3083 case MBLOCK: | |
3084 block_prep(oap, &bd, lnum, FALSE); | |
3085 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3086 goto fail; | |
3087 break; | |
3088 | |
3089 case MLINE: | |
3090 if ((y_current->y_array[y_idx] = | |
3091 vim_strsave(ml_get(lnum))) == NULL) | |
3092 goto fail; | |
3093 break; | |
3094 | |
3095 case MCHAR: | |
3096 { | |
3097 colnr_T startcol = 0, endcol = MAXCOL; | |
3098 int is_oneChar = FALSE; | |
3099 colnr_T cs, ce; | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3100 |
7 | 3101 p = ml_get(lnum); |
3102 bd.startspaces = 0; | |
3103 bd.endspaces = 0; | |
3104 | |
3105 if (lnum == oap->start.lnum) | |
3106 { | |
3107 startcol = oap->start.col; | |
3108 if (virtual_op) | |
3109 { | |
3110 getvcol(curwin, &oap->start, &cs, NULL, &ce); | |
3111 if (ce != cs && oap->start.coladd > 0) | |
3112 { | |
3113 /* Part of a tab selected -- but don't | |
3114 * double-count it. */ | |
3115 bd.startspaces = (ce - cs + 1) | |
3116 - oap->start.coladd; | |
3117 startcol++; | |
3118 } | |
3119 } | |
3120 } | |
3121 | |
3122 if (lnum == oap->end.lnum) | |
3123 { | |
3124 endcol = oap->end.col; | |
3125 if (virtual_op) | |
3126 { | |
3127 getvcol(curwin, &oap->end, &cs, NULL, &ce); | |
3128 if (p[endcol] == NUL || (cs + oap->end.coladd < ce | |
3129 /* Don't add space for double-wide | |
3130 * char; endcol will be on last byte | |
3131 * of multi-byte char. */ | |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
3132 && (*mb_head_off)(p, p + endcol) == 0)) |
7 | 3133 { |
3134 if (oap->start.lnum == oap->end.lnum | |
3135 && oap->start.col == oap->end.col) | |
3136 { | |
3137 /* Special case: inside a single char */ | |
3138 is_oneChar = TRUE; | |
3139 bd.startspaces = oap->end.coladd | |
3140 - oap->start.coladd + oap->inclusive; | |
3141 endcol = startcol; | |
3142 } | |
3143 else | |
3144 { | |
3145 bd.endspaces = oap->end.coladd | |
3146 + oap->inclusive; | |
3147 endcol -= oap->inclusive; | |
3148 } | |
3149 } | |
3150 } | |
3151 } | |
3510 | 3152 if (endcol == MAXCOL) |
3153 endcol = (colnr_T)STRLEN(p); | |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15597
diff
changeset
|
3154 if (startcol > endcol || is_oneChar) |
7 | 3155 bd.textlen = 0; |
3156 else | |
3157 bd.textlen = endcol - startcol + oap->inclusive; | |
3158 bd.textstart = p + startcol; | |
3159 if (yank_copy_line(&bd, y_idx) == FAIL) | |
3160 goto fail; | |
3161 break; | |
3162 } | |
3163 /* NOTREACHED */ | |
3164 } | |
3165 } | |
3166 | |
3167 if (curr != y_current) /* append the new block to the old block */ | |
3168 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3169 new_ptr = ALLOC_MULT(char_u *, curr->y_size + y_current->y_size); |
7 | 3170 if (new_ptr == NULL) |
3171 goto fail; | |
3172 for (j = 0; j < curr->y_size; ++j) | |
3173 new_ptr[j] = curr->y_array[j]; | |
3174 vim_free(curr->y_array); | |
3175 curr->y_array = new_ptr; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3176 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3177 curr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3178 #endif |
7 | 3179 |
3180 if (yanktype == MLINE) /* MLINE overrides MCHAR and MBLOCK */ | |
3181 curr->y_type = MLINE; | |
3182 | |
164 | 3183 /* Concatenate the last line of the old block with the first line of |
3184 * the new block, unless being Vi compatible. */ | |
3185 if (curr->y_type == MCHAR && vim_strchr(p_cpo, CPO_REGAPPEND) == NULL) | |
7 | 3186 { |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
3187 pnew = alloc(STRLEN(curr->y_array[curr->y_size - 1]) |
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
3188 + STRLEN(y_current->y_array[0]) + 1); |
7 | 3189 if (pnew == NULL) |
3190 { | |
3191 y_idx = y_current->y_size - 1; | |
3192 goto fail; | |
3193 } | |
3194 STRCPY(pnew, curr->y_array[--j]); | |
3195 STRCAT(pnew, y_current->y_array[0]); | |
3196 vim_free(curr->y_array[j]); | |
3197 vim_free(y_current->y_array[0]); | |
3198 curr->y_array[j++] = pnew; | |
3199 y_idx = 1; | |
3200 } | |
3201 else | |
3202 y_idx = 0; | |
3203 while (y_idx < y_current->y_size) | |
3204 curr->y_array[j++] = y_current->y_array[y_idx++]; | |
3205 curr->y_size = j; | |
3206 vim_free(y_current->y_array); | |
3207 y_current = curr; | |
3208 } | |
5981 | 3209 if (curwin->w_p_rnu) |
3210 redraw_later(SOME_VALID); /* cursor moved to start */ | |
7 | 3211 if (mess) /* Display message about yank? */ |
3212 { | |
3213 if (yanktype == MCHAR | |
3214 && !oap->block_mode | |
3215 && yanklines == 1) | |
3216 yanklines = 0; | |
3217 /* Some versions of Vi use ">=" here, some don't... */ | |
3218 if (yanklines > p_report) | |
3219 { | |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3220 char namebuf[100]; |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3221 |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3222 if (oap->regname == NUL) |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3223 *namebuf = NUL; |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3224 else |
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3225 vim_snprintf(namebuf, sizeof(namebuf), |
11688
570f00932da8
patch 8.0.0727: message about what register to yank into is not translated
Christian Brabandt <cb@256bit.org>
parents:
11682
diff
changeset
|
3226 _(" into \"%c"), oap->regname); |
11682
b9928ef8632f
patch 8.0.0724: the message for yanking doesn't indicate the register
Christian Brabandt <cb@256bit.org>
parents:
11597
diff
changeset
|
3227 |
7 | 3228 /* redisplay now, so message is not deleted */ |
3229 update_topline_redraw(); | |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3230 if (oap->block_mode) |
205 | 3231 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3232 smsg(NGETTEXT("block of %ld line yanked%s", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3233 "block of %ld lines yanked%s", yanklines), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3234 yanklines, namebuf); |
205 | 3235 } |
7 | 3236 else |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3237 { |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3238 smsg(NGETTEXT("%ld line yanked%s", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3239 "%ld lines yanked%s", yanklines), |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3240 yanklines, namebuf); |
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
3241 } |
7 | 3242 } |
3243 } | |
3244 | |
3245 /* | |
3246 * Set "'[" and "']" marks. | |
3247 */ | |
3248 curbuf->b_op_start = oap->start; | |
3249 curbuf->b_op_end = oap->end; | |
5735 | 3250 if (yanktype == MLINE && !oap->block_mode) |
36 | 3251 { |
3252 curbuf->b_op_start.col = 0; | |
3253 curbuf->b_op_end.col = MAXCOL; | |
3254 } | |
7 | 3255 |
3256 #ifdef FEAT_CLIPBOARD | |
3257 /* | |
3258 * If we were yanking to the '*' register, send result to clipboard. | |
3259 * If no register was specified, and "unnamed" in 'clipboard', make a copy | |
3260 * to the '*' register. | |
3261 */ | |
3262 if (clip_star.available | |
3263 && (curr == &(y_regs[STAR_REGISTER]) | |
2654 | 3264 || (!deleting && oap->regname == 0 |
6116 | 3265 && ((clip_unnamed | clip_unnamed_saved) & CLIP_UNNAMED)))) |
7 | 3266 { |
3267 if (curr != &(y_regs[STAR_REGISTER])) | |
3268 /* Copy the text from register 0 to the clipboard register. */ | |
3269 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3270 | |
3271 clip_own_selection(&clip_star); | |
3272 clip_gen_set_selection(&clip_star); | |
2658 | 3273 # ifdef FEAT_X11 |
2654 | 3274 did_star = TRUE; |
2658 | 3275 # endif |
7 | 3276 } |
3277 | |
3278 # ifdef FEAT_X11 | |
3279 /* | |
3280 * If we were yanking to the '+' register, send result to selection. | |
3281 * Also copy to the '*' register, in case auto-select is off. | |
3282 */ | |
2654 | 3283 if (clip_plus.available |
3284 && (curr == &(y_regs[PLUS_REGISTER]) | |
3285 || (!deleting && oap->regname == 0 | |
6116 | 3286 && ((clip_unnamed | clip_unnamed_saved) & |
3287 CLIP_UNNAMED_PLUS)))) | |
7 | 3288 { |
2654 | 3289 if (curr != &(y_regs[PLUS_REGISTER])) |
3290 /* Copy the text from register 0 to the clipboard register. */ | |
3291 copy_yank_reg(&(y_regs[PLUS_REGISTER])); | |
3292 | |
7 | 3293 clip_own_selection(&clip_plus); |
3294 clip_gen_set_selection(&clip_plus); | |
12642
d1cbe8cb05d0
patch 8.0.1199: when 'clipboard' is "autoselectplus" star register is set
Christian Brabandt <cb@256bit.org>
parents:
12329
diff
changeset
|
3295 if (!clip_isautosel_star() && !clip_isautosel_plus() |
d1cbe8cb05d0
patch 8.0.1199: when 'clipboard' is "autoselectplus" star register is set
Christian Brabandt <cb@256bit.org>
parents:
12329
diff
changeset
|
3296 && !did_star && curr == &(y_regs[PLUS_REGISTER])) |
7 | 3297 { |
3298 copy_yank_reg(&(y_regs[STAR_REGISTER])); | |
3299 clip_own_selection(&clip_star); | |
3300 clip_gen_set_selection(&clip_star); | |
3301 } | |
3302 } | |
3303 # endif | |
3304 #endif | |
3305 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13254
diff
changeset
|
3306 #if defined(FEAT_EVAL) |
13037
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3307 if (!deleting && has_textyankpost()) |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3308 yank_do_autocmd(oap, y_current); |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3309 #endif |
6e81a68d63a1
patch 8.0.1394: cannot intercept a yank command
Christian Brabandt <cb@256bit.org>
parents:
12996
diff
changeset
|
3310 |
7 | 3311 return OK; |
3312 | |
3313 fail: /* free the allocated lines */ | |
3314 free_yank(y_idx + 1); | |
3315 y_current = curr; | |
3316 return FAIL; | |
3317 } | |
3318 | |
3319 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3320 yank_copy_line(struct block_def *bd, long y_idx) |
7 | 3321 { |
3322 char_u *pnew; | |
3323 | |
3324 if ((pnew = alloc(bd->startspaces + bd->endspaces + bd->textlen + 1)) | |
3325 == NULL) | |
3326 return FAIL; | |
3327 y_current->y_array[y_idx] = pnew; | |
6929 | 3328 vim_memset(pnew, ' ', (size_t)bd->startspaces); |
7 | 3329 pnew += bd->startspaces; |
3330 mch_memmove(pnew, bd->textstart, (size_t)bd->textlen); | |
3331 pnew += bd->textlen; | |
6929 | 3332 vim_memset(pnew, ' ', (size_t)bd->endspaces); |
7 | 3333 pnew += bd->endspaces; |
3334 *pnew = NUL; | |
3335 return OK; | |
3336 } | |
3337 | |
3338 #ifdef FEAT_CLIPBOARD | |
3339 /* | |
3340 * Make a copy of the y_current register to register "reg". | |
3341 */ | |
3342 static void | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3343 copy_yank_reg(yankreg_T *reg) |
7 | 3344 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3345 yankreg_T *curr = y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
3346 long j; |
7 | 3347 |
3348 y_current = reg; | |
3349 free_yank_all(); | |
3350 *y_current = *curr; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3351 y_current->y_array = lalloc_clear( |
16782
fc58fee685e2
patch 8.1.1393: unnecessary type casts
Bram Moolenaar <Bram@vim.org>
parents:
16768
diff
changeset
|
3352 sizeof(char_u *) * y_current->y_size, TRUE); |
7 | 3353 if (y_current->y_array == NULL) |
3354 y_current->y_size = 0; | |
3355 else | |
3356 for (j = 0; j < y_current->y_size; ++j) | |
3357 if ((y_current->y_array[j] = vim_strsave(curr->y_array[j])) == NULL) | |
3358 { | |
3359 free_yank(j); | |
3360 y_current->y_size = 0; | |
3361 break; | |
3362 } | |
3363 y_current = curr; | |
3364 } | |
3365 #endif | |
3366 | |
3367 /* | |
140 | 3368 * Put contents of register "regname" into the text. |
3369 * Caller must check "regname" to be valid! | |
3370 * "flags": PUT_FIXINDENT make indent look nice | |
3371 * PUT_CURSEND leave cursor after end of new text | |
3372 * PUT_LINE force linewise put (":put") | |
7 | 3373 */ |
3374 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3375 do_put( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3376 int regname, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3377 int dir, /* BACKWARD for 'P', FORWARD for 'p' */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3378 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
3379 int flags) |
7 | 3380 { |
3381 char_u *ptr; | |
3382 char_u *newp, *oldp; | |
3383 int yanklen; | |
3384 int totlen = 0; /* init for gcc */ | |
3385 linenr_T lnum; | |
3386 colnr_T col; | |
3387 long i; /* index in y_array[] */ | |
3388 int y_type; | |
3389 long y_size; | |
3390 int oldlen; | |
3391 long y_width = 0; | |
3392 colnr_T vcol; | |
3393 int delcount; | |
3394 int incr = 0; | |
3395 long j; | |
3396 struct block_def bd; | |
3397 char_u **y_array = NULL; | |
3398 long nr_lines = 0; | |
3399 pos_T new_cursor; | |
3400 int indent; | |
3401 int orig_indent = 0; /* init for gcc */ | |
3402 int indent_diff = 0; /* init for gcc */ | |
3403 int first_indent = TRUE; | |
3404 int lendiff = 0; | |
3405 pos_T old_pos; | |
3406 char_u *insert_string = NULL; | |
3407 int allocated = FALSE; | |
3408 long cnt; | |
3409 | |
3410 #ifdef FEAT_CLIPBOARD | |
3411 /* Adjust register name for "unnamed" in 'clipboard'. */ | |
3412 adjust_clip_reg(®name); | |
3413 (void)may_get_selection(regname); | |
3414 #endif | |
3415 | |
3416 if (flags & PUT_FIXINDENT) | |
3417 orig_indent = get_indent(); | |
3418 | |
3419 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3420 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3421 | |
3422 /* | |
3423 * Using inserted text works differently, because the register includes | |
3424 * special characters (newlines, etc.). | |
3425 */ | |
3426 if (regname == '.') | |
3427 { | |
10494
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3428 if (VIsual_active) |
1e700d72561d
commit https://github.com/vim/vim/commit/f8eb9c51e5bbd10e59c9b1247f8f6c7f5b77ccd0
Christian Brabandt <cb@256bit.org>
parents:
10486
diff
changeset
|
3429 stuffcharReadbuff(VIsual_mode); |
7 | 3430 (void)stuff_inserted((dir == FORWARD ? (count == -1 ? 'o' : 'a') : |
3431 (count == -1 ? 'O' : 'i')), count, FALSE); | |
3432 /* Putting the text is done later, so can't really move the cursor to | |
3433 * the next character. Use "l" to simulate it. */ | |
3434 if ((flags & PUT_CURSEND) && gchar_cursor() != NUL) | |
3435 stuffcharReadbuff('l'); | |
3436 return; | |
3437 } | |
3438 | |
3439 /* | |
3440 * For special registers '%' (file name), '#' (alternate file name) and | |
3441 * ':' (last command line), etc. we have to create a fake yank register. | |
3442 */ | |
3443 if (get_spec_reg(regname, &insert_string, &allocated, TRUE)) | |
3444 { | |
3445 if (insert_string == NULL) | |
3446 return; | |
3447 } | |
3448 | |
14202
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3449 /* Autocommands may be executed when saving lines for undo. This might |
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3450 * make "y_array" invalid, so we start undo now to avoid that. */ |
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3451 if (u_save(curwin->w_cursor.lnum, curwin->w_cursor.lnum + 1) == FAIL) |
51693b1a640e
patch 8.1.0118: duplicate error message for put command
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3452 goto end; |
4005 | 3453 |
7 | 3454 if (insert_string != NULL) |
3455 { | |
3456 y_type = MCHAR; | |
3457 #ifdef FEAT_EVAL | |
3458 if (regname == '=') | |
3459 { | |
3460 /* For the = register we need to split the string at NL | |
3093 | 3461 * characters. |
3462 * Loop twice: count the number of lines and save them. */ | |
7 | 3463 for (;;) |
3464 { | |
3465 y_size = 0; | |
3466 ptr = insert_string; | |
3467 while (ptr != NULL) | |
3468 { | |
3469 if (y_array != NULL) | |
3470 y_array[y_size] = ptr; | |
3471 ++y_size; | |
3472 ptr = vim_strchr(ptr, '\n'); | |
3473 if (ptr != NULL) | |
3474 { | |
3475 if (y_array != NULL) | |
3476 *ptr = NUL; | |
3477 ++ptr; | |
3093 | 3478 /* A trailing '\n' makes the register linewise. */ |
7 | 3479 if (*ptr == NUL) |
3480 { | |
3481 y_type = MLINE; | |
3482 break; | |
3483 } | |
3484 } | |
3485 } | |
3486 if (y_array != NULL) | |
3487 break; | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
3488 y_array = ALLOC_MULT(char_u *, y_size); |
7 | 3489 if (y_array == NULL) |
3490 goto end; | |
3491 } | |
3492 } | |
3493 else | |
3494 #endif | |
3495 { | |
3496 y_size = 1; /* use fake one-line yank register */ | |
3497 y_array = &insert_string; | |
3498 } | |
3499 } | |
3500 else | |
3501 { | |
3502 get_yank_register(regname, FALSE); | |
3503 | |
3504 y_type = y_current->y_type; | |
3505 y_width = y_current->y_width; | |
3506 y_size = y_current->y_size; | |
3507 y_array = y_current->y_array; | |
3508 } | |
3509 | |
3510 if (y_type == MLINE) | |
3511 { | |
3512 if (flags & PUT_LINE_SPLIT) | |
3513 { | |
6845 | 3514 char_u *p; |
3515 | |
7 | 3516 /* "p" or "P" in Visual mode: split the lines to put the text in |
3517 * between. */ | |
3518 if (u_save_cursor() == FAIL) | |
3519 goto end; | |
6845 | 3520 p = ml_get_cursor(); |
3521 if (dir == FORWARD && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3522 MB_PTR_ADV(p); |
6845 | 3523 ptr = vim_strsave(p); |
7 | 3524 if (ptr == NULL) |
3525 goto end; | |
3526 ml_append(curwin->w_cursor.lnum, ptr, (colnr_T)0, FALSE); | |
3527 vim_free(ptr); | |
3528 | |
6845 | 3529 oldp = ml_get_curline(); |
3530 p = oldp + curwin->w_cursor.col; | |
3531 if (dir == FORWARD && *p != NUL) | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
3532 MB_PTR_ADV(p); |
6845 | 3533 ptr = vim_strnsave(oldp, p - oldp); |
7 | 3534 if (ptr == NULL) |
3535 goto end; | |
3536 ml_replace(curwin->w_cursor.lnum, ptr, FALSE); | |
3537 ++nr_lines; | |
3538 dir = FORWARD; | |
3539 } | |
3540 if (flags & PUT_LINE_FORWARD) | |
3541 { | |
3542 /* Must be "p" for a Visual block, put lines below the block. */ | |
692 | 3543 curwin->w_cursor = curbuf->b_visual.vi_end; |
7 | 3544 dir = FORWARD; |
3545 } | |
3546 curbuf->b_op_start = curwin->w_cursor; /* default for '[ mark */ | |
3547 curbuf->b_op_end = curwin->w_cursor; /* default for '] mark */ | |
3548 } | |
3549 | |
3550 if (flags & PUT_LINE) /* :put command or "p" in Visual line mode. */ | |
3551 y_type = MLINE; | |
3552 | |
3553 if (y_size == 0 || y_array == NULL) | |
3554 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
3555 semsg(_("E353: Nothing in register %s"), |
7 | 3556 regname == 0 ? (char_u *)"\"" : transchar(regname)); |
3557 goto end; | |
3558 } | |
3559 | |
3560 if (y_type == MBLOCK) | |
3561 { | |
3562 lnum = curwin->w_cursor.lnum + y_size + 1; | |
3563 if (lnum > curbuf->b_ml.ml_line_count) | |
3564 lnum = curbuf->b_ml.ml_line_count + 1; | |
3565 if (u_save(curwin->w_cursor.lnum - 1, lnum) == FAIL) | |
3566 goto end; | |
3567 } | |
5735 | 3568 else if (y_type == MLINE) |
7 | 3569 { |
3570 lnum = curwin->w_cursor.lnum; | |
3571 #ifdef FEAT_FOLDING | |
3572 /* Correct line number for closed fold. Don't move the cursor yet, | |
3573 * u_save() uses it. */ | |
3574 if (dir == BACKWARD) | |
3575 (void)hasFolding(lnum, &lnum, NULL); | |
3576 else | |
3577 (void)hasFolding(lnum, NULL, &lnum); | |
3578 #endif | |
3579 if (dir == FORWARD) | |
3580 ++lnum; | |
5053
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3581 /* In an empty buffer the empty line is going to be replaced, include |
35b6fc57a286
updated for version 7.3.1270
Bram Moolenaar <bram@vim.org>
parents:
4352
diff
changeset
|
3582 * it in the saved lines. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
3583 if ((BUFEMPTY() ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) |
7 | 3584 goto end; |
3585 #ifdef FEAT_FOLDING | |
3586 if (dir == FORWARD) | |
3587 curwin->w_cursor.lnum = lnum - 1; | |
3588 else | |
3589 curwin->w_cursor.lnum = lnum; | |
3590 curbuf->b_op_start = curwin->w_cursor; /* for mark_adjust() */ | |
3591 #endif | |
3592 } | |
3593 else if (u_save_cursor() == FAIL) | |
3594 goto end; | |
3595 | |
3596 yanklen = (int)STRLEN(y_array[0]); | |
3597 | |
3598 if (ve_flags == VE_ALL && y_type == MCHAR) | |
3599 { | |
3600 if (gchar_cursor() == TAB) | |
3601 { | |
3602 /* Don't need to insert spaces when "p" on the last position of a | |
3603 * tab or "P" on the first position. */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3604 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3605 int viscol = getviscol(); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3606 if (dir == FORWARD |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3607 ? tabstop_padding(viscol, curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3608 curbuf->b_p_vts_array) != 1 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3609 : curwin->w_cursor.coladd > 0) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3610 coladvance_force(viscol); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3611 #else |
7 | 3612 if (dir == FORWARD |
3613 ? (int)curwin->w_cursor.coladd < curbuf->b_p_ts - 1 | |
3614 : curwin->w_cursor.coladd > 0) | |
3615 coladvance_force(getviscol()); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14019
diff
changeset
|
3616 #endif |
7 | 3617 else |
3618 curwin->w_cursor.coladd = 0; | |
3619 } | |
3620 else if (curwin->w_cursor.coladd > 0 || gchar_cursor() == NUL) | |
3621 coladvance_force(getviscol() + (dir == FORWARD)); | |
3622 } | |
3623 | |
3624 lnum = curwin->w_cursor.lnum; | |
3625 col = curwin->w_cursor.col; | |
3626 | |
3627 /* | |
3628 * Block mode | |
3629 */ | |
3630 if (y_type == MBLOCK) | |
3631 { | |
10664
94db9c08e206
patch 8.0.0222: blockwise put on multi-byte character misplaced
Christian Brabandt <cb@256bit.org>
parents:
10494
diff
changeset
|
3632 int c = gchar_cursor(); |
7 | 3633 colnr_T endcol2 = 0; |
3634 | |
3635 if (dir == FORWARD && c != NUL) | |
3636 { | |
3637 if (ve_flags == VE_ALL) | |
3638 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3639 else | |
3640 getvcol(curwin, &curwin->w_cursor, NULL, NULL, &col); | |
3641 | |
3642 if (has_mbyte) | |
3643 /* move to start of next multi-byte character */ | |
474 | 3644 curwin->w_cursor.col += (*mb_ptr2len)(ml_get_cursor()); |
7 | 3645 else |
3646 if (c != TAB || ve_flags != VE_ALL) | |
3647 ++curwin->w_cursor.col; | |
3648 ++col; | |
3649 } | |
3650 else | |
3651 getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); | |
3652 | |
3653 col += curwin->w_cursor.coladd; | |
1304 | 3654 if (ve_flags == VE_ALL |
3655 && (curwin->w_cursor.coladd > 0 | |
3656 || endcol2 == curwin->w_cursor.col)) | |
7 | 3657 { |
3658 if (dir == FORWARD && c == NUL) | |
3659 ++col; | |
3660 if (dir != FORWARD && c != NUL) | |
3661 ++curwin->w_cursor.col; | |
3662 if (c == TAB) | |
3663 { | |
3664 if (dir == BACKWARD && curwin->w_cursor.col) | |
3665 curwin->w_cursor.col--; | |
3666 if (dir == FORWARD && col - 1 == endcol2) | |
3667 curwin->w_cursor.col++; | |
3668 } | |
3669 } | |
3670 curwin->w_cursor.coladd = 0; | |
699 | 3671 bd.textcol = 0; |
7 | 3672 for (i = 0; i < y_size; ++i) |
3673 { | |
3674 int spaces; | |
3675 char shortline; | |
3676 | |
3677 bd.startspaces = 0; | |
3678 bd.endspaces = 0; | |
3679 vcol = 0; | |
3680 delcount = 0; | |
3681 | |
3682 /* add a new line */ | |
3683 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
3684 { | |
3685 if (ml_append(curbuf->b_ml.ml_line_count, (char_u *)"", | |
3686 (colnr_T)1, FALSE) == FAIL) | |
3687 break; | |
3688 ++nr_lines; | |
3689 } | |
3690 /* get the old line and advance to the position to insert at */ | |
3691 oldp = ml_get_curline(); | |
3692 oldlen = (int)STRLEN(oldp); | |
3693 for (ptr = oldp; vcol < col && *ptr; ) | |
3694 { | |
3695 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 3696 incr = lbr_chartabsize_adv(oldp, &ptr, (colnr_T)vcol); |
7 | 3697 vcol += incr; |
3698 } | |
3699 bd.textcol = (colnr_T)(ptr - oldp); | |
3700 | |
3701 shortline = (vcol < col) || (vcol == col && !*ptr) ; | |
3702 | |
3703 if (vcol < col) /* line too short, padd with spaces */ | |
3704 bd.startspaces = col - vcol; | |
3705 else if (vcol > col) | |
3706 { | |
3707 bd.endspaces = vcol - col; | |
3708 bd.startspaces = incr - bd.endspaces; | |
3709 --bd.textcol; | |
3710 delcount = 1; | |
3711 if (has_mbyte) | |
3712 bd.textcol -= (*mb_head_off)(oldp, oldp + bd.textcol); | |
3713 if (oldp[bd.textcol] != TAB) | |
3714 { | |
3715 /* Only a Tab can be split into spaces. Other | |
3716 * characters will have to be moved to after the | |
3717 * block, causing misalignment. */ | |
3718 delcount = 0; | |
3719 bd.endspaces = 0; | |
3720 } | |
3721 } | |
3722 | |
3723 yanklen = (int)STRLEN(y_array[i]); | |
3724 | |
3725 /* calculate number of spaces required to fill right side of block*/ | |
3726 spaces = y_width + 1; | |
3727 for (j = 0; j < yanklen; j++) | |
5995 | 3728 spaces -= lbr_chartabsize(NULL, &y_array[i][j], 0); |
7 | 3729 if (spaces < 0) |
3730 spaces = 0; | |
3731 | |
3732 /* insert the new text */ | |
3733 totlen = count * (yanklen + spaces) + bd.startspaces + bd.endspaces; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
3734 newp = alloc(totlen + oldlen + 1); |
7 | 3735 if (newp == NULL) |
3736 break; | |
3737 /* copy part up to cursor to new line */ | |
3738 ptr = newp; | |
3739 mch_memmove(ptr, oldp, (size_t)bd.textcol); | |
3740 ptr += bd.textcol; | |
3741 /* may insert some spaces before the new text */ | |
6929 | 3742 vim_memset(ptr, ' ', (size_t)bd.startspaces); |
7 | 3743 ptr += bd.startspaces; |
3744 /* insert the new text */ | |
3745 for (j = 0; j < count; ++j) | |
3746 { | |
3747 mch_memmove(ptr, y_array[i], (size_t)yanklen); | |
3748 ptr += yanklen; | |
3749 | |
3750 /* insert block's trailing spaces only if there's text behind */ | |
3751 if ((j < count - 1 || !shortline) && spaces) | |
3752 { | |
6929 | 3753 vim_memset(ptr, ' ', (size_t)spaces); |
7 | 3754 ptr += spaces; |
3755 } | |
3756 } | |
3757 /* may insert some spaces after the new text */ | |
6929 | 3758 vim_memset(ptr, ' ', (size_t)bd.endspaces); |
7 | 3759 ptr += bd.endspaces; |
3760 /* move the text after the cursor to the end of the line. */ | |
3761 mch_memmove(ptr, oldp + bd.textcol + delcount, | |
3762 (size_t)(oldlen - bd.textcol - delcount + 1)); | |
3763 ml_replace(curwin->w_cursor.lnum, newp, FALSE); | |
3764 | |
3765 ++curwin->w_cursor.lnum; | |
3766 if (i == 0) | |
3767 curwin->w_cursor.col += bd.startspaces; | |
3768 } | |
3769 | |
3770 changed_lines(lnum, 0, curwin->w_cursor.lnum, nr_lines); | |
3771 | |
3772 /* Set '[ mark. */ | |
3773 curbuf->b_op_start = curwin->w_cursor; | |
3774 curbuf->b_op_start.lnum = lnum; | |
3775 | |
3776 /* adjust '] mark */ | |
3777 curbuf->b_op_end.lnum = curwin->w_cursor.lnum - 1; | |
3778 curbuf->b_op_end.col = bd.textcol + totlen - 1; | |
3779 curbuf->b_op_end.coladd = 0; | |
3780 if (flags & PUT_CURSEND) | |
3781 { | |
916 | 3782 colnr_T len; |
3783 | |
7 | 3784 curwin->w_cursor = curbuf->b_op_end; |
3785 curwin->w_cursor.col++; | |
916 | 3786 |
3787 /* in Insert mode we might be after the NUL, correct for that */ | |
3788 len = (colnr_T)STRLEN(ml_get_curline()); | |
3789 if (curwin->w_cursor.col > len) | |
3790 curwin->w_cursor.col = len; | |
7 | 3791 } |
3792 else | |
3793 curwin->w_cursor.lnum = lnum; | |
3794 } | |
3795 else | |
3796 { | |
3797 /* | |
3798 * Character or Line mode | |
3799 */ | |
3800 if (y_type == MCHAR) | |
3801 { | |
3802 /* if type is MCHAR, FORWARD is the same as BACKWARD on the next | |
3803 * char */ | |
3804 if (dir == FORWARD && gchar_cursor() != NUL) | |
3805 { | |
3806 if (has_mbyte) | |
3807 { | |
474 | 3808 int bytelen = (*mb_ptr2len)(ml_get_cursor()); |
7 | 3809 |
3810 /* put it on the next of the multi-byte character. */ | |
3811 col += bytelen; | |
3812 if (yanklen) | |
3813 { | |
3814 curwin->w_cursor.col += bytelen; | |
3815 curbuf->b_op_end.col += bytelen; | |
3816 } | |
3817 } | |
3818 else | |
3819 { | |
3820 ++col; | |
3821 if (yanklen) | |
3822 { | |
3823 ++curwin->w_cursor.col; | |
3824 ++curbuf->b_op_end.col; | |
3825 } | |
3826 } | |
3827 } | |
3828 curbuf->b_op_start = curwin->w_cursor; | |
3829 } | |
3830 /* | |
3831 * Line mode: BACKWARD is the same as FORWARD on the previous line | |
3832 */ | |
3833 else if (dir == BACKWARD) | |
3834 --lnum; | |
699 | 3835 new_cursor = curwin->w_cursor; |
7 | 3836 |
3837 /* | |
3838 * simple case: insert into current line | |
3839 */ | |
3840 if (y_type == MCHAR && y_size == 1) | |
3841 { | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3842 linenr_T end_lnum = 0; /* init for gcc */ |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3843 |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3844 if (VIsual_active) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3845 { |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3846 end_lnum = curbuf->b_visual.vi_end.lnum; |
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3847 if (end_lnum < curbuf->b_visual.vi_start.lnum) |
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3848 end_lnum = curbuf->b_visual.vi_start.lnum; |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3849 } |
10670
bce3eccea39a
patch 8.0.0225: put in Visual block mode terminates early
Christian Brabandt <cb@256bit.org>
parents:
10664
diff
changeset
|
3850 |
5365 | 3851 do { |
3852 totlen = count * yanklen; | |
3853 if (totlen > 0) | |
7 | 3854 { |
5365 | 3855 oldp = ml_get(lnum); |
10688
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3856 if (VIsual_active && col > (int)STRLEN(oldp)) |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3857 { |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3858 lnum++; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3859 continue; |
3d1872fbecc4
patch 8.0.0234: crash when using put in Visual mode
Christian Brabandt <cb@256bit.org>
parents:
10670
diff
changeset
|
3860 } |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
3861 newp = alloc(STRLEN(oldp) + totlen + 1); |
5365 | 3862 if (newp == NULL) |
3863 goto end; /* alloc() gave an error message */ | |
3864 mch_memmove(newp, oldp, (size_t)col); | |
3865 ptr = newp + col; | |
3866 for (i = 0; i < count; ++i) | |
3867 { | |
3868 mch_memmove(ptr, y_array[0], (size_t)yanklen); | |
3869 ptr += yanklen; | |
3870 } | |
3871 STRMOVE(ptr, oldp + col); | |
3872 ml_replace(lnum, newp, FALSE); | |
3873 /* Place cursor on last putted char. */ | |
3874 if (lnum == curwin->w_cursor.lnum) | |
5496 | 3875 { |
3876 /* make sure curwin->w_virtcol is updated */ | |
3877 changed_cline_bef_curs(); | |
5365 | 3878 curwin->w_cursor.col += (colnr_T)(totlen - 1); |
5496 | 3879 } |
7 | 3880 } |
5365 | 3881 if (VIsual_active) |
3882 lnum++; | |
10692
d9aeddd9086b
patch 8.0.0236: gcc complains about uninitialized variable
Christian Brabandt <cb@256bit.org>
parents:
10688
diff
changeset
|
3883 } while (VIsual_active && lnum <= end_lnum); |
5365 | 3884 |
6379 | 3885 if (VIsual_active) /* reset lnum to the last visual line */ |
3886 lnum--; | |
3887 | |
7 | 3888 curbuf->b_op_end = curwin->w_cursor; |
3889 /* For "CTRL-O p" in Insert mode, put cursor after last char */ | |
3890 if (totlen && (restart_edit != 0 || (flags & PUT_CURSEND))) | |
3891 ++curwin->w_cursor.col; | |
3892 changed_bytes(lnum, col); | |
3893 } | |
3894 else | |
3895 { | |
3896 /* | |
3897 * Insert at least one line. When y_type is MCHAR, break the first | |
3898 * line in two. | |
3899 */ | |
3900 for (cnt = 1; cnt <= count; ++cnt) | |
3901 { | |
3902 i = 0; | |
3903 if (y_type == MCHAR) | |
3904 { | |
3905 /* | |
3906 * Split the current line in two at the insert position. | |
3907 * First insert y_array[size - 1] in front of second line. | |
3908 * Then append y_array[0] to first line. | |
3909 */ | |
3910 lnum = new_cursor.lnum; | |
3911 ptr = ml_get(lnum) + col; | |
3912 totlen = (int)STRLEN(y_array[y_size - 1]); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
3913 newp = alloc(STRLEN(ptr) + totlen + 1); |
7 | 3914 if (newp == NULL) |
3915 goto error; | |
3916 STRCPY(newp, y_array[y_size - 1]); | |
3917 STRCAT(newp, ptr); | |
3918 /* insert second line */ | |
3919 ml_append(lnum, newp, (colnr_T)0, FALSE); | |
3920 vim_free(newp); | |
3921 | |
3922 oldp = ml_get(lnum); | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
3923 newp = alloc(col + yanklen + 1); |
7 | 3924 if (newp == NULL) |
3925 goto error; | |
3926 /* copy first part of line */ | |
3927 mch_memmove(newp, oldp, (size_t)col); | |
3928 /* append to first line */ | |
3929 mch_memmove(newp + col, y_array[0], (size_t)(yanklen + 1)); | |
3930 ml_replace(lnum, newp, FALSE); | |
3931 | |
3932 curwin->w_cursor.lnum = lnum; | |
3933 i = 1; | |
3934 } | |
3935 | |
3936 for (; i < y_size; ++i) | |
3937 { | |
3938 if ((y_type != MCHAR || i < y_size - 1) | |
3939 && ml_append(lnum, y_array[i], (colnr_T)0, FALSE) | |
3940 == FAIL) | |
3941 goto error; | |
3942 lnum++; | |
3943 ++nr_lines; | |
3944 if (flags & PUT_FIXINDENT) | |
3945 { | |
3946 old_pos = curwin->w_cursor; | |
3947 curwin->w_cursor.lnum = lnum; | |
3948 ptr = ml_get(lnum); | |
3949 if (cnt == count && i == y_size - 1) | |
3950 lendiff = (int)STRLEN(ptr); | |
3951 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) | |
3952 if (*ptr == '#' && preprocs_left()) | |
3953 indent = 0; /* Leave # lines at start */ | |
3954 else | |
3955 #endif | |
3956 if (*ptr == NUL) | |
3957 indent = 0; /* Ignore empty lines */ | |
3958 else if (first_indent) | |
3959 { | |
3960 indent_diff = orig_indent - get_indent(); | |
3961 indent = orig_indent; | |
3962 first_indent = FALSE; | |
3963 } | |
3964 else if ((indent = get_indent() + indent_diff) < 0) | |
3965 indent = 0; | |
3966 (void)set_indent(indent, 0); | |
3967 curwin->w_cursor = old_pos; | |
3968 /* remember how many chars were removed */ | |
3969 if (cnt == count && i == y_size - 1) | |
3970 lendiff -= (int)STRLEN(ml_get(lnum)); | |
3971 } | |
3972 } | |
3973 } | |
3974 | |
3975 error: | |
3976 /* Adjust marks. */ | |
3977 if (y_type == MLINE) | |
3978 { | |
3979 curbuf->b_op_start.col = 0; | |
3980 if (dir == FORWARD) | |
3981 curbuf->b_op_start.lnum++; | |
3982 } | |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3983 /* Skip mark_adjust when adding lines after the last one, there |
11065
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3984 * can't be marks there. But still needed in diff mode. */ |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3985 if (curbuf->b_op_start.lnum + (y_type == MCHAR) - 1 + nr_lines |
11065
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3986 < curbuf->b_ml.ml_line_count |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3987 #ifdef FEAT_DIFF |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3988 || curwin->w_p_diff |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3989 #endif |
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
3990 ) |
9225
b0b2bd8e5217
commit https://github.com/vim/vim/commit/82faa259cc42379f2a17d598a2a39d14048685b0
Christian Brabandt <cb@256bit.org>
parents:
8989
diff
changeset
|
3991 mark_adjust(curbuf->b_op_start.lnum + (y_type == MCHAR), |
7 | 3992 (linenr_T)MAXLNUM, nr_lines, 0L); |
3993 | |
3994 /* note changed text for displaying and folding */ | |
3995 if (y_type == MCHAR) | |
3996 changed_lines(curwin->w_cursor.lnum, col, | |
3997 curwin->w_cursor.lnum + 1, nr_lines); | |
3998 else | |
3999 changed_lines(curbuf->b_op_start.lnum, 0, | |
4000 curbuf->b_op_start.lnum, nr_lines); | |
4001 | |
4002 /* put '] mark at last inserted character */ | |
4003 curbuf->b_op_end.lnum = lnum; | |
4004 /* correct length for change in indent */ | |
4005 col = (colnr_T)STRLEN(y_array[y_size - 1]) - lendiff; | |
4006 if (col > 1) | |
4007 curbuf->b_op_end.col = col - 1; | |
4008 else | |
4009 curbuf->b_op_end.col = 0; | |
4010 | |
168 | 4011 if (flags & PUT_CURSLINE) |
4012 { | |
237 | 4013 /* ":put": put cursor on last inserted line */ |
168 | 4014 curwin->w_cursor.lnum = lnum; |
4015 beginline(BL_WHITE | BL_FIX); | |
4016 } | |
4017 else if (flags & PUT_CURSEND) | |
7 | 4018 { |
4019 /* put cursor after inserted text */ | |
4020 if (y_type == MLINE) | |
4021 { | |
4022 if (lnum >= curbuf->b_ml.ml_line_count) | |
4023 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4024 else | |
4025 curwin->w_cursor.lnum = lnum + 1; | |
4026 curwin->w_cursor.col = 0; | |
4027 } | |
4028 else | |
4029 { | |
4030 curwin->w_cursor.lnum = lnum; | |
4031 curwin->w_cursor.col = col; | |
4032 } | |
4033 } | |
4034 else if (y_type == MLINE) | |
4035 { | |
168 | 4036 /* put cursor on first non-blank in first inserted line */ |
7 | 4037 curwin->w_cursor.col = 0; |
4038 if (dir == FORWARD) | |
4039 ++curwin->w_cursor.lnum; | |
4040 beginline(BL_WHITE | BL_FIX); | |
4041 } | |
4042 else /* put cursor on first inserted character */ | |
4043 curwin->w_cursor = new_cursor; | |
4044 } | |
4045 } | |
4046 | |
4047 msgmore(nr_lines); | |
4048 curwin->w_set_curswant = TRUE; | |
4049 | |
4050 end: | |
4051 if (allocated) | |
4052 vim_free(insert_string); | |
840 | 4053 if (regname == '=') |
4054 vim_free(y_array); | |
4055 | |
5380 | 4056 VIsual_active = FALSE; |
4057 | |
140 | 4058 /* If the cursor is past the end of the line put it at the end. */ |
844 | 4059 adjust_cursor_eol(); |
4060 } | |
4061 | |
4062 /* | |
4063 * When the cursor is on the NUL past the end of the line and it should not be | |
4064 * there move it left. | |
4065 */ | |
4066 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4067 adjust_cursor_eol(void) |
844 | 4068 { |
4069 if (curwin->w_cursor.col > 0 | |
4070 && gchar_cursor() == NUL | |
773 | 4071 && (ve_flags & VE_ONEMORE) == 0 |
7 | 4072 && !(restart_edit || (State & INSERT))) |
4073 { | |
557 | 4074 /* Put the cursor on the last character in the line. */ |
555 | 4075 dec_cursor(); |
844 | 4076 |
7 | 4077 if (ve_flags == VE_ALL) |
557 | 4078 { |
4079 colnr_T scol, ecol; | |
4080 | |
4081 /* Coladd is set to the width of the last character. */ | |
4082 getvcol(curwin, &curwin->w_cursor, &scol, NULL, &ecol); | |
4083 curwin->w_cursor.coladd = ecol - scol + 1; | |
4084 } | |
7 | 4085 } |
4086 } | |
4087 | |
4088 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT) || defined(PROTO) | |
4089 /* | |
4090 * Return TRUE if lines starting with '#' should be left aligned. | |
4091 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17652
diff
changeset
|
4092 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4093 preprocs_left(void) |
7 | 4094 { |
4095 return | |
4096 # ifdef FEAT_SMARTINDENT | |
4097 # ifdef FEAT_CINDENT | |
4098 (curbuf->b_p_si && !curbuf->b_p_cin) || | |
4099 # else | |
4100 curbuf->b_p_si | |
4101 # endif | |
4102 # endif | |
4103 # ifdef FEAT_CINDENT | |
5438 | 4104 (curbuf->b_p_cin && in_cinkeys('#', ' ', TRUE) |
4105 && curbuf->b_ind_hash_comment == 0) | |
7 | 4106 # endif |
4107 ; | |
4108 } | |
4109 #endif | |
4110 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4111 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4112 * Return the character name of the register with the given number. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4113 */ |
7 | 4114 int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4115 get_register_name(int num) |
7 | 4116 { |
4117 if (num == -1) | |
4118 return '"'; | |
4119 else if (num < 10) | |
4120 return num + '0'; | |
4121 else if (num == DELETION_REGISTER) | |
4122 return '-'; | |
4123 #ifdef FEAT_CLIPBOARD | |
4124 else if (num == STAR_REGISTER) | |
4125 return '*'; | |
4126 else if (num == PLUS_REGISTER) | |
4127 return '+'; | |
4128 #endif | |
4129 else | |
4130 { | |
4131 #ifdef EBCDIC | |
4132 int i; | |
4133 | |
4134 /* EBCDIC is really braindead ... */ | |
4135 i = 'a' + (num - 10); | |
4136 if (i > 'i') | |
4137 i += 7; | |
4138 if (i > 'r') | |
4139 i += 8; | |
4140 return i; | |
4141 #else | |
4142 return num + 'a' - 10; | |
4143 #endif | |
4144 } | |
4145 } | |
4146 | |
4147 /* | |
4148 * ":dis" and ":registers": Display the contents of the yank registers. | |
4149 */ | |
4150 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4151 ex_display(exarg_T *eap) |
7 | 4152 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4153 int i, n; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4154 long j; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4155 char_u *p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4156 yankreg_T *yb; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4157 int name; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4158 int attr; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4159 char_u *arg = eap->arg; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
4160 int clen; |
7 | 4161 |
4162 if (arg != NULL && *arg == NUL) | |
4163 arg = NULL; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11131
diff
changeset
|
4164 attr = HL_ATTR(HLF_8); |
7 | 4165 |
4166 /* Highlight title */ | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4167 msg_puts_title(_("\n--- Registers ---")); |
7 | 4168 for (i = -1; i < NUM_REGISTERS && !got_int; ++i) |
4169 { | |
4170 name = get_register_name(i); | |
2644 | 4171 if (arg != NULL && vim_strchr(arg, name) == NULL |
4172 #ifdef ONE_CLIPBOARD | |
4173 /* Star register and plus register contain the same thing. */ | |
4174 && (name != '*' || vim_strchr(arg, '+') == NULL) | |
4175 #endif | |
4176 ) | |
7 | 4177 continue; /* did not ask for this register */ |
4178 | |
4179 #ifdef FEAT_CLIPBOARD | |
4180 /* Adjust register name for "unnamed" in 'clipboard'. | |
4181 * When it's a clipboard register, fill it with the current contents | |
4182 * of the clipboard. */ | |
4183 adjust_clip_reg(&name); | |
4184 (void)may_get_selection(name); | |
4185 #endif | |
4186 | |
4187 if (i == -1) | |
4188 { | |
4189 if (y_previous != NULL) | |
4190 yb = y_previous; | |
4191 else | |
4192 yb = &(y_regs[0]); | |
4193 } | |
4194 else | |
4195 yb = &(y_regs[i]); | |
2000 | 4196 |
4197 #ifdef FEAT_EVAL | |
4198 if (name == MB_TOLOWER(redir_reg) | |
4199 || (redir_reg == '"' && yb == y_previous)) | |
4200 continue; /* do not list register being written to, the | |
4201 * pointer can be freed */ | |
4202 #endif | |
4203 | |
7 | 4204 if (yb->y_array != NULL) |
4205 { | |
4206 msg_putchar('\n'); | |
4207 msg_putchar('"'); | |
4208 msg_putchar(name); | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4209 msg_puts(" "); |
7 | 4210 |
4211 n = (int)Columns - 6; | |
4212 for (j = 0; j < yb->y_size && n > 1; ++j) | |
4213 { | |
4214 if (j) | |
4215 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4216 msg_puts_attr("^J", attr); |
7 | 4217 n -= 2; |
4218 } | |
4219 for (p = yb->y_array[j]; *p && (n -= ptr2cells(p)) >= 0; ++p) | |
4220 { | |
474 | 4221 clen = (*mb_ptr2len)(p); |
22 | 4222 msg_outtrans_len(p, clen); |
4223 p += clen - 1; | |
7 | 4224 } |
4225 } | |
4226 if (n > 1 && yb->y_type == MLINE) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4227 msg_puts_attr("^J", attr); |
7 | 4228 out_flush(); /* show one line at a time */ |
4229 } | |
4230 ui_breakcheck(); | |
4231 } | |
4232 | |
4233 /* | |
4234 * display last inserted text | |
4235 */ | |
4236 if ((p = get_last_insert()) != NULL | |
4237 && (arg == NULL || vim_strchr(arg, '.') != NULL) && !got_int) | |
4238 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4239 msg_puts("\n\". "); |
7 | 4240 dis_msg(p, TRUE); |
4241 } | |
4242 | |
4243 /* | |
4244 * display last command line | |
4245 */ | |
4246 if (last_cmdline != NULL && (arg == NULL || vim_strchr(arg, ':') != NULL) | |
4247 && !got_int) | |
4248 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4249 msg_puts("\n\": "); |
7 | 4250 dis_msg(last_cmdline, FALSE); |
4251 } | |
4252 | |
4253 /* | |
4254 * display current file name | |
4255 */ | |
4256 if (curbuf->b_fname != NULL | |
4257 && (arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4258 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4259 msg_puts("\n\"% "); |
7 | 4260 dis_msg(curbuf->b_fname, FALSE); |
4261 } | |
4262 | |
4263 /* | |
4264 * display alternate file name | |
4265 */ | |
4266 if ((arg == NULL || vim_strchr(arg, '%') != NULL) && !got_int) | |
4267 { | |
4268 char_u *fname; | |
4269 linenr_T dummy; | |
4270 | |
4271 if (buflist_name_nr(0, &fname, &dummy) != FAIL) | |
4272 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4273 msg_puts("\n\"# "); |
7 | 4274 dis_msg(fname, FALSE); |
4275 } | |
4276 } | |
4277 | |
4278 /* | |
4279 * display last search pattern | |
4280 */ | |
4281 if (last_search_pat() != NULL | |
4282 && (arg == NULL || vim_strchr(arg, '/') != NULL) && !got_int) | |
4283 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4284 msg_puts("\n\"/ "); |
7 | 4285 dis_msg(last_search_pat(), FALSE); |
4286 } | |
4287 | |
4288 #ifdef FEAT_EVAL | |
4289 /* | |
4290 * display last used expression | |
4291 */ | |
4292 if (expr_line != NULL && (arg == NULL || vim_strchr(arg, '=') != NULL) | |
4293 && !got_int) | |
4294 { | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
4295 msg_puts("\n\"= "); |
7 | 4296 dis_msg(expr_line, FALSE); |
4297 } | |
4298 #endif | |
4299 } | |
4300 | |
4301 /* | |
4302 * display a string for do_dis() | |
4303 * truncate at end of screen line | |
4304 */ | |
4305 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4306 dis_msg( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4307 char_u *p, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4308 int skip_esc) /* if TRUE, ignore trailing ESC */ |
7 | 4309 { |
4310 int n; | |
4311 int l; | |
4312 | |
4313 n = (int)Columns - 6; | |
4314 while (*p != NUL | |
4315 && !(*p == ESC && skip_esc && *(p + 1) == NUL) | |
4316 && (n -= ptr2cells(p)) >= 0) | |
4317 { | |
474 | 4318 if (has_mbyte && (l = (*mb_ptr2len)(p)) > 1) |
7 | 4319 { |
4320 msg_outtrans_len(p, l); | |
4321 p += l; | |
4322 } | |
4323 else | |
4324 msg_outtrans_len(p++, 1); | |
4325 } | |
4326 ui_breakcheck(); | |
4327 } | |
4328 | |
3562 | 4329 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4330 /* | |
4331 * If "process" is TRUE and the line begins with a comment leader (possibly | |
4332 * after some white space), return a pointer to the text after it. Put a boolean | |
4333 * value indicating whether the line ends with an unclosed comment in | |
4334 * "is_comment". | |
4335 * line - line to be processed, | |
4336 * process - if FALSE, will only check whether the line ends with an unclosed | |
3584 | 4337 * comment, |
3562 | 4338 * include_space - whether to also skip space following the comment leader, |
4339 * is_comment - will indicate whether the current line ends with an unclosed | |
3584 | 4340 * comment. |
3562 | 4341 */ |
11131
8d9ecf09183a
patch 8.0.0453: adding fold marker creates new comment
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
4342 char_u * |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4343 skip_comment( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4344 char_u *line, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4345 int process, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4346 int include_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4347 int *is_comment) |
3562 | 4348 { |
4349 char_u *comment_flags = NULL; | |
4350 int lead_len; | |
4351 int leader_offset = get_last_leader_offset(line, &comment_flags); | |
4352 | |
4353 *is_comment = FALSE; | |
4354 if (leader_offset != -1) | |
4355 { | |
4356 /* Let's check whether the line ends with an unclosed comment. | |
4357 * If the last comment leader has COM_END in flags, there's no comment. | |
4358 */ | |
4359 while (*comment_flags) | |
4360 { | |
4361 if (*comment_flags == COM_END | |
4362 || *comment_flags == ':') | |
4363 break; | |
4364 ++comment_flags; | |
4365 } | |
4366 if (*comment_flags != COM_END) | |
4367 *is_comment = TRUE; | |
4368 } | |
4369 | |
4370 if (process == FALSE) | |
4371 return line; | |
4372 | |
4373 lead_len = get_leader_len(line, &comment_flags, FALSE, include_space); | |
4374 | |
4375 if (lead_len == 0) | |
4376 return line; | |
4377 | |
4378 /* Find: | |
4379 * - COM_END, | |
4380 * - colon, | |
4381 * whichever comes first. | |
4382 */ | |
4383 while (*comment_flags) | |
4384 { | |
3580 | 4385 if (*comment_flags == COM_END |
3562 | 4386 || *comment_flags == ':') |
4387 break; | |
4388 ++comment_flags; | |
4389 } | |
4390 | |
4391 /* If we found a colon, it means that we are not processing a line | |
3580 | 4392 * starting with a closing part of a three-part comment. That's good, |
4393 * because we don't want to remove those as this would be annoying. | |
3562 | 4394 */ |
4395 if (*comment_flags == ':' || *comment_flags == NUL) | |
4396 line += lead_len; | |
4397 | |
4398 return line; | |
4399 } | |
4400 #endif | |
4401 | |
7 | 4402 /* |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4403 * Join 'count' lines (minimal 2) at cursor position. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4404 * When "save_undo" is TRUE save lines for undo first. |
5848 | 4405 * Set "use_formatoptions" to FALSE when e.g. processing backspace and comment |
4406 * leaders should not be removed. | |
4407 * When setmark is TRUE, sets the '[ and '] mark, else, the caller is expected | |
4408 * to set those marks. | |
7 | 4409 * |
1217 | 4410 * return FAIL for failure, OK otherwise |
7 | 4411 */ |
4412 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4413 do_join( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4414 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4415 int insert_space, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4416 int save_undo, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4417 int use_formatoptions UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4418 int setmark) |
7 | 4419 { |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4420 char_u *curr = NULL; |
2597 | 4421 char_u *curr_start = NULL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4422 char_u *cend; |
7 | 4423 char_u *newp; |
2597 | 4424 char_u *spaces; /* number of spaces inserted before a line */ |
2310
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4425 int endcurr1 = NUL; |
3e4574a4b627
Fix a few compiler warnings.
Bram Moolenaar <bram@vim.org>
parents:
2298
diff
changeset
|
4426 int endcurr2 = NUL; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4427 int currsize = 0; /* size of the current line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4428 int sumsize = 0; /* size of the long new line */ |
7 | 4429 linenr_T t; |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4430 colnr_T col = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4431 int ret = OK; |
3562 | 4432 #if defined(FEAT_COMMENTS) || defined(PROTO) |
3574 | 4433 int *comments = NULL; |
3562 | 4434 int remove_comments = (use_formatoptions == TRUE) |
4435 && has_format_option(FO_REMOVE_COMS); | |
4436 int prev_was_comment; | |
4437 #endif | |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4438 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4439 textprop_T **prop_lines = NULL; |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4440 int *prop_lengths = NULL; |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4441 #endif |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4442 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4443 if (save_undo && u_save((linenr_T)(curwin->w_cursor.lnum - 1), |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4444 (linenr_T)(curwin->w_cursor.lnum + count)) == FAIL) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4445 return FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4446 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4447 /* Allocate an array to store the number of spaces inserted before each |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4448 * line. We will use it to pre-compute the length of the new line and the |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4449 * proper placement of each original line in the new one. */ |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
4450 spaces = lalloc_clear(count, TRUE); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4451 if (spaces == NULL) |
7 | 4452 return FAIL; |
3562 | 4453 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4454 if (remove_comments) | |
4455 { | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
4456 comments = lalloc_clear(count * sizeof(int), TRUE); |
3562 | 4457 if (comments == NULL) |
4458 { | |
4459 vim_free(spaces); | |
4460 return FAIL; | |
4461 } | |
4462 } | |
4463 #endif | |
7 | 4464 |
4465 /* | |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4466 * Don't move anything yet, just compute the final line length |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4467 * and setup the array of space strings lengths |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4468 * This loops forward over the joined lines. |
7 | 4469 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4470 for (t = 0; t < count; ++t) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4471 { |
2597 | 4472 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t)); |
5848 | 4473 if (t == 0 && setmark) |
5664 | 4474 { |
4475 /* Set the '[ mark. */ | |
4476 curwin->w_buffer->b_op_start.lnum = curwin->w_cursor.lnum; | |
4477 curwin->w_buffer->b_op_start.col = (colnr_T)STRLEN(curr); | |
4478 } | |
3562 | 4479 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4480 if (remove_comments) | |
4481 { | |
4482 /* We don't want to remove the comment leader if the | |
4483 * previous line is not a comment. */ | |
4484 if (t > 0 && prev_was_comment) | |
4485 { | |
4486 | |
4487 char_u *new_curr = skip_comment(curr, TRUE, insert_space, | |
4488 &prev_was_comment); | |
3576 | 4489 comments[t] = (int)(new_curr - curr); |
3562 | 4490 curr = new_curr; |
4491 } | |
4492 else | |
4493 curr = skip_comment(curr, FALSE, insert_space, | |
4494 &prev_was_comment); | |
4495 } | |
4496 #endif | |
4497 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4498 if (insert_space && t > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4499 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4500 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4501 if (*curr != ')' && currsize != 0 && endcurr1 != TAB |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4502 && (!has_format_option(FO_MBYTE_JOIN) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4503 || (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4504 && (!has_format_option(FO_MBYTE_JOIN2) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4505 || mb_ptr2char(curr) < 0x100 || endcurr1 < 0x100) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4506 ) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4507 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4508 /* don't add a space if the line is ending in a space */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4509 if (endcurr1 == ' ') |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4510 endcurr1 = endcurr2; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4511 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4512 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4513 /* extra space when 'joinspaces' set and line ends in '.' */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4514 if ( p_js |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4515 && (endcurr1 == '.' |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4516 || (vim_strchr(p_cpo, CPO_JOINSP) == NULL |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4517 && (endcurr1 == '?' || endcurr1 == '!')))) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4518 ++spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4519 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4520 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4521 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4522 sumsize += currsize + spaces[t]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4523 endcurr1 = endcurr2 = NUL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4524 if (insert_space && currsize > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4525 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4526 if (has_mbyte) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4527 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4528 cend = curr + currsize; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4529 MB_PTR_BACK(curr, cend); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4530 endcurr1 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4531 if (cend > curr) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4532 { |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
4533 MB_PTR_BACK(curr, cend); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4534 endcurr2 = (*mb_ptr2char)(cend); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4535 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4536 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4537 else |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4538 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4539 endcurr1 = *(curr + currsize - 1); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4540 if (currsize > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4541 endcurr2 = *(curr + currsize - 2); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4542 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4543 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4544 line_breakcheck(); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4545 if (got_int) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4546 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4547 ret = FAIL; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4548 goto theend; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4549 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4550 } |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4551 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4552 /* store the column position before last line */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4553 col = sumsize - currsize - spaces[count - 1]; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4554 |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4555 /* allocate the space for the new line */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
4556 newp = alloc(sumsize + 1); |
17797
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
4557 if (newp == NULL) |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
4558 { |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
4559 ret = FAIL; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
4560 goto theend; |
ec1717981acf
patch 8.1.1895: using NULL pointer when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
4561 } |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4562 cend = newp + sumsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4563 *cend = 0; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4564 |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4565 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4566 // We need to move properties of the lines that are going to be deleted to |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4567 // the new long one. |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4568 if (curbuf->b_has_textprop && !text_prop_frozen) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4569 { |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4570 // Allocate an array to copy the text properties of joined lines into. |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4571 // And another array to store the number of properties in each line. |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
4572 prop_lines = ALLOC_CLEAR_MULT(textprop_T *, count - 1); |
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
4573 prop_lengths = ALLOC_CLEAR_MULT(int, count - 1); |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4574 if (prop_lengths == NULL) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4575 VIM_CLEAR(prop_lines); |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4576 } |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4577 #endif |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4578 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4579 /* |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4580 * Move affected lines to the new long one. |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4581 * This loops backwards over the joined lines, including the original line. |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4582 * |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4583 * Move marks from each deleted line to the joined line, adjusting the |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4584 * column. This is not Vi compatible, but Vi deletes the marks, thus that |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4585 * should not really be a problem. |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4586 */ |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4587 for (t = count - 1; ; --t) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4588 { |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4589 int spaces_removed; |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4590 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4591 cend -= currsize; |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4592 mch_memmove(cend, curr, (size_t)currsize); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4593 if (spaces[t] > 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4594 { |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4595 cend -= spaces[t]; |
6929 | 4596 vim_memset(cend, ' ', (size_t)(spaces[t])); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4597 } |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4598 |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4599 // If deleting more spaces than adding, the cursor moves no more than |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4600 // what is added if it is inside these spaces. |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4601 spaces_removed = (curr - curr_start) - spaces[t]; |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4602 |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4603 mark_col_adjust(curwin->w_cursor.lnum + t, (colnr_T)0, (linenr_T)-t, |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
4604 (long)(cend - newp - spaces_removed), spaces_removed); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4605 if (t == 0) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4606 break; |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4607 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4608 if (prop_lines != NULL) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4609 adjust_props_for_join(curwin->w_cursor.lnum + t, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4610 prop_lines + t - 1, prop_lengths + t - 1, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4611 (long)(cend - newp - spaces_removed), spaces_removed); |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4612 #endif |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4613 |
2597 | 4614 curr = curr_start = ml_get((linenr_T)(curwin->w_cursor.lnum + t - 1)); |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4615 #if defined(FEAT_COMMENTS) |
3562 | 4616 if (remove_comments) |
4617 curr += comments[t - 1]; | |
4618 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4619 if (insert_space && t > 1) |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4620 curr = skipwhite(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4621 currsize = (int)STRLEN(curr); |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4622 } |
16678
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4623 |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4624 #ifdef FEAT_TEXT_PROP |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4625 if (prop_lines != NULL) |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4626 join_prop_lines(curwin->w_cursor.lnum, newp, |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4627 prop_lines, prop_lengths, count); |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4628 else |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4629 #endif |
6f453673eb19
patch 8.1.1341: text properties are lost when joining lines
Bram Moolenaar <Bram@vim.org>
parents:
16429
diff
changeset
|
4630 ml_replace(curwin->w_cursor.lnum, newp, FALSE); |
7 | 4631 |
5848 | 4632 if (setmark) |
4633 { | |
4634 /* Set the '] mark. */ | |
4635 curwin->w_buffer->b_op_end.lnum = curwin->w_cursor.lnum; | |
16680
c263acbbd961
patch 8.1.1342: using freed memory when joining line with text property
Bram Moolenaar <Bram@vim.org>
parents:
16678
diff
changeset
|
4636 curwin->w_buffer->b_op_end.col = (colnr_T)sumsize; |
5848 | 4637 } |
5664 | 4638 |
7 | 4639 /* Only report the change in the first line here, del_lines() will report |
4640 * the deleted line. */ | |
4641 changed_lines(curwin->w_cursor.lnum, currsize, | |
4642 curwin->w_cursor.lnum + 1, 0L); | |
4643 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4644 * Delete following lines. To do this we move the cursor there |
7 | 4645 * briefly, and then move it back. After del_lines() the cursor may |
4646 * have moved up (last line deleted), so the current lnum is kept in t. | |
4647 */ | |
4648 t = curwin->w_cursor.lnum; | |
4649 ++curwin->w_cursor.lnum; | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4650 del_lines(count - 1, FALSE); |
7 | 4651 curwin->w_cursor.lnum = t; |
4652 | |
4653 /* | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4654 * Set the cursor column: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4655 * Vi compatible: use the column of the first join |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2310
diff
changeset
|
4656 * vim: use the column of the last join |
7 | 4657 */ |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4658 curwin->w_cursor.col = |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4659 (vim_strchr(p_cpo, CPO_JOINCOL) != NULL ? currsize : col); |
7 | 4660 check_cursor_col(); |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4661 |
7 | 4662 curwin->w_cursor.coladd = 0; |
4663 curwin->w_set_curswant = TRUE; | |
4664 | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4665 theend: |
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4666 vim_free(spaces); |
3562 | 4667 #if defined(FEAT_COMMENTS) || defined(PROTO) |
4668 if (remove_comments) | |
4669 vim_free(comments); | |
4670 #endif | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
4671 return ret; |
7 | 4672 } |
4673 | |
4674 #ifdef FEAT_COMMENTS | |
4675 /* | |
4676 * Return TRUE if the two comment leaders given are the same. "lnum" is | |
4677 * the first line. White-space is ignored. Note that the whole of | |
4678 * 'leader1' must match 'leader2_len' characters from 'leader2' -- webb | |
4679 */ | |
4680 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4681 same_leader( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4682 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4683 int leader1_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4684 char_u *leader1_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4685 int leader2_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4686 char_u *leader2_flags) |
7 | 4687 { |
4688 int idx1 = 0, idx2 = 0; | |
4689 char_u *p; | |
4690 char_u *line1; | |
4691 char_u *line2; | |
4692 | |
4693 if (leader1_len == 0) | |
4694 return (leader2_len == 0); | |
4695 | |
4696 /* | |
4697 * If first leader has 'f' flag, the lines can be joined only if the | |
4698 * second line does not have a leader. | |
4699 * If first leader has 'e' flag, the lines can never be joined. | |
4700 * If fist leader has 's' flag, the lines can only be joined if there is | |
4701 * some text after it and the second line has the 'm' flag. | |
4702 */ | |
4703 if (leader1_flags != NULL) | |
4704 { | |
4705 for (p = leader1_flags; *p && *p != ':'; ++p) | |
4706 { | |
4707 if (*p == COM_FIRST) | |
4708 return (leader2_len == 0); | |
4709 if (*p == COM_END) | |
4710 return FALSE; | |
4711 if (*p == COM_START) | |
4712 { | |
4713 if (*(ml_get(lnum) + leader1_len) == NUL) | |
4714 return FALSE; | |
4715 if (leader2_flags == NULL || leader2_len == 0) | |
4716 return FALSE; | |
4717 for (p = leader2_flags; *p && *p != ':'; ++p) | |
4718 if (*p == COM_MIDDLE) | |
4719 return TRUE; | |
4720 return FALSE; | |
4721 } | |
4722 } | |
4723 } | |
4724 | |
4725 /* | |
4726 * Get current line and next line, compare the leaders. | |
4727 * The first line has to be saved, only one line can be locked at a time. | |
4728 */ | |
4729 line1 = vim_strsave(ml_get(lnum)); | |
4730 if (line1 != NULL) | |
4731 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4732 for (idx1 = 0; VIM_ISWHITE(line1[idx1]); ++idx1) |
7 | 4733 ; |
4734 line2 = ml_get(lnum + 1); | |
4735 for (idx2 = 0; idx2 < leader2_len; ++idx2) | |
4736 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4737 if (!VIM_ISWHITE(line2[idx2])) |
7 | 4738 { |
4739 if (line1[idx1++] != line2[idx2]) | |
4740 break; | |
4741 } | |
4742 else | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4743 while (VIM_ISWHITE(line1[idx1])) |
7 | 4744 ++idx1; |
4745 } | |
4746 vim_free(line1); | |
4747 } | |
4748 return (idx2 == leader2_len && idx1 == leader1_len); | |
4749 } | |
4750 #endif | |
4751 | |
4752 /* | |
3252 | 4753 * Implementation of the format operator 'gq'. |
7 | 4754 */ |
4755 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4756 op_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4757 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4758 int keep_cursor) /* keep cursor on same text char */ |
7 | 4759 { |
4760 long old_line_count = curbuf->b_ml.ml_line_count; | |
4761 | |
4762 /* Place the cursor where the "gq" or "gw" command was given, so that "u" | |
4763 * can put it back there. */ | |
4764 curwin->w_cursor = oap->cursor_start; | |
4765 | |
4766 if (u_save((linenr_T)(oap->start.lnum - 1), | |
4767 (linenr_T)(oap->end.lnum + 1)) == FAIL) | |
4768 return; | |
4769 curwin->w_cursor = oap->start; | |
4770 | |
4771 if (oap->is_VIsual) | |
4772 /* When there is no change: need to remove the Visual selection */ | |
4773 redraw_curbuf_later(INVERTED); | |
4774 | |
4775 /* Set '[ mark at the start of the formatted area */ | |
4776 curbuf->b_op_start = oap->start; | |
4777 | |
4778 /* For "gw" remember the cursor position and put it back below (adjusted | |
4779 * for joined and split lines). */ | |
4780 if (keep_cursor) | |
4781 saved_cursor = oap->cursor_start; | |
4782 | |
1563 | 4783 format_lines(oap->line_count, keep_cursor); |
7 | 4784 |
4785 /* | |
4786 * Leave the cursor at the first non-blank of the last formatted line. | |
4787 * If the cursor was moved one line back (e.g. with "Q}") go to the next | |
4788 * line, so "." will do the next lines. | |
4789 */ | |
4790 if (oap->end_adjusted && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
4791 ++curwin->w_cursor.lnum; | |
4792 beginline(BL_WHITE | BL_FIX); | |
4793 old_line_count = curbuf->b_ml.ml_line_count - old_line_count; | |
4794 msgmore(old_line_count); | |
4795 | |
4796 /* put '] mark on the end of the formatted area */ | |
4797 curbuf->b_op_end = curwin->w_cursor; | |
4798 | |
4799 if (keep_cursor) | |
4800 { | |
4801 curwin->w_cursor = saved_cursor; | |
4802 saved_cursor.lnum = 0; | |
4803 } | |
4804 | |
4805 if (oap->is_VIsual) | |
4806 { | |
4807 win_T *wp; | |
4808 | |
4809 FOR_ALL_WINDOWS(wp) | |
4810 { | |
4811 if (wp->w_old_cursor_lnum != 0) | |
4812 { | |
4813 /* When lines have been inserted or deleted, adjust the end of | |
4814 * the Visual area to be redrawn. */ | |
4815 if (wp->w_old_cursor_lnum > wp->w_old_visual_lnum) | |
4816 wp->w_old_cursor_lnum += old_line_count; | |
4817 else | |
4818 wp->w_old_visual_lnum += old_line_count; | |
4819 } | |
4820 } | |
4821 } | |
4822 } | |
4823 | |
667 | 4824 #if defined(FEAT_EVAL) || defined(PROTO) |
4825 /* | |
4826 * Implementation of the format operator 'gq' for when using 'formatexpr'. | |
4827 */ | |
4828 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4829 op_formatexpr(oparg_T *oap) |
667 | 4830 { |
4831 if (oap->is_VIsual) | |
4832 /* When there is no change: need to remove the Visual selection */ | |
4833 redraw_curbuf_later(INVERTED); | |
4834 | |
2298
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4835 if (fex_format(oap->start.lnum, oap->line_count, NUL) != 0) |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4836 /* As documented: when 'formatexpr' returns non-zero fall back to |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4837 * internal formatting. */ |
a3562a127cf6
When 'formatexpr' evaluates to non-zero fall back to internal formatting, also
Bram Moolenaar <bram@vim.org>
parents:
2294
diff
changeset
|
4838 op_format(oap, FALSE); |
667 | 4839 } |
4840 | |
4841 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4842 fex_format( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4843 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4844 long count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4845 int c) /* character to be inserted */ |
667 | 4846 { |
681 | 4847 int use_sandbox = was_set_insecurely((char_u *)"formatexpr", |
4848 OPT_LOCAL); | |
667 | 4849 int r; |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4850 char_u *fex; |
667 | 4851 |
4852 /* | |
4853 * Set v:lnum to the first line number and v:count to the number of lines. | |
844 | 4854 * Set v:char to the character to be inserted (can be NUL). |
667 | 4855 */ |
4856 set_vim_var_nr(VV_LNUM, lnum); | |
4857 set_vim_var_nr(VV_COUNT, count); | |
1969 | 4858 set_vim_var_char(c); |
844 | 4859 |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4860 /* Make a copy, the option could be changed while calling it. */ |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4861 fex = vim_strsave(curbuf->b_p_fex); |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4862 if (fex == NULL) |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4863 return 0; |
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4864 |
667 | 4865 /* |
4866 * Evaluate the function. | |
4867 */ | |
4868 if (use_sandbox) | |
4869 ++sandbox; | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4870 r = (int)eval_to_number(fex); |
667 | 4871 if (use_sandbox) |
4872 --sandbox; | |
844 | 4873 |
4874 set_vim_var_string(VV_CHAR, NULL, -1); | |
10104
b2dbe79639a2
commit https://github.com/vim/vim/commit/d77f9d595eb5f301b39b4373f2900a13c0ca30e2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4875 vim_free(fex); |
844 | 4876 |
667 | 4877 return r; |
4878 } | |
4879 #endif | |
4880 | |
7 | 4881 /* |
4882 * Format "line_count" lines, starting at the cursor position. | |
4883 * When "line_count" is negative, format until the end of the paragraph. | |
4884 * Lines after the cursor line are saved for undo, caller must have saved the | |
4885 * first line. | |
4886 */ | |
4887 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4888 format_lines( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4889 linenr_T line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
4890 int avoid_fex) /* don't use 'formatexpr' */ |
7 | 4891 { |
4892 int max_len; | |
4893 int is_not_par; /* current line not part of parag. */ | |
4894 int next_is_not_par; /* next line not part of paragraph */ | |
4895 int is_end_par; /* at end of paragraph */ | |
4896 int prev_is_end_par = FALSE;/* prev. line not part of parag. */ | |
4897 int next_is_start_par = FALSE; | |
4898 #ifdef FEAT_COMMENTS | |
4899 int leader_len = 0; /* leader len of current line */ | |
4900 int next_leader_len; /* leader len of next line */ | |
4901 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
4902 char_u *next_leader_flags; /* flags for leader of next line */ | |
4903 int do_comments; /* format comments */ | |
3584 | 4904 int do_comments_list = 0; /* format comments with 'n' or '2' */ |
7 | 4905 #endif |
4906 int advance = TRUE; | |
3584 | 4907 int second_indent = -1; /* indent for second line (comment |
4908 * aware) */ | |
7 | 4909 int do_second_indent; |
4910 int do_number_indent; | |
4911 int do_trail_white; | |
4912 int first_par_line = TRUE; | |
4913 int smd_save; | |
4914 long count; | |
4915 int need_set_indent = TRUE; /* set indent of next paragraph */ | |
4916 int force_format = FALSE; | |
4917 int old_State = State; | |
4918 | |
4919 /* length of a line to force formatting: 3 * 'tw' */ | |
4920 max_len = comp_textwidth(TRUE) * 3; | |
4921 | |
4922 /* check for 'q', '2' and '1' in 'formatoptions' */ | |
4923 #ifdef FEAT_COMMENTS | |
4924 do_comments = has_format_option(FO_Q_COMS); | |
4925 #endif | |
4926 do_second_indent = has_format_option(FO_Q_SECOND); | |
4927 do_number_indent = has_format_option(FO_Q_NUMBER); | |
4928 do_trail_white = has_format_option(FO_WHITE_PAR); | |
4929 | |
4930 /* | |
4931 * Get info about the previous and current line. | |
4932 */ | |
4933 if (curwin->w_cursor.lnum > 1) | |
4934 is_not_par = fmt_check_par(curwin->w_cursor.lnum - 1 | |
4935 #ifdef FEAT_COMMENTS | |
4936 , &leader_len, &leader_flags, do_comments | |
4937 #endif | |
4938 ); | |
4939 else | |
4940 is_not_par = TRUE; | |
4941 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum | |
4942 #ifdef FEAT_COMMENTS | |
4943 , &next_leader_len, &next_leader_flags, do_comments | |
4944 #endif | |
4945 ); | |
4946 is_end_par = (is_not_par || next_is_not_par); | |
4947 if (!is_end_par && do_trail_white) | |
4948 is_end_par = !ends_in_white(curwin->w_cursor.lnum - 1); | |
4949 | |
4950 curwin->w_cursor.lnum--; | |
4951 for (count = line_count; count != 0 && !got_int; --count) | |
4952 { | |
4953 /* | |
4954 * Advance to next paragraph. | |
4955 */ | |
4956 if (advance) | |
4957 { | |
4958 curwin->w_cursor.lnum++; | |
4959 prev_is_end_par = is_end_par; | |
4960 is_not_par = next_is_not_par; | |
4961 #ifdef FEAT_COMMENTS | |
4962 leader_len = next_leader_len; | |
4963 leader_flags = next_leader_flags; | |
4964 #endif | |
4965 } | |
4966 | |
4967 /* | |
4968 * The last line to be formatted. | |
4969 */ | |
4970 if (count == 1 || curwin->w_cursor.lnum == curbuf->b_ml.ml_line_count) | |
4971 { | |
4972 next_is_not_par = TRUE; | |
4973 #ifdef FEAT_COMMENTS | |
4974 next_leader_len = 0; | |
4975 next_leader_flags = NULL; | |
4976 #endif | |
4977 } | |
4978 else | |
4979 { | |
4980 next_is_not_par = fmt_check_par(curwin->w_cursor.lnum + 1 | |
4981 #ifdef FEAT_COMMENTS | |
4982 , &next_leader_len, &next_leader_flags, do_comments | |
4983 #endif | |
4984 ); | |
4985 if (do_number_indent) | |
4986 next_is_start_par = | |
4987 (get_number_indent(curwin->w_cursor.lnum + 1) > 0); | |
4988 } | |
4989 advance = TRUE; | |
4990 is_end_par = (is_not_par || next_is_not_par || next_is_start_par); | |
4991 if (!is_end_par && do_trail_white) | |
4992 is_end_par = !ends_in_white(curwin->w_cursor.lnum); | |
4993 | |
4994 /* | |
4995 * Skip lines that are not in a paragraph. | |
4996 */ | |
4997 if (is_not_par) | |
4998 { | |
4999 if (line_count < 0) | |
5000 break; | |
5001 } | |
5002 else | |
5003 { | |
5004 /* | |
5005 * For the first line of a paragraph, check indent of second line. | |
5006 * Don't do this for comments and empty lines. | |
5007 */ | |
5008 if (first_par_line | |
5009 && (do_second_indent || do_number_indent) | |
5010 && prev_is_end_par | |
3584 | 5011 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) |
5012 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
5013 if (do_second_indent && !LINEEMPTY(curwin->w_cursor.lnum + 1)) |
3584 | 5014 { |
5015 #ifdef FEAT_COMMENTS | |
5016 if (leader_len == 0 && next_leader_len == 0) | |
5017 { | |
5018 /* no comment found */ | |
5019 #endif | |
5020 second_indent = | |
5021 get_indent_lnum(curwin->w_cursor.lnum + 1); | |
7 | 5022 #ifdef FEAT_COMMENTS |
3584 | 5023 } |
5024 else | |
5025 { | |
5026 second_indent = next_leader_len; | |
5027 do_comments_list = 1; | |
5028 } | |
5029 #endif | |
5030 } | |
7 | 5031 else if (do_number_indent) |
3584 | 5032 { |
5033 #ifdef FEAT_COMMENTS | |
5034 if (leader_len == 0 && next_leader_len == 0) | |
5035 { | |
5036 /* no comment found */ | |
5037 #endif | |
5038 second_indent = | |
5039 get_number_indent(curwin->w_cursor.lnum); | |
5040 #ifdef FEAT_COMMENTS | |
5041 } | |
5042 else | |
5043 { | |
5044 /* get_number_indent() is now "comment aware"... */ | |
5045 second_indent = | |
5046 get_number_indent(curwin->w_cursor.lnum); | |
5047 do_comments_list = 1; | |
5048 } | |
5049 #endif | |
5050 } | |
7 | 5051 } |
5052 | |
5053 /* | |
5054 * When the comment leader changes, it's the end of the paragraph. | |
5055 */ | |
5056 if (curwin->w_cursor.lnum >= curbuf->b_ml.ml_line_count | |
5057 #ifdef FEAT_COMMENTS | |
5058 || !same_leader(curwin->w_cursor.lnum, | |
5059 leader_len, leader_flags, | |
5060 next_leader_len, next_leader_flags) | |
5061 #endif | |
5062 ) | |
5063 is_end_par = TRUE; | |
5064 | |
5065 /* | |
5066 * If we have got to the end of a paragraph, or the line is | |
5067 * getting long, format it. | |
5068 */ | |
5069 if (is_end_par || force_format) | |
5070 { | |
5071 if (need_set_indent) | |
5072 /* replace indent in first line with minimal number of | |
5073 * tabs and spaces, according to current options */ | |
5074 (void)set_indent(get_indent(), SIN_CHANGED); | |
5075 | |
5076 /* put cursor on last non-space */ | |
5077 State = NORMAL; /* don't go past end-of-line */ | |
5078 coladvance((colnr_T)MAXCOL); | |
5079 while (curwin->w_cursor.col && vim_isspace(gchar_cursor())) | |
5080 dec_cursor(); | |
5081 | |
5082 /* do the formatting, without 'showmode' */ | |
5083 State = INSERT; /* for open_line() */ | |
5084 smd_save = p_smd; | |
5085 p_smd = FALSE; | |
5086 insertchar(NUL, INSCHAR_FORMAT | |
5087 #ifdef FEAT_COMMENTS | |
5088 + (do_comments ? INSCHAR_DO_COM : 0) | |
3584 | 5089 + (do_comments && do_comments_list |
5090 ? INSCHAR_COM_LIST : 0) | |
7 | 5091 #endif |
1563 | 5092 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent); |
7 | 5093 State = old_State; |
5094 p_smd = smd_save; | |
5095 second_indent = -1; | |
5096 /* at end of par.: need to set indent of next par. */ | |
5097 need_set_indent = is_end_par; | |
5098 if (is_end_par) | |
5099 { | |
5100 /* When called with a negative line count, break at the | |
5101 * end of the paragraph. */ | |
5102 if (line_count < 0) | |
5103 break; | |
5104 first_par_line = TRUE; | |
5105 } | |
5106 force_format = FALSE; | |
5107 } | |
5108 | |
5109 /* | |
5110 * When still in same paragraph, join the lines together. But | |
5403 | 5111 * first delete the leader from the second line. |
7 | 5112 */ |
5113 if (!is_end_par) | |
5114 { | |
5115 advance = FALSE; | |
5116 curwin->w_cursor.lnum++; | |
5117 curwin->w_cursor.col = 0; | |
5118 if (line_count < 0 && u_save_cursor() == FAIL) | |
2294
2209060c340d
Make joining a range of lines much faster. (Milan Vancura)
Bram Moolenaar <bram@vim.org>
parents:
2289
diff
changeset
|
5119 break; |
7 | 5120 #ifdef FEAT_COMMENTS |
5121 if (next_leader_len > 0) | |
5403 | 5122 { |
5123 (void)del_bytes((long)next_leader_len, FALSE, FALSE); | |
7 | 5124 mark_col_adjust(curwin->w_cursor.lnum, (colnr_T)0, 0L, |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5125 (long)-next_leader_len, 0); |
5403 | 5126 } else |
5127 #endif | |
5128 if (second_indent > 0) /* the "leader" for FO_Q_SECOND */ | |
5129 { | |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
11997
diff
changeset
|
5130 int indent = getwhitecols_curline(); |
5403 | 5131 |
5132 if (indent > 0) | |
5133 { | |
5134 (void)del_bytes(indent, FALSE, FALSE); | |
5135 mark_col_adjust(curwin->w_cursor.lnum, | |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
15062
diff
changeset
|
5136 (colnr_T)0, 0L, (long)-indent, 0); |
5415 | 5137 } |
5403 | 5138 } |
7 | 5139 curwin->w_cursor.lnum--; |
5848 | 5140 if (do_join(2, TRUE, FALSE, FALSE, FALSE) == FAIL) |
7 | 5141 { |
5142 beep_flush(); | |
5143 break; | |
5144 } | |
5145 first_par_line = FALSE; | |
5146 /* If the line is getting long, format it next time */ | |
5147 if (STRLEN(ml_get_curline()) > (size_t)max_len) | |
5148 force_format = TRUE; | |
5149 else | |
5150 force_format = FALSE; | |
5151 } | |
5152 } | |
5153 line_breakcheck(); | |
5154 } | |
5155 } | |
5156 | |
5157 /* | |
5158 * Return TRUE if line "lnum" ends in a white character. | |
5159 */ | |
5160 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5161 ends_in_white(linenr_T lnum) |
7 | 5162 { |
5163 char_u *s = ml_get(lnum); | |
5164 size_t l; | |
5165 | |
5166 if (*s == NUL) | |
5167 return FALSE; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5168 /* Don't use STRLEN() inside VIM_ISWHITE(), SAS/C complains: "macro |
7 | 5169 * invocation may call function multiple times". */ |
5170 l = STRLEN(s) - 1; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5171 return VIM_ISWHITE(s[l]); |
7 | 5172 } |
5173 | |
5174 /* | |
5175 * Blank lines, and lines containing only the comment leader, are left | |
5176 * untouched by the formatting. The function returns TRUE in this | |
5177 * case. It also returns TRUE when a line starts with the end of a comment | |
5178 * ('e' in comment flags), so that this line is skipped, and not joined to the | |
5179 * previous line. A new paragraph starts after a blank line, or when the | |
5180 * comment leader changes -- webb. | |
5181 */ | |
5182 #ifdef FEAT_COMMENTS | |
5183 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5184 fmt_check_par( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5185 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5186 int *leader_len, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5187 char_u **leader_flags, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5188 int do_comments) |
7 | 5189 { |
5190 char_u *flags = NULL; /* init for GCC */ | |
5191 char_u *ptr; | |
5192 | |
5193 ptr = ml_get(lnum); | |
5194 if (do_comments) | |
3562 | 5195 *leader_len = get_leader_len(ptr, leader_flags, FALSE, TRUE); |
7 | 5196 else |
5197 *leader_len = 0; | |
5198 | |
5199 if (*leader_len > 0) | |
5200 { | |
5201 /* | |
5202 * Search for 'e' flag in comment leader flags. | |
5203 */ | |
5204 flags = *leader_flags; | |
5205 while (*flags && *flags != ':' && *flags != COM_END) | |
5206 ++flags; | |
5207 } | |
5208 | |
5209 return (*skipwhite(ptr + *leader_len) == NUL | |
5210 || (*leader_len > 0 && *flags == COM_END) | |
5211 || startPS(lnum, NUL, FALSE)); | |
5212 } | |
5213 #else | |
5214 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5215 fmt_check_par(linenr_T lnum) |
7 | 5216 { |
5217 return (*skipwhite(ml_get(lnum)) == NUL || startPS(lnum, NUL, FALSE)); | |
5218 } | |
5219 #endif | |
5220 | |
5221 /* | |
5222 * Return TRUE when a paragraph starts in line "lnum". Return FALSE when the | |
5223 * previous line is in the same paragraph. Used for auto-formatting. | |
5224 */ | |
5225 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5226 paragraph_start(linenr_T lnum) |
7 | 5227 { |
5228 char_u *p; | |
5229 #ifdef FEAT_COMMENTS | |
5230 int leader_len = 0; /* leader len of current line */ | |
5231 char_u *leader_flags = NULL; /* flags for leader of current line */ | |
5232 int next_leader_len; /* leader len of next line */ | |
5233 char_u *next_leader_flags; /* flags for leader of next line */ | |
5234 int do_comments; /* format comments */ | |
5235 #endif | |
5236 | |
5237 if (lnum <= 1) | |
5238 return TRUE; /* start of the file */ | |
5239 | |
5240 p = ml_get(lnum - 1); | |
5241 if (*p == NUL) | |
5242 return TRUE; /* after empty line */ | |
5243 | |
5244 #ifdef FEAT_COMMENTS | |
5245 do_comments = has_format_option(FO_Q_COMS); | |
5246 #endif | |
5247 if (fmt_check_par(lnum - 1 | |
5248 #ifdef FEAT_COMMENTS | |
5249 , &leader_len, &leader_flags, do_comments | |
5250 #endif | |
5251 )) | |
5252 return TRUE; /* after non-paragraph line */ | |
5253 | |
5254 if (fmt_check_par(lnum | |
5255 #ifdef FEAT_COMMENTS | |
5256 , &next_leader_len, &next_leader_flags, do_comments | |
5257 #endif | |
5258 )) | |
5259 return TRUE; /* "lnum" is not a paragraph line */ | |
5260 | |
5261 if (has_format_option(FO_WHITE_PAR) && !ends_in_white(lnum - 1)) | |
5262 return TRUE; /* missing trailing space in previous line. */ | |
5263 | |
5264 if (has_format_option(FO_Q_NUMBER) && (get_number_indent(lnum) > 0)) | |
5265 return TRUE; /* numbered item starts in "lnum". */ | |
5266 | |
5267 #ifdef FEAT_COMMENTS | |
5268 if (!same_leader(lnum - 1, leader_len, leader_flags, | |
5269 next_leader_len, next_leader_flags)) | |
5270 return TRUE; /* change of comment leader. */ | |
5271 #endif | |
5272 | |
5273 return FALSE; | |
5274 } | |
5275 | |
5276 /* | |
5277 * prepare a few things for block mode yank/delete/tilde | |
5278 * | |
5279 * for delete: | |
5280 * - textlen includes the first/last char to be (partly) deleted | |
5281 * - start/endspaces is the number of columns that are taken by the | |
5282 * first/last deleted char minus the number of columns that have to be | |
1839 | 5283 * deleted. |
5284 * for yank and tilde: | |
7 | 5285 * - textlen includes the first/last char to be wholly yanked |
5286 * - start/endspaces is the number of columns of the first/last yanked char | |
5287 * that are to be yanked. | |
5288 */ | |
5289 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5290 block_prep( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5291 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5292 struct block_def *bdp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5293 linenr_T lnum, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5294 int is_del) |
7 | 5295 { |
5296 int incr = 0; | |
5297 char_u *pend; | |
5298 char_u *pstart; | |
5299 char_u *line; | |
5300 char_u *prev_pstart; | |
5301 char_u *prev_pend; | |
5302 | |
5303 bdp->startspaces = 0; | |
5304 bdp->endspaces = 0; | |
5305 bdp->textlen = 0; | |
5306 bdp->start_vcol = 0; | |
5307 bdp->end_vcol = 0; | |
5308 bdp->is_short = FALSE; | |
5309 bdp->is_oneChar = FALSE; | |
5310 bdp->pre_whitesp = 0; | |
5311 bdp->pre_whitesp_c = 0; | |
5312 bdp->end_char_vcols = 0; | |
5313 bdp->start_char_vcols = 0; | |
5314 | |
5315 line = ml_get(lnum); | |
5316 pstart = line; | |
5317 prev_pstart = line; | |
5318 while (bdp->start_vcol < oap->start_vcol && *pstart) | |
5319 { | |
5320 /* Count a tab for what it's worth (if list mode not on) */ | |
5995 | 5321 incr = lbr_chartabsize(line, pstart, (colnr_T)bdp->start_vcol); |
7 | 5322 bdp->start_vcol += incr; |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
5323 if (VIM_ISWHITE(*pstart)) |
7 | 5324 { |
5325 bdp->pre_whitesp += incr; | |
5326 bdp->pre_whitesp_c++; | |
5327 } | |
5328 else | |
5329 { | |
5330 bdp->pre_whitesp = 0; | |
5331 bdp->pre_whitesp_c = 0; | |
5332 } | |
5333 prev_pstart = pstart; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
5334 MB_PTR_ADV(pstart); |
7 | 5335 } |
5336 bdp->start_char_vcols = incr; | |
5337 if (bdp->start_vcol < oap->start_vcol) /* line too short */ | |
5338 { | |
5339 bdp->end_vcol = bdp->start_vcol; | |
5340 bdp->is_short = TRUE; | |
5341 if (!is_del || oap->op_type == OP_APPEND) | |
5342 bdp->endspaces = oap->end_vcol - oap->start_vcol + 1; | |
5343 } | |
5344 else | |
5345 { | |
5346 /* notice: this converts partly selected Multibyte characters to | |
5347 * spaces, too. */ | |
5348 bdp->startspaces = bdp->start_vcol - oap->start_vcol; | |
5349 if (is_del && bdp->startspaces) | |
5350 bdp->startspaces = bdp->start_char_vcols - bdp->startspaces; | |
5351 pend = pstart; | |
5352 bdp->end_vcol = bdp->start_vcol; | |
5353 if (bdp->end_vcol > oap->end_vcol) /* it's all in one character */ | |
5354 { | |
5355 bdp->is_oneChar = TRUE; | |
5356 if (oap->op_type == OP_INSERT) | |
5357 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5358 else if (oap->op_type == OP_APPEND) | |
5359 { | |
5360 bdp->startspaces += oap->end_vcol - oap->start_vcol + 1; | |
5361 bdp->endspaces = bdp->start_char_vcols - bdp->startspaces; | |
5362 } | |
5363 else | |
5364 { | |
5365 bdp->startspaces = oap->end_vcol - oap->start_vcol + 1; | |
5366 if (is_del && oap->op_type != OP_LSHIFT) | |
5367 { | |
5368 /* just putting the sum of those two into | |
5369 * bdp->startspaces doesn't work for Visual replace, | |
5370 * so we have to split the tab in two */ | |
5371 bdp->startspaces = bdp->start_char_vcols | |
5372 - (bdp->start_vcol - oap->start_vcol); | |
5373 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5374 } | |
5375 } | |
5376 } | |
5377 else | |
5378 { | |
5379 prev_pend = pend; | |
5380 while (bdp->end_vcol <= oap->end_vcol && *pend != NUL) | |
5381 { | |
5382 /* Count a tab for what it's worth (if list mode not on) */ | |
5383 prev_pend = pend; | |
6535 | 5384 incr = lbr_chartabsize_adv(line, &pend, (colnr_T)bdp->end_vcol); |
7 | 5385 bdp->end_vcol += incr; |
5386 } | |
5387 if (bdp->end_vcol <= oap->end_vcol | |
5388 && (!is_del | |
5389 || oap->op_type == OP_APPEND | |
5390 || oap->op_type == OP_REPLACE)) /* line too short */ | |
5391 { | |
5392 bdp->is_short = TRUE; | |
5393 /* Alternative: include spaces to fill up the block. | |
5394 * Disadvantage: can lead to trailing spaces when the line is | |
5395 * short where the text is put */ | |
5396 /* if (!is_del || oap->op_type == OP_APPEND) */ | |
5397 if (oap->op_type == OP_APPEND || virtual_op) | |
5398 bdp->endspaces = oap->end_vcol - bdp->end_vcol | |
593 | 5399 + oap->inclusive; |
7 | 5400 else |
5401 bdp->endspaces = 0; /* replace doesn't add characters */ | |
5402 } | |
5403 else if (bdp->end_vcol > oap->end_vcol) | |
5404 { | |
5405 bdp->endspaces = bdp->end_vcol - oap->end_vcol - 1; | |
5406 if (!is_del && bdp->endspaces) | |
5407 { | |
5408 bdp->endspaces = incr - bdp->endspaces; | |
5409 if (pend != pstart) | |
5410 pend = prev_pend; | |
5411 } | |
5412 } | |
5413 } | |
5414 bdp->end_char_vcols = incr; | |
5415 if (is_del && bdp->startspaces) | |
5416 pstart = prev_pstart; | |
5417 bdp->textlen = (int)(pend - pstart); | |
5418 } | |
5419 bdp->textcol = (colnr_T) (pstart - line); | |
5420 bdp->textstart = pstart; | |
5421 } | |
5422 | |
5423 /* | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5424 * Handle the add/subtract operator. |
7 | 5425 */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5426 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5427 op_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5428 oparg_T *oap, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5429 linenr_T Prenum1, /* Amount of add/subtract */ |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5430 int g_cmd) /* was g<c-a>/g<c-x> */ |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5431 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5432 pos_T pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5433 struct block_def bd; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5434 int change_cnt = 0; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5435 linenr_T amount = Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5436 |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5437 // do_addsub() might trigger re-evaluation of 'foldexpr' halfway, when the |
15967
ddd82b1c9e9d
patch 8.1.0989: various small code ugliness
Bram Moolenaar <Bram@vim.org>
parents:
15840
diff
changeset
|
5438 // buffer is not completely updated yet. Postpone updating folds until before |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5439 // the call to changed_lines(). |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5440 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5441 disable_fold_update++; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5442 #endif |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5443 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5444 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5445 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5446 pos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5447 if (u_save_cursor() == FAIL) |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5448 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5449 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5450 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5451 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5452 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5453 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5454 change_cnt = do_addsub(oap->op_type, &pos, 0, amount); |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5455 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5456 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5457 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5458 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5459 changed_lines(pos.lnum, 0, pos.lnum + 1, 0L); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5460 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5461 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5462 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5463 int one_change; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5464 int length; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5465 pos_T startpos; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5466 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5467 if (u_save((linenr_T)(oap->start.lnum - 1), |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5468 (linenr_T)(oap->end.lnum + 1)) == FAIL) |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5469 { |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5470 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5471 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5472 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5473 return; |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5474 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5475 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5476 pos = oap->start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5477 for (; pos.lnum <= oap->end.lnum; ++pos.lnum) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5478 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5479 if (oap->block_mode) /* Visual block mode */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5480 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5481 block_prep(oap, &bd, pos.lnum, FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5482 pos.col = bd.textcol; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5483 length = bd.textlen; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5484 } |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5485 else if (oap->motion_type == MLINE) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5486 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5487 curwin->w_cursor.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5488 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5489 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5490 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5491 else /* oap->motion_type == MCHAR */ |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5492 { |
12996
973a0037f4c3
patch 8.0.1374: CTRL-A does not work with an empty line
Christian Brabandt <cb@256bit.org>
parents:
12642
diff
changeset
|
5493 if (pos.lnum == oap->start.lnum && !oap->inclusive) |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5494 dec(&(oap->end)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5495 length = (colnr_T)STRLEN(ml_get(pos.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5496 pos.col = 0; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5497 if (pos.lnum == oap->start.lnum) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5498 { |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5499 pos.col += oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5500 length -= oap->start.col; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5501 } |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5502 if (pos.lnum == oap->end.lnum) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5503 { |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5504 length = (int)STRLEN(ml_get(oap->end.lnum)); |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5505 if (oap->end.col >= length) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5506 oap->end.col = length - 1; |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5507 length = oap->end.col - pos.col + 1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5508 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5509 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5510 one_change = do_addsub(oap->op_type, &pos, length, amount); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5511 if (one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5512 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5513 /* Remember the start position of the first change. */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5514 if (change_cnt == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5515 startpos = curbuf->b_op_start; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5516 ++change_cnt; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5517 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5518 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5519 #ifdef FEAT_NETBEANS_INTG |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5520 if (netbeans_active() && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5521 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5522 char_u *ptr = ml_get_buf(curbuf, pos.lnum, FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5523 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5524 netbeans_removed(curbuf, pos.lnum, pos.col, (long)length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5525 netbeans_inserted(curbuf, pos.lnum, pos.col, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5526 &ptr[pos.col], length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5527 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5528 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5529 if (g_cmd && one_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5530 amount += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5531 } |
15048
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5532 |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5533 #ifdef FEAT_FOLDING |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5534 disable_fold_update--; |
73f59cd01ba7
patch 8.1.0535: increment/decrement might get interrupted by updating folds
Bram Moolenaar <Bram@vim.org>
parents:
14862
diff
changeset
|
5535 #endif |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5536 if (change_cnt) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5537 changed_lines(oap->start.lnum, 0, oap->end.lnum + 1, 0L); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5538 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5539 if (!change_cnt && oap->is_VIsual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5540 /* No change: need to remove the Visual selection */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5541 redraw_curbuf_later(INVERTED); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5542 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5543 /* Set '[ mark if something changed. Keep the last end |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5544 * position from do_addsub(). */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5545 if (change_cnt > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5546 curbuf->b_op_start = startpos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5547 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5548 if (change_cnt > p_report) |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
5549 smsg(NGETTEXT("%ld line changed", "%ld lines changed", |
14585
c8f07e8b273e
patch 8.1.0306: plural messages are not translated properly
Christian Brabandt <cb@256bit.org>
parents:
14424
diff
changeset
|
5550 change_cnt), change_cnt); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5551 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5552 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5553 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5554 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5555 * Add or subtract 'Prenum1' from a number in a line |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5556 * op_type is OP_NR_ADD or OP_NR_SUB |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5557 * |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5558 * Returns TRUE if some character was changed. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5559 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5560 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5561 do_addsub( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5562 int op_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5563 pos_T *pos, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5564 int length, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5565 linenr_T Prenum1) |
7 | 5566 { |
5567 int col; | |
5568 char_u *buf1; | |
5569 char_u buf2[NUMBUFLEN]; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5570 int pre; /* 'X'/'x': hex; '0': octal; 'B'/'b': bin */ |
7 | 5571 static int hexupper = FALSE; /* 0xABC */ |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5572 uvarnumber_T n; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5573 uvarnumber_T oldn; |
7 | 5574 char_u *ptr; |
5575 int c; | |
5576 int todel; | |
5577 int dohex; | |
5578 int dooct; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5579 int dobin; |
7 | 5580 int doalp; |
5581 int firstdigit; | |
5582 int subtract; | |
6868 | 5583 int negative = FALSE; |
6891 | 5584 int was_positive = TRUE; |
6868 | 5585 int visual = VIsual_active; |
6921 | 5586 int did_change = FALSE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5587 pos_T save_cursor = curwin->w_cursor; |
6927 | 5588 int maxlen = 0; |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5589 pos_T startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5590 pos_T endpos; |
7 | 5591 |
18100
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
5592 dohex = (vim_strchr(curbuf->b_p_nf, 'x') != NULL); // "heX" |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
5593 dooct = (vim_strchr(curbuf->b_p_nf, 'o') != NULL); // "Octal" |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
5594 dobin = (vim_strchr(curbuf->b_p_nf, 'b') != NULL); // "Bin" |
df5778d73320
patch 8.1.2045: the option.c file is too big
Bram Moolenaar <Bram@vim.org>
parents:
18062
diff
changeset
|
5595 doalp = (vim_strchr(curbuf->b_p_nf, 'p') != NULL); // "alPha" |
7 | 5596 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5597 curwin->w_cursor = *pos; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5598 ptr = ml_get(pos->lnum); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5599 col = pos->col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5600 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5601 if (*ptr == NUL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5602 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5603 |
7 | 5604 /* |
5605 * First check if we are on a hexadecimal number, after the "0x". | |
5606 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5607 if (!VIsual_active) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5608 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5609 if (dobin) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5610 while (col > 0 && vim_isbdigit(ptr[col])) |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5611 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5612 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5613 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5614 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5615 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5616 |
6868 | 5617 if (dohex) |
5618 while (col > 0 && vim_isxdigit(ptr[col])) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5619 { |
6868 | 5620 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5621 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5622 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5623 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5624 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5625 if ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5626 && dohex |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5627 && ! ((col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5628 && (ptr[col] == 'X' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5629 || ptr[col] == 'x') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5630 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5631 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5632 !(*mb_head_off)(ptr, ptr + col - 1)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5633 && vim_isxdigit(ptr[col + 1])))) |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5634 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5635 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5636 /* In case of binary/hexadecimal pattern overlap match, rescan */ |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5637 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5638 col = pos->col; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5639 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5640 while (col > 0 && vim_isdigit(ptr[col])) |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5641 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5642 col--; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5643 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5644 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5645 } |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5646 } |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5647 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5648 if (( dohex |
6868 | 5649 && col > 0 |
5650 && (ptr[col] == 'X' | |
5651 || ptr[col] == 'x') | |
5652 && ptr[col - 1] == '0' | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5653 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5654 !(*mb_head_off)(ptr, ptr + col - 1)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5655 && vim_isxdigit(ptr[col + 1])) || |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5656 ( dobin |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5657 && col > 0 |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5658 && (ptr[col] == 'B' |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5659 || ptr[col] == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5660 && ptr[col - 1] == '0' |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5661 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5662 !(*mb_head_off)(ptr, ptr + col - 1)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5663 && vim_isbdigit(ptr[col + 1]))) |
6868 | 5664 { |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
5665 /* Found hexadecimal or binary number, move to its start. */ |
7 | 5666 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5667 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5668 col -= (*mb_head_off)(ptr, ptr + col); |
6868 | 5669 } |
5670 else | |
7 | 5671 { |
6868 | 5672 /* |
5673 * Search forward and then backward to find the start of number. | |
5674 */ | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5675 col = pos->col; |
6868 | 5676 |
5677 while (ptr[col] != NUL | |
5678 && !vim_isdigit(ptr[col]) | |
5679 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5680 col += MB_PTR2LEN(ptr + col); |
6868 | 5681 |
5682 while (col > 0 | |
5683 && vim_isdigit(ptr[col - 1]) | |
5684 && !(doalp && ASCII_ISALPHA(ptr[col]))) | |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5685 { |
6868 | 5686 --col; |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5687 if (has_mbyte) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5688 col -= (*mb_head_off)(ptr, ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5689 } |
6868 | 5690 } |
5691 } | |
5692 | |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5693 if (visual) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5694 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5695 while (ptr[col] != NUL && length > 0 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5696 && !vim_isdigit(ptr[col]) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5697 && !(doalp && ASCII_ISALPHA(ptr[col]))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5698 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5699 int mb_len = MB_PTR2LEN(ptr + col); |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5700 |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5701 col += mb_len; |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5702 length -= mb_len; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5703 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5704 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5705 if (length == 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5706 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5707 |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5708 if (col > pos->col && ptr[col - 1] == '-' |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
5709 && (!has_mbyte || !(*mb_head_off)(ptr, ptr + col - 1))) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5710 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5711 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5712 was_positive = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5713 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5714 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5715 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5716 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5717 * If a number was found, and saving for undo works, replace the number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5718 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5719 firstdigit = ptr[col]; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5720 if (!VIM_ISDIGIT(firstdigit) && !(doalp && ASCII_ISALPHA(firstdigit))) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5721 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5722 beep_flush(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5723 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5724 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5725 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5726 if (doalp && ASCII_ISALPHA(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5727 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5728 /* decrement or increment alphabetic character */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5729 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5730 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5731 if (CharOrd(firstdigit) < Prenum1) |
6927 | 5732 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5733 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5734 firstdigit = 'A'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5735 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5736 firstdigit = 'a'; |
6927 | 5737 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5738 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5739 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5740 firstdigit = EBCDIC_CHAR_ADD(firstdigit, -Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5741 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5742 firstdigit -= Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5743 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5744 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5745 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5746 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5747 if (26 - CharOrd(firstdigit) - 1 < Prenum1) |
6927 | 5748 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5749 if (isupper(firstdigit)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5750 firstdigit = 'Z'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5751 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5752 firstdigit = 'z'; |
6927 | 5753 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5754 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5755 #ifdef EBCDIC |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5756 firstdigit = EBCDIC_CHAR_ADD(firstdigit, Prenum1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5757 #else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5758 firstdigit += Prenum1; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5759 #endif |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5760 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5761 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5762 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5763 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5764 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5765 (void)del_char(FALSE); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5766 ins_char(firstdigit); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5767 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5768 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5769 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5770 else |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5771 { |
9332
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5772 if (col > 0 && ptr[col - 1] == '-' |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5773 && (!has_mbyte || |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5774 !(*mb_head_off)(ptr, ptr + col - 1)) |
a9b8f5613601
commit https://github.com/vim/vim/commit/ad5ca9bc1e7145474adb082775a805f1731e9e37
Christian Brabandt <cb@256bit.org>
parents:
9307
diff
changeset
|
5775 && !visual) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5776 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5777 /* negative number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5778 --col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5779 negative = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5780 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5781 /* get the number value (unsigned) */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5782 if (visual && VIsual_mode != 'V') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5783 maxlen = (curbuf->b_visual.vi_curswant == MAXCOL |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5784 ? (int)STRLEN(ptr) - col |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5785 : length); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5786 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5787 vim_str2nr(ptr + col, &pre, &length, |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5788 0 + (dobin ? STR2NR_BIN : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5789 + (dooct ? STR2NR_OCT : 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5790 + (dohex ? STR2NR_HEX : 0), |
16706
77bcb5055fec
patch 8.1.1355: obvious mistakes are accepted as valid expressions
Bram Moolenaar <Bram@vim.org>
parents:
16698
diff
changeset
|
5791 NULL, &n, maxlen, FALSE); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5792 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5793 /* ignore leading '-' for hex and octal and bin numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5794 if (pre && negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5795 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5796 ++col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5797 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5798 negative = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5799 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5800 /* add or subtract */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5801 subtract = FALSE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5802 if (op_type == OP_NR_SUB) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5803 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5804 if (negative) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5805 subtract ^= TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5806 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5807 oldn = n; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5808 if (subtract) |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5809 n -= (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5810 else |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5811 n += (uvarnumber_T)Prenum1; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5812 /* handle wraparound for decimal numbers */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5813 if (!pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5814 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5815 if (subtract) |
6927 | 5816 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5817 if (n > oldn) |
6868 | 5818 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5819 n = 1 + (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5820 negative ^= TRUE; |
6868 | 5821 } |
7 | 5822 } |
5823 else | |
6868 | 5824 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5825 /* add */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5826 if (n < oldn) |
6868 | 5827 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5828 n = (n ^ (uvarnumber_T)-1); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5829 negative ^= TRUE; |
6868 | 5830 } |
6927 | 5831 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5832 if (n == 0) |
6868 | 5833 negative = FALSE; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5834 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5835 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5836 if (visual && !was_positive && !negative && col > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5837 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5838 /* need to remove the '-' */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5839 col--; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5840 length++; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5841 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5842 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5843 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5844 * Delete the old number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5845 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5846 curwin->w_cursor.col = col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5847 if (!did_change) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5848 startpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5849 did_change = TRUE; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5850 todel = length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5851 c = gchar_cursor(); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5852 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5853 * Don't include the '-' in the length, only the length of the |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5854 * part after it is kept the same. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5855 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5856 if (c == '-') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5857 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5858 while (todel-- > 0) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5859 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5860 if (c < 0x100 && isalpha(c)) |
6868 | 5861 { |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5862 if (isupper(c)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5863 hexupper = TRUE; |
6868 | 5864 else |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5865 hexupper = FALSE; |
6891 | 5866 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5867 /* del_char() will mark line needing displaying */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5868 (void)del_char(FALSE); |
6868 | 5869 c = gchar_cursor(); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5870 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5871 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5872 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5873 * Prepare the leading characters in buf1[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5874 * When there are many leading zeros it could be very long. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5875 * Allocate a bit too much. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5876 */ |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
5877 buf1 = alloc(length + NUMBUFLEN); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5878 if (buf1 == NULL) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5879 goto theend; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5880 ptr = buf1; |
8989
e600e696c0a1
commit https://github.com/vim/vim/commit/dc633cf82758f67f656cda7fa8ccc30414ee53f8
Christian Brabandt <cb@256bit.org>
parents:
8863
diff
changeset
|
5881 if (negative && (!visual || was_positive)) |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5882 *ptr++ = '-'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5883 if (pre) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5884 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5885 *ptr++ = '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5886 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5887 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5888 if (pre == 'b' || pre == 'B' || |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5889 pre == 'x' || pre == 'X') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5890 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5891 *ptr++ = pre; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5892 --length; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5893 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5894 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5895 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5896 * Put the number characters in buf2[]. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5897 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5898 if (pre == 'b' || pre == 'B') |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5899 { |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5900 int i; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5901 int bit = 0; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
5902 int bits = sizeof(uvarnumber_T) * 8; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5903 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5904 /* leading zeros */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5905 for (bit = bits; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5906 if ((n >> (bit - 1)) & 0x1) break; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5907 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5908 for (i = 0; bit > 0; bit--) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5909 buf2[i++] = ((n >> (bit - 1)) & 0x1) ? '1' : '0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5910 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5911 buf2[i] = '\0'; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5912 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5913 else if (pre == 0) |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
5914 vim_snprintf((char *)buf2, NUMBUFLEN, "%llu", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5915 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5916 else if (pre == '0') |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
5917 vim_snprintf((char *)buf2, NUMBUFLEN, "%llo", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5918 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5919 else if (pre && hexupper) |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
5920 vim_snprintf((char *)buf2, NUMBUFLEN, "%llX", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5921 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5922 else |
13610
e76499e85744
patch 8.0.1677: no compiler warning for wrong format in vim_snprintf()
Christian Brabandt <cb@256bit.org>
parents:
13425
diff
changeset
|
5923 vim_snprintf((char *)buf2, NUMBUFLEN, "%llx", |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
5924 (long_long_u_T)n); |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5925 length -= (int)STRLEN(buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5926 |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5927 /* |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5928 * Adjust number of zeros to the new number of digits, so the |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5929 * total length of the number remains the same. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5930 * Don't do this when |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5931 * the result may look like an octal number. |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5932 */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5933 if (firstdigit == '0' && !(dooct && pre == 0)) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5934 while (length-- > 0) |
6868 | 5935 *ptr++ = '0'; |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5936 *ptr = NUL; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5937 STRCAT(buf1, buf2); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5938 ins_str(buf1); /* insert the new number */ |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5939 vim_free(buf1); |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5940 endpos = curwin->w_cursor; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5941 if (did_change && curwin->w_cursor.col) |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5942 --curwin->w_cursor.col; |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5943 } |
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5944 |
7570
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5945 if (did_change) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5946 { |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5947 /* set the '[ and '] marks */ |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5948 curbuf->b_op_start = startpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5949 curbuf->b_op_end = endpos; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5950 if (curbuf->b_op_end.col > 0) |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5951 --curbuf->b_op_end.col; |
4250ecde6009
commit https://github.com/vim/vim/commit/a52dfaed104183c1fa2a3b6e4430b23d86bcbece
Christian Brabandt <cb@256bit.org>
parents:
7551
diff
changeset
|
5952 } |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5953 |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5954 theend: |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5955 if (visual) |
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5956 curwin->w_cursor = save_cursor; |
8690
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5957 else if (did_change) |
6a1becf4f282
commit https://github.com/vim/vim/commit/8e08125d3a9afd0b16cd84454ae9ddad0abaaab0
Christian Brabandt <cb@256bit.org>
parents:
8399
diff
changeset
|
5958 curwin->w_set_curswant = TRUE; |
7576
e008ca0e2af2
commit https://github.com/vim/vim/commit/7ae4fbca552c972eb3645ece02a2807e517610d7
Christian Brabandt <cb@256bit.org>
parents:
7574
diff
changeset
|
5959 |
7574
b872724c37db
commit https://github.com/vim/vim/commit/d79e55016cf8268cee935f1ac3b5b28712d1399e
Christian Brabandt <cb@256bit.org>
parents:
7570
diff
changeset
|
5960 return did_change; |
7 | 5961 } |
5962 | |
5963 #if defined(FEAT_CLIPBOARD) || defined(PROTO) | |
5964 /* | |
5965 * SELECTION / PRIMARY ('*') | |
5966 * | |
5967 * Text selection stuff that uses the GUI selection register '*'. When using a | |
5968 * GUI this may be text from another window, otherwise it is the last text we | |
5969 * had highlighted with VIsual mode. With mouse support, clicking the middle | |
5970 * button performs the paste, otherwise you will need to do <"*p>. " | |
5971 * If not under X, it is synonymous with the clipboard register '+'. | |
5972 * | |
5973 * X CLIPBOARD ('+') | |
5974 * | |
5975 * Text selection stuff that uses the GUI clipboard register '+'. | |
5976 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection. | |
5977 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed", | |
5978 * otherwise you will need to do <"+p>. " | |
5979 * If not under X, it is synonymous with the selection register '*'. | |
5980 */ | |
5981 | |
5982 /* | |
5983 * Routine to export any final X selection we had to the environment | |
11065
f5bd684e47a1
patch 8.0.0421: diff mode wrong when adding line at end of buffer
Christian Brabandt <cb@256bit.org>
parents:
10827
diff
changeset
|
5984 * so that the text is still available after Vim has exited. X selections |
7 | 5985 * only exist while the owning application exists, so we write to the |
5986 * permanent (while X runs) store CUT_BUFFER0. | |
5987 * Dump the CLIPBOARD selection if we own it (it's logically the more | |
5988 * 'permanent' of the two), otherwise the PRIMARY one. | |
5989 * For now, use a hard-coded sanity limit of 1Mb of data. | |
5990 */ | |
9834
80ace3687eec
commit https://github.com/vim/vim/commit/a6b7a08ae04a3cd4d9c45c906bb7a197e2135179
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
5991 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO) |
7 | 5992 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
5993 x11_export_final_selection(void) |
7 | 5994 { |
5995 Display *dpy; | |
5996 char_u *str = NULL; | |
5997 long_u len = 0; | |
5998 int motion_type = -1; | |
5999 | |
6000 # ifdef FEAT_GUI | |
6001 if (gui.in_use) | |
6002 dpy = X_DISPLAY; | |
6003 else | |
6004 # endif | |
6005 # ifdef FEAT_XCLIPBOARD | |
6006 dpy = xterm_dpy; | |
6007 # else | |
6008 return; | |
6009 # endif | |
6010 | |
6011 /* Get selection to export */ | |
6012 if (clip_plus.owned) | |
6013 motion_type = clip_convert_selection(&str, &len, &clip_plus); | |
6014 else if (clip_star.owned) | |
6015 motion_type = clip_convert_selection(&str, &len, &clip_star); | |
6016 | |
6017 /* Check it's OK */ | |
6018 if (dpy != NULL && str != NULL && motion_type >= 0 | |
6019 && len < 1024*1024 && len > 0) | |
6020 { | |
4201 | 6021 int ok = TRUE; |
6022 | |
1924 | 6023 /* The CUT_BUFFER0 is supposed to always contain latin1. Convert from |
6024 * 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit | |
6025 * encoding conversion usually doesn't work, so keep the text as-is. | |
6026 */ | |
6027 if (has_mbyte) | |
6028 { | |
6029 vimconv_T vc; | |
6030 | |
6031 vc.vc_type = CONV_NONE; | |
6032 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK) | |
6033 { | |
2047
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6034 int intlen = len; |
85da03763130
updated for version 7.2.333
Bram Moolenaar <bram@zimbu.org>
parents:
2007
diff
changeset
|
6035 char_u *conv_str; |
2007 | 6036 |
4201 | 6037 vc.vc_fail = TRUE; |
2007 | 6038 conv_str = string_convert(&vc, str, &intlen); |
6039 len = intlen; | |
1924 | 6040 if (conv_str != NULL) |
6041 { | |
6042 vim_free(str); | |
6043 str = conv_str; | |
6044 } | |
4201 | 6045 else |
6046 { | |
6047 ok = FALSE; | |
6048 } | |
1924 | 6049 convert_setup(&vc, NULL, NULL); |
6050 } | |
4201 | 6051 else |
6052 { | |
6053 ok = FALSE; | |
6054 } | |
1924 | 6055 } |
4201 | 6056 |
6057 /* Do not store the string if conversion failed. Better to use any | |
6058 * other selection than garbled text. */ | |
6059 if (ok) | |
6060 { | |
6061 XStoreBuffer(dpy, (char *)str, (int)len, 0); | |
6062 XFlush(dpy); | |
6063 } | |
7 | 6064 } |
6065 | |
6066 vim_free(str); | |
6067 } | |
6068 #endif | |
6069 | |
6070 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
6071 clip_free_selection(Clipboard_T *cbd) |
7 | 6072 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6073 yankreg_T *y_ptr = y_current; |
7 | 6074 |
6075 if (cbd == &clip_plus) | |
6076 y_current = &y_regs[PLUS_REGISTER]; | |
6077 else | |
6078 y_current = &y_regs[STAR_REGISTER]; | |
6079 free_yank_all(); | |
6080 y_current->y_size = 0; | |
6081 y_current = y_ptr; | |
6082 } | |
6083 | |
6084 /* | |
15422
b55b89692fd2
patch 8.1.0719: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15326
diff
changeset
|
6085 * Get the selected text and put it in register '*' or '+'. |
7 | 6086 */ |
6087 void | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
6088 clip_get_selection(Clipboard_T *cbd) |
7 | 6089 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6090 yankreg_T *old_y_previous, *old_y_current; |
7 | 6091 pos_T old_cursor; |
6092 pos_T old_visual; | |
6093 int old_visual_mode; | |
6094 colnr_T old_curswant; | |
6095 int old_set_curswant; | |
6096 pos_T old_op_start, old_op_end; | |
6097 oparg_T oa; | |
6098 cmdarg_T ca; | |
6099 | |
6100 if (cbd->owned) | |
6101 { | |
6102 if ((cbd == &clip_plus && y_regs[PLUS_REGISTER].y_array != NULL) | |
6103 || (cbd == &clip_star && y_regs[STAR_REGISTER].y_array != NULL)) | |
6104 return; | |
6105 | |
6106 /* Get the text between clip_star.start & clip_star.end */ | |
6107 old_y_previous = y_previous; | |
6108 old_y_current = y_current; | |
6109 old_cursor = curwin->w_cursor; | |
6110 old_curswant = curwin->w_curswant; | |
6111 old_set_curswant = curwin->w_set_curswant; | |
6112 old_op_start = curbuf->b_op_start; | |
6113 old_op_end = curbuf->b_op_end; | |
6114 old_visual = VIsual; | |
6115 old_visual_mode = VIsual_mode; | |
6116 clear_oparg(&oa); | |
6117 oa.regname = (cbd == &clip_plus ? '+' : '*'); | |
6118 oa.op_type = OP_YANK; | |
6119 vim_memset(&ca, 0, sizeof(ca)); | |
6120 ca.oap = &oa; | |
6121 ca.cmdchar = 'y'; | |
6122 ca.count1 = 1; | |
6123 ca.retval = CA_NO_ADJ_OP_END; | |
6124 do_pending_operator(&ca, 0, TRUE); | |
6125 y_previous = old_y_previous; | |
6126 y_current = old_y_current; | |
6127 curwin->w_cursor = old_cursor; | |
688 | 6128 changed_cline_bef_curs(); /* need to update w_virtcol et al */ |
7 | 6129 curwin->w_curswant = old_curswant; |
6130 curwin->w_set_curswant = old_set_curswant; | |
6131 curbuf->b_op_start = old_op_start; | |
6132 curbuf->b_op_end = old_op_end; | |
6133 VIsual = old_visual; | |
6134 VIsual_mode = old_visual_mode; | |
6135 } | |
11273
96d83cd2904a
patch 8.0.0522: Win32: when 'clipboard' is "unnamed" yyp does not work
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
6136 else if (!is_clipboard_needs_update()) |
7 | 6137 { |
6138 clip_free_selection(cbd); | |
6139 | |
6140 /* Try to get selected text from another window */ | |
6141 clip_gen_request_selection(cbd); | |
6142 } | |
6143 } | |
6144 | |
2896 | 6145 /* |
6146 * Convert from the GUI selection string into the '*'/'+' register. | |
6147 */ | |
7 | 6148 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6149 clip_yank_selection( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6150 int type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6151 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6152 long len, |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
6153 Clipboard_T *cbd) |
7 | 6154 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6155 yankreg_T *y_ptr; |
7 | 6156 |
6157 if (cbd == &clip_plus) | |
6158 y_ptr = &y_regs[PLUS_REGISTER]; | |
6159 else | |
6160 y_ptr = &y_regs[STAR_REGISTER]; | |
6161 | |
6162 clip_free_selection(cbd); | |
6163 | |
5798 | 6164 str_to_reg(y_ptr, type, str, len, 0L, FALSE); |
7 | 6165 } |
6166 | |
6167 /* | |
6168 * Convert the '*'/'+' register into a GUI selection string returned in *str | |
6169 * with length *len. | |
6170 * Returns the motion type, or -1 for failure. | |
6171 */ | |
6172 int | |
17063
3147c7c2e86b
patch 8.1.1531: clipboard type name is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
6173 clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd) |
7 | 6174 { |
6175 char_u *p; | |
6176 int lnum; | |
6177 int i, j; | |
6178 int_u eolsize; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6179 yankreg_T *y_ptr; |
7 | 6180 |
6181 if (cbd == &clip_plus) | |
6182 y_ptr = &y_regs[PLUS_REGISTER]; | |
6183 else | |
6184 y_ptr = &y_regs[STAR_REGISTER]; | |
6185 | |
6186 #ifdef USE_CRNL | |
6187 eolsize = 2; | |
6188 #else | |
6189 eolsize = 1; | |
6190 #endif | |
6191 | |
6192 *str = NULL; | |
6193 *len = 0; | |
6194 if (y_ptr->y_array == NULL) | |
6195 return -1; | |
6196 | |
6197 for (i = 0; i < y_ptr->y_size; i++) | |
6198 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize; | |
6199 | |
6200 /* | |
6201 * Don't want newline character at end of last line if we're in MCHAR mode. | |
6202 */ | |
6203 if (y_ptr->y_type == MCHAR && *len >= eolsize) | |
6204 *len -= eolsize; | |
6205 | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
6206 p = *str = alloc(*len + 1); // add one to avoid zero |
7 | 6207 if (p == NULL) |
6208 return -1; | |
6209 lnum = 0; | |
6210 for (i = 0, j = 0; i < (int)*len; i++, j++) | |
6211 { | |
6212 if (y_ptr->y_array[lnum][j] == '\n') | |
6213 p[i] = NUL; | |
6214 else if (y_ptr->y_array[lnum][j] == NUL) | |
6215 { | |
6216 #ifdef USE_CRNL | |
6217 p[i++] = '\r'; | |
6218 #endif | |
6219 p[i] = '\n'; | |
6220 lnum++; | |
6221 j = -1; | |
6222 } | |
6223 else | |
6224 p[i] = y_ptr->y_array[lnum][j]; | |
6225 } | |
6226 return y_ptr->y_type; | |
6227 } | |
6228 | |
6229 | |
6230 /* | |
6231 * If we have written to a clipboard register, send the text to the clipboard. | |
6232 */ | |
6233 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6234 may_set_selection(void) |
7 | 6235 { |
6236 if (y_current == &(y_regs[STAR_REGISTER]) && clip_star.available) | |
6237 { | |
6238 clip_own_selection(&clip_star); | |
6239 clip_gen_set_selection(&clip_star); | |
6240 } | |
6241 else if (y_current == &(y_regs[PLUS_REGISTER]) && clip_plus.available) | |
6242 { | |
6243 clip_own_selection(&clip_plus); | |
6244 clip_gen_set_selection(&clip_plus); | |
6245 } | |
6246 } | |
6247 | |
6248 #endif /* FEAT_CLIPBOARD || PROTO */ | |
6249 | |
6250 | |
6251 #if defined(FEAT_DND) || defined(PROTO) | |
6252 /* | |
6253 * Replace the contents of the '~' register with str. | |
6254 */ | |
6255 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6256 dnd_yank_drag_data(char_u *str, long len) |
7 | 6257 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6258 yankreg_T *curr; |
7 | 6259 |
6260 curr = y_current; | |
6261 y_current = &y_regs[TILDE_REGISTER]; | |
6262 free_yank_all(); | |
5798 | 6263 str_to_reg(y_current, MCHAR, str, len, 0L, FALSE); |
7 | 6264 y_current = curr; |
6265 } | |
6266 #endif | |
6267 | |
6268 | |
6269 #if defined(FEAT_EVAL) || defined(PROTO) | |
6270 /* | |
6271 * Return the type of a register. | |
6272 * Used for getregtype() | |
6273 * Returns MAUTO for error. | |
6274 */ | |
6275 char_u | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6276 get_reg_type(int regname, long *reglen) |
7 | 6277 { |
6278 switch (regname) | |
6279 { | |
6280 case '%': /* file name */ | |
6281 case '#': /* alternate file name */ | |
6282 case '=': /* expression */ | |
6283 case ':': /* last command line */ | |
6284 case '/': /* last search-pattern */ | |
6285 case '.': /* last inserted text */ | |
6286 #ifdef FEAT_SEARCHPATH | |
6287 case Ctrl_F: /* Filename under cursor */ | |
6288 case Ctrl_P: /* Path under cursor, expand via "path" */ | |
6289 #endif | |
6290 case Ctrl_W: /* word under cursor */ | |
6291 case Ctrl_A: /* WORD (mnemonic All) under cursor */ | |
6292 case '_': /* black hole: always empty */ | |
6293 return MCHAR; | |
6294 } | |
6295 | |
6296 #ifdef FEAT_CLIPBOARD | |
6297 regname = may_get_selection(regname); | |
6298 #endif | |
6299 | |
5596 | 6300 if (regname != NUL && !valid_yank_reg(regname, FALSE)) |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7336
diff
changeset
|
6301 return MAUTO; |
5596 | 6302 |
7 | 6303 get_yank_register(regname, FALSE); |
6304 | |
6305 if (y_current->y_array != NULL) | |
6306 { | |
6307 if (reglen != NULL && y_current->y_type == MBLOCK) | |
6308 *reglen = y_current->y_width; | |
6309 return y_current->y_type; | |
6310 } | |
6311 return MAUTO; | |
6312 } | |
6313 | |
5796 | 6314 /* |
6315 * When "flags" has GREG_LIST return a list with text "s". | |
6316 * Otherwise just return "s". | |
6317 */ | |
6318 static char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6319 getreg_wrap_one_line(char_u *s, int flags) |
5796 | 6320 { |
6321 if (flags & GREG_LIST) | |
6322 { | |
6323 list_T *list = list_alloc(); | |
6324 | |
6325 if (list != NULL) | |
6326 { | |
6327 if (list_append_string(list, NULL, -1) == FAIL) | |
6328 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6329 list_free(list); |
5796 | 6330 return NULL; |
6331 } | |
6332 list->lv_first->li_tv.vval.v_string = s; | |
6333 } | |
6334 return (char_u *)list; | |
6335 } | |
6336 return s; | |
6337 } | |
6338 | |
7 | 6339 /* |
6340 * Return the contents of a register as a single allocated string. | |
6341 * Used for "@r" in expressions and for getreg(). | |
6342 * Returns NULL for error. | |
5796 | 6343 * Flags: |
6344 * GREG_NO_EXPR Do not allow expression register | |
6345 * GREG_EXPR_SRC For the expression register: return expression itself, | |
6346 * not the result of its evaluation. | |
6347 * GREG_LIST Return a list of lines in place of a single string. | |
7 | 6348 */ |
6349 char_u * | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6350 get_reg_contents(int regname, int flags) |
7 | 6351 { |
6352 long i; | |
6353 char_u *retval; | |
6354 int allocated; | |
6355 long len; | |
6356 | |
6357 /* Don't allow using an expression register inside an expression */ | |
6358 if (regname == '=') | |
6359 { | |
5796 | 6360 if (flags & GREG_NO_EXPR) |
6361 return NULL; | |
6362 if (flags & GREG_EXPR_SRC) | |
6363 return getreg_wrap_one_line(get_expr_line_src(), flags); | |
6364 return getreg_wrap_one_line(get_expr_line(), flags); | |
7 | 6365 } |
6366 | |
6367 if (regname == '@') /* "@@" is used for unnamed register */ | |
6368 regname = '"'; | |
6369 | |
6370 /* check for valid regname */ | |
6371 if (regname != NUL && !valid_yank_reg(regname, FALSE)) | |
6372 return NULL; | |
6373 | |
6374 #ifdef FEAT_CLIPBOARD | |
6375 regname = may_get_selection(regname); | |
6376 #endif | |
6377 | |
6378 if (get_spec_reg(regname, &retval, &allocated, FALSE)) | |
6379 { | |
6380 if (retval == NULL) | |
6381 return NULL; | |
5796 | 6382 if (allocated) |
6383 return getreg_wrap_one_line(retval, flags); | |
6384 return getreg_wrap_one_line(vim_strsave(retval), flags); | |
7 | 6385 } |
6386 | |
6387 get_yank_register(regname, FALSE); | |
6388 if (y_current->y_array == NULL) | |
6389 return NULL; | |
6390 | |
5796 | 6391 if (flags & GREG_LIST) |
6392 { | |
6393 list_T *list = list_alloc(); | |
6394 int error = FALSE; | |
6395 | |
6396 if (list == NULL) | |
6397 return NULL; | |
6398 for (i = 0; i < y_current->y_size; ++i) | |
6399 if (list_append_string(list, y_current->y_array[i], -1) == FAIL) | |
6400 error = TRUE; | |
6401 if (error) | |
6402 { | |
8863
e1b84109506a
commit https://github.com/vim/vim/commit/107e1eef1df3b786ad3ad49fbdb9e058649303b5
Christian Brabandt <cb@256bit.org>
parents:
8690
diff
changeset
|
6403 list_free(list); |
5796 | 6404 return NULL; |
6405 } | |
6406 return (char_u *)list; | |
6407 } | |
6408 | |
7 | 6409 /* |
6410 * Compute length of resulting string. | |
6411 */ | |
6412 len = 0; | |
6413 for (i = 0; i < y_current->y_size; ++i) | |
6414 { | |
6415 len += (long)STRLEN(y_current->y_array[i]); | |
6416 /* | |
6417 * Insert a newline between lines and after last line if | |
6418 * y_type is MLINE. | |
6419 */ | |
6420 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6421 ++len; | |
6422 } | |
6423 | |
16768
695d9ef00b03
patch 8.1.1386: unessesary type casts for lalloc()
Bram Moolenaar <Bram@vim.org>
parents:
16764
diff
changeset
|
6424 retval = alloc(len + 1); |
7 | 6425 |
6426 /* | |
6427 * Copy the lines of the yank register into the string. | |
6428 */ | |
6429 if (retval != NULL) | |
6430 { | |
6431 len = 0; | |
6432 for (i = 0; i < y_current->y_size; ++i) | |
6433 { | |
6434 STRCPY(retval + len, y_current->y_array[i]); | |
6435 len += (long)STRLEN(retval + len); | |
6436 | |
6437 /* | |
6438 * Insert a NL between lines and after the last line if y_type is | |
6439 * MLINE. | |
6440 */ | |
6441 if (y_current->y_type == MLINE || i < y_current->y_size - 1) | |
6442 retval[len++] = '\n'; | |
6443 } | |
6444 retval[len] = NUL; | |
6445 } | |
6446 | |
6447 return retval; | |
6448 } | |
6449 | |
5798 | 6450 static int |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6451 init_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6452 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6453 yankreg_T **old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6454 yankreg_T **old_y_current, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6455 int must_append, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6456 int *yank_type UNUSED) |
5798 | 6457 { |
6458 if (!valid_yank_reg(name, TRUE)) /* check for valid reg name */ | |
6459 { | |
6460 emsg_invreg(name); | |
6461 return FAIL; | |
6462 } | |
6463 | |
6464 /* Don't want to change the current (unnamed) register */ | |
6465 *old_y_previous = y_previous; | |
6466 *old_y_current = y_current; | |
6467 | |
6468 get_yank_register(name, TRUE); | |
6469 if (!y_append && !must_append) | |
6470 free_yank_all(); | |
6471 return OK; | |
6472 } | |
6473 | |
6474 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6475 finish_write_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6476 int name, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6477 yankreg_T *old_y_previous, |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6478 yankreg_T *old_y_current) |
5798 | 6479 { |
6480 # ifdef FEAT_CLIPBOARD | |
6481 /* Send text of clipboard register to the clipboard. */ | |
6482 may_set_selection(); | |
6483 # endif | |
6484 | |
6485 /* ':let @" = "val"' should change the meaning of the "" register */ | |
6486 if (name != '"') | |
6487 y_previous = old_y_previous; | |
6488 y_current = old_y_current; | |
6489 } | |
6490 | |
7 | 6491 /* |
6492 * Store string "str" in register "name". | |
6493 * "maxlen" is the maximum number of bytes to use, -1 for all bytes. | |
6494 * If "must_append" is TRUE, always append to the register. Otherwise append | |
6495 * if "name" is an uppercase letter. | |
6496 * Note: "maxlen" and "must_append" don't work for the "/" register. | |
6497 * Careful: 'str' is modified, you may have to use a copy! | |
6498 * If "str" ends in '\n' or '\r', use linewise, otherwise use characterwise. | |
6499 */ | |
6500 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6501 write_reg_contents( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6502 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6503 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6504 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6505 int must_append) |
7 | 6506 { |
6507 write_reg_contents_ex(name, str, maxlen, must_append, MAUTO, 0L); | |
6508 } | |
6509 | |
6510 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6511 write_reg_contents_lst( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6512 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6513 char_u **strings, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6514 int maxlen UNUSED, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6515 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6516 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6517 long block_len) |
5798 | 6518 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6519 yankreg_T *old_y_previous, *old_y_current; |
5798 | 6520 |
6521 if (name == '/' | |
6522 #ifdef FEAT_EVAL | |
6523 || name == '=' | |
6524 #endif | |
6525 ) | |
6526 { | |
6527 char_u *s; | |
6528 | |
6529 if (strings[0] == NULL) | |
6530 s = (char_u *)""; | |
6531 else if (strings[1] != NULL) | |
6532 { | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6533 emsg(_("E883: search pattern and expression register may not " |
5798 | 6534 "contain two or more lines")); |
6535 return; | |
6536 } | |
6537 else | |
6538 s = strings[0]; | |
6539 write_reg_contents_ex(name, s, -1, must_append, yank_type, block_len); | |
6540 return; | |
6541 } | |
6542 | |
6543 if (name == '_') /* black hole: nothing to do */ | |
6544 return; | |
6545 | |
6546 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, | |
6547 &yank_type) == FAIL) | |
6548 return; | |
6549 | |
6550 str_to_reg(y_current, yank_type, (char_u *) strings, -1, block_len, TRUE); | |
6551 | |
6552 finish_write_reg(name, old_y_previous, old_y_current); | |
6553 } | |
6554 | |
6555 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6556 write_reg_contents_ex( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6557 int name, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6558 char_u *str, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6559 int maxlen, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6560 int must_append, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6561 int yank_type, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6562 long block_len) |
7 | 6563 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6564 yankreg_T *old_y_previous, *old_y_current; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6565 long len; |
7 | 6566 |
336 | 6567 if (maxlen >= 0) |
6568 len = maxlen; | |
6569 else | |
6570 len = (long)STRLEN(str); | |
6571 | |
7 | 6572 /* Special case: '/' search pattern */ |
6573 if (name == '/') | |
6574 { | |
6575 set_last_search_pat(str, RE_SEARCH, TRUE, TRUE); | |
6576 return; | |
6577 } | |
6578 | |
6557 | 6579 if (name == '#') |
6580 { | |
6581 buf_T *buf; | |
6582 | |
6583 if (VIM_ISDIGIT(*str)) | |
6584 { | |
6585 int num = atoi((char *)str); | |
6586 | |
6587 buf = buflist_findnr(num); | |
6588 if (buf == NULL) | |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15428
diff
changeset
|
6589 semsg(_(e_nobufnr), (long)num); |
6557 | 6590 } |
6591 else | |
6592 buf = buflist_findnr(buflist_findpat(str, str + STRLEN(str), | |
6593 TRUE, FALSE, FALSE)); | |
6594 if (buf == NULL) | |
6595 return; | |
6596 curwin->w_alt_fnum = buf->b_fnum; | |
6597 return; | |
6598 } | |
6599 | |
336 | 6600 #ifdef FEAT_EVAL |
6601 if (name == '=') | |
6602 { | |
6603 char_u *p, *s; | |
6604 | |
6605 p = vim_strnsave(str, (int)len); | |
6606 if (p == NULL) | |
6607 return; | |
6608 if (must_append) | |
6609 { | |
6610 s = concat_str(get_expr_line_src(), p); | |
6611 vim_free(p); | |
6612 p = s; | |
6613 } | |
6614 set_expr_line(p); | |
6615 return; | |
6616 } | |
6617 #endif | |
6618 | |
7 | 6619 if (name == '_') /* black hole: nothing to do */ |
6620 return; | |
6621 | |
5798 | 6622 if (init_write_reg(name, &old_y_previous, &old_y_current, must_append, |
6623 &yank_type) == FAIL) | |
6624 return; | |
6625 | |
6626 str_to_reg(y_current, yank_type, str, len, block_len, FALSE); | |
6627 | |
6628 finish_write_reg(name, old_y_previous, old_y_current); | |
7 | 6629 } |
6630 #endif /* FEAT_EVAL */ | |
6631 | |
6632 #if defined(FEAT_CLIPBOARD) || defined(FEAT_EVAL) | |
6633 /* | |
6634 * Put a string into a register. When the register is not empty, the string | |
6635 * is appended. | |
6636 */ | |
6637 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6638 str_to_reg( |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6639 yankreg_T *y_ptr, /* pointer to yank register */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6640 int yank_type, /* MCHAR, MLINE, MBLOCK, MAUTO */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6641 char_u *str, /* string to put in register */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6642 long len, /* length of string */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6643 long blocklen, /* width of Visual block */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6644 int str_list) /* TRUE if str is char_u ** */ |
7 | 6645 { |
2896 | 6646 int type; /* MCHAR, MLINE or MBLOCK */ |
7 | 6647 int lnum; |
6648 long start; | |
6649 long i; | |
6650 int extra; | |
6651 int newlines; /* number of lines added */ | |
6652 int extraline = 0; /* extra line at the end */ | |
6653 int append = FALSE; /* append to last line in register */ | |
6654 char_u *s; | |
5798 | 6655 char_u **ss; |
7 | 6656 char_u **pp; |
6657 long maxlen; | |
6658 | |
2000 | 6659 if (y_ptr->y_array == NULL) /* NULL means empty register */ |
7 | 6660 y_ptr->y_size = 0; |
6661 | |
2896 | 6662 if (yank_type == MAUTO) |
5798 | 6663 type = ((str_list || (len > 0 && (str[len - 1] == NL |
6664 || str[len - 1] == CAR))) | |
2896 | 6665 ? MLINE : MCHAR); |
6666 else | |
6667 type = yank_type; | |
6668 | |
7 | 6669 /* |
6670 * Count the number of lines within the string | |
6671 */ | |
6672 newlines = 0; | |
5798 | 6673 if (str_list) |
6674 { | |
6675 for (ss = (char_u **) str; *ss != NULL; ++ss) | |
7 | 6676 ++newlines; |
5798 | 6677 } |
6678 else | |
6679 { | |
6680 for (i = 0; i < len; i++) | |
6681 if (str[i] == '\n') | |
6682 ++newlines; | |
6683 if (type == MCHAR || len == 0 || str[len - 1] != '\n') | |
6684 { | |
6685 extraline = 1; | |
6686 ++newlines; /* count extra newline at the end */ | |
6687 } | |
6688 if (y_ptr->y_size > 0 && y_ptr->y_type == MCHAR) | |
6689 { | |
6690 append = TRUE; | |
6691 --newlines; /* uncount newline when appending first line */ | |
6692 } | |
7 | 6693 } |
6694 | |
6807 | 6695 /* Without any lines make the register empty. */ |
6696 if (y_ptr->y_size + newlines == 0) | |
6697 { | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13202
diff
changeset
|
6698 VIM_CLEAR(y_ptr->y_array); |
6807 | 6699 return; |
6700 } | |
6701 | |
7 | 6702 /* |
6703 * Allocate an array to hold the pointers to the new register lines. | |
6704 * If the register was not empty, move the existing lines to the new array. | |
6705 */ | |
16825
ce04ebdf26b8
patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents:
16782
diff
changeset
|
6706 pp = lalloc_clear((y_ptr->y_size + newlines) * sizeof(char_u *), TRUE); |
7 | 6707 if (pp == NULL) /* out of memory */ |
6708 return; | |
6709 for (lnum = 0; lnum < y_ptr->y_size; ++lnum) | |
6710 pp[lnum] = y_ptr->y_array[lnum]; | |
6711 vim_free(y_ptr->y_array); | |
6712 y_ptr->y_array = pp; | |
6713 maxlen = 0; | |
6714 | |
6715 /* | |
6716 * Find the end of each line and save it into the array. | |
6717 */ | |
5798 | 6718 if (str_list) |
6719 { | |
6720 for (ss = (char_u **) str; *ss != NULL; ++ss, ++lnum) | |
7 | 6721 { |
5856 | 6722 i = (long)STRLEN(*ss); |
5798 | 6723 pp[lnum] = vim_strnsave(*ss, i); |
6724 if (i > maxlen) | |
6725 maxlen = i; | |
7 | 6726 } |
5798 | 6727 } |
6728 else | |
6729 { | |
6730 for (start = 0; start < len + extraline; start += i + 1) | |
7 | 6731 { |
5798 | 6732 for (i = start; i < len; ++i) /* find the end of the line */ |
6733 if (str[i] == '\n') | |
6734 break; | |
6735 i -= start; /* i is now length of line */ | |
6736 if (i > maxlen) | |
6737 maxlen = i; | |
6738 if (append) | |
6739 { | |
6740 --lnum; | |
6741 extra = (int)STRLEN(y_ptr->y_array[lnum]); | |
6742 } | |
6743 else | |
6744 extra = 0; | |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16714
diff
changeset
|
6745 s = alloc(i + extra + 1); |
5798 | 6746 if (s == NULL) |
6747 break; | |
6748 if (extra) | |
6749 mch_memmove(s, y_ptr->y_array[lnum], (size_t)extra); | |
6750 if (append) | |
6751 vim_free(y_ptr->y_array[lnum]); | |
6752 if (i) | |
6753 mch_memmove(s + extra, str + start, (size_t)i); | |
6754 extra += i; | |
6755 s[extra] = NUL; | |
6756 y_ptr->y_array[lnum++] = s; | |
6757 while (--extra >= 0) | |
6758 { | |
6759 if (*s == NUL) | |
6760 *s = '\n'; /* replace NUL with newline */ | |
6761 ++s; | |
6762 } | |
6763 append = FALSE; /* only first line is appended */ | |
7 | 6764 } |
6765 } | |
6766 y_ptr->y_type = type; | |
6767 y_ptr->y_size = lnum; | |
6768 if (type == MBLOCK) | |
6769 y_ptr->y_width = (blocklen < 0 ? maxlen - 1 : blocklen); | |
6770 else | |
6771 y_ptr->y_width = 0; | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6772 #ifdef FEAT_VIMINFO |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6773 y_ptr->y_time_set = vim_time(); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9225
diff
changeset
|
6774 #endif |
7 | 6775 } |
6776 #endif /* FEAT_CLIPBOARD || FEAT_EVAL || PROTO */ | |
6777 | |
6778 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6779 clear_oparg(oparg_T *oap) |
7 | 6780 { |
6781 vim_memset(oap, 0, sizeof(oparg_T)); | |
6782 } | |
6783 | |
6784 /* | |
161 | 6785 * Count the number of bytes, characters and "words" in a line. |
7 | 6786 * |
6787 * "Words" are counted by looking for boundaries between non-space and | |
6788 * space characters. (it seems to produce results that match 'wc'.) | |
6789 * | |
161 | 6790 * Return value is byte count; word count for the line is added to "*wc". |
6791 * Char count is added to "*cc". | |
7 | 6792 * |
6793 * The function will only examine the first "limit" characters in the | |
6794 * line, stopping if it encounters an end-of-line (NUL byte). In that | |
6795 * case, eol_size will be added to the character count to account for | |
6796 * the size of the EOL character. | |
6797 */ | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6798 static varnumber_T |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6799 line_count_info( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6800 char_u *line, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6801 varnumber_T *wc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6802 varnumber_T *cc, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6803 varnumber_T limit, |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6804 int eol_size) |
7 | 6805 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6806 varnumber_T i; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6807 varnumber_T words = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6808 varnumber_T chars = 0; |
7 | 6809 int is_word = 0; |
6810 | |
3626 | 6811 for (i = 0; i < limit && line[i] != NUL; ) |
7 | 6812 { |
6813 if (is_word) | |
6814 { | |
6815 if (vim_isspace(line[i])) | |
6816 { | |
6817 words++; | |
6818 is_word = 0; | |
6819 } | |
6820 } | |
6821 else if (!vim_isspace(line[i])) | |
6822 is_word = 1; | |
161 | 6823 ++chars; |
474 | 6824 i += (*mb_ptr2len)(line + i); |
7 | 6825 } |
6826 | |
6827 if (is_word) | |
6828 words++; | |
6829 *wc += words; | |
6830 | |
6831 /* Add eol_size if the end of line was reached before hitting limit. */ | |
2996 | 6832 if (i < limit && line[i] == NUL) |
161 | 6833 { |
7 | 6834 i += eol_size; |
161 | 6835 chars += eol_size; |
6836 } | |
6837 *cc += chars; | |
7 | 6838 return i; |
6839 } | |
6840 | |
6841 /* | |
6842 * Give some info about the position of the cursor (for "g CTRL-G"). | |
6843 * In Visual mode, give some info about the selected region. (In this case, | |
6844 * the *_count_cursor variables store running totals for the selection.) | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6845 * When "dict" is not NULL store the info there instead of showing it. |
7 | 6846 */ |
6847 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7805
diff
changeset
|
6848 cursor_pos_info(dict_T *dict) |
7 | 6849 { |
6850 char_u *p; | |
274 | 6851 char_u buf1[50]; |
6852 char_u buf2[40]; | |
7 | 6853 linenr_T lnum; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6854 varnumber_T byte_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6855 varnumber_T bom_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6856 varnumber_T byte_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6857 varnumber_T char_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6858 varnumber_T char_count_cursor = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6859 varnumber_T word_count = 0; |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6860 varnumber_T word_count_cursor = 0; |
7 | 6861 int eol_size; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6862 varnumber_T last_check = 100000L; |
7 | 6863 long line_count_selected = 0; |
6864 pos_T min_pos, max_pos; | |
6865 oparg_T oparg; | |
6866 struct block_def bd; | |
6867 | |
6868 /* | |
6869 * Compute the length of the file in characters. | |
6870 */ | |
6871 if (curbuf->b_ml.ml_flags & ML_EMPTY) | |
6872 { | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6873 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6874 { |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
6875 msg(_(no_lines_msg)); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6876 return; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
6877 } |
7 | 6878 } |
6879 else | |
6880 { | |
6881 if (get_fileformat(curbuf) == EOL_DOS) | |
6882 eol_size = 2; | |
6883 else | |
6884 eol_size = 1; | |
6885 | |
6886 if (VIsual_active) | |
6887 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11065
diff
changeset
|
6888 if (LT_POS(VIsual, curwin->w_cursor)) |
7 | 6889 { |
6890 min_pos = VIsual; | |
6891 max_pos = curwin->w_cursor; | |
6892 } | |
6893 else | |
6894 { | |
6895 min_pos = curwin->w_cursor; | |
6896 max_pos = VIsual; | |
6897 } | |
6898 if (*p_sel == 'e' && max_pos.col > 0) | |
6899 --max_pos.col; | |
6900 | |
6901 if (VIsual_mode == Ctrl_V) | |
6902 { | |
1866 | 6903 #ifdef FEAT_LINEBREAK |
6904 char_u * saved_sbr = p_sbr; | |
6905 | |
6906 /* Make 'sbr' empty for a moment to get the correct size. */ | |
6907 p_sbr = empty_option; | |
6908 #endif | |
7 | 6909 oparg.is_VIsual = 1; |
6910 oparg.block_mode = TRUE; | |
6911 oparg.op_type = OP_NOP; | |
6912 getvcols(curwin, &min_pos, &max_pos, | |
688 | 6913 &oparg.start_vcol, &oparg.end_vcol); |
1866 | 6914 #ifdef FEAT_LINEBREAK |
6915 p_sbr = saved_sbr; | |
6916 #endif | |
688 | 6917 if (curwin->w_curswant == MAXCOL) |
6918 oparg.end_vcol = MAXCOL; | |
7 | 6919 /* Swap the start, end vcol if needed */ |
6920 if (oparg.end_vcol < oparg.start_vcol) | |
6921 { | |
6922 oparg.end_vcol += oparg.start_vcol; | |
6923 oparg.start_vcol = oparg.end_vcol - oparg.start_vcol; | |
6924 oparg.end_vcol -= oparg.start_vcol; | |
6925 } | |
6926 } | |
6927 line_count_selected = max_pos.lnum - min_pos.lnum + 1; | |
6928 } | |
6929 | |
6930 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
6931 { | |
6932 /* Check for a CTRL-C every 100000 characters. */ | |
161 | 6933 if (byte_count > last_check) |
7 | 6934 { |
6935 ui_breakcheck(); | |
6936 if (got_int) | |
6937 return; | |
161 | 6938 last_check = byte_count + 100000L; |
7 | 6939 } |
6940 | |
6941 /* Do extra processing for VIsual mode. */ | |
6942 if (VIsual_active | |
6943 && lnum >= min_pos.lnum && lnum <= max_pos.lnum) | |
6944 { | |
45 | 6945 char_u *s = NULL; |
6946 long len = 0L; | |
6947 | |
7 | 6948 switch (VIsual_mode) |
6949 { | |
6950 case Ctrl_V: | |
6951 virtual_op = virtual_active(); | |
6952 block_prep(&oparg, &bd, lnum, 0); | |
6953 virtual_op = MAYBE; | |
45 | 6954 s = bd.textstart; |
6955 len = (long)bd.textlen; | |
7 | 6956 break; |
6957 case 'V': | |
45 | 6958 s = ml_get(lnum); |
6959 len = MAXCOL; | |
7 | 6960 break; |
6961 case 'v': | |
6962 { | |
6963 colnr_T start_col = (lnum == min_pos.lnum) | |
6964 ? min_pos.col : 0; | |
6965 colnr_T end_col = (lnum == max_pos.lnum) | |
6966 ? max_pos.col - start_col + 1 : MAXCOL; | |
6967 | |
45 | 6968 s = ml_get(lnum) + start_col; |
6969 len = end_col; | |
7 | 6970 } |
6971 break; | |
6972 } | |
45 | 6973 if (s != NULL) |
6974 { | |
161 | 6975 byte_count_cursor += line_count_info(s, &word_count_cursor, |
6976 &char_count_cursor, len, eol_size); | |
45 | 6977 if (lnum == curbuf->b_ml.ml_line_count |
6978 && !curbuf->b_p_eol | |
6933 | 6979 && (curbuf->b_p_bin || !curbuf->b_p_fixeol) |
50 | 6980 && (long)STRLEN(s) < len) |
161 | 6981 byte_count_cursor -= eol_size; |
45 | 6982 } |
7 | 6983 } |
6984 else | |
6985 { | |
6986 /* In non-visual mode, check for the line the cursor is on */ | |
6987 if (lnum == curwin->w_cursor.lnum) | |
6988 { | |
6989 word_count_cursor += word_count; | |
161 | 6990 char_count_cursor += char_count; |
6991 byte_count_cursor = byte_count + | |
6992 line_count_info(ml_get(lnum), | |
6993 &word_count_cursor, &char_count_cursor, | |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6994 (varnumber_T)(curwin->w_cursor.col + 1), |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
6995 eol_size); |
7 | 6996 } |
6997 } | |
6998 /* Add to the running totals */ | |
161 | 6999 byte_count += line_count_info(ml_get(lnum), &word_count, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7000 &char_count, (varnumber_T)MAXCOL, |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7001 eol_size); |
7 | 7002 } |
7003 | |
7004 /* Correction for when last line doesn't have an EOL. */ | |
6933 | 7005 if (!curbuf->b_p_eol && (curbuf->b_p_bin || !curbuf->b_p_fixeol)) |
161 | 7006 byte_count -= eol_size; |
7 | 7007 |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7008 if (dict == NULL) |
7 | 7009 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7010 if (VIsual_active) |
7 | 7011 { |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7012 if (VIsual_mode == Ctrl_V && curwin->w_curswant < MAXCOL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7013 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7014 getvcols(curwin, &min_pos, &max_pos, &min_pos.col, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7015 &max_pos.col); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7016 vim_snprintf((char *)buf1, sizeof(buf1), _("%ld Cols; "), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7017 (long)(oparg.end_vcol - oparg.start_vcol + 1)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7018 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7019 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7020 buf1[0] = NUL; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7021 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7022 if (char_count_cursor == byte_count_cursor |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7023 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7024 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7025 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Bytes"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7026 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7027 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7028 (long_long_T)word_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7029 (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7030 (long_long_T)byte_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7031 (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7032 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7033 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7034 _("Selected %s%ld of %ld Lines; %lld of %lld Words; %lld of %lld Chars; %lld of %lld Bytes"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7035 buf1, line_count_selected, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7036 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7037 (long_long_T)word_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7038 (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7039 (long_long_T)char_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7040 (long_long_T)char_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7041 (long_long_T)byte_count_cursor, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7042 (long_long_T)byte_count); |
7 | 7043 } |
7044 else | |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7045 { |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7046 p = ml_get_curline(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7047 validate_virtcol(); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7048 col_print(buf1, sizeof(buf1), (int)curwin->w_cursor.col + 1, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7049 (int)curwin->w_virtcol + 1); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7050 col_print(buf2, sizeof(buf2), (int)STRLEN(p), |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7051 linetabsize(p)); |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7052 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7053 if (char_count_cursor == byte_count_cursor |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7054 && char_count == byte_count) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7055 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7056 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Byte %lld of %lld"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7057 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7058 (long)curwin->w_cursor.lnum, |
7 | 7059 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7060 (long_long_T)word_count_cursor, (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7061 (long_long_T)byte_count_cursor, (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7062 else |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7063 vim_snprintf((char *)IObuff, IOSIZE, |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9332
diff
changeset
|
7064 _("Col %s of %s; Line %ld of %ld; Word %lld of %lld; Char %lld of %lld; Byte %lld of %lld"), |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7065 (char *)buf1, (char *)buf2, |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7066 (long)curwin->w_cursor.lnum, |
161 | 7067 (long)curbuf->b_ml.ml_line_count, |
15517
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7068 (long_long_T)word_count_cursor, (long_long_T)word_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7069 (long_long_T)char_count_cursor, (long_long_T)char_count, |
2ad5f0ffaa2e
patch 8.1.0766: various problems when using Vim on VMS
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
7070 (long_long_T)byte_count_cursor, (long_long_T)byte_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7071 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7072 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7073 |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7074 bom_count = bomb_size(); |
18062
0b351691071c
patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
17797
diff
changeset
|
7075 if (dict == NULL && bom_count > 0) |
7496
6d969668bfc8
commit https://github.com/vim/vim/commit/c71982b23978ef61d0a2f0fe5535e782e1c561ed
Christian Brabandt <cb@256bit.org>
parents:
7484
diff
changeset
|
7076 vim_snprintf((char *)IObuff + STRLEN(IObuff), IOSIZE, |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7077 _("(+%lld for BOM)"), (long_long_T)bom_count); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7078 if (dict == NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7079 { |
18062
0b351691071c
patch 8.1.2026: possibly using uninitialized memory
Bram Moolenaar <Bram@vim.org>
parents:
17797
diff
changeset
|
7080 // Don't shorten this message, the user asked for it. |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7081 p = p_shm; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7082 p_shm = (char_u *)""; |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15517
diff
changeset
|
7083 msg((char *)IObuff); |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7084 p_shm = p; |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7085 } |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7086 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7087 #if defined(FEAT_EVAL) |
7480
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7088 if (dict != NULL) |
a49163681559
commit https://github.com/vim/vim/commit/ed767a2073ef150971b0439a58e7ee582af6984e
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
7089 { |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7090 dict_add_number(dict, "words", word_count); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7091 dict_add_number(dict, "chars", char_count); |
15597
536dd2bc5ac9
patch 8.1.0806: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15555
diff
changeset
|
7092 dict_add_number(dict, "bytes", byte_count + bom_count); |
14301
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7093 dict_add_number(dict, VIsual_active ? "visual_bytes" : "cursor_bytes", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7094 byte_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7095 dict_add_number(dict, VIsual_active ? "visual_chars" : "cursor_chars", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7096 char_count_cursor); |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7097 dict_add_number(dict, VIsual_active ? "visual_words" : "cursor_words", |
3c80092eb211
patch 8.1.0166: using dict_add_nr_str() is clumsy
Christian Brabandt <cb@256bit.org>
parents:
14216
diff
changeset
|
7098 word_count_cursor); |
7 | 7099 } |
7484
1fe988587423
commit https://github.com/vim/vim/commit/718272a7e13c71095ce07eb3b3d5e1f9790a6991
Christian Brabandt <cb@256bit.org>
parents:
7480
diff
changeset
|
7100 #endif |
7 | 7101 } |