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.c312
1 files changed, 131 insertions, 181 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 809aa30692..e9d89c2f91 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -109,11 +109,9 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags)
int retval = OK;
linenr_T line_count;
- //
// Read from the buffer which the text is already filled in and append at
// the end. This makes it possible to retry when 'fileformat' or
// 'fileencoding' was guessed wrong.
- //
line_count = curbuf->b_ml.ml_line_count;
retval = readfile(read_stdin ? NULL : curbuf->b_ffname,
read_stdin ? NULL : curbuf->b_fname,
@@ -164,21 +162,17 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
long old_tw = curbuf->b_p_tw;
int read_fifo = false;
- /*
- * The 'readonly' flag is only set when BF_NEVERLOADED is being reset.
- * When re-entering the same buffer, it should not change, because the
- * user may have reset the flag by hand.
- */
+ // The 'readonly' flag is only set when BF_NEVERLOADED is being reset.
+ // When re-entering the same buffer, it should not change, because the
+ // user may have reset the flag by hand.
if (readonlymode && curbuf->b_ffname != NULL
&& (curbuf->b_flags & BF_NEVERLOADED)) {
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
- */
+ // 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);
curbuf = NULL;
@@ -192,7 +186,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
// If there is no memfile at all, exit.
// This is OK, since there are no changes to lose.
if (curbuf == NULL) {
- EMSG(_("E82: Cannot allocate any buffer, exiting..."));
+ emsg(_("E82: Cannot allocate any buffer, exiting..."));
// Don't try to do any saving, with "curbuf" NULL almost nothing
// will work.
@@ -200,7 +194,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
getout(2);
}
- EMSG(_("E83: Cannot allocate buffer, using other one..."));
+ emsg(_("E83: Cannot allocate buffer, using other one..."));
enter_buffer(curbuf);
if (old_tw != curbuf->b_p_tw) {
check_colorcolumn(curwin);
@@ -260,12 +254,10 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
} else if (read_stdin) {
int save_bin = curbuf->b_p_bin;
- /*
- * First read the text in binary mode into the buffer.
- * Then read from that same buffer and append at the end. This makes
- * it possible to retry when 'fileformat' or 'fileencoding' was
- * guessed wrong.
- */
+ // First read the text in binary mode into the buffer.
+ // Then read from that same buffer and append at the end. This makes
+ // it possible to retry when 'fileformat' or 'fileencoding' was
+ // guessed wrong.
curbuf->b_p_bin = true;
retval = readfile(NULL, NULL, (linenr_T)0,
(linenr_T)0, (linenr_T)MAXLNUM, NULL,
@@ -308,8 +300,8 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
curbuf->b_flags |= BF_READERR;
}
- /* Need to update automatic folding. Do this before the autocommands,
- * they may use the fold info. */
+ // 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.
@@ -323,10 +315,8 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
return FAIL;
}
- /*
- * The autocommands may have changed the current buffer. Apply the
- * modelines to the correct buffer, if it still exists and is loaded.
- */
+ // The autocommands may have changed the current buffer. Apply the
+ // modelines to the correct buffer, if it still exists and is loaded.
if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) {
aco_save_T aco;
@@ -335,8 +325,10 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
do_modelines(0);
curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
- apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, false, curbuf,
- &retval);
+ if ((flags & READ_NOWINENTER) == 0) {
+ apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, false, curbuf,
+ &retval);
+ }
// restore curwin/curbuf and a few other things
aucmd_restbuf(&aco);
@@ -447,7 +439,7 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
// Disallow deleting the buffer when it is locked (already being closed or
// halfway a command that relies on it). Unloading is allowed.
if (buf->b_locked > 0 && (del_buf || wipe_buf)) {
- EMSG(_("E937: Attempt to delete a buffer that is in use"));
+ emsg(_("E937: Attempt to delete a buffer that is in use"));
return false;
}
@@ -474,13 +466,13 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
if (apply_autocmds(EVENT_BUFWINLEAVE, buf->b_fname, buf->b_fname, false,
buf) && !bufref_valid(&bufref)) {
// Autocommands deleted the buffer.
- EMSG(_(e_auabort));
+ emsg(_(e_auabort));
return false;
}
buf->b_locked--;
if (abort_if_last && last_nonfloat(win)) {
// Autocommands made this the only window.
- EMSG(_(e_auabort));
+ emsg(_(e_auabort));
return false;
}
@@ -491,13 +483,13 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
if (apply_autocmds(EVENT_BUFHIDDEN, buf->b_fname, buf->b_fname, false,
buf) && !bufref_valid(&bufref)) {
// Autocommands deleted the buffer.
- EMSG(_(e_auabort));
+ emsg(_(e_auabort));
return false;
}
buf->b_locked--;
if (abort_if_last && last_nonfloat(win)) {
// Autocommands made this the only window.
- EMSG(_(e_auabort));
+ emsg(_(e_auabort));
return false;
}
}
@@ -509,7 +501,7 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
// If the buffer was in curwin and the window has changed, go back to that
// window, if it still exists. This avoids that ":edit x" triggering a
// "tabnext" BufUnload autocmd leaves a window behind without a buffer.
- if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) {
+ if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) {
block_autocmds();
goto_tabpage_win(the_curtab, the_curwin);
unblock_autocmds();
@@ -570,13 +562,11 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
return false;
}
- /*
- * It's possible that autocommands change curbuf to the one being deleted.
- * This might cause the previous curbuf to be deleted unexpectedly. But
- * in some cases it's OK to delete the curbuf, because a new one is
- * obtained anyway. Therefore only return if curbuf changed to the
- * deleted buffer.
- */
+ // It's possible that autocommands change curbuf to the one being deleted.
+ // This might cause the previous curbuf to be deleted unexpectedly. But
+ // in some cases 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) {
return false;
}
@@ -708,7 +698,7 @@ void buf_freeall(buf_T *buf, int flags)
// If the buffer was in curwin and the window has changed, go back to that
// window, if it still exists. This avoids that ":edit x" triggering a
// "tabnext" BufUnload autocmd leaves a window behind without a buffer.
- if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) {
+ if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) {
block_autocmds();
goto_tabpage_win(the_curtab, the_curwin);
unblock_autocmds();
@@ -717,12 +707,10 @@ void buf_freeall(buf_T *buf, int flags)
return;
}
- /*
- * It's possible that autocommands change curbuf to the one being deleted.
- * This might cause curbuf to be deleted unexpectedly. But in some cases
- * it's OK to delete the curbuf, because a new one is obtained anyway.
- * Therefore only return if curbuf changed to the deleted buffer.
- */
+ // It's possible that autocommands change curbuf to the one being deleted.
+ // This might cause curbuf to be deleted unexpectedly. But in some cases
+ // 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) {
return;
}
@@ -818,7 +806,6 @@ static void free_buffer_stuff(buf_T *buf, int free_flags)
uc_clear(&buf->b_ucmds); // clear local user commands
buf_delete_signs(buf, (char_u *)"*"); // delete any signs
extmark_free_all(buf); // delete any extmarks
- clear_virt_lines(buf, -1);
map_clear_int(buf, MAP_ALL_MODES, true, false); // clear local mappings
map_clear_int(buf, MAP_ALL_MODES, true, true); // clear local abbrevs
XFREE_CLEAR(buf->b_start_fenc);
@@ -864,8 +851,8 @@ void goto_buffer(exarg_T *eap, int start, int dir, int count)
swap_exists_action = SEA_NONE;
swap_exists_did_quit = true;
- /* Restore the error/interrupt/exception state if not discarded by a
- * new aborting error, interrupt, or uncaught exception. */
+ // Restore the error/interrupt/exception state if not discarded by a
+ // new aborting error, interrupt, or uncaught exception.
leave_cleanup(&cs);
} else {
handle_swap_exists(&old_curbuf);
@@ -920,8 +907,8 @@ void handle_swap_exists(bufref_T *old_curbuf)
}
// 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. */
+ // 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
@@ -931,12 +918,12 @@ void handle_swap_exists(bufref_T *old_curbuf)
// User selected Recover at ATTENTION prompt.
msg_scroll = true;
ml_recover(false);
- 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);
- /* Restore the error/interrupt/exception state if not discarded by a
- * new aborting error, interrupt, or uncaught exception. */
+ // Restore the error/interrupt/exception state if not discarded by a
+ // new aborting error, interrupt, or uncaught exception.
leave_cleanup(&cs);
}
swap_exists_action = SEA_NONE; // -V519
@@ -957,11 +944,11 @@ void handle_swap_exists(bufref_T *old_curbuf)
/// @param end_bnr buffer nr or last buffer nr in a range
///
/// @return error message or NULL
-char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit)
+char *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end_bnr, int forceit)
{
int do_current = 0; // delete current buffer?
int deleted = 0; // number of buffers deleted
- char_u *errormsg = NULL; // return value
+ char *errormsg = NULL; // return value
int bnr; // buffer number
char_u *p;
@@ -970,7 +957,7 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e
} else {
if (addr_count == 2) {
if (*arg) { // both range and argument is not allowed
- return (char_u *)_(e_trailing);
+ return _(e_trailing);
}
bnr = start_bnr;
} else { // addr_count == 1
@@ -978,12 +965,10 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e
}
for (; !got_int; os_breakcheck()) {
- /*
- * delete the current buffer last, otherwise when the
- * current buffer is deleted, the next buffer becomes
- * the current one and will be loaded, which may then
- * also be deleted, etc.
- */
+ // delete the current buffer last, otherwise when the
+ // current buffer is deleted, the next buffer becomes
+ // the current one and will be loaded, which may then
+ // also be deleted, etc.
if (bnr == curbuf->b_fnum) {
do_current = bnr;
} else if (do_buffer(command, DOBUF_FIRST, FORWARD, bnr,
@@ -991,9 +976,7 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e
deleted++;
}
- /*
- * find next buffer number to delete/unload
- */
+ // find next buffer number to delete/unload
if (addr_count == 2) {
if (++bnr > end_bnr) {
break;
@@ -1030,26 +1013,17 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e
} else {
STRCPY(IObuff, _("E517: No buffers were wiped out"));
}
- errormsg = IObuff;
+ errormsg = (char *)IObuff;
} else if (deleted >= p_report) {
if (command == DOBUF_UNLOAD) {
- if (deleted == 1) {
- MSG(_("1 buffer unloaded"));
- } else {
- smsg(_("%d buffers unloaded"), deleted);
- }
+ smsg(NGETTEXT("%d buffer unloaded", "%d buffers unloaded", (unsigned long)deleted),
+ deleted);
} else if (command == DOBUF_DEL) {
- if (deleted == 1) {
- MSG(_("1 buffer deleted"));
- } else {
- smsg(_("%d buffers deleted"), deleted);
- }
+ smsg(NGETTEXT("%d buffer deleted", "%d buffers deleted", (unsigned long)deleted),
+ deleted);
} else {
- if (deleted == 1) {
- MSG(_("1 buffer wiped out"));
- } else {
- smsg(_("%d buffers wiped out"), deleted);
- }
+ smsg(NGETTEXT("%d buffer wiped out", "%d buffers wiped out", (unsigned long)deleted),
+ deleted);
}
}
}
@@ -1059,7 +1033,6 @@ char_u *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int e
}
-
/*
* Make the current buffer empty.
* Used when it is wiped out and it's the last buffer.
@@ -1070,7 +1043,7 @@ static int empty_curbuf(int close_others, int forceit, int action)
buf_T *buf = curbuf;
if (action == DOBUF_UNLOAD) {
- EMSG(_("E90: Cannot unload last buffer"));
+ emsg(_("E90: Cannot unload last buffer"));
return FAIL;
}
@@ -1143,7 +1116,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
} while (buf != curbuf && !bufIsChanged(buf));
}
if (!bufIsChanged(buf)) {
- EMSG(_("E84: No modified buffer found"));
+ emsg(_("E84: No modified buffer found"));
return FAIL;
}
} else if (start == DOBUF_FIRST && count) { // find specified buffer number
@@ -1153,8 +1126,8 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
} 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. */
+ // remember the buffer where we start, we come back there when all
+ // buffers are unlisted.
if (bp == NULL) {
bp = buf;
}
@@ -1176,7 +1149,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
}
if (bp == buf) {
// back where we started, didn't find anything.
- EMSG(_("E85: There is no listed buffer"));
+ emsg(_("E85: There is no listed buffer"));
return FAIL;
}
}
@@ -1186,27 +1159,25 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
if (start == DOBUF_FIRST) {
// don't warn when deleting
if (!unload) {
- EMSGN(_(e_nobufnr), count);
+ semsg(_(e_nobufnr), (int64_t)count);
}
} else if (dir == FORWARD) {
- EMSG(_("E87: Cannot go beyond last buffer"));
+ emsg(_("E87: Cannot go beyond last buffer"));
} else {
- EMSG(_("E88: Cannot go before first buffer"));
+ emsg(_("E88: Cannot go before first buffer"));
}
return FAIL;
}
- /*
- * delete buffer buf from memory and/or the list
- */
+ // delete buffer "buf" from memory and/or the list
if (unload) {
int forward;
bufref_T bufref;
set_bufref(&bufref, buf);
- /* When unloading or deleting a buffer that's already unloaded and
- * unlisted: fail silently. */
+ // 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) {
return FAIL;
}
@@ -1224,9 +1195,9 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
return FAIL;
}
} else {
- EMSGN(_("E89: No write since last change for buffer %" PRId64
+ semsg(_("E89: No write since last change for buffer %" PRId64
" (add ! to override)"),
- buf->b_fnum);
+ (int64_t)buf->b_fnum);
return FAIL;
}
}
@@ -1237,7 +1208,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
return FAIL;
}
} else {
- EMSG2(_("E89: %s will be killed (add ! to override)"),
+ semsg(_("E89: %s will be killed (add ! to override)"),
(char *)buf->b_fname);
return FAIL;
}
@@ -1248,10 +1219,8 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
end_visual_mode();
}
- /*
- * If deleting the last (listed) buffer, make it empty.
- * The last (listed) buffer cannot be unloaded.
- */
+ // If deleting the last (listed) buffer, make it empty.
+ // The last (listed) buffer cannot be unloaded.
bp = NULL;
FOR_ALL_BUFFERS(bp2) {
if (bp2->b_p_bl && bp2 != buf) {
@@ -1263,11 +1232,9 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
return empty_curbuf(true, forceit, action);
}
- /*
- * If the deleted buffer is the current one, close the current window
- * (unless it's the only window). Repeat this so long as we end up in
- * a window with this buffer.
- */
+ // If the deleted buffer is the current one, close the current window
+ // (unless it's the only window). Repeat this so long as we end up in
+ // a window with this buffer.
while (buf == curbuf
&& !(curwin->w_closing || curwin->w_buffer->b_locked > 0)
&& (!ONE_WINDOW || first_tabpage->tp_next != NULL)) {
@@ -1276,9 +1243,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
}
}
- /*
- * If the buffer to be deleted is not the current one, delete it here.
- */
+ // If the buffer to be deleted is not the current one, delete it here.
if (buf != curbuf) {
close_windows(buf, false);
if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows <= 0) {
@@ -1386,14 +1351,12 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
}
if (buf == NULL) {
- /* Autocommands must have wiped out all other buffers. Only option
- * now is to make the current buffer empty. */
+ // Autocommands must have wiped out all other buffers. Only option
+ // now is to make the current buffer empty.
return empty_curbuf(false, forceit, action);
}
- /*
- * make buf current buffer
- */
+ // make "buf" the current buffer
if (action == DOBUF_SPLIT) { // split window first
// If 'switchbuf' contains "useopen": jump to first window containing
// "buf" if one exists
@@ -1415,9 +1378,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
return OK;
}
- /*
- * Check if the current buffer may be abandoned.
- */
+ // Check if the current buffer may be abandoned.
if (action == DOBUF_GOTO && !can_abandon(curbuf, forceit)) {
if ((p_confirm || cmdmod.confirm) && p_write) {
bufref_T bufref;
@@ -1510,9 +1471,9 @@ void set_curbuf(buf_T *buf, int action)
}
}
}
- /* An autocommand may have deleted "buf", already entered it (e.g., when
- * it did ":bunload") or aborted the script processing!
- * If curwin->w_buffer is null, enter_buffer() will make it valid again */
+ // An autocommand may have deleted "buf", already entered it (e.g., when
+ // it did ":bunload") or aborted the script processing!
+ // If curwin->w_buffer is null, enter_buffer() will make it valid again
if ((buf_valid(buf) && buf != curbuf
&& !aborting()
) || curwin->w_buffer == NULL) {
@@ -1636,9 +1597,9 @@ void no_write_message(void)
{
if (curbuf->terminal
&& channel_job_running((uint64_t)curbuf->b_p_channel)) {
- EMSG(_("E948: Job still running (add ! to end the job)"));
+ emsg(_("E948: Job still running (add ! to end the job)"));
} else {
- EMSG(_("E37: No write since last change (add ! to override)"));
+ emsg(_("E37: No write since last change (add ! to override)"));
}
}
@@ -1647,9 +1608,9 @@ void no_write_message_nobang(const buf_T *const buf)
{
if (buf->terminal
&& channel_job_running((uint64_t)buf->b_p_channel)) {
- EMSG(_("E948: Job still running"));
+ emsg(_("E948: Job still running"));
} else {
- EMSG(_("E37: No write since last change"));
+ emsg(_("E37: No write since last change"));
}
}
@@ -1705,11 +1666,10 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl
fname_expand(curbuf, &ffname, &sfname); // will allocate ffname
- /*
- * If file name already exists in the list, update the entry.
- */
- /* We can use inode numbers when the file exists. Works better
- * for hard links. */
+ // If the file name already exists in the list, update the entry.
+
+ // We can use inode numbers when the file exists. Works better
+ // for hard links.
FileID file_id;
bool file_id_valid = (sfname != NULL
&& os_fileid((char *)sfname, &file_id));
@@ -1833,7 +1793,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl
buf->b_fnum = top_file_num++;
pmap_put(handle_T)(&buffer_handles, buf->b_fnum, buf);
if (top_file_num < 0) { // wrap around (may cause duplicates)
- EMSG(_("W14: Warning: List of file names overflow"));
+ emsg(_("W14: Warning: List of file names overflow"));
if (emsg_silent == 0) {
ui_flush();
os_delay(3001L, true); // make sure it is noticed
@@ -1841,9 +1801,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl
top_file_num = 1;
}
- /*
- * Always copy the options from the current buffer.
- */
+ // Always copy the options from the current buffer.
buf_copy_options(buf, BCO_ALWAYS);
}
@@ -2005,9 +1963,9 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
buf = buflist_findnr(n);
if (buf == NULL) {
if ((options & GETF_ALT) && n == 0) {
- EMSG(_(e_noalt));
+ emsg(_(e_noalt));
} else {
- EMSGN(_("E92: Buffer %" PRId64 " not found"), n);
+ semsg(_("E92: Buffer %" PRId64 " not found"), (int64_t)n);
}
return FAIL;
}
@@ -2228,8 +2186,8 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis
&& (!diffmode || diff_mode_buf(buf))
&& buflist_match(&regmatch, buf, false) != NULL) {
if (curtab_only) {
- /* Ignore the match if the buffer is not open in
- * the current tab. */
+ // Ignore the match if the buffer is not open in
+ // the current tab.
bool found_window = false;
FOR_ALL_WINDOWS_IN_TAB(wp, curtab) {
if (wp->w_buffer == buf) {
@@ -2267,9 +2225,9 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis
}
if (match == -2) {
- EMSG2(_("E93: More than one match for %s"), pattern);
+ semsg(_("E93: More than one match for %s"), pattern);
} else if (match < 0) {
- EMSG2(_("E94: No matching buffer for %s"), pattern);
+ semsg(_("E94: No matching buffer for %s"), pattern);
}
return match;
}
@@ -2321,10 +2279,8 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
patc = pat;
}
- /*
- * attempt == 0: try match with '\<', match at start of word
- * attempt == 1: try match without '\<', match anywhere
- */
+ // attempt == 0: try match with '\<', match at start of word
+ // attempt == 1: try match without '\<', match anywhere
for (attempt = 0; attempt <= 1; attempt++) {
if (attempt > 0 && patc == pat) {
break; // there was no anchor, no need to try again
@@ -2339,10 +2295,8 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
return FAIL;
}
- /*
- * round == 1: Count the matches.
- * round == 2: Build the array to keep the matches.
- */
+ // round == 1: Count the matches.
+ // round == 2: Build the array to keep the matches.
for (round = 1; round <= 2; round++) {
count = 0;
FOR_ALL_BUFFERS(buf) {
@@ -2832,11 +2786,9 @@ int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message)
return FAIL;
}
- /*
- * if the file name is already used in another buffer:
- * - if the buffer is loaded, fail
- * - if the buffer is not loaded, delete it from the list
- */
+ // If the file name is already used in another buffer:
+ // - if the buffer is loaded, fail
+ // - if the buffer is not loaded, delete it from the list
file_id_valid = os_fileid((char *)ffname, &file_id);
if (!(buf->b_flags & BF_DUMMY)) {
obuf = buflist_findname_file_id(ffname, &file_id, file_id_valid);
@@ -2844,7 +2796,7 @@ int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message)
if (obuf != NULL && obuf != buf) {
if (obuf->b_ml.ml_mfp != NULL) { // it's loaded, fail
if (message) {
- EMSG(_("E95: Buffer with this name already exists"));
+ emsg(_("E95: Buffer with this name already exists"));
}
xfree(ffname);
return FAIL;
@@ -2949,7 +2901,7 @@ char_u *getaltfname(bool errmsg)
if (buflist_name_nr(0, &fname, &dummy) == FAIL) {
if (errmsg) {
- EMSG(_(e_noalt));
+ emsg(_(e_noalt));
}
return NULL;
}
@@ -3088,14 +3040,14 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
{
char_u *name;
int n;
- char_u *p;
- char_u *buffer;
+ char *p;
+ char *buffer;
size_t len;
buffer = xmalloc(IOSIZE);
if (fullname > 1) { // 2 CTRL-G: include buffer number
- vim_snprintf((char *)buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
+ vim_snprintf(buffer, IOSIZE, "buf %d: ", curbuf->b_fnum);
p = buffer + STRLEN(buffer);
} else {
p = buffer;
@@ -3110,12 +3062,12 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
} else {
name = curbuf->b_ffname;
}
- home_replace(shorthelp ? curbuf : NULL, name, p,
+ home_replace(shorthelp ? curbuf : NULL, name, (char_u *)p,
(size_t)(IOSIZE - (p - buffer)), true);
}
bool dontwrite = bt_dontwrite(curbuf);
- vim_snprintf_add((char *)buffer, IOSIZE, "\"%s%s%s%s%s%s",
+ vim_snprintf_add(buffer, IOSIZE, "\"%s%s%s%s%s%s",
curbufIsChanged()
? (shortmess(SHM_MOD) ? " [+]" : _(" [Modified]")) : " ",
(curbuf->b_flags & BF_NOTEDITED) && !dontwrite
@@ -3140,28 +3092,27 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
(long)curbuf->b_ml.ml_line_count);
}
if (curbuf->b_ml.ml_flags & ML_EMPTY) {
- vim_snprintf_add((char *)buffer, IOSIZE, "%s", _(no_lines_msg));
+ vim_snprintf_add(buffer, IOSIZE, "%s", _(no_lines_msg));
} else if (p_ru) {
// Current line and column are already on the screen -- webb
- if (curbuf->b_ml.ml_line_count == 1) {
- vim_snprintf_add((char *)buffer, IOSIZE, _("1 line --%d%%--"), n);
- } else {
- vim_snprintf_add((char *)buffer, IOSIZE, _("%" PRId64 " lines --%d%%--"),
- (int64_t)curbuf->b_ml.ml_line_count, n);
- }
+ vim_snprintf_add(buffer, IOSIZE,
+ NGETTEXT("%" PRId64 " line --%d%%--",
+ "%" PRId64 " lines --%d%%--",
+ (unsigned long)curbuf->b_ml.ml_line_count),
+ (int64_t)curbuf->b_ml.ml_line_count, n);
} else {
- vim_snprintf_add((char *)buffer, IOSIZE,
+ vim_snprintf_add(buffer, IOSIZE,
_("line %" PRId64 " of %" PRId64 " --%d%%-- col "),
(int64_t)curwin->w_cursor.lnum,
(int64_t)curbuf->b_ml.ml_line_count,
n);
validate_virtcol();
len = STRLEN(buffer);
- col_print(buffer + len, IOSIZE - len,
+ col_print((char_u *)buffer + len, IOSIZE - len,
(int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1);
}
- (void)append_arg_number(curwin, buffer, IOSIZE, !shortmess(SHM_FILE));
+ (void)append_arg_number(curwin, (char_u *)buffer, IOSIZE, !shortmess(SHM_FILE));
if (dont_truncate) {
// Temporarily set msg_scroll to avoid the message being truncated.
@@ -3179,7 +3130,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
// before redrawing).
// - When the screen was scrolled but there is no wait-return
// prompt.
- set_keep_msg(p, 0);
+ set_keep_msg((char_u *)p, 0);
}
}
@@ -3438,7 +3389,7 @@ void free_titles(void)
/// be used when printing numbers in the status line.
typedef enum {
kNumBaseDecimal = 10,
- kNumBaseHexadecimal = 16
+ kNumBaseHexadecimal = 16,
} NumberBase;
@@ -3511,7 +3462,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
if (fillchar == 0) {
fillchar = ' ';
- } else if (mb_char2len(fillchar) > 1) {
+ } else if (utf_char2len(fillchar) > 1) {
// Can't handle a multi-byte fill character yet.
fillchar = '-';
}
@@ -3699,7 +3650,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
long n = 0;
while (group_len >= stl_items[stl_groupitems[groupdepth]].maxwid) {
group_len -= ptr2cells(t + n);
- n += (*mb_ptr2len)(t + n);
+ n += utfc_ptr2len(t + n);
}
// }
@@ -5161,9 +5112,9 @@ void ex_buffer_all(exarg_T *eap)
swap_exists_action = SEA_NONE;
swap_exists_did_quit = true;
- /* Restore the error/interrupt/exception state if not
- * discarded by a new aborting error, interrupt, or uncaught
- * exception. */
+ // Restore the error/interrupt/exception state if not
+ // discarded by a new aborting error, interrupt, or uncaught
+ // exception.
leave_cleanup(&cs);
} else {
handle_swap_exists(NULL);
@@ -5211,7 +5162,6 @@ void ex_buffer_all(exarg_T *eap)
}
-
/*
* do_modelines() - process mode lines for the current file
*
@@ -5437,7 +5387,7 @@ bool bt_dontwrite_msg(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
if (bt_dontwrite(buf)) {
- EMSG(_("E382: Cannot write, 'buftype' option is set"));
+ emsg(_("E382: Cannot write, 'buftype' option is set"));
return true;
}
return false;