comparison src/mark.c @ 26532:255bc9a08e58 v8.2.3795

patch 8.2.3795: too many #ifdefs Commit: https://github.com/vim/vim/commit/739f13a55b4982efb37ebc9282e7f79975fff982 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Dec 13 13:12:53 2021 +0000 patch 8.2.3795: too many #ifdefs Problem: Too many #ifdefs. Solution: Graduate the jumplist feature.
author Bram Moolenaar <Bram@vim.org>
date Mon, 13 Dec 2021 14:15:03 +0100
parents b18f3b0f317c
children bce848ec8b1b
comparison
equal deleted inserted replaced
26531:b8398b0fb0ed 26532:255bc9a08e58
134 * jump list. 134 * jump list.
135 */ 135 */
136 void 136 void
137 setpcmark(void) 137 setpcmark(void)
138 { 138 {
139 #ifdef FEAT_JUMPLIST
140 int i; 139 int i;
141 xfmark_T *fm; 140 xfmark_T *fm;
142 #endif
143 141
144 // for :global the mark is set only once 142 // for :global the mark is set only once
145 if (global_busy || listcmd_busy || (cmdmod.cmod_flags & CMOD_KEEPJUMPS)) 143 if (global_busy || listcmd_busy || (cmdmod.cmod_flags & CMOD_KEEPJUMPS))
146 return; 144 return;
147 145
148 curwin->w_prev_pcmark = curwin->w_pcmark; 146 curwin->w_prev_pcmark = curwin->w_pcmark;
149 curwin->w_pcmark = curwin->w_cursor; 147 curwin->w_pcmark = curwin->w_cursor;
150 148
151 #ifdef FEAT_JUMPLIST
152 // If jumplist is full: remove oldest entry 149 // If jumplist is full: remove oldest entry
153 if (++curwin->w_jumplistlen > JUMPLISTSIZE) 150 if (++curwin->w_jumplistlen > JUMPLISTSIZE)
154 { 151 {
155 curwin->w_jumplistlen = JUMPLISTSIZE; 152 curwin->w_jumplistlen = JUMPLISTSIZE;
156 vim_free(curwin->w_jumplist[0].fname); 153 vim_free(curwin->w_jumplist[0].fname);
161 fm = &curwin->w_jumplist[curwin->w_jumplistlen - 1]; 158 fm = &curwin->w_jumplist[curwin->w_jumplistlen - 1];
162 159
163 fm->fmark.mark = curwin->w_pcmark; 160 fm->fmark.mark = curwin->w_pcmark;
164 fm->fmark.fnum = curbuf->b_fnum; 161 fm->fmark.fnum = curbuf->b_fnum;
165 fm->fname = NULL; 162 fm->fname = NULL;
166 # ifdef FEAT_VIMINFO 163 #ifdef FEAT_VIMINFO
167 fm->time_set = vim_time(); 164 fm->time_set = vim_time();
168 # endif
169 #endif 165 #endif
170 } 166 }
171 167
172 /* 168 /*
173 * To change context, call setpcmark(), then move the current position to 169 * To change context, call setpcmark(), then move the current position to
183 || curwin->w_pcmark.lnum == 0)) 179 || curwin->w_pcmark.lnum == 0))
184 curwin->w_pcmark = curwin->w_prev_pcmark; 180 curwin->w_pcmark = curwin->w_prev_pcmark;
185 curwin->w_prev_pcmark.lnum = 0; // it has been checked 181 curwin->w_prev_pcmark.lnum = 0; // it has been checked
186 } 182 }
187 183
188 #if defined(FEAT_JUMPLIST) || defined(PROTO)
189 /* 184 /*
190 * move "count" positions in the jump list (count may be negative) 185 * move "count" positions in the jump list (count may be negative)
191 */ 186 */
192 pos_T * 187 pos_T *
193 movemark(int count) 188 movemark(int count)
272 else 267 else
273 n += count; 268 n += count;
274 curwin->w_changelistidx = n; 269 curwin->w_changelistidx = n;
275 return curbuf->b_changelist + n; 270 return curbuf->b_changelist + n;
276 } 271 }
277 #endif
278 272
279 /* 273 /*
280 * Find mark "c" in buffer pointed to by "buf". 274 * Find mark "c" in buffer pointed to by "buf".
281 * If "changefile" is TRUE it's allowed to edit another file for '0, 'A, etc. 275 * If "changefile" is TRUE it's allowed to edit another file for '0, 'A, etc.
282 * If "fnum" is not NULL store the fnum there for '0, 'A etc., don't edit 276 * If "fnum" is not NULL store the fnum there for '0, 'A etc., don't edit
530 void 524 void
531 fmarks_check_names(buf_T *buf) 525 fmarks_check_names(buf_T *buf)
532 { 526 {
533 char_u *name; 527 char_u *name;
534 int i; 528 int i;
535 #ifdef FEAT_JUMPLIST
536 win_T *wp; 529 win_T *wp;
537 #endif
538 530
539 if (buf->b_ffname == NULL) 531 if (buf->b_ffname == NULL)
540 return; 532 return;
541 533
542 name = home_replace_save(buf, buf->b_ffname); 534 name = home_replace_save(buf, buf->b_ffname);
544 return; 536 return;
545 537
546 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i) 538 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
547 fmarks_check_one(&namedfm[i], name, buf); 539 fmarks_check_one(&namedfm[i], name, buf);
548 540
549 #ifdef FEAT_JUMPLIST
550 FOR_ALL_WINDOWS(wp) 541 FOR_ALL_WINDOWS(wp)
551 { 542 {
552 for (i = 0; i < wp->w_jumplistlen; ++i) 543 for (i = 0; i < wp->w_jumplistlen; ++i)
553 fmarks_check_one(&wp->w_jumplist[i], name, buf); 544 fmarks_check_one(&wp->w_jumplist[i], name, buf);
554 } 545 }
555 #endif
556 546
557 vim_free(name); 547 vim_free(name);
558 } 548 }
559 549
560 static void 550 static void
624 buf->b_last_cursor.lnum = 1; // '" mark cleared 614 buf->b_last_cursor.lnum = 1; // '" mark cleared
625 buf->b_last_cursor.col = 0; 615 buf->b_last_cursor.col = 0;
626 buf->b_last_cursor.coladd = 0; 616 buf->b_last_cursor.coladd = 0;
627 buf->b_last_insert.lnum = 0; // '^ mark cleared 617 buf->b_last_insert.lnum = 0; // '^ mark cleared
628 buf->b_last_change.lnum = 0; // '. mark cleared 618 buf->b_last_change.lnum = 0; // '. mark cleared
629 #ifdef FEAT_JUMPLIST
630 buf->b_changelistlen = 0; 619 buf->b_changelistlen = 0;
631 #endif
632 } 620 }
633 621
634 /* 622 /*
635 * Get name of file from a filemark. 623 * Get name of file from a filemark.
636 * When it's in the current buffer, return the text at the mark. 624 * When it's in the current buffer, return the text at the mark.
865 } 853 }
866 } 854 }
867 } 855 }
868 } 856 }
869 857
870 #if defined(FEAT_JUMPLIST) || defined(PROTO)
871 /* 858 /*
872 * print the jumplist 859 * print the jumplist
873 */ 860 */
874 void 861 void
875 ex_jumps(exarg_T *eap UNUSED) 862 ex_jumps(exarg_T *eap UNUSED)
963 out_flush(); 950 out_flush();
964 } 951 }
965 if (curwin->w_changelistidx == curbuf->b_changelistlen) 952 if (curwin->w_changelistidx == curbuf->b_changelistlen)
966 msg_puts("\n>"); 953 msg_puts("\n>");
967 } 954 }
968 #endif
969 955
970 #define one_adjust(add) \ 956 #define one_adjust(add) \
971 { \ 957 { \
972 lp = add; \ 958 lp = add; \
973 if (*lp >= line1 && *lp <= line2) \ 959 if (*lp >= line1 && *lp <= line2) \
1069 // last cursor position, if it was set 1055 // last cursor position, if it was set
1070 if (!EQUAL_POS(curbuf->b_last_cursor, initpos)) 1056 if (!EQUAL_POS(curbuf->b_last_cursor, initpos))
1071 one_adjust(&(curbuf->b_last_cursor.lnum)); 1057 one_adjust(&(curbuf->b_last_cursor.lnum));
1072 1058
1073 1059
1074 #ifdef FEAT_JUMPLIST
1075 // list of change positions 1060 // list of change positions
1076 for (i = 0; i < curbuf->b_changelistlen; ++i) 1061 for (i = 0; i < curbuf->b_changelistlen; ++i)
1077 one_adjust_nodel(&(curbuf->b_changelist[i].lnum)); 1062 one_adjust_nodel(&(curbuf->b_changelist[i].lnum));
1078 #endif
1079 1063
1080 // Visual area 1064 // Visual area
1081 one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum)); 1065 one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum));
1082 one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum)); 1066 one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum));
1083 1067
1107 /* 1091 /*
1108 * Adjust items in all windows related to the current buffer. 1092 * Adjust items in all windows related to the current buffer.
1109 */ 1093 */
1110 FOR_ALL_TAB_WINDOWS(tab, win) 1094 FOR_ALL_TAB_WINDOWS(tab, win)
1111 { 1095 {
1112 #ifdef FEAT_JUMPLIST
1113 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) 1096 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
1114 // Marks in the jumplist. When deleting lines, this may create 1097 // Marks in the jumplist. When deleting lines, this may create
1115 // duplicate marks in the jumplist, they will be removed later. 1098 // duplicate marks in the jumplist, they will be removed later.
1116 for (i = 0; i < win->w_jumplistlen; ++i) 1099 for (i = 0; i < win->w_jumplistlen; ++i)
1117 if (win->w_jumplist[i].fmark.fnum == fnum) 1100 if (win->w_jumplist[i].fmark.fnum == fnum)
1118 one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum)); 1101 one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum));
1119 #endif
1120 1102
1121 if (win->w_buffer == curbuf) 1103 if (win->w_buffer == curbuf)
1122 { 1104 {
1123 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0) 1105 if ((cmdmod.cmod_flags & CMOD_LOCKMARKS) == 0)
1124 // marks in the tag stack 1106 // marks in the tag stack
1247 col_adjust(&(curbuf->b_last_insert)); 1229 col_adjust(&(curbuf->b_last_insert));
1248 1230
1249 // last change position 1231 // last change position
1250 col_adjust(&(curbuf->b_last_change)); 1232 col_adjust(&(curbuf->b_last_change));
1251 1233
1252 #ifdef FEAT_JUMPLIST
1253 // list of change positions 1234 // list of change positions
1254 for (i = 0; i < curbuf->b_changelistlen; ++i) 1235 for (i = 0; i < curbuf->b_changelistlen; ++i)
1255 col_adjust(&(curbuf->b_changelist[i])); 1236 col_adjust(&(curbuf->b_changelist[i]));
1256 #endif
1257 1237
1258 // Visual area 1238 // Visual area
1259 col_adjust(&(curbuf->b_visual.vi_start)); 1239 col_adjust(&(curbuf->b_visual.vi_start));
1260 col_adjust(&(curbuf->b_visual.vi_end)); 1240 col_adjust(&(curbuf->b_visual.vi_end));
1261 1241
1271 /* 1251 /*
1272 * Adjust items in all windows related to the current buffer. 1252 * Adjust items in all windows related to the current buffer.
1273 */ 1253 */
1274 FOR_ALL_WINDOWS(win) 1254 FOR_ALL_WINDOWS(win)
1275 { 1255 {
1276 #ifdef FEAT_JUMPLIST
1277 // marks in the jumplist 1256 // marks in the jumplist
1278 for (i = 0; i < win->w_jumplistlen; ++i) 1257 for (i = 0; i < win->w_jumplistlen; ++i)
1279 if (win->w_jumplist[i].fmark.fnum == fnum) 1258 if (win->w_jumplist[i].fmark.fnum == fnum)
1280 col_adjust(&(win->w_jumplist[i].fmark.mark)); 1259 col_adjust(&(win->w_jumplist[i].fmark.mark));
1281 #endif
1282 1260
1283 if (win->w_buffer == curbuf) 1261 if (win->w_buffer == curbuf)
1284 { 1262 {
1285 // marks in the tag stack 1263 // marks in the tag stack
1286 for (i = 0; i < win->w_tagstacklen; i++) 1264 for (i = 0; i < win->w_tagstacklen; i++)
1292 col_adjust(&win->w_cursor); 1270 col_adjust(&win->w_cursor);
1293 } 1271 }
1294 } 1272 }
1295 } 1273 }
1296 1274
1297 #ifdef FEAT_JUMPLIST
1298 /* 1275 /*
1299 * When deleting lines, this may create duplicate marks in the 1276 * When deleting lines, this may create duplicate marks in the
1300 * jumplist. They will be removed here for the specified window. 1277 * jumplist. They will be removed here for the specified window.
1301 * When "loadfiles" is TRUE first ensure entries have the "fnum" field set 1278 * When "loadfiles" is TRUE first ensure entries have the "fnum" field set
1302 * (this may be a bit slow). 1279 * (this may be a bit slow).
1369 int i; 1346 int i;
1370 1347
1371 for (i = 0; i < wp->w_jumplistlen; ++i) 1348 for (i = 0; i < wp->w_jumplistlen; ++i)
1372 vim_free(wp->w_jumplist[i].fname); 1349 vim_free(wp->w_jumplist[i].fname);
1373 } 1350 }
1374 #endif // FEAT_JUMPLIST
1375 1351
1376 void 1352 void
1377 set_last_cursor(win_T *win) 1353 set_last_cursor(win_T *win)
1378 { 1354 {
1379 if (win->w_buffer != NULL) 1355 if (win->w_buffer != NULL)