mirror of
https://github.com/neovim/neovim.git
synced 2025-10-17 23:31:51 +00:00
buffer: move BUFEMPTY to a function
This commit is contained in:
@@ -55,7 +55,6 @@
|
|||||||
#include "nvim/mark.h"
|
#include "nvim/mark.h"
|
||||||
#include "nvim/extmark.h"
|
#include "nvim/extmark.h"
|
||||||
#include "nvim/mbyte.h"
|
#include "nvim/mbyte.h"
|
||||||
#include "nvim/memline.h"
|
|
||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/message.h"
|
#include "nvim/message.h"
|
||||||
#include "nvim/misc1.h"
|
#include "nvim/misc1.h"
|
||||||
@@ -139,7 +138,7 @@ read_buffer(
|
|||||||
if (read_stdin) {
|
if (read_stdin) {
|
||||||
// Set or reset 'modified' before executing autocommands, so that
|
// Set or reset 'modified' before executing autocommands, so that
|
||||||
// it can be changed there.
|
// it can be changed there.
|
||||||
if (!readonlymode && !BUFEMPTY(curbuf)) {
|
if (!readonlymode && !buf_is_empty(curbuf)) {
|
||||||
changed();
|
changed();
|
||||||
} else if (retval != FAIL) {
|
} else if (retval != FAIL) {
|
||||||
unchanged(curbuf, false, true);
|
unchanged(curbuf, false, true);
|
||||||
@@ -1921,7 +1920,7 @@ bool curbuf_reusable(void)
|
|||||||
return (curbuf != NULL
|
return (curbuf != NULL
|
||||||
&& curbuf->b_ffname == NULL
|
&& curbuf->b_ffname == NULL
|
||||||
&& curbuf->b_nwindows <= 1
|
&& 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)
|
&& !bt_quickfix(curbuf)
|
||||||
&& !curbufIsChanged());
|
&& !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
|
// If 'switchbuf' contains "split", "vsplit" or "newtab" and the
|
||||||
// current buffer isn't empty: open new tab or window
|
// current buffer isn't empty: open new tab or window
|
||||||
if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB))
|
if (wp == NULL && (swb_flags & (SWB_VSPLIT | SWB_SPLIT | SWB_NEWTAB))
|
||||||
&& !BUFEMPTY(curbuf)) {
|
&& !buf_is_empty(curbuf)) {
|
||||||
if (swb_flags & SWB_NEWTAB) {
|
if (swb_flags & SWB_NEWTAB) {
|
||||||
tabpage_new();
|
tabpage_new();
|
||||||
} else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0)
|
} else if (win_split(0, (swb_flags & SWB_VSPLIT) ? WSP_VERT : 0)
|
||||||
@@ -4951,7 +4950,7 @@ do_arg_all(
|
|||||||
win_enter(lastwin, false);
|
win_enter(lastwin, false);
|
||||||
// ":tab drop file" should re-use an empty window to avoid "--remote-tab"
|
// ":tab drop file" should re-use an empty window to avoid "--remote-tab"
|
||||||
// leaving an empty tab page when executed locally.
|
// 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) {
|
&& curbuf->b_ffname == NULL && !curbuf->b_changed) {
|
||||||
use_firstwin = true;
|
use_firstwin = true;
|
||||||
tab_drop_empty_window = 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);
|
set_option_value("swf", 0L, NULL, OPT_LOCAL);
|
||||||
RESET_BINDING(curwin);
|
RESET_BINDING(curwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include "nvim/func_attr.h"
|
#include "nvim/func_attr.h"
|
||||||
#include "nvim/eval.h"
|
#include "nvim/eval.h"
|
||||||
#include "nvim/macros.h"
|
#include "nvim/macros.h"
|
||||||
|
#include "nvim/memline.h"
|
||||||
|
|
||||||
// Values for buflist_getfile()
|
// Values for buflist_getfile()
|
||||||
enum getf_values {
|
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);
|
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
|
#endif // NVIM_BUFFER_H
|
||||||
|
@@ -2669,7 +2669,7 @@ void ex_diffgetput(exarg_T *eap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
buf_empty = BUFEMPTY(curbuf);
|
buf_empty = buf_is_empty(curbuf);
|
||||||
added = 0;
|
added = 0;
|
||||||
|
|
||||||
for (i = 0; i < count; ++i) {
|
for (i = 0; i < count; ++i) {
|
||||||
|
@@ -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 first character in buffer
|
||||||
// can't backup past starting point unless 'backspace' > 1
|
// can't backup past starting point unless 'backspace' > 1
|
||||||
// can backup to a previous line if 'backspace' == 0
|
// can backup to a previous line if 'backspace' == 0
|
||||||
if (BUFEMPTY(curbuf)
|
if (buf_is_empty(curbuf)
|
||||||
|| (!revins_on
|
|| (!revins_on
|
||||||
&& ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
|
&& ((curwin->w_cursor.lnum == 1 && curwin->w_cursor.col == 0)
|
||||||
|| (!can_bs(BS_START)
|
|| (!can_bs(BS_START)
|
||||||
|
@@ -5027,7 +5027,7 @@ void buf_reload(buf_T *buf, int orig_mode)
|
|||||||
// buffer contents. But if reading the file fails we should keep
|
// buffer contents. But if reading the file fails we should keep
|
||||||
// the old contents. Can't use memory only, the file might be
|
// the old contents. Can't use memory only, the file might be
|
||||||
// too big. Use a hidden buffer to move the buffer contents to.
|
// 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;
|
savebuf = NULL;
|
||||||
} else {
|
} else {
|
||||||
// Allocate a buffer without putting it in the buffer list.
|
// 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) {
|
if (savebuf != NULL && bufref_valid(&bufref) && buf == curbuf) {
|
||||||
// Put the text back from the save buffer. First
|
// Put the text back from the save buffer. First
|
||||||
// delete any lines that readfile() added.
|
// 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) {
|
if (ml_delete(buf->b_ml.ml_line_count, false) == FAIL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -34,10 +34,6 @@
|
|||||||
/// LINEEMPTY() - return TRUE if the line is empty
|
/// LINEEMPTY() - return TRUE if the line is empty
|
||||||
#define LINEEMPTY(p) (*ml_get(p) == NUL)
|
#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.
|
// toupper() and tolower() that use the current locale.
|
||||||
// Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the
|
// 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.
|
// range 0 - 255. toupper()/tolower() on some systems can't handle others.
|
||||||
|
@@ -1446,7 +1446,7 @@ static void read_stdin(void)
|
|||||||
set_buflisted(true);
|
set_buflisted(true);
|
||||||
// Create memfile and read from stdin.
|
// Create memfile and read from stdin.
|
||||||
(void)open_buffer(true, NULL, 0);
|
(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
|
// stdin was empty, go to buffer 2 (e.g. "echo file1 | xargs nvim"). #8561
|
||||||
do_cmdline_cmd("silent! bnext");
|
do_cmdline_cmd("silent! bnext");
|
||||||
// Delete the empty stdin buffer.
|
// Delete the empty stdin buffer.
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/move.h"
|
#include "nvim/move.h"
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
#include "nvim/cursor.h"
|
#include "nvim/cursor.h"
|
||||||
@@ -172,7 +173,7 @@ void update_topline(win_T *wp)
|
|||||||
old_topfill = wp->w_topfill;
|
old_topfill = wp->w_topfill;
|
||||||
|
|
||||||
// If the buffer is empty, always set topline to 1.
|
// 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) {
|
if (wp->w_topline != 1) {
|
||||||
redraw_later(wp, NOT_VALID);
|
redraw_later(wp, NOT_VALID);
|
||||||
}
|
}
|
||||||
|
@@ -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
|
// In an empty buffer the empty line is going to be replaced, include
|
||||||
// it in the saved lines.
|
// 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;
|
goto end;
|
||||||
}
|
}
|
||||||
if (dir == FORWARD) {
|
if (dir == FORWARD) {
|
||||||
|
@@ -880,7 +880,7 @@ void set_init_3(void)
|
|||||||
xfree(p);
|
xfree(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BUFEMPTY(curbuf)) {
|
if (buf_is_empty(curbuf)) {
|
||||||
int idx_ffs = findoption_len(S_LEN("ffs"));
|
int idx_ffs = findoption_len(S_LEN("ffs"));
|
||||||
|
|
||||||
// Apply the first entry of 'fileformats' to the initial buffer.
|
// Apply the first entry of 'fileformats' to the initial buffer.
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/ascii.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_bt[2] == 'f')
|
||||||
&& (curbuf->b_p_bh[0] == 'w')) {
|
&& (curbuf->b_p_bh[0] == 'w')) {
|
||||||
// Already a "wipeout" buffer, make it empty.
|
// Already a "wipeout" buffer, make it empty.
|
||||||
while (!BUFEMPTY(curbuf)) {
|
while (!buf_is_empty(curbuf)) {
|
||||||
ml_delete((linenr_T)1, false);
|
ml_delete((linenr_T)1, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@@ -6672,7 +6672,7 @@ void ex_spelldump(exarg_T *eap)
|
|||||||
set_option_value("spl", dummy, (char *)spl, OPT_LOCAL);
|
set_option_value("spl", dummy, (char *)spl, OPT_LOCAL);
|
||||||
xfree(spl);
|
xfree(spl);
|
||||||
|
|
||||||
if (!BUFEMPTY(curbuf)) {
|
if (!buf_is_empty(curbuf)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2431,7 +2431,7 @@ static void u_undoredo(int undo, bool do_buf_event)
|
|||||||
|
|
||||||
curhead->uh_entry = newlist;
|
curhead->uh_entry = newlist;
|
||||||
curhead->uh_flags = new_flags;
|
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;
|
curbuf->b_ml.ml_flags |= ML_EMPTY;
|
||||||
}
|
}
|
||||||
if (old_flags & UH_CHANGED) {
|
if (old_flags & UH_CHANGED) {
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
#include "nvim/api/private/helpers.h"
|
#include "nvim/api/private/helpers.h"
|
||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/ascii.h"
|
#include "nvim/ascii.h"
|
||||||
|
#include "nvim/buffer.h"
|
||||||
#include "nvim/iconv.h"
|
#include "nvim/iconv.h"
|
||||||
#include "nvim/version.h"
|
#include "nvim/version.h"
|
||||||
#include "nvim/charset.h"
|
#include "nvim/charset.h"
|
||||||
@@ -2190,7 +2191,7 @@ void list_version(void)
|
|||||||
/// Show the intro message when not editing a file.
|
/// Show the intro message when not editing a file.
|
||||||
void maybe_intro_message(void)
|
void maybe_intro_message(void)
|
||||||
{
|
{
|
||||||
if (BUFEMPTY(curbuf)
|
if (buf_is_empty(curbuf)
|
||||||
&& (curbuf->b_fname == NULL)
|
&& (curbuf->b_fname == NULL)
|
||||||
&& (firstwin->w_next == NULL)
|
&& (firstwin->w_next == NULL)
|
||||||
&& (vim_strchr(p_shm, SHM_INTRO) == NULL)) {
|
&& (vim_strchr(p_shm, SHM_INTRO) == NULL)) {
|
||||||
|
Reference in New Issue
Block a user