comparison src/buffer.c @ 18757:c469e1930456 v8.1.2368

patch 8.1.2368: using old C style comments Commit: https://github.com/vim/vim/commit/c667da5185ce5dce914d2006d62da2be0cedb384 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Nov 30 20:52:27 2019 +0100 patch 8.1.2368: using old C style comments Problem: Using old C style comments. Solution: Use // comments where appropriate.
author Bram Moolenaar <Bram@vim.org>
date Sat, 30 Nov 2019 21:00:04 +0100
parents 64eea864dff6
children 49b78d6465e5
comparison
equal deleted inserted replaced
18756:c58a9ff2b806 18757:c469e1930456
76 /* 76 /*
77 * Read data from buffer for retrying. 77 * Read data from buffer for retrying.
78 */ 78 */
79 static int 79 static int
80 read_buffer( 80 read_buffer(
81 int read_stdin, /* read file from stdin, otherwise fifo */ 81 int read_stdin, // read file from stdin, otherwise fifo
82 exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ 82 exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
83 int flags) /* extra flags for readfile() */ 83 int flags) // extra flags for readfile()
84 { 84 {
85 int retval = OK; 85 int retval = OK;
86 linenr_T line_count; 86 linenr_T line_count;
87 87
88 /* 88 /*
96 read_stdin ? NULL : curbuf->b_fname, 96 read_stdin ? NULL : curbuf->b_fname,
97 (linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap, 97 (linenr_T)line_count, (linenr_T)0, (linenr_T)MAXLNUM, eap,
98 flags | READ_BUFFER); 98 flags | READ_BUFFER);
99 if (retval == OK) 99 if (retval == OK)
100 { 100 {
101 /* Delete the binary lines. */ 101 // Delete the binary lines.
102 while (--line_count >= 0) 102 while (--line_count >= 0)
103 ml_delete((linenr_T)1, FALSE); 103 ml_delete((linenr_T)1, FALSE);
104 } 104 }
105 else 105 else
106 { 106 {
107 /* Delete the converted lines. */ 107 // Delete the converted lines.
108 while (curbuf->b_ml.ml_line_count > line_count) 108 while (curbuf->b_ml.ml_line_count > line_count)
109 ml_delete(line_count, FALSE); 109 ml_delete(line_count, FALSE);
110 } 110 }
111 /* Put the cursor on the first line. */ 111 // Put the cursor on the first line.
112 curwin->w_cursor.lnum = 1; 112 curwin->w_cursor.lnum = 1;
113 curwin->w_cursor.col = 0; 113 curwin->w_cursor.col = 0;
114 114
115 if (read_stdin) 115 if (read_stdin)
116 { 116 {
117 /* Set or reset 'modified' before executing autocommands, so that 117 // Set or reset 'modified' before executing autocommands, so that
118 * it can be changed there. */ 118 // it can be changed there.
119 if (!readonlymode && !BUFEMPTY()) 119 if (!readonlymode && !BUFEMPTY())
120 changed(); 120 changed();
121 else if (retval == OK) 121 else if (retval == OK)
122 unchanged(curbuf, FALSE, TRUE); 122 unchanged(curbuf, FALSE, TRUE);
123 123
156 * memory. 156 * memory.
157 * Return FAIL for failure, OK otherwise. 157 * Return FAIL for failure, OK otherwise.
158 */ 158 */
159 int 159 int
160 open_buffer( 160 open_buffer(
161 int read_stdin, /* read file from stdin */ 161 int read_stdin, // read file from stdin
162 exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ 162 exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
163 int flags) /* extra flags for readfile() */ 163 int flags) // extra flags for readfile()
164 { 164 {
165 int retval = OK; 165 int retval = OK;
166 bufref_T old_curbuf; 166 bufref_T old_curbuf;
167 #ifdef FEAT_SYN_HL 167 #ifdef FEAT_SYN_HL
168 long old_tw = curbuf->b_p_tw; 168 long old_tw = curbuf->b_p_tw;
209 check_colorcolumn(curwin); 209 check_colorcolumn(curwin);
210 #endif 210 #endif
211 return FAIL; 211 return FAIL;
212 } 212 }
213 213
214 /* The autocommands in readfile() may change the buffer, but only AFTER 214 // The autocommands in readfile() may change the buffer, but only AFTER
215 * reading the file. */ 215 // reading the file.
216 set_bufref(&old_curbuf, curbuf); 216 set_bufref(&old_curbuf, curbuf);
217 modified_was_set = FALSE; 217 modified_was_set = FALSE;
218 218
219 /* mark cursor position as being invalid */ 219 // mark cursor position as being invalid
220 curwin->w_valid = 0; 220 curwin->w_valid = 0;
221 221
222 if (curbuf->b_ffname != NULL 222 if (curbuf->b_ffname != NULL
223 #ifdef FEAT_NETBEANS_INTG 223 #ifdef FEAT_NETBEANS_INTG
224 && netbeansReadFile 224 && netbeansReadFile
262 #endif 262 #endif
263 msg_silent = old_msg_silent; 263 msg_silent = old_msg_silent;
264 #ifdef FEAT_NETBEANS_INTG 264 #ifdef FEAT_NETBEANS_INTG
265 netbeansFireChanges = oldFire; 265 netbeansFireChanges = oldFire;
266 #endif 266 #endif
267 /* Help buffer is filtered. */ 267 // Help buffer is filtered.
268 if (bt_help(curbuf)) 268 if (bt_help(curbuf))
269 fix_help_buffer(); 269 fix_help_buffer();
270 } 270 }
271 else if (read_stdin) 271 else if (read_stdin)
272 { 272 {
285 curbuf->b_p_bin = save_bin; 285 curbuf->b_p_bin = save_bin;
286 if (retval == OK) 286 if (retval == OK)
287 retval = read_buffer(TRUE, eap, flags); 287 retval = read_buffer(TRUE, eap, flags);
288 } 288 }
289 289
290 /* if first time loading this buffer, init b_chartab[] */ 290 // if first time loading this buffer, init b_chartab[]
291 if (curbuf->b_flags & BF_NEVERLOADED) 291 if (curbuf->b_flags & BF_NEVERLOADED)
292 { 292 {
293 (void)buf_init_chartab(curbuf, FALSE); 293 (void)buf_init_chartab(curbuf, FALSE);
294 #ifdef FEAT_CINDENT 294 #ifdef FEAT_CINDENT
295 parse_cino(curbuf); 295 parse_cino(curbuf);
299 /* 299 /*
300 * Set/reset the Changed flag first, autocmds may change the buffer. 300 * Set/reset the Changed flag first, autocmds may change the buffer.
301 * Apply the automatic commands, before processing the modelines. 301 * Apply the automatic commands, before processing the modelines.
302 * So the modelines have priority over autocommands. 302 * So the modelines have priority over autocommands.
303 */ 303 */
304 /* When reading stdin, the buffer contents always needs writing, so set 304 // When reading stdin, the buffer contents always needs writing, so set
305 * the changed flag. Unless in readonly mode: "ls | gview -". 305 // the changed flag. Unless in readonly mode: "ls | gview -".
306 * When interrupted and 'cpoptions' contains 'i' set changed flag. */ 306 // When interrupted and 'cpoptions' contains 'i' set changed flag.
307 if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) 307 if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
308 || modified_was_set /* ":set modified" used in autocmd */ 308 || modified_was_set // ":set modified" used in autocmd
309 #ifdef FEAT_EVAL 309 #ifdef FEAT_EVAL
310 || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) 310 || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL)
311 #endif 311 #endif
312 ) 312 )
313 changed(); 313 changed();
314 else if (retval == OK && !read_stdin && !read_fifo) 314 else if (retval == OK && !read_stdin && !read_fifo)
315 unchanged(curbuf, FALSE, TRUE); 315 unchanged(curbuf, FALSE, TRUE);
316 save_file_ff(curbuf); /* keep this fileformat */ 316 save_file_ff(curbuf); // keep this fileformat
317 317
318 /* Set last_changedtick to avoid triggering a TextChanged autocommand right 318 // Set last_changedtick to avoid triggering a TextChanged autocommand right
319 * after it was added. */ 319 // after it was added.
320 curbuf->b_last_changedtick = CHANGEDTICK(curbuf); 320 curbuf->b_last_changedtick = CHANGEDTICK(curbuf);
321 curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf); 321 curbuf->b_last_changedtick_pum = CHANGEDTICK(curbuf);
322 322
323 /* require "!" to overwrite the file, because it wasn't read completely */ 323 // require "!" to overwrite the file, because it wasn't read completely
324 #ifdef FEAT_EVAL 324 #ifdef FEAT_EVAL
325 if (aborting()) 325 if (aborting())
326 #else 326 #else
327 if (got_int) 327 if (got_int)
328 #endif 328 #endif
329 curbuf->b_flags |= BF_READERR; 329 curbuf->b_flags |= BF_READERR;
330 330
331 #ifdef FEAT_FOLDING 331 #ifdef FEAT_FOLDING
332 /* Need to update automatic folding. Do this before the autocommands, 332 // Need to update automatic folding. Do this before the autocommands,
333 * they may use the fold info. */ 333 // they may use the fold info.
334 foldUpdateAll(curwin); 334 foldUpdateAll(curwin);
335 #endif 335 #endif
336 336
337 /* need to set w_topline, unless some autocommand already did that. */ 337 // need to set w_topline, unless some autocommand already did that.
338 if (!(curwin->w_valid & VALID_TOPLINE)) 338 if (!(curwin->w_valid & VALID_TOPLINE))
339 { 339 {
340 curwin->w_topline = 1; 340 curwin->w_topline = 1;
341 #ifdef FEAT_DIFF 341 #ifdef FEAT_DIFF
342 curwin->w_topfill = 0; 342 curwin->w_topfill = 0;
356 */ 356 */
357 if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) 357 if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL)
358 { 358 {
359 aco_save_T aco; 359 aco_save_T aco;
360 360
361 /* Go to the buffer that was opened. */ 361 // Go to the buffer that was opened.
362 aucmd_prepbuf(&aco, old_curbuf.br_buf); 362 aucmd_prepbuf(&aco, old_curbuf.br_buf);
363 do_modelines(0); 363 do_modelines(0);
364 curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); 364 curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
365 365
366 #ifdef FEAT_EVAL 366 #ifdef FEAT_EVAL
368 &retval); 368 &retval);
369 #else 369 #else
370 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); 370 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
371 #endif 371 #endif
372 372
373 /* restore curwin/curbuf and a few other things */ 373 // restore curwin/curbuf and a few other things
374 aucmd_restbuf(&aco); 374 aucmd_restbuf(&aco);
375 } 375 }
376 } 376 }
377 377
378 return retval; 378 return retval;
411 int 411 int
412 buf_valid(buf_T *buf) 412 buf_valid(buf_T *buf)
413 { 413 {
414 buf_T *bp; 414 buf_T *bp;
415 415
416 /* Assume that we more often have a recent buffer, start with the last 416 // Assume that we more often have a recent buffer, start with the last
417 * one. */ 417 // one.
418 for (bp = lastbuf; bp != NULL; bp = bp->b_prev) 418 for (bp = lastbuf; bp != NULL; bp = bp->b_prev)
419 if (bp == buf) 419 if (bp == buf)
420 return TRUE; 420 return TRUE;
421 return FALSE; 421 return FALSE;
422 } 422 }
488 * cause there to be only one window with this buffer. e.g. when ":quit" is 488 * cause there to be only one window with this buffer. e.g. when ":quit" is
489 * supposed to close the window but autocommands close all other windows. 489 * supposed to close the window but autocommands close all other windows.
490 */ 490 */
491 void 491 void
492 close_buffer( 492 close_buffer(
493 win_T *win, /* if not NULL, set b_last_cursor */ 493 win_T *win, // if not NULL, set b_last_cursor
494 buf_T *buf, 494 buf_T *buf,
495 int action, 495 int action,
496 int abort_if_last) 496 int abort_if_last)
497 { 497 {
498 int is_curbuf; 498 int is_curbuf;
508 /* 508 /*
509 * Force unloading or deleting when 'bufhidden' says so. 509 * Force unloading or deleting when 'bufhidden' says so.
510 * The caller must take care of NOT deleting/freeing when 'bufhidden' is 510 * The caller must take care of NOT deleting/freeing when 'bufhidden' is
511 * "hide" (otherwise we could never free or delete a buffer). 511 * "hide" (otherwise we could never free or delete a buffer).
512 */ 512 */
513 if (buf->b_p_bh[0] == 'd') /* 'bufhidden' == "delete" */ 513 if (buf->b_p_bh[0] == 'd') // 'bufhidden' == "delete"
514 { 514 {
515 del_buf = TRUE; 515 del_buf = TRUE;
516 unload_buf = TRUE; 516 unload_buf = TRUE;
517 } 517 }
518 else if (buf->b_p_bh[0] == 'w') /* 'bufhidden' == "wipe" */ 518 else if (buf->b_p_bh[0] == 'w') // 'bufhidden' == "wipe"
519 { 519 {
520 del_buf = TRUE; 520 del_buf = TRUE;
521 unload_buf = TRUE; 521 unload_buf = TRUE;
522 wipe_buf = TRUE; 522 wipe_buf = TRUE;
523 } 523 }
524 else if (buf->b_p_bh[0] == 'u') /* 'bufhidden' == "unload" */ 524 else if (buf->b_p_bh[0] == 'u') // 'bufhidden' == "unload"
525 unload_buf = TRUE; 525 unload_buf = TRUE;
526 526
527 #ifdef FEAT_TERMINAL 527 #ifdef FEAT_TERMINAL
528 if (bt_terminal(buf) && (buf->b_nwindows == 1 || del_buf)) 528 if (bt_terminal(buf) && (buf->b_nwindows == 1 || del_buf))
529 { 529 {
532 if (wipe_buf || unload_buf) 532 if (wipe_buf || unload_buf)
533 { 533 {
534 if (!can_unload_buffer(buf)) 534 if (!can_unload_buffer(buf))
535 return; 535 return;
536 536
537 /* Wiping out or unloading a terminal buffer kills the job. */ 537 // Wiping out or unloading a terminal buffer kills the job.
538 free_terminal(buf); 538 free_terminal(buf);
539 } 539 }
540 else 540 else
541 { 541 {
542 /* The job keeps running, hide the buffer. */ 542 // The job keeps running, hide the buffer.
543 del_buf = FALSE; 543 del_buf = FALSE;
544 unload_buf = FALSE; 544 unload_buf = FALSE;
545 } 545 }
546 } 546 }
547 else 547 else
548 { 548 {
549 /* A terminal buffer is wiped out if the job has finished. */ 549 // A terminal buffer is wiped out if the job has finished.
550 del_buf = TRUE; 550 del_buf = TRUE;
551 unload_buf = TRUE; 551 unload_buf = TRUE;
552 wipe_buf = TRUE; 552 wipe_buf = TRUE;
553 } 553 }
554 } 554 }
555 #endif 555 #endif
556 556
557 /* Disallow deleting the buffer when it is locked (already being closed or 557 // Disallow deleting the buffer when it is locked (already being closed or
558 * halfway a command that relies on it). Unloading is allowed. */ 558 // halfway a command that relies on it). Unloading is allowed.
559 if ((del_buf || wipe_buf) && !can_unload_buffer(buf)) 559 if ((del_buf || wipe_buf) && !can_unload_buffer(buf))
560 return; 560 return;
561 561
562 /* check no autocommands closed the window */ 562 // check no autocommands closed the window
563 if (win != NULL && win_valid_any_tab(win)) 563 if (win != NULL && win_valid_any_tab(win))
564 { 564 {
565 /* Set b_last_cursor when closing the last window for the buffer. 565 // Set b_last_cursor when closing the last window for the buffer.
566 * Remember the last cursor position and window options of the buffer. 566 // Remember the last cursor position and window options of the buffer.
567 * This used to be only for the current window, but then options like 567 // This used to be only for the current window, but then options like
568 * 'foldmethod' may be lost with a ":only" command. */ 568 // 'foldmethod' may be lost with a ":only" command.
569 if (buf->b_nwindows == 1) 569 if (buf->b_nwindows == 1)
570 set_last_cursor(win); 570 set_last_cursor(win);
571 buflist_setfpos(buf, win, 571 buflist_setfpos(buf, win,
572 win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum, 572 win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum,
573 win->w_cursor.col, TRUE); 573 win->w_cursor.col, TRUE);
574 } 574 }
575 575
576 set_bufref(&bufref, buf); 576 set_bufref(&bufref, buf);
577 577
578 /* When the buffer is no longer in a window, trigger BufWinLeave */ 578 // When the buffer is no longer in a window, trigger BufWinLeave
579 if (buf->b_nwindows == 1) 579 if (buf->b_nwindows == 1)
580 { 580 {
581 ++buf->b_locked; 581 ++buf->b_locked;
582 if (apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, 582 if (apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname,
583 FALSE, buf) 583 FALSE, buf)
584 && !bufref_valid(&bufref)) 584 && !bufref_valid(&bufref))
585 { 585 {
586 /* Autocommands deleted the buffer. */ 586 // Autocommands deleted the buffer.
587 aucmd_abort: 587 aucmd_abort:
588 emsg(_(e_auabort)); 588 emsg(_(e_auabort));
589 return; 589 return;
590 } 590 }
591 --buf->b_locked; 591 --buf->b_locked;
592 if (abort_if_last && one_window()) 592 if (abort_if_last && one_window())
593 /* Autocommands made this the only window. */ 593 // Autocommands made this the only window.
594 goto aucmd_abort; 594 goto aucmd_abort;
595 595
596 /* When the buffer becomes hidden, but is not unloaded, trigger 596 // When the buffer becomes hidden, but is not unloaded, trigger
597 * BufHidden */ 597 // BufHidden
598 if (!unload_buf) 598 if (!unload_buf)
599 { 599 {
600 ++buf->b_locked; 600 ++buf->b_locked;
601 if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, 601 if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname,
602 FALSE, buf) 602 FALSE, buf)
603 && !bufref_valid(&bufref)) 603 && !bufref_valid(&bufref))
604 /* Autocommands deleted the buffer. */ 604 // Autocommands deleted the buffer.
605 goto aucmd_abort; 605 goto aucmd_abort;
606 --buf->b_locked; 606 --buf->b_locked;
607 if (abort_if_last && one_window()) 607 if (abort_if_last && one_window())
608 /* Autocommands made this the only window. */ 608 // Autocommands made this the only window.
609 goto aucmd_abort; 609 goto aucmd_abort;
610 } 610 }
611 #ifdef FEAT_EVAL 611 #ifdef FEAT_EVAL
612 if (aborting()) /* autocmds may abort script processing */ 612 if (aborting()) // autocmds may abort script processing
613 return; 613 return;
614 #endif 614 #endif
615 } 615 }
616 616
617 /* If the buffer was in curwin and the window has changed, go back to that 617 // If the buffer was in curwin and the window has changed, go back to that
618 * window, if it still exists. This avoids that ":edit x" triggering a 618 // window, if it still exists. This avoids that ":edit x" triggering a
619 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ 619 // "tabnext" BufUnload autocmd leaves a window behind without a buffer.
620 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) 620 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
621 { 621 {
622 block_autocmds(); 622 block_autocmds();
623 goto_tabpage_win(the_curtab, the_curwin); 623 goto_tabpage_win(the_curtab, the_curwin);
624 unblock_autocmds(); 624 unblock_autocmds();
625 } 625 }
626 626
627 nwindows = buf->b_nwindows; 627 nwindows = buf->b_nwindows;
628 628
629 /* decrease the link count from windows (unless not in any window) */ 629 // decrease the link count from windows (unless not in any window)
630 if (buf->b_nwindows > 0) 630 if (buf->b_nwindows > 0)
631 --buf->b_nwindows; 631 --buf->b_nwindows;
632 632
633 #ifdef FEAT_DIFF 633 #ifdef FEAT_DIFF
634 if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0) 634 if (diffopt_hiddenoff() && !unload_buf && buf->b_nwindows == 0)
635 diff_buf_delete(buf); /* Clear 'diff' for hidden buffer. */ 635 diff_buf_delete(buf); // Clear 'diff' for hidden buffer.
636 #endif 636 #endif
637 637
638 /* Return when a window is displaying the buffer or when it's not 638 // Return when a window is displaying the buffer or when it's not
639 * unloaded. */ 639 // unloaded.
640 if (buf->b_nwindows > 0 || !unload_buf) 640 if (buf->b_nwindows > 0 || !unload_buf)
641 return; 641 return;
642 642
643 /* Always remove the buffer when there is no file name. */ 643 // Always remove the buffer when there is no file name.
644 if (buf->b_ffname == NULL) 644 if (buf->b_ffname == NULL)
645 del_buf = TRUE; 645 del_buf = TRUE;
646 646
647 /* When closing the current buffer stop Visual mode before freeing 647 // When closing the current buffer stop Visual mode before freeing
648 * anything. */ 648 // anything.
649 if (buf == curbuf && VIsual_active 649 if (buf == curbuf && VIsual_active
650 #if defined(EXITFREE) 650 #if defined(EXITFREE)
651 && !entered_free_all_mem 651 && !entered_free_all_mem
652 #endif 652 #endif
653 ) 653 )
655 655
656 /* 656 /*
657 * Free all things allocated for this buffer. 657 * Free all things allocated for this buffer.
658 * Also calls the "BufDelete" autocommands when del_buf is TRUE. 658 * Also calls the "BufDelete" autocommands when del_buf is TRUE.
659 */ 659 */
660 /* Remember if we are closing the current buffer. Restore the number of 660 // Remember if we are closing the current buffer. Restore the number of
661 * windows, so that autocommands in buf_freeall() don't get confused. */ 661 // windows, so that autocommands in buf_freeall() don't get confused.
662 is_curbuf = (buf == curbuf); 662 is_curbuf = (buf == curbuf);
663 buf->b_nwindows = nwindows; 663 buf->b_nwindows = nwindows;
664 664
665 buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); 665 buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0));
666 666
667 /* Autocommands may have deleted the buffer. */ 667 // Autocommands may have deleted the buffer.
668 if (!bufref_valid(&bufref)) 668 if (!bufref_valid(&bufref))
669 return; 669 return;
670 #ifdef FEAT_EVAL 670 #ifdef FEAT_EVAL
671 if (aborting()) /* autocmds may abort script processing */ 671 if (aborting()) // autocmds may abort script processing
672 return; 672 return;
673 #endif 673 #endif
674 674
675 /* 675 /*
676 * It's possible that autocommands change curbuf to the one being deleted. 676 * It's possible that autocommands change curbuf to the one being deleted.
681 */ 681 */
682 if (buf == curbuf && !is_curbuf) 682 if (buf == curbuf && !is_curbuf)
683 return; 683 return;
684 684
685 if (win_valid_any_tab(win) && win->w_buffer == buf) 685 if (win_valid_any_tab(win) && win->w_buffer == buf)
686 win->w_buffer = NULL; /* make sure we don't use the buffer now */ 686 win->w_buffer = NULL; // make sure we don't use the buffer now
687 687
688 /* Autocommands may have opened or closed windows for this buffer. 688 // Autocommands may have opened or closed windows for this buffer.
689 * Decrement the count for the close we do here. */ 689 // Decrement the count for the close we do here.
690 if (buf->b_nwindows > 0) 690 if (buf->b_nwindows > 0)
691 --buf->b_nwindows; 691 --buf->b_nwindows;
692 692
693 /* 693 /*
694 * Remove the buffer from the list. 694 * Remove the buffer from the list.
720 } 720 }
721 else 721 else
722 { 722 {
723 if (del_buf) 723 if (del_buf)
724 { 724 {
725 /* Free all internal variables and reset option values, to make 725 // Free all internal variables and reset option values, to make
726 * ":bdel" compatible with Vim 5.7. */ 726 // ":bdel" compatible with Vim 5.7.
727 free_buffer_stuff(buf, TRUE); 727 free_buffer_stuff(buf, TRUE);
728 728
729 /* Make it look like a new buffer. */ 729 // Make it look like a new buffer.
730 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; 730 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED;
731 731
732 /* Init the options when loaded again. */ 732 // Init the options when loaded again.
733 buf->b_p_initialized = FALSE; 733 buf->b_p_initialized = FALSE;
734 } 734 }
735 buf_clear_file(buf); 735 buf_clear_file(buf);
736 if (del_buf) 736 if (del_buf)
737 buf->b_p_bl = FALSE; 737 buf->b_p_bl = FALSE;
750 buf->b_p_eol = TRUE; 750 buf->b_p_eol = TRUE;
751 buf->b_start_eol = TRUE; 751 buf->b_start_eol = TRUE;
752 buf->b_p_bomb = FALSE; 752 buf->b_p_bomb = FALSE;
753 buf->b_start_bomb = FALSE; 753 buf->b_start_bomb = FALSE;
754 buf->b_ml.ml_mfp = NULL; 754 buf->b_ml.ml_mfp = NULL;
755 buf->b_ml.ml_flags = ML_EMPTY; /* empty buffer */ 755 buf->b_ml.ml_flags = ML_EMPTY; // empty buffer
756 #ifdef FEAT_NETBEANS_INTG 756 #ifdef FEAT_NETBEANS_INTG
757 netbeans_deleted_all_lines(buf); 757 netbeans_deleted_all_lines(buf);
758 #endif 758 #endif
759 } 759 }
760 760
773 bufref_T bufref; 773 bufref_T bufref;
774 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); 774 int is_curwin = (curwin != NULL && curwin->w_buffer == buf);
775 win_T *the_curwin = curwin; 775 win_T *the_curwin = curwin;
776 tabpage_T *the_curtab = curtab; 776 tabpage_T *the_curtab = curtab;
777 777
778 /* Make sure the buffer isn't closed by autocommands. */ 778 // Make sure the buffer isn't closed by autocommands.
779 ++buf->b_locked; 779 ++buf->b_locked;
780 set_bufref(&bufref, buf); 780 set_bufref(&bufref, buf);
781 if (buf->b_ml.ml_mfp != NULL) 781 if (buf->b_ml.ml_mfp != NULL)
782 { 782 {
783 if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, 783 if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname,
784 FALSE, buf) 784 FALSE, buf)
785 && !bufref_valid(&bufref)) 785 && !bufref_valid(&bufref))
786 /* autocommands deleted the buffer */ 786 // autocommands deleted the buffer
787 return; 787 return;
788 } 788 }
789 if ((flags & BFA_DEL) && buf->b_p_bl) 789 if ((flags & BFA_DEL) && buf->b_p_bl)
790 { 790 {
791 if (apply_autocmds(EVENT_BUFDELETE, buf->b_fname, buf->b_fname, 791 if (apply_autocmds(EVENT_BUFDELETE, buf->b_fname, buf->b_fname,
792 FALSE, buf) 792 FALSE, buf)
793 && !bufref_valid(&bufref)) 793 && !bufref_valid(&bufref))
794 /* autocommands deleted the buffer */ 794 // autocommands deleted the buffer
795 return; 795 return;
796 } 796 }
797 if (flags & BFA_WIPE) 797 if (flags & BFA_WIPE)
798 { 798 {
799 if (apply_autocmds(EVENT_BUFWIPEOUT, buf->b_fname, buf->b_fname, 799 if (apply_autocmds(EVENT_BUFWIPEOUT, buf->b_fname, buf->b_fname,
800 FALSE, buf) 800 FALSE, buf)
801 && !bufref_valid(&bufref)) 801 && !bufref_valid(&bufref))
802 /* autocommands deleted the buffer */ 802 // autocommands deleted the buffer
803 return; 803 return;
804 } 804 }
805 --buf->b_locked; 805 --buf->b_locked;
806 806
807 /* If the buffer was in curwin and the window has changed, go back to that 807 // If the buffer was in curwin and the window has changed, go back to that
808 * window, if it still exists. This avoids that ":edit x" triggering a 808 // window, if it still exists. This avoids that ":edit x" triggering a
809 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ 809 // "tabnext" BufUnload autocmd leaves a window behind without a buffer.
810 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) 810 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
811 { 811 {
812 block_autocmds(); 812 block_autocmds();
813 goto_tabpage_win(the_curtab, the_curwin); 813 goto_tabpage_win(the_curtab, the_curwin);
814 unblock_autocmds(); 814 unblock_autocmds();
815 } 815 }
816 816
817 #ifdef FEAT_EVAL 817 #ifdef FEAT_EVAL
818 if (aborting()) /* autocmds may abort script processing */ 818 if (aborting()) // autocmds may abort script processing
819 return; 819 return;
820 #endif 820 #endif
821 821
822 /* 822 /*
823 * It's possible that autocommands change curbuf to the one being deleted. 823 * It's possible that autocommands change curbuf to the one being deleted.
826 * Therefore only return if curbuf changed to the deleted buffer. 826 * Therefore only return if curbuf changed to the deleted buffer.
827 */ 827 */
828 if (buf == curbuf && !is_curbuf) 828 if (buf == curbuf && !is_curbuf)
829 return; 829 return;
830 #ifdef FEAT_DIFF 830 #ifdef FEAT_DIFF
831 diff_buf_delete(buf); /* Can't use 'diff' for unloaded buffer. */ 831 diff_buf_delete(buf); // Can't use 'diff' for unloaded buffer.
832 #endif 832 #endif
833 #ifdef FEAT_SYN_HL 833 #ifdef FEAT_SYN_HL
834 /* Remove any ownsyntax, unless exiting. */ 834 // Remove any ownsyntax, unless exiting.
835 if (curwin != NULL && curwin->w_buffer == buf) 835 if (curwin != NULL && curwin->w_buffer == buf)
836 reset_synblock(curwin); 836 reset_synblock(curwin);
837 #endif 837 #endif
838 838
839 #ifdef FEAT_FOLDING 839 #ifdef FEAT_FOLDING
840 /* No folds in an empty buffer. */ 840 // No folds in an empty buffer.
841 { 841 {
842 win_T *win; 842 win_T *win;
843 tabpage_T *tp; 843 tabpage_T *tp;
844 844
845 FOR_ALL_TAB_WINDOWS(tp, win) 845 FOR_ALL_TAB_WINDOWS(tp, win)
849 #endif 849 #endif
850 850
851 #ifdef FEAT_TCL 851 #ifdef FEAT_TCL
852 tcl_buffer_free(buf); 852 tcl_buffer_free(buf);
853 #endif 853 #endif
854 ml_close(buf, TRUE); /* close and delete the memline/memfile */ 854 ml_close(buf, TRUE); // close and delete the memline/memfile
855 buf->b_ml.ml_line_count = 0; /* no lines in buffer */ 855 buf->b_ml.ml_line_count = 0; // no lines in buffer
856 if ((flags & BFA_KEEP_UNDO) == 0) 856 if ((flags & BFA_KEEP_UNDO) == 0)
857 { 857 {
858 u_blockfree(buf); /* free the memory allocated for undo */ 858 u_blockfree(buf); // free the memory allocated for undo
859 u_clearall(buf); /* reset all undo information */ 859 u_clearall(buf); // reset all undo information
860 } 860 }
861 #ifdef FEAT_SYN_HL 861 #ifdef FEAT_SYN_HL
862 syntax_clear(&buf->b_s); /* reset syntax info */ 862 syntax_clear(&buf->b_s); // reset syntax info
863 #endif 863 #endif
864 #ifdef FEAT_TEXT_PROP 864 #ifdef FEAT_TEXT_PROP
865 clear_buf_prop_types(buf); 865 clear_buf_prop_types(buf);
866 #endif 866 #endif
867 buf->b_flags &= ~BF_READERR; /* a read error is no longer relevant */ 867 buf->b_flags &= ~BF_READERR; // a read error is no longer relevant
868 } 868 }
869 869
870 /* 870 /*
871 * Free a buffer structure and the things it contains related to the buffer 871 * Free a buffer structure and the things it contains related to the buffer
872 * itself (not the file, that must have been done already). 872 * itself (not the file, that must have been done already).
875 free_buffer(buf_T *buf) 875 free_buffer(buf_T *buf)
876 { 876 {
877 ++buf_free_count; 877 ++buf_free_count;
878 free_buffer_stuff(buf, TRUE); 878 free_buffer_stuff(buf, TRUE);
879 #ifdef FEAT_EVAL 879 #ifdef FEAT_EVAL
880 /* b:changedtick uses an item in buf_T, remove it now */ 880 // b:changedtick uses an item in buf_T, remove it now
881 dictitem_remove(buf->b_vars, (dictitem_T *)&buf->b_ct_di); 881 dictitem_remove(buf->b_vars, (dictitem_T *)&buf->b_ct_di);
882 unref_var_dict(buf->b_vars); 882 unref_var_dict(buf->b_vars);
883 remove_listeners(buf); 883 remove_listeners(buf);
884 #endif 884 #endif
885 #ifdef FEAT_LUA 885 #ifdef FEAT_LUA
916 916
917 aubuflocal_remove(buf); 917 aubuflocal_remove(buf);
918 918
919 if (autocmd_busy) 919 if (autocmd_busy)
920 { 920 {
921 /* Do not free the buffer structure while autocommands are executing, 921 // Do not free the buffer structure while autocommands are executing,
922 * it's still needed. Free it when autocmd_busy is reset. */ 922 // it's still needed. Free it when autocmd_busy is reset.
923 buf->b_next = au_pending_free_buf; 923 buf->b_next = au_pending_free_buf;
924 au_pending_free_buf = buf; 924 au_pending_free_buf = buf;
925 } 925 }
926 else 926 else
927 vim_free(buf); 927 vim_free(buf);
950 * Free stuff in the buffer for ":bdel" and when wiping out the buffer. 950 * Free stuff in the buffer for ":bdel" and when wiping out the buffer.
951 */ 951 */
952 static void 952 static void
953 free_buffer_stuff( 953 free_buffer_stuff(
954 buf_T *buf, 954 buf_T *buf,
955 int free_options) /* free options as well */ 955 int free_options) // free options as well
956 { 956 {
957 if (free_options) 957 if (free_options)
958 { 958 {
959 clear_wininfo(buf); /* including window-local options */ 959 clear_wininfo(buf); // including window-local options
960 free_buf_options(buf, TRUE); 960 free_buf_options(buf, TRUE);
961 #ifdef FEAT_SPELL 961 #ifdef FEAT_SPELL
962 ga_clear(&buf->b_s.b_langp); 962 ga_clear(&buf->b_s.b_langp);
963 #endif 963 #endif
964 } 964 }
965 #ifdef FEAT_EVAL 965 #ifdef FEAT_EVAL
966 { 966 {
967 varnumber_T tick = CHANGEDTICK(buf); 967 varnumber_T tick = CHANGEDTICK(buf);
968 968
969 vars_clear(&buf->b_vars->dv_hashtab); /* free all buffer variables */ 969 vars_clear(&buf->b_vars->dv_hashtab); // free all buffer variables
970 hash_init(&buf->b_vars->dv_hashtab); 970 hash_init(&buf->b_vars->dv_hashtab);
971 init_changedtick(buf); 971 init_changedtick(buf);
972 CHANGEDTICK(buf) = tick; 972 CHANGEDTICK(buf) = tick;
973 } 973 }
974 #endif 974 #endif
977 buf_delete_signs(buf, (char_u *)"*"); // delete any signs 977 buf_delete_signs(buf, (char_u *)"*"); // delete any signs
978 #endif 978 #endif
979 #ifdef FEAT_NETBEANS_INTG 979 #ifdef FEAT_NETBEANS_INTG
980 netbeans_file_killed(buf); 980 netbeans_file_killed(buf);
981 #endif 981 #endif
982 map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); /* clear local mappings */ 982 map_clear_int(buf, MAP_ALL_MODES, TRUE, FALSE); // clear local mappings
983 map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); /* clear local abbrevs */ 983 map_clear_int(buf, MAP_ALL_MODES, TRUE, TRUE); // clear local abbrevs
984 VIM_CLEAR(buf->b_start_fenc); 984 VIM_CLEAR(buf->b_start_fenc);
985 } 985 }
986 986
987 /* 987 /*
988 * Free the b_wininfo list for buffer "buf". 988 * Free the b_wininfo list for buffer "buf".
1027 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') 1027 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's')
1028 { 1028 {
1029 #if defined(FEAT_EVAL) 1029 #if defined(FEAT_EVAL)
1030 cleanup_T cs; 1030 cleanup_T cs;
1031 1031
1032 /* Reset the error/interrupt/exception state here so that 1032 // Reset the error/interrupt/exception state here so that
1033 * aborting() returns FALSE when closing a window. */ 1033 // aborting() returns FALSE when closing a window.
1034 enter_cleanup(&cs); 1034 enter_cleanup(&cs);
1035 #endif 1035 #endif
1036 1036
1037 /* Quitting means closing the split window, nothing else. */ 1037 // Quitting means closing the split window, nothing else.
1038 win_close(curwin, TRUE); 1038 win_close(curwin, TRUE);
1039 swap_exists_action = SEA_NONE; 1039 swap_exists_action = SEA_NONE;
1040 swap_exists_did_quit = TRUE; 1040 swap_exists_did_quit = TRUE;
1041 1041
1042 #if defined(FEAT_EVAL) 1042 #if defined(FEAT_EVAL)
1043 /* Restore the error/interrupt/exception state if not discarded by a 1043 // Restore the error/interrupt/exception state if not discarded by a
1044 * new aborting error, interrupt, or uncaught exception. */ 1044 // new aborting error, interrupt, or uncaught exception.
1045 leave_cleanup(&cs); 1045 leave_cleanup(&cs);
1046 #endif 1046 #endif
1047 } 1047 }
1048 else 1048 else
1049 handle_swap_exists(&old_curbuf); 1049 handle_swap_exists(&old_curbuf);
1065 buf_T *buf; 1065 buf_T *buf;
1066 1066
1067 if (swap_exists_action == SEA_QUIT) 1067 if (swap_exists_action == SEA_QUIT)
1068 { 1068 {
1069 #if defined(FEAT_EVAL) 1069 #if defined(FEAT_EVAL)
1070 /* Reset the error/interrupt/exception state here so that 1070 // Reset the error/interrupt/exception state here so that
1071 * aborting() returns FALSE when closing a buffer. */ 1071 // aborting() returns FALSE when closing a buffer.
1072 enter_cleanup(&cs); 1072 enter_cleanup(&cs);
1073 #endif 1073 #endif
1074 1074
1075 /* User selected Quit at ATTENTION prompt. Go back to previous 1075 // User selected Quit at ATTENTION prompt. Go back to previous
1076 * buffer. If that buffer is gone or the same as the current one, 1076 // buffer. If that buffer is gone or the same as the current one,
1077 * open a new, empty buffer. */ 1077 // open a new, empty buffer.
1078 swap_exists_action = SEA_NONE; /* don't want it again */ 1078 swap_exists_action = SEA_NONE; // don't want it again
1079 swap_exists_did_quit = TRUE; 1079 swap_exists_did_quit = TRUE;
1080 close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE); 1080 close_buffer(curwin, curbuf, DOBUF_UNLOAD, FALSE);
1081 if (old_curbuf == NULL || !bufref_valid(old_curbuf) 1081 if (old_curbuf == NULL || !bufref_valid(old_curbuf)
1082 || old_curbuf->br_buf == curbuf) 1082 || old_curbuf->br_buf == curbuf)
1083 buf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED); 1083 buf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED);
1096 #ifdef FEAT_SYN_HL 1096 #ifdef FEAT_SYN_HL
1097 if (old_tw != curbuf->b_p_tw) 1097 if (old_tw != curbuf->b_p_tw)
1098 check_colorcolumn(curwin); 1098 check_colorcolumn(curwin);
1099 #endif 1099 #endif
1100 } 1100 }
1101 /* If "old_curbuf" is NULL we are in big trouble here... */ 1101 // If "old_curbuf" is NULL we are in big trouble here...
1102 1102
1103 #if defined(FEAT_EVAL) 1103 #if defined(FEAT_EVAL)
1104 /* Restore the error/interrupt/exception state if not discarded by a 1104 // Restore the error/interrupt/exception state if not discarded by a
1105 * new aborting error, interrupt, or uncaught exception. */ 1105 // new aborting error, interrupt, or uncaught exception.
1106 leave_cleanup(&cs); 1106 leave_cleanup(&cs);
1107 #endif 1107 #endif
1108 } 1108 }
1109 else if (swap_exists_action == SEA_RECOVER) 1109 else if (swap_exists_action == SEA_RECOVER)
1110 { 1110 {
1111 #if defined(FEAT_EVAL) 1111 #if defined(FEAT_EVAL)
1112 /* Reset the error/interrupt/exception state here so that 1112 // Reset the error/interrupt/exception state here so that
1113 * aborting() returns FALSE when closing a buffer. */ 1113 // aborting() returns FALSE when closing a buffer.
1114 enter_cleanup(&cs); 1114 enter_cleanup(&cs);
1115 #endif 1115 #endif
1116 1116
1117 /* User selected Recover at ATTENTION prompt. */ 1117 // User selected Recover at ATTENTION prompt.
1118 msg_scroll = TRUE; 1118 msg_scroll = TRUE;
1119 ml_recover(FALSE); 1119 ml_recover(FALSE);
1120 msg_puts("\n"); /* don't overwrite the last message */ 1120 msg_puts("\n"); // don't overwrite the last message
1121 cmdline_row = msg_row; 1121 cmdline_row = msg_row;
1122 do_modelines(0); 1122 do_modelines(0);
1123 1123
1124 #if defined(FEAT_EVAL) 1124 #if defined(FEAT_EVAL)
1125 /* Restore the error/interrupt/exception state if not discarded by a 1125 // Restore the error/interrupt/exception state if not discarded by a
1126 * new aborting error, interrupt, or uncaught exception. */ 1126 // new aborting error, interrupt, or uncaught exception.
1127 leave_cleanup(&cs); 1127 leave_cleanup(&cs);
1128 #endif 1128 #endif
1129 } 1129 }
1130 swap_exists_action = SEA_NONE; 1130 swap_exists_action = SEA_NONE;
1131 } 1131 }
1144 * Returns error message or NULL 1144 * Returns error message or NULL
1145 */ 1145 */
1146 char * 1146 char *
1147 do_bufdel( 1147 do_bufdel(
1148 int command, 1148 int command,
1149 char_u *arg, /* pointer to extra arguments */ 1149 char_u *arg, // pointer to extra arguments
1150 int addr_count, 1150 int addr_count,
1151 int start_bnr, /* first buffer number in a range */ 1151 int start_bnr, // first buffer number in a range
1152 int end_bnr, /* buffer nr or last buffer nr in a range */ 1152 int end_bnr, // buffer nr or last buffer nr in a range
1153 int forceit) 1153 int forceit)
1154 { 1154 {
1155 int do_current = 0; /* delete current buffer? */ 1155 int do_current = 0; // delete current buffer?
1156 int deleted = 0; /* number of buffers deleted */ 1156 int deleted = 0; // number of buffers deleted
1157 char *errormsg = NULL; /* return value */ 1157 char *errormsg = NULL; // return value
1158 int bnr; /* buffer number */ 1158 int bnr; // buffer number
1159 char_u *p; 1159 char_u *p;
1160 1160
1161 if (addr_count == 0) 1161 if (addr_count == 0)
1162 { 1162 {
1163 (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit); 1163 (void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit);
1164 } 1164 }
1165 else 1165 else
1166 { 1166 {
1167 if (addr_count == 2) 1167 if (addr_count == 2)
1168 { 1168 {
1169 if (*arg) /* both range and argument is not allowed */ 1169 if (*arg) // both range and argument is not allowed
1170 return _(e_trailing); 1170 return _(e_trailing);
1171 bnr = start_bnr; 1171 bnr = start_bnr;
1172 } 1172 }
1173 else /* addr_count == 1 */ 1173 else // addr_count == 1
1174 bnr = end_bnr; 1174 bnr = end_bnr;
1175 1175
1176 for ( ;!got_int; ui_breakcheck()) 1176 for ( ;!got_int; ui_breakcheck())
1177 { 1177 {
1178 /* 1178 /*
1193 if (addr_count == 2) 1193 if (addr_count == 2)
1194 { 1194 {
1195 if (++bnr > end_bnr) 1195 if (++bnr > end_bnr)
1196 break; 1196 break;
1197 } 1197 }
1198 else /* addr_count == 1 */ 1198 else // addr_count == 1
1199 { 1199 {
1200 arg = skipwhite(arg); 1200 arg = skipwhite(arg);
1201 if (*arg == NUL) 1201 if (*arg == NUL)
1202 break; 1202 break;
1203 if (!VIM_ISDIGIT(*arg)) 1203 if (!VIM_ISDIGIT(*arg))
1204 { 1204 {
1205 p = skiptowhite_esc(arg); 1205 p = skiptowhite_esc(arg);
1206 bnr = buflist_findpat(arg, p, 1206 bnr = buflist_findpat(arg, p,
1207 command == DOBUF_WIPE || command == DOBUF_WIPE_REUSE, 1207 command == DOBUF_WIPE || command == DOBUF_WIPE_REUSE,
1208 FALSE, FALSE); 1208 FALSE, FALSE);
1209 if (bnr < 0) /* failed */ 1209 if (bnr < 0) // failed
1210 break; 1210 break;
1211 arg = p; 1211 arg = p;
1212 } 1212 }
1213 else 1213 else
1214 bnr = getdigits(&arg); 1214 bnr = getdigits(&arg);
1266 return FAIL; 1266 return FAIL;
1267 } 1267 }
1268 1268
1269 set_bufref(&bufref, buf); 1269 set_bufref(&bufref, buf);
1270 if (close_others) 1270 if (close_others)
1271 /* Close any other windows on this buffer, then make it empty. */ 1271 // Close any other windows on this buffer, then make it empty.
1272 close_windows(buf, TRUE); 1272 close_windows(buf, TRUE);
1273 1273
1274 setpcmark(); 1274 setpcmark();
1275 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, 1275 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE,
1276 forceit ? ECMD_FORCEIT : 0, curwin); 1276 forceit ? ECMD_FORCEIT : 0, curwin);
1306 */ 1306 */
1307 int 1307 int
1308 do_buffer( 1308 do_buffer(
1309 int action, 1309 int action,
1310 int start, 1310 int start,
1311 int dir, /* FORWARD or BACKWARD */ 1311 int dir, // FORWARD or BACKWARD
1312 int count, /* buffer number or number of buffers */ 1312 int count, // buffer number or number of buffers
1313 int forceit) /* TRUE for :...! */ 1313 int forceit) // TRUE for :...!
1314 { 1314 {
1315 buf_T *buf; 1315 buf_T *buf;
1316 buf_T *bp; 1316 buf_T *bp;
1317 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL 1317 int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
1318 || action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE); 1318 || action == DOBUF_WIPE || action == DOBUF_WIPE_REUSE);
1321 { 1321 {
1322 case DOBUF_FIRST: buf = firstbuf; break; 1322 case DOBUF_FIRST: buf = firstbuf; break;
1323 case DOBUF_LAST: buf = lastbuf; break; 1323 case DOBUF_LAST: buf = lastbuf; break;
1324 default: buf = curbuf; break; 1324 default: buf = curbuf; break;
1325 } 1325 }
1326 if (start == DOBUF_MOD) /* find next modified buffer */ 1326 if (start == DOBUF_MOD) // find next modified buffer
1327 { 1327 {
1328 while (count-- > 0) 1328 while (count-- > 0)
1329 { 1329 {
1330 do 1330 do
1331 { 1331 {
1339 { 1339 {
1340 emsg(_("E84: No modified buffer found")); 1340 emsg(_("E84: No modified buffer found"));
1341 return FAIL; 1341 return FAIL;
1342 } 1342 }
1343 } 1343 }
1344 else if (start == DOBUF_FIRST && count) /* find specified buffer number */ 1344 else if (start == DOBUF_FIRST && count) // find specified buffer number
1345 { 1345 {
1346 while (buf != NULL && buf->b_fnum != count) 1346 while (buf != NULL && buf->b_fnum != count)
1347 buf = buf->b_next; 1347 buf = buf->b_next;
1348 } 1348 }
1349 else 1349 else
1350 { 1350 {
1351 bp = NULL; 1351 bp = NULL;
1352 while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) 1352 while (count > 0 || (!unload && !buf->b_p_bl && bp != buf))
1353 { 1353 {
1354 /* remember the buffer where we start, we come back there when all 1354 // remember the buffer where we start, we come back there when all
1355 * buffers are unlisted. */ 1355 // buffers are unlisted.
1356 if (bp == NULL) 1356 if (bp == NULL)
1357 bp = buf; 1357 bp = buf;
1358 if (dir == FORWARD) 1358 if (dir == FORWARD)
1359 { 1359 {
1360 buf = buf->b_next; 1360 buf = buf->b_next;
1365 { 1365 {
1366 buf = buf->b_prev; 1366 buf = buf->b_prev;
1367 if (buf == NULL) 1367 if (buf == NULL)
1368 buf = lastbuf; 1368 buf = lastbuf;
1369 } 1369 }
1370 /* don't count unlisted buffers */ 1370 // don't count unlisted buffers
1371 if (unload || buf->b_p_bl) 1371 if (unload || buf->b_p_bl)
1372 { 1372 {
1373 --count; 1373 --count;
1374 bp = NULL; /* use this buffer as new starting point */ 1374 bp = NULL; // use this buffer as new starting point
1375 } 1375 }
1376 if (bp == buf) 1376 if (bp == buf)
1377 { 1377 {
1378 /* back where we started, didn't find anything. */ 1378 // back where we started, didn't find anything.
1379 emsg(_("E85: There is no listed buffer")); 1379 emsg(_("E85: There is no listed buffer"));
1380 return FAIL; 1380 return FAIL;
1381 } 1381 }
1382 } 1382 }
1383 } 1383 }
1384 1384
1385 if (buf == NULL) /* could not find it */ 1385 if (buf == NULL) // could not find it
1386 { 1386 {
1387 if (start == DOBUF_FIRST) 1387 if (start == DOBUF_FIRST)
1388 { 1388 {
1389 /* don't warn when deleting */ 1389 // don't warn when deleting
1390 if (!unload) 1390 if (!unload)
1391 semsg(_(e_nobufnr), count); 1391 semsg(_(e_nobufnr), count);
1392 } 1392 }
1393 else if (dir == FORWARD) 1393 else if (dir == FORWARD)
1394 emsg(_("E87: Cannot go beyond last buffer")); 1394 emsg(_("E87: Cannot go beyond last buffer"));
1412 if (!can_unload_buffer(buf)) 1412 if (!can_unload_buffer(buf))
1413 return FAIL; 1413 return FAIL;
1414 1414
1415 set_bufref(&bufref, buf); 1415 set_bufref(&bufref, buf);
1416 1416
1417 /* When unloading or deleting a buffer that's already unloaded and 1417 // When unloading or deleting a buffer that's already unloaded and
1418 * unlisted: fail silently. */ 1418 // unlisted: fail silently.
1419 if (action != DOBUF_WIPE && action != DOBUF_WIPE_REUSE 1419 if (action != DOBUF_WIPE && action != DOBUF_WIPE_REUSE
1420 && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) 1420 && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl)
1421 return FAIL; 1421 return FAIL;
1422 1422
1423 if (!forceit && bufIsChanged(buf)) 1423 if (!forceit && bufIsChanged(buf))
1425 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) 1425 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
1426 if ((p_confirm || cmdmod.confirm) && p_write) 1426 if ((p_confirm || cmdmod.confirm) && p_write)
1427 { 1427 {
1428 dialog_changed(buf, FALSE); 1428 dialog_changed(buf, FALSE);
1429 if (!bufref_valid(&bufref)) 1429 if (!bufref_valid(&bufref))
1430 /* Autocommand deleted buffer, oops! It's not changed 1430 // Autocommand deleted buffer, oops! It's not changed
1431 * now. */ 1431 // now.
1432 return FAIL; 1432 return FAIL;
1433 /* If it's still changed fail silently, the dialog already 1433 // If it's still changed fail silently, the dialog already
1434 * mentioned why it fails. */ 1434 // mentioned why it fails.
1435 if (bufIsChanged(buf)) 1435 if (bufIsChanged(buf))
1436 return FAIL; 1436 return FAIL;
1437 } 1437 }
1438 else 1438 else
1439 #endif 1439 #endif
1442 buf->b_fnum); 1442 buf->b_fnum);
1443 return FAIL; 1443 return FAIL;
1444 } 1444 }
1445 } 1445 }
1446 1446
1447 /* When closing the current buffer stop Visual mode. */ 1447 // When closing the current buffer stop Visual mode.
1448 if (buf == curbuf && VIsual_active) 1448 if (buf == curbuf && VIsual_active)
1449 end_visual_mode(); 1449 end_visual_mode();
1450 1450
1451 /* 1451 /*
1452 * If deleting the last (listed) buffer, make it empty. 1452 * If deleting the last (listed) buffer, make it empty.
1490 * Then prefer the buffer we most recently visited. 1490 * Then prefer the buffer we most recently visited.
1491 * Else try to find one that is loaded, after the current buffer, 1491 * Else try to find one that is loaded, after the current buffer,
1492 * then before the current buffer. 1492 * then before the current buffer.
1493 * Finally use any buffer. 1493 * Finally use any buffer.
1494 */ 1494 */
1495 buf = NULL; /* selected buffer */ 1495 buf = NULL; // selected buffer
1496 bp = NULL; /* used when no loaded buffer found */ 1496 bp = NULL; // used when no loaded buffer found
1497 if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) 1497 if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf))
1498 buf = au_new_curbuf.br_buf; 1498 buf = au_new_curbuf.br_buf;
1499 #ifdef FEAT_JUMPLIST 1499 #ifdef FEAT_JUMPLIST
1500 else if (curwin->w_jumplistlen > 0) 1500 else if (curwin->w_jumplistlen > 0)
1501 { 1501 {
1510 { 1510 {
1511 buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum); 1511 buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum);
1512 if (buf != NULL) 1512 if (buf != NULL)
1513 { 1513 {
1514 if (buf == curbuf || !buf->b_p_bl) 1514 if (buf == curbuf || !buf->b_p_bl)
1515 buf = NULL; /* skip current and unlisted bufs */ 1515 buf = NULL; // skip current and unlisted bufs
1516 else if (buf->b_ml.ml_mfp == NULL) 1516 else if (buf->b_ml.ml_mfp == NULL)
1517 { 1517 {
1518 /* skip unloaded buf, but may keep it for later */ 1518 // skip unloaded buf, but may keep it for later
1519 if (bp == NULL) 1519 if (bp == NULL)
1520 bp = buf; 1520 bp = buf;
1521 buf = NULL; 1521 buf = NULL;
1522 } 1522 }
1523 } 1523 }
1524 if (buf != NULL) /* found a valid buffer: stop searching */ 1524 if (buf != NULL) // found a valid buffer: stop searching
1525 break; 1525 break;
1526 /* advance to older entry in jump list */ 1526 // advance to older entry in jump list
1527 if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen) 1527 if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen)
1528 break; 1528 break;
1529 if (--jumpidx < 0) 1529 if (--jumpidx < 0)
1530 jumpidx = curwin->w_jumplistlen - 1; 1530 jumpidx = curwin->w_jumplistlen - 1;
1531 if (jumpidx == forward) /* List exhausted for sure */ 1531 if (jumpidx == forward) // List exhausted for sure
1532 break; 1532 break;
1533 } 1533 }
1534 } 1534 }
1535 #endif 1535 #endif
1536 1536
1537 if (buf == NULL) /* No previous buffer, Try 2'nd approach */ 1537 if (buf == NULL) // No previous buffer, Try 2'nd approach
1538 { 1538 {
1539 forward = TRUE; 1539 forward = TRUE;
1540 buf = curbuf->b_next; 1540 buf = curbuf->b_next;
1541 for (;;) 1541 for (;;)
1542 { 1542 {
1543 if (buf == NULL) 1543 if (buf == NULL)
1544 { 1544 {
1545 if (!forward) /* tried both directions */ 1545 if (!forward) // tried both directions
1546 break; 1546 break;
1547 buf = curbuf->b_prev; 1547 buf = curbuf->b_prev;
1548 forward = FALSE; 1548 forward = FALSE;
1549 continue; 1549 continue;
1550 } 1550 }
1551 /* in non-help buffer, try to skip help buffers, and vv */ 1551 // in non-help buffer, try to skip help buffers, and vv
1552 if (buf->b_help == curbuf->b_help && buf->b_p_bl) 1552 if (buf->b_help == curbuf->b_help && buf->b_p_bl)
1553 { 1553 {
1554 if (buf->b_ml.ml_mfp != NULL) /* found loaded buffer */ 1554 if (buf->b_ml.ml_mfp != NULL) // found loaded buffer
1555 break; 1555 break;
1556 if (bp == NULL) /* remember unloaded buf for later */ 1556 if (bp == NULL) // remember unloaded buf for later
1557 bp = buf; 1557 bp = buf;
1558 } 1558 }
1559 if (forward) 1559 if (forward)
1560 buf = buf->b_next; 1560 buf = buf->b_next;
1561 else 1561 else
1562 buf = buf->b_prev; 1562 buf = buf->b_prev;
1563 } 1563 }
1564 } 1564 }
1565 if (buf == NULL) /* No loaded buffer, use unloaded one */ 1565 if (buf == NULL) // No loaded buffer, use unloaded one
1566 buf = bp; 1566 buf = bp;
1567 if (buf == NULL) /* No loaded buffer, find listed one */ 1567 if (buf == NULL) // No loaded buffer, find listed one
1568 { 1568 {
1569 FOR_ALL_BUFFERS(buf) 1569 FOR_ALL_BUFFERS(buf)
1570 if (buf->b_p_bl && buf != curbuf) 1570 if (buf->b_p_bl && buf != curbuf)
1571 break; 1571 break;
1572 } 1572 }
1573 if (buf == NULL) /* Still no buffer, just take one */ 1573 if (buf == NULL) // Still no buffer, just take one
1574 { 1574 {
1575 if (curbuf->b_next != NULL) 1575 if (curbuf->b_next != NULL)
1576 buf = curbuf->b_next; 1576 buf = curbuf->b_next;
1577 else 1577 else
1578 buf = curbuf->b_prev; 1578 buf = curbuf->b_prev;
1579 } 1579 }
1580 } 1580 }
1581 1581
1582 if (buf == NULL) 1582 if (buf == NULL)
1583 { 1583 {
1584 /* Autocommands must have wiped out all other buffers. Only option 1584 // Autocommands must have wiped out all other buffers. Only option
1585 * now is to make the current buffer empty. */ 1585 // now is to make the current buffer empty.
1586 return empty_curbuf(FALSE, forceit, action); 1586 return empty_curbuf(FALSE, forceit, action);
1587 } 1587 }
1588 1588
1589 /* 1589 /*
1590 * make buf current buffer 1590 * make buf current buffer
1591 */ 1591 */
1592 if (action == DOBUF_SPLIT) /* split window first */ 1592 if (action == DOBUF_SPLIT) // split window first
1593 { 1593 {
1594 /* If 'switchbuf' contains "useopen": jump to first window containing 1594 // If 'switchbuf' contains "useopen": jump to first window containing
1595 * "buf" if one exists */ 1595 // "buf" if one exists
1596 if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) 1596 if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf))
1597 return OK; 1597 return OK;
1598 /* If 'switchbuf' contains "usetab": jump to first window in any tab 1598 // If 'switchbuf' contains "usetab": jump to first window in any tab
1599 * page containing "buf" if one exists */ 1599 // page containing "buf" if one exists
1600 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) 1600 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf))
1601 return OK; 1601 return OK;
1602 if (win_split(0, 0) == FAIL) 1602 if (win_split(0, 0) == FAIL)
1603 return FAIL; 1603 return FAIL;
1604 } 1604 }
1605 1605
1606 /* go to current buffer - nothing to do */ 1606 // go to current buffer - nothing to do
1607 if (buf == curbuf) 1607 if (buf == curbuf)
1608 return OK; 1608 return OK;
1609 1609
1610 /* 1610 /*
1611 * Check if the current buffer may be abandoned. 1611 * Check if the current buffer may be abandoned.
1618 bufref_T bufref; 1618 bufref_T bufref;
1619 1619
1620 set_bufref(&bufref, buf); 1620 set_bufref(&bufref, buf);
1621 dialog_changed(curbuf, FALSE); 1621 dialog_changed(curbuf, FALSE);
1622 if (!bufref_valid(&bufref)) 1622 if (!bufref_valid(&bufref))
1623 /* Autocommand deleted buffer, oops! */ 1623 // Autocommand deleted buffer, oops!
1624 return FAIL; 1624 return FAIL;
1625 } 1625 }
1626 if (bufIsChanged(curbuf)) 1626 if (bufIsChanged(curbuf))
1627 #endif 1627 #endif
1628 { 1628 {
1629 no_write_message(); 1629 no_write_message();
1630 return FAIL; 1630 return FAIL;
1631 } 1631 }
1632 } 1632 }
1633 1633
1634 /* Go to the other buffer. */ 1634 // Go to the other buffer.
1635 set_curbuf(buf, action); 1635 set_curbuf(buf, action);
1636 1636
1637 if (action == DOBUF_SPLIT) 1637 if (action == DOBUF_SPLIT)
1638 RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ 1638 RESET_BINDING(curwin); // reset 'scrollbind' and 'cursorbind'
1639 1639
1640 #if defined(FEAT_EVAL) 1640 #if defined(FEAT_EVAL)
1641 if (aborting()) /* autocmds may abort script processing */ 1641 if (aborting()) // autocmds may abort script processing
1642 return FAIL; 1642 return FAIL;
1643 #endif 1643 #endif
1644 1644
1645 return OK; 1645 return OK;
1646 } 1646 }
1667 bufref_T newbufref; 1667 bufref_T newbufref;
1668 bufref_T prevbufref; 1668 bufref_T prevbufref;
1669 1669
1670 setpcmark(); 1670 setpcmark();
1671 if (!cmdmod.keepalt) 1671 if (!cmdmod.keepalt)
1672 curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */ 1672 curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file
1673 buflist_altfpos(curwin); /* remember curpos */ 1673 buflist_altfpos(curwin); // remember curpos
1674 1674
1675 /* Don't restart Select mode after switching to another buffer. */ 1675 // Don't restart Select mode after switching to another buffer.
1676 VIsual_reselect = FALSE; 1676 VIsual_reselect = FALSE;
1677 1677
1678 /* close_windows() or apply_autocmds() may change curbuf and wipe out "buf" 1678 // close_windows() or apply_autocmds() may change curbuf and wipe out "buf"
1679 */
1680 prevbuf = curbuf; 1679 prevbuf = curbuf;
1681 set_bufref(&prevbufref, prevbuf); 1680 set_bufref(&prevbufref, prevbuf);
1682 set_bufref(&newbufref, buf); 1681 set_bufref(&newbufref, buf);
1683 1682
1684 /* Autocommands may delete the curren buffer and/or the buffer we wan to go 1683 // Autocommands may delete the curren buffer and/or the buffer we wan to go
1685 * to. In those cases don't close the buffer. */ 1684 // to. In those cases don't close the buffer.
1686 if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf) 1685 if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf)
1687 || (bufref_valid(&prevbufref) 1686 || (bufref_valid(&prevbufref)
1688 && bufref_valid(&newbufref) 1687 && bufref_valid(&newbufref)
1689 #ifdef FEAT_EVAL 1688 #ifdef FEAT_EVAL
1690 && !aborting() 1689 && !aborting()
1709 close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf, 1708 close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf,
1710 unload ? action : (action == DOBUF_GOTO 1709 unload ? action : (action == DOBUF_GOTO
1711 && !buf_hide(prevbuf) 1710 && !buf_hide(prevbuf)
1712 && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE); 1711 && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE);
1713 if (curwin != previouswin && win_valid(previouswin)) 1712 if (curwin != previouswin && win_valid(previouswin))
1714 /* autocommands changed curwin, Grr! */ 1713 // autocommands changed curwin, Grr!
1715 curwin = previouswin; 1714 curwin = previouswin;
1716 } 1715 }
1717 } 1716 }
1718 /* An autocommand may have deleted "buf", already entered it (e.g., when 1717 // An autocommand may have deleted "buf", already entered it (e.g., when
1719 * it did ":bunload") or aborted the script processing. 1718 // it did ":bunload") or aborted the script processing.
1720 * If curwin->w_buffer is null, enter_buffer() will make it valid again */ 1719 // If curwin->w_buffer is null, enter_buffer() will make it valid again
1721 if ((buf_valid(buf) && buf != curbuf 1720 if ((buf_valid(buf) && buf != curbuf
1722 #ifdef FEAT_EVAL 1721 #ifdef FEAT_EVAL
1723 && !aborting() 1722 && !aborting()
1724 #endif 1723 #endif
1725 ) || curwin->w_buffer == NULL) 1724 ) || curwin->w_buffer == NULL)
1763 1762
1764 #ifdef FEAT_SYN_HL 1763 #ifdef FEAT_SYN_HL
1765 curwin->w_s = &(curbuf->b_s); 1764 curwin->w_s = &(curbuf->b_s);
1766 #endif 1765 #endif
1767 1766
1768 /* Cursor on first line by default. */ 1767 // Cursor on first line by default.
1769 curwin->w_cursor.lnum = 1; 1768 curwin->w_cursor.lnum = 1;
1770 curwin->w_cursor.col = 0; 1769 curwin->w_cursor.col = 0;
1771 curwin->w_cursor.coladd = 0; 1770 curwin->w_cursor.coladd = 0;
1772 curwin->w_set_curswant = TRUE; 1771 curwin->w_set_curswant = TRUE;
1773 curwin->w_topline_was_set = FALSE; 1772 curwin->w_topline_was_set = FALSE;
1774 1773
1775 /* mark cursor position as being invalid */ 1774 // mark cursor position as being invalid
1776 curwin->w_valid = 0; 1775 curwin->w_valid = 0;
1777 1776
1778 buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.lnum, 1777 buflist_setfpos(curbuf, curwin, curbuf->b_last_cursor.lnum,
1779 curbuf->b_last_cursor.col, TRUE); 1778 curbuf->b_last_cursor.col, TRUE);
1780 1779
1781 /* Make sure the buffer is loaded. */ 1780 // Make sure the buffer is loaded.
1782 if (curbuf->b_ml.ml_mfp == NULL) /* need to load the file */ 1781 if (curbuf->b_ml.ml_mfp == NULL) // need to load the file
1783 { 1782 {
1784 /* If there is no filetype, allow for detecting one. Esp. useful for 1783 // If there is no filetype, allow for detecting one. Esp. useful for
1785 * ":ball" used in a autocommand. If there already is a filetype we 1784 // ":ball" used in a autocommand. If there already is a filetype we
1786 * might prefer to keep it. */ 1785 // might prefer to keep it.
1787 if (*curbuf->b_p_ft == NUL) 1786 if (*curbuf->b_p_ft == NUL)
1788 did_filetype = FALSE; 1787 did_filetype = FALSE;
1789 1788
1790 open_buffer(FALSE, NULL, 0); 1789 open_buffer(FALSE, NULL, 0);
1791 } 1790 }
1803 #endif 1802 #endif
1804 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); 1803 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
1805 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); 1804 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
1806 } 1805 }
1807 1806
1808 /* If autocommands did not change the cursor position, restore cursor lnum 1807 // If autocommands did not change the cursor position, restore cursor lnum
1809 * and possibly cursor col. */ 1808 // and possibly cursor col.
1810 if (curwin->w_cursor.lnum == 1 && inindent(0)) 1809 if (curwin->w_cursor.lnum == 1 && inindent(0))
1811 buflist_getfpos(); 1810 buflist_getfpos();
1812 1811
1813 check_arg_idx(curwin); /* check for valid arg_idx */ 1812 check_arg_idx(curwin); // check for valid arg_idx
1814 #ifdef FEAT_TITLE 1813 #ifdef FEAT_TITLE
1815 maketitle(); 1814 maketitle();
1816 #endif 1815 #endif
1817 /* when autocmds didn't change it */ 1816 // when autocmds didn't change it
1818 if (curwin->w_topline == 1 && !curwin->w_topline_was_set) 1817 if (curwin->w_topline == 1 && !curwin->w_topline_was_set)
1819 scroll_cursor_halfway(FALSE); /* redisplay at correct position */ 1818 scroll_cursor_halfway(FALSE); // redisplay at correct position
1820 1819
1821 #ifdef FEAT_NETBEANS_INTG 1820 #ifdef FEAT_NETBEANS_INTG
1822 /* Send fileOpened event because we've changed buffers. */ 1821 // Send fileOpened event because we've changed buffers.
1823 netbeans_file_activated(curbuf); 1822 netbeans_file_activated(curbuf);
1824 #endif 1823 #endif
1825 1824
1826 /* Change directories when the 'acd' option is set. */ 1825 // Change directories when the 'acd' option is set.
1827 DO_AUTOCHDIR; 1826 DO_AUTOCHDIR;
1828 1827
1829 #ifdef FEAT_KEYMAP 1828 #ifdef FEAT_KEYMAP
1830 if (curbuf->b_kmap_state & KEYMAP_INIT) 1829 if (curbuf->b_kmap_state & KEYMAP_INIT)
1831 (void)keymap_init(); 1830 (void)keymap_init();
1832 #endif 1831 #endif
1833 #ifdef FEAT_SPELL 1832 #ifdef FEAT_SPELL
1834 /* May need to set the spell language. Can only do this after the buffer 1833 // May need to set the spell language. Can only do this after the buffer
1835 * has been properly setup. */ 1834 // has been properly setup.
1836 if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) 1835 if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL)
1837 (void)did_set_spelllang(curwin); 1836 (void)did_set_spelllang(curwin);
1838 #endif 1837 #endif
1839 #ifdef FEAT_VIMINFO 1838 #ifdef FEAT_VIMINFO
1840 curbuf->b_last_used = vim_time(); 1839 curbuf->b_last_used = vim_time();
1935 1934
1936 /* 1935 /*
1937 * If file name already exists in the list, update the entry. 1936 * If file name already exists in the list, update the entry.
1938 */ 1937 */
1939 #ifdef UNIX 1938 #ifdef UNIX
1940 /* On Unix we can use inode numbers when the file exists. Works better 1939 // On Unix we can use inode numbers when the file exists. Works better
1941 * for hard links. */ 1940 // for hard links.
1942 if (sfname == NULL || mch_stat((char *)sfname, &st) < 0) 1941 if (sfname == NULL || mch_stat((char *)sfname, &st) < 0)
1943 st.st_dev = (dev_T)-1; 1942 st.st_dev = (dev_T)-1;
1944 #endif 1943 #endif
1945 if (ffname != NULL && !(flags & (BLN_DUMMY | BLN_NEW)) && (buf = 1944 if (ffname != NULL && !(flags & (BLN_DUMMY | BLN_NEW)) && (buf =
1946 #ifdef UNIX 1945 #ifdef UNIX
1953 vim_free(ffname); 1952 vim_free(ffname);
1954 if (lnum != 0) 1953 if (lnum != 0)
1955 buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE); 1954 buflist_setfpos(buf, curwin, lnum, (colnr_T)0, FALSE);
1956 1955
1957 if ((flags & BLN_NOOPT) == 0) 1956 if ((flags & BLN_NOOPT) == 0)
1958 /* copy the options now, if 'cpo' doesn't have 's' and not done 1957 // copy the options now, if 'cpo' doesn't have 's' and not done
1959 * already */ 1958 // already
1960 buf_copy_options(buf, 0); 1959 buf_copy_options(buf, 0);
1961 1960
1962 if ((flags & BLN_LISTED) && !buf->b_p_bl) 1961 if ((flags & BLN_LISTED) && !buf->b_p_bl)
1963 { 1962 {
1964 bufref_T bufref; 1963 bufref_T bufref;
1985 */ 1984 */
1986 buf = NULL; 1985 buf = NULL;
1987 if ((flags & BLN_CURBUF) && curbuf_reusable()) 1986 if ((flags & BLN_CURBUF) && curbuf_reusable())
1988 { 1987 {
1989 buf = curbuf; 1988 buf = curbuf;
1990 /* It's like this buffer is deleted. Watch out for autocommands that 1989 // It's like this buffer is deleted. Watch out for autocommands that
1991 * change curbuf! If that happens, allocate a new buffer anyway. */ 1990 // change curbuf! If that happens, allocate a new buffer anyway.
1992 if (curbuf->b_p_bl) 1991 if (curbuf->b_p_bl)
1993 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); 1992 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
1994 if (buf == curbuf) 1993 if (buf == curbuf)
1995 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); 1994 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf);
1996 #ifdef FEAT_EVAL 1995 #ifdef FEAT_EVAL
1997 if (aborting()) /* autocmds may abort script processing */ 1996 if (aborting()) // autocmds may abort script processing
1998 return NULL; 1997 return NULL;
1999 #endif 1998 #endif
2000 if (buf == curbuf) 1999 if (buf == curbuf)
2001 { 2000 {
2002 /* Make sure 'bufhidden' and 'buftype' are empty */ 2001 // Make sure 'bufhidden' and 'buftype' are empty
2003 clear_string_option(&buf->b_p_bh); 2002 clear_string_option(&buf->b_p_bh);
2004 clear_string_option(&buf->b_p_bt); 2003 clear_string_option(&buf->b_p_bt);
2005 } 2004 }
2006 } 2005 }
2007 if (buf != curbuf || curbuf == NULL) 2006 if (buf != curbuf || curbuf == NULL)
2011 { 2010 {
2012 vim_free(ffname); 2011 vim_free(ffname);
2013 return NULL; 2012 return NULL;
2014 } 2013 }
2015 #ifdef FEAT_EVAL 2014 #ifdef FEAT_EVAL
2016 /* init b: variables */ 2015 // init b: variables
2017 buf->b_vars = dict_alloc(); 2016 buf->b_vars = dict_alloc();
2018 if (buf->b_vars == NULL) 2017 if (buf->b_vars == NULL)
2019 { 2018 {
2020 vim_free(ffname); 2019 vim_free(ffname);
2021 vim_free(buf); 2020 vim_free(buf);
2048 return NULL; 2047 return NULL;
2049 } 2048 }
2050 2049
2051 if (buf == curbuf) 2050 if (buf == curbuf)
2052 { 2051 {
2053 /* free all things allocated for this buffer */ 2052 // free all things allocated for this buffer
2054 buf_freeall(buf, 0); 2053 buf_freeall(buf, 0);
2055 if (buf != curbuf) /* autocommands deleted the buffer! */ 2054 if (buf != curbuf) // autocommands deleted the buffer!
2056 return NULL; 2055 return NULL;
2057 #if defined(FEAT_EVAL) 2056 #if defined(FEAT_EVAL)
2058 if (aborting()) /* autocmds may abort script processing */ 2057 if (aborting()) // autocmds may abort script processing
2059 return NULL; 2058 return NULL;
2060 #endif 2059 #endif
2061 free_buffer_stuff(buf, FALSE); /* delete local variables et al. */ 2060 free_buffer_stuff(buf, FALSE); // delete local variables et al.
2062 2061
2063 /* Init the options. */ 2062 // Init the options.
2064 buf->b_p_initialized = FALSE; 2063 buf->b_p_initialized = FALSE;
2065 buf_copy_options(buf, BCO_ENTER); 2064 buf_copy_options(buf, BCO_ENTER);
2066 2065
2067 #ifdef FEAT_KEYMAP 2066 #ifdef FEAT_KEYMAP
2068 /* need to reload lmaps and set b:keymap_name */ 2067 // need to reload lmaps and set b:keymap_name
2069 curbuf->b_kmap_state |= KEYMAP_INIT; 2068 curbuf->b_kmap_state |= KEYMAP_INIT;
2070 #endif 2069 #endif
2071 } 2070 }
2072 else 2071 else
2073 { 2072 {
2074 /* 2073 /*
2075 * put new buffer at the end of the buffer list 2074 * put new buffer at the end of the buffer list
2076 */ 2075 */
2077 buf->b_next = NULL; 2076 buf->b_next = NULL;
2078 if (firstbuf == NULL) /* buffer list is empty */ 2077 if (firstbuf == NULL) // buffer list is empty
2079 { 2078 {
2080 buf->b_prev = NULL; 2079 buf->b_prev = NULL;
2081 firstbuf = buf; 2080 firstbuf = buf;
2082 } 2081 }
2083 else /* append new buffer at end of list */ 2082 else // append new buffer at end of list
2084 { 2083 {
2085 lastbuf->b_next = buf; 2084 lastbuf->b_next = buf;
2086 buf->b_prev = lastbuf; 2085 buf->b_prev = lastbuf;
2087 } 2086 }
2088 lastbuf = buf; 2087 lastbuf = buf;
2095 --buf_reuse.ga_len; 2094 --buf_reuse.ga_len;
2096 buf->b_fnum = ((int *)buf_reuse.ga_data)[buf_reuse.ga_len]; 2095 buf->b_fnum = ((int *)buf_reuse.ga_data)[buf_reuse.ga_len];
2097 } 2096 }
2098 else 2097 else
2099 buf->b_fnum = top_file_num++; 2098 buf->b_fnum = top_file_num++;
2100 if (top_file_num < 0) /* wrap around (may cause duplicates) */ 2099 if (top_file_num < 0) // wrap around (may cause duplicates)
2101 { 2100 {
2102 emsg(_("W14: Warning: List of file names overflow")); 2101 emsg(_("W14: Warning: List of file names overflow"));
2103 if (emsg_silent == 0) 2102 if (emsg_silent == 0)
2104 { 2103 {
2105 out_flush(); 2104 out_flush();
2137 buf->b_u_synced = TRUE; 2136 buf->b_u_synced = TRUE;
2138 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED; 2137 buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED;
2139 if (flags & BLN_DUMMY) 2138 if (flags & BLN_DUMMY)
2140 buf->b_flags |= BF_DUMMY; 2139 buf->b_flags |= BF_DUMMY;
2141 buf_clear_file(buf); 2140 buf_clear_file(buf);
2142 clrallmarks(buf); /* clear marks */ 2141 clrallmarks(buf); // clear marks
2143 fmarks_check_names(buf); /* check file marks for this file */ 2142 fmarks_check_names(buf); // check file marks for this file
2144 buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */ 2143 buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; // init 'buflisted'
2145 if (!(flags & BLN_DUMMY)) 2144 if (!(flags & BLN_DUMMY))
2146 { 2145 {
2147 bufref_T bufref; 2146 bufref_T bufref;
2148 2147
2149 /* Tricky: these autocommands may change the buffer list. They could 2148 // Tricky: these autocommands may change the buffer list. They could
2150 * also split the window with re-using the one empty buffer. This may 2149 // also split the window with re-using the one empty buffer. This may
2151 * result in unexpectedly losing the empty buffer. */ 2150 // result in unexpectedly losing the empty buffer.
2152 set_bufref(&bufref, buf); 2151 set_bufref(&bufref, buf);
2153 if (apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf) 2152 if (apply_autocmds(EVENT_BUFNEW, NULL, NULL, FALSE, buf)
2154 && !bufref_valid(&bufref)) 2153 && !bufref_valid(&bufref))
2155 return NULL; 2154 return NULL;
2156 if (flags & BLN_LISTED) 2155 if (flags & BLN_LISTED)
2158 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) 2157 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf)
2159 && !bufref_valid(&bufref)) 2158 && !bufref_valid(&bufref))
2160 return NULL; 2159 return NULL;
2161 } 2160 }
2162 #ifdef FEAT_EVAL 2161 #ifdef FEAT_EVAL
2163 if (aborting()) /* autocmds may abort script processing */ 2162 if (aborting()) // autocmds may abort script processing
2164 return NULL; 2163 return NULL;
2165 #endif 2164 #endif
2166 } 2165 }
2167 2166
2168 return buf; 2167 return buf;
2316 else 2315 else
2317 semsg(_("E92: Buffer %d not found"), n); 2316 semsg(_("E92: Buffer %d not found"), n);
2318 return FAIL; 2317 return FAIL;
2319 } 2318 }
2320 2319
2321 /* if alternate file is the current buffer, nothing to do */ 2320 // if alternate file is the current buffer, nothing to do
2322 if (buf == curbuf) 2321 if (buf == curbuf)
2323 return OK; 2322 return OK;
2324 2323
2325 if (text_locked()) 2324 if (text_locked())
2326 { 2325 {
2328 return FAIL; 2327 return FAIL;
2329 } 2328 }
2330 if (curbuf_locked()) 2329 if (curbuf_locked())
2331 return FAIL; 2330 return FAIL;
2332 2331
2333 /* altfpos may be changed by getfile(), get it now */ 2332 // altfpos may be changed by getfile(), get it now
2334 if (lnum == 0) 2333 if (lnum == 0)
2335 { 2334 {
2336 fpos = buflist_findfpos(buf); 2335 fpos = buflist_findfpos(buf);
2337 lnum = fpos->lnum; 2336 lnum = fpos->lnum;
2338 col = fpos->col; 2337 col = fpos->col;
2340 else 2339 else
2341 col = 0; 2340 col = 0;
2342 2341
2343 if (options & GETF_SWITCH) 2342 if (options & GETF_SWITCH)
2344 { 2343 {
2345 /* If 'switchbuf' contains "useopen": jump to first window containing 2344 // If 'switchbuf' contains "useopen": jump to first window containing
2346 * "buf" if one exists */ 2345 // "buf" if one exists
2347 if (swb_flags & SWB_USEOPEN) 2346 if (swb_flags & SWB_USEOPEN)
2348 wp = buf_jump_open_win(buf); 2347 wp = buf_jump_open_win(buf);
2349 2348
2350 /* If 'switchbuf' contains "usetab": jump to first window in any tab 2349 // If 'switchbuf' contains "usetab": jump to first window in any tab
2351 * page containing "buf" if one exists */ 2350 // page containing "buf" if one exists
2352 if (wp == NULL && (swb_flags & SWB_USETAB)) 2351 if (wp == NULL && (swb_flags & SWB_USETAB))
2353 wp = buf_jump_open_tab(buf); 2352 wp = buf_jump_open_tab(buf);
2354 2353
2355 /* If 'switchbuf' contains "split", "vsplit" or "newtab" and the 2354 // If 'switchbuf' contains "split", "vsplit" or "newtab" and the
2356 * current buffer isn't empty: open new tab or window */ 2355 // current buffer isn't empty: open new tab or window
2357 if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB)) 2356 if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB))
2358 && !BUFEMPTY()) 2357 && !BUFEMPTY())
2359 { 2358 {
2360 if (swb_flags & SWB_NEWTAB) 2359 if (swb_flags & SWB_NEWTAB)
2361 tabpage_new(); 2360 tabpage_new();
2370 if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL, 2369 if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL,
2371 (options & GETF_SETMARK), lnum, forceit))) 2370 (options & GETF_SETMARK), lnum, forceit)))
2372 { 2371 {
2373 --RedrawingDisabled; 2372 --RedrawingDisabled;
2374 2373
2375 /* cursor is at to BOL and w_cursor.lnum is checked due to getfile() */ 2374 // cursor is at to BOL and w_cursor.lnum is checked due to getfile()
2376 if (!p_sol && col != 0) 2375 if (!p_sol && col != 0)
2377 { 2376 {
2378 curwin->w_cursor.col = col; 2377 curwin->w_cursor.col = col;
2379 check_cursor_col(); 2378 check_cursor_col();
2380 curwin->w_cursor.coladd = 0; 2379 curwin->w_cursor.coladd = 0;
2419 buflist_findname_exp(char_u *fname) 2418 buflist_findname_exp(char_u *fname)
2420 { 2419 {
2421 char_u *ffname; 2420 char_u *ffname;
2422 buf_T *buf = NULL; 2421 buf_T *buf = NULL;
2423 2422
2424 /* First make the name into a full path name */ 2423 // First make the name into a full path name
2425 ffname = FullName_save(fname, 2424 ffname = FullName_save(fname,
2426 #ifdef UNIX 2425 #ifdef UNIX
2427 TRUE /* force expansion, get rid of symbolic links */ 2426 TRUE // force expansion, get rid of symbolic links
2428 #else 2427 #else
2429 FALSE 2428 FALSE
2430 #endif 2429 #endif
2431 ); 2430 );
2432 if (ffname != NULL) 2431 if (ffname != NULL)
2466 stat_T *stp) 2465 stat_T *stp)
2467 { 2466 {
2468 #endif 2467 #endif
2469 buf_T *buf; 2468 buf_T *buf;
2470 2469
2471 /* Start at the last buffer, expect to find a match sooner. */ 2470 // Start at the last buffer, expect to find a match sooner.
2472 for (buf = lastbuf; buf != NULL; buf = buf->b_prev) 2471 for (buf = lastbuf; buf != NULL; buf = buf->b_prev)
2473 if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname 2472 if ((buf->b_flags & BF_DUMMY) == 0 && !otherfile_buf(buf, ffname
2474 #ifdef UNIX 2473 #ifdef UNIX
2475 , stp 2474 , stp
2476 #endif 2475 #endif
2485 * Return < 0 for error. 2484 * Return < 0 for error.
2486 */ 2485 */
2487 int 2486 int
2488 buflist_findpat( 2487 buflist_findpat(
2489 char_u *pattern, 2488 char_u *pattern,
2490 char_u *pattern_end, /* pointer to first char after pattern */ 2489 char_u *pattern_end, // pointer to first char after pattern
2491 int unlisted, /* find unlisted buffers */ 2490 int unlisted, // find unlisted buffers
2492 int diffmode UNUSED, /* find diff-mode buffers only */ 2491 int diffmode UNUSED, // find diff-mode buffers only
2493 int curtab_only) /* find buffers in current tab only */ 2492 int curtab_only) // find buffers in current tab only
2494 { 2493 {
2495 buf_T *buf; 2494 buf_T *buf;
2496 int match = -1; 2495 int match = -1;
2497 int find_listed; 2496 int find_listed;
2498 char_u *pat; 2497 char_u *pat;
2528 if (pat == NULL) 2527 if (pat == NULL)
2529 return -1; 2528 return -1;
2530 patend = pat + STRLEN(pat) - 1; 2529 patend = pat + STRLEN(pat) - 1;
2531 toggledollar = (patend > pat && *patend == '$'); 2530 toggledollar = (patend > pat && *patend == '$');
2532 2531
2533 /* First try finding a listed buffer. If not found and "unlisted" 2532 // First try finding a listed buffer. If not found and "unlisted"
2534 * is TRUE, try finding an unlisted buffer. */ 2533 // is TRUE, try finding an unlisted buffer.
2535 find_listed = TRUE; 2534 find_listed = TRUE;
2536 for (;;) 2535 for (;;)
2537 { 2536 {
2538 for (attempt = 0; attempt <= 3; ++attempt) 2537 for (attempt = 0; attempt <= 3; ++attempt)
2539 { 2538 {
2540 regmatch_T regmatch; 2539 regmatch_T regmatch;
2541 2540
2542 /* may add '^' and '$' */ 2541 // may add '^' and '$'
2543 if (toggledollar) 2542 if (toggledollar)
2544 *patend = (attempt < 2) ? NUL : '$'; /* add/remove '$' */ 2543 *patend = (attempt < 2) ? NUL : '$'; // add/remove '$'
2545 p = pat; 2544 p = pat;
2546 if (*p == '^' && !(attempt & 1)) /* add/remove '^' */ 2545 if (*p == '^' && !(attempt & 1)) // add/remove '^'
2547 ++p; 2546 ++p;
2548 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0); 2547 regmatch.regprog = vim_regcomp(p, p_magic ? RE_MAGIC : 0);
2549 if (regmatch.regprog == NULL) 2548 if (regmatch.regprog == NULL)
2550 { 2549 {
2551 vim_free(pat); 2550 vim_free(pat);
2559 #endif 2558 #endif
2560 && buflist_match(&regmatch, buf, FALSE) != NULL) 2559 && buflist_match(&regmatch, buf, FALSE) != NULL)
2561 { 2560 {
2562 if (curtab_only) 2561 if (curtab_only)
2563 { 2562 {
2564 /* Ignore the match if the buffer is not open in 2563 // Ignore the match if the buffer is not open in
2565 * the current tab. */ 2564 // the current tab.
2566 win_T *wp; 2565 win_T *wp;
2567 2566
2568 FOR_ALL_WINDOWS(wp) 2567 FOR_ALL_WINDOWS(wp)
2569 if (wp->w_buffer == buf) 2568 if (wp->w_buffer == buf)
2570 break; 2569 break;
2571 if (wp == NULL) 2570 if (wp == NULL)
2572 continue; 2571 continue;
2573 } 2572 }
2574 if (match >= 0) /* already found a match */ 2573 if (match >= 0) // already found a match
2575 { 2574 {
2576 match = -2; 2575 match = -2;
2577 break; 2576 break;
2578 } 2577 }
2579 match = buf->b_fnum; /* remember first match */ 2578 match = buf->b_fnum; // remember first match
2580 } 2579 }
2581 2580
2582 vim_regfree(regmatch.regprog); 2581 vim_regfree(regmatch.regprog);
2583 if (match >= 0) /* found one match */ 2582 if (match >= 0) // found one match
2584 break; 2583 break;
2585 } 2584 }
2586 2585
2587 /* Only search for unlisted buffers if there was no match with 2586 // Only search for unlisted buffers if there was no match with
2588 * a listed buffer. */ 2587 // a listed buffer.
2589 if (!unlisted || !find_listed || match != -1) 2588 if (!unlisted || !find_listed || match != -1)
2590 break; 2589 break;
2591 find_listed = FALSE; 2590 find_listed = FALSE;
2592 } 2591 }
2593 2592
2628 char_u *patc; 2627 char_u *patc;
2629 #ifdef FEAT_VIMINFO 2628 #ifdef FEAT_VIMINFO
2630 bufmatch_T *matches = NULL; 2629 bufmatch_T *matches = NULL;
2631 #endif 2630 #endif
2632 2631
2633 *num_file = 0; /* return values in case of FAIL */ 2632 *num_file = 0; // return values in case of FAIL
2634 *file = NULL; 2633 *file = NULL;
2635 2634
2636 /* Make a copy of "pat" and change "^" to "\(^\|[\/]\)". */ 2635 // Make a copy of "pat" and change "^" to "\(^\|[\/]\)".
2637 if (*pat == '^') 2636 if (*pat == '^')
2638 { 2637 {
2639 patc = alloc(STRLEN(pat) + 11); 2638 patc = alloc(STRLEN(pat) + 11);
2640 if (patc == NULL) 2639 if (patc == NULL)
2641 return FAIL; 2640 return FAIL;
2652 for (attempt = 0; attempt <= 1; ++attempt) 2651 for (attempt = 0; attempt <= 1; ++attempt)
2653 { 2652 {
2654 regmatch_T regmatch; 2653 regmatch_T regmatch;
2655 2654
2656 if (attempt > 0 && patc == pat) 2655 if (attempt > 0 && patc == pat)
2657 break; /* there was no anchor, no need to try again */ 2656 break; // there was no anchor, no need to try again
2658 regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC); 2657 regmatch.regprog = vim_regcomp(patc + attempt * 11, RE_MAGIC);
2659 if (regmatch.regprog == NULL) 2658 if (regmatch.regprog == NULL)
2660 { 2659 {
2661 if (patc != pat) 2660 if (patc != pat)
2662 vim_free(patc); 2661 vim_free(patc);
2670 for (round = 1; round <= 2; ++round) 2669 for (round = 1; round <= 2; ++round)
2671 { 2670 {
2672 count = 0; 2671 count = 0;
2673 FOR_ALL_BUFFERS(buf) 2672 FOR_ALL_BUFFERS(buf)
2674 { 2673 {
2675 if (!buf->b_p_bl) /* skip unlisted buffers */ 2674 if (!buf->b_p_bl) // skip unlisted buffers
2676 continue; 2675 continue;
2677 p = buflist_match(&regmatch, buf, p_wic); 2676 p = buflist_match(&regmatch, buf, p_wic);
2678 if (p != NULL) 2677 if (p != NULL)
2679 { 2678 {
2680 if (round == 1) 2679 if (round == 1)
2696 #endif 2695 #endif
2697 (*file)[count++] = p; 2696 (*file)[count++] = p;
2698 } 2697 }
2699 } 2698 }
2700 } 2699 }
2701 if (count == 0) /* no match found, break here */ 2700 if (count == 0) // no match found, break here
2702 break; 2701 break;
2703 if (round == 1) 2702 if (round == 1)
2704 { 2703 {
2705 *file = ALLOC_MULT(char_u *, count); 2704 *file = ALLOC_MULT(char_u *, count);
2706 if (*file == NULL) 2705 if (*file == NULL)
2715 matches = ALLOC_MULT(bufmatch_T, count); 2714 matches = ALLOC_MULT(bufmatch_T, count);
2716 #endif 2715 #endif
2717 } 2716 }
2718 } 2717 }
2719 vim_regfree(regmatch.regprog); 2718 vim_regfree(regmatch.regprog);
2720 if (count) /* match(es) found, break here */ 2719 if (count) // match(es) found, break here
2721 break; 2720 break;
2722 } 2721 }
2723 2722
2724 if (patc != pat) 2723 if (patc != pat)
2725 vim_free(patc); 2724 vim_free(patc);
2755 */ 2754 */
2756 static char_u * 2755 static char_u *
2757 buflist_match( 2756 buflist_match(
2758 regmatch_T *rmp, 2757 regmatch_T *rmp,
2759 buf_T *buf, 2758 buf_T *buf,
2760 int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ 2759 int ignore_case) // when TRUE ignore case, when FALSE use 'fic'
2761 { 2760 {
2762 char_u *match; 2761 char_u *match;
2763 2762
2764 /* First try the short file name, then the long file name. */ 2763 // First try the short file name, then the long file name.
2765 match = fname_match(rmp, buf->b_sfname, ignore_case); 2764 match = fname_match(rmp, buf->b_sfname, ignore_case);
2766 if (match == NULL) 2765 if (match == NULL)
2767 match = fname_match(rmp, buf->b_ffname, ignore_case); 2766 match = fname_match(rmp, buf->b_ffname, ignore_case);
2768 2767
2769 return match; 2768 return match;
2775 */ 2774 */
2776 static char_u * 2775 static char_u *
2777 fname_match( 2776 fname_match(
2778 regmatch_T *rmp, 2777 regmatch_T *rmp,
2779 char_u *name, 2778 char_u *name,
2780 int ignore_case) /* when TRUE ignore case, when FALSE use 'fic' */ 2779 int ignore_case) // when TRUE ignore case, when FALSE use 'fic'
2781 { 2780 {
2782 char_u *match = NULL; 2781 char_u *match = NULL;
2783 char_u *p; 2782 char_u *p;
2784 2783
2785 if (name != NULL) 2784 if (name != NULL)
2786 { 2785 {
2787 /* Ignore case when 'fileignorecase' or the argument is set. */ 2786 // Ignore case when 'fileignorecase' or the argument is set.
2788 rmp->rm_ic = p_fic || ignore_case; 2787 rmp->rm_ic = p_fic || ignore_case;
2789 if (vim_regexec(rmp, name, (colnr_T)0)) 2788 if (vim_regexec(rmp, name, (colnr_T)0))
2790 match = name; 2789 match = name;
2791 else 2790 else
2792 { 2791 {
2793 /* Replace $(HOME) with '~' and try matching again. */ 2792 // Replace $(HOME) with '~' and try matching again.
2794 p = home_replace_save(NULL, name); 2793 p = home_replace_save(NULL, name);
2795 if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) 2794 if (p != NULL && vim_regexec(rmp, p, (colnr_T)0))
2796 match = name; 2795 match = name;
2797 vim_free(p); 2796 vim_free(p);
2798 } 2797 }
2829 */ 2828 */
2830 char_u * 2829 char_u *
2831 buflist_nr2name( 2830 buflist_nr2name(
2832 int n, 2831 int n,
2833 int fullname, 2832 int fullname,
2834 int helptail) /* for help buffers return tail only */ 2833 int helptail) // for help buffers return tail only
2835 { 2834 {
2836 buf_T *buf; 2835 buf_T *buf;
2837 2836
2838 buf = buflist_findnr(n); 2837 buf = buflist_findnr(n);
2839 if (buf == NULL) 2838 if (buf == NULL)
2860 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next) 2859 for (wip = buf->b_wininfo; wip != NULL; wip = wip->wi_next)
2861 if (wip->wi_win == win) 2860 if (wip->wi_win == win)
2862 break; 2861 break;
2863 if (wip == NULL) 2862 if (wip == NULL)
2864 { 2863 {
2865 /* allocate a new entry */ 2864 // allocate a new entry
2866 wip = ALLOC_CLEAR_ONE(wininfo_T); 2865 wip = ALLOC_CLEAR_ONE(wininfo_T);
2867 if (wip == NULL) 2866 if (wip == NULL)
2868 return; 2867 return;
2869 wip->wi_win = win; 2868 wip->wi_win = win;
2870 if (lnum == 0) /* set lnum even when it's 0 */ 2869 if (lnum == 0) // set lnum even when it's 0
2871 lnum = 1; 2870 lnum = 1;
2872 } 2871 }
2873 else 2872 else
2874 { 2873 {
2875 /* remove the entry from the list */ 2874 // remove the entry from the list
2876 if (wip->wi_prev) 2875 if (wip->wi_prev)
2877 wip->wi_prev->wi_next = wip->wi_next; 2876 wip->wi_prev->wi_next = wip->wi_next;
2878 else 2877 else
2879 buf->b_wininfo = wip->wi_next; 2878 buf->b_wininfo = wip->wi_next;
2880 if (wip->wi_next) 2879 if (wip->wi_next)
2892 wip->wi_fpos.lnum = lnum; 2891 wip->wi_fpos.lnum = lnum;
2893 wip->wi_fpos.col = col; 2892 wip->wi_fpos.col = col;
2894 } 2893 }
2895 if (copy_options) 2894 if (copy_options)
2896 { 2895 {
2897 /* Save the window-specific option values. */ 2896 // Save the window-specific option values.
2898 copy_winopt(&win->w_onebuf_opt, &wip->wi_opt); 2897 copy_winopt(&win->w_onebuf_opt, &wip->wi_opt);
2899 #ifdef FEAT_FOLDING 2898 #ifdef FEAT_FOLDING
2900 wip->wi_fold_manual = win->w_fold_manual; 2899 wip->wi_fold_manual = win->w_fold_manual;
2901 cloneFoldGrowArray(&win->w_folds, &wip->wi_folds); 2900 cloneFoldGrowArray(&win->w_folds, &wip->wi_folds);
2902 #endif 2901 #endif
2903 wip->wi_optset = TRUE; 2902 wip->wi_optset = TRUE;
2904 } 2903 }
2905 2904
2906 /* insert the entry in front of the list */ 2905 // insert the entry in front of the list
2907 wip->wi_next = buf->b_wininfo; 2906 wip->wi_next = buf->b_wininfo;
2908 buf->b_wininfo = wip; 2907 buf->b_wininfo = wip;
2909 wip->wi_prev = NULL; 2908 wip->wi_prev = NULL;
2910 if (wip->wi_next) 2909 if (wip->wi_next)
2911 wip->wi_next->wi_prev = wip; 2910 wip->wi_next->wi_prev = wip;
2924 win_T *wp; 2923 win_T *wp;
2925 2924
2926 if (wip->wi_opt.wo_diff) 2925 if (wip->wi_opt.wo_diff)
2927 { 2926 {
2928 FOR_ALL_WINDOWS(wp) 2927 FOR_ALL_WINDOWS(wp)
2929 /* return FALSE when it's a window in the current tab page, thus 2928 // return FALSE when it's a window in the current tab page, thus
2930 * the buffer was in diff mode here */ 2929 // the buffer was in diff mode here
2931 if (wip->wi_win == wp) 2930 if (wip->wi_win == wp)
2932 return FALSE; 2931 return FALSE;
2933 return TRUE; 2932 return TRUE;
2934 } 2933 }
2935 return FALSE; 2934 return FALSE;
2956 && (!skip_diff_buffer || !wininfo_other_tab_diff(wip)) 2955 && (!skip_diff_buffer || !wininfo_other_tab_diff(wip))
2957 #endif 2956 #endif
2958 ) 2957 )
2959 break; 2958 break;
2960 2959
2961 /* If no wininfo for curwin, use the first in the list (that doesn't have 2960 // If no wininfo for curwin, use the first in the list (that doesn't have
2962 * 'diff' set and is in another tab page). */ 2961 // 'diff' set and is in another tab page).
2963 if (wip == NULL) 2962 if (wip == NULL)
2964 { 2963 {
2965 #ifdef FEAT_DIFF 2964 #ifdef FEAT_DIFF
2966 if (skip_diff_buffer) 2965 if (skip_diff_buffer)
2967 { 2966 {
2994 2993
2995 wip = find_wininfo(buf, TRUE); 2994 wip = find_wininfo(buf, TRUE);
2996 if (wip != NULL && wip->wi_win != NULL 2995 if (wip != NULL && wip->wi_win != NULL
2997 && wip->wi_win != curwin && wip->wi_win->w_buffer == buf) 2996 && wip->wi_win != curwin && wip->wi_win->w_buffer == buf)
2998 { 2997 {
2999 /* The buffer is currently displayed in the window: use the actual 2998 // The buffer is currently displayed in the window: use the actual
3000 * option values instead of the saved (possibly outdated) values. */ 2999 // option values instead of the saved (possibly outdated) values.
3001 win_T *wp = wip->wi_win; 3000 win_T *wp = wip->wi_win;
3002 3001
3003 copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt); 3002 copy_winopt(&wp->w_onebuf_opt, &curwin->w_onebuf_opt);
3004 #ifdef FEAT_FOLDING 3003 #ifdef FEAT_FOLDING
3005 curwin->w_fold_manual = wp->w_fold_manual; 3004 curwin->w_fold_manual = wp->w_fold_manual;
3007 cloneFoldGrowArray(&wp->w_folds, &curwin->w_folds); 3006 cloneFoldGrowArray(&wp->w_folds, &curwin->w_folds);
3008 #endif 3007 #endif
3009 } 3008 }
3010 else if (wip != NULL && wip->wi_optset) 3009 else if (wip != NULL && wip->wi_optset)
3011 { 3010 {
3012 /* the buffer was displayed in the current window earlier */ 3011 // the buffer was displayed in the current window earlier
3013 copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt); 3012 copy_winopt(&wip->wi_opt, &curwin->w_onebuf_opt);
3014 #ifdef FEAT_FOLDING 3013 #ifdef FEAT_FOLDING
3015 curwin->w_fold_manual = wip->wi_fold_manual; 3014 curwin->w_fold_manual = wip->wi_fold_manual;
3016 curwin->w_foldinvalid = TRUE; 3015 curwin->w_foldinvalid = TRUE;
3017 cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds); 3016 cloneFoldGrowArray(&wip->wi_folds, &curwin->w_folds);
3019 } 3018 }
3020 else 3019 else
3021 copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt); 3020 copy_winopt(&curwin->w_allbuf_opt, &curwin->w_onebuf_opt);
3022 3021
3023 #ifdef FEAT_FOLDING 3022 #ifdef FEAT_FOLDING
3024 /* Set 'foldlevel' to 'foldlevelstart' if it's not negative. */ 3023 // Set 'foldlevel' to 'foldlevelstart' if it's not negative.
3025 if (p_fdls >= 0) 3024 if (p_fdls >= 0)
3026 curwin->w_p_fdl = p_fdls; 3025 curwin->w_p_fdl = p_fdls;
3027 #endif 3026 #endif
3028 after_copy_winopt(curwin); 3027 after_copy_winopt(curwin);
3029 } 3028 }
3101 { 3100 {
3102 #ifdef FEAT_TERMINAL 3101 #ifdef FEAT_TERMINAL
3103 job_running = term_job_running(buf->b_term); 3102 job_running = term_job_running(buf->b_term);
3104 job_none_open = job_running && term_none_open(buf->b_term); 3103 job_none_open = job_running && term_none_open(buf->b_term);
3105 #endif 3104 #endif
3106 /* skip unlisted buffers, unless ! was used */ 3105 // skip unlisted buffers, unless ! was used
3107 if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u')) 3106 if ((!buf->b_p_bl && !eap->forceit && !vim_strchr(eap->arg, 'u'))
3108 || (vim_strchr(eap->arg, 'u') && buf->b_p_bl) 3107 || (vim_strchr(eap->arg, 'u') && buf->b_p_bl)
3109 || (vim_strchr(eap->arg, '+') 3108 || (vim_strchr(eap->arg, '+')
3110 && ((buf->b_flags & BF_READERR) || !bufIsChanged(buf))) 3109 && ((buf->b_flags & BF_READERR) || !bufIsChanged(buf)))
3111 || (vim_strchr(eap->arg, 'a') 3110 || (vim_strchr(eap->arg, 'a')
3141 { 3140 {
3142 if (term_none_open(buf->b_term)) 3141 if (term_none_open(buf->b_term))
3143 ro_char = '?'; 3142 ro_char = '?';
3144 else 3143 else
3145 ro_char = 'R'; 3144 ro_char = 'R';
3146 changed_char = ' '; /* bufIsChanged() returns TRUE to avoid 3145 changed_char = ' '; // bufIsChanged() returns TRUE to avoid
3147 * closing, but it's not actually changed. */ 3146 // closing, but it's not actually changed.
3148 } 3147 }
3149 else if (buf->b_term != NULL) 3148 else if (buf->b_term != NULL)
3150 ro_char = 'F'; 3149 ro_char = 'F';
3151 else 3150 else
3152 #endif 3151 #endif
3164 changed_char, 3163 changed_char,
3165 NameBuff); 3164 NameBuff);
3166 if (len > IOSIZE - 20) 3165 if (len > IOSIZE - 20)
3167 len = IOSIZE - 20; 3166 len = IOSIZE - 20;
3168 3167
3169 /* put "line 999" in column 40 or after the file name */ 3168 // put "line 999" in column 40 or after the file name
3170 i = 40 - vim_strsize(IObuff); 3169 i = 40 - vim_strsize(IObuff);
3171 do 3170 do
3172 IObuff[len++] = ' '; 3171 IObuff[len++] = ' ';
3173 while (--i > 0 && len < IOSIZE - 18); 3172 while (--i > 0 && len < IOSIZE - 18);
3174 #ifdef FEAT_VIMINFO 3173 #ifdef FEAT_VIMINFO
3178 #endif 3177 #endif
3179 vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), 3178 vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len),
3180 _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum 3179 _("line %ld"), buf == curbuf ? curwin->w_cursor.lnum
3181 : (long)buflist_findlnum(buf)); 3180 : (long)buflist_findlnum(buf));
3182 msg_outtrans(IObuff); 3181 msg_outtrans(IObuff);
3183 out_flush(); /* output one line at a time */ 3182 out_flush(); // output one line at a time
3184 ui_breakcheck(); 3183 ui_breakcheck();
3185 } 3184 }
3186 3185
3187 #ifdef FEAT_VIMINFO 3186 #ifdef FEAT_VIMINFO
3188 if (buflist_data) 3187 if (buflist_data)
3224 int 3223 int
3225 setfname( 3224 setfname(
3226 buf_T *buf, 3225 buf_T *buf,
3227 char_u *ffname_arg, 3226 char_u *ffname_arg,
3228 char_u *sfname_arg, 3227 char_u *sfname_arg,
3229 int message) /* give message when buffer already exists */ 3228 int message) // give message when buffer already exists
3230 { 3229 {
3231 char_u *ffname = ffname_arg; 3230 char_u *ffname = ffname_arg;
3232 char_u *sfname = sfname_arg; 3231 char_u *sfname = sfname_arg;
3233 buf_T *obuf = NULL; 3232 buf_T *obuf = NULL;
3234 #ifdef UNIX 3233 #ifdef UNIX
3235 stat_T st; 3234 stat_T st;
3236 #endif 3235 #endif
3237 3236
3238 if (ffname == NULL || *ffname == NUL) 3237 if (ffname == NULL || *ffname == NUL)
3239 { 3238 {
3240 /* Removing the name. */ 3239 // Removing the name.
3241 if (buf->b_sfname != buf->b_ffname) 3240 if (buf->b_sfname != buf->b_ffname)
3242 VIM_CLEAR(buf->b_sfname); 3241 VIM_CLEAR(buf->b_sfname);
3243 else 3242 else
3244 buf->b_sfname = NULL; 3243 buf->b_sfname = NULL;
3245 VIM_CLEAR(buf->b_ffname); 3244 VIM_CLEAR(buf->b_ffname);
3247 st.st_dev = (dev_T)-1; 3246 st.st_dev = (dev_T)-1;
3248 #endif 3247 #endif
3249 } 3248 }
3250 else 3249 else
3251 { 3250 {
3252 fname_expand(buf, &ffname, &sfname); /* will allocate ffname */ 3251 fname_expand(buf, &ffname, &sfname); // will allocate ffname
3253 if (ffname == NULL) /* out of memory */ 3252 if (ffname == NULL) // out of memory
3254 return FAIL; 3253 return FAIL;
3255 3254
3256 /* 3255 /*
3257 * if the file name is already used in another buffer: 3256 * if the file name is already used in another buffer:
3258 * - if the buffer is loaded, fail 3257 * - if the buffer is loaded, fail
3268 #else 3267 #else
3269 obuf = buflist_findname(ffname); 3268 obuf = buflist_findname(ffname);
3270 #endif 3269 #endif
3271 if (obuf != NULL && obuf != buf) 3270 if (obuf != NULL && obuf != buf)
3272 { 3271 {
3273 if (obuf->b_ml.ml_mfp != NULL) /* it's loaded, fail */ 3272 if (obuf->b_ml.ml_mfp != NULL) // it's loaded, fail
3274 { 3273 {
3275 if (message) 3274 if (message)
3276 emsg(_("E95: Buffer with this name already exists")); 3275 emsg(_("E95: Buffer with this name already exists"));
3277 vim_free(ffname); 3276 vim_free(ffname);
3278 return FAIL; 3277 return FAIL;
3279 } 3278 }
3280 /* delete from the list */ 3279 // delete from the list
3281 close_buffer(NULL, obuf, DOBUF_WIPE, FALSE); 3280 close_buffer(NULL, obuf, DOBUF_WIPE, FALSE);
3282 } 3281 }
3283 sfname = vim_strsave(sfname); 3282 sfname = vim_strsave(sfname);
3284 if (ffname == NULL || sfname == NULL) 3283 if (ffname == NULL || sfname == NULL)
3285 { 3284 {
3286 vim_free(sfname); 3285 vim_free(sfname);
3287 vim_free(ffname); 3286 vim_free(ffname);
3288 return FAIL; 3287 return FAIL;
3289 } 3288 }
3290 #ifdef USE_FNAME_CASE 3289 #ifdef USE_FNAME_CASE
3291 fname_case(sfname, 0); /* set correct case for short file name */ 3290 fname_case(sfname, 0); // set correct case for short file name
3292 #endif 3291 #endif
3293 if (buf->b_sfname != buf->b_ffname) 3292 if (buf->b_sfname != buf->b_ffname)
3294 vim_free(buf->b_sfname); 3293 vim_free(buf->b_sfname);
3295 vim_free(buf->b_ffname); 3294 vim_free(buf->b_ffname);
3296 buf->b_ffname = ffname; 3295 buf->b_ffname = ffname;
3329 if (buf->b_sfname != buf->b_ffname) 3328 if (buf->b_sfname != buf->b_ffname)
3330 vim_free(buf->b_sfname); 3329 vim_free(buf->b_sfname);
3331 vim_free(buf->b_ffname); 3330 vim_free(buf->b_ffname);
3332 buf->b_ffname = vim_strsave(name); 3331 buf->b_ffname = vim_strsave(name);
3333 buf->b_sfname = NULL; 3332 buf->b_sfname = NULL;
3334 /* Allocate ffname and expand into full path. Also resolves .lnk 3333 // Allocate ffname and expand into full path. Also resolves .lnk
3335 * files on Win32. */ 3334 // files on Win32.
3336 fname_expand(buf, &buf->b_ffname, &buf->b_sfname); 3335 fname_expand(buf, &buf->b_ffname, &buf->b_sfname);
3337 buf->b_fname = buf->b_sfname; 3336 buf->b_fname = buf->b_sfname;
3338 } 3337 }
3339 } 3338 }
3340 3339
3350 */ 3349 */
3351 if (buf->b_ml.ml_mfp != NULL) 3350 if (buf->b_ml.ml_mfp != NULL)
3352 ml_setname(buf); 3351 ml_setname(buf);
3353 3352
3354 if (curwin->w_buffer == buf) 3353 if (curwin->w_buffer == buf)
3355 check_arg_idx(curwin); /* check file name for arg list */ 3354 check_arg_idx(curwin); // check file name for arg list
3356 #ifdef FEAT_TITLE 3355 #ifdef FEAT_TITLE
3357 maketitle(); /* set window title */ 3356 maketitle(); // set window title
3358 #endif 3357 #endif
3359 status_redraw_all(); /* status lines need to be redrawn */ 3358 status_redraw_all(); // status lines need to be redrawn
3360 fmarks_check_names(buf); /* check named file marks */ 3359 fmarks_check_names(buf); // check named file marks
3361 ml_timestamp(buf); /* reset timestamp */ 3360 ml_timestamp(buf); // reset timestamp
3362 } 3361 }
3363 3362
3364 /* 3363 /*
3365 * set alternate file name for current window 3364 * set alternate file name for current window
3366 * 3365 *
3373 char_u *sfname, 3372 char_u *sfname,
3374 linenr_T lnum) 3373 linenr_T lnum)
3375 { 3374 {
3376 buf_T *buf; 3375 buf_T *buf;
3377 3376
3378 /* Create a buffer. 'buflisted' is not set if it's a new buffer */ 3377 // Create a buffer. 'buflisted' is not set if it's a new buffer
3379 buf = buflist_new(ffname, sfname, lnum, 0); 3378 buf = buflist_new(ffname, sfname, lnum, 0);
3380 if (buf != NULL && !cmdmod.keepalt) 3379 if (buf != NULL && !cmdmod.keepalt)
3381 curwin->w_alt_fnum = buf->b_fnum; 3380 curwin->w_alt_fnum = buf->b_fnum;
3382 return buf; 3381 return buf;
3383 } 3382 }
3386 * Get alternate file name for current window. 3385 * Get alternate file name for current window.
3387 * Return NULL if there isn't any, and give error message if requested. 3386 * Return NULL if there isn't any, and give error message if requested.
3388 */ 3387 */
3389 char_u * 3388 char_u *
3390 getaltfname( 3389 getaltfname(
3391 int errmsg) /* give error message */ 3390 int errmsg) // give error message
3392 { 3391 {
3393 char_u *fname; 3392 char_u *fname;
3394 linenr_T dummy; 3393 linenr_T dummy;
3395 3394
3396 if (buflist_name_nr(0, &fname, &dummy) == FAIL) 3395 if (buflist_name_nr(0, &fname, &dummy) == FAIL)
3469 #ifdef UNIX 3468 #ifdef UNIX
3470 , stat_T *stp 3469 , stat_T *stp
3471 #endif 3470 #endif
3472 ) 3471 )
3473 { 3472 {
3474 /* no name is different */ 3473 // no name is different
3475 if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL) 3474 if (ffname == NULL || *ffname == NUL || buf->b_ffname == NULL)
3476 return TRUE; 3475 return TRUE;
3477 if (fnamecmp(ffname, buf->b_ffname) == 0) 3476 if (fnamecmp(ffname, buf->b_ffname) == 0)
3478 return FALSE; 3477 return FALSE;
3479 #ifdef UNIX 3478 #ifdef UNIX
3480 { 3479 {
3481 stat_T st; 3480 stat_T st;
3482 3481
3483 /* If no stat_T given, get it now */ 3482 // If no stat_T given, get it now
3484 if (stp == NULL) 3483 if (stp == NULL)
3485 { 3484 {
3486 if (!buf->b_dev_valid || mch_stat((char *)ffname, &st) < 0) 3485 if (!buf->b_dev_valid || mch_stat((char *)ffname, &st) < 0)
3487 st.st_dev = (dev_T)-1; 3486 st.st_dev = (dev_T)-1;
3488 stp = &st; 3487 stp = &st;
3489 } 3488 }
3490 /* Use dev/ino to check if the files are the same, even when the names 3489 // Use dev/ino to check if the files are the same, even when the names
3491 * are different (possible with links). Still need to compare the 3490 // are different (possible with links). Still need to compare the
3492 * name above, for when the file doesn't exist yet. 3491 // name above, for when the file doesn't exist yet.
3493 * Problem: The dev/ino changes when a file is deleted (and created 3492 // Problem: The dev/ino changes when a file is deleted (and created
3494 * again) and remains the same when renamed/moved. We don't want to 3493 // again) and remains the same when renamed/moved. We don't want to
3495 * mch_stat() each buffer each time, that would be too slow. Get the 3494 // mch_stat() each buffer each time, that would be too slow. Get the
3496 * dev/ino again when they appear to match, but not when they appear 3495 // dev/ino again when they appear to match, but not when they appear
3497 * to be different: Could skip a buffer when it's actually the same 3496 // to be different: Could skip a buffer when it's actually the same
3498 * file. */ 3497 // file.
3499 if (buf_same_ino(buf, stp)) 3498 if (buf_same_ino(buf, stp))
3500 { 3499 {
3501 buf_setino(buf); 3500 buf_setino(buf);
3502 if (buf_same_ino(buf, stp)) 3501 if (buf_same_ino(buf, stp))
3503 return FALSE; 3502 return FALSE;
3544 /* 3543 /*
3545 * Print info about the current buffer. 3544 * Print info about the current buffer.
3546 */ 3545 */
3547 void 3546 void
3548 fileinfo( 3547 fileinfo(
3549 int fullname, /* when non-zero print full path */ 3548 int fullname, // when non-zero print full path
3550 int shorthelp, 3549 int shorthelp,
3551 int dont_truncate) 3550 int dont_truncate)
3552 { 3551 {
3553 char_u *name; 3552 char_u *name;
3554 int n; 3553 int n;
3558 3557
3559 buffer = alloc(IOSIZE); 3558 buffer = alloc(IOSIZE);
3560 if (buffer == NULL) 3559 if (buffer == NULL)
3561 return; 3560 return;
3562 3561
3563 if (fullname > 1) /* 2 CTRL-G: include buffer number */ 3562 if (fullname > 1) // 2 CTRL-G: include buffer number
3564 { 3563 {
3565 vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum); 3564 vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
3566 p = buffer + STRLEN(buffer); 3565 p = buffer + STRLEN(buffer);
3567 } 3566 }
3568 else 3567 else
3598 curbuf->b_p_ro ? (shortmess(SHM_RO) ? _("[RO]") 3597 curbuf->b_p_ro ? (shortmess(SHM_RO) ? _("[RO]")
3599 : _("[readonly]")) : "", 3598 : _("[readonly]")) : "",
3600 (curbufIsChanged() || (curbuf->b_flags & BF_WRITE_MASK) 3599 (curbufIsChanged() || (curbuf->b_flags & BF_WRITE_MASK)
3601 || curbuf->b_p_ro) ? 3600 || curbuf->b_p_ro) ?
3602 " " : ""); 3601 " " : "");
3603 /* With 32 bit longs and more than 21,474,836 lines multiplying by 100 3602 // With 32 bit longs and more than 21,474,836 lines multiplying by 100
3604 * causes an overflow, thus for large numbers divide instead. */ 3603 // causes an overflow, thus for large numbers divide instead.
3605 if (curwin->w_cursor.lnum > 1000000L) 3604 if (curwin->w_cursor.lnum > 1000000L)
3606 n = (int)(((long)curwin->w_cursor.lnum) / 3605 n = (int)(((long)curwin->w_cursor.lnum) /
3607 ((long)curbuf->b_ml.ml_line_count / 100L)); 3606 ((long)curbuf->b_ml.ml_line_count / 100L));
3608 else 3607 else
3609 n = (int)(((long)curwin->w_cursor.lnum * 100L) / 3608 n = (int)(((long)curwin->w_cursor.lnum * 100L) /
3610 (long)curbuf->b_ml.ml_line_count); 3609 (long)curbuf->b_ml.ml_line_count);
3611 if (curbuf->b_ml.ml_flags & ML_EMPTY) 3610 if (curbuf->b_ml.ml_flags & ML_EMPTY)
3612 vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg)); 3611 vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg));
3613 #ifdef FEAT_CMDL_INFO 3612 #ifdef FEAT_CMDL_INFO
3614 else if (p_ru) 3613 else if (p_ru)
3615 /* Current line and column are already on the screen -- webb */ 3614 // Current line and column are already on the screen -- webb
3616 vim_snprintf_add(buffer, IOSIZE, 3615 vim_snprintf_add(buffer, IOSIZE,
3617 NGETTEXT("%ld line --%d%%--", "%ld lines --%d%%--", 3616 NGETTEXT("%ld line --%d%%--", "%ld lines --%d%%--",
3618 curbuf->b_ml.ml_line_count), 3617 curbuf->b_ml.ml_line_count),
3619 (long)curbuf->b_ml.ml_line_count, n); 3618 (long)curbuf->b_ml.ml_line_count, n);
3620 #endif 3619 #endif
3634 (void)append_arg_number(curwin, (char_u *)buffer, IOSIZE, 3633 (void)append_arg_number(curwin, (char_u *)buffer, IOSIZE,
3635 !shortmess(SHM_FILE)); 3634 !shortmess(SHM_FILE));
3636 3635
3637 if (dont_truncate) 3636 if (dont_truncate)
3638 { 3637 {
3639 /* Temporarily set msg_scroll to avoid the message being truncated. 3638 // Temporarily set msg_scroll to avoid the message being truncated.
3640 * First call msg_start() to get the message in the right place. */ 3639 // First call msg_start() to get the message in the right place.
3641 msg_start(); 3640 msg_start();
3642 n = msg_scroll; 3641 n = msg_scroll;
3643 msg_scroll = TRUE; 3642 msg_scroll = TRUE;
3644 msg(buffer); 3643 msg(buffer);
3645 msg_scroll = n; 3644 msg_scroll = n;
3646 } 3645 }
3647 else 3646 else
3648 { 3647 {
3649 p = (char *)msg_trunc_attr(buffer, FALSE, 0); 3648 p = (char *)msg_trunc_attr(buffer, FALSE, 0);
3650 if (restart_edit != 0 || (msg_scrolled && !need_wait_return)) 3649 if (restart_edit != 0 || (msg_scrolled && !need_wait_return))
3651 /* Need to repeat the message after redrawing when: 3650 // Need to repeat the message after redrawing when:
3652 * - When restart_edit is set (otherwise there will be a delay 3651 // - When restart_edit is set (otherwise there will be a delay
3653 * before redrawing). 3652 // before redrawing).
3654 * - When the screen was scrolled but there is no wait-return 3653 // - When the screen was scrolled but there is no wait-return
3655 * prompt. */ 3654 // prompt.
3656 set_keep_msg((char_u *)p, 0); 3655 set_keep_msg((char_u *)p, 0);
3657 } 3656 }
3658 3657
3659 vim_free(buffer); 3658 vim_free(buffer);
3660 } 3659 }
3691 char_u buf[IOSIZE]; 3690 char_u buf[IOSIZE];
3692 int off; 3691 int off;
3693 3692
3694 if (!redrawing()) 3693 if (!redrawing())
3695 { 3694 {
3696 /* Postpone updating the title when 'lazyredraw' is set. */ 3695 // Postpone updating the title when 'lazyredraw' is set.
3697 need_maketitle = TRUE; 3696 need_maketitle = TRUE;
3698 return; 3697 return;
3699 } 3698 }
3700 3699
3701 need_maketitle = FALSE; 3700 need_maketitle = FALSE;
3736 #endif 3735 #endif
3737 title_str = p_titlestring; 3736 title_str = p_titlestring;
3738 } 3737 }
3739 else 3738 else
3740 { 3739 {
3741 /* format: "fname + (path) (1 of 2) - VIM" */ 3740 // format: "fname + (path) (1 of 2) - VIM"
3742 3741
3743 #define SPACE_FOR_FNAME (IOSIZE - 100) 3742 #define SPACE_FOR_FNAME (IOSIZE - 100)
3744 #define SPACE_FOR_DIR (IOSIZE - 20) 3743 #define SPACE_FOR_DIR (IOSIZE - 20)
3745 #define SPACE_FOR_ARGNR (IOSIZE - 10) /* at least room for " - VIM" */ 3744 #define SPACE_FOR_ARGNR (IOSIZE - 10) // at least room for " - VIM"
3746 if (curbuf->b_fname == NULL) 3745 if (curbuf->b_fname == NULL)
3747 vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME); 3746 vim_strncpy(buf, (char_u *)_("[No Name]"), SPACE_FOR_FNAME);
3748 #ifdef FEAT_TERMINAL 3747 #ifdef FEAT_TERMINAL
3749 else if (curbuf->b_term != NULL) 3748 else if (curbuf->b_term != NULL)
3750 { 3749 {
3779 #ifdef FEAT_TERMINAL 3778 #ifdef FEAT_TERMINAL
3780 && curbuf->b_term == NULL 3779 && curbuf->b_term == NULL
3781 #endif 3780 #endif
3782 ) 3781 )
3783 { 3782 {
3784 /* Get path of file, replace home dir with ~ */ 3783 // Get path of file, replace home dir with ~
3785 off = (int)STRLEN(buf); 3784 off = (int)STRLEN(buf);
3786 buf[off++] = ' '; 3785 buf[off++] = ' ';
3787 buf[off++] = '('; 3786 buf[off++] = '(';
3788 home_replace(curbuf, curbuf->b_ffname, 3787 home_replace(curbuf, curbuf->b_ffname,
3789 buf + off, SPACE_FOR_DIR - off, TRUE); 3788 buf + off, SPACE_FOR_DIR - off, TRUE);
3790 #ifdef BACKSLASH_IN_FILENAME 3789 #ifdef BACKSLASH_IN_FILENAME
3791 /* avoid "c:/name" to be reduced to "c" */ 3790 // avoid "c:/name" to be reduced to "c"
3792 if (isalpha(buf[off]) && buf[off + 1] == ':') 3791 if (isalpha(buf[off]) && buf[off + 1] == ':')
3793 off += 2; 3792 off += 2;
3794 #endif 3793 #endif
3795 /* remove the file name */ 3794 // remove the file name
3796 p = gettail_sep(buf + off); 3795 p = gettail_sep(buf + off);
3797 if (p == buf + off) 3796 if (p == buf + off)
3798 { 3797 {
3799 /* must be a help buffer */ 3798 // must be a help buffer
3800 vim_strncpy(buf + off, (char_u *)_("help"), 3799 vim_strncpy(buf + off, (char_u *)_("help"),
3801 (size_t)(SPACE_FOR_DIR - off - 1)); 3800 (size_t)(SPACE_FOR_DIR - off - 1));
3802 } 3801 }
3803 else 3802 else
3804 *p = NUL; 3803 *p = NUL;
3805 3804
3806 /* Translate unprintable chars and concatenate. Keep some 3805 // Translate unprintable chars and concatenate. Keep some
3807 * room for the server name. When there is no room (very long 3806 // room for the server name. When there is no room (very long
3808 * file name) use (...). */ 3807 // file name) use (...).
3809 if (off < SPACE_FOR_DIR) 3808 if (off < SPACE_FOR_DIR)
3810 { 3809 {
3811 p = transstr(buf + off); 3810 p = transstr(buf + off);
3812 vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off)); 3811 vim_strncpy(buf + off, p, (size_t)(SPACE_FOR_DIR - off));
3813 vim_free(p); 3812 vim_free(p);
3832 #endif 3831 #endif
3833 STRCAT(buf, " - VIM"); 3832 STRCAT(buf, " - VIM");
3834 3833
3835 if (maxlen > 0) 3834 if (maxlen > 0)
3836 { 3835 {
3837 /* make it shorter by removing a bit in the middle */ 3836 // make it shorter by removing a bit in the middle
3838 if (vim_strsize(buf) > maxlen) 3837 if (vim_strsize(buf) > maxlen)
3839 trunc_string(buf, buf, maxlen, IOSIZE); 3838 trunc_string(buf, buf, maxlen, IOSIZE);
3840 } 3839 }
3841 } 3840 }
3842 } 3841 }
3871 } 3870 }
3872 else 3871 else
3873 { 3872 {
3874 if (buf_spname(curbuf) != NULL) 3873 if (buf_spname(curbuf) != NULL)
3875 p = buf_spname(curbuf); 3874 p = buf_spname(curbuf);
3876 else /* use file name only in icon */ 3875 else // use file name only in icon
3877 p = gettail(curbuf->b_ffname); 3876 p = gettail(curbuf->b_ffname);
3878 *icon_str = NUL; 3877 *icon_str = NUL;
3879 /* Truncate name at 100 bytes. */ 3878 // Truncate name at 100 bytes.
3880 len = (int)STRLEN(p); 3879 len = (int)STRLEN(p);
3881 if (len > 100) 3880 if (len > 100)
3882 { 3881 {
3883 len -= 100; 3882 len -= 100;
3884 if (has_mbyte) 3883 if (has_mbyte)
3939 vim_free(lasttitle); 3938 vim_free(lasttitle);
3940 vim_free(lasticon); 3939 vim_free(lasticon);
3941 } 3940 }
3942 # endif 3941 # endif
3943 3942
3944 #endif /* FEAT_TITLE */ 3943 #endif // FEAT_TITLE
3945 3944
3946 #if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO) 3945 #if defined(FEAT_STL_OPT) || defined(FEAT_GUI_TABLINE) || defined(PROTO)
3947 /* 3946 /*
3948 * Build a string from the status line items in "fmt". 3947 * Build a string from the status line items in "fmt".
3949 * Return length of string in screen cells. 3948 * Return length of string in screen cells.
3959 * or truncated if too long, fillchar is used for all whitespace. 3958 * or truncated if too long, fillchar is used for all whitespace.
3960 */ 3959 */
3961 int 3960 int
3962 build_stl_str_hl( 3961 build_stl_str_hl(
3963 win_T *wp, 3962 win_T *wp,
3964 char_u *out, /* buffer to write into != NameBuff */ 3963 char_u *out, // buffer to write into != NameBuff
3965 size_t outlen, /* length of out[] */ 3964 size_t outlen, // length of out[]
3966 char_u *fmt, 3965 char_u *fmt,
3967 int use_sandbox UNUSED, /* "fmt" was set insecurely, use sandbox */ 3966 int use_sandbox UNUSED, // "fmt" was set insecurely, use sandbox
3968 int fillchar, 3967 int fillchar,
3969 int maxwidth, 3968 int maxwidth,
3970 struct stl_hlrec *hltab, /* return: HL attributes (can be NULL) */ 3969 struct stl_hlrec *hltab, // return: HL attributes (can be NULL)
3971 struct stl_hlrec *tabtab) /* return: tab page nrs (can be NULL) */ 3970 struct stl_hlrec *tabtab) // return: tab page nrs (can be NULL)
3972 { 3971 {
3973 linenr_T lnum; 3972 linenr_T lnum;
3974 size_t len; 3973 size_t len;
3975 char_u *p; 3974 char_u *p;
3976 char_u *s; 3975 char_u *s;
4048 } 4047 }
4049 #endif 4048 #endif
4050 4049
4051 if (fillchar == 0) 4050 if (fillchar == 0)
4052 fillchar = ' '; 4051 fillchar = ' ';
4053 /* Can't handle a multi-byte fill character yet. */ 4052 // Can't handle a multi-byte fill character yet.
4054 else if (mb_char2len(fillchar) > 1) 4053 else if (mb_char2len(fillchar) > 1)
4055 fillchar = '-'; 4054 fillchar = '-';
4056 4055
4057 // The cursor in windows other than the current one isn't always 4056 // The cursor in windows other than the current one isn't always
4058 // up-to-date, esp. because of autocommands and timers. 4057 // up-to-date, esp. because of autocommands and timers.
4089 prevchar_isitem = FALSE; 4088 prevchar_isitem = FALSE;
4090 for (s = usefmt; *s; ) 4089 for (s = usefmt; *s; )
4091 { 4090 {
4092 if (curitem == STL_MAX_ITEM) 4091 if (curitem == STL_MAX_ITEM)
4093 { 4092 {
4094 /* There are too many items. Add the error code to the statusline 4093 // There are too many items. Add the error code to the statusline
4095 * to give the user a hint about what went wrong. */ 4094 // to give the user a hint about what went wrong.
4096 if (p + 6 < out + outlen) 4095 if (p + 6 < out + outlen)
4097 { 4096 {
4098 mch_memmove(p, " E541", (size_t)5); 4097 mch_memmove(p, " E541", (size_t)5);
4099 p += 5; 4098 p += 5;
4100 } 4099 }
4114 4113
4115 /* 4114 /*
4116 * Handle one '%' item. 4115 * Handle one '%' item.
4117 */ 4116 */
4118 s++; 4117 s++;
4119 if (*s == NUL) /* ignore trailing % */ 4118 if (*s == NUL) // ignore trailing %
4120 break; 4119 break;
4121 if (*s == '%') 4120 if (*s == '%')
4122 { 4121 {
4123 if (p + 1 >= out + outlen) 4122 if (p + 1 >= out + outlen)
4124 break; 4123 break;
4153 *p = NUL; 4152 *p = NUL;
4154 l = vim_strsize(t); 4153 l = vim_strsize(t);
4155 if (curitem > groupitem[groupdepth] + 1 4154 if (curitem > groupitem[groupdepth] + 1
4156 && item[groupitem[groupdepth]].minwid == 0) 4155 && item[groupitem[groupdepth]].minwid == 0)
4157 { 4156 {
4158 /* remove group if all items are empty and highlight group 4157 // remove group if all items are empty and highlight group
4159 * doesn't change */ 4158 // doesn't change
4160 group_start_userhl = group_end_userhl = 0; 4159 group_start_userhl = group_end_userhl = 0;
4161 for (n = groupitem[groupdepth] - 1; n >= 0; n--) 4160 for (n = groupitem[groupdepth] - 1; n >= 0; n--)
4162 { 4161 {
4163 if (item[n].type == Highlight) 4162 if (item[n].type == Highlight)
4164 { 4163 {
4179 l = 0; 4178 l = 0;
4180 } 4179 }
4181 } 4180 }
4182 if (l > item[groupitem[groupdepth]].maxwid) 4181 if (l > item[groupitem[groupdepth]].maxwid)
4183 { 4182 {
4184 /* truncate, remove n bytes of text at the start */ 4183 // truncate, remove n bytes of text at the start
4185 if (has_mbyte) 4184 if (has_mbyte)
4186 { 4185 {
4187 /* Find the first character that should be included. */ 4186 // Find the first character that should be included.
4188 n = 0; 4187 n = 0;
4189 while (l >= item[groupitem[groupdepth]].maxwid) 4188 while (l >= item[groupitem[groupdepth]].maxwid)
4190 { 4189 {
4191 l -= ptr2cells(t + n); 4190 l -= ptr2cells(t + n);
4192 n += (*mb_ptr2len)(t + n); 4191 n += (*mb_ptr2len)(t + n);
4201 4200
4202 // Fill up space left over by half a double-wide char. 4201 // Fill up space left over by half a double-wide char.
4203 while (++l < item[groupitem[groupdepth]].minwid) 4202 while (++l < item[groupitem[groupdepth]].minwid)
4204 *p++ = fillchar; 4203 *p++ = fillchar;
4205 4204
4206 /* correct the start of the items for the truncation */ 4205 // correct the start of the items for the truncation
4207 for (l = groupitem[groupdepth] + 1; l < curitem; l++) 4206 for (l = groupitem[groupdepth] + 1; l < curitem; l++)
4208 { 4207 {
4209 item[l].start -= n; 4208 item[l].start -= n;
4210 if (item[l].start < t) 4209 if (item[l].start < t)
4211 item[l].start = t; 4210 item[l].start = t;
4212 } 4211 }
4213 } 4212 }
4214 else if (abs(item[groupitem[groupdepth]].minwid) > l) 4213 else if (abs(item[groupitem[groupdepth]].minwid) > l)
4215 { 4214 {
4216 /* fill */ 4215 // fill
4217 n = item[groupitem[groupdepth]].minwid; 4216 n = item[groupitem[groupdepth]].minwid;
4218 if (n < 0) 4217 if (n < 0)
4219 { 4218 {
4220 /* fill by appending characters */ 4219 // fill by appending characters
4221 n = 0 - n; 4220 n = 0 - n;
4222 while (l++ < n && p + 1 < out + outlen) 4221 while (l++ < n && p + 1 < out + outlen)
4223 *p++ = fillchar; 4222 *p++ = fillchar;
4224 } 4223 }
4225 else 4224 else
4226 { 4225 {
4227 /* fill by inserting characters */ 4226 // fill by inserting characters
4228 mch_memmove(t + n - l, t, (size_t)(p - t)); 4227 mch_memmove(t + n - l, t, (size_t)(p - t));
4229 l = n - l; 4228 l = n - l;
4230 if (p + l >= out + outlen) 4229 if (p + l >= out + outlen)
4231 l = (long)((out + outlen) - p - 1); 4230 l = (long)((out + outlen) - p - 1);
4232 p += l; 4231 p += l;
4253 l = -1; 4252 l = -1;
4254 } 4253 }
4255 if (VIM_ISDIGIT(*s)) 4254 if (VIM_ISDIGIT(*s))
4256 { 4255 {
4257 minwid = (int)getdigits(&s); 4256 minwid = (int)getdigits(&s);
4258 if (minwid < 0) /* overflow */ 4257 if (minwid < 0) // overflow
4259 minwid = 0; 4258 minwid = 0;
4260 } 4259 }
4261 if (*s == STL_USER_HL) 4260 if (*s == STL_USER_HL)
4262 { 4261 {
4263 item[curitem].type = Highlight; 4262 item[curitem].type = Highlight;
4271 { 4270 {
4272 if (*s == STL_TABCLOSENR) 4271 if (*s == STL_TABCLOSENR)
4273 { 4272 {
4274 if (minwid == 0) 4273 if (minwid == 0)
4275 { 4274 {
4276 /* %X ends the close label, go back to the previously 4275 // %X ends the close label, go back to the previously
4277 * define tab label nr. */ 4276 // define tab label nr.
4278 for (n = curitem - 1; n >= 0; --n) 4277 for (n = curitem - 1; n >= 0; --n)
4279 if (item[n].type == TabPage && item[n].minwid >= 0) 4278 if (item[n].type == TabPage && item[n].minwid >= 0)
4280 { 4279 {
4281 minwid = item[n].minwid; 4280 minwid = item[n].minwid;
4282 break; 4281 break;
4283 } 4282 }
4284 } 4283 }
4285 else 4284 else
4286 /* close nrs are stored as negative values */ 4285 // close nrs are stored as negative values
4287 minwid = - minwid; 4286 minwid = - minwid;
4288 } 4287 }
4289 item[curitem].type = TabPage; 4288 item[curitem].type = TabPage;
4290 item[curitem].start = p; 4289 item[curitem].start = p;
4291 item[curitem].minwid = minwid; 4290 item[curitem].minwid = minwid;
4297 { 4296 {
4298 s++; 4297 s++;
4299 if (VIM_ISDIGIT(*s)) 4298 if (VIM_ISDIGIT(*s))
4300 { 4299 {
4301 maxwid = (int)getdigits(&s); 4300 maxwid = (int)getdigits(&s);
4302 if (maxwid <= 0) /* overflow */ 4301 if (maxwid <= 0) // overflow
4303 maxwid = 50; 4302 maxwid = 50;
4304 } 4303 }
4305 } 4304 }
4306 minwid = (minwid > 50 ? 50 : minwid) * l; 4305 minwid = (minwid > 50 ? 50 : minwid) * l;
4307 if (*s == '(') 4306 if (*s == '(')
4320 s++; 4319 s++;
4321 continue; 4320 continue;
4322 } 4321 }
4323 opt = *s++; 4322 opt = *s++;
4324 4323
4325 /* OK - now for the real work */ 4324 // OK - now for the real work
4326 base = 'D'; 4325 base = 'D';
4327 itemisflag = FALSE; 4326 itemisflag = FALSE;
4328 fillable = TRUE; 4327 fillable = TRUE;
4329 num = -1; 4328 num = -1;
4330 str = NULL; 4329 str = NULL;
4331 switch (opt) 4330 switch (opt)
4332 { 4331 {
4333 case STL_FILEPATH: 4332 case STL_FILEPATH:
4334 case STL_FULLPATH: 4333 case STL_FULLPATH:
4335 case STL_FILENAME: 4334 case STL_FILENAME:
4336 fillable = FALSE; /* don't change ' ' to fillchar */ 4335 fillable = FALSE; // don't change ' ' to fillchar
4337 if (buf_spname(wp->w_buffer) != NULL) 4336 if (buf_spname(wp->w_buffer) != NULL)
4338 vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1); 4337 vim_strncpy(NameBuff, buf_spname(wp->w_buffer), MAXPATHL - 1);
4339 else 4338 else
4340 { 4339 {
4341 t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname 4340 t = (opt == STL_FULLPATH) ? wp->w_buffer->b_ffname
4347 str = NameBuff; 4346 str = NameBuff;
4348 else 4347 else
4349 str = gettail(NameBuff); 4348 str = gettail(NameBuff);
4350 break; 4349 break;
4351 4350
4352 case STL_VIM_EXPR: /* '{' */ 4351 case STL_VIM_EXPR: // '{'
4353 itemisflag = TRUE; 4352 itemisflag = TRUE;
4354 t = p; 4353 t = p;
4355 while (*s != '}' && *s != NUL && p + 1 < out + outlen) 4354 while (*s != '}' && *s != NUL && p + 1 < out + outlen)
4356 *p++ = *s++; 4355 *p++ = *s++;
4357 if (*s != '}') /* missing '}' or out of space */ 4356 if (*s != '}') // missing '}' or out of space
4358 break; 4357 break;
4359 s++; 4358 s++;
4360 *p = 0; 4359 *p = 0;
4361 p = t; 4360 p = t;
4362 4361
4410 ? 0 : (int)wp->w_cursor.col + 1; 4409 ? 0 : (int)wp->w_cursor.col + 1;
4411 break; 4410 break;
4412 4411
4413 case STL_VIRTCOL: 4412 case STL_VIRTCOL:
4414 case STL_VIRTCOL_ALT: 4413 case STL_VIRTCOL_ALT:
4415 /* In list mode virtcol needs to be recomputed */ 4414 // In list mode virtcol needs to be recomputed
4416 virtcol = wp->w_virtcol; 4415 virtcol = wp->w_virtcol;
4417 if (wp->w_p_list && lcs_tab1 == NUL) 4416 if (wp->w_p_list && lcs_tab1 == NUL)
4418 { 4417 {
4419 wp->w_p_list = FALSE; 4418 wp->w_p_list = FALSE;
4420 getvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); 4419 getvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
4421 wp->w_p_list = TRUE; 4420 wp->w_p_list = TRUE;
4422 } 4421 }
4423 ++virtcol; 4422 ++virtcol;
4424 /* Don't display %V if it's the same as %c. */ 4423 // Don't display %V if it's the same as %c.
4425 if (opt == STL_VIRTCOL_ALT 4424 if (opt == STL_VIRTCOL_ALT
4426 && (virtcol == (colnr_T)(!(State & INSERT) && empty_line 4425 && (virtcol == (colnr_T)(!(State & INSERT) && empty_line
4427 ? 0 : (int)wp->w_cursor.col + 1))) 4426 ? 0 : (int)wp->w_cursor.col + 1)))
4428 break; 4427 break;
4429 num = (long)virtcol; 4428 num = (long)virtcol;
4463 num = wp->w_buffer->b_fnum; 4462 num = wp->w_buffer->b_fnum;
4464 break; 4463 break;
4465 4464
4466 case STL_OFFSET_X: 4465 case STL_OFFSET_X:
4467 base = 'X'; 4466 base = 'X';
4468 /* FALLTHROUGH */ 4467 // FALLTHROUGH
4469 case STL_OFFSET: 4468 case STL_OFFSET:
4470 #ifdef FEAT_BYTEOFF 4469 #ifdef FEAT_BYTEOFF
4471 l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL); 4470 l = ml_find_line_or_offset(wp->w_buffer, wp->w_cursor.lnum, NULL);
4472 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ? 4471 num = (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) || l < 0 ?
4473 0L : l + 1 + (!(State & INSERT) && empty_line ? 4472 0L : l + 1 + (!(State & INSERT) && empty_line ?
4475 #endif 4474 #endif
4476 break; 4475 break;
4477 4476
4478 case STL_BYTEVAL_X: 4477 case STL_BYTEVAL_X:
4479 base = 'X'; 4478 base = 'X';
4480 /* FALLTHROUGH */ 4479 // FALLTHROUGH
4481 case STL_BYTEVAL: 4480 case STL_BYTEVAL:
4482 num = byteval; 4481 num = byteval;
4483 if (num == NL) 4482 if (num == NL)
4484 num = 0; 4483 num = 0;
4485 else if (num == CAR && get_fileformat(wp->w_buffer) == EOL_MAC) 4484 else if (num == CAR && get_fileformat(wp->w_buffer) == EOL_MAC)
4605 } 4604 }
4606 if (minwid > 0) 4605 if (minwid > 0)
4607 { 4606 {
4608 for (; l < minwid && p + 1 < out + outlen; l++) 4607 for (; l < minwid && p + 1 < out + outlen; l++)
4609 { 4608 {
4610 /* Don't put a "-" in front of a digit. */ 4609 // Don't put a "-" in front of a digit.
4611 if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t)) 4610 if (l + 1 == minwid && fillchar == '-' && VIM_ISDIGIT(*t))
4612 *p++ = ' '; 4611 *p++ = ' ';
4613 else 4612 else
4614 *p++ = fillchar; 4613 *p++ = fillchar;
4615 } 4614 }
4618 else 4617 else
4619 minwid *= -1; 4618 minwid *= -1;
4620 while (*t && p + 1 < out + outlen) 4619 while (*t && p + 1 < out + outlen)
4621 { 4620 {
4622 *p++ = *t++; 4621 *p++ = *t++;
4623 /* Change a space by fillchar, unless fillchar is '-' and a 4622 // Change a space by fillchar, unless fillchar is '-' and a
4624 * digit follows. */ 4623 // digit follows.
4625 if (fillable && p[-1] == ' ' 4624 if (fillable && p[-1] == ' '
4626 && (!VIM_ISDIGIT(*t) || fillchar != '-')) 4625 && (!VIM_ISDIGIT(*t) || fillchar != '-'))
4627 p[-1] = fillchar; 4626 p[-1] = fillchar;
4628 } 4627 }
4629 for (; l < minwid && p + 1 < out + outlen; l++) 4628 for (; l < minwid && p + 1 < out + outlen; l++)
4633 { 4632 {
4634 int nbase = (base == 'D' ? 10 : (base == 'O' ? 8 : 16)); 4633 int nbase = (base == 'D' ? 10 : (base == 'O' ? 8 : 16));
4635 char_u nstr[20]; 4634 char_u nstr[20];
4636 4635
4637 if (p + 20 >= out + outlen) 4636 if (p + 20 >= out + outlen)
4638 break; /* not sufficient space */ 4637 break; // not sufficient space
4639 prevchar_isitem = TRUE; 4638 prevchar_isitem = TRUE;
4640 t = nstr; 4639 t = nstr;
4641 if (opt == STL_VIRTCOL_ALT) 4640 if (opt == STL_VIRTCOL_ALT)
4642 { 4641 {
4643 *t++ = '-'; 4642 *t++ = '-';
4677 4676
4678 if (opt == STL_VIM_EXPR) 4677 if (opt == STL_VIM_EXPR)
4679 vim_free(str); 4678 vim_free(str);
4680 4679
4681 if (num >= 0 || (!itemisflag && str && *str)) 4680 if (num >= 0 || (!itemisflag && str && *str))
4682 prevchar_isflag = FALSE; /* Item not NULL, but not a flag */ 4681 prevchar_isflag = FALSE; // Item not NULL, but not a flag
4683 curitem++; 4682 curitem++;
4684 } 4683 }
4685 *p = NUL; 4684 *p = NUL;
4686 itemcnt = curitem; 4685 itemcnt = curitem;
4687 4686
4691 #endif 4690 #endif
4692 4691
4693 width = vim_strsize(out); 4692 width = vim_strsize(out);
4694 if (maxwidth > 0 && width > maxwidth) 4693 if (maxwidth > 0 && width > maxwidth)
4695 { 4694 {
4696 /* Result is too long, must truncate somewhere. */ 4695 // Result is too long, must truncate somewhere.
4697 l = 0; 4696 l = 0;
4698 if (itemcnt == 0) 4697 if (itemcnt == 0)
4699 s = out; 4698 s = out;
4700 else 4699 else
4701 { 4700 {
4702 for ( ; l < itemcnt; l++) 4701 for ( ; l < itemcnt; l++)
4703 if (item[l].type == Trunc) 4702 if (item[l].type == Trunc)
4704 { 4703 {
4705 /* Truncate at %< item. */ 4704 // Truncate at %< item.
4706 s = item[l].start; 4705 s = item[l].start;
4707 break; 4706 break;
4708 } 4707 }
4709 if (l == itemcnt) 4708 if (l == itemcnt)
4710 { 4709 {
4711 /* No %< item, truncate first item. */ 4710 // No %< item, truncate first item.
4712 s = item[0].start; 4711 s = item[0].start;
4713 l = 0; 4712 l = 0;
4714 } 4713 }
4715 } 4714 }
4716 4715
4717 if (width - vim_strsize(s) >= maxwidth) 4716 if (width - vim_strsize(s) >= maxwidth)
4718 { 4717 {
4719 /* Truncation mark is beyond max length */ 4718 // Truncation mark is beyond max length
4720 if (has_mbyte) 4719 if (has_mbyte)
4721 { 4720 {
4722 s = out; 4721 s = out;
4723 width = 0; 4722 width = 0;
4724 for (;;) 4723 for (;;)
4726 width += ptr2cells(s); 4725 width += ptr2cells(s);
4727 if (width >= maxwidth) 4726 if (width >= maxwidth)
4728 break; 4727 break;
4729 s += (*mb_ptr2len)(s); 4728 s += (*mb_ptr2len)(s);
4730 } 4729 }
4731 /* Fill up for half a double-wide character. */ 4730 // Fill up for half a double-wide character.
4732 while (++width < maxwidth) 4731 while (++width < maxwidth)
4733 *s++ = fillchar; 4732 *s++ = fillchar;
4734 } 4733 }
4735 else 4734 else
4736 s = out + maxwidth - 1; 4735 s = out + maxwidth - 1;
4756 n = width - maxwidth + 1; 4755 n = width - maxwidth + 1;
4757 p = s + n; 4756 p = s + n;
4758 STRMOVE(s + 1, p); 4757 STRMOVE(s + 1, p);
4759 *s = '<'; 4758 *s = '<';
4760 4759
4761 /* Fill up for half a double-wide character. */ 4760 // Fill up for half a double-wide character.
4762 while (++width < maxwidth) 4761 while (++width < maxwidth)
4763 { 4762 {
4764 s = s + STRLEN(s); 4763 s = s + STRLEN(s);
4765 *s++ = fillchar; 4764 *s++ = fillchar;
4766 *s = NUL; 4765 *s = NUL;
4767 } 4766 }
4768 4767
4769 --n; /* count the '<' */ 4768 --n; // count the '<'
4770 for (; l < itemcnt; l++) 4769 for (; l < itemcnt; l++)
4771 { 4770 {
4772 if (item[l].start - n >= s) 4771 if (item[l].start - n >= s)
4773 item[l].start -= n; 4772 item[l].start -= n;
4774 else 4773 else
4777 } 4776 }
4778 width = maxwidth; 4777 width = maxwidth;
4779 } 4778 }
4780 else if (width < maxwidth && STRLEN(out) + maxwidth - width + 1 < outlen) 4779 else if (width < maxwidth && STRLEN(out) + maxwidth - width + 1 < outlen)
4781 { 4780 {
4782 /* Apply STL_MIDDLE if any */ 4781 // Apply STL_MIDDLE if any
4783 for (l = 0; l < itemcnt; l++) 4782 for (l = 0; l < itemcnt; l++)
4784 if (item[l].type == Middle) 4783 if (item[l].type == Middle)
4785 break; 4784 break;
4786 if (l < itemcnt) 4785 if (l < itemcnt)
4787 { 4786 {
4793 item[l].start += maxwidth - width; 4792 item[l].start += maxwidth - width;
4794 width = maxwidth; 4793 width = maxwidth;
4795 } 4794 }
4796 } 4795 }
4797 4796
4798 /* Store the info about highlighting. */ 4797 // Store the info about highlighting.
4799 if (hltab != NULL) 4798 if (hltab != NULL)
4800 { 4799 {
4801 sp = hltab; 4800 sp = hltab;
4802 for (l = 0; l < itemcnt; l++) 4801 for (l = 0; l < itemcnt; l++)
4803 { 4802 {
4810 } 4809 }
4811 sp->start = NULL; 4810 sp->start = NULL;
4812 sp->userhl = 0; 4811 sp->userhl = 0;
4813 } 4812 }
4814 4813
4815 /* Store the info about tab pages labels. */ 4814 // Store the info about tab pages labels.
4816 if (tabtab != NULL) 4815 if (tabtab != NULL)
4817 { 4816 {
4818 sp = tabtab; 4817 sp = tabtab;
4819 for (l = 0; l < itemcnt; l++) 4818 for (l = 0; l < itemcnt; l++)
4820 { 4819 {
4827 } 4826 }
4828 sp->start = NULL; 4827 sp->start = NULL;
4829 sp->userhl = 0; 4828 sp->userhl = 0;
4830 } 4829 }
4831 4830
4832 /* When inside update_screen we do not want redrawing a stausline, ruler, 4831 // When inside update_screen we do not want redrawing a stausline, ruler,
4833 * title, etc. to trigger another redraw, it may cause an endless loop. */ 4832 // title, etc. to trigger another redraw, it may cause an endless loop.
4834 if (updating_screen) 4833 if (updating_screen)
4835 { 4834 {
4836 must_redraw = save_must_redraw; 4835 must_redraw = save_must_redraw;
4837 curwin->w_redr_type = save_redr_type; 4836 curwin->w_redr_type = save_redr_type;
4838 } 4837 }
4839 4838
4840 return width; 4839 return width;
4841 } 4840 }
4842 #endif /* FEAT_STL_OPT */ 4841 #endif // FEAT_STL_OPT
4843 4842
4844 #if defined(FEAT_STL_OPT) || defined(FEAT_CMDL_INFO) \ 4843 #if defined(FEAT_STL_OPT) || defined(FEAT_CMDL_INFO) \
4845 || defined(FEAT_GUI_TABLINE) || defined(PROTO) 4844 || defined(FEAT_GUI_TABLINE) || defined(PROTO)
4846 /* 4845 /*
4847 * Get relative cursor position in window into "buf[buflen]", in the form 99%, 4846 * Get relative cursor position in window into "buf[buflen]", in the form 99%,
4851 get_rel_pos( 4850 get_rel_pos(
4852 win_T *wp, 4851 win_T *wp,
4853 char_u *buf, 4852 char_u *buf,
4854 int buflen) 4853 int buflen)
4855 { 4854 {
4856 long above; /* number of lines above window */ 4855 long above; // number of lines above window
4857 long below; /* number of lines below window */ 4856 long below; // number of lines below window
4858 4857
4859 if (buflen < 3) /* need at least 3 chars for writing */ 4858 if (buflen < 3) // need at least 3 chars for writing
4860 return; 4859 return;
4861 above = wp->w_topline - 1; 4860 above = wp->w_topline - 1;
4862 #ifdef FEAT_DIFF 4861 #ifdef FEAT_DIFF
4863 above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill; 4862 above += diff_check_fill(wp, wp->w_topline) - wp->w_topfill;
4864 if (wp->w_topline == 1 && wp->w_topfill >= 1) 4863 if (wp->w_topline == 1 && wp->w_topfill >= 1)
4865 above = 0; /* All buffer lines are displayed and there is an 4864 above = 0; // All buffer lines are displayed and there is an
4866 * indication of filler lines, that can be considered 4865 // indication of filler lines, that can be considered
4867 * seeing all lines. */ 4866 // seeing all lines.
4868 #endif 4867 #endif
4869 below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1; 4868 below = wp->w_buffer->b_ml.ml_line_count - wp->w_botline + 1;
4870 if (below <= 0) 4869 if (below <= 0)
4871 vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")), 4870 vim_strncpy(buf, (char_u *)(above == 0 ? _("All") : _("Bot")),
4872 (size_t)(buflen - 1)); 4871 (size_t)(buflen - 1));
4886 static int 4885 static int
4887 append_arg_number( 4886 append_arg_number(
4888 win_T *wp, 4887 win_T *wp,
4889 char_u *buf, 4888 char_u *buf,
4890 int buflen, 4889 int buflen,
4891 int add_file) /* Add "file" before the arg number */ 4890 int add_file) // Add "file" before the arg number
4892 { 4891 {
4893 char_u *p; 4892 char_u *p;
4894 4893
4895 if (ARGCOUNT <= 1) /* nothing to do */ 4894 if (ARGCOUNT <= 1) // nothing to do
4896 return FALSE; 4895 return FALSE;
4897 4896
4898 p = buf + STRLEN(buf); /* go to the end of the buffer */ 4897 p = buf + STRLEN(buf); // go to the end of the buffer
4899 if (p - buf + 35 >= buflen) /* getting too long */ 4898 if (p - buf + 35 >= buflen) // getting too long
4900 return FALSE; 4899 return FALSE;
4901 *p++ = ' '; 4900 *p++ = ' ';
4902 *p++ = '('; 4901 *p++ = '(';
4903 if (add_file) 4902 if (add_file)
4904 { 4903 {
4943 4942
4944 fname = vim_strsave(fname); 4943 fname = vim_strsave(fname);
4945 4944
4946 # ifdef USE_FNAME_CASE 4945 # ifdef USE_FNAME_CASE
4947 if (fname != NULL) 4946 if (fname != NULL)
4948 fname_case(fname, 0); /* set correct case for file name */ 4947 fname_case(fname, 0); // set correct case for file name
4949 # endif 4948 # endif
4950 4949
4951 return fname; 4950 return fname;
4952 #endif 4951 #endif
4953 } 4952 }
4999 win_T *wp, *wpnext; 4998 win_T *wp, *wpnext;
5000 int split_ret = OK; 4999 int split_ret = OK;
5001 int p_ea_save; 5000 int p_ea_save;
5002 int open_wins = 0; 5001 int open_wins = 0;
5003 int r; 5002 int r;
5004 int count; /* Maximum number of windows to open. */ 5003 int count; // Maximum number of windows to open.
5005 int all; /* When TRUE also load inactive buffers. */ 5004 int all; // When TRUE also load inactive buffers.
5006 int had_tab = cmdmod.tab; 5005 int had_tab = cmdmod.tab;
5007 tabpage_T *tpnext; 5006 tabpage_T *tpnext;
5008 5007
5009 if (eap->addr_count == 0) /* make as many windows as possible */ 5008 if (eap->addr_count == 0) // make as many windows as possible
5010 count = 9999; 5009 count = 9999;
5011 else 5010 else
5012 count = eap->line2; /* make as many windows as specified */ 5011 count = eap->line2; // make as many windows as specified
5013 if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide) 5012 if (eap->cmdidx == CMD_unhide || eap->cmdidx == CMD_sunhide)
5014 all = FALSE; 5013 all = FALSE;
5015 else 5014 else
5016 all = TRUE; 5015 all = TRUE;
5017 5016
5040 : wp->w_width != Columns) 5039 : wp->w_width != Columns)
5041 || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW 5040 || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW
5042 && !(wp->w_closing || wp->w_buffer->b_locked > 0)) 5041 && !(wp->w_closing || wp->w_buffer->b_locked > 0))
5043 { 5042 {
5044 win_close(wp, FALSE); 5043 win_close(wp, FALSE);
5045 wpnext = firstwin; /* just in case an autocommand does 5044 wpnext = firstwin; // just in case an autocommand does
5046 something strange with windows */ 5045 // something strange with windows
5047 tpnext = first_tabpage; /* start all over... */ 5046 tpnext = first_tabpage; // start all over...
5048 open_wins = 0; 5047 open_wins = 0;
5049 } 5048 }
5050 else 5049 else
5051 ++open_wins; 5050 ++open_wins;
5052 } 5051 }
5053 5052
5054 /* Without the ":tab" modifier only do the current tab page. */ 5053 // Without the ":tab" modifier only do the current tab page.
5055 if (had_tab == 0 || tpnext == NULL) 5054 if (had_tab == 0 || tpnext == NULL)
5056 break; 5055 break;
5057 goto_tabpage_tp(tpnext, TRUE, TRUE); 5056 goto_tabpage_tp(tpnext, TRUE, TRUE);
5058 } 5057 }
5059 5058
5060 /* 5059 /*
5061 * Go through the buffer list. When a buffer doesn't have a window yet, 5060 * Go through the buffer list. When a buffer doesn't have a window yet,
5062 * open one. Otherwise move the window to the right position. 5061 * open one. Otherwise move the window to the right position.
5063 * Watch out for autocommands that delete buffers or windows! 5062 * Watch out for autocommands that delete buffers or windows!
5064 */ 5063 */
5065 /* Don't execute Win/Buf Enter/Leave autocommands here. */ 5064 // Don't execute Win/Buf Enter/Leave autocommands here.
5066 ++autocmd_no_enter; 5065 ++autocmd_no_enter;
5067 win_enter(lastwin, FALSE); 5066 win_enter(lastwin, FALSE);
5068 ++autocmd_no_leave; 5067 ++autocmd_no_leave;
5069 for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) 5068 for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next)
5070 { 5069 {
5071 /* Check if this buffer needs a window */ 5070 // Check if this buffer needs a window
5072 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) 5071 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl)
5073 continue; 5072 continue;
5074 5073
5075 if (had_tab != 0) 5074 if (had_tab != 0)
5076 { 5075 {
5077 /* With the ":tab" modifier don't move the window. */ 5076 // With the ":tab" modifier don't move the window.
5078 if (buf->b_nwindows > 0) 5077 if (buf->b_nwindows > 0)
5079 wp = lastwin; /* buffer has a window, skip it */ 5078 wp = lastwin; // buffer has a window, skip it
5080 else 5079 else
5081 wp = NULL; 5080 wp = NULL;
5082 } 5081 }
5083 else 5082 else
5084 { 5083 {
5085 /* Check if this buffer already has a window */ 5084 // Check if this buffer already has a window
5086 FOR_ALL_WINDOWS(wp) 5085 FOR_ALL_WINDOWS(wp)
5087 if (wp->w_buffer == buf) 5086 if (wp->w_buffer == buf)
5088 break; 5087 break;
5089 /* If the buffer already has a window, move it */ 5088 // If the buffer already has a window, move it
5090 if (wp != NULL) 5089 if (wp != NULL)
5091 win_move_after(wp, curwin); 5090 win_move_after(wp, curwin);
5092 } 5091 }
5093 5092
5094 if (wp == NULL && split_ret == OK) 5093 if (wp == NULL && split_ret == OK)
5095 { 5094 {
5096 bufref_T bufref; 5095 bufref_T bufref;
5097 5096
5098 set_bufref(&bufref, buf); 5097 set_bufref(&bufref, buf);
5099 5098
5100 /* Split the window and put the buffer in it */ 5099 // Split the window and put the buffer in it
5101 p_ea_save = p_ea; 5100 p_ea_save = p_ea;
5102 p_ea = TRUE; /* use space from all windows */ 5101 p_ea = TRUE; // use space from all windows
5103 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); 5102 split_ret = win_split(0, WSP_ROOM | WSP_BELOW);
5104 ++open_wins; 5103 ++open_wins;
5105 p_ea = p_ea_save; 5104 p_ea = p_ea_save;
5106 if (split_ret == FAIL) 5105 if (split_ret == FAIL)
5107 continue; 5106 continue;
5108 5107
5109 /* Open the buffer in this window. */ 5108 // Open the buffer in this window.
5110 swap_exists_action = SEA_DIALOG; 5109 swap_exists_action = SEA_DIALOG;
5111 set_curbuf(buf, DOBUF_GOTO); 5110 set_curbuf(buf, DOBUF_GOTO);
5112 if (!bufref_valid(&bufref)) 5111 if (!bufref_valid(&bufref))
5113 { 5112 {
5114 /* autocommands deleted the buffer!!! */ 5113 // autocommands deleted the buffer!!!
5115 swap_exists_action = SEA_NONE; 5114 swap_exists_action = SEA_NONE;
5116 break; 5115 break;
5117 } 5116 }
5118 if (swap_exists_action == SEA_QUIT) 5117 if (swap_exists_action == SEA_QUIT)
5119 { 5118 {
5120 #if defined(FEAT_EVAL) 5119 #if defined(FEAT_EVAL)
5121 cleanup_T cs; 5120 cleanup_T cs;
5122 5121
5123 /* Reset the error/interrupt/exception state here so that 5122 // Reset the error/interrupt/exception state here so that
5124 * aborting() returns FALSE when closing a window. */ 5123 // aborting() returns FALSE when closing a window.
5125 enter_cleanup(&cs); 5124 enter_cleanup(&cs);
5126 #endif 5125 #endif
5127 5126
5128 /* User selected Quit at ATTENTION prompt; close this window. */ 5127 // User selected Quit at ATTENTION prompt; close this window.
5129 win_close(curwin, TRUE); 5128 win_close(curwin, TRUE);
5130 --open_wins; 5129 --open_wins;
5131 swap_exists_action = SEA_NONE; 5130 swap_exists_action = SEA_NONE;
5132 swap_exists_did_quit = TRUE; 5131 swap_exists_did_quit = TRUE;
5133 5132
5134 #if defined(FEAT_EVAL) 5133 #if defined(FEAT_EVAL)
5135 /* Restore the error/interrupt/exception state if not 5134 // Restore the error/interrupt/exception state if not
5136 * discarded by a new aborting error, interrupt, or uncaught 5135 // discarded by a new aborting error, interrupt, or uncaught
5137 * exception. */ 5136 // exception.
5138 leave_cleanup(&cs); 5137 leave_cleanup(&cs);
5139 #endif 5138 #endif
5140 } 5139 }
5141 else 5140 else
5142 handle_swap_exists(NULL); 5141 handle_swap_exists(NULL);
5143 } 5142 }
5144 5143
5145 ui_breakcheck(); 5144 ui_breakcheck();
5146 if (got_int) 5145 if (got_int)
5147 { 5146 {
5148 (void)vgetc(); /* only break the file loading, not the rest */ 5147 (void)vgetc(); // only break the file loading, not the rest
5149 break; 5148 break;
5150 } 5149 }
5151 #ifdef FEAT_EVAL 5150 #ifdef FEAT_EVAL
5152 /* Autocommands deleted the buffer or aborted script processing!!! */ 5151 // Autocommands deleted the buffer or aborted script processing!!!
5153 if (aborting()) 5152 if (aborting())
5154 break; 5153 break;
5155 #endif 5154 #endif
5156 /* When ":tab" was used open a new tab for a new window repeatedly. */ 5155 // When ":tab" was used open a new tab for a new window repeatedly.
5157 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) 5156 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm)
5158 cmdmod.tab = 9999; 5157 cmdmod.tab = 9999;
5159 } 5158 }
5160 --autocmd_no_enter; 5159 --autocmd_no_enter;
5161 win_enter(firstwin, FALSE); /* back to first window */ 5160 win_enter(firstwin, FALSE); // back to first window
5162 --autocmd_no_leave; 5161 --autocmd_no_leave;
5163 5162
5164 /* 5163 /*
5165 * Close superfluous windows. 5164 * Close superfluous windows.
5166 */ 5165 */
5168 { 5167 {
5169 r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) 5168 r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer)
5170 || autowrite(wp->w_buffer, FALSE) == OK); 5169 || autowrite(wp->w_buffer, FALSE) == OK);
5171 if (!win_valid(wp)) 5170 if (!win_valid(wp))
5172 { 5171 {
5173 /* BufWrite Autocommands made the window invalid, start over */ 5172 // BufWrite Autocommands made the window invalid, start over
5174 wp = lastwin; 5173 wp = lastwin;
5175 } 5174 }
5176 else if (r) 5175 else if (r)
5177 { 5176 {
5178 win_close(wp, !buf_hide(wp->w_buffer)); 5177 win_close(wp, !buf_hide(wp->w_buffer));
5208 static int entered = 0; 5207 static int entered = 0;
5209 5208
5210 if (!curbuf->b_p_ml || (nmlines = (int)p_mls) == 0) 5209 if (!curbuf->b_p_ml || (nmlines = (int)p_mls) == 0)
5211 return; 5210 return;
5212 5211
5213 /* Disallow recursive entry here. Can happen when executing a modeline 5212 // Disallow recursive entry here. Can happen when executing a modeline
5214 * triggers an autocommand, which reloads modelines with a ":do". */ 5213 // triggers an autocommand, which reloads modelines with a ":do".
5215 if (entered) 5214 if (entered)
5216 return; 5215 return;
5217 5216
5218 ++entered; 5217 ++entered;
5219 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count && lnum <= nmlines; 5218 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count && lnum <= nmlines;
5226 if (chk_modeline(lnum, flags) == FAIL) 5225 if (chk_modeline(lnum, flags) == FAIL)
5227 nmlines = 0; 5226 nmlines = 0;
5228 --entered; 5227 --entered;
5229 } 5228 }
5230 5229
5231 #include "version.h" /* for version number */ 5230 #include "version.h" // for version number
5232 5231
5233 /* 5232 /*
5234 * chk_modeline() - check a single line for a mode string 5233 * chk_modeline() - check a single line for a mode string
5235 * Return FAIL if an error encountered. 5234 * Return FAIL if an error encountered.
5236 */ 5235 */
5237 static int 5236 static int
5238 chk_modeline( 5237 chk_modeline(
5239 linenr_T lnum, 5238 linenr_T lnum,
5240 int flags) /* Same as for do_modelines(). */ 5239 int flags) // Same as for do_modelines().
5241 { 5240 {
5242 char_u *s; 5241 char_u *s;
5243 char_u *e; 5242 char_u *e;
5244 char_u *linecopy; /* local copy of any modeline found */ 5243 char_u *linecopy; // local copy of any modeline found
5245 int prev; 5244 int prev;
5246 int vers; 5245 int vers;
5247 int end; 5246 int end;
5248 int retval = OK; 5247 int retval = OK;
5249 char_u *save_sourcing_name; 5248 char_u *save_sourcing_name;
5258 if (prev == -1 || vim_isspace(prev)) 5257 if (prev == -1 || vim_isspace(prev))
5259 { 5258 {
5260 if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0) 5259 if ((prev != -1 && STRNCMP(s, "ex:", (size_t)3) == 0)
5261 || STRNCMP(s, "vi:", (size_t)3) == 0) 5260 || STRNCMP(s, "vi:", (size_t)3) == 0)
5262 break; 5261 break;
5263 /* Accept both "vim" and "Vim". */ 5262 // Accept both "vim" and "Vim".
5264 if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm') 5263 if ((s[0] == 'v' || s[0] == 'V') && s[1] == 'i' && s[2] == 'm')
5265 { 5264 {
5266 if (s[3] == '<' || s[3] == '=' || s[3] == '>') 5265 if (s[3] == '<' || s[3] == '=' || s[3] == '>')
5267 e = s + 4; 5266 e = s + 4;
5268 else 5267 else
5282 prev = *s; 5281 prev = *s;
5283 } 5282 }
5284 5283
5285 if (*s) 5284 if (*s)
5286 { 5285 {
5287 do /* skip over "ex:", "vi:" or "vim:" */ 5286 do // skip over "ex:", "vi:" or "vim:"
5288 ++s; 5287 ++s;
5289 while (s[-1] != ':'); 5288 while (s[-1] != ':');
5290 5289
5291 s = linecopy = vim_strsave(s); /* copy the line, it will change */ 5290 s = linecopy = vim_strsave(s); // copy the line, it will change
5292 if (linecopy == NULL) 5291 if (linecopy == NULL)
5293 return FAIL; 5292 return FAIL;
5294 5293
5295 save_sourcing_lnum = sourcing_lnum; 5294 save_sourcing_lnum = sourcing_lnum;
5296 save_sourcing_name = sourcing_name; 5295 save_sourcing_name = sourcing_name;
5297 sourcing_lnum = lnum; /* prepare for emsg() */ 5296 sourcing_lnum = lnum; // prepare for emsg()
5298 sourcing_name = (char_u *)"modelines"; 5297 sourcing_name = (char_u *)"modelines";
5299 5298
5300 end = FALSE; 5299 end = FALSE;
5301 while (end == FALSE) 5300 while (end == FALSE)
5302 { 5301 {
5322 * Accept "se" for compatibility with Elvis. 5321 * Accept "se" for compatibility with Elvis.
5323 */ 5322 */
5324 if (STRNCMP(s, "set ", (size_t)4) == 0 5323 if (STRNCMP(s, "set ", (size_t)4) == 0
5325 || STRNCMP(s, "se ", (size_t)3) == 0) 5324 || STRNCMP(s, "se ", (size_t)3) == 0)
5326 { 5325 {
5327 if (*e != ':') /* no terminating ':'? */ 5326 if (*e != ':') // no terminating ':'?
5328 break; 5327 break;
5329 end = TRUE; 5328 end = TRUE;
5330 s = vim_strchr(s, ' ') + 1; 5329 s = vim_strchr(s, ' ') + 1;
5331 } 5330 }
5332 *e = NUL; /* truncate the set command */ 5331 *e = NUL; // truncate the set command
5333 5332
5334 if (*s != NUL) /* skip over an empty "::" */ 5333 if (*s != NUL) // skip over an empty "::"
5335 { 5334 {
5336 int secure_save = secure; 5335 int secure_save = secure;
5337 #ifdef FEAT_EVAL 5336 #ifdef FEAT_EVAL
5338 save_current_sctx = current_sctx; 5337 save_current_sctx = current_sctx;
5339 current_sctx.sc_sid = SID_MODELINE; 5338 current_sctx.sc_sid = SID_MODELINE;
5348 5347
5349 secure = secure_save; 5348 secure = secure_save;
5350 #ifdef FEAT_EVAL 5349 #ifdef FEAT_EVAL
5351 current_sctx = save_current_sctx; 5350 current_sctx = save_current_sctx;
5352 #endif 5351 #endif
5353 if (retval == FAIL) /* stop if error found */ 5352 if (retval == FAIL) // stop if error found
5354 break; 5353 break;
5355 } 5354 }
5356 s = e + 1; /* advance to next part */ 5355 s = e + 1; // advance to next part
5357 } 5356 }
5358 5357
5359 sourcing_lnum = save_sourcing_lnum; 5358 sourcing_lnum = save_sourcing_lnum;
5360 sourcing_name = save_sourcing_name; 5359 sourcing_name = save_sourcing_name;
5361 5360
5475 * and 'bufhidden'. 5474 * and 'bufhidden'.
5476 */ 5475 */
5477 int 5476 int
5478 buf_hide(buf_T *buf) 5477 buf_hide(buf_T *buf)
5479 { 5478 {
5480 /* 'bufhidden' overrules 'hidden' and ":hide", check it first */ 5479 // 'bufhidden' overrules 'hidden' and ":hide", check it first
5481 switch (buf->b_p_bh[0]) 5480 switch (buf->b_p_bh[0])
5482 { 5481 {
5483 case 'u': /* "unload" */ 5482 case 'u': // "unload"
5484 case 'w': /* "wipe" */ 5483 case 'w': // "wipe"
5485 case 'd': return FALSE; /* "delete" */ 5484 case 'd': return FALSE; // "delete"
5486 case 'h': return TRUE; /* "hide" */ 5485 case 'h': return TRUE; // "hide"
5487 } 5486 }
5488 return (p_hid || cmdmod.hide); 5487 return (p_hid || cmdmod.hide);
5489 } 5488 }
5490 5489
5491 /* 5490 /*
5507 else 5506 else
5508 return (char_u *)_(msg_loclist); 5507 return (char_u *)_(msg_loclist);
5509 } 5508 }
5510 #endif 5509 #endif
5511 5510
5512 /* There is no _file_ when 'buftype' is "nofile", b_sfname 5511 // There is no _file_ when 'buftype' is "nofile", b_sfname
5513 * contains the name as specified by the user. */ 5512 // contains the name as specified by the user.
5514 if (bt_nofilename(buf)) 5513 if (bt_nofilename(buf))
5515 { 5514 {
5516 #ifdef FEAT_TERMINAL 5515 #ifdef FEAT_TERMINAL
5517 if (buf->b_term != NULL) 5516 if (buf->b_term != NULL)
5518 return term_get_status_text(buf->b_term); 5517 return term_get_status_text(buf->b_term);
5562 int differ = TRUE; 5561 int differ = TRUE;
5563 linenr_T lnum; 5562 linenr_T lnum;
5564 aco_save_T aco; 5563 aco_save_T aco;
5565 exarg_T ea; 5564 exarg_T ea;
5566 5565
5567 /* Allocate a buffer without putting it in the buffer list. */ 5566 // Allocate a buffer without putting it in the buffer list.
5568 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY); 5567 newbuf = buflist_new(NULL, NULL, (linenr_T)1, BLN_DUMMY);
5569 if (newbuf == NULL) 5568 if (newbuf == NULL)
5570 return TRUE; 5569 return TRUE;
5571 5570
5572 /* Force the 'fileencoding' and 'fileformat' to be equal. */ 5571 // Force the 'fileencoding' and 'fileformat' to be equal.
5573 if (prep_exarg(&ea, buf) == FAIL) 5572 if (prep_exarg(&ea, buf) == FAIL)
5574 { 5573 {
5575 wipe_buffer(newbuf, FALSE); 5574 wipe_buffer(newbuf, FALSE);
5576 return TRUE; 5575 return TRUE;
5577 } 5576 }
5578 5577
5579 /* set curwin/curbuf to buf and save a few things */ 5578 // set curwin/curbuf to buf and save a few things
5580 aucmd_prepbuf(&aco, newbuf); 5579 aucmd_prepbuf(&aco, newbuf);
5581 5580
5582 if (ml_open(curbuf) == OK 5581 if (ml_open(curbuf) == OK
5583 && readfile(buf->b_ffname, buf->b_fname, 5582 && readfile(buf->b_ffname, buf->b_fname,
5584 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM, 5583 (linenr_T)0, (linenr_T)0, (linenr_T)MAXLNUM,
5585 &ea, READ_NEW | READ_DUMMY) == OK) 5584 &ea, READ_NEW | READ_DUMMY) == OK)
5586 { 5585 {
5587 /* compare the two files line by line */ 5586 // compare the two files line by line
5588 if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count) 5587 if (buf->b_ml.ml_line_count == curbuf->b_ml.ml_line_count)
5589 { 5588 {
5590 differ = FALSE; 5589 differ = FALSE;
5591 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) 5590 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum)
5592 if (STRCMP(ml_get_buf(buf, lnum, FALSE), ml_get(lnum)) != 0) 5591 if (STRCMP(ml_get_buf(buf, lnum, FALSE), ml_get(lnum)) != 0)
5596 } 5595 }
5597 } 5596 }
5598 } 5597 }
5599 vim_free(ea.cmd); 5598 vim_free(ea.cmd);
5600 5599
5601 /* restore curwin/curbuf and a few other things */ 5600 // restore curwin/curbuf and a few other things
5602 aucmd_restbuf(&aco); 5601 aucmd_restbuf(&aco);
5603 5602
5604 if (curbuf != newbuf) /* safety check */ 5603 if (curbuf != newbuf) // safety check
5605 wipe_buffer(newbuf, FALSE); 5604 wipe_buffer(newbuf, FALSE);
5606 5605
5607 return differ; 5606 return differ;
5608 } 5607 }
5609 5608
5613 * marks. 5612 * marks.
5614 */ 5613 */
5615 void 5614 void
5616 wipe_buffer( 5615 wipe_buffer(
5617 buf_T *buf, 5616 buf_T *buf,
5618 int aucmd UNUSED) /* When TRUE trigger autocommands. */ 5617 int aucmd UNUSED) // When TRUE trigger autocommands.
5619 { 5618 {
5620 if (buf->b_fnum == top_file_num - 1) 5619 if (buf->b_fnum == top_file_num - 1)
5621 --top_file_num; 5620 --top_file_num;
5622 5621
5623 if (!aucmd) /* Don't trigger BufDelete autocommands here. */ 5622 if (!aucmd) // Don't trigger BufDelete autocommands here.
5624 block_autocmds(); 5623 block_autocmds();
5625 5624
5626 close_buffer(NULL, buf, DOBUF_WIPE, FALSE); 5625 close_buffer(NULL, buf, DOBUF_WIPE, FALSE);
5627 5626
5628 if (!aucmd) 5627 if (!aucmd)