Mercurial > vim
annotate src/mark.c @ 30711:e1fbb6571b58 v9.0.0690
patch 9.0.0690: buffer size for expanding tab not correctly computed
Commit: https://github.com/vim/vim/commit/a0789478f6ebbb823670b7e14ce13ea3fd3b0217
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 8 11:16:40 2022 +0100
patch 9.0.0690: buffer size for expanding tab not correctly computed
Problem: Buffer size for expanding tab not correctly computed.
Solution: Correctly use size of end character.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 08 Oct 2022 12:30:06 +0200 |
parents | 14c0d0c72bcd |
children | 238ca27dbfd2 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9649
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 * mark.c: functions for setting marks and jumping to them | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 | |
16 /* | |
17 * This file contains routines to maintain and manipulate marks. | |
18 */ | |
19 | |
20 /* | |
21 * If a named file mark's lnum is non-zero, it is valid. | |
22 * If a named file mark's fnum is non-zero, it is for an existing buffer, | |
23 * otherwise it is from .viminfo and namedfm[n].fname is the file name. | |
24 * There are marks 'A - 'Z (set by user) and '0 to '9 (set when writing | |
25 * viminfo). | |
26 */ | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
27 static xfmark_T namedfm[NMARKS + EXTRA_MARKS]; // marks with file nr |
7 | 28 |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17464
diff
changeset
|
29 static void fname2fnum(xfmark_T *fm); |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
30 static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
31 static char_u *mark_line(pos_T *mp, int lead_len); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
5735
diff
changeset
|
32 static void show_one_mark(int, char_u *, pos_T *, char_u *, int current); |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
33 static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount, |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
34 long amount_after, int adjust_folds); |
7 | 35 |
36 /* | |
706 | 37 * Set named mark "c" at current cursor position. |
7 | 38 * Returns OK on success, FAIL if bad name given. |
39 */ | |
40 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
41 setmark(int c) |
7 | 42 { |
706 | 43 return setmark_pos(c, &curwin->w_cursor, curbuf->b_fnum); |
44 } | |
45 | |
46 /* | |
47 * Set named mark "c" to position "pos". | |
48 * When "c" is upper case use file "fnum". | |
49 * Returns OK on success, FAIL if bad name given. | |
50 */ | |
51 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
52 setmark_pos(int c, pos_T *pos, int fnum) |
706 | 53 { |
7 | 54 int i; |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
55 buf_T *buf; |
7 | 56 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
57 // Check for a special key (may cause islower() to crash). |
7 | 58 if (c < 0) |
59 return FAIL; | |
60 | |
61 if (c == '\'' || c == '`') | |
62 { | |
706 | 63 if (pos == &curwin->w_cursor) |
64 { | |
65 setpcmark(); | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
66 // keep it even when the cursor doesn't move |
706 | 67 curwin->w_prev_pcmark = curwin->w_pcmark; |
68 } | |
69 else | |
70 curwin->w_pcmark = *pos; | |
7 | 71 return OK; |
72 } | |
73 | |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
74 buf = buflist_findnr(fnum); |
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
75 if (buf == NULL) |
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
76 return FAIL; |
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
77 |
1533 | 78 if (c == '"') |
79 { | |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
80 buf->b_last_cursor = *pos; |
1533 | 81 return OK; |
82 } | |
83 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
84 // Allow setting '[ and '] for an autocommand that simulates reading a |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
85 // file. |
7 | 86 if (c == '[') |
87 { | |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
88 buf->b_op_start = *pos; |
7 | 89 return OK; |
90 } | |
91 if (c == ']') | |
92 { | |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
93 buf->b_op_end = *pos; |
7 | 94 return OK; |
95 } | |
96 | |
5265
cd971e951b06
updated for version 7.4b.009
Bram Moolenaar <bram@vim.org>
parents:
4092
diff
changeset
|
97 if (c == '<' || c == '>') |
3660 | 98 { |
5265
cd971e951b06
updated for version 7.4b.009
Bram Moolenaar <bram@vim.org>
parents:
4092
diff
changeset
|
99 if (c == '<') |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
100 buf->b_visual.vi_start = *pos; |
5265
cd971e951b06
updated for version 7.4b.009
Bram Moolenaar <bram@vim.org>
parents:
4092
diff
changeset
|
101 else |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
102 buf->b_visual.vi_end = *pos; |
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
103 if (buf->b_visual.vi_mode == NUL) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
104 // Visual_mode has not yet been set, use a sane default. |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
105 buf->b_visual.vi_mode = 'v'; |
3660 | 106 return OK; |
107 } | |
108 | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
109 if (ASCII_ISLOWER(c)) |
7 | 110 { |
111 i = c - 'a'; | |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
112 buf->b_namedm[i] = *pos; |
7 | 113 return OK; |
114 } | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
115 if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c)) |
7 | 116 { |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
117 if (VIM_ISDIGIT(c)) |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
118 i = c - '0' + NMARKS; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
119 else |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
120 i = c - 'A'; |
706 | 121 namedfm[i].fmark.mark = *pos; |
122 namedfm[i].fmark.fnum = fnum; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
123 VIM_CLEAR(namedfm[i].fname); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
124 #ifdef FEAT_VIMINFO |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
125 namedfm[i].time_set = vim_time(); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
126 #endif |
7 | 127 return OK; |
128 } | |
129 return FAIL; | |
130 } | |
131 | |
132 /* | |
133 * Set the previous context mark to the current position and add it to the | |
134 * jump list. | |
135 */ | |
136 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
137 setpcmark(void) |
7 | 138 { |
139 int i; | |
140 xfmark_T *fm; | |
141 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
142 // for :global the mark is set only once |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
21403
diff
changeset
|
143 if (global_busy || listcmd_busy || (cmdmod.cmod_flags & CMOD_KEEPJUMPS)) |
7 | 144 return; |
145 | |
146 curwin->w_prev_pcmark = curwin->w_pcmark; | |
147 curwin->w_pcmark = curwin->w_cursor; | |
148 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
149 // If jumplist is full: remove oldest entry |
7 | 150 if (++curwin->w_jumplistlen > JUMPLISTSIZE) |
151 { | |
152 curwin->w_jumplistlen = JUMPLISTSIZE; | |
153 vim_free(curwin->w_jumplist[0].fname); | |
154 for (i = 1; i < JUMPLISTSIZE; ++i) | |
155 curwin->w_jumplist[i - 1] = curwin->w_jumplist[i]; | |
156 } | |
157 curwin->w_jumplistidx = curwin->w_jumplistlen; | |
158 fm = &curwin->w_jumplist[curwin->w_jumplistlen - 1]; | |
159 | |
160 fm->fmark.mark = curwin->w_pcmark; | |
161 fm->fmark.fnum = curbuf->b_fnum; | |
162 fm->fname = NULL; | |
26532
255bc9a08e58
patch 8.2.3795: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
163 #ifdef FEAT_VIMINFO |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
164 fm->time_set = vim_time(); |
7 | 165 #endif |
166 } | |
167 | |
168 /* | |
169 * To change context, call setpcmark(), then move the current position to | |
170 * where ever, then call checkpcmark(). This ensures that the previous | |
171 * context will only be changed if the cursor moved to a different line. | |
172 * If pcmark was deleted (with "dG") the previous mark is restored. | |
173 */ | |
174 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
175 checkpcmark(void) |
7 | 176 { |
177 if (curwin->w_prev_pcmark.lnum != 0 | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10730
diff
changeset
|
178 && (EQUAL_POS(curwin->w_pcmark, curwin->w_cursor) |
7 | 179 || curwin->w_pcmark.lnum == 0)) |
180 curwin->w_pcmark = curwin->w_prev_pcmark; | |
25998
902aab6dc499
patch 8.2.3532: the previous '' mark is restored after moving the cursor
Bram Moolenaar <Bram@vim.org>
parents:
25384
diff
changeset
|
181 curwin->w_prev_pcmark.lnum = 0; // it has been checked |
7 | 182 } |
183 | |
184 /* | |
185 * move "count" positions in the jump list (count may be negative) | |
186 */ | |
187 pos_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
188 movemark(int count) |
7 | 189 { |
190 pos_T *pos; | |
191 xfmark_T *jmp; | |
192 | |
13278
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
193 cleanup_jumplist(curwin, TRUE); |
7 | 194 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
195 if (curwin->w_jumplistlen == 0) // nothing to jump to |
7 | 196 return (pos_T *)NULL; |
197 | |
198 for (;;) | |
199 { | |
200 if (curwin->w_jumplistidx + count < 0 | |
201 || curwin->w_jumplistidx + count >= curwin->w_jumplistlen) | |
202 return (pos_T *)NULL; | |
203 | |
204 /* | |
205 * if first CTRL-O or CTRL-I command after a jump, add cursor position | |
1188 | 206 * to list. Careful: If there are duplicates (CTRL-O immediately after |
7 | 207 * starting Vim on a file), another entry may have been removed. |
208 */ | |
209 if (curwin->w_jumplistidx == curwin->w_jumplistlen) | |
210 { | |
211 setpcmark(); | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
212 --curwin->w_jumplistidx; // skip the new entry |
7 | 213 if (curwin->w_jumplistidx + count < 0) |
214 return (pos_T *)NULL; | |
215 } | |
216 | |
217 curwin->w_jumplistidx += count; | |
218 | |
219 jmp = curwin->w_jumplist + curwin->w_jumplistidx; | |
220 if (jmp->fmark.fnum == 0) | |
221 fname2fnum(jmp); | |
222 if (jmp->fmark.fnum != curbuf->b_fnum) | |
223 { | |
30389
14c0d0c72bcd
patch 9.0.0530: using freed memory when autocmd changes mark
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
224 // Make a copy, an autocommand may make "jmp" invalid. |
14c0d0c72bcd
patch 9.0.0530: using freed memory when autocmd changes mark
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
225 fmark_T fmark = jmp->fmark; |
14c0d0c72bcd
patch 9.0.0530: using freed memory when autocmd changes mark
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
226 |
14c0d0c72bcd
patch 9.0.0530: using freed memory when autocmd changes mark
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
227 // jump to the file with the mark |
14c0d0c72bcd
patch 9.0.0530: using freed memory when autocmd changes mark
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
228 if (buflist_findnr(fmark.fnum) == NULL) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
229 { // Skip this one .. |
7 | 230 count += count < 0 ? -1 : 1; |
231 continue; | |
232 } | |
30389
14c0d0c72bcd
patch 9.0.0530: using freed memory when autocmd changes mark
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
233 if (buflist_getfile(fmark.fnum, fmark.mark.lnum, 0, FALSE) == FAIL) |
7 | 234 return (pos_T *)NULL; |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
235 // Set lnum again, autocommands my have changed it |
30389
14c0d0c72bcd
patch 9.0.0530: using freed memory when autocmd changes mark
Bram Moolenaar <Bram@vim.org>
parents:
29239
diff
changeset
|
236 curwin->w_cursor = fmark.mark; |
7 | 237 pos = (pos_T *)-1; |
238 } | |
239 else | |
240 pos = &(jmp->fmark.mark); | |
241 return pos; | |
242 } | |
243 } | |
244 | |
245 /* | |
246 * Move "count" positions in the changelist (count may be negative). | |
247 */ | |
248 pos_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
249 movechangelist(int count) |
7 | 250 { |
251 int n; | |
252 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
253 if (curbuf->b_changelistlen == 0) // nothing to jump to |
7 | 254 return (pos_T *)NULL; |
255 | |
256 n = curwin->w_changelistidx; | |
257 if (n + count < 0) | |
258 { | |
259 if (n == 0) | |
260 return (pos_T *)NULL; | |
261 n = 0; | |
262 } | |
263 else if (n + count >= curbuf->b_changelistlen) | |
264 { | |
265 if (n == curbuf->b_changelistlen - 1) | |
266 return (pos_T *)NULL; | |
267 n = curbuf->b_changelistlen - 1; | |
268 } | |
269 else | |
270 n += count; | |
271 curwin->w_changelistidx = n; | |
272 return curbuf->b_changelist + n; | |
273 } | |
274 | |
275 /* | |
4043 | 276 * Find mark "c" in buffer pointed to by "buf". |
706 | 277 * If "changefile" is TRUE it's allowed to edit another file for '0, 'A, etc. |
278 * If "fnum" is not NULL store the fnum there for '0, 'A etc., don't edit | |
279 * another file. | |
7 | 280 * Returns: |
281 * - pointer to pos_T if found. lnum is 0 when mark not set, -1 when mark is | |
282 * in another file which can't be gotten. (caller needs to check lnum!) | |
283 * - NULL if there is no mark called 'c'. | |
284 * - -1 if mark is in other file and jumped there (only if changefile is TRUE) | |
285 */ | |
286 pos_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
287 getmark_buf(buf_T *buf, int c, int changefile) |
4043 | 288 { |
289 return getmark_buf_fnum(buf, c, changefile, NULL); | |
290 } | |
291 | |
292 pos_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
293 getmark(int c, int changefile) |
706 | 294 { |
4043 | 295 return getmark_buf_fnum(curbuf, c, changefile, NULL); |
706 | 296 } |
297 | |
298 pos_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
299 getmark_buf_fnum( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
300 buf_T *buf, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
301 int c, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
302 int changefile, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
303 int *fnum) |
7 | 304 { |
305 pos_T *posp; | |
306 pos_T *startp, *endp; | |
307 static pos_T pos_copy; | |
308 | |
309 posp = NULL; | |
310 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
311 // Check for special key, can't be a mark name and might cause islower() |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
312 // to crash. |
7 | 313 if (c < 0) |
314 return posp; | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
315 if (c > '~') // check for islower()/isupper() |
7 | 316 ; |
27490
fb4c30606b4a
patch 8.2.4273: the EBCDIC support is outdated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
317 else if (c == '\'' || c == '`') // previous context mark |
7 | 318 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
319 pos_copy = curwin->w_pcmark; // need to make a copy because |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
320 posp = &pos_copy; // w_pcmark may be changed soon |
7 | 321 } |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
322 else if (c == '"') // to pos when leaving buffer |
4043 | 323 posp = &(buf->b_last_cursor); |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
324 else if (c == '^') // to where Insert mode stopped |
4043 | 325 posp = &(buf->b_last_insert); |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
326 else if (c == '.') // to where last change was made |
4043 | 327 posp = &(buf->b_last_change); |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
328 else if (c == '[') // to start of previous operator |
4043 | 329 posp = &(buf->b_op_start); |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
330 else if (c == ']') // to end of previous operator |
4043 | 331 posp = &(buf->b_op_end); |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
332 else if (c == '{' || c == '}') // to previous/next paragraph |
7 | 333 { |
334 pos_T pos; | |
335 oparg_T oa; | |
336 int slcb = listcmd_busy; | |
337 | |
338 pos = curwin->w_cursor; | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
339 listcmd_busy = TRUE; // avoid that '' is changed |
503 | 340 if (findpar(&oa.inclusive, |
341 c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE)) | |
7 | 342 { |
343 pos_copy = curwin->w_cursor; | |
344 posp = &pos_copy; | |
345 } | |
346 curwin->w_cursor = pos; | |
347 listcmd_busy = slcb; | |
348 } | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
349 else if (c == '(' || c == ')') // to previous/next sentence |
7 | 350 { |
351 pos_T pos; | |
352 int slcb = listcmd_busy; | |
353 | |
354 pos = curwin->w_cursor; | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
355 listcmd_busy = TRUE; // avoid that '' is changed |
7 | 356 if (findsent(c == ')' ? FORWARD : BACKWARD, 1L)) |
357 { | |
358 pos_copy = curwin->w_cursor; | |
359 posp = &pos_copy; | |
360 } | |
361 curwin->w_cursor = pos; | |
362 listcmd_busy = slcb; | |
363 } | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
364 else if (c == '<' || c == '>') // start/end of visual area |
7 | 365 { |
4043 | 366 startp = &buf->b_visual.vi_start; |
367 endp = &buf->b_visual.vi_end; | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10730
diff
changeset
|
368 if (((c == '<') == LT_POS(*startp, *endp) || endp->lnum == 0) |
10730
44e9340dc604
patch 8.0.0255: setpos() does not use the buffer argument for all marks
Christian Brabandt <cb@256bit.org>
parents:
10285
diff
changeset
|
369 && startp->lnum != 0) |
7 | 370 posp = startp; |
371 else | |
372 posp = endp; | |
373 /* | |
374 * For Visual line mode, set mark at begin or end of line | |
375 */ | |
4043 | 376 if (buf->b_visual.vi_mode == 'V') |
7 | 377 { |
378 pos_copy = *posp; | |
379 posp = &pos_copy; | |
380 if (c == '<') | |
381 pos_copy.col = 0; | |
382 else | |
383 pos_copy.col = MAXCOL; | |
384 pos_copy.coladd = 0; | |
385 } | |
386 } | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
387 else if (ASCII_ISLOWER(c)) // normal named mark |
7 | 388 { |
4043 | 389 posp = &(buf->b_namedm[c - 'a']); |
7 | 390 } |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
391 else if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c)) // named file mark |
7 | 392 { |
393 if (VIM_ISDIGIT(c)) | |
394 c = c - '0' + NMARKS; | |
395 else | |
396 c -= 'A'; | |
397 posp = &(namedfm[c].fmark.mark); | |
398 | |
399 if (namedfm[c].fmark.fnum == 0) | |
400 fname2fnum(&namedfm[c]); | |
706 | 401 |
402 if (fnum != NULL) | |
403 *fnum = namedfm[c].fmark.fnum; | |
4043 | 404 else if (namedfm[c].fmark.fnum != buf->b_fnum) |
7 | 405 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
406 // mark is in another file |
7 | 407 posp = &pos_copy; |
408 | |
409 if (namedfm[c].fmark.mark.lnum != 0 | |
410 && changefile && namedfm[c].fmark.fnum) | |
411 { | |
412 if (buflist_getfile(namedfm[c].fmark.fnum, | |
413 (linenr_T)1, GETF_SETMARK, FALSE) == OK) | |
414 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
415 // Set the lnum now, autocommands could have changed it |
7 | 416 curwin->w_cursor = namedfm[c].fmark.mark; |
417 return (pos_T *)-1; | |
418 } | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
419 pos_copy.lnum = -1; // can't get file |
7 | 420 } |
421 else | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
422 pos_copy.lnum = 0; // mark exists, but is not valid in |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
423 // current buffer |
7 | 424 } |
425 } | |
426 | |
427 return posp; | |
428 } | |
429 | |
430 /* | |
431 * Search for the next named mark in the current file. | |
432 * | |
433 * Returns pointer to pos_T of the next mark or NULL if no mark is found. | |
434 */ | |
435 pos_T * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
436 getnextmark( |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
437 pos_T *startpos, // where to start |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
438 int dir, // direction for search |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
439 int begin_line) |
7 | 440 { |
441 int i; | |
442 pos_T *result = NULL; | |
443 pos_T pos; | |
444 | |
445 pos = *startpos; | |
446 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
447 // When searching backward and leaving the cursor on the first non-blank, |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
448 // position must be in a previous line. |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
449 // When searching forward and leaving the cursor on the first non-blank, |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
450 // position must be in a next line. |
7 | 451 if (dir == BACKWARD && begin_line) |
452 pos.col = 0; | |
453 else if (dir == FORWARD && begin_line) | |
454 pos.col = MAXCOL; | |
455 | |
456 for (i = 0; i < NMARKS; i++) | |
457 { | |
458 if (curbuf->b_namedm[i].lnum > 0) | |
459 { | |
460 if (dir == FORWARD) | |
461 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10730
diff
changeset
|
462 if ((result == NULL || LT_POS(curbuf->b_namedm[i], *result)) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10730
diff
changeset
|
463 && LT_POS(pos, curbuf->b_namedm[i])) |
7 | 464 result = &curbuf->b_namedm[i]; |
465 } | |
466 else | |
467 { | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10730
diff
changeset
|
468 if ((result == NULL || LT_POS(*result, curbuf->b_namedm[i])) |
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10730
diff
changeset
|
469 && LT_POS(curbuf->b_namedm[i], pos)) |
7 | 470 result = &curbuf->b_namedm[i]; |
471 } | |
472 } | |
473 } | |
474 | |
475 return result; | |
476 } | |
477 | |
478 /* | |
479 * For an xtended filemark: set the fnum from the fname. | |
480 * This is used for marks obtained from the .viminfo file. It's postponed | |
481 * until the mark is used to avoid a long startup delay. | |
482 */ | |
17789
0f7ae8010787
patch 8.1.1891: functions used in one file are global
Bram Moolenaar <Bram@vim.org>
parents:
17464
diff
changeset
|
483 static void |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
484 fname2fnum(xfmark_T *fm) |
7 | 485 { |
486 char_u *p; | |
487 | |
488 if (fm->fname != NULL) | |
489 { | |
490 /* | |
491 * First expand "~/" in the file name to the home directory. | |
1480 | 492 * Don't expand the whole name, it may contain other '~' chars. |
7 | 493 */ |
1480 | 494 if (fm->fname[0] == '~' && (fm->fname[1] == '/' |
495 #ifdef BACKSLASH_IN_FILENAME | |
496 || fm->fname[1] == '\\' | |
497 #endif | |
498 )) | |
499 { | |
500 int len; | |
501 | |
502 expand_env((char_u *)"~/", NameBuff, MAXPATHL); | |
1570 | 503 len = (int)STRLEN(NameBuff); |
1480 | 504 vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1); |
505 } | |
506 else | |
507 vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1); | |
508 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
509 // Try to shorten the file name. |
7 | 510 mch_dirname(IObuff, IOSIZE); |
511 p = shorten_fname(NameBuff, IObuff); | |
512 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
513 // buflist_new() will call fmarks_check_names() |
7 | 514 (void)buflist_new(NameBuff, p, (linenr_T)1, 0); |
515 } | |
516 } | |
517 | |
518 /* | |
519 * Check all file marks for a name that matches the file name in buf. | |
520 * May replace the name with an fnum. | |
521 * Used for marks that come from the .viminfo file. | |
522 */ | |
523 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
524 fmarks_check_names(buf_T *buf) |
7 | 525 { |
526 char_u *name; | |
527 int i; | |
528 win_T *wp; | |
529 | |
530 if (buf->b_ffname == NULL) | |
531 return; | |
532 | |
533 name = home_replace_save(buf, buf->b_ffname); | |
534 if (name == NULL) | |
535 return; | |
536 | |
537 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i) | |
538 fmarks_check_one(&namedfm[i], name, buf); | |
539 | |
540 FOR_ALL_WINDOWS(wp) | |
541 { | |
542 for (i = 0; i < wp->w_jumplistlen; ++i) | |
543 fmarks_check_one(&wp->w_jumplist[i], name, buf); | |
544 } | |
545 | |
546 vim_free(name); | |
547 } | |
548 | |
549 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
550 fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf) |
7 | 551 { |
552 if (fm->fmark.fnum == 0 | |
553 && fm->fname != NULL | |
554 && fnamecmp(name, fm->fname) == 0) | |
555 { | |
556 fm->fmark.fnum = buf->b_fnum; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
557 VIM_CLEAR(fm->fname); |
7 | 558 } |
559 } | |
560 | |
561 /* | |
562 * Check a if a position from a mark is valid. | |
563 * Give and error message and return FAIL if not. | |
564 */ | |
565 int | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
566 check_mark(pos_T *pos) |
7 | 567 { |
568 if (pos == NULL) | |
569 { | |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
25998
diff
changeset
|
570 emsg(_(e_unknown_mark)); |
7 | 571 return FAIL; |
572 } | |
573 if (pos->lnum <= 0) | |
574 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
575 // lnum is negative if mark is in another file can can't get that |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
576 // file, error message already give then. |
7 | 577 if (pos->lnum == 0) |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
23731
diff
changeset
|
578 emsg(_(e_mark_not_set)); |
7 | 579 return FAIL; |
580 } | |
581 if (pos->lnum > curbuf->b_ml.ml_line_count) | |
582 { | |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
23731
diff
changeset
|
583 emsg(_(e_mark_has_invalid_line_number)); |
7 | 584 return FAIL; |
585 } | |
586 return OK; | |
587 } | |
588 | |
589 /* | |
590 * clrallmarks() - clear all marks in the buffer 'buf' | |
591 * | |
592 * Used mainly when trashing the entire buffer during ":e" type commands | |
593 */ | |
594 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
595 clrallmarks(buf_T *buf) |
7 | 596 { |
597 static int i = -1; | |
598 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
599 if (i == -1) // first call ever: initialize |
7 | 600 for (i = 0; i < NMARKS + 1; i++) |
601 { | |
602 namedfm[i].fmark.mark.lnum = 0; | |
603 namedfm[i].fname = NULL; | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
604 #ifdef FEAT_VIMINFO |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
605 namedfm[i].time_set = 0; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
606 #endif |
7 | 607 } |
608 | |
609 for (i = 0; i < NMARKS; i++) | |
610 buf->b_namedm[i].lnum = 0; | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
611 buf->b_op_start.lnum = 0; // start/end op mark cleared |
7 | 612 buf->b_op_end.lnum = 0; |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
613 buf->b_last_cursor.lnum = 1; // '" mark cleared |
7 | 614 buf->b_last_cursor.col = 0; |
615 buf->b_last_cursor.coladd = 0; | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
616 buf->b_last_insert.lnum = 0; // '^ mark cleared |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
617 buf->b_last_change.lnum = 0; // '. mark cleared |
7 | 618 buf->b_changelistlen = 0; |
619 } | |
620 | |
621 /* | |
622 * Get name of file from a filemark. | |
623 * When it's in the current buffer, return the text at the mark. | |
624 * Returns an allocated string. | |
625 */ | |
626 char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
627 fm_getname(fmark_T *fmark, int lead_len) |
7 | 628 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
629 if (fmark->fnum == curbuf->b_fnum) // current buffer |
7 | 630 return mark_line(&(fmark->mark), lead_len); |
631 return buflist_nr2name(fmark->fnum, FALSE, TRUE); | |
632 } | |
633 | |
634 /* | |
635 * Return the line at mark "mp". Truncate to fit in window. | |
636 * The returned string has been allocated. | |
637 */ | |
638 static char_u * | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
639 mark_line(pos_T *mp, int lead_len) |
7 | 640 { |
641 char_u *s, *p; | |
642 int len; | |
643 | |
644 if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count) | |
645 return vim_strsave((char_u *)"-invalid-"); | |
14305
8a4c0ab88201
patch 8.1.0168: output of :marks is too short with multi-byte chars
Christian Brabandt <cb@256bit.org>
parents:
13278
diff
changeset
|
646 // Allow for up to 5 bytes per character. |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20635
diff
changeset
|
647 s = vim_strnsave(skipwhite(ml_get(mp->lnum)), Columns * 5); |
7 | 648 if (s == NULL) |
649 return NULL; | |
14305
8a4c0ab88201
patch 8.1.0168: output of :marks is too short with multi-byte chars
Christian Brabandt <cb@256bit.org>
parents:
13278
diff
changeset
|
650 // Truncate the line to fit it in the window. |
7 | 651 len = 0; |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
652 for (p = s; *p != NUL; MB_PTR_ADV(p)) |
7 | 653 { |
654 len += ptr2cells(p); | |
655 if (len >= Columns - lead_len) | |
656 break; | |
657 } | |
658 *p = NUL; | |
659 return s; | |
660 } | |
661 | |
662 /* | |
663 * print the marks | |
664 */ | |
665 void | |
18126
f89e2e720b5b
patch 8.1.2058: function for ex command is named inconsistently
Bram Moolenaar <Bram@vim.org>
parents:
17789
diff
changeset
|
666 ex_marks(exarg_T *eap) |
7 | 667 { |
668 char_u *arg = eap->arg; | |
669 int i; | |
670 char_u *name; | |
21403
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
671 pos_T *posp, *startp, *endp; |
7 | 672 |
673 if (arg != NULL && *arg == NUL) | |
674 arg = NULL; | |
675 | |
676 show_one_mark('\'', arg, &curwin->w_pcmark, NULL, TRUE); | |
677 for (i = 0; i < NMARKS; ++i) | |
678 show_one_mark(i + 'a', arg, &curbuf->b_namedm[i], NULL, TRUE); | |
679 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i) | |
680 { | |
681 if (namedfm[i].fmark.fnum != 0) | |
682 name = fm_getname(&namedfm[i].fmark, 15); | |
683 else | |
684 name = namedfm[i].fname; | |
685 if (name != NULL) | |
686 { | |
687 show_one_mark(i >= NMARKS ? i - NMARKS + '0' : i + 'A', | |
688 arg, &namedfm[i].fmark.mark, name, | |
689 namedfm[i].fmark.fnum == curbuf->b_fnum); | |
690 if (namedfm[i].fmark.fnum != 0) | |
691 vim_free(name); | |
692 } | |
693 } | |
694 show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE); | |
695 show_one_mark('[', arg, &curbuf->b_op_start, NULL, TRUE); | |
696 show_one_mark(']', arg, &curbuf->b_op_end, NULL, TRUE); | |
697 show_one_mark('^', arg, &curbuf->b_last_insert, NULL, TRUE); | |
698 show_one_mark('.', arg, &curbuf->b_last_change, NULL, TRUE); | |
21403
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
699 |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
700 // Show the marks as where they will jump to. |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
701 startp = &curbuf->b_visual.vi_start; |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
702 endp = &curbuf->b_visual.vi_end; |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
703 if ((LT_POS(*startp, *endp) || endp->lnum == 0) && startp->lnum != 0) |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
704 posp = startp; |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
705 else |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
706 posp = endp; |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
707 show_one_mark('<', arg, posp, NULL, TRUE); |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
708 show_one_mark('>', arg, posp == startp ? endp : startp, NULL, TRUE); |
d387121083a4
patch 8.2.1252: ":marks" may show '< and '> mixed up
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
709 |
7 | 710 show_one_mark(-1, arg, NULL, NULL, FALSE); |
711 } | |
712 | |
713 static void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
714 show_one_mark( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
715 int c, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
716 char_u *arg, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
717 pos_T *p, |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
718 char_u *name_arg, |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
719 int current) // in current file |
7 | 720 { |
721 static int did_title = FALSE; | |
722 int mustfree = FALSE; | |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
723 char_u *name = name_arg; |
7 | 724 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
725 if (c == -1) // finish up |
7 | 726 { |
727 if (did_title) | |
728 did_title = FALSE; | |
729 else | |
730 { | |
731 if (arg == NULL) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
732 msg(_("No marks set")); |
7 | 733 else |
26897
d02d40f0261c
patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
734 semsg(_(e_no_marks_matching_str), arg); |
7 | 735 } |
736 } | |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
737 // don't output anything if 'q' typed at --more-- prompt |
7 | 738 else if (!got_int |
739 && (arg == NULL || vim_strchr(arg, c) != NULL) | |
740 && p->lnum != 0) | |
741 { | |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
742 if (name == NULL && current) |
7 | 743 { |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
744 name = mark_line(p, 15); |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
745 mustfree = TRUE; |
7 | 746 } |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
747 if (!message_filtered(name)) |
7 | 748 { |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
749 if (!did_title) |
7 | 750 { |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
751 // Highlight title |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
752 msg_puts_title(_("\nmark line col file/text")); |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
753 did_title = TRUE; |
7 | 754 } |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
755 msg_putchar('\n'); |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
756 if (!got_int) |
7 | 757 { |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
758 sprintf((char *)IObuff, " %c %6ld %4d ", c, p->lnum, p->col); |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
759 msg_outtrans(IObuff); |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
760 if (name != NULL) |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
761 { |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
762 msg_outtrans_attr(name, current ? HL_ATTR(HLF_D) : 0); |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
763 } |
7 | 764 } |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
765 out_flush(); // show one line at a time |
7 | 766 } |
16433
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
767 if (mustfree) |
9c206a78ec04
patch 8.1.1221: filtering does not work when listing marks
Bram Moolenaar <Bram@vim.org>
parents:
15651
diff
changeset
|
768 vim_free(name); |
7 | 769 } |
770 } | |
771 | |
24 | 772 /* |
773 * ":delmarks[!] [marks]" | |
774 */ | |
775 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
776 ex_delmarks(exarg_T *eap) |
24 | 777 { |
778 char_u *p; | |
779 int from, to; | |
780 int i; | |
781 int lower; | |
782 int digit; | |
783 int n; | |
784 | |
785 if (*eap->arg == NUL && eap->forceit) | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
786 // clear all marks |
24 | 787 clrallmarks(curbuf); |
788 else if (eap->forceit) | |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
789 emsg(_(e_invalid_argument)); |
24 | 790 else if (*eap->arg == NUL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
791 emsg(_(e_argument_required)); |
24 | 792 else |
793 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
794 // clear specified marks only |
24 | 795 for (p = eap->arg; *p != NUL; ++p) |
796 { | |
797 lower = ASCII_ISLOWER(*p); | |
798 digit = VIM_ISDIGIT(*p); | |
799 if (lower || digit || ASCII_ISUPPER(*p)) | |
800 { | |
801 if (p[1] == '-') | |
802 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
803 // clear range of marks |
24 | 804 from = *p; |
805 to = p[2]; | |
806 if (!(lower ? ASCII_ISLOWER(p[2]) | |
807 : (digit ? VIM_ISDIGIT(p[2]) | |
808 : ASCII_ISUPPER(p[2]))) | |
809 || to < from) | |
810 { | |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
811 semsg(_(e_invalid_argument_str), p); |
24 | 812 return; |
813 } | |
814 p += 2; | |
815 } | |
816 else | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
817 // clear one lower case mark |
24 | 818 from = to = *p; |
819 | |
820 for (i = from; i <= to; ++i) | |
821 { | |
822 if (lower) | |
823 curbuf->b_namedm[i - 'a'].lnum = 0; | |
824 else | |
825 { | |
826 if (digit) | |
827 n = i - '0' + NMARKS; | |
828 else | |
829 n = i - 'A'; | |
830 namedfm[n].fmark.mark.lnum = 0; | |
18979
de2d1820215a
patch 8.2.0050: after deleting a file mark it is still in viminfo
Bram Moolenaar <Bram@vim.org>
parents:
18800
diff
changeset
|
831 namedfm[n].fmark.fnum = 0; |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
832 VIM_CLEAR(namedfm[n].fname); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
833 #ifdef FEAT_VIMINFO |
18979
de2d1820215a
patch 8.2.0050: after deleting a file mark it is still in viminfo
Bram Moolenaar <Bram@vim.org>
parents:
18800
diff
changeset
|
834 namedfm[n].time_set = digit ? 0 : vim_time(); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
835 #endif |
24 | 836 } |
837 } | |
838 } | |
839 else | |
840 switch (*p) | |
841 { | |
842 case '"': curbuf->b_last_cursor.lnum = 0; break; | |
843 case '^': curbuf->b_last_insert.lnum = 0; break; | |
844 case '.': curbuf->b_last_change.lnum = 0; break; | |
845 case '[': curbuf->b_op_start.lnum = 0; break; | |
846 case ']': curbuf->b_op_end.lnum = 0; break; | |
690 | 847 case '<': curbuf->b_visual.vi_start.lnum = 0; break; |
848 case '>': curbuf->b_visual.vi_end.lnum = 0; break; | |
24 | 849 case ' ': break; |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26532
diff
changeset
|
850 default: semsg(_(e_invalid_argument_str), p); |
24 | 851 return; |
852 } | |
853 } | |
854 } | |
855 } | |
856 | |
7 | 857 /* |
858 * print the jumplist | |
859 */ | |
860 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
861 ex_jumps(exarg_T *eap UNUSED) |
7 | 862 { |
863 int i; | |
864 char_u *name; | |
865 | |
13278
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
866 cleanup_jumplist(curwin, TRUE); |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
867 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
868 // Highlight title |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
869 msg_puts_title(_("\n jump line col file/text")); |
7 | 870 for (i = 0; i < curwin->w_jumplistlen && !got_int; ++i) |
871 { | |
872 if (curwin->w_jumplist[i].fmark.mark.lnum != 0) | |
873 { | |
874 name = fm_getname(&curwin->w_jumplist[i].fmark, 16); | |
14968
c5ec5ddbe814
patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents:
14305
diff
changeset
|
875 |
28388
320991d9812e
patch 8.2.4719: ">" marker sometimes not displayed in the jumplist
Bram Moolenaar <Bram@vim.org>
parents:
28247
diff
changeset
|
876 // Make sure to output the current indicator, even when on an wiped |
320991d9812e
patch 8.2.4719: ">" marker sometimes not displayed in the jumplist
Bram Moolenaar <Bram@vim.org>
parents:
28247
diff
changeset
|
877 // out buffer. ":filter" may still skip it. |
320991d9812e
patch 8.2.4719: ">" marker sometimes not displayed in the jumplist
Bram Moolenaar <Bram@vim.org>
parents:
28247
diff
changeset
|
878 if (name == NULL && i == curwin->w_jumplistidx) |
320991d9812e
patch 8.2.4719: ">" marker sometimes not displayed in the jumplist
Bram Moolenaar <Bram@vim.org>
parents:
28247
diff
changeset
|
879 name = vim_strsave((char_u *)"-invalid-"); |
14968
c5ec5ddbe814
patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents:
14305
diff
changeset
|
880 // apply :filter /pat/ or file name not available |
c5ec5ddbe814
patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents:
14305
diff
changeset
|
881 if (name == NULL || message_filtered(name)) |
15651
dd4e6f077874
patch 8.1.0833: memory leak when jumps output is filtered
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
882 { |
dd4e6f077874
patch 8.1.0833: memory leak when jumps output is filtered
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
883 vim_free(name); |
7 | 884 continue; |
15651
dd4e6f077874
patch 8.1.0833: memory leak when jumps output is filtered
Bram Moolenaar <Bram@vim.org>
parents:
15636
diff
changeset
|
885 } |
7 | 886 |
887 msg_putchar('\n'); | |
888 if (got_int) | |
1702 | 889 { |
890 vim_free(name); | |
7 | 891 break; |
1702 | 892 } |
7 | 893 sprintf((char *)IObuff, "%c %2d %5ld %4d ", |
894 i == curwin->w_jumplistidx ? '>' : ' ', | |
895 i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx | |
896 : curwin->w_jumplistidx - i, | |
897 curwin->w_jumplist[i].fmark.mark.lnum, | |
898 curwin->w_jumplist[i].fmark.mark.col); | |
899 msg_outtrans(IObuff); | |
900 msg_outtrans_attr(name, | |
901 curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11140
diff
changeset
|
902 ? HL_ATTR(HLF_D) : 0); |
7 | 903 vim_free(name); |
904 ui_breakcheck(); | |
905 } | |
906 out_flush(); | |
907 } | |
908 if (curwin->w_jumplistidx == curwin->w_jumplistlen) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
909 msg_puts("\n>"); |
7 | 910 } |
911 | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
912 void |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
913 ex_clearjumps(exarg_T *eap UNUSED) |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
914 { |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
915 free_jumplist(curwin); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
916 curwin->w_jumplistlen = 0; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
917 curwin->w_jumplistidx = 0; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
918 } |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
919 |
7 | 920 /* |
921 * print the changelist | |
922 */ | |
923 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
924 ex_changes(exarg_T *eap UNUSED) |
7 | 925 { |
926 int i; | |
927 char_u *name; | |
928 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
929 // Highlight title |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
930 msg_puts_title(_("\nchange line col text")); |
7 | 931 |
932 for (i = 0; i < curbuf->b_changelistlen && !got_int; ++i) | |
933 { | |
934 if (curbuf->b_changelist[i].lnum != 0) | |
935 { | |
936 msg_putchar('\n'); | |
937 if (got_int) | |
938 break; | |
939 sprintf((char *)IObuff, "%c %3d %5ld %4d ", | |
940 i == curwin->w_changelistidx ? '>' : ' ', | |
941 i > curwin->w_changelistidx ? i - curwin->w_changelistidx | |
942 : curwin->w_changelistidx - i, | |
943 (long)curbuf->b_changelist[i].lnum, | |
944 curbuf->b_changelist[i].col); | |
945 msg_outtrans(IObuff); | |
946 name = mark_line(&curbuf->b_changelist[i], 17); | |
947 if (name == NULL) | |
948 break; | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11140
diff
changeset
|
949 msg_outtrans_attr(name, HL_ATTR(HLF_D)); |
7 | 950 vim_free(name); |
951 ui_breakcheck(); | |
952 } | |
953 out_flush(); | |
954 } | |
955 if (curwin->w_changelistidx == curbuf->b_changelistlen) | |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
956 msg_puts("\n>"); |
7 | 957 } |
958 | |
959 #define one_adjust(add) \ | |
960 { \ | |
961 lp = add; \ | |
962 if (*lp >= line1 && *lp <= line2) \ | |
963 { \ | |
964 if (amount == MAXLNUM) \ | |
965 *lp = 0; \ | |
966 else \ | |
967 *lp += amount; \ | |
968 } \ | |
969 else if (amount_after && *lp > line2) \ | |
970 *lp += amount_after; \ | |
971 } | |
972 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
973 // don't delete the line, just put at first deleted line |
7 | 974 #define one_adjust_nodel(add) \ |
975 { \ | |
976 lp = add; \ | |
977 if (*lp >= line1 && *lp <= line2) \ | |
978 { \ | |
979 if (amount == MAXLNUM) \ | |
980 *lp = line1; \ | |
981 else \ | |
982 *lp += amount; \ | |
983 } \ | |
984 else if (amount_after && *lp > line2) \ | |
985 *lp += amount_after; \ | |
986 } | |
987 | |
988 /* | |
989 * Adjust marks between line1 and line2 (inclusive) to move 'amount' lines. | |
990 * Must be called before changed_*(), appended_lines() or deleted_lines(). | |
991 * May be called before or after changing the text. | |
992 * When deleting lines line1 to line2, use an 'amount' of MAXLNUM: The marks | |
993 * within this range are made invalid. | |
994 * If 'amount_after' is non-zero adjust marks after line2. | |
995 * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2); | |
996 * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0); | |
997 * or: mark_adjust(56, 55, MAXLNUM, 2); | |
998 */ | |
999 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1000 mark_adjust( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1001 linenr_T line1, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1002 linenr_T line2, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1003 long amount, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1004 long amount_after) |
7 | 1005 { |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1006 mark_adjust_internal(line1, line2, amount, amount_after, TRUE); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1007 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1008 |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1009 void |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1010 mark_adjust_nofold( |
28247
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1011 linenr_T line1, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1012 linenr_T line2, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1013 long amount, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1014 long amount_after) |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1015 { |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1016 mark_adjust_internal(line1, line2, amount, amount_after, FALSE); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1017 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1018 |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1019 static void |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1020 mark_adjust_internal( |
28247
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1021 linenr_T line1, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1022 linenr_T line2, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1023 long amount, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1024 long amount_after, |
f70015784777
patch 8.2.4649: various formatting problems
Bram Moolenaar <Bram@vim.org>
parents:
27490
diff
changeset
|
1025 int adjust_folds UNUSED) |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1026 { |
7 | 1027 int i; |
1028 int fnum = curbuf->b_fnum; | |
1029 linenr_T *lp; | |
1030 win_T *win; | |
1863 | 1031 tabpage_T *tab; |
15636
6f1c7e9a6393
patch 8.1.0826: too many #ifdefs
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
1032 static pos_T initpos = {1, 0, 0}; |
7 | 1033 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1034 if (line2 < line1 && amount_after == 0L) // nothing to do |
7 | 1035 return; |
1036 | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
21403
diff
changeset
|
1037 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
7 | 1038 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1039 // named marks, lower case and upper case |
7 | 1040 for (i = 0; i < NMARKS; i++) |
1041 { | |
1042 one_adjust(&(curbuf->b_namedm[i].lnum)); | |
1043 if (namedfm[i].fmark.fnum == fnum) | |
1044 one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); | |
1045 } | |
1046 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++) | |
1047 { | |
1048 if (namedfm[i].fmark.fnum == fnum) | |
1049 one_adjust_nodel(&(namedfm[i].fmark.mark.lnum)); | |
1050 } | |
1051 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1052 // last Insert position |
7 | 1053 one_adjust(&(curbuf->b_last_insert.lnum)); |
1054 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1055 // last change position |
7 | 1056 one_adjust(&(curbuf->b_last_change.lnum)); |
1057 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1058 // last cursor position, if it was set |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10730
diff
changeset
|
1059 if (!EQUAL_POS(curbuf->b_last_cursor, initpos)) |
4092 | 1060 one_adjust(&(curbuf->b_last_cursor.lnum)); |
1061 | |
1062 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1063 // list of change positions |
7 | 1064 for (i = 0; i < curbuf->b_changelistlen; ++i) |
1065 one_adjust_nodel(&(curbuf->b_changelist[i].lnum)); | |
1066 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1067 // Visual area |
690 | 1068 one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); |
1069 one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); | |
7 | 1070 |
1071 #ifdef FEAT_QUICKFIX | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1072 // quickfix marks |
643 | 1073 qf_mark_adjust(NULL, line1, line2, amount, amount_after); |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1074 // location lists |
1863 | 1075 FOR_ALL_TAB_WINDOWS(tab, win) |
643 | 1076 qf_mark_adjust(win, line1, line2, amount, amount_after); |
7 | 1077 #endif |
1078 | |
1079 #ifdef FEAT_SIGNS | |
1080 sign_mark_adjust(line1, line2, amount, amount_after); | |
1081 #endif | |
1082 } | |
1083 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1084 // previous context mark |
7 | 1085 one_adjust(&(curwin->w_pcmark.lnum)); |
1086 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1087 // previous pcmark |
7 | 1088 one_adjust(&(curwin->w_prev_pcmark.lnum)); |
1089 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1090 // saved cursor for formatting |
7 | 1091 if (saved_cursor.lnum != 0) |
1092 one_adjust_nodel(&(saved_cursor.lnum)); | |
1093 | |
1094 /* | |
1095 * Adjust items in all windows related to the current buffer. | |
1096 */ | |
1863 | 1097 FOR_ALL_TAB_WINDOWS(tab, win) |
7 | 1098 { |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
21403
diff
changeset
|
1099 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1100 // Marks in the jumplist. When deleting lines, this may create |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1101 // duplicate marks in the jumplist, they will be removed later. |
7 | 1102 for (i = 0; i < win->w_jumplistlen; ++i) |
1103 if (win->w_jumplist[i].fmark.fnum == fnum) | |
1104 one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum)); | |
1105 | |
1106 if (win->w_buffer == curbuf) | |
1107 { | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
21403
diff
changeset
|
1108 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1109 // marks in the tag stack |
7 | 1110 for (i = 0; i < win->w_tagstacklen; i++) |
1111 if (win->w_tagstack[i].fmark.fnum == fnum) | |
1112 one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum)); | |
1113 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1114 // the displayed Visual area |
7 | 1115 if (win->w_old_cursor_lnum != 0) |
1116 { | |
1117 one_adjust_nodel(&(win->w_old_cursor_lnum)); | |
1118 one_adjust_nodel(&(win->w_old_visual_lnum)); | |
1119 } | |
1120 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1121 // topline and cursor position for windows with the same buffer |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1122 // other than the current window |
7 | 1123 if (win != curwin) |
1124 { | |
1125 if (win->w_topline >= line1 && win->w_topline <= line2) | |
1126 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1127 if (amount == MAXLNUM) // topline is deleted |
7 | 1128 { |
1129 if (line1 <= 1) | |
1130 win->w_topline = 1; | |
1131 else | |
1132 win->w_topline = line1 - 1; | |
1133 } | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1134 else // keep topline on the same line |
7 | 1135 win->w_topline += amount; |
1136 #ifdef FEAT_DIFF | |
1137 win->w_topfill = 0; | |
1138 #endif | |
1139 } | |
1140 else if (amount_after && win->w_topline > line2) | |
1141 { | |
1142 win->w_topline += amount_after; | |
1143 #ifdef FEAT_DIFF | |
1144 win->w_topfill = 0; | |
1145 #endif | |
1146 } | |
1147 if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2) | |
1148 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1149 if (amount == MAXLNUM) // line with cursor is deleted |
7 | 1150 { |
1151 if (line1 <= 1) | |
1152 win->w_cursor.lnum = 1; | |
1153 else | |
1154 win->w_cursor.lnum = line1 - 1; | |
1155 win->w_cursor.col = 0; | |
1156 } | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1157 else // keep cursor on the same line |
7 | 1158 win->w_cursor.lnum += amount; |
1159 } | |
1160 else if (amount_after && win->w_cursor.lnum > line2) | |
1161 win->w_cursor.lnum += amount_after; | |
1162 } | |
1163 | |
1164 #ifdef FEAT_FOLDING | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1165 // adjust folds |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1166 if (adjust_folds) |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
1167 foldMarkAdjust(win, line1, line2, amount, amount_after); |
7 | 1168 #endif |
1169 } | |
1170 } | |
1171 | |
1172 #ifdef FEAT_DIFF | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1173 // adjust diffs |
7 | 1174 diff_mark_adjust(line1, line2, amount, amount_after); |
1175 #endif | |
1176 } | |
1177 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1178 // This code is used often, needs to be fast. |
7 | 1179 #define col_adjust(pp) \ |
1180 { \ | |
1181 posp = pp; \ | |
1182 if (posp->lnum == lnum && posp->col >= mincol) \ | |
1183 { \ | |
1184 posp->lnum += lnum_amount; \ | |
1185 if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \ | |
1186 posp->col = 0; \ | |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
1187 else if (posp->col < spaces_removed) \ |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
1188 posp->col = col_amount + spaces_removed; \ |
7 | 1189 else \ |
1190 posp->col += col_amount; \ | |
1191 } \ | |
1192 } | |
1193 | |
1194 /* | |
1195 * Adjust marks in line "lnum" at column "mincol" and further: add | |
1196 * "lnum_amount" to the line number and add "col_amount" to the column | |
1197 * position. | |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
1198 * "spaces_removed" is the number of spaces that were removed, matters when the |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
1199 * cursor is inside them. |
7 | 1200 */ |
1201 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1202 mark_col_adjust( |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1203 linenr_T lnum, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1204 colnr_T mincol, |
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1205 long lnum_amount, |
15326
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
1206 long col_amount, |
fe428bee74b3
patch 8.1.0671: cursor in the wrong column after auto-formatting
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
1207 int spaces_removed) |
7 | 1208 { |
1209 int i; | |
1210 int fnum = curbuf->b_fnum; | |
1211 win_T *win; | |
1212 pos_T *posp; | |
1213 | |
22699
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
21403
diff
changeset
|
1214 if ((col_amount == 0L && lnum_amount == 0L) |
e82579016863
patch 8.2.1898: command modifier parsing always uses global cmdmod
Bram Moolenaar <Bram@vim.org>
parents:
21403
diff
changeset
|
1215 || (cmdmod.cmod_flags & CMOD_LOCKMARKS)) |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1216 return; // nothing to do |
7 | 1217 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1218 // named marks, lower case and upper case |
7 | 1219 for (i = 0; i < NMARKS; i++) |
1220 { | |
1221 col_adjust(&(curbuf->b_namedm[i])); | |
1222 if (namedfm[i].fmark.fnum == fnum) | |
1223 col_adjust(&(namedfm[i].fmark.mark)); | |
1224 } | |
1225 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++) | |
1226 { | |
1227 if (namedfm[i].fmark.fnum == fnum) | |
1228 col_adjust(&(namedfm[i].fmark.mark)); | |
1229 } | |
1230 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1231 // last Insert position |
7 | 1232 col_adjust(&(curbuf->b_last_insert)); |
1233 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1234 // last change position |
7 | 1235 col_adjust(&(curbuf->b_last_change)); |
1236 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1237 // list of change positions |
7 | 1238 for (i = 0; i < curbuf->b_changelistlen; ++i) |
1239 col_adjust(&(curbuf->b_changelist[i])); | |
1240 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1241 // Visual area |
690 | 1242 col_adjust(&(curbuf->b_visual.vi_start)); |
1243 col_adjust(&(curbuf->b_visual.vi_end)); | |
7 | 1244 |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1245 // previous context mark |
7 | 1246 col_adjust(&(curwin->w_pcmark)); |
1247 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1248 // previous pcmark |
7 | 1249 col_adjust(&(curwin->w_prev_pcmark)); |
1250 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1251 // saved cursor for formatting |
7 | 1252 col_adjust(&saved_cursor); |
1253 | |
1254 /* | |
1255 * Adjust items in all windows related to the current buffer. | |
1256 */ | |
1257 FOR_ALL_WINDOWS(win) | |
1258 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1259 // marks in the jumplist |
7 | 1260 for (i = 0; i < win->w_jumplistlen; ++i) |
1261 if (win->w_jumplist[i].fmark.fnum == fnum) | |
1262 col_adjust(&(win->w_jumplist[i].fmark.mark)); | |
1263 | |
1264 if (win->w_buffer == curbuf) | |
1265 { | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1266 // marks in the tag stack |
7 | 1267 for (i = 0; i < win->w_tagstacklen; i++) |
1268 if (win->w_tagstack[i].fmark.fnum == fnum) | |
1269 col_adjust(&(win->w_tagstack[i].fmark.mark)); | |
1270 | |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1271 // cursor position for other windows with the same buffer |
7 | 1272 if (win != curwin) |
1273 col_adjust(&win->w_cursor); | |
1274 } | |
1275 } | |
1276 } | |
1277 | |
1278 /* | |
1279 * When deleting lines, this may create duplicate marks in the | |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1280 * jumplist. They will be removed here for the specified window. |
13278
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1281 * When "loadfiles" is TRUE first ensure entries have the "fnum" field set |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1282 * (this may be a bit slow). |
7 | 1283 */ |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1284 void |
13278
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1285 cleanup_jumplist(win_T *wp, int loadfiles) |
7 | 1286 { |
1287 int i; | |
1288 int from, to; | |
1289 | |
13278
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1290 if (loadfiles) |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1291 { |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1292 // If specified, load all the files from the jump list. This is |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1293 // needed to properly clean up duplicate entries, but will take some |
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1294 // time. |
13278
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1295 for (i = 0; i < wp->w_jumplistlen; ++i) |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1296 { |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1297 if ((wp->w_jumplist[i].fmark.fnum == 0) && |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1298 (wp->w_jumplist[i].fmark.mark.lnum != 0)) |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1299 fname2fnum(&wp->w_jumplist[i]); |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1300 } |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1301 } |
28ae299c6af0
patch 8.0.1513: the jumplist is not always properly cleaned up
Christian Brabandt <cb@256bit.org>
parents:
13248
diff
changeset
|
1302 |
7 | 1303 to = 0; |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1304 for (from = 0; from < wp->w_jumplistlen; ++from) |
7 | 1305 { |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1306 if (wp->w_jumplistidx == from) |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1307 wp->w_jumplistidx = to; |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1308 for (i = from + 1; i < wp->w_jumplistlen; ++i) |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1309 if (wp->w_jumplist[i].fmark.fnum |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1310 == wp->w_jumplist[from].fmark.fnum |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1311 && wp->w_jumplist[from].fmark.fnum != 0 |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1312 && wp->w_jumplist[i].fmark.mark.lnum |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1313 == wp->w_jumplist[from].fmark.mark.lnum) |
7 | 1314 break; |
18800
f41b55f9357c
patch 8.1.2388: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18126
diff
changeset
|
1315 if (i >= wp->w_jumplistlen) // no duplicate |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1316 wp->w_jumplist[to++] = wp->w_jumplist[from]; |
7 | 1317 else |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1318 vim_free(wp->w_jumplist[from].fname); |
7 | 1319 } |
13248
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1320 if (wp->w_jumplistidx == wp->w_jumplistlen) |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1321 wp->w_jumplistidx = to; |
5958573d8a72
patch 8.0.1498: getjumplist() returns duplicate entries
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
1322 wp->w_jumplistlen = to; |
7 | 1323 } |
1324 | |
1325 /* | |
1326 * Copy the jumplist from window "from" to window "to". | |
1327 */ | |
1328 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1329 copy_jumplist(win_T *from, win_T *to) |
7 | 1330 { |
1331 int i; | |
1332 | |
1333 for (i = 0; i < from->w_jumplistlen; ++i) | |
1334 { | |
1335 to->w_jumplist[i] = from->w_jumplist[i]; | |
1336 if (from->w_jumplist[i].fname != NULL) | |
1337 to->w_jumplist[i].fname = vim_strsave(from->w_jumplist[i].fname); | |
1338 } | |
1339 to->w_jumplistlen = from->w_jumplistlen; | |
1340 to->w_jumplistidx = from->w_jumplistidx; | |
1341 } | |
1342 | |
1343 /* | |
1344 * Free items in the jumplist of window "wp". | |
1345 */ | |
1346 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1347 free_jumplist(win_T *wp) |
7 | 1348 { |
1349 int i; | |
1350 | |
1351 for (i = 0; i < wp->w_jumplistlen; ++i) | |
1352 vim_free(wp->w_jumplist[i].fname); | |
1353 } | |
1354 | |
1355 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1356 set_last_cursor(win_T *win) |
7 | 1357 { |
5417 | 1358 if (win->w_buffer != NULL) |
1359 win->w_buffer->b_last_cursor = win->w_cursor; | |
7 | 1360 } |
1361 | |
358 | 1362 #if defined(EXITFREE) || defined(PROTO) |
1363 void | |
7827
41789f16d6b2
commit https://github.com/vim/vim/commit/52ea13da0fe86df1abf34de52841e367035170c0
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1364 free_all_marks(void) |
358 | 1365 { |
1366 int i; | |
1367 | |
1368 for (i = 0; i < NMARKS + EXTRA_MARKS; i++) | |
1369 if (namedfm[i].fmark.mark.lnum != 0) | |
1370 vim_free(namedfm[i].fname); | |
1371 } | |
1372 #endif | |
1373 | |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
1374 #if defined(FEAT_VIMINFO) || defined(PROTO) |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
1375 /* |
17464
3e708b5c0509
patch 8.1.1730: wrong place for mark viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1376 * Return a pointer to the named file marks. |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
7827
diff
changeset
|
1377 */ |
17464
3e708b5c0509
patch 8.1.1730: wrong place for mark viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1378 xfmark_T * |
3e708b5c0509
patch 8.1.1730: wrong place for mark viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1379 get_namedfm(void) |
7 | 1380 { |
17464
3e708b5c0509
patch 8.1.1730: wrong place for mark viminfo support
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
1381 return namedfm; |
7 | 1382 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
1383 #endif |
20615
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1384 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1385 #if defined(FEAT_EVAL) || defined(PROTO) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1386 /* |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1387 * Add information about mark 'mname' to list 'l' |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1388 */ |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1389 static int |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1390 add_mark(list_T *l, char_u *mname, pos_T *pos, int bufnr, char_u *fname) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1391 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1392 dict_T *d; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1393 list_T *lpos; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1394 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1395 if (pos->lnum <= 0) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1396 return OK; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1397 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1398 d = dict_alloc(); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1399 if (d == NULL) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1400 return FAIL; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1401 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1402 if (list_append_dict(l, d) == FAIL) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1403 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1404 dict_unref(d); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1405 return FAIL; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1406 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1407 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1408 lpos = list_alloc(); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1409 if (lpos == NULL) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1410 return FAIL; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1411 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1412 list_append_number(lpos, bufnr); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1413 list_append_number(lpos, pos->lnum); |
20635
3e36a51ff152
patch 8.2.0871: cannot use getmarklist() as a method
Bram Moolenaar <Bram@vim.org>
parents:
20615
diff
changeset
|
1414 list_append_number(lpos, pos->col + 1); |
20615
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1415 list_append_number(lpos, pos->coladd); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1416 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1417 if (dict_add_string(d, "mark", mname) == FAIL |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1418 || dict_add_list(d, "pos", lpos) == FAIL |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1419 || (fname != NULL && dict_add_string(d, "file", fname) == FAIL)) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1420 return FAIL; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1421 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1422 return OK; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1423 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1424 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1425 /* |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1426 * Get information about marks local to a buffer. |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1427 */ |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1428 static void |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1429 get_buf_local_marks(buf_T *buf, list_T *l) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1430 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1431 char_u mname[3] = "' "; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1432 int i; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1433 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1434 // Marks 'a' to 'z' |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1435 for (i = 0; i < NMARKS; ++i) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1436 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1437 mname[1] = 'a' + i; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1438 add_mark(l, mname, &buf->b_namedm[i], buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1439 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1440 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1441 // Mark '' is a window local mark and not a buffer local mark |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1442 add_mark(l, (char_u *)"''", &curwin->w_pcmark, curbuf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1443 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1444 add_mark(l, (char_u *)"'\"", &buf->b_last_cursor, buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1445 add_mark(l, (char_u *)"'[", &buf->b_op_start, buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1446 add_mark(l, (char_u *)"']", &buf->b_op_end, buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1447 add_mark(l, (char_u *)"'^", &buf->b_last_insert, buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1448 add_mark(l, (char_u *)"'.", &buf->b_last_change, buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1449 add_mark(l, (char_u *)"'<", &buf->b_visual.vi_start, buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1450 add_mark(l, (char_u *)"'>", &buf->b_visual.vi_end, buf->b_fnum, NULL); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1451 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1452 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1453 /* |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1454 * Get information about global marks ('A' to 'Z' and '0' to '9') |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1455 */ |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1456 static void |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1457 get_global_marks(list_T *l) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1458 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1459 char_u mname[3] = "' "; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1460 int i; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1461 char_u *name; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1462 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1463 // Marks 'A' to 'Z' and '0' to '9' |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1464 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1465 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1466 if (namedfm[i].fmark.fnum != 0) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1467 name = buflist_nr2name(namedfm[i].fmark.fnum, TRUE, TRUE); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1468 else |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1469 name = namedfm[i].fname; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1470 if (name != NULL) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1471 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1472 mname[1] = i >= NMARKS ? i - NMARKS + '0' : i + 'A'; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1473 add_mark(l, mname, &namedfm[i].fmark.mark, |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1474 namedfm[i].fmark.fnum, name); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1475 if (namedfm[i].fmark.fnum != 0) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1476 vim_free(name); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1477 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1478 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1479 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1480 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1481 /* |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1482 * getmarklist() function |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1483 */ |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1484 void |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1485 f_getmarklist(typval_T *argvars, typval_T *rettv) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1486 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1487 buf_T *buf = NULL; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1488 |
29239
da56650de132
patch 8.2.5138: various small issues
Bram Moolenaar <Bram@vim.org>
parents:
28388
diff
changeset
|
1489 if (rettv_list_alloc(rettv) == FAIL) |
20615
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1490 return; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1491 |
25384
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1492 if (in_vim9script() && check_for_opt_buffer_arg(argvars, 0) == FAIL) |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1493 return; |
e8e2c4d33b9b
patch 8.2.3229: Vim9: runtime and compile time type checks are not the same
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
1494 |
20615
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1495 if (argvars[0].v_type == VAR_UNKNOWN) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1496 { |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1497 get_global_marks(rettv->vval.v_list); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1498 return; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1499 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1500 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1501 buf = tv_get_buf(&argvars[0], FALSE); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1502 if (buf == NULL) |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1503 return; |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1504 |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1505 get_buf_local_marks(buf, rettv->vval.v_list); |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1506 } |
8eed1e9389bb
patch 8.2.0861: cannot easily get all the current marks
Bram Moolenaar <Bram@vim.org>
parents:
18979
diff
changeset
|
1507 #endif |