aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r--src/nvim/buffer.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index f1f32076bf..587ef74b35 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -55,7 +55,6 @@
#include "nvim/mark.h"
#include "nvim/extmark.h"
#include "nvim/mbyte.h"
-#include "nvim/memline.h"
#include "nvim/memory.h"
#include "nvim/message.h"
#include "nvim/misc1.h"
@@ -139,7 +138,7 @@ read_buffer(
if (read_stdin) {
// Set or reset 'modified' before executing autocommands, so that
// it can be changed there.
- if (!readonlymode && !BUFEMPTY()) {
+ if (!readonlymode && !buf_is_empty(curbuf)) {
changed();
} else if (retval != FAIL) {
unchanged(curbuf, false, true);
@@ -541,12 +540,10 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
del_buf = true;
}
- /*
- * Free all things allocated for this buffer.
- * Also calls the "BufDelete" autocommands when del_buf is TRUE.
- */
- /* Remember if we are closing the current buffer. Restore the number of
- * windows, so that autocommands in buf_freeall() don't get confused. */
+ // Free all things allocated for this buffer.
+ // Also calls the "BufDelete" autocommands when del_buf is true.
+ // Remember if we are closing the current buffer. Restore the number of
+ // windows, so that autocommands in buf_freeall() don't get confused.
bool is_curbuf = (buf == curbuf);
// When closing the current buffer stop Visual mode before freeing
@@ -901,7 +898,10 @@ void handle_swap_exists(bufref_T *old_curbuf)
if (old_curbuf == NULL
|| !bufref_valid(old_curbuf)
|| old_curbuf->br_buf == curbuf) {
+ // Block autocommands here because curwin->w_buffer is NULL.
+ block_autocmds();
buf = buflist_new(NULL, NULL, 1L, BLN_CURBUF | BLN_LISTED);
+ unblock_autocmds();
} else {
buf = old_curbuf->br_buf;
}
@@ -1489,7 +1489,7 @@ void set_curbuf(buf_T *buf, int action)
set_bufref(&prevbufref, prevbuf);
set_bufref(&newbufref, buf);
- // Autocommands may delete the curren buffer and/or the buffer we wan to go
+ // Autocommands may delete the curren buffer and/or the buffer we want to go
// to. In those cases don't close the buffer.
if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, false, curbuf)
|| (bufref_valid(&prevbufref) && bufref_valid(&newbufref)
@@ -1670,7 +1670,7 @@ static int top_file_num = 1; ///< highest file number
/// Initialize b:changedtick and changedtick_val attribute
///
-/// @param[out] buf Buffer to intialize for.
+/// @param[out] buf Buffer to initialize for.
static inline void buf_init_changedtick(buf_T *const buf)
FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_NONNULL_ALL
{
@@ -1783,7 +1783,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum,
buf = xcalloc(1, sizeof(buf_T));
// init b: variables
buf->b_vars = tv_dict_alloc();
- buf->b_signcols_max = -1;
+ buf->b_signcols_valid = false;
init_var_dict(buf->b_vars, &buf->b_bufvar, VAR_SCOPE);
buf_init_changedtick(buf);
}
@@ -1918,7 +1918,7 @@ bool curbuf_reusable(void)
return (curbuf != NULL
&& curbuf->b_ffname == NULL
&& curbuf->b_nwindows <= 1
- && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY())
+ && (curbuf->b_ml.ml_mfp == NULL || buf_is_empty(curbuf))
&& !bt_quickfix(curbuf)
&& !curbufIsChanged());
}
@@ -2058,7 +2058,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
// If 'switchbuf' contains "split", "vsplit" or "newtab" and the
// current buffer isn't empty: open new tab or window
if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB))
- && !BUFEMPTY()) {
+ && !buf_is_empty(curbuf)) {
if (swb_flags & SWB_NEWTAB) {
tabpage_new();
} else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0)
@@ -3587,7 +3587,7 @@ int build_stl_str_hl(
// Proceed character by character through the statusline format string
- // fmt_p is the current positon in the input buffer
+ // fmt_p is the current position in the input buffer
for (char_u *fmt_p = usefmt; *fmt_p; ) {
if (curitem == (int)stl_items_len) {
size_t new_len = stl_items_len * 3 / 2;
@@ -4735,7 +4735,7 @@ static bool append_arg_number(win_T *wp, char_u *buf, int buflen, bool add_file)
// When resolving a link both "*sfname" and "*ffname" will point to the same
// allocated memory.
// The "*ffname" and "*sfname" pointer values on call will not be freed.
-// Note that the resulting "*ffname" pointer should be considered not allocaed.
+// Note that the resulting "*ffname" pointer should be considered not allocated.
void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
{
if (*ffname == NULL) { // no file name given, nothing to do
@@ -4948,7 +4948,7 @@ do_arg_all(
win_enter(lastwin, false);
// ":tab drop file" should re-use an empty window to avoid "--remote-tab"
// leaving an empty tab page when executed locally.
- if (keep_tabs && BUFEMPTY() && curbuf->b_nwindows == 1
+ if (keep_tabs && buf_is_empty(curbuf) && curbuf->b_nwindows == 1
&& curbuf->b_ffname == NULL && !curbuf->b_changed) {
use_firstwin = true;
tab_drop_empty_window = true;
@@ -5044,8 +5044,8 @@ do_arg_all(
xfree(opened);
}
-// Return TRUE if "buf" is a prompt buffer.
-int bt_prompt(buf_T *buf)
+/// @return true if "buf" is a prompt buffer.
+bool bt_prompt(buf_T *buf)
{
return buf != NULL && buf->b_p_bt[0] == 'p';
}
@@ -5544,16 +5544,16 @@ bool find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp)
int buf_signcols(buf_T *buf)
{
- if (buf->b_signcols_max == -1) {
+ if (!buf->b_signcols_valid) {
sign_entry_T *sign; // a sign in the sign list
- buf->b_signcols_max = 0;
+ int signcols = 0;
int linesum = 0;
linenr_T curline = 0;
FOR_ALL_SIGNS_IN_BUF(buf, sign) {
if (sign->se_lnum > curline) {
- if (linesum > buf->b_signcols_max) {
- buf->b_signcols_max = linesum;
+ if (linesum > signcols) {
+ signcols = linesum;
}
curline = sign->se_lnum;
linesum = 0;
@@ -5562,15 +5562,17 @@ int buf_signcols(buf_T *buf)
linesum++;
}
}
- if (linesum > buf->b_signcols_max) {
- buf->b_signcols_max = linesum;
+ if (linesum > signcols) {
+ signcols = linesum;
}
// Check if we need to redraw
- if (buf->b_signcols_max != buf->b_signcols) {
- buf->b_signcols = buf->b_signcols_max;
+ if (signcols != buf->b_signcols) {
+ buf->b_signcols = signcols;
redraw_buf_later(buf, NOT_VALID);
}
+
+ buf->b_signcols_valid = true;
}
return buf->b_signcols;
@@ -5691,3 +5693,4 @@ void buf_open_scratch(handle_T bufnr, char *bufname)
set_option_value("swf", 0L, NULL, OPT_LOCAL);
RESET_BINDING(curwin);
}
+