refactor: follow style guide

This commit is contained in:
dundargoc
2023-12-28 13:42:24 +01:00
committed by dundargoc
parent d634cd5b0b
commit c89292fcb7
90 changed files with 953 additions and 1121 deletions

View File

@@ -128,7 +128,7 @@ int get_highest_fnum(void)
/// @param read_stdin read file from stdin, otherwise fifo
/// @param eap for forced 'ff' and 'fenc' or NULL
/// @param flags extra flags for readfile()
static int read_buffer(int read_stdin, exarg_T *eap, int flags)
static int read_buffer(bool read_stdin, exarg_T *eap, int flags)
{
int retval = OK;
bool silent = shortmess(SHM_FILEINFO);
@@ -269,9 +269,7 @@ int open_buffer(bool read_stdin, exarg_T *eap, int flags_arg)
if (curbuf->b_ffname != NULL) {
#ifdef UNIX
int save_bin = curbuf->b_p_bin;
int perm;
perm = os_getperm(curbuf->b_ffname);
int perm = os_getperm(curbuf->b_ffname);
if (perm >= 0 && (0 || S_ISFIFO(perm)
|| S_ISSOCK(perm)
# ifdef OPEN_CHR_FILES
@@ -327,7 +325,7 @@ int open_buffer(bool read_stdin, exarg_T *eap, int flags_arg)
// if first time loading this buffer, init b_chartab[]
if (curbuf->b_flags & BF_NEVERLOADED) {
(void)buf_init_chartab(curbuf, false);
buf_init_chartab(curbuf, false);
parse_cino(curbuf);
}
@@ -937,8 +935,8 @@ void goto_buffer(exarg_T *eap, int start, int dir, int count)
if (swap_exists_action == SEA_NONE) {
swap_exists_action = SEA_DIALOG;
}
(void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO,
start, dir, count, eap->forceit);
do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO,
start, dir, count, eap->forceit);
if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') {
cleanup_T cs;
@@ -1046,7 +1044,7 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b
int bnr; // buffer number
if (addr_count == 0) {
(void)do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit);
do_buffer(command, DOBUF_CURRENT, FORWARD, 0, forceit);
} else {
if (addr_count == 2) {
if (*arg) { // both range and argument is not allowed
@@ -1125,7 +1123,7 @@ char *do_bufdel(int command, char *arg, int addr_count, int start_bnr, int end_b
/// Make the current buffer empty.
/// 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(bool close_others, int forceit, int action)
{
buf_T *buf = curbuf;
@@ -1197,8 +1195,8 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
{
buf_T *buf;
buf_T *bp;
int unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
|| action == DOBUF_WIPE);
bool unload = (action == DOBUF_UNLOAD || action == DOBUF_DEL
|| action == DOBUF_WIPE);
switch (start) {
case DOBUF_FIRST:
@@ -1374,9 +1372,7 @@ int do_buffer(int action, int start, int dir, int count, int forceit)
if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) {
buf = au_new_curbuf.br_buf;
} else if (curwin->w_jumplistlen > 0) {
int jumpidx;
jumpidx = curwin->w_jumplistidx - 1;
int jumpidx = curwin->w_jumplistidx - 1;
if (jumpidx < 0) {
jumpidx = curwin->w_jumplistlen - 1;
}
@@ -1665,7 +1661,7 @@ void enter_buffer(buf_T *buf)
need_fileinfo = true; // display file info after redraw
}
// check if file changed
(void)buf_check_timestamp(curbuf);
buf_check_timestamp(curbuf);
curwin->w_topline = 1;
curwin->w_topfill = 0;
@@ -1690,12 +1686,12 @@ void enter_buffer(buf_T *buf)
do_autochdir();
if (curbuf->b_kmap_state & KEYMAP_INIT) {
(void)keymap_init();
keymap_init();
}
// May need to set the spell language. Can only do this after the buffer
// has been properly setup.
if (!curbuf->b_help && curwin->w_p_spell && *curwin->w_s->b_p_spl != NUL) {
(void)parse_spelllang(curwin);
parse_spelllang(curwin);
}
curbuf->b_last_used = time(NULL);
@@ -1961,7 +1957,7 @@ bool curbuf_reusable(void)
/// Free the memory for the options of a buffer.
/// If "free_p_ff" is true also free 'fileformat', 'buftype' and
/// 'fileencoding'.
void free_buf_options(buf_T *buf, int free_p_ff)
void free_buf_options(buf_T *buf, bool free_p_ff)
{
if (free_p_ff) {
clear_string_option(&buf->b_p_fenc);
@@ -2224,7 +2220,7 @@ int buflist_findpat(const char *pattern, const char *pattern_end, bool unlisted,
return -1;
}
char *patend = pat + strlen(pat) - 1;
int toggledollar = (patend > pat && *patend == '$');
bool toggledollar = (patend > pat && *patend == '$');
// First try finding a listed buffer. If not found and "unlisted"
// is true, try finding an unlisted buffer.
@@ -2755,8 +2751,6 @@ linenr_T buflist_findlnum(buf_T *buf)
void buflist_list(exarg_T *eap)
{
buf_T *buf = firstbuf;
int len;
int i;
garray_T buflist;
buf_T **buflist_data = NULL;
@@ -2821,21 +2815,21 @@ void buflist_list(exarg_T *eap)
}
msg_putchar('\n');
len = vim_snprintf(IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
buf->b_fnum,
buf->b_p_bl ? ' ' : 'u',
buf == curbuf ? '%' : (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
buf->b_ml.ml_mfp == NULL ? ' ' : (buf->b_nwindows == 0 ? 'h' : 'a'),
ro_char,
changed_char,
NameBuff);
int len = vim_snprintf(IObuff, IOSIZE - 20, "%3d%c%c%c%c%c \"%s\"",
buf->b_fnum,
buf->b_p_bl ? ' ' : 'u',
buf == curbuf ? '%' : (curwin->w_alt_fnum == buf->b_fnum ? '#' : ' '),
buf->b_ml.ml_mfp == NULL ? ' ' : (buf->b_nwindows == 0 ? 'h' : 'a'),
ro_char,
changed_char,
NameBuff);
if (len > IOSIZE - 20) {
len = IOSIZE - 20;
}
// put "line 999" in column 40 or after the file name
i = 40 - vim_strsize(IObuff);
int i = 40 - vim_strsize(IObuff);
do {
IObuff[len++] = ' ';
} while (--i > 0 && len < IOSIZE - 18);
@@ -3134,7 +3128,7 @@ static bool buf_same_file_id(buf_T *buf, FileID *file_id)
/// Print info about the current buffer.
///
/// @param fullname when non-zero print full path
void fileinfo(int fullname, int shorthelp, int dont_truncate)
void fileinfo(int fullname, int shorthelp, bool dont_truncate)
{
char *name;
int n;
@@ -3208,7 +3202,7 @@ void fileinfo(int fullname, int shorthelp, int dont_truncate)
(int)curwin->w_cursor.col + 1, (int)curwin->w_virtcol + 1);
}
(void)append_arg_number(curwin, buffer, IOSIZE);
append_arg_number(curwin, buffer, IOSIZE);
if (dont_truncate) {
// Temporarily set msg_scroll to avoid the message being truncated.
@@ -3251,7 +3245,6 @@ void maketitle(void)
char *title_str = NULL;
char *icon_str = NULL;
int maxlen = 0;
int len;
char buf[IOSIZE];
if (!redrawing()) {
@@ -3374,7 +3367,7 @@ void maketitle(void)
#undef SPACE_FOR_ARGNR
}
}
int mustset = value_change(title_str, &lasttitle);
bool mustset = value_change(title_str, &lasttitle);
if (p_icon) {
icon_str = buf;
@@ -3394,7 +3387,7 @@ void maketitle(void)
}
*icon_str = NUL;
// Truncate name at 100 bytes.
len = (int)strlen(buf_p);
int len = (int)strlen(buf_p);
if (len > 100) {
len -= 100;
len += utf_cp_tail_off(buf_p, buf_p + len) + 1;
@@ -3556,16 +3549,12 @@ bool bt_prompt(buf_T *buf)
/// Open a window for a number of buffers.
void ex_buffer_all(exarg_T *eap)
{
buf_T *buf;
win_T *wp, *wpnext;
int split_ret = OK;
bool p_ea_save;
int open_wins = 0;
int r;
linenr_T count; // Maximum number of windows to open.
int all; // When true also load inactive buffers.
int had_tab = cmdmod.cmod_tab;
tabpage_T *tpnext;
if (eap->addr_count == 0) { // make as many windows as possible
count = 9999;
@@ -3590,7 +3579,7 @@ void ex_buffer_all(exarg_T *eap)
goto_tabpage_tp(first_tabpage, true, true);
}
while (true) {
tpnext = curtab->tp_next;
tabpage_T *tpnext = curtab->tp_next;
// Try to close floating windows first
for (wp = lastwin->w_floating ? lastwin : firstwin; wp != NULL; wp = wpnext) {
wpnext = wp->w_floating
@@ -3635,7 +3624,7 @@ void ex_buffer_all(exarg_T *eap)
// lastwin may be aucmd_win
win_enter(lastwin_nofloating(), false);
autocmd_no_leave++;
for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) {
for (buf_T *buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) {
// Check if this buffer needs a window
if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) {
continue;
@@ -3665,7 +3654,7 @@ void ex_buffer_all(exarg_T *eap)
bufref_T bufref;
set_bufref(&bufref, buf);
// Split the window and put the buffer in it.
p_ea_save = p_ea;
bool p_ea_save = p_ea;
p_ea = true; // use space from all windows
split_ret = win_split(0, WSP_ROOM | WSP_BELOW);
open_wins++;
@@ -3706,7 +3695,7 @@ void ex_buffer_all(exarg_T *eap)
os_breakcheck();
if (got_int) {
(void)vgetc(); // only break the file loading, not the rest
vgetc(); // only break the file loading, not the rest
break;
}
// Autocommands deleted the buffer or aborted script processing!!!
@@ -3724,8 +3713,8 @@ void ex_buffer_all(exarg_T *eap)
// Close superfluous windows.
for (wp = lastwin; open_wins > count;) {
r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer)
|| autowrite(wp->w_buffer, false) == OK) && !is_aucmd_win(wp);
bool r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer)
|| autowrite(wp->w_buffer, false) == OK) && !is_aucmd_win(wp);
if (!win_valid(wp)) {
// BufWrite Autocommands made the window invalid, start over
wp = lastwin;
@@ -3798,8 +3787,8 @@ static int chk_modeline(linenr_T lnum, int flags)
int prev = -1;
for (s = ml_get(lnum); *s != NUL; s++) {
if (prev == -1 || ascii_isspace(prev)) {
if ((prev != -1 && strncmp(s, "ex:", (size_t)3) == 0)
|| strncmp(s, "vi:", (size_t)3) == 0) {
if ((prev != -1 && strncmp(s, "ex:", 3) == 0)
|| strncmp(s, "vi:", 3) == 0) {
break;
}
// Accept both "vim" and "Vim".
@@ -3864,8 +3853,8 @@ static int chk_modeline(linenr_T lnum, int flags)
// "vi:set opt opt opt: foo" -- foo not interpreted
// "vi:opt opt opt: foo" -- foo interpreted
// Accept "se" for compatibility with Elvis.
if (strncmp(s, "set ", (size_t)4) == 0
|| strncmp(s, "se ", (size_t)3) == 0) {
if (strncmp(s, "set ", 4) == 0
|| strncmp(s, "se ", 3) == 0) {
if (*e != ':') { // no terminating ':'?
break;
}
@@ -4140,7 +4129,7 @@ int buf_open_scratch(handle_T bufnr, char *bufname)
return FAIL;
}
apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, false, curbuf);
(void)setfname(curbuf, bufname, NULL, true);
setfname(curbuf, bufname, NULL, true);
apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, false, curbuf);
set_option_value_give_err(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL);
set_option_value_give_err(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL);