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:
committed by
Bram Moolenaar
parent
043d7b2c84
commit
0233bdfa2b
@@ -221,12 +221,15 @@ set_context_in_cscope_cmd(
|
||||
expand_what = (cmdidx == CMD_scscope)
|
||||
? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD;
|
||||
|
||||
if (*arg == NUL)
|
||||
return;
|
||||
|
||||
// (part of) subcommand already typed
|
||||
if (*arg != NUL)
|
||||
{
|
||||
p = skiptowhite(arg);
|
||||
if (*p != NUL) // past first word
|
||||
{
|
||||
if (*p == NUL)
|
||||
return;
|
||||
|
||||
// past first word
|
||||
xp->xp_pattern = skipwhite(p);
|
||||
if (*skiptowhite(xp->xp_pattern) != NUL)
|
||||
xp->xp_context = EXPAND_NOTHING;
|
||||
@@ -238,8 +241,6 @@ set_context_in_cscope_cmd(
|
||||
expand_what = EXP_CSCOPE_FIND;
|
||||
else
|
||||
xp->xp_context = EXPAND_NOTHING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
98
src/if_lua.c
98
src/if_lua.c
@@ -505,8 +505,10 @@ luaV_toudata(lua_State *L, int ud, const char *tname)
|
||||
{
|
||||
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?
|
||||
{
|
||||
luaV_getfield(L, tname); // get metatable
|
||||
@@ -516,7 +518,7 @@ luaV_toudata(lua_State *L, int ud, const char *tname)
|
||||
return p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1090,9 +1092,11 @@ luaV_dict_index(lua_State *L)
|
||||
dictitem_T *di = dict_find(d, key, -1);
|
||||
|
||||
if (di == NULL)
|
||||
lua_pushnil(L);
|
||||
else
|
||||
{
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
luaV_pushtypval(L, &di->di_tv);
|
||||
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
|
||||
d->dv_refcount++;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1235,8 +1239,10 @@ luaV_blob_newindex(lua_State *L)
|
||||
blob_T *b = luaV_unbox(L, luaV_Blob, 1);
|
||||
if (b->bv_lock)
|
||||
luaL_error(L, "blob is locked");
|
||||
if (lua_isnumber(L, 2))
|
||||
{
|
||||
|
||||
if (!lua_isnumber(L, 2))
|
||||
return 0;
|
||||
|
||||
long len = blob_len(b);
|
||||
int idx = luaL_checkinteger(L, 2);
|
||||
int val = luaL_checkinteger(L, 3);
|
||||
@@ -1248,7 +1254,7 @@ luaV_blob_newindex(lua_State *L)
|
||||
}
|
||||
else
|
||||
luaL_error(L, "index out of range");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1943,14 +1949,19 @@ luaV_list(lua_State *L)
|
||||
|
||||
if (initarg && lua_type(L, 1) != LUA_TTABLE)
|
||||
luaL_error(L, "table expected, got %s", luaL_typename(L, 1));
|
||||
|
||||
l = list_alloc();
|
||||
if (l == NULL)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
luaV_newlist(L, l);
|
||||
if (initarg) // traverse table to init list
|
||||
{
|
||||
if (!initarg)
|
||||
return 1;
|
||||
|
||||
// traverse table to init list
|
||||
int notnil, i = 0;
|
||||
typval_T v;
|
||||
do
|
||||
@@ -1965,8 +1976,7 @@ luaV_list(lua_State *L)
|
||||
}
|
||||
lua_pop(L, 1); // value
|
||||
} while (notnil);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1978,14 +1988,19 @@ luaV_dict(lua_State *L)
|
||||
|
||||
if (initarg && lua_type(L, 1) != LUA_TTABLE)
|
||||
luaL_error(L, "table expected, got %s", luaL_typename(L, 1));
|
||||
|
||||
d = dict_alloc();
|
||||
if (d == NULL)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
luaV_newdict(L, d);
|
||||
if (initarg) // traverse table to init dict
|
||||
{
|
||||
if (!initarg)
|
||||
return 1;
|
||||
|
||||
// traverse table to init dict
|
||||
lua_pushnil(L);
|
||||
while (lua_next(L, 1))
|
||||
{
|
||||
@@ -2013,8 +2028,7 @@ luaV_dict(lua_State *L)
|
||||
di->di_tv = v;
|
||||
lua_pop(L, 2); // key copy and value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2026,22 +2040,26 @@ luaV_blob(lua_State *L)
|
||||
|
||||
if (initarg && !lua_isstring(L, 1))
|
||||
luaL_error(L, "string expected, got %s", luaL_typename(L, 1));
|
||||
|
||||
b = blob_alloc();
|
||||
if (b == NULL)
|
||||
{
|
||||
lua_pushnil(L);
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
luaV_newblob(L, b);
|
||||
if (initarg)
|
||||
{
|
||||
if (!initarg)
|
||||
return 1;
|
||||
|
||||
// traverse table to init blob
|
||||
size_t i, l = 0;
|
||||
const char *s = lua_tolstring(L, 1, &l);
|
||||
|
||||
if (ga_grow(&b->bv_ga, (int)l) == OK)
|
||||
for (i = 0; i < l; ++i)
|
||||
ga_append(&b->bv_ga, s[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -2548,8 +2566,9 @@ lua_isopen(void)
|
||||
static int
|
||||
lua_init(void)
|
||||
{
|
||||
if (!lua_isopen())
|
||||
{
|
||||
if (lua_isopen())
|
||||
return OK;
|
||||
|
||||
#ifdef DYNAMIC_LUA
|
||||
if (!lua_enabled(TRUE))
|
||||
{
|
||||
@@ -2558,18 +2577,18 @@ lua_init(void)
|
||||
}
|
||||
#endif
|
||||
L = luaV_newstate();
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void
|
||||
lua_end(void)
|
||||
{
|
||||
if (lua_isopen())
|
||||
{
|
||||
if (!lua_isopen())
|
||||
return;
|
||||
|
||||
lua_close(L);
|
||||
L = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2698,8 +2717,9 @@ set_ref_in_lua(int copyID)
|
||||
{
|
||||
int aborted = 0;
|
||||
|
||||
if (lua_isopen())
|
||||
{
|
||||
if (!lua_isopen())
|
||||
return 0;
|
||||
|
||||
luaV_getfield(L, LUAVIM_SETREF);
|
||||
// call the function with 1 arg, getting 1 result back
|
||||
lua_pushinteger(L, copyID);
|
||||
@@ -2708,21 +2728,21 @@ set_ref_in_lua(int copyID)
|
||||
aborted = lua_tointeger(L, -1);
|
||||
// pop result off the stack
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return aborted;
|
||||
}
|
||||
|
||||
void
|
||||
update_package_paths_in_lua()
|
||||
{
|
||||
if (lua_isopen())
|
||||
{
|
||||
if (!lua_isopen())
|
||||
return;
|
||||
|
||||
lua_getglobal(L, "vim");
|
||||
lua_getfield(L, -1, "_update_package_paths");
|
||||
|
||||
if (lua_pcall(L, 0, 0, 0))
|
||||
luaV_emsg(L);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -1352,8 +1352,9 @@ do_mzscheme_command(exarg_T *eap, void *data, Scheme_Closed_Prim *what)
|
||||
void
|
||||
mzscheme_buffer_free(buf_T *buf)
|
||||
{
|
||||
if (buf->b_mzscheme_ref)
|
||||
{
|
||||
if (buf->b_mzscheme_ref == NULL)
|
||||
return;
|
||||
|
||||
vim_mz_buffer *bp = NULL;
|
||||
MZ_GC_DECL_REG(1);
|
||||
MZ_GC_VAR_IN_REG(0, bp);
|
||||
@@ -1369,7 +1370,6 @@ mzscheme_buffer_free(buf_T *buf)
|
||||
buf->b_mzscheme_ref = NULL;
|
||||
MZ_GC_CHECK();
|
||||
MZ_GC_UNREG();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1378,8 +1378,9 @@ mzscheme_buffer_free(buf_T *buf)
|
||||
void
|
||||
mzscheme_window_free(win_T *win)
|
||||
{
|
||||
if (win->w_mzscheme_ref)
|
||||
{
|
||||
if (win->w_mzscheme_ref == NULL)
|
||||
return;
|
||||
|
||||
vim_mz_window *wp = NULL;
|
||||
MZ_GC_DECL_REG(1);
|
||||
MZ_GC_VAR_IN_REG(0, wp);
|
||||
@@ -1394,7 +1395,6 @@ mzscheme_window_free(win_T *win)
|
||||
win->w_mzscheme_ref = NULL;
|
||||
MZ_GC_CHECK();
|
||||
MZ_GC_UNREG();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1406,8 +1406,9 @@ ex_mzscheme(exarg_T *eap)
|
||||
char_u *script;
|
||||
|
||||
script = script_get(eap, eap->arg);
|
||||
if (!eap->skip)
|
||||
{
|
||||
if (eap->skip)
|
||||
return;
|
||||
|
||||
if (script == NULL)
|
||||
do_mzscheme_command(eap, eap->arg, do_eval);
|
||||
else
|
||||
@@ -1415,7 +1416,6 @@ ex_mzscheme(exarg_T *eap)
|
||||
do_mzscheme_command(eap, script, do_eval);
|
||||
vim_free(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Scheme_Object *
|
||||
@@ -1489,8 +1489,9 @@ ex_mzfile(exarg_T *eap)
|
||||
static void
|
||||
init_exn_catching_apply(void)
|
||||
{
|
||||
if (!exn_catching_apply)
|
||||
{
|
||||
if (exn_catching_apply)
|
||||
return;
|
||||
|
||||
char *e =
|
||||
"(lambda (thunk) "
|
||||
"(with-handlers ([void (lambda (exn) (cons #f exn))]) "
|
||||
@@ -1502,7 +1503,6 @@ init_exn_catching_apply(void)
|
||||
MZ_GC_CHECK();
|
||||
exn_message = scheme_builtin_value("exn-message");
|
||||
MZ_GC_CHECK();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3827,8 +3827,9 @@ sandbox_check(void)
|
||||
static Scheme_Object *
|
||||
sandbox_file_guard(int argc UNUSED, Scheme_Object **argv)
|
||||
{
|
||||
if (sandbox)
|
||||
{
|
||||
if (!sandbox)
|
||||
return scheme_void;
|
||||
|
||||
Scheme_Object *requested_access = argv[2];
|
||||
|
||||
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"));
|
||||
requested_access = SCHEME_CDR(requested_access);
|
||||
}
|
||||
}
|
||||
|
||||
return scheme_void;
|
||||
}
|
||||
|
||||
|
@@ -1393,34 +1393,31 @@ static PySequenceMethods WinListAsSeq = {
|
||||
void
|
||||
python_buffer_free(buf_T *buf)
|
||||
{
|
||||
if (BUF_PYTHON_REF(buf) != NULL)
|
||||
{
|
||||
BufferObject *bp = BUF_PYTHON_REF(buf);
|
||||
if (bp == NULL)
|
||||
return;
|
||||
bp->buf = INVALID_BUFFER_VALUE;
|
||||
BUF_PYTHON_REF(buf) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python_window_free(win_T *win)
|
||||
{
|
||||
if (WIN_PYTHON_REF(win) != NULL)
|
||||
{
|
||||
WindowObject *wp = WIN_PYTHON_REF(win);
|
||||
if (wp == NULL)
|
||||
return;
|
||||
wp->win = INVALID_WINDOW_VALUE;
|
||||
WIN_PYTHON_REF(win) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python_tabpage_free(tabpage_T *tab)
|
||||
{
|
||||
if (TAB_PYTHON_REF(tab) != NULL)
|
||||
{
|
||||
TabPageObject *tp = TAB_PYTHON_REF(tab);
|
||||
if (tp == NULL)
|
||||
return;
|
||||
tp->tab = INVALID_TABPAGE_VALUE;
|
||||
TAB_PYTHON_REF(tab) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
|
@@ -1835,34 +1835,31 @@ FunctionGetattro(PyObject *self, PyObject *nameobj)
|
||||
void
|
||||
python3_buffer_free(buf_T *buf)
|
||||
{
|
||||
if (BUF_PYTHON_REF(buf) != NULL)
|
||||
{
|
||||
BufferObject *bp = BUF_PYTHON_REF(buf);
|
||||
if (bp == NULL)
|
||||
return;
|
||||
bp->buf = INVALID_BUFFER_VALUE;
|
||||
BUF_PYTHON_REF(buf) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python3_window_free(win_T *win)
|
||||
{
|
||||
if (WIN_PYTHON_REF(win) != NULL)
|
||||
{
|
||||
WindowObject *wp = WIN_PYTHON_REF(win);
|
||||
if (wp == NULL)
|
||||
return;
|
||||
wp->win = INVALID_WINDOW_VALUE;
|
||||
WIN_PYTHON_REF(win) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
python3_tabpage_free(tabpage_T *tab)
|
||||
{
|
||||
if (TAB_PYTHON_REF(tab) != NULL)
|
||||
{
|
||||
TabPageObject *tp = TAB_PYTHON_REF(tab);
|
||||
if (tp == NULL)
|
||||
return;
|
||||
tp->tab = INVALID_TABPAGE_VALUE;
|
||||
TAB_PYTHON_REF(tab) = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
@@ -866,8 +866,9 @@ ex_rubydo(exarg_T *eap)
|
||||
linenr_T i;
|
||||
buf_T *was_curbuf = curbuf;
|
||||
|
||||
if (ensure_ruby_initialized())
|
||||
{
|
||||
if (!ensure_ruby_initialized())
|
||||
return;
|
||||
|
||||
if (u_save(eap->line1 - 1, eap->line2 + 1) != OK)
|
||||
return;
|
||||
for (i = eap->line1; i <= eap->line2; i++)
|
||||
@@ -903,7 +904,6 @@ ex_rubydo(exarg_T *eap)
|
||||
}
|
||||
check_cursor();
|
||||
update_curbuf(UPD_NOT_VALID);
|
||||
}
|
||||
}
|
||||
|
||||
static VALUE
|
||||
@@ -918,40 +918,41 @@ ex_rubyfile(exarg_T *eap)
|
||||
{
|
||||
int state;
|
||||
|
||||
if (ensure_ruby_initialized())
|
||||
{
|
||||
if (!ensure_ruby_initialized())
|
||||
return;
|
||||
|
||||
VALUE file_to_load = rb_str_new2((const char *)eap->arg);
|
||||
rb_protect(rb_load_wrap, file_to_load, &state);
|
||||
if (state)
|
||||
error_print(state);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
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);
|
||||
RDATA(buf->b_ruby_ref)->data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
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);
|
||||
RDATA(win->w_ruby_ref)->data = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
ensure_ruby_initialized(void)
|
||||
{
|
||||
if (!ruby_initialized)
|
||||
{
|
||||
if (ruby_initialized)
|
||||
return ruby_initialized;
|
||||
|
||||
#ifdef DYNAMIC_RUBY
|
||||
if (ruby_enabled(TRUE))
|
||||
#endif
|
||||
@@ -984,7 +985,7 @@ ensure_ruby_initialized(void)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return ruby_initialized;
|
||||
}
|
||||
|
||||
|
@@ -221,8 +221,9 @@ serverRegisterName(
|
||||
char_u *p = NULL;
|
||||
|
||||
res = DoRegisterName(dpy, name);
|
||||
if (res < 0)
|
||||
{
|
||||
if (res >= 0)
|
||||
return OK;
|
||||
|
||||
i = 1;
|
||||
do
|
||||
{
|
||||
@@ -245,7 +246,7 @@ serverRegisterName(
|
||||
while (res < 0)
|
||||
;
|
||||
vim_free(p);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -756,17 +757,17 @@ serverSendReply(char_u *name, char_u *str)
|
||||
return -1;
|
||||
|
||||
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",
|
||||
0, 0, p_enc, 0, str, 0, (unsigned int)commWindow);
|
||||
// Add length of what "%x" resulted in.
|
||||
length += STRLEN(property + length);
|
||||
res = AppendPropCarefully(dpy, win, commProperty, property, length + 1);
|
||||
vim_free(property);
|
||||
|
||||
return res;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int
|
||||
|
@@ -2188,12 +2188,12 @@ fixthisline(int (*get_the_indent)(void))
|
||||
{
|
||||
int amount = get_the_indent();
|
||||
|
||||
if (amount >= 0)
|
||||
{
|
||||
if (amount < 0)
|
||||
return;
|
||||
|
||||
change_indent(INDENT_SET, amount, FALSE, 0, TRUE);
|
||||
if (linewhite(curwin->w_cursor.lnum))
|
||||
did_ai = TRUE; // delete the indent if the line stays empty
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
1183,
|
||||
/**/
|
||||
1182,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user