aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2020-11-24 08:48:05 +0100
committerThomas Vigouroux <tomvig38@gmail.com>2021-07-06 19:12:15 +0200
commit7970631fa01e95a41ba4520e030e6208c8fb3648 (patch)
tree60a6a82ffb1f5d0388cb816c68e2a31ead1cda2d /src
parent763c852812c8c7e819881a76a237b6f19920f803 (diff)
downloadrneovim-7970631fa01e95a41ba4520e030e6208c8fb3648.tar.gz
rneovim-7970631fa01e95a41ba4520e030e6208c8fb3648.tar.bz2
rneovim-7970631fa01e95a41ba4520e030e6208c8fb3648.zip
buffer: move BUFEMPTY to a function
Diffstat (limited to 'src')
-rw-r--r--src/nvim/buffer.c10
-rw-r--r--src/nvim/buffer.h7
-rw-r--r--src/nvim/diff.c2
-rw-r--r--src/nvim/edit.c2
-rw-r--r--src/nvim/fileio.c4
-rw-r--r--src/nvim/macros.h4
-rw-r--r--src/nvim/main.c2
-rw-r--r--src/nvim/move.c3
-rw-r--r--src/nvim/ops.c3
-rw-r--r--src/nvim/option.c2
-rw-r--r--src/nvim/popupmnu.c3
-rw-r--r--src/nvim/spell.c2
-rw-r--r--src/nvim/undo.c2
-rw-r--r--src/nvim/version.c3
14 files changed, 28 insertions, 21 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 5e300a5df5..02c0391c7a 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(curbuf)) {
+ if (!readonlymode && !buf_is_empty(curbuf)) {
changed();
} else if (retval != FAIL) {
unchanged(curbuf, false, true);
@@ -1921,7 +1920,7 @@ bool curbuf_reusable(void)
return (curbuf != NULL
&& curbuf->b_ffname == NULL
&& curbuf->b_nwindows <= 1
- && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY(curbuf))
+ && (curbuf->b_ml.ml_mfp == NULL || buf_is_empty(curbuf))
&& !bt_quickfix(curbuf)
&& !curbufIsChanged());
}
@@ -2061,7 +2060,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(curbuf)) {
+ && !buf_is_empty(curbuf)) {
if (swb_flags & SWB_NEWTAB) {
tabpage_new();
} else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0)
@@ -4951,7 +4950,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) && 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;
@@ -5696,3 +5695,4 @@ void buf_open_scratch(handle_T bufnr, char *bufname)
set_option_value("swf", 0L, NULL, OPT_LOCAL);
RESET_BINDING(curwin);
}
+
diff --git a/src/nvim/buffer.h b/src/nvim/buffer.h
index ac7ead5f92..02a2ac36f7 100644
--- a/src/nvim/buffer.h
+++ b/src/nvim/buffer.h
@@ -9,6 +9,7 @@
#include "nvim/func_attr.h"
#include "nvim/eval.h"
#include "nvim/macros.h"
+#include "nvim/memline.h"
// Values for buflist_getfile()
enum getf_values {
@@ -128,4 +129,10 @@ static inline void buf_inc_changedtick(buf_T *const buf)
buf_set_changedtick(buf, buf_get_changedtick(buf) + 1);
}
+static inline bool buf_is_empty(buf_T *buf)
+{
+ return buf->b_ml.ml_line_count == 1
+ && *ml_get_buf(buf, (linenr_T)1, false) == '\0';
+}
+
#endif // NVIM_BUFFER_H
diff --git a/src/nvim/diff.c b/src/nvim/diff.c
index d462cea9dd..654475bd0f 100644
--- a/src/nvim/diff.c
+++ b/src/nvim/diff.c
@@ -2669,7 +2669,7 @@ void ex_diffgetput(exarg_T *eap)
}
}
- buf_empty = BUFEMPTY(curbuf);
+ buf_empty = buf_is_empty(curbuf);
added = 0;
for (i = 0; i < count; ++i) {
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 1fe8c0e8e9..e31655bd98 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -8047,7 +8047,7 @@ static bool ins_bs(int c, int mode, int *inserted_space_p)
// can't backup past first character in buffer
// can't backup past starting point unless 'backspace' > 1
// can backup to a previous line if 'backspace' == 0
- if (BUFEMPTY(curbuf)
+ if (buf_is_empty(curbuf)
|| (!revins_on
&& ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
|| (!can_bs(BS_START)
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 5d44a70a05..1203e231ac 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -5027,7 +5027,7 @@ void buf_reload(buf_T *buf, int orig_mode)
// buffer contents. But if reading the file fails we should keep
// the old contents. Can't use memory only, the file might be
// too big. Use a hidden buffer to move the buffer contents to.
- if (BUFEMPTY(curbuf) || saved == FAIL) {
+ if (buf_is_empty(curbuf) || saved == FAIL) {
savebuf = NULL;
} else {
// Allocate a buffer without putting it in the buffer list.
@@ -5060,7 +5060,7 @@ void buf_reload(buf_T *buf, int orig_mode)
if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf) {
// Put the text back from the save buffer. First
// delete any lines that readfile() added.
- while (!BUFEMPTY(curbuf)) {
+ while (!buf_is_empty(curbuf)) {
if (ml_delete(buf->b_ml.ml_line_count, false) == FAIL) {
break;
}
diff --git a/src/nvim/macros.h b/src/nvim/macros.h
index dce1e73dfd..e1aa1b7704 100644
--- a/src/nvim/macros.h
+++ b/src/nvim/macros.h
@@ -34,10 +34,6 @@
/// LINEEMPTY() - return TRUE if the line is empty
#define LINEEMPTY(p) (*ml_get(p) == NUL)
-/// BUFEMPTY() - return TRUE if the current buffer is empty
-#define BUFEMPTY(buf) ((buf)->b_ml.ml_line_count == 1 \
- && *ml_get_buf((buf), (linenr_T)1, false) == '\0')
-
// toupper() and tolower() that use the current locale.
// Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the
// range 0 - 255. toupper()/tolower() on some systems can't handle others.
diff --git a/src/nvim/main.c b/src/nvim/main.c
index 9bccca85ee..16700d20ab 100644
--- a/src/nvim/main.c
+++ b/src/nvim/main.c
@@ -1446,7 +1446,7 @@ static void read_stdin(void)
set_buflisted(true);
// Create memfile and read from stdin.
(void)open_buffer(true, NULL, 0);
- if (BUFEMPTY(curbuf) && curbuf->b_next != NULL) {
+ if (buf_is_empty(curbuf) && curbuf->b_next != NULL) {
// stdin was empty, go to buffer 2 (e.g. "echo file1 | xargs nvim"). #8561
do_cmdline_cmd("silent! bnext");
// Delete the empty stdin buffer.
diff --git a/src/nvim/move.c b/src/nvim/move.c
index dee46d6291..293f51f2d9 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -17,6 +17,7 @@
#include <stdbool.h>
#include "nvim/ascii.h"
+#include "nvim/buffer.h"
#include "nvim/move.h"
#include "nvim/charset.h"
#include "nvim/cursor.h"
@@ -172,7 +173,7 @@ void update_topline(win_T *wp)
old_topfill = wp->w_topfill;
// If the buffer is empty, always set topline to 1.
- if (BUFEMPTY(curbuf)) { // special case - file is empty
+ if (buf_is_empty(curbuf)) { // special case - file is empty
if (wp->w_topline != 1) {
redraw_later(wp, NOT_VALID);
}
diff --git a/src/nvim/ops.c b/src/nvim/ops.c
index 545ab8a94a..79e701d7d8 100644
--- a/src/nvim/ops.c
+++ b/src/nvim/ops.c
@@ -3069,7 +3069,8 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
}
// In an empty buffer the empty line is going to be replaced, include
// it in the saved lines.
- if ((BUFEMPTY(curbuf) ? u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) {
+ if ((buf_is_empty(curbuf) ?
+ u_save(0, 2) : u_save(lnum - 1, lnum)) == FAIL) {
goto end;
}
if (dir == FORWARD) {
diff --git a/src/nvim/option.c b/src/nvim/option.c
index 113297412c..8c763767ad 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -880,7 +880,7 @@ void set_init_3(void)
xfree(p);
}
- if (BUFEMPTY(curbuf)) {
+ if (buf_is_empty(curbuf)) {
int idx_ffs = findoption_len(S_LEN("ffs"));
// Apply the first entry of 'fileformats' to the initial buffer.
diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c
index ef9346b6c8..1705ea0c12 100644
--- a/src/nvim/popupmnu.c
+++ b/src/nvim/popupmnu.c
@@ -9,6 +9,7 @@
#include <inttypes.h>
#include <stdbool.h>
+#include "nvim/buffer.h"
#include "nvim/vim.h"
#include "nvim/api/private/helpers.h"
#include "nvim/ascii.h"
@@ -735,7 +736,7 @@ static int pum_set_selected(int n, int repeat)
&& (curbuf->b_p_bt[2] == 'f')
&& (curbuf->b_p_bh[0] == 'w')) {
// Already a "wipeout" buffer, make it empty.
- while (!BUFEMPTY(curbuf)) {
+ while (!buf_is_empty(curbuf)) {
ml_delete((linenr_T)1, false);
}
} else {
diff --git a/src/nvim/spell.c b/src/nvim/spell.c
index f09223eab5..28276884b0 100644
--- a/src/nvim/spell.c
+++ b/src/nvim/spell.c
@@ -6672,7 +6672,7 @@ void ex_spelldump(exarg_T *eap)
set_option_value("spl", dummy, (char *)spl, OPT_LOCAL);
xfree(spl);
- if (!BUFEMPTY(curbuf)) {
+ if (!buf_is_empty(curbuf)) {
return;
}
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index ea254033f1..63224eb0a6 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -2431,7 +2431,7 @@ static void u_undoredo(int undo, bool do_buf_event)
curhead->uh_entry = newlist;
curhead->uh_flags = new_flags;
- if ((old_flags & UH_EMPTYBUF) && BUFEMPTY(curbuf)) {
+ if ((old_flags & UH_EMPTYBUF) && buf_is_empty(curbuf)) {
curbuf->b_ml.ml_flags |= ML_EMPTY;
}
if (old_flags & UH_CHANGED) {
diff --git a/src/nvim/version.c b/src/nvim/version.c
index 507352e146..48ef71613e 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -13,6 +13,7 @@
#include "nvim/api/private/helpers.h"
#include "nvim/vim.h"
#include "nvim/ascii.h"
+#include "nvim/buffer.h"
#include "nvim/iconv.h"
#include "nvim/version.h"
#include "nvim/charset.h"
@@ -2190,7 +2191,7 @@ void list_version(void)
/// Show the intro message when not editing a file.
void maybe_intro_message(void)
{
- if (BUFEMPTY(curbuf)
+ if (buf_is_empty(curbuf)
&& (curbuf->b_fname == NULL)
&& (firstwin->w_next == NULL)
&& (vim_strchr(p_shm, SHM_INTRO) == NULL)) {