mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-patch:partial:9.0.1196: code is indented more than necessary (#21796)
Problem: Code is indented more than necessary.
Solution: Use an early return where it makes sense. (Yegappan Lakshmanan,
closes vim/vim#11813)
e857598896
Partial port as this depends on some previous eval and 'smoothscroll'
patches.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
This commit is contained in:
parent
d549734fb4
commit
2065ce877e
@ -326,11 +326,13 @@ void tv_list_free_list(list_T *const l)
|
||||
void tv_list_free(list_T *const l)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
if (!tv_in_free_unref_items) {
|
||||
if (tv_in_free_unref_items) {
|
||||
return;
|
||||
}
|
||||
|
||||
tv_list_free_contents(l);
|
||||
tv_list_free_list(l);
|
||||
}
|
||||
}
|
||||
|
||||
/// Unreference a list
|
||||
///
|
||||
|
@ -403,7 +403,10 @@ int name_to_mod_mask(int c)
|
||||
int simplify_key(const int key, int *modifiers)
|
||||
FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
if (*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT)) {
|
||||
if (!(*modifiers & (MOD_MASK_SHIFT | MOD_MASK_CTRL | MOD_MASK_ALT))) {
|
||||
return key;
|
||||
}
|
||||
|
||||
// TAB is a special case.
|
||||
if (key == TAB && (*modifiers & MOD_MASK_SHIFT)) {
|
||||
*modifiers &= ~MOD_MASK_SHIFT;
|
||||
@ -420,7 +423,6 @@ int simplify_key(const int key, int *modifiers)
|
||||
modifier_keys_table[i + 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
|
@ -317,24 +317,27 @@ static char **find_locales(void)
|
||||
static void init_locales(void)
|
||||
{
|
||||
# ifndef MSWIN
|
||||
if (!did_init_locales) {
|
||||
if (did_init_locales) {
|
||||
return;
|
||||
}
|
||||
|
||||
did_init_locales = true;
|
||||
locales = find_locales();
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
# if defined(EXITFREE)
|
||||
void free_locales(void)
|
||||
{
|
||||
int i;
|
||||
if (locales != NULL) {
|
||||
for (i = 0; locales[i] != NULL; i++) {
|
||||
if (locales == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; locales[i] != NULL; i++) {
|
||||
xfree(locales[i]);
|
||||
}
|
||||
XFREE_CLEAR(locales);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
/// Function given to ExpandGeneric() to obtain the possible arguments of the
|
||||
|
@ -1828,7 +1828,10 @@ static void exe_pre_commands(mparm_T *parmp)
|
||||
int cnt = parmp->n_pre_commands;
|
||||
int i;
|
||||
|
||||
if (cnt > 0) {
|
||||
if (cnt <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
curwin->w_cursor.lnum = 0; // just in case..
|
||||
estack_push(ETYPE_ARGS, _("pre-vimrc command line"), 0);
|
||||
current_sctx.sc_sid = SID_CMDARG;
|
||||
@ -1839,7 +1842,6 @@ static void exe_pre_commands(mparm_T *parmp)
|
||||
current_sctx.sc_sid = 0;
|
||||
TIME_MSG("--cmd commands");
|
||||
}
|
||||
}
|
||||
|
||||
// Execute "+", "-c" and "-S" arguments.
|
||||
static void exe_commands(mparm_T *parmp)
|
||||
@ -2079,7 +2081,10 @@ static int execute_env(char *env)
|
||||
FUNC_ATTR_NONNULL_ALL
|
||||
{
|
||||
const char *initstr = os_getenv(env);
|
||||
if (initstr != NULL) {
|
||||
if (initstr == NULL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
estack_push(ETYPE_ENV, env, 0);
|
||||
const sctx_T save_current_sctx = current_sctx;
|
||||
current_sctx.sc_sid = SID_ENV;
|
||||
@ -2091,8 +2096,6 @@ static int execute_env(char *env)
|
||||
current_sctx = save_current_sctx;
|
||||
return OK;
|
||||
}
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
/// Prints the following then exits:
|
||||
/// - An error message `errstr`
|
||||
|
@ -653,7 +653,10 @@ fmark_T *getnextmark(pos_T *startpos, int dir, int begin_line)
|
||||
// until the mark is used to avoid a long startup delay.
|
||||
static void fname2fnum(xfmark_T *fm)
|
||||
{
|
||||
if (fm->fname != NULL) {
|
||||
if (fm->fname == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// First expand "~/" in the file name to the home directory.
|
||||
// Don't expand the whole name, it may contain other '~' chars.
|
||||
#ifdef BACKSLASH_IN_FILENAME
|
||||
@ -676,7 +679,6 @@ static void fname2fnum(xfmark_T *fm)
|
||||
// buflist_new() will call fmarks_check_names()
|
||||
(void)buflist_new(NameBuff, p, (linenr_T)1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Check all file marks for a name that matches the file name in buf.
|
||||
// May replace the name with an fnum.
|
||||
|
@ -880,13 +880,15 @@ static int matchadd_dict_arg(typval_T *tv, const char **conceal_char, win_T **wi
|
||||
*conceal_char = tv_get_string(&di->di_tv);
|
||||
}
|
||||
|
||||
if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("window"))) != NULL) {
|
||||
if ((di = tv_dict_find(tv->vval.v_dict, S_LEN("window"))) == NULL) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
*win = find_win_by_nr_or_id(&di->di_tv);
|
||||
if (*win == NULL) {
|
||||
emsg(_(e_invalwindow));
|
||||
return FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -767,12 +767,14 @@ void mf_set_fnames(memfile_T *mfp, char *fname)
|
||||
/// Used before doing a :cd
|
||||
void mf_fullname(memfile_T *mfp)
|
||||
{
|
||||
if (mfp != NULL && mfp->mf_fname != NULL && mfp->mf_ffname != NULL) {
|
||||
if (mfp == NULL || mfp->mf_fname == NULL || mfp->mf_ffname == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xfree(mfp->mf_fname);
|
||||
mfp->mf_fname = mfp->mf_ffname;
|
||||
mfp->mf_ffname = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/// Return true if there are any translations pending for memfile.
|
||||
bool mf_need_trans(memfile_T *mfp)
|
||||
|
@ -1377,7 +1377,10 @@ char *make_percent_swname(const char *dir, const char *name)
|
||||
{
|
||||
char *d = NULL;
|
||||
char *f = fix_fname(name != NULL ? name : "");
|
||||
if (f != NULL) {
|
||||
if (f == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *s = xstrdup(f);
|
||||
for (d = s; *d != NUL; MB_PTR_ADV(d)) {
|
||||
if (vim_ispathsep(*d)) {
|
||||
@ -1387,7 +1390,6 @@ char *make_percent_swname(const char *dir, const char *name)
|
||||
d = concat_fnames(dir, s, true);
|
||||
xfree(s);
|
||||
xfree(f);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
|
@ -1449,9 +1449,11 @@ void show_popupmenu(void)
|
||||
}
|
||||
|
||||
// Only show a popup when it is defined and has entries
|
||||
if (menu != NULL && menu->children != NULL) {
|
||||
pum_show_popupmenu(menu);
|
||||
if (menu == NULL || menu->children == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
pum_show_popupmenu(menu);
|
||||
}
|
||||
|
||||
/// Execute "menu". Use by ":emenu" and the window toolbar.
|
||||
|
@ -606,30 +606,40 @@ void validate_virtcol(void)
|
||||
void validate_virtcol_win(win_T *wp)
|
||||
{
|
||||
check_cursor_moved(wp);
|
||||
if (!(wp->w_valid & VALID_VIRTCOL)) {
|
||||
|
||||
if (wp->w_valid & VALID_VIRTCOL) {
|
||||
return;
|
||||
}
|
||||
|
||||
getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL);
|
||||
redraw_for_cursorcolumn(wp);
|
||||
wp->w_valid |= VALID_VIRTCOL;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate curwin->w_cline_height only.
|
||||
void validate_cheight(void)
|
||||
{
|
||||
check_cursor_moved(curwin);
|
||||
if (!(curwin->w_valid & VALID_CHEIGHT)) {
|
||||
|
||||
if (curwin->w_valid & VALID_CHEIGHT) {
|
||||
return;
|
||||
}
|
||||
|
||||
curwin->w_cline_height = plines_win_full(curwin, curwin->w_cursor.lnum,
|
||||
NULL, &curwin->w_cline_folded,
|
||||
true);
|
||||
curwin->w_valid |= VALID_CHEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate w_wcol and w_virtcol only.
|
||||
void validate_cursor_col(void)
|
||||
{
|
||||
validate_virtcol();
|
||||
if (!(curwin->w_valid & VALID_WCOL)) {
|
||||
|
||||
if (curwin->w_valid & VALID_WCOL) {
|
||||
return;
|
||||
}
|
||||
|
||||
colnr_T col = curwin->w_virtcol;
|
||||
colnr_T off = curwin_col_off();
|
||||
col += off;
|
||||
@ -650,7 +660,6 @@ void validate_cursor_col(void)
|
||||
|
||||
curwin->w_valid |= VALID_WCOL;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute offset of a window, occupied by absolute or relative line number,
|
||||
// fold column and sign column (these don't move when scrolling horizontally).
|
||||
|
@ -292,7 +292,10 @@ void vim_beep(unsigned val)
|
||||
{
|
||||
called_vim_beep = true;
|
||||
|
||||
if (emsg_silent == 0 && !in_assert_fails) {
|
||||
if (emsg_silent != 0 || in_assert_fails) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!((bo_flags & val) || (bo_flags & BO_ALL))) {
|
||||
static int beeps = 0;
|
||||
static uint64_t start_time = 0;
|
||||
@ -321,7 +324,6 @@ void vim_beep(unsigned val)
|
||||
msg_attr(_("Beep!"), HL_ATTR(HLF_W));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ui_attach_impl(UI *ui, uint64_t chanid)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user