Mercurial > vim
changeset 31702:27c9212d10aa v9.0.1183
patch 9.0.1183: code is indented more than necessary
Commit: https://github.com/vim/vim/commit/0233bdfa2b487c392dc4fd1a29113e08fbace334
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Jan 12 12:33:30 2023 +0000
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 12 Jan 2023 13:45:04 +0100 |
parents | fea20ce67efd |
children | be916188a456 |
files | src/if_cscope.c src/if_lua.c src/if_mzsch.c src/if_python.c src/if_python3.c src/if_ruby.c src/if_xcmdsrv.c src/indent.c src/version.c |
diffstat | 9 files changed, 400 insertions(+), 380 deletions(-) [+] |
line wrap: on
line diff
--- a/src/if_cscope.c +++ b/src/if_cscope.c @@ -221,25 +221,26 @@ 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 - { - xp->xp_pattern = skipwhite(p); - if (*skiptowhite(xp->xp_pattern) != NUL) - xp->xp_context = EXPAND_NOTHING; - else if (STRNICMP(arg, "add", p - arg) == 0) - xp->xp_context = EXPAND_FILES; - else if (STRNICMP(arg, "kill", p - arg) == 0) - expand_what = EXP_CSCOPE_KILL; - else if (STRNICMP(arg, "find", p - arg) == 0) - expand_what = EXP_CSCOPE_FIND; - else - xp->xp_context = EXPAND_NOTHING; - } - } + p = skiptowhite(arg); + if (*p == NUL) + return; + + // past first word + xp->xp_pattern = skipwhite(p); + if (*skiptowhite(xp->xp_pattern) != NUL) + xp->xp_context = EXPAND_NOTHING; + else if (STRNICMP(arg, "add", p - arg) == 0) + xp->xp_context = EXPAND_FILES; + else if (STRNICMP(arg, "kill", p - arg) == 0) + expand_what = EXP_CSCOPE_KILL; + else if (STRNICMP(arg, "find", p - arg) == 0) + expand_what = EXP_CSCOPE_FIND; + else + xp->xp_context = EXPAND_NOTHING; } /*
--- a/src/if_lua.c +++ b/src/if_lua.c @@ -505,18 +505,20 @@ luaV_toudata(lua_State *L, int ud, const { 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 + if (lua_rawequal(L, -1, -2)) // MTs match? { - luaV_getfield(L, tname); // get metatable - if (lua_rawequal(L, -1, -2)) // MTs match? - { - lua_pop(L, 2); // MTs - return p; - } + lua_pop(L, 2); // MTs + return p; } } + return NULL; } @@ -1090,17 +1092,19 @@ luaV_dict_index(lua_State *L) dictitem_T *di = dict_find(d, key, -1); if (di == NULL) - lua_pushnil(L); - else { - luaV_pushtypval(L, &di->di_tv); - if (di->di_tv.v_type == VAR_FUNC) // funcref? - { - luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1); - f->self = d; // keep "self" reference - d->dv_refcount++; - } + lua_pushnil(L); + return 1; } + + luaV_pushtypval(L, &di->di_tv); + if (di->di_tv.v_type == VAR_FUNC) // funcref? + { + luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1); + f->self = d; // keep "self" reference + d->dv_refcount++; + } + return 1; } @@ -1235,20 +1239,22 @@ 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); + if (idx < len || (idx == len && ga_grow(&b->bv_ga, 1) == OK)) { - long len = blob_len(b); - int idx = luaL_checkinteger(L, 2); - int val = luaL_checkinteger(L, 3); - if (idx < len || (idx == len && ga_grow(&b->bv_ga, 1) == OK)) - { - blob_set(b, idx, (char_u) val); - if (idx == len) - ++b->bv_ga.ga_len; - } - else - luaL_error(L, "index out of range"); + blob_set(b, idx, (char_u) val); + if (idx == len) + ++b->bv_ga.ga_len; } + else + luaL_error(L, "index out of range"); + return 0; } @@ -1943,30 +1949,34 @@ 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 { - luaV_newlist(L, l); - if (initarg) // traverse table to init list + lua_pushnil(L); + return 1; + } + + luaV_newlist(L, l); + if (!initarg) + return 1; + + // traverse table to init list + int notnil, i = 0; + typval_T v; + do + { + lua_rawgeti(L, 1, ++i); + notnil = !lua_isnil(L, -1); + if (notnil) { - int notnil, i = 0; - typval_T v; - do - { - lua_rawgeti(L, 1, ++i); - notnil = !lua_isnil(L, -1); - if (notnil) - { - luaV_checktypval(L, -1, &v, "vim.list"); - list_append_tv(l, &v); - clear_tv(&v); - } - lua_pop(L, 1); // value - } while (notnil); + luaV_checktypval(L, -1, &v, "vim.list"); + list_append_tv(l, &v); + clear_tv(&v); } - } + lua_pop(L, 1); // value + } while (notnil); + return 1; } @@ -1978,43 +1988,47 @@ 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 { - luaV_newdict(L, d); - if (initarg) // traverse table to init dict + lua_pushnil(L); + return 1; + } + + luaV_newdict(L, d); + if (!initarg) + return 1; + + // traverse table to init dict + lua_pushnil(L); + while (lua_next(L, 1)) + { + char_u *key; + dictitem_T *di; + typval_T v; + + lua_pushvalue(L, -2); // dup key in case it's a number + key = (char_u *) lua_tostring(L, -1); + if (key == NULL) { lua_pushnil(L); - while (lua_next(L, 1)) - { - char_u *key; - dictitem_T *di; - typval_T v; + return 1; + } + if (*key == NUL) + luaL_error(L, "table has empty key"); + luaV_checktypval(L, -2, &v, "vim.dict"); // value + di = dictitem_alloc(key); + if (di == NULL || dict_add(d, di) == FAIL) + { + vim_free(di); + lua_pushnil(L); + return 1; + } + di->di_tv = v; + lua_pop(L, 2); // key copy and value + } - lua_pushvalue(L, -2); // dup key in case it's a number - key = (char_u *) lua_tostring(L, -1); - if (key == NULL) - { - lua_pushnil(L); - return 1; - } - if (*key == NUL) - luaL_error(L, "table has empty key"); - luaV_checktypval(L, -2, &v, "vim.dict"); // value - di = dictitem_alloc(key); - if (di == NULL || dict_add(d, di) == FAIL) - { - vim_free(di); - lua_pushnil(L); - return 1; - } - 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 - { - luaV_newblob(L, b); - if (initarg) - { - size_t i, l = 0; - const char *s = lua_tolstring(L, 1, &l); + return 1; + } + + luaV_newblob(L, b); + if (!initarg) + return 1; - if (ga_grow(&b->bv_ga, (int)l) == OK) - for (i = 0; i < l; ++i) - ga_append(&b->bv_ga, s[i]); - } - } + // 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,28 +2566,29 @@ lua_isopen(void) static int lua_init(void) { - if (!lua_isopen()) - { + if (lua_isopen()) + return OK; + #ifdef DYNAMIC_LUA - if (!lua_enabled(TRUE)) - { - emsg(_("Lua library cannot be loaded.")); - return FAIL; - } + if (!lua_enabled(TRUE)) + { + emsg(_("Lua library cannot be loaded.")); + return FAIL; + } #endif - L = luaV_newstate(); - } + L = luaV_newstate(); + return OK; } void lua_end(void) { - if (lua_isopen()) - { - lua_close(L); - L = NULL; - } + if (!lua_isopen()) + return; + + lua_close(L); + L = NULL; } /* @@ -2698,31 +2717,32 @@ set_ref_in_lua(int copyID) { int aborted = 0; - if (lua_isopen()) - { - luaV_getfield(L, LUAVIM_SETREF); - // call the function with 1 arg, getting 1 result back - lua_pushinteger(L, copyID); - lua_call(L, 1, 1); - // get the result - aborted = lua_tointeger(L, -1); - // pop result off the stack - lua_pop(L, 1); - } + if (!lua_isopen()) + return 0; + + luaV_getfield(L, LUAVIM_SETREF); + // call the function with 1 arg, getting 1 result back + lua_pushinteger(L, copyID); + lua_call(L, 1, 1); + // get the result + 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()) - { - lua_getglobal(L, "vim"); - lua_getfield(L, -1, "_update_package_paths"); + if (!lua_isopen()) + return; - if (lua_pcall(L, 0, 0, 0)) - luaV_emsg(L); - } + lua_getglobal(L, "vim"); + lua_getfield(L, -1, "_update_package_paths"); + + if (lua_pcall(L, 0, 0, 0)) + luaV_emsg(L); } /*
--- a/src/if_mzsch.c +++ b/src/if_mzsch.c @@ -1352,24 +1352,24 @@ do_mzscheme_command(exarg_T *eap, void * void mzscheme_buffer_free(buf_T *buf) { - if (buf->b_mzscheme_ref) - { - vim_mz_buffer *bp = NULL; - MZ_GC_DECL_REG(1); - MZ_GC_VAR_IN_REG(0, bp); - MZ_GC_REG(); - - bp = BUFFER_REF(buf); - bp->buf = INVALID_BUFFER_VALUE; + if (buf->b_mzscheme_ref == NULL) + return; + + vim_mz_buffer *bp = NULL; + MZ_GC_DECL_REG(1); + MZ_GC_VAR_IN_REG(0, bp); + MZ_GC_REG(); + + bp = BUFFER_REF(buf); + bp->buf = INVALID_BUFFER_VALUE; #ifndef MZ_PRECISE_GC - scheme_gc_ptr_ok(bp); + scheme_gc_ptr_ok(bp); #else - scheme_free_immobile_box(buf->b_mzscheme_ref); + scheme_free_immobile_box(buf->b_mzscheme_ref); #endif - buf->b_mzscheme_ref = NULL; - MZ_GC_CHECK(); - MZ_GC_UNREG(); - } + buf->b_mzscheme_ref = NULL; + MZ_GC_CHECK(); + MZ_GC_UNREG(); } /* @@ -1378,23 +1378,23 @@ mzscheme_buffer_free(buf_T *buf) void mzscheme_window_free(win_T *win) { - if (win->w_mzscheme_ref) - { - vim_mz_window *wp = NULL; - MZ_GC_DECL_REG(1); - MZ_GC_VAR_IN_REG(0, wp); - MZ_GC_REG(); - wp = WINDOW_REF(win); - wp->win = INVALID_WINDOW_VALUE; + if (win->w_mzscheme_ref == NULL) + return; + + vim_mz_window *wp = NULL; + MZ_GC_DECL_REG(1); + MZ_GC_VAR_IN_REG(0, wp); + MZ_GC_REG(); + wp = WINDOW_REF(win); + wp->win = INVALID_WINDOW_VALUE; #ifndef MZ_PRECISE_GC - scheme_gc_ptr_ok(wp); + scheme_gc_ptr_ok(wp); #else - scheme_free_immobile_box(win->w_mzscheme_ref); + scheme_free_immobile_box(win->w_mzscheme_ref); #endif - win->w_mzscheme_ref = NULL; - MZ_GC_CHECK(); - MZ_GC_UNREG(); - } + win->w_mzscheme_ref = NULL; + MZ_GC_CHECK(); + MZ_GC_UNREG(); } /* @@ -1406,15 +1406,15 @@ 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 { - if (script == NULL) - do_mzscheme_command(eap, eap->arg, do_eval); - else - { - do_mzscheme_command(eap, script, do_eval); - vim_free(script); - } + do_mzscheme_command(eap, script, do_eval); + vim_free(script); } } @@ -1489,20 +1489,20 @@ ex_mzfile(exarg_T *eap) static void init_exn_catching_apply(void) { - if (!exn_catching_apply) - { - char *e = - "(lambda (thunk) " - "(with-handlers ([void (lambda (exn) (cons #f exn))]) " - "(cons #t (thunk))))"; - - exn_catching_apply = scheme_eval_string(e, environment); - MZ_GC_CHECK(); - exn_p = scheme_builtin_value("exn?"); - MZ_GC_CHECK(); - exn_message = scheme_builtin_value("exn-message"); - MZ_GC_CHECK(); - } + if (exn_catching_apply) + return; + + char *e = + "(lambda (thunk) " + "(with-handlers ([void (lambda (exn) (cons #f exn))]) " + "(cons #t (thunk))))"; + + exn_catching_apply = scheme_eval_string(e, environment); + MZ_GC_CHECK(); + exn_p = scheme_builtin_value("exn?"); + MZ_GC_CHECK(); + exn_message = scheme_builtin_value("exn-message"); + MZ_GC_CHECK(); } /* @@ -3827,44 +3827,45 @@ 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) + { + MZ_REGISTER_STATIC(M_write); + M_write = scheme_intern_symbol("write"); + MZ_GC_CHECK(); + } + if (M_read == NULL) + { + MZ_REGISTER_STATIC(M_read); + M_read = scheme_intern_symbol("read"); + MZ_GC_CHECK(); + } + if (M_execute == NULL) { - Scheme_Object *requested_access = argv[2]; - - if (M_write == NULL) - { - MZ_REGISTER_STATIC(M_write); - M_write = scheme_intern_symbol("write"); - MZ_GC_CHECK(); - } - if (M_read == NULL) - { - MZ_REGISTER_STATIC(M_read); - M_read = scheme_intern_symbol("read"); - MZ_GC_CHECK(); - } - if (M_execute == NULL) - { - MZ_REGISTER_STATIC(M_execute); - M_execute = scheme_intern_symbol("execute"); - MZ_GC_CHECK(); - } - if (M_delete == NULL) - { - MZ_REGISTER_STATIC(M_delete); - M_delete = scheme_intern_symbol("delete"); - MZ_GC_CHECK(); - } - - while (!SCHEME_NULLP(requested_access)) - { - Scheme_Object *item = SCHEME_CAR(requested_access); - if (scheme_eq(item, M_write) || scheme_eq(item, M_read) - || scheme_eq(item, M_execute) || scheme_eq(item, M_delete)) - raise_vim_exn(_("not allowed in the Vim sandbox")); - requested_access = SCHEME_CDR(requested_access); - } + MZ_REGISTER_STATIC(M_execute); + M_execute = scheme_intern_symbol("execute"); + MZ_GC_CHECK(); + } + if (M_delete == NULL) + { + MZ_REGISTER_STATIC(M_delete); + M_delete = scheme_intern_symbol("delete"); + MZ_GC_CHECK(); } + + while (!SCHEME_NULLP(requested_access)) + { + Scheme_Object *item = SCHEME_CAR(requested_access); + if (scheme_eq(item, M_write) || scheme_eq(item, M_read) + || scheme_eq(item, M_execute) || scheme_eq(item, M_delete)) + raise_vim_exn(_("not allowed in the Vim sandbox")); + requested_access = SCHEME_CDR(requested_access); + } + return scheme_void; }
--- a/src/if_python.c +++ b/src/if_python.c @@ -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); - bp->buf = INVALID_BUFFER_VALUE; - 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); - wp->win = INVALID_WINDOW_VALUE; - 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); - tp->tab = INVALID_TABPAGE_VALUE; - 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
--- a/src/if_python3.c +++ b/src/if_python3.c @@ -1835,34 +1835,31 @@ FunctionGetattro(PyObject *self, PyObjec void python3_buffer_free(buf_T *buf) { - if (BUF_PYTHON_REF(buf) != NULL) - { - BufferObject *bp = BUF_PYTHON_REF(buf); - bp->buf = INVALID_BUFFER_VALUE; - 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); - wp->win = INVALID_WINDOW_VALUE; - 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); - tp->tab = INVALID_TABPAGE_VALUE; - 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 *
--- a/src/if_ruby.c +++ b/src/if_ruby.c @@ -866,44 +866,44 @@ 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++) { - if (u_save(eap->line1 - 1, eap->line2 + 1) != OK) - return; - for (i = eap->line1; i <= eap->line2; i++) - { - VALUE line; + VALUE line; - if (i > curbuf->b_ml.ml_line_count) - break; - line = vim_str2rb_enc_str((char *)ml_get(i)); - rb_lastline_set(line); - eval_enc_string_protect((char *) eap->arg, &state); - if (state) + if (i > curbuf->b_ml.ml_line_count) + break; + line = vim_str2rb_enc_str((char *)ml_get(i)); + rb_lastline_set(line); + eval_enc_string_protect((char *) eap->arg, &state); + if (state) + { + error_print(state); + break; + } + if (was_curbuf != curbuf) + break; + line = rb_lastline_get(); + if (!NIL_P(line)) + { + if (TYPE(line) != T_STRING) { - error_print(state); - break; + emsg(_(e_dollar_must_be_an_instance_of_string)); + return; } - if (was_curbuf != curbuf) - break; - line = rb_lastline_get(); - if (!NIL_P(line)) - { - if (TYPE(line) != T_STRING) - { - emsg(_(e_dollar_must_be_an_instance_of_string)); - return; - } - ml_replace(i, (char_u *) StringValuePtr(line), 1); - changed(); + ml_replace(i, (char_u *) StringValuePtr(line), 1); + changed(); #ifdef SYNTAX_HL - syn_changed(i); // recompute syntax hl. for this line + syn_changed(i); // recompute syntax hl. for this line #endif - } } - check_cursor(); - update_curbuf(UPD_NOT_VALID); } + check_cursor(); + update_curbuf(UPD_NOT_VALID); } static VALUE @@ -918,73 +918,74 @@ ex_rubyfile(exarg_T *eap) { int state; - if (ensure_ruby_initialized()) - { - 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); - } + 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) - { - rb_hash_aset(objtbl, rb_obj_id((VALUE) buf->b_ruby_ref), Qnil); - RDATA(buf->b_ruby_ref)->data = NULL; - } + 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) - { - rb_hash_aset(objtbl, rb_obj_id((VALUE) win->w_ruby_ref), Qnil); - RDATA(win->w_ruby_ref)->data = NULL; - } + 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 { -#ifdef DYNAMIC_RUBY - if (ruby_enabled(TRUE)) +#ifdef MSWIN + // suggested by Ariya Mizutani + int argc = 1; + char *argv[] = {"gvim.exe"}; + char **argvp = argv; + ruby_sysinit(&argc, &argvp); #endif { -#ifdef MSWIN - // suggested by Ariya Mizutani - int argc = 1; - char *argv[] = {"gvim.exe"}; - char **argvp = argv; - ruby_sysinit(&argc, &argvp); + ruby_init_stack(ruby_stack_start); + ruby_init(); + } + { + int dummy_argc = 2; + char *dummy_argv[] = {"vim-ruby", "-e_=0"}; + ruby_options(dummy_argc, dummy_argv); + } + ruby_script("vim-ruby"); + ruby_io_init(); + ruby_vim_init(); + ruby_initialized = 1; + } +#ifdef DYNAMIC_RUBY + else + { + emsg(_(e_sorry_this_command_is_disabled_the_ruby_library_could_not_be_loaded)); + return 0; + } #endif - { - ruby_init_stack(ruby_stack_start); - ruby_init(); - } - { - int dummy_argc = 2; - char *dummy_argv[] = {"vim-ruby", "-e_=0"}; - ruby_options(dummy_argc, dummy_argv); - } - ruby_script("vim-ruby"); - ruby_io_init(); - ruby_vim_init(); - ruby_initialized = 1; - } -#ifdef DYNAMIC_RUBY - else - { - emsg(_(e_sorry_this_command_is_disabled_the_ruby_library_could_not_be_loaded)); - return 0; - } -#endif - } + return ruby_initialized; }
--- a/src/if_xcmdsrv.c +++ b/src/if_xcmdsrv.c @@ -221,31 +221,32 @@ serverRegisterName( char_u *p = NULL; res = DoRegisterName(dpy, name); - if (res < 0) + if (res >= 0) + return OK; + + i = 1; + do { - i = 1; - do + if (res < -1 || i >= 1000) { - if (res < -1 || i >= 1000) - { - msg_attr(_("Unable to register a command server name"), - HL_ATTR(HLF_W)); - return FAIL; - } - if (p == NULL) - p = alloc(STRLEN(name) + 10); - if (p == NULL) - { - res = -10; - continue; - } - sprintf((char *)p, "%s%d", name, i++); - res = DoRegisterName(dpy, p); + msg_attr(_("Unable to register a command server name"), + HL_ATTR(HLF_W)); + return FAIL; } - while (res < 0) - ; - vim_free(p); + if (p == NULL) + p = alloc(STRLEN(name) + 10); + if (p == NULL) + { + res = -10; + continue; + } + sprintf((char *)p, "%s%d", name, i++); + res = DoRegisterName(dpy, p); } + while (res < 0) + ; + vim_free(p); + return OK; } @@ -756,17 +757,17 @@ serverSendReply(char_u *name, char_u *st return -1; length = STRLEN(p_enc) + STRLEN(str) + 14; - if ((property = alloc(length + 30)) != NULL) - { - 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; + 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; } static int
--- a/src/indent.c +++ b/src/indent.c @@ -2188,12 +2188,12 @@ fixthisline(int (*get_the_indent)(void)) { int amount = get_the_indent(); - if (amount >= 0) - { - 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 - } + 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 } /*