0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 9.0.1183: code is indented more than necessary

Problem:    Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
            closes #11805)
This commit is contained in:
Yegappan Lakshmanan
2023-01-12 12:33:30 +00:00
committed by Bram Moolenaar
parent 043d7b2c84
commit 0233bdfa2b
9 changed files with 401 additions and 381 deletions

View File

@@ -221,12 +221,15 @@ set_context_in_cscope_cmd(
expand_what = (cmdidx == CMD_scscope) expand_what = (cmdidx == CMD_scscope)
? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD; ? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD;
if (*arg == NUL)
return;
// (part of) subcommand already typed // (part of) subcommand already typed
if (*arg != NUL)
{
p = skiptowhite(arg); p = skiptowhite(arg);
if (*p != NUL) // past first word if (*p == NUL)
{ return;
// past first word
xp->xp_pattern = skipwhite(p); xp->xp_pattern = skipwhite(p);
if (*skiptowhite(xp->xp_pattern) != NUL) if (*skiptowhite(xp->xp_pattern) != NUL)
xp->xp_context = EXPAND_NOTHING; xp->xp_context = EXPAND_NOTHING;
@@ -239,8 +242,6 @@ set_context_in_cscope_cmd(
else else
xp->xp_context = EXPAND_NOTHING; xp->xp_context = EXPAND_NOTHING;
} }
}
}
/* /*
* Find the command, print help if invalid, and then call the corresponding * Find the command, print help if invalid, and then call the corresponding

View File

@@ -505,8 +505,10 @@ luaV_toudata(lua_State *L, int ud, const char *tname)
{ {
void *p = lua_touserdata(L, ud); void *p = lua_touserdata(L, ud);
if (p != NULL) // value is userdata? if (p == NULL)
{ return NULL;
// value is userdata
if (lua_getmetatable(L, ud)) // does it have a metatable? if (lua_getmetatable(L, ud)) // does it have a metatable?
{ {
luaV_getfield(L, tname); // get metatable luaV_getfield(L, tname); // get metatable
@@ -516,7 +518,7 @@ luaV_toudata(lua_State *L, int ud, const char *tname)
return p; return p;
} }
} }
}
return NULL; return NULL;
} }
@@ -1090,9 +1092,11 @@ luaV_dict_index(lua_State *L)
dictitem_T *di = dict_find(d, key, -1); dictitem_T *di = dict_find(d, key, -1);
if (di == NULL) if (di == NULL)
lua_pushnil(L);
else
{ {
lua_pushnil(L);
return 1;
}
luaV_pushtypval(L, &di->di_tv); luaV_pushtypval(L, &di->di_tv);
if (di->di_tv.v_type == VAR_FUNC) // funcref? if (di->di_tv.v_type == VAR_FUNC) // funcref?
{ {
@@ -1100,7 +1104,7 @@ luaV_dict_index(lua_State *L)
f->self = d; // keep "self" reference f->self = d; // keep "self" reference
d->dv_refcount++; d->dv_refcount++;
} }
}
return 1; return 1;
} }
@@ -1235,8 +1239,10 @@ luaV_blob_newindex(lua_State *L)
blob_T *b = luaV_unbox(L, luaV_Blob, 1); blob_T *b = luaV_unbox(L, luaV_Blob, 1);
if (b->bv_lock) if (b->bv_lock)
luaL_error(L, "blob is locked"); luaL_error(L, "blob is locked");
if (lua_isnumber(L, 2))
{ if (!lua_isnumber(L, 2))
return 0;
long len = blob_len(b); long len = blob_len(b);
int idx = luaL_checkinteger(L, 2); int idx = luaL_checkinteger(L, 2);
int val = luaL_checkinteger(L, 3); int val = luaL_checkinteger(L, 3);
@@ -1248,7 +1254,7 @@ luaV_blob_newindex(lua_State *L)
} }
else else
luaL_error(L, "index out of range"); luaL_error(L, "index out of range");
}
return 0; return 0;
} }
@@ -1943,14 +1949,19 @@ luaV_list(lua_State *L)
if (initarg && lua_type(L, 1) != LUA_TTABLE) if (initarg && lua_type(L, 1) != LUA_TTABLE)
luaL_error(L, "table expected, got %s", luaL_typename(L, 1)); luaL_error(L, "table expected, got %s", luaL_typename(L, 1));
l = list_alloc(); l = list_alloc();
if (l == NULL) if (l == NULL)
{
lua_pushnil(L); lua_pushnil(L);
else return 1;
{ }
luaV_newlist(L, l); luaV_newlist(L, l);
if (initarg) // traverse table to init list if (!initarg)
{ return 1;
// traverse table to init list
int notnil, i = 0; int notnil, i = 0;
typval_T v; typval_T v;
do do
@@ -1965,8 +1976,7 @@ luaV_list(lua_State *L)
} }
lua_pop(L, 1); // value lua_pop(L, 1); // value
} while (notnil); } while (notnil);
}
}
return 1; return 1;
} }
@@ -1978,14 +1988,19 @@ luaV_dict(lua_State *L)
if (initarg && lua_type(L, 1) != LUA_TTABLE) if (initarg && lua_type(L, 1) != LUA_TTABLE)
luaL_error(L, "table expected, got %s", luaL_typename(L, 1)); luaL_error(L, "table expected, got %s", luaL_typename(L, 1));
d = dict_alloc(); d = dict_alloc();
if (d == NULL) if (d == NULL)
{
lua_pushnil(L); lua_pushnil(L);
else return 1;
{ }
luaV_newdict(L, d); luaV_newdict(L, d);
if (initarg) // traverse table to init dict if (!initarg)
{ return 1;
// traverse table to init dict
lua_pushnil(L); lua_pushnil(L);
while (lua_next(L, 1)) while (lua_next(L, 1))
{ {
@@ -2013,8 +2028,7 @@ luaV_dict(lua_State *L)
di->di_tv = v; di->di_tv = v;
lua_pop(L, 2); // key copy and value lua_pop(L, 2); // key copy and value
} }
}
}
return 1; return 1;
} }
@@ -2026,22 +2040,26 @@ luaV_blob(lua_State *L)
if (initarg && !lua_isstring(L, 1)) if (initarg && !lua_isstring(L, 1))
luaL_error(L, "string expected, got %s", luaL_typename(L, 1)); luaL_error(L, "string expected, got %s", luaL_typename(L, 1));
b = blob_alloc(); b = blob_alloc();
if (b == NULL) if (b == NULL)
{
lua_pushnil(L); lua_pushnil(L);
else return 1;
{ }
luaV_newblob(L, b); luaV_newblob(L, b);
if (initarg) if (!initarg)
{ return 1;
// traverse table to init blob
size_t i, l = 0; size_t i, l = 0;
const char *s = lua_tolstring(L, 1, &l); const char *s = lua_tolstring(L, 1, &l);
if (ga_grow(&b->bv_ga, (int)l) == OK) if (ga_grow(&b->bv_ga, (int)l) == OK)
for (i = 0; i < l; ++i) for (i = 0; i < l; ++i)
ga_append(&b->bv_ga, s[i]); ga_append(&b->bv_ga, s[i]);
}
}
return 1; return 1;
} }
@@ -2548,8 +2566,9 @@ lua_isopen(void)
static int static int
lua_init(void) lua_init(void)
{ {
if (!lua_isopen()) if (lua_isopen())
{ return OK;
#ifdef DYNAMIC_LUA #ifdef DYNAMIC_LUA
if (!lua_enabled(TRUE)) if (!lua_enabled(TRUE))
{ {
@@ -2558,19 +2577,19 @@ lua_init(void)
} }
#endif #endif
L = luaV_newstate(); L = luaV_newstate();
}
return OK; return OK;
} }
void void
lua_end(void) lua_end(void)
{ {
if (lua_isopen()) if (!lua_isopen())
{ return;
lua_close(L); lua_close(L);
L = NULL; L = NULL;
} }
}
/* /*
* ex commands * ex commands
@@ -2698,8 +2717,9 @@ set_ref_in_lua(int copyID)
{ {
int aborted = 0; int aborted = 0;
if (lua_isopen()) if (!lua_isopen())
{ return 0;
luaV_getfield(L, LUAVIM_SETREF); luaV_getfield(L, LUAVIM_SETREF);
// call the function with 1 arg, getting 1 result back // call the function with 1 arg, getting 1 result back
lua_pushinteger(L, copyID); lua_pushinteger(L, copyID);
@@ -2708,22 +2728,22 @@ set_ref_in_lua(int copyID)
aborted = lua_tointeger(L, -1); aborted = lua_tointeger(L, -1);
// pop result off the stack // pop result off the stack
lua_pop(L, 1); lua_pop(L, 1);
}
return aborted; return aborted;
} }
void void
update_package_paths_in_lua() update_package_paths_in_lua()
{ {
if (lua_isopen()) if (!lua_isopen())
{ return;
lua_getglobal(L, "vim"); lua_getglobal(L, "vim");
lua_getfield(L, -1, "_update_package_paths"); lua_getfield(L, -1, "_update_package_paths");
if (lua_pcall(L, 0, 0, 0)) if (lua_pcall(L, 0, 0, 0))
luaV_emsg(L); luaV_emsg(L);
} }
}
/* /*
* Native C function callback * Native C function callback

View File

@@ -1352,8 +1352,9 @@ do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what)
void void
mzscheme_buffer_free(buf_T *buf) mzscheme_buffer_free(buf_T *buf)
{ {
if (buf->b_mzscheme_ref) if (buf->b_mzscheme_ref == NULL)
{ return;
vim_mz_buffer *bp = NULL; vim_mz_buffer *bp = NULL;
MZ_GC_DECL_REG(1); MZ_GC_DECL_REG(1);
MZ_GC_VAR_IN_REG(0, bp); MZ_GC_VAR_IN_REG(0, bp);
@@ -1370,7 +1371,6 @@ mzscheme_buffer_free(buf_T *buf)
MZ_GC_CHECK(); MZ_GC_CHECK();
MZ_GC_UNREG(); MZ_GC_UNREG();
} }
}
/* /*
* Routine called by VIM when deleting a Window * Routine called by VIM when deleting a Window
@@ -1378,8 +1378,9 @@ mzscheme_buffer_free(buf_T *buf)
void void
mzscheme_window_free(win_T *win) mzscheme_window_free(win_T *win)
{ {
if (win->w_mzscheme_ref) if (win->w_mzscheme_ref == NULL)
{ return;
vim_mz_window *wp = NULL; vim_mz_window *wp = NULL;
MZ_GC_DECL_REG(1); MZ_GC_DECL_REG(1);
MZ_GC_VAR_IN_REG(0, wp); MZ_GC_VAR_IN_REG(0, wp);
@@ -1395,7 +1396,6 @@ mzscheme_window_free(win_T *win)
MZ_GC_CHECK(); MZ_GC_CHECK();
MZ_GC_UNREG(); MZ_GC_UNREG();
} }
}
/* /*
* ":mzscheme" (or ":mz") * ":mzscheme" (or ":mz")
@@ -1406,8 +1406,9 @@ ex_mzscheme(exarg_T *eap)
char_u *script; char_u *script;
script = script_get(eap, eap->arg); script = script_get(eap, eap->arg);
if (!eap->skip) if (eap->skip)
{ return;
if (script == NULL) if (script == NULL)
do_mzscheme_command(eap, eap->arg, do_eval); do_mzscheme_command(eap, eap->arg, do_eval);
else else
@@ -1416,7 +1417,6 @@ ex_mzscheme(exarg_T *eap)
vim_free(script); vim_free(script);
} }
} }
}
static Scheme_Object * static Scheme_Object *
do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED) do_load(void *data, int noargc UNUSED, Scheme_Object **noargv UNUSED)
@@ -1489,8 +1489,9 @@ ex_mzfile(exarg_T *eap)
static void static void
init_exn_catching_apply(void) init_exn_catching_apply(void)
{ {
if (!exn_catching_apply) if (exn_catching_apply)
{ return;
char *e = char *e =
"(lambda (thunk) " "(lambda (thunk) "
"(with-handlers ([void (lambda (exn) (cons #f exn))]) " "(with-handlers ([void (lambda (exn) (cons #f exn))]) "
@@ -1503,7 +1504,6 @@ init_exn_catching_apply(void)
exn_message = scheme_builtin_value("exn-message"); exn_message = scheme_builtin_value("exn-message");
MZ_GC_CHECK(); MZ_GC_CHECK();
} }
}
/* /*
* This function applies a thunk, returning the Scheme value if there's * This function applies a thunk, returning the Scheme value if there's
@@ -3827,8 +3827,9 @@ sandbox_check(void)
static Scheme_Object * static Scheme_Object *
sandbox_file_guard(int argc UNUSED, Scheme_Object **argv) sandbox_file_guard(int argc UNUSED, Scheme_Object **argv)
{ {
if (sandbox) if (!sandbox)
{ return scheme_void;
Scheme_Object *requested_access = argv[2]; Scheme_Object *requested_access = argv[2];
if (M_write == NULL) if (M_write == NULL)
@@ -3864,7 +3865,7 @@ sandbox_file_guard(int argc UNUSED, Scheme_Object **argv)
raise_vim_exn(_("not allowed in the Vim sandbox")); raise_vim_exn(_("not allowed in the Vim sandbox"));
requested_access = SCHEME_CDR(requested_access); requested_access = SCHEME_CDR(requested_access);
} }
}
return scheme_void; return scheme_void;
} }

View File

@@ -1392,36 +1392,33 @@ static PySequenceMethods WinListAsSeq = {
void void
python_buffer_free(buf_T *buf) python_buffer_free(buf_T *buf)
{
if (BUF_PYTHON_REF(buf) != NULL)
{ {
BufferObject *bp = BUF_PYTHON_REF(buf); BufferObject *bp = BUF_PYTHON_REF(buf);
if (bp == NULL)
return;
bp->buf = INVALID_BUFFER_VALUE; bp->buf = INVALID_BUFFER_VALUE;
BUF_PYTHON_REF(buf) = NULL; BUF_PYTHON_REF(buf) = NULL;
} }
}
void void
python_window_free(win_T *win) python_window_free(win_T *win)
{
if (WIN_PYTHON_REF(win) != NULL)
{ {
WindowObject *wp = WIN_PYTHON_REF(win); WindowObject *wp = WIN_PYTHON_REF(win);
if (wp == NULL)
return;
wp->win = INVALID_WINDOW_VALUE; wp->win = INVALID_WINDOW_VALUE;
WIN_PYTHON_REF(win) = NULL; WIN_PYTHON_REF(win) = NULL;
} }
}
void void
python_tabpage_free(tabpage_T *tab) python_tabpage_free(tabpage_T *tab)
{
if (TAB_PYTHON_REF(tab) != NULL)
{ {
TabPageObject *tp = TAB_PYTHON_REF(tab); TabPageObject *tp = TAB_PYTHON_REF(tab);
if (tp == NULL)
return;
tp->tab = INVALID_TABPAGE_VALUE; tp->tab = INVALID_TABPAGE_VALUE;
TAB_PYTHON_REF(tab) = NULL; TAB_PYTHON_REF(tab) = NULL;
} }
}
static int static int
PythonMod_Init(void) PythonMod_Init(void)

View File

@@ -1834,36 +1834,33 @@ FunctionGetattro(PyObject *self, PyObject *nameobj)
void void
python3_buffer_free(buf_T *buf) python3_buffer_free(buf_T *buf)
{
if (BUF_PYTHON_REF(buf) != NULL)
{ {
BufferObject *bp = BUF_PYTHON_REF(buf); BufferObject *bp = BUF_PYTHON_REF(buf);
if (bp == NULL)
return;
bp->buf = INVALID_BUFFER_VALUE; bp->buf = INVALID_BUFFER_VALUE;
BUF_PYTHON_REF(buf) = NULL; BUF_PYTHON_REF(buf) = NULL;
} }
}
void void
python3_window_free(win_T *win) python3_window_free(win_T *win)
{
if (WIN_PYTHON_REF(win) != NULL)
{ {
WindowObject *wp = WIN_PYTHON_REF(win); WindowObject *wp = WIN_PYTHON_REF(win);
if (wp == NULL)
return;
wp->win = INVALID_WINDOW_VALUE; wp->win = INVALID_WINDOW_VALUE;
WIN_PYTHON_REF(win) = NULL; WIN_PYTHON_REF(win) = NULL;
} }
}
void void
python3_tabpage_free(tabpage_T *tab) python3_tabpage_free(tabpage_T *tab)
{
if (TAB_PYTHON_REF(tab) != NULL)
{ {
TabPageObject *tp = TAB_PYTHON_REF(tab); TabPageObject *tp = TAB_PYTHON_REF(tab);
if (tp == NULL)
return;
tp->tab = INVALID_TABPAGE_VALUE; tp->tab = INVALID_TABPAGE_VALUE;
TAB_PYTHON_REF(tab) = NULL; TAB_PYTHON_REF(tab) = NULL;
} }
}
static PyObject * static PyObject *
Py3Init_vim(void) Py3Init_vim(void)

View File

@@ -866,8 +866,9 @@ ex_rubydo(exarg_T *eap)
linenr_T i; linenr_T i;
buf_T *was_curbuf = curbuf; buf_T *was_curbuf = curbuf;
if (ensure_ruby_initialized()) if (!ensure_ruby_initialized())
{ return;
if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) if (u_save(eap->line1 - 1, eap->line2 + 1) != OK)
return; return;
for (i = eap->line1; i <= eap->line2; i++) for (i = eap->line1; i <= eap->line2; i++)
@@ -904,7 +905,6 @@ ex_rubydo(exarg_T *eap)
check_cursor(); check_cursor();
update_curbuf(UPD_NOT_VALID); update_curbuf(UPD_NOT_VALID);
} }
}
static VALUE static VALUE
rb_load_wrap(VALUE file_to_load) rb_load_wrap(VALUE file_to_load)
@@ -918,40 +918,41 @@ ex_rubyfile(exarg_T *eap)
{ {
int state; int state;
if (ensure_ruby_initialized()) if (!ensure_ruby_initialized())
{ return;
VALUE file_to_load = rb_str_new2((const char *)eap->arg); VALUE file_to_load = rb_str_new2((const char *)eap->arg);
rb_protect(rb_load_wrap, file_to_load, &state); rb_protect(rb_load_wrap, file_to_load, &state);
if (state) if (state)
error_print(state); error_print(state);
} }
}
void void
ruby_buffer_free(buf_T *buf) ruby_buffer_free(buf_T *buf)
{ {
if (buf->b_ruby_ref) if (buf->b_ruby_ref == NULL)
{ return;
rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil);
RDATA(buf->b_ruby_ref)->data = NULL; RDATA(buf->b_ruby_ref)->data = NULL;
} }
}
void void
ruby_window_free(win_T *win) ruby_window_free(win_T *win)
{ {
if (win->w_ruby_ref) if (win->w_ruby_ref == NULL)
{ return;
rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil);
RDATA(win->w_ruby_ref)->data = NULL; RDATA(win->w_ruby_ref)->data = NULL;
} }
}
static int static int
ensure_ruby_initialized(void) ensure_ruby_initialized(void)
{ {
if (!ruby_initialized) if (ruby_initialized)
{ return ruby_initialized;
#ifdef DYNAMIC_RUBY #ifdef DYNAMIC_RUBY
if (ruby_enabled(TRUE)) if (ruby_enabled(TRUE))
#endif #endif
@@ -984,7 +985,7 @@ ensure_ruby_initialized(void)
return 0; return 0;
} }
#endif #endif
}
return ruby_initialized; return ruby_initialized;
} }

View File

@@ -221,8 +221,9 @@ serverRegisterName(
char_u *p = NULL; char_u *p = NULL;
res = DoRegisterName(dpy, name); res = DoRegisterName(dpy, name);
if (res < 0) if (res >= 0)
{ return OK;
i = 1; i = 1;
do do
{ {
@@ -245,7 +246,7 @@ serverRegisterName(
while (res < 0) while (res < 0)
; ;
vim_free(p); vim_free(p);
}
return OK; return OK;
} }
@@ -756,18 +757,18 @@ serverSendReply(char_u *name, char_u *str)
return -1; return -1;
length = STRLEN(p_enc) + STRLEN(str) + 14; length = STRLEN(p_enc) + STRLEN(str) + 14;
if ((property = alloc(length + 30)) != NULL) if ((property = alloc(length + 30)) == NULL)
{ return -1;
sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x", sprintf((char *)property, "%cn%c-E %s%c-n %s%c-w %x",
0, 0, p_enc, 0, str, 0, (unsigned int)commWindow); 0, 0, p_enc, 0, str, 0, (unsigned int)commWindow);
// Add length of what "%x" resulted in. // Add length of what "%x" resulted in.
length += STRLEN(property + length); length += STRLEN(property + length);
res = AppendPropCarefully(dpy, win, commProperty, property, length + 1); res = AppendPropCarefully(dpy, win, commProperty, property, length + 1);
vim_free(property); vim_free(property);
return res; return res;
} }
return -1;
}
static int static int
WaitForReply(void *p) WaitForReply(void *p)

View File

@@ -2188,13 +2188,13 @@ fixthisline(int (*get_the_indent)(void))
{ {
int amount = get_the_indent(); int amount = get_the_indent();
if (amount >= 0) if (amount < 0)
{ return;
change_indent(INDENT_SET, amount, FALSE, 0, TRUE); change_indent(INDENT_SET, amount, FALSE, 0, TRUE);
if (linewhite(curwin->w_cursor.lnum)) if (linewhite(curwin->w_cursor.lnum))
did_ai = TRUE; // delete the indent if the line stays empty did_ai = TRUE; // delete the indent if the line stays empty
} }
}
/* /*
* Return TRUE if 'indentexpr' should be used for Lisp indenting. * Return TRUE if 'indentexpr' should be used for Lisp indenting.

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1183,
/**/ /**/
1182, 1182,
/**/ /**/