refactor: fix all clint warnings from buffer.c

This commit is contained in:
Dundar Göc 2022-03-10 17:34:41 +01:00
parent 6170574d2f
commit 9ff4acbb36

View File

@ -34,9 +34,9 @@
#include "nvim/channel.h" #include "nvim/channel.h"
#include "nvim/charset.h" #include "nvim/charset.h"
#include "nvim/cursor.h" #include "nvim/cursor.h"
#include "nvim/decoration.h"
#include "nvim/diff.h" #include "nvim/diff.h"
#include "nvim/digraph.h" #include "nvim/digraph.h"
#include "nvim/decoration.h"
#include "nvim/eval.h" #include "nvim/eval.h"
#include "nvim/ex_cmds.h" #include "nvim/ex_cmds.h"
#include "nvim/ex_cmds2.h" #include "nvim/ex_cmds2.h"
@ -223,7 +223,7 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags)
|| (S_ISCHR(perm) || (S_ISCHR(perm)
&& is_dev_fd_file(curbuf->b_ffname)) && is_dev_fd_file(curbuf->b_ffname))
# endif # endif
)) { )) { // NOLINT(whitespace/parens)
read_fifo = true; read_fifo = true;
} }
if (read_fifo) { if (read_fifo) {
@ -401,7 +401,7 @@ bool buf_valid(buf_T *buf)
/// there to be only one window with this buffer. e.g. when /// there to be only one window with this buffer. e.g. when
/// ":quit" is supposed to close the window but autocommands /// ":quit" is supposed to close the window but autocommands
/// close all other windows. /// close all other windows.
/// @returns true when we got to the end and b_nwindows was decremented. /// @return true when we got to the end and b_nwindows was decremented.
bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last) bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
{ {
bool unload_buf = (action != 0); bool unload_buf = (action != 0);
@ -587,9 +587,7 @@ bool close_buffer(win_T *win, buf_T *buf, int action, bool abort_if_last)
// No need to check `unload_buf`: in that case the function returned above. // No need to check `unload_buf`: in that case the function returned above.
buf_updates_unload(buf, false); buf_updates_unload(buf, false);
/* // Remove the buffer from the list.
* Remove the buffer from the list.
*/
if (wipe_buf) { if (wipe_buf) {
if (buf->b_sfname != buf->b_ffname) { if (buf->b_sfname != buf->b_ffname) {
XFREE_CLEAR(buf->b_sfname); XFREE_CLEAR(buf->b_sfname);
@ -737,10 +735,8 @@ void buf_freeall(buf_T *buf, int flags)
buf->b_flags &= ~BF_READERR; // a read error is no longer relevant buf->b_flags &= ~BF_READERR; // a read error is no longer relevant
} }
/* /// Free a buffer structure and the things it contains related to the buffer
* Free a buffer structure and the things it contains related to the buffer /// itself (not the file, that must have been done already).
* itself (not the file, that must have been done already).
*/
static void free_buffer(buf_T *buf) static void free_buffer(buf_T *buf)
{ {
pmap_del(handle_T)(&buffer_handles, buf->b_fnum); pmap_del(handle_T)(&buffer_handles, buf->b_fnum);
@ -813,9 +809,7 @@ static void free_buffer_stuff(buf_T *buf, int free_flags)
buf_updates_unload(buf, false); buf_updates_unload(buf, false);
} }
/* /// Free the b_wininfo list for buffer "buf".
* Free the b_wininfo list for buffer "buf".
*/
static void clear_wininfo(buf_T *buf) static void clear_wininfo(buf_T *buf)
{ {
wininfo_T *wip; wininfo_T *wip;
@ -827,9 +821,7 @@ static void clear_wininfo(buf_T *buf)
} }
} }
/* /// Go to another buffer. Handles the result of the ATTENTION dialog.
* Go to another buffer. Handles the result of the ATTENTION dialog.
*/
void goto_buffer(exarg_T *eap, int start, int dir, int count) void goto_buffer(exarg_T *eap, int start, int dir, int count)
{ {
bufref_T old_curbuf; bufref_T old_curbuf;
@ -1033,10 +1025,8 @@ char *do_bufdel(int command, char_u *arg, int addr_count, int start_bnr, int end
} }
/* /// Make the current buffer empty.
* Make the current buffer empty. /// Used when it is wiped out and it's the last buffer.
* Used when it is wiped out and it's the last buffer.
*/
static int empty_curbuf(int close_others, int forceit, int action) static int empty_curbuf(int close_others, int forceit, int action)
{ {
int retval; int retval;
@ -1410,15 +1400,15 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
} }
/* /// Set current buffer to "buf". Executes autocommands and closes current
* Set current buffer to "buf". Executes autocommands and closes current /// buffer.
* buffer. "action" tells how to close the current buffer: ///
* DOBUF_GOTO free or hide it /// @param action tells how to close the current buffer:
* DOBUF_SPLIT nothing /// DOBUF_GOTO free or hide it
* DOBUF_UNLOAD unload it /// DOBUF_SPLIT nothing
* DOBUF_DEL delete it /// DOBUF_UNLOAD unload it
* DOBUF_WIPE wipe it out /// DOBUF_DEL delete it
*/ /// DOBUF_WIPE wipe it out
void set_curbuf(buf_T *buf, int action) void set_curbuf(buf_T *buf, int action)
{ {
buf_T *prevbuf; buf_T *prevbuf;
@ -1478,9 +1468,7 @@ void set_curbuf(buf_T *buf, int action)
// An autocommand may have deleted "buf", already entered it (e.g., when // An autocommand may have deleted "buf", already entered it (e.g., when
// it did ":bunload") or aborted the script processing! // it did ":bunload") or aborted the script processing!
// If curwin->w_buffer is null, enter_buffer() will make it valid again // If curwin->w_buffer is null, enter_buffer() will make it valid again
if ((buf_valid(buf) && buf != curbuf if ((buf_valid(buf) && buf != curbuf && !aborting()) || curwin->w_buffer == NULL) {
&& !aborting()
) || curwin->w_buffer == NULL) {
enter_buffer(buf); enter_buffer(buf);
if (old_tw != curbuf->b_p_tw) { if (old_tw != curbuf->b_p_tw) {
check_colorcolumn(curwin); check_colorcolumn(curwin);
@ -1492,11 +1480,9 @@ void set_curbuf(buf_T *buf, int action)
} }
} }
/* /// Enter a new current buffer.
* Enter a new current buffer. /// Old curbuf must have been abandoned already! This also means "curbuf" may
* Old curbuf must have been abandoned already! This also means "curbuf" may /// be pointing to freed memory.
* be pointing to freed memory.
*/
void enter_buffer(buf_T *buf) void enter_buffer(buf_T *buf)
{ {
// Get the buffer in the current window. // Get the buffer in the current window.
@ -1583,8 +1569,8 @@ void enter_buffer(buf_T *buf)
redraw_later(curwin, NOT_VALID); redraw_later(curwin, NOT_VALID);
} }
// Change to the directory of the current buffer. /// Change to the directory of the current buffer.
// Don't do this while still starting up. /// Don't do this while still starting up.
void do_autochdir(void) void do_autochdir(void)
{ {
if (p_acd) { if (p_acd) {
@ -1661,7 +1647,7 @@ static inline void buf_init_changedtick(buf_T *const buf)
/// @param flags BLN_ defines /// @param flags BLN_ defines
/// @param bufnr /// @param bufnr
/// ///
/// @return pointer to the buffer /// @return pointer to the buffer
buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int flags) buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int flags)
{ {
char_u *ffname = ffname_arg; char_u *ffname = ffname_arg;
@ -1703,14 +1689,12 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl
return buf; return buf;
} }
/* // If the current buffer has no name and no contents, use the current
* If the current buffer has no name and no contents, use the current // buffer. Otherwise: Need to allocate a new buffer structure.
* buffer. Otherwise: Need to allocate a new buffer structure. //
* // This is the ONLY place where a new buffer structure is allocated!
* This is the ONLY place where a new buffer structure is allocated! // (A spell file buffer is allocated in spell.c, but that's not a normal
* (A spell file buffer is allocated in spell.c, but that's not a normal // buffer.)
* buffer.)
*/
buf = NULL; buf = NULL;
if ((flags & BLN_CURBUF) && curbuf_reusable()) { if ((flags & BLN_CURBUF) && curbuf_reusable()) {
assert(curbuf != NULL); assert(curbuf != NULL);
@ -1781,9 +1765,7 @@ buf_T *buflist_new(char_u *ffname_arg, char_u *sfname_arg, linenr_T lnum, int fl
// need to reload lmaps and set b:keymap_name // need to reload lmaps and set b:keymap_name
curbuf->b_kmap_state |= KEYMAP_INIT; curbuf->b_kmap_state |= KEYMAP_INIT;
} else { } else {
/* // put new buffer at the end of the buffer list
* put new buffer at the end of the buffer list
*/
buf->b_next = NULL; buf->b_next = NULL;
if (firstbuf == NULL) { // buffer list is empty if (firstbuf == NULL) { // buffer list is empty
buf->b_prev = NULL; buf->b_prev = NULL;
@ -1875,11 +1857,9 @@ bool curbuf_reusable(void)
&& !curbufIsChanged()); && !curbufIsChanged());
} }
/* /// Free the memory for the options of a buffer.
* Free the memory for the options of a buffer. /// If "free_p_ff" is true also free 'fileformat', 'buftype' and
* If "free_p_ff" is true also free 'fileformat', 'buftype' and /// 'fileencoding'.
* 'fileencoding'.
*/
void free_buf_options(buf_T *buf, int free_p_ff) void free_buf_options(buf_T *buf, int free_p_ff)
{ {
if (free_p_ff) { if (free_p_ff) {
@ -2039,7 +2019,7 @@ int buflist_getfile(int n, linenr_T lnum, int options, int forceit)
return FAIL; return FAIL;
} }
// Go to the last known line number for the current buffer. /// Go to the last known line number for the current buffer.
void buflist_getfpos(void) void buflist_getfpos(void)
{ {
pos_T *fpos; pos_T *fpos;
@ -2059,10 +2039,9 @@ void buflist_getfpos(void)
} }
} }
/* /// Find file in buffer list by name (it has to be for the current window).
* Find file in buffer list by name (it has to be for the current window). ///
* Returns NULL if not found. /// @return buffer or NULL if not found
*/
buf_T *buflist_findname_exp(char_u *fname) buf_T *buflist_findname_exp(char_u *fname)
{ {
char_u *ffname; char_u *ffname;
@ -2076,7 +2055,7 @@ buf_T *buflist_findname_exp(char_u *fname)
#else #else
false false
#endif #endif
); ); // NOLINT(whitespace/parens)
if (ffname != NULL) { if (ffname != NULL) {
buf = buflist_findname(ffname); buf = buflist_findname(ffname);
xfree(ffname); xfree(ffname);
@ -2084,12 +2063,11 @@ buf_T *buflist_findname_exp(char_u *fname)
return buf; return buf;
} }
/* /// Find file in buffer list by name (it has to be for the current window).
* Find file in buffer list by name (it has to be for the current window). /// "ffname" must have a full path.
* "ffname" must have a full path. /// Skips dummy buffers.
* Skips dummy buffers. ///
* Returns NULL if not found. /// @return buffer or NULL if not found
*/
buf_T *buflist_findname(char_u *ffname) buf_T *buflist_findname(char_u *ffname)
{ {
FileID file_id; FileID file_id;
@ -2097,11 +2075,10 @@ buf_T *buflist_findname(char_u *ffname)
return buflist_findname_file_id(ffname, &file_id, file_id_valid); return buflist_findname_file_id(ffname, &file_id, file_id_valid);
} }
/* /// Same as buflist_findname(), but pass the FileID structure to avoid
* Same as buflist_findname(), but pass the FileID structure to avoid /// getting it twice for the same file.
* getting it twice for the same file. ///
* Returns NULL if not found. /// @return buffer or NULL if not found
*/
static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid) static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool file_id_valid)
{ {
// Start at the last buffer, expect to find a match sooner. // Start at the last buffer, expect to find a match sooner.
@ -2115,13 +2092,13 @@ static buf_T *buflist_findname_file_id(char_u *ffname, FileID *file_id, bool fil
} }
/// Find file in buffer list by a regexp pattern. /// Find file in buffer list by a regexp pattern.
/// Return fnum of the found buffer.
/// Return < 0 for error.
/// ///
/// @param pattern_end pointer to first char after pattern /// @param pattern_end pointer to first char after pattern
/// @param unlisted find unlisted buffers /// @param unlisted find unlisted buffers
/// @param diffmode find diff-mode buffers only /// @param diffmode find diff-mode buffers only
/// @param curtab_only find buffers in current tab only /// @param curtab_only find buffers in current tab only
///
/// @return fnum of the found buffer or < 0 for error.
int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlisted, bool diffmode, int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlisted, bool diffmode,
bool curtab_only) bool curtab_only)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(1)
@ -2145,7 +2122,6 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis
match = -1; match = -1;
} }
} else { } else {
//
// Try four ways of matching a listed buffer: // Try four ways of matching a listed buffer:
// attempt == 0: without '^' or '$' (at any position) // attempt == 0: without '^' or '$' (at any position)
// attempt == 1: with '^' at start (only at position 0) // attempt == 1: with '^' at start (only at position 0)
@ -2153,7 +2129,6 @@ int buflist_findpat(const char_u *pattern, const char_u *pattern_end, bool unlis
// attempt == 3: with '^' at start and '$' at end (only full match) // attempt == 3: with '^' at start and '$' at end (only full match)
// Repeat this for finding an unlisted buffer if there was no matching // Repeat this for finding an unlisted buffer if there was no matching
// listed buffer. // listed buffer.
//
pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, false); pat = file_pat_to_reg_pat(pattern, pattern_end, NULL, false);
if (pat == NULL) { if (pat == NULL) {
@ -2251,11 +2226,10 @@ static int buf_time_compare(const void *s1, const void *s2)
return buf1->b_last_used > buf2->b_last_used ? -1 : 1; return buf1->b_last_used > buf2->b_last_used ? -1 : 1;
} }
/* /// Find all buffer names that match.
* Find all buffer names that match. /// For command line expansion of ":buf" and ":sbuf".
* For command line expansion of ":buf" and ":sbuf". ///
* Return OK if matches found, FAIL otherwise. /// @return OK if matches found, FAIL otherwise.
*/
int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options) int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
{ {
int count = 0; int count = 0;
@ -2379,7 +2353,7 @@ int ExpandBufnames(char_u *pat, int *num_file, char_u ***file, int options)
/// Check for a match on the file name for buffer "buf" with regprog "prog". /// Check for a match on the file name for buffer "buf" with regprog "prog".
/// ///
/// @param ignore_case When true, ignore case. Use 'fic' otherwise. /// @param ignore_case When true, ignore case. Use 'fic' otherwise.
static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case) static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case)
{ {
// First try the short file name, then the long file name. // First try the short file name, then the long file name.
@ -2392,8 +2366,9 @@ static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, bool ignore_case)
/// Try matching the regexp in "prog" with file name "name". /// Try matching the regexp in "prog" with file name "name".
/// ///
/// @param ignore_case When true, ignore case. Use 'fileignorecase' otherwise. /// @param ignore_case When true, ignore case. Use 'fileignorecase' otherwise.
/// @return "name" when there is a match, NULL when not. ///
/// @return "name" when there is a match, NULL when not.
static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case) static char_u *fname_match(regmatch_T *rmp, char_u *name, bool ignore_case)
{ {
char_u *match = NULL; char_u *match = NULL;
@ -2528,12 +2503,13 @@ static bool wininfo_other_tab_diff(wininfo_T *wip)
return false; return false;
} }
// Find info for the current window in buffer "buf". /// Find info for the current window in buffer "buf".
// If not found, return the info for the most recently used window. /// If not found, return the info for the most recently used window.
// When "need_options" is true skip entries where wi_optset is false. ///
// When "skip_diff_buffer" is true avoid windows with 'diff' set that is in /// @param need_options when true, skip entries where wi_optset is false.
// another tab page. /// @param skip_diff_buffer when true, avoid windows with 'diff' set that is in another tab page.
// Returns NULL when there isn't any info. ///
/// @return NULL when there isn't any info.
static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buffer) static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buffer)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
@ -2570,12 +2546,10 @@ static wininfo_T *find_wininfo(buf_T *buf, bool need_options, bool skip_diff_buf
return wip; return wip;
} }
/* /// Reset the local window options to the values last used in this window.
* Reset the local window options to the values last used in this window. /// If the buffer wasn't used in this window before, use the values from
* If the buffer wasn't used in this window before, use the values from /// the most recently used window. If the values were never set, use the
* the most recently used window. If the values were never set, use the /// global values for the window.
* global values for the window.
*/
void get_winopts(buf_T *buf) void get_winopts(buf_T *buf)
{ {
clear_winopt(&curwin->w_onebuf_opt); clear_winopt(&curwin->w_onebuf_opt);
@ -2610,11 +2584,10 @@ void get_winopts(buf_T *buf)
didset_window_options(curwin); didset_window_options(curwin);
} }
/* /// Find the position (lnum and col) for the buffer 'buf' for the current
* Find the position (lnum and col) for the buffer 'buf' for the current /// window.
* window. ///
* Returns a pointer to no_position if no position is found. /// @return a pointer to no_position if no position is found.
*/
pos_T *buflist_findfpos(buf_T *buf) pos_T *buflist_findfpos(buf_T *buf)
{ {
static pos_T no_position = { 1, 0, 0 }; static pos_T no_position = { 1, 0, 0 };
@ -2623,15 +2596,13 @@ pos_T *buflist_findfpos(buf_T *buf)
return (wip == NULL) ? &no_position : &(wip->wi_fpos); return (wip == NULL) ? &no_position : &(wip->wi_fpos);
} }
/* /// Find the lnum for the buffer 'buf' for the current window.
* Find the lnum for the buffer 'buf' for the current window.
*/
linenr_T buflist_findlnum(buf_T *buf) linenr_T buflist_findlnum(buf_T *buf)
{ {
return buflist_findfpos(buf)->lnum; return buflist_findfpos(buf)->lnum;
} }
// List all known file names (for :files and :buffers command). /// List all known file names (for :files and :buffers command).
void buflist_list(exarg_T *eap) void buflist_list(exarg_T *eap)
{ {
buf_T *buf = firstbuf; buf_T *buf = firstbuf;
@ -2659,8 +2630,7 @@ void buflist_list(exarg_T *eap)
for (; for (;
buf != NULL && !got_int; buf != NULL && !got_int;
buf = buflist_data != NULL buf = buflist_data != NULL
? (++p < buflist_data + buflist.ga_len ? *p : NULL) ? (++p < buflist_data + buflist.ga_len ? *p : NULL) : buf->b_next) {
: buf->b_next) {
const bool is_terminal = buf->terminal; const bool is_terminal = buf->terminal;
const bool job_running = buf->terminal && terminal_running(buf->terminal); const bool job_running = buf->terminal && terminal_running(buf->terminal);
@ -2723,10 +2693,8 @@ void buflist_list(exarg_T *eap)
if (vim_strchr(eap->arg, 't') && buf->b_last_used) { if (vim_strchr(eap->arg, 't') && buf->b_last_used) {
undo_fmt_time(IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used); undo_fmt_time(IObuff + len, (size_t)(IOSIZE - len), buf->b_last_used);
} else { } else {
vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), vim_snprintf((char *)IObuff + len, (size_t)(IOSIZE - len), _("line %" PRId64),
_("line %" PRId64), buf == curbuf ? (int64_t)curwin->w_cursor.lnum : (int64_t)buflist_findlnum(buf));
buf == curbuf ? (int64_t)curwin->w_cursor.lnum
: (int64_t)buflist_findlnum(buf));
} }
msg_outtrans(IObuff); msg_outtrans(IObuff);
@ -2738,12 +2706,11 @@ void buflist_list(exarg_T *eap)
} }
} }
/* /// Get file name and line number for file 'fnum'.
* Get file name and line number for file 'fnum'. /// Used by DoOneCmd() for translating '%' and '#'.
* Used by DoOneCmd() for translating '%' and '#'. /// Used by insert_reg() and cmdline_paste() for '#' register.
* Used by insert_reg() and cmdline_paste() for '#' register. ///
* Return FAIL if not found, OK for success. /// @return FAIL if not found, OK for success.
*/
int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum) int buflist_name_nr(int fnum, char_u **fname, linenr_T *lnum)
{ {
buf_T *buf; buf_T *buf;
@ -2829,10 +2796,8 @@ int setfname(buf_T *buf, char_u *ffname_arg, char_u *sfname_arg, bool message)
return OK; return OK;
} }
/* /// Crude way of changing the name of a buffer. Use with care!
* Crude way of changing the name of a buffer. Use with care! /// The name should be relative to the current directory.
* The name should be relative to the current directory.
*/
void buf_set_name(int fnum, char_u *name) void buf_set_name(int fnum, char_u *name)
{ {
buf_T *buf; buf_T *buf;
@ -2852,15 +2817,10 @@ void buf_set_name(int fnum, char_u *name)
} }
} }
/* /// Take care of what needs to be done when the name of buffer "buf" has changed.
* Take care of what needs to be done when the name of buffer "buf" has
* changed.
*/
void buf_name_changed(buf_T *buf) void buf_name_changed(buf_T *buf)
{ {
/* // If the file name changed, also change the name of the swapfile
* If the file name changed, also change the name of the swapfile
*/
if (buf->b_ml.ml_mfp != NULL) { if (buf->b_ml.ml_mfp != NULL) {
ml_setname(buf); ml_setname(buf);
} }
@ -2874,12 +2834,11 @@ void buf_name_changed(buf_T *buf)
ml_timestamp(buf); // reset timestamp ml_timestamp(buf); // reset timestamp
} }
/* /// Set alternate file name for current window
* set alternate file name for current window ///
* /// Used by do_one_cmd(), do_write() and do_ecmd().
* Used by do_one_cmd(), do_write() and do_ecmd(). ///
* Return the buffer. /// @return the buffer.
*/
buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum) buf_T *setaltfname(char_u *ffname, char_u *sfname, linenr_T lnum)
{ {
buf_T *buf; buf_T *buf;
@ -2910,12 +2869,10 @@ char_u *getaltfname(bool errmsg)
return fname; return fname;
} }
/* /// Add a file name to the buflist and return its number.
* Add a file name to the buflist and return its number. /// Uses same flags as buflist_new(), except BLN_DUMMY.
* Uses same flags as buflist_new(), except BLN_DUMMY. ///
* /// Used by qf_init(), main() and doarglist()
* used by qf_init(), main() and doarglist()
*/
int buflist_add(char_u *fname, int flags) int buflist_add(char_u *fname, int flags)
{ {
buf_T *buf; buf_T *buf;
@ -2928,9 +2885,7 @@ int buflist_add(char_u *fname, int flags)
} }
#if defined(BACKSLASH_IN_FILENAME) #if defined(BACKSLASH_IN_FILENAME)
/* /// Adjust slashes in file names. Called after 'shellslash' was set.
* Adjust slashes in file names. Called after 'shellslash' was set.
*/
void buflist_slash_adjust(void) void buflist_slash_adjust(void)
{ {
FOR_ALL_BUFFERS(bp) { FOR_ALL_BUFFERS(bp) {
@ -2945,10 +2900,8 @@ void buflist_slash_adjust(void)
#endif #endif
/* /// Set alternate cursor position for the current buffer and window "win".
* Set alternate cursor position for the current buffer and window "win". /// Also save the local window option values.
* Also save the local window option values.
*/
void buflist_altfpos(win_T *win) void buflist_altfpos(win_T *win)
{ {
buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, true); buflist_setfpos(curbuf, win, win->w_cursor.lnum, win->w_cursor.col, true);
@ -3011,8 +2964,8 @@ static bool otherfile_buf(buf_T *buf, char_u *ffname, FileID *file_id_p, bool fi
return true; return true;
} }
// Set file_id for a buffer. /// Set file_id for a buffer.
// Must always be called when b_fname is changed! /// Must always be called when b_fname is changed!
void buf_set_file_id(buf_T *buf) void buf_set_file_id(buf_T *buf)
{ {
FileID file_id; FileID file_id;
@ -3152,7 +3105,7 @@ static char_u *lasttitle = NULL;
static char_u *lasticon = NULL; static char_u *lasticon = NULL;
// Put the title name in the title bar and icon of the window. /// Put the title name in the title bar and icon of the window.
void maketitle(void) void maketitle(void)
{ {
char_u *title_str = NULL; char_u *title_str = NULL;
@ -3350,8 +3303,8 @@ void maketitle(void)
/// ///
/// @param str desired title string /// @param str desired title string
/// @param[in,out] last current title string /// @param[in,out] last current title string
// ///
/// @return true if resettitle() is to be called. /// @return true if resettitle() is to be called.
static bool value_change(char_u *str, char_u **last) static bool value_change(char_u *str, char_u **last)
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_WARN_UNUSED_RESULT
{ {
@ -3408,18 +3361,18 @@ typedef enum {
/// If maxwidth is not zero, the string will be filled at any middle marker /// If maxwidth is not zero, the string will be filled at any middle marker
/// or truncated if too long, fillchar is used for all whitespace. /// or truncated if too long, fillchar is used for all whitespace.
/// ///
/// @param wp The window to build a statusline for /// @param wp The window to build a statusline for
/// @param out The output buffer to write the statusline to /// @param out The output buffer to write the statusline to
/// Note: This should not be NameBuff /// Note: This should not be NameBuff
/// @param outlen The length of the output buffer /// @param outlen The length of the output buffer
/// @param fmt The statusline format string /// @param fmt The statusline format string
/// @param use_sandbox Use a sandboxed environment when evaluating fmt /// @param use_sandbox Use a sandboxed environment when evaluating fmt
/// @param fillchar Character to use when filling empty space in the statusline /// @param fillchar Character to use when filling empty space in the statusline
/// @param maxwidth The maximum width to make the statusline /// @param maxwidth The maximum width to make the statusline
/// @param hltab HL attributes (can be NULL) /// @param hltab HL attributes (can be NULL)
/// @param tabtab Tab clicks definition (can be NULL). /// @param tabtab Tab clicks definition (can be NULL).
/// ///
/// @return The final width of the statusline /// @return The final width of the statusline
int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use_sandbox, int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use_sandbox,
int fillchar, int maxwidth, stl_hlrec_t **hltab, StlClickRecord **tabtab) int fillchar, int maxwidth, stl_hlrec_t **hltab, StlClickRecord **tabtab)
{ {
@ -3681,8 +3634,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
} }
} }
// If the group is shorter than the minimum width, add padding characters. // If the group is shorter than the minimum width, add padding characters.
} else if ( } else if (abs(stl_items[stl_groupitems[groupdepth]].minwid) > group_len) {
abs(stl_items[stl_groupitems[groupdepth]].minwid) > group_len) {
long min_group_width = stl_items[stl_groupitems[groupdepth]].minwid; long min_group_width = stl_items[stl_groupitems[groupdepth]].minwid;
// If the group is left-aligned, add characters to the right. // If the group is left-aligned, add characters to the right.
if (min_group_width < 0) { if (min_group_width < 0) {
@ -4508,7 +4460,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
char_u *start = stl_items[stl_separator_locations[i]].start; char_u *start = stl_items[stl_separator_locations[i]].start;
char_u *seploc = start + dislocation; char_u *seploc = start + dislocation;
STRMOVE(seploc, start); STRMOVE(seploc, start);
for (char_u *s = start; s < seploc; ) { for (char_u *s = start; s < seploc;) {
MB_CHAR2BYTES(fillchar, s); MB_CHAR2BYTES(fillchar, s);
} }
@ -4582,12 +4534,10 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
} }
return width; return width;
} } // NOLINT(readability/fn_size)
/* /// Get relative cursor position in window into "buf[buflen]", in the form 99%,
* Get relative cursor position in window into "buf[buflen]", in the form 99%, /// using "Top", "Bot" or "All" when appropriate.
* using "Top", "Bot" or "All" when appropriate.
*/
void get_rel_pos(win_T *wp, char_u *buf, int buflen) void get_rel_pos(win_T *wp, char_u *buf, int buflen)
{ {
// Need at least 3 chars for writing. // Need at least 3 chars for writing.
@ -4624,7 +4574,7 @@ void get_rel_pos(win_T *wp, char_u *buf, int buflen)
/// @param buflen length of the string buffer /// @param buflen length of the string buffer
/// @param add_file if true, add "file" before the arg number /// @param add_file if true, add "file" before the arg number
/// ///
/// @return true if it was appended. /// @return true if it was appended.
static bool append_arg_number(win_T *wp, char_u *buf, int buflen, bool add_file) static bool append_arg_number(win_T *wp, char_u *buf, int buflen, bool add_file)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
@ -4653,12 +4603,12 @@ static bool append_arg_number(win_T *wp, char_u *buf, int buflen, bool add_file)
return true; return true;
} }
// Make "*ffname" a full file name, set "*sfname" to "*ffname" if not NULL. /// Make "*ffname" a full file name, set "*sfname" to "*ffname" if not NULL.
// "*ffname" becomes a pointer to allocated memory (or NULL). /// "*ffname" becomes a pointer to allocated memory (or NULL).
// When resolving a link both "*sfname" and "*ffname" will point to the same /// When resolving a link both "*sfname" and "*ffname" will point to the same
// allocated memory. /// allocated memory.
// The "*ffname" and "*sfname" pointer values on call will not be freed. /// The "*ffname" and "*sfname" pointer values on call will not be freed.
// Note that the resulting "*ffname" pointer should be considered not allocated. /// Note that the resulting "*ffname" pointer should be considered not allocated.
void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname) void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
{ {
if (*ffname == NULL) { // no file name given, nothing to do if (*ffname == NULL) { // no file name given, nothing to do
@ -4682,9 +4632,7 @@ void fname_expand(buf_T *buf, char_u **ffname, char_u **sfname)
#endif #endif
} }
/* /// Get the file name for an argument list entry.
* Get the file name for an argument list entry.
*/
char_u *alist_name(aentry_T *aep) char_u *alist_name(aentry_T *aep)
{ {
buf_T *bp; buf_T *bp;
@ -4726,8 +4674,7 @@ void do_arg_all(int count, int forceit, int keep_tabs)
assert(firstwin != NULL); // satisfy coverity assert(firstwin != NULL); // satisfy coverity
if (ARGCOUNT <= 0) { if (ARGCOUNT <= 0) {
/* Don't give an error message. We don't want it when the ":all" // Don't give an error message. We don't want it when the ":all" command is in the .vimrc.
* command is in the .vimrc. */
return; return;
} }
setpcmark(); setpcmark();
@ -4735,9 +4682,9 @@ void do_arg_all(int count, int forceit, int keep_tabs)
opened_len = ARGCOUNT; opened_len = ARGCOUNT;
opened = xcalloc((size_t)opened_len, 1); opened = xcalloc((size_t)opened_len, 1);
/* Autocommands may do anything to the argument list. Make sure it's not // Autocommands may do anything to the argument list. Make sure it's not
* freed while we are working here by "locking" it. We still have to // freed while we are working here by "locking" it. We still have to
* watch out for its size to be changed. */ // watch out for its size to be changed.
alist = curwin->w_alist; alist = curwin->w_alist;
alist->al_refcount++; alist->al_refcount++;
@ -4745,13 +4692,11 @@ void do_arg_all(int count, int forceit, int keep_tabs)
old_curtab = curtab; old_curtab = curtab;
/* // Try closing all windows that are not in the argument list.
* Try closing all windows that are not in the argument list. // Also close windows that are not full width;
* Also close windows that are not full width; // When 'hidden' or "forceit" set the buffer becomes hidden.
* When 'hidden' or "forceit" set the buffer becomes hidden. // Windows that have a changed buffer and can't be hidden won't be closed.
* Windows that have a changed buffer and can't be hidden won't be closed. // When the ":tab" modifier was used do this for all tab pages.
* When the ":tab" modifier was used do this for all tab pages.
*/
if (had_tab > 0) { if (had_tab > 0) {
goto_tabpage_tp(first_tabpage, true, true); goto_tabpage_tp(first_tabpage, true, true);
} }
@ -4796,8 +4741,7 @@ void do_arg_all(int count, int forceit, int keep_tabs)
} }
if (wp->w_alist != alist) { if (wp->w_alist != alist) {
/* Use the current argument list for all windows // Use the current argument list for all windows containing a file from it.
* containing a file from it. */
alist_unlink(wp->w_alist); alist_unlink(wp->w_alist);
wp->w_alist = alist; wp->w_alist = alist;
wp->w_alist->al_refcount++; wp->w_alist->al_refcount++;
@ -4811,8 +4755,7 @@ void do_arg_all(int count, int forceit, int keep_tabs)
if (i == opened_len && !keep_tabs) { // close this window if (i == opened_len && !keep_tabs) { // close this window
if (buf_hide(buf) || forceit || buf->b_nwindows > 1 if (buf_hide(buf) || forceit || buf->b_nwindows > 1
|| !bufIsChanged(buf)) { || !bufIsChanged(buf)) {
/* If the buffer was changed, and we would like to hide it, // If the buffer was changed, and we would like to hide it, try autowriting.
* try autowriting. */
if (!buf_hide(buf) && buf->b_nwindows <= 1 && bufIsChanged(buf)) { if (!buf_hide(buf) && buf->b_nwindows <= 1 && bufIsChanged(buf)) {
bufref_T bufref; bufref_T bufref;
set_bufref(&bufref, buf); set_bufref(&bufref, buf);
@ -4851,10 +4794,8 @@ void do_arg_all(int count, int forceit, int keep_tabs)
goto_tabpage_tp(tpnext, true, true); goto_tabpage_tp(tpnext, true, true);
} }
/* // Open a window for files in the argument list that don't have one.
* Open a window for files in the argument list that don't have one. // ARGCOUNT may change while doing this, because of autocommands.
* ARGCOUNT may change while doing this, because of autocommands.
*/
if (count > opened_len || count <= 0) { if (count > opened_len || count <= 0) {
count = opened_len; count = opened_len;
} }
@ -4909,9 +4850,7 @@ void do_arg_all(int count, int forceit, int keep_tabs)
autocmd_no_leave--; autocmd_no_leave--;
} }
/* // edit file "i"
* edit file "i"
*/
curwin->w_arg_idx = i; curwin->w_arg_idx = i;
if (i == 0) { if (i == 0) {
new_curwin = curwin; new_curwin = curwin;
@ -4963,15 +4902,13 @@ void do_arg_all(int count, int forceit, int keep_tabs)
xfree(opened); xfree(opened);
} }
/// @return true if "buf" is a prompt buffer. /// @return true if "buf" is a prompt buffer.
bool bt_prompt(buf_T *buf) bool bt_prompt(buf_T *buf)
{ {
return buf != NULL && buf->b_p_bt[0] == 'p'; return buf != NULL && buf->b_p_bt[0] == 'p';
} }
/* /// Open a window for a number of buffers.
* Open a window for a number of buffers.
*/
void ex_buffer_all(exarg_T *eap) void ex_buffer_all(exarg_T *eap)
{ {
buf_T *buf; buf_T *buf;
@ -4999,10 +4936,8 @@ void ex_buffer_all(exarg_T *eap)
setpcmark(); setpcmark();
/* // Close superfluous windows (two windows for the same buffer).
* Close superfluous windows (two windows for the same buffer). // Also close windows that are not full-width.
* Also close windows that are not full-width.
*/
if (had_tab > 0) { if (had_tab > 0) {
goto_tabpage_tp(first_tabpage, true, true); goto_tabpage_tp(first_tabpage, true, true);
} }
@ -5036,7 +4971,6 @@ void ex_buffer_all(exarg_T *eap)
goto_tabpage_tp(tpnext, true, true); goto_tabpage_tp(tpnext, true, true);
} }
//
// Go through the buffer list. When a buffer doesn't have a window yet, // Go through the buffer list. When a buffer doesn't have a window yet,
// open one. Otherwise move the window to the right position. // open one. Otherwise move the window to the right position.
// Watch out for autocommands that delete buffers or windows! // Watch out for autocommands that delete buffers or windows!
@ -5132,9 +5066,7 @@ void ex_buffer_all(exarg_T *eap)
win_enter(firstwin, false); // back to first window win_enter(firstwin, false); // back to first window
autocmd_no_leave--; autocmd_no_leave--;
/* // Close superfluous windows.
* Close superfluous windows.
*/
for (wp = lastwin; open_wins > count;) { for (wp = lastwin; open_wins > count;) {
r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer)
|| autowrite(wp->w_buffer, false) == OK); || autowrite(wp->w_buffer, false) == OK);
@ -5155,15 +5087,13 @@ void ex_buffer_all(exarg_T *eap)
} }
/* /// do_modelines() - process mode lines for the current file
* do_modelines() - process mode lines for the current file ///
* /// @param flags
* "flags" can be: /// OPT_WINONLY only set options local to window
* OPT_WINONLY only set options local to window /// OPT_NOWIN don't set options local to window
* OPT_NOWIN don't set options local to window ///
* /// Returns immediately if the "ml" option isn't set.
* Returns immediately if the "ml" option isn't set.
*/
void do_modelines(int flags) void do_modelines(int flags)
{ {
linenr_T lnum; linenr_T lnum;
@ -5269,10 +5199,8 @@ static int chk_modeline(linenr_T lnum, int flags)
break; break;
} }
/* // Find end of set command: ':' or end of line.
* Find end of set command: ':' or end of line. // Skip over "\:", replacing it with ":".
* Skip over "\:", replacing it with ":".
*/
for (e = s; *e != ':' && *e != NUL; e++) { for (e = s; *e != ':' && *e != NUL; e++) {
if (e[0] == '\\' && e[1] == ':') { if (e[0] == '\\' && e[1] == ':') {
STRMOVE(e, e + 1); STRMOVE(e, e + 1);
@ -5282,13 +5210,11 @@ static int chk_modeline(linenr_T lnum, int flags)
end = true; end = true;
} }
/* // If there is a "set" command, require a terminating ':' and
* If there is a "set" command, require a terminating ':' and // ignore the stuff after the ':'.
* ignore the stuff after the ':'. // "vi:set opt opt opt: foo" -- foo not interpreted
* "vi:set opt opt opt: foo" -- foo not interpreted // "vi:opt opt opt: foo" -- foo interpreted
* "vi:opt opt opt: foo" -- foo interpreted // Accept "se" for compatibility with Elvis.
* Accept "se" for compatibility with Elvis.
*/
if (STRNCMP(s, "set ", (size_t)4) == 0 if (STRNCMP(s, "set ", (size_t)4) == 0
|| STRNCMP(s, "se ", (size_t)3) == 0) { || STRNCMP(s, "se ", (size_t)3) == 0) {
if (*e != ':') { // no terminating ':'? if (*e != ':') { // no terminating ':'?
@ -5327,36 +5253,36 @@ static int chk_modeline(linenr_T lnum, int flags)
return retval; return retval;
} }
// Return true if "buf" is a help buffer. /// @return true if "buf" is a help buffer.
bool bt_help(const buf_T *const buf) bool bt_help(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return buf != NULL && buf->b_help; return buf != NULL && buf->b_help;
} }
// Return true if "buf" is a normal buffer, 'buftype' is empty. /// @return true if "buf" is a normal buffer, 'buftype' is empty.
bool bt_normal(const buf_T *const buf) bool bt_normal(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return buf != NULL && buf->b_p_bt[0] == NUL; return buf != NULL && buf->b_p_bt[0] == NUL;
} }
// Return true if "buf" is the quickfix buffer. /// @return true if "buf" is the quickfix buffer.
bool bt_quickfix(const buf_T *const buf) bool bt_quickfix(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return buf != NULL && buf->b_p_bt[0] == 'q'; return buf != NULL && buf->b_p_bt[0] == 'q';
} }
// Return true if "buf" is a terminal buffer. /// @return true if "buf" is a terminal buffer.
bool bt_terminal(const buf_T *const buf) bool bt_terminal(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
return buf != NULL && buf->b_p_bt[0] == 't'; return buf != NULL && buf->b_p_bt[0] == 't';
} }
// Return true if "buf" is a "nofile", "acwrite", "terminal" or "prompt" /// @return true if "buf" is a "nofile", "acwrite", "terminal" or "prompt" /
// buffer. This means the buffer name is not a file name. /// buffer. This means the buffer name is not a file name.
bool bt_nofile(const buf_T *const buf) bool bt_nofile(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
@ -5366,8 +5292,8 @@ bool bt_nofile(const buf_T *const buf)
|| buf->b_p_bt[0] == 'p'); || buf->b_p_bt[0] == 'p');
} }
// Return true if "buf" is a "nowrite", "nofile", "terminal" or "prompt" /// @return true if "buf" is a "nowrite", "nofile", "terminal" or "prompt"
// buffer. /// buffer.
bool bt_dontwrite(const buf_T *const buf) bool bt_dontwrite(const buf_T *const buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
@ -5386,8 +5312,8 @@ bool bt_dontwrite_msg(const buf_T *const buf)
return false; return false;
} }
// Return true if the buffer should be hidden, according to 'hidden', ":hide" /// @return true if the buffer should be hidden, according to 'hidden', ":hide"
// and 'bufhidden'. /// and 'bufhidden'.
bool buf_hide(const buf_T *const buf) bool buf_hide(const buf_T *const buf)
{ {
// 'bufhidden' overrules 'hidden' and ":hide", check it first // 'bufhidden' overrules 'hidden' and ":hide", check it first
@ -5402,10 +5328,8 @@ bool buf_hide(const buf_T *const buf)
return p_hid || cmdmod.hide; return p_hid || cmdmod.hide;
} }
/* /// @return special buffer name or
* Return special buffer name. /// NULL when the buffer has a normal file name.
* Returns NULL when the buffer has a normal file name.
*/
char_u *buf_spname(buf_T *buf) char_u *buf_spname(buf_T *buf)
{ {
if (bt_quickfix(buf)) { if (bt_quickfix(buf)) {
@ -5446,7 +5370,7 @@ char_u *buf_spname(buf_T *buf)
/// @param[out] wp stores the found window /// @param[out] wp stores the found window
/// @param[out] tp stores the found tabpage /// @param[out] tp stores the found tabpage
/// ///
/// @return true if a window was found for the buffer. /// @return true if a window was found for the buffer.
bool find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp) bool find_win_for_buf(buf_T *buf, win_T **wp, tabpage_T **tp)
{ {
*wp = NULL; *wp = NULL;
@ -5608,7 +5532,7 @@ int buf_signcols(buf_T *buf, int maximum)
return buf->b_signcols.size; return buf->b_signcols.size;
} }
// Get "buf->b_fname", use "[No Name]" if it is NULL. /// Get "buf->b_fname", use "[No Name]" if it is NULL.
char_u *buf_get_fname(const buf_T *buf) char_u *buf_get_fname(const buf_T *buf)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
@ -5618,9 +5542,7 @@ char_u *buf_get_fname(const buf_T *buf)
return buf->b_fname; return buf->b_fname;
} }
/* /// Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed.
* Set 'buflisted' for curbuf to "on" and trigger autocommands if it changed.
*/
void set_buflisted(int on) void set_buflisted(int on)
{ {
if (on != curbuf->b_p_bl) { if (on != curbuf->b_p_bl) {
@ -5638,7 +5560,7 @@ void set_buflisted(int on)
/// ///
/// @param buf buffer to check /// @param buf buffer to check
/// ///
/// @return true if the buffer's contents have changed /// @return true if the buffer's contents have changed
bool buf_contents_changed(buf_T *buf) bool buf_contents_changed(buf_T *buf)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
@ -5719,4 +5641,3 @@ 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);
} }