aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
diff options
context:
space:
mode:
authorAbdelhakeem <abdelhakeem.osama@hotmail.com>2019-03-27 21:50:32 +0200
committerJustin M. Keyes <justinkz@gmail.com>2019-03-29 03:28:15 +0100
commitb22ca804dd3a064206e27dea43b791b2a6d23f6e (patch)
treed67b202ea8e71e49a2373d9fa38c68d6b0cadaa2 /src/nvim/buffer.c
parentc933378b9bfe519fe8de9b65b1cbde335c08513a (diff)
downloadrneovim-b22ca804dd3a064206e27dea43b791b2a6d23f6e.tar.gz
rneovim-b22ca804dd3a064206e27dea43b791b2a6d23f6e.tar.bz2
rneovim-b22ca804dd3a064206e27dea43b791b2a6d23f6e.zip
lint
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r--src/nvim/buffer.c1337
1 files changed, 751 insertions, 586 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index ad1170e718..4c9a14b25f 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -145,16 +145,13 @@ read_buffer(
return retval;
}
-/*
- * Open current buffer, that is: open the memfile and read the file into
- * memory.
- * Return FAIL for failure, OK otherwise.
- */
-int
-open_buffer (
- int read_stdin, /* read file from stdin */
- exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */
- int flags /* extra flags for readfile() */
+// Open current buffer, that is: open the memfile and read the file into
+// memory.
+// Return FAIL for failure, OK otherwise.
+int open_buffer(
+ int read_stdin, // read file from stdin
+ exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
+ int flags // extra flags for readfile()
)
{
int retval = OK;
@@ -169,14 +166,14 @@ open_buffer (
*/
if (readonlymode && curbuf->b_ffname != NULL
&& (curbuf->b_flags & BF_NEVERLOADED))
- curbuf->b_p_ro = TRUE;
+ curbuf->b_p_ro = true;
if (ml_open(curbuf) == FAIL) {
/*
* There MUST be a memfile, otherwise we can't do anything
* If we can't create one for the current buffer, take another buffer
*/
- close_buffer(NULL, curbuf, 0, FALSE);
+ close_buffer(NULL, curbuf, 0, false);
curbuf = NULL;
FOR_ALL_BUFFERS(buf) {
@@ -196,8 +193,9 @@ open_buffer (
}
EMSG(_("E83: Cannot allocate buffer, using other one..."));
enter_buffer(curbuf);
- if (old_tw != curbuf->b_p_tw)
+ if (old_tw != curbuf->b_p_tw) {
check_colorcolumn(curwin);
+ }
return FAIL;
}
@@ -206,7 +204,7 @@ open_buffer (
set_bufref(&old_curbuf, curbuf);
modified_was_set = false;
- /* mark cursor position as being invalid */
+ // mark cursor position as being invalid
curwin->w_valid = 0;
if (curbuf->b_ffname != NULL) {
@@ -265,7 +263,7 @@ open_buffer (
* it possible to retry when 'fileformat' or 'fileencoding' was
* guessed wrong.
*/
- curbuf->b_p_bin = TRUE;
+ curbuf->b_p_bin = true;
retval = readfile(NULL, NULL, (linenr_T)0,
(linenr_T)0, (linenr_T)MAXLNUM, NULL,
flags | (READ_NEW + READ_STDIN));
@@ -275,7 +273,7 @@ open_buffer (
}
}
- /* if first time loading this buffer, init b_chartab[] */
+ // if first time loading this buffer, init b_chartab[]
if (curbuf->b_flags & BF_NEVERLOADED) {
(void)buf_init_chartab(curbuf, false);
parse_cino(curbuf);
@@ -302,20 +300,21 @@ open_buffer (
curbuf->b_last_changedtick = buf_get_changedtick(curbuf);
curbuf->b_last_changedtick_pum = buf_get_changedtick(curbuf);
- /* require "!" to overwrite the file, because it wasn't read completely */
- if (aborting())
+ // require "!" to overwrite the file, because it wasn't read completely
+ if (aborting()) {
curbuf->b_flags |= BF_READERR;
+ }
/* Need to update automatic folding. Do this before the autocommands,
* they may use the fold info. */
foldUpdateAll(curwin);
- /* need to set w_topline, unless some autocommand already did that. */
+ // need to set w_topline, unless some autocommand already did that.
if (!(curwin->w_valid & VALID_TOPLINE)) {
curwin->w_topline = 1;
curwin->w_topfill = 0;
}
- apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval);
+ apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, false, curbuf, &retval);
if (retval == FAIL) {
return FAIL;
@@ -333,10 +332,10 @@ open_buffer (
do_modelines(0);
curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
- apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf,
- &retval);
+ apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, false, curbuf,
+ &retval);
- /* restore curwin/curbuf and a few other things */
+ // restore curwin/curbuf and a few other things
aucmd_restbuf(&aco);
}
@@ -457,14 +456,14 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
set_last_cursor(win);
}
buflist_setfpos(buf, win,
- win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum,
- win->w_cursor.col, TRUE);
+ win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum,
+ win->w_cursor.col, true);
}
bufref_T bufref;
set_bufref(&bufref, buf);
- /* When the buffer is no longer in a window, trigger BufWinLeave */
+ // When the buffer is no longer in a window, trigger BufWinLeave
if (buf->b_nwindows == 1) {
buf->b_locked++;
if (apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, false,
@@ -497,8 +496,9 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
return;
}
}
- if (aborting()) /* autocmds may abort script processing */
+ if (aborting()) { // autocmds may abort script processing
return;
+ }
}
// If the buffer was in curwin and the window has changed, go back to that
@@ -531,9 +531,10 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
terminal_close(buf->terminal, NULL);
}
- /* Always remove the buffer when there is no file name. */
- if (buf->b_ffname == NULL)
- del_buf = TRUE;
+ // Always remove the buffer when there is no file name.
+ if (buf->b_ffname == NULL) {
+ del_buf = true;
+ }
/*
* Free all things allocated for this buffer.
@@ -573,8 +574,9 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
* obtained anyway. Therefore only return if curbuf changed to the
* deleted buffer.
*/
- if (buf == curbuf && !is_curbuf)
+ if (buf == curbuf && !is_curbuf) {
return;
+ }
if (win != NULL // Avoid bogus clang warning.
&& win_valid_any_tab(win)
@@ -588,7 +590,7 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
buf->b_nwindows--;
}
- /* Change directories when the 'acd' option is set. */
+ // Change directories when the 'acd' option is set.
do_autochdir();
// Disable buffer-updates for the current buffer.
@@ -601,30 +603,33 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
if (wipe_buf) {
xfree(buf->b_ffname);
xfree(buf->b_sfname);
- if (buf->b_prev == NULL)
+ if (buf->b_prev == NULL) {
firstbuf = buf->b_next;
- else
+ } else {
buf->b_prev->b_next = buf->b_next;
- if (buf->b_next == NULL)
+ }
+ if (buf->b_next == NULL) {
lastbuf = buf->b_prev;
- else
+ } else {
buf->b_next->b_prev = buf->b_prev;
+ }
free_buffer(buf);
} else {
if (del_buf) {
/* Free all internal variables and reset option values, to make
* ":bdel" compatible with Vim 5.7. */
- free_buffer_stuff(buf, TRUE);
+ free_buffer_stuff(buf, true);
- /* Make it look like a new buffer. */
+ // Make it look like a new buffer.
buf->b_flags = BF_CHECK_RO | BF_NEVERLOADED;
- /* Init the options when loaded again. */
+ // Init the options when loaded again.
buf->b_p_initialized = false;
}
buf_clear_file(buf);
- if (del_buf)
- buf->b_p_bl = FALSE;
+ if (del_buf) {
+ buf->b_p_bl = false;
+ }
}
}
@@ -634,13 +639,13 @@ void close_buffer(win_T *win, buf_T *buf, int action, int abort_if_last)
void buf_clear_file(buf_T *buf)
{
buf->b_ml.ml_line_count = 1;
- unchanged(buf, TRUE);
- buf->b_p_eol = TRUE;
- buf->b_start_eol = TRUE;
- buf->b_p_bomb = FALSE;
- buf->b_start_bomb = FALSE;
+ unchanged(buf, true);
+ buf->b_p_eol = true;
+ buf->b_start_eol = true;
+ buf->b_p_bomb = false;
+ buf->b_start_bomb = false;
buf->b_ml.ml_mfp = NULL;
- buf->b_ml.ml_flags = ML_EMPTY; /* empty buffer */
+ buf->b_ml.ml_flags = ML_EMPTY; // empty buffer
}
/// Clears the current buffer contents.
@@ -714,29 +719,30 @@ void buf_freeall(buf_T *buf, int flags)
* it's OK to delete the curbuf, because a new one is obtained anyway.
* Therefore only return if curbuf changed to the deleted buffer.
*/
- if (buf == curbuf && !is_curbuf)
+ if (buf == curbuf && !is_curbuf) {
return;
+ }
diff_buf_delete(buf); // Can't use 'diff' for unloaded buffer.
// Remove any ownsyntax, unless exiting.
if (curwin != NULL && curwin->w_buffer == buf) {
reset_synblock(curwin);
}
- /* No folds in an empty buffer. */
+ // No folds in an empty buffer.
FOR_ALL_TAB_WINDOWS(tp, win) {
if (win->w_buffer == buf) {
clearFolding(win);
}
}
- ml_close(buf, TRUE); /* close and delete the memline/memfile */
- buf->b_ml.ml_line_count = 0; /* no lines in buffer */
+ ml_close(buf, true); // close and delete the memline/memfile
+ buf->b_ml.ml_line_count = 0; // no lines in buffer
if ((flags & BFA_KEEP_UNDO) == 0) {
- u_blockfree(buf); /* free the memory allocated for undo */
- u_clearall(buf); /* reset all undo information */
+ u_blockfree(buf); // free the memory allocated for undo
+ u_clearall(buf); // reset all undo information
}
- syntax_clear(&buf->b_s); /* reset syntax info */
- buf->b_flags &= ~BF_READERR; /* a read error is no longer relevant */
+ syntax_clear(&buf->b_s); // reset syntax info
+ buf->b_flags &= ~BF_READERR; // a read error is no longer relevant
}
/*
@@ -775,10 +781,10 @@ static void free_buffer(buf_T *buf)
/*
* Free stuff in the buffer for ":bdel" and when wiping out the buffer.
*/
-static void
-free_buffer_stuff (
+static void
+free_buffer_stuff(
buf_T *buf,
- int free_options /* free options as well */
+ int free_options // free options as well
)
{
if (free_options) {
@@ -842,14 +848,14 @@ void goto_buffer(exarg_T *eap, int start, int dir, int count)
if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') {
cleanup_T cs;
- /* Reset the error/interrupt/exception state here so that
- * aborting() returns FALSE when closing a window. */
+ // Reset the error/interrupt/exception state here so that
+ // aborting() returns false when closing a window.
enter_cleanup(&cs);
// Quitting means closing the split window, nothing else.
win_close(curwin, true);
swap_exists_action = SEA_NONE;
- swap_exists_did_quit = TRUE;
+ swap_exists_did_quit = true;
/* Restore the error/interrupt/exception state if not discarded by a
* new aborting error, interrupt, or uncaught exception. */
@@ -871,8 +877,8 @@ void handle_swap_exists(bufref_T *old_curbuf)
buf_T *buf;
if (swap_exists_action == SEA_QUIT) {
- /* Reset the error/interrupt/exception state here so that
- * aborting() returns FALSE when closing a buffer. */
+ // Reset the error/interrupt/exception state here so that
+ // aborting() returns false when closing a buffer.
enter_cleanup(&cs);
// User selected Quit at ATTENTION prompt. Go back to previous
@@ -902,20 +908,20 @@ void handle_swap_exists(bufref_T *old_curbuf)
check_colorcolumn(curwin);
}
}
- /* If "old_curbuf" is NULL we are in big trouble here... */
+ // If "old_curbuf" is NULL we are in big trouble here...
/* Restore the error/interrupt/exception state if not discarded by a
* new aborting error, interrupt, or uncaught exception. */
leave_cleanup(&cs);
} else if (swap_exists_action == SEA_RECOVER) {
- /* Reset the error/interrupt/exception state here so that
- * aborting() returns FALSE when closing a buffer. */
+ // Reset the error/interrupt/exception state here so that
+ // aborting() returns false when closing a buffer.
enter_cleanup(&cs);
- /* User selected Recover at ATTENTION prompt. */
- msg_scroll = TRUE;
+ // User selected Recover at ATTENTION prompt.
+ msg_scroll = true;
ml_recover();
- MSG_PUTS("\n"); /* don't overwrite the last message */
+ MSG_PUTS("\n"); // don't overwrite the last message
cmdline_row = msg_row;
do_modelines(0);
@@ -940,30 +946,32 @@ void handle_swap_exists(bufref_T *old_curbuf)
* Returns error message or NULL
*/
char_u *
-do_bufdel (
+do_bufdel(
int command,
- char_u *arg, /* pointer to extra arguments */
+ char_u *arg, // pointer to extra arguments
int addr_count,
- int start_bnr, /* first buffer number in a range */
- int end_bnr, /* buffer nr or last buffer nr in a range */
+ int start_bnr, // first buffer number in a range
+ int end_bnr, // buffer nr or last buffer nr in a range
int forceit
)
{
- int do_current = 0; /* delete current buffer? */
- int deleted = 0; /* number of buffers deleted */
- char_u *errormsg = NULL; /* return value */
- int bnr; /* buffer number */
+ int do_current = 0; // delete current buffer?
+ int deleted = 0; // number of buffers deleted
+ char_u *errormsg = NULL; // return value
+ int bnr; // buffer number
char_u *p;
if (addr_count == 0) {
(void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit);
} else {
if (addr_count == 2) {
- if (*arg) /* both range and argument is not allowed */
+ if (*arg) { // both range and argument is not allowed
return (char_u *)_(e_trailing);
+ }
bnr = start_bnr;
- } else /* addr_count == 1 */
+ } else { // addr_count == 1
bnr = end_bnr;
+ }
for (; !got_int; os_breakcheck()) {
/*
@@ -972,61 +980,71 @@ do_bufdel (
* the current one and will be loaded, which may then
* also be deleted, etc.
*/
- if (bnr == curbuf->b_fnum)
+ if (bnr == curbuf->b_fnum) {
do_current = bnr;
- else if (do_buffer(command, DOBUF_FIRST, FORWARD, bnr,
- forceit) == OK)
- ++deleted;
+ } else if (do_buffer(command, DOBUF_FIRST, FORWARD, bnr,
+ forceit) == OK) {
+ deleted++;
+ }
/*
* find next buffer number to delete/unload
*/
if (addr_count == 2) {
- if (++bnr > end_bnr)
+ if (++bnr > end_bnr) {
break;
- } else { /* addr_count == 1 */
+ }
+ } else { // addr_count == 1
arg = skipwhite(arg);
- if (*arg == NUL)
+ if (*arg == NUL) {
break;
+ }
if (!ascii_isdigit(*arg)) {
p = skiptowhite_esc(arg);
bnr = buflist_findpat(arg, p, command == DOBUF_WIPE,
- FALSE, FALSE);
- if (bnr < 0) /* failed */
+ false, false);
+ if (bnr < 0) { // failed
break;
+ }
arg = p;
} else
bnr = getdigits_int(&arg);
}
}
- if (!got_int && do_current && do_buffer(command, DOBUF_FIRST,
- FORWARD, do_current, forceit) == OK)
- ++deleted;
+ if (!got_int && do_current
+ && do_buffer(command, DOBUF_FIRST,
+ FORWARD, do_current, forceit) == OK) {
+ deleted++;
+ }
if (deleted == 0) {
- if (command == DOBUF_UNLOAD)
+ if (command == DOBUF_UNLOAD) {
STRCPY(IObuff, _("E515: No buffers were unloaded"));
- else if (command == DOBUF_DEL)
+ } else if (command == DOBUF_DEL) {
STRCPY(IObuff, _("E516: No buffers were deleted"));
- else
+ } else {
STRCPY(IObuff, _("E517: No buffers were wiped out"));
+ }
errormsg = IObuff;
} else if (deleted >= p_report) {
if (command == DOBUF_UNLOAD) {
- if (deleted == 1)
+ if (deleted == 1) {
MSG(_("1 buffer unloaded"));
- else
+ } else {
smsg(_("%d buffers unloaded"), deleted);
+ }
} else if (command == DOBUF_DEL) {
- if (deleted == 1)
+ if (deleted == 1) {
MSG(_("1 buffer deleted"));
- else
+ } else {
smsg(_("%d buffers deleted"), deleted);
+ }
} else {
- if (deleted == 1)
+ if (deleted == 1) {
MSG(_("1 buffer wiped out"));
- else
+ } else {
smsg(_("%d buffers wiped out"), deleted);
+ }
}
}
}
@@ -1055,8 +1073,8 @@ static int empty_curbuf(int close_others, int forceit, int action)
set_bufref(&bufref, buf);
if (close_others) {
- /* Close any other windows on this buffer, then make it empty. */
- close_windows(buf, TRUE);
+ // Close any other windows on this buffer, then make it empty.
+ close_windows(buf, true);
}
setpcmark();
@@ -1092,13 +1110,13 @@ static int empty_curbuf(int close_others, int forceit, int action)
*
* Return FAIL or OK.
*/
-int
-do_buffer (
+int
+do_buffer(
int action,
int start,
- int dir, /* FORWARD or BACKWARD */
- int count, /* buffer number or number of buffers */
- int forceit /* TRUE for :...! */
+ int dir, // FORWARD or BACKWARD
+ int count, // buffer number or number of buffers
+ int forceit // true for :...!
)
{
buf_T *buf;
@@ -1111,51 +1129,56 @@ do_buffer (
case DOBUF_LAST: buf = lastbuf; break;
default: buf = curbuf; break;
}
- if (start == DOBUF_MOD) { /* find next modified buffer */
+ if (start == DOBUF_MOD) { // find next modified buffer
while (count-- > 0) {
do {
buf = buf->b_next;
- if (buf == NULL)
+ if (buf == NULL) {
buf = firstbuf;
+ }
} while (buf != curbuf && !bufIsChanged(buf));
}
if (!bufIsChanged(buf)) {
EMSG(_("E84: No modified buffer found"));
return FAIL;
}
- } else if (start == DOBUF_FIRST && count) { /* find specified buffer number */
- while (buf != NULL && buf->b_fnum != count)
+ } else if (start == DOBUF_FIRST && count) { // find specified buffer number
+ while (buf != NULL && buf->b_fnum != count) {
buf = buf->b_next;
+ }
} else {
bp = NULL;
while (count > 0 || (!unload && !buf->b_p_bl && bp != buf)) {
/* remember the buffer where we start, we come back there when all
* buffers are unlisted. */
- if (bp == NULL)
+ if (bp == NULL) {
bp = buf;
+ }
if (dir == FORWARD) {
buf = buf->b_next;
- if (buf == NULL)
+ if (buf == NULL) {
buf = firstbuf;
+ }
} else {
buf = buf->b_prev;
- if (buf == NULL)
+ if (buf == NULL) {
buf = lastbuf;
+ }
}
- /* don't count unlisted buffers */
+ // don't count unlisted buffers
if (unload || buf->b_p_bl) {
- --count;
- bp = NULL; /* use this buffer as new starting point */
+ count--;
+ bp = NULL; // use this buffer as new starting point
}
if (bp == buf) {
- /* back where we started, didn't find anything. */
+ // back where we started, didn't find anything.
EMSG(_("E85: There is no listed buffer"));
return FAIL;
}
}
}
- if (buf == NULL) { /* could not find it */
+ if (buf == NULL) { // could not find it
if (start == DOBUF_FIRST) {
// don't warn when deleting
if (!unload) {
@@ -1180,8 +1203,9 @@ do_buffer (
/* When unloading or deleting a buffer that's already unloaded and
* unlisted: fail silently. */
- if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl)
+ if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) {
return FAIL;
+ }
if (!forceit && (buf->terminal || bufIsChanged(buf))) {
if ((p_confirm || cmdmod.confirm) && p_write && !buf->terminal) {
@@ -1231,8 +1255,9 @@ do_buffer (
break;
}
}
- if (bp == NULL && buf == curbuf)
- return empty_curbuf(TRUE, forceit, action);
+ if (bp == NULL && buf == curbuf) {
+ return empty_curbuf(true, forceit, action);
+ }
/*
* If the deleted buffer is the current one, close the current window
@@ -1242,8 +1267,9 @@ do_buffer (
while (buf == curbuf
&& !(curwin->w_closing || curwin->w_buffer->b_locked > 0)
&& (!ONE_WINDOW || first_tabpage->tp_next != NULL)) {
- if (win_close(curwin, false) == FAIL)
+ if (win_close(curwin, false) == FAIL) {
break;
+ }
}
/*
@@ -1273,61 +1299,72 @@ do_buffer (
int jumpidx;
jumpidx = curwin->w_jumplistidx - 1;
- if (jumpidx < 0)
+ if (jumpidx < 0) {
jumpidx = curwin->w_jumplistlen - 1;
+ }
forward = jumpidx;
while (jumpidx != curwin->w_jumplistidx) {
buf = buflist_findnr(curwin->w_jumplist[jumpidx].fmark.fnum);
if (buf != NULL) {
- if (buf == curbuf || !buf->b_p_bl)
- buf = NULL; /* skip current and unlisted bufs */
- else if (buf->b_ml.ml_mfp == NULL) {
- /* skip unloaded buf, but may keep it for later */
- if (bp == NULL)
+ if (buf == curbuf || !buf->b_p_bl) {
+ buf = NULL; // skip current and unlisted bufs
+ } else if (buf->b_ml.ml_mfp == NULL) {
+ // skip unloaded buf, but may keep it for later
+ if (bp == NULL) {
bp = buf;
+ }
buf = NULL;
}
}
- if (buf != NULL) /* found a valid buffer: stop searching */
+ if (buf != NULL) { // found a valid buffer: stop searching
break;
- /* advance to older entry in jump list */
- if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen)
+ }
+ // advance to older entry in jump list
+ if (!jumpidx && curwin->w_jumplistidx == curwin->w_jumplistlen) {
break;
- if (--jumpidx < 0)
+ }
+ if (--jumpidx < 0) {
jumpidx = curwin->w_jumplistlen - 1;
- if (jumpidx == forward) /* List exhausted for sure */
+ }
+ if (jumpidx == forward) { // List exhausted for sure
break;
+ }
}
}
- if (buf == NULL) { /* No previous buffer, Try 2'nd approach */
- forward = TRUE;
+ if (buf == NULL) { // No previous buffer, Try 2'nd approach
+ forward = true;
buf = curbuf->b_next;
for (;; ) {
if (buf == NULL) {
- if (!forward) /* tried both directions */
+ if (!forward) { // tried both directions
break;
+ }
buf = curbuf->b_prev;
- forward = FALSE;
+ forward = false;
continue;
}
- /* in non-help buffer, try to skip help buffers, and vv */
+ // in non-help buffer, try to skip help buffers, and vv
if (buf->b_help == curbuf->b_help && buf->b_p_bl) {
- if (buf->b_ml.ml_mfp != NULL) /* found loaded buffer */
+ if (buf->b_ml.ml_mfp != NULL) { // found loaded buffer
break;
- if (bp == NULL) /* remember unloaded buf for later */
+ }
+ if (bp == NULL) { // remember unloaded buf for later
bp = buf;
+ }
}
- if (forward)
+ if (forward) {
buf = buf->b_next;
- else
+ } else {
buf = buf->b_prev;
+ }
}
}
- if (buf == NULL) /* No loaded buffer, use unloaded one */
+ if (buf == NULL) { // No loaded buffer, use unloaded one
buf = bp;
- if (buf == NULL) { /* No loaded buffer, find listed one */
+ }
+ if (buf == NULL) { // No loaded buffer, find listed one
FOR_ALL_BUFFERS(buf2) {
if (buf2->b_p_bl && buf2 != curbuf) {
buf = buf2;
@@ -1335,39 +1372,44 @@ do_buffer (
}
}
}
- if (buf == NULL) { /* Still no buffer, just take one */
- if (curbuf->b_next != NULL)
+ if (buf == NULL) { // Still no buffer, just take one
+ if (curbuf->b_next != NULL) {
buf = curbuf->b_next;
- else
+ } else {
buf = curbuf->b_prev;
+ }
}
}
if (buf == NULL) {
/* Autocommands must have wiped out all other buffers. Only option
* now is to make the current buffer empty. */
- return empty_curbuf(FALSE, forceit, action);
+ return empty_curbuf(false, forceit, action);
}
/*
* make buf current buffer
*/
- if (action == DOBUF_SPLIT) { /* split window first */
- /* If 'switchbuf' contains "useopen": jump to first window containing
- * "buf" if one exists */
- if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf))
+ if (action == DOBUF_SPLIT) { // split window first
+ // If 'switchbuf' contains "useopen": jump to first window containing
+ // "buf" if one exists
+ if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) {
return OK;
- /* If 'switchbuf' contains "usetab": jump to first window in any tab
- * page containing "buf" if one exists */
- if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf))
+ }
+ // If 'switchbuf' contains "usetab": jump to first window in any tab
+ // page containing "buf" if one exists
+ if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) {
return OK;
- if (win_split(0, 0) == FAIL)
+ }
+ if (win_split(0, 0) == FAIL) {
return FAIL;
+ }
}
- /* go to current buffer - nothing to do */
- if (buf == curbuf)
+ // go to current buffer - nothing to do
+ if (buf == curbuf) {
return OK;
+ }
/*
* Check if the current buffer may be abandoned.
@@ -1388,15 +1430,16 @@ do_buffer (
}
}
- /* Go to the other buffer. */
+ // Go to the other buffer.
set_curbuf(buf, action);
if (action == DOBUF_SPLIT) {
- RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */
+ RESET_BINDING(curwin); // reset 'scrollbind' and 'cursorbind'
}
- if (aborting()) /* autocmds may abort script processing */
+ if (aborting()) { // autocmds may abort script processing
return FAIL;
+ }
return OK;
}
@@ -1419,12 +1462,13 @@ void set_curbuf(buf_T *buf, int action)
long old_tw = curbuf->b_p_tw;
setpcmark();
- if (!cmdmod.keepalt)
- curwin->w_alt_fnum = curbuf->b_fnum; /* remember alternate file */
- buflist_altfpos(curwin); /* remember curpos */
+ if (!cmdmod.keepalt) {
+ curwin->w_alt_fnum = curbuf->b_fnum; // remember alternate file
+ }
+ buflist_altfpos(curwin); // remember curpos
- /* Don't restart Select mode after switching to another buffer. */
- VIsual_reselect = FALSE;
+ // Don't restart Select mode after switching to another buffer.
+ VIsual_reselect = false;
// close_windows() or apply_autocmds() may change curbuf and wipe out "buf"
prevbuf = curbuf;
@@ -1470,8 +1514,9 @@ void set_curbuf(buf_T *buf, int action)
) || curwin->w_buffer == NULL
) {
enter_buffer(buf);
- if (old_tw != curbuf->b_p_tw)
+ if (old_tw != curbuf->b_p_tw) {
check_colorcolumn(curwin);
+ }
}
if (bufref_valid(&prevbufref) && prevbuf->terminal != NULL) {
@@ -1486,75 +1531,83 @@ void set_curbuf(buf_T *buf, int action)
*/
void enter_buffer(buf_T *buf)
{
- /* Copy buffer and window local option values. Not for a help buffer. */
+ // Copy buffer and window local option values. Not for a help buffer.
buf_copy_options(buf, BCO_ENTER | BCO_NOHELP);
- if (!buf->b_help)
+ if (!buf->b_help) {
get_winopts(buf);
- else
- /* Remove all folds in the window. */
+ } else {
+ // Remove all folds in the window.
clearFolding(curwin);
- foldUpdateAll(curwin); /* update folds (later). */
+ }
+ foldUpdateAll(curwin); // update folds (later).
- /* Get the buffer in the current window. */
+ // Get the buffer in the current window.
curwin->w_buffer = buf;
curbuf = buf;
- ++curbuf->b_nwindows;
+ curbuf->b_nwindows++;
- if (curwin->w_p_diff)
+ if (curwin->w_p_diff) {
diff_buf_add(curbuf);
+ }
curwin->w_s = &(buf->b_s);
- /* Cursor on first line by default. */
+ // Cursor on first line by default.
curwin->w_cursor.lnum = 1;
curwin->w_cursor.col = 0;
curwin->w_cursor.coladd = 0;
- curwin->w_set_curswant = TRUE;
- curwin->w_topline_was_set = FALSE;
+ curwin->w_set_curswant = true;
+ curwin->w_topline_was_set = false;
- /* mark cursor position as being invalid */
+ // mark cursor position as being invalid
curwin->w_valid = 0;
- /* Make sure the buffer is loaded. */
- if (curbuf->b_ml.ml_mfp == NULL) { /* need to load the file */
- /* If there is no filetype, allow for detecting one. Esp. useful for
- * ":ball" used in an autocommand. If there already is a filetype we
- * might prefer to keep it. */
- if (*curbuf->b_p_ft == NUL)
- did_filetype = FALSE;
+ // Make sure the buffer is loaded.
+ if (curbuf->b_ml.ml_mfp == NULL) { // need to load the file
+ // If there is no filetype, allow for detecting one. Esp. useful for
+ // ":ball" used in an autocommand. If there already is a filetype we
+ // might prefer to keep it.
+ if (*curbuf->b_p_ft == NUL) {
+ did_filetype = false;
+ }
- open_buffer(FALSE, NULL, 0);
+ open_buffer(false, NULL, 0);
} else {
- if (!msg_silent)
- need_fileinfo = TRUE; /* display file info after redraw */
- (void)buf_check_timestamp(curbuf, FALSE); /* check if file changed */
+ if (!msg_silent) {
+ need_fileinfo = true; // display file info after redraw
+ }
+ (void)buf_check_timestamp(curbuf, false); // check if file changed
curwin->w_topline = 1;
curwin->w_topfill = 0;
- apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf);
- apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
+ apply_autocmds(EVENT_BUFENTER, NULL, NULL, false, curbuf);
+ apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, false, curbuf);
}
/* If autocommands did not change the cursor position, restore cursor lnum
* and possibly cursor col. */
- if (curwin->w_cursor.lnum == 1 && inindent(0))
+ if (curwin->w_cursor.lnum == 1 && inindent(0)) {
buflist_getfpos();
+ }
- check_arg_idx(curwin); /* check for valid arg_idx */
+ check_arg_idx(curwin); // check for valid arg_idx
maketitle();
- /* when autocmds didn't change it */
- if (curwin->w_topline == 1 && !curwin->w_topline_was_set)
- scroll_cursor_halfway(FALSE); /* redisplay at correct position */
+ // when autocmds didn't change it
+ if (curwin->w_topline == 1 && !curwin->w_topline_was_set) {
+ scroll_cursor_halfway(false); // redisplay at correct position
+ }
- /* Change directories when the 'acd' option is set. */
+ // Change directories when the 'acd' option is set.
do_autochdir();
- if (curbuf->b_kmap_state & KEYMAP_INIT)
+ if (curbuf->b_kmap_state & KEYMAP_INIT) {
(void)keymap_init();
- /* May need to set the spell language. Can only do this after the buffer
- * has been properly setup. */
- if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL)
+ }
+ // May need to set the spell language. Can only do this after the buffer
+ // has been properly setup.
+ if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) {
(void)did_set_spelllang(curwin);
+ }
redraw_later(NOT_VALID);
}
@@ -1601,11 +1654,11 @@ static inline void buf_init_changedtick(buf_T *const buf)
/// Add a file name to the buffer list.
/// If the same file name already exists return a pointer to that buffer.
/// If it does not exist, or if fname == NULL, a new entry is created.
-/// If (flags & BLN_CURBUF) is TRUE, may use current buffer.
-/// If (flags & BLN_LISTED) is TRUE, add new buffer to buffer list.
-/// If (flags & BLN_DUMMY) is TRUE, don't count it as a real buffer.
-/// If (flags & BLN_NEW) is TRUE, don't use an existing buffer.
-/// If (flags & BLN_NOOPT) is TRUE, don't copy options from the current buffer
+/// If (flags & BLN_CURBUF) is true, may use current buffer.
+/// If (flags & BLN_LISTED) is true, add new buffer to buffer list.
+/// If (flags & BLN_DUMMY) is true, don't count it as a real buffer.
+/// If (flags & BLN_NEW) is true, don't use an existing buffer.
+/// If (flags & BLN_NOOPT) is true, don't copy options from the current buffer
/// if the buffer already exists.
/// This is the ONLY way to create a new buffer.
///
@@ -1672,14 +1725,17 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
buf = curbuf;
/* It's like this buffer is deleted. Watch out for autocommands that
* change curbuf! If that happens, allocate a new buffer anyway. */
- if (curbuf->b_p_bl)
- apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
- if (buf == curbuf)
- apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf);
- if (aborting()) /* autocmds may abort script processing */
+ if (curbuf->b_p_bl) {
+ apply_autocmds(EVENT_BUFDELETE, NULL, NULL, false, curbuf);
+ }
+ if (buf == curbuf) {
+ apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, false, curbuf);
+ }
+ if (aborting()) { // autocmds may abort script processing
return NULL;
+ }
if (buf == curbuf) {
- /* Make sure 'bufhidden' and 'buftype' are empty */
+ // Make sure 'bufhidden' and 'buftype' are empty
clear_string_option(&buf->b_p_bh);
clear_string_option(&buf->b_p_bt);
}
@@ -1706,35 +1762,38 @@ buf_T * buflist_new(char_u *ffname, char_u *sfname, linenr_T lnum, int flags)
buf->b_ffname = NULL;