From 1cfb14aa972ccf3235ac67f07b7db1175b7c5384 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Mon, 9 Jan 2023 19:04:23 +0000 Subject: patch 9.0.1166: 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 #11792) --- src/buffer.c | 114 +++++++++++++++++++++++++++++------------------------------ 1 file changed, 56 insertions(+), 58 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 4016822616..a3de68df29 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -357,34 +357,34 @@ open_buffer( apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); #endif - if (retval == OK) + if (retval != OK) + return retval; + + // The autocommands may have changed the current buffer. Apply the + // modelines to the correct buffer, if it still exists and is loaded. + if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) { - // The autocommands may have changed the current buffer. Apply the - // modelines to the correct buffer, if it still exists and is loaded. - if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) - { - aco_save_T aco; + aco_save_T aco; - // Go to the buffer that was opened, make sure it is in a window. - // If not then skip it. - aucmd_prepbuf(&aco, old_curbuf.br_buf); - if (curbuf == old_curbuf.br_buf) - { - do_modelines(0); - curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); + // Go to the buffer that was opened, make sure it is in a window. + // If not then skip it. + aucmd_prepbuf(&aco, old_curbuf.br_buf); + if (curbuf == old_curbuf.br_buf) + { + do_modelines(0); + curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); - if ((flags & READ_NOWINENTER) == 0) + if ((flags & READ_NOWINENTER) == 0) #ifdef FEAT_EVAL - apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, - FALSE, curbuf, &retval); + apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, + FALSE, curbuf, &retval); #else - apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, - FALSE, curbuf); + apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, + FALSE, curbuf); #endif - // restore curwin/curbuf and a few other things - aucmd_restbuf(&aco); - } + // restore curwin/curbuf and a few other things + aucmd_restbuf(&aco); } } @@ -1761,7 +1761,6 @@ do_bufdel( } } - return errormsg; } @@ -3019,20 +3018,20 @@ fname_match( char_u *p; // extra check for valid arguments - if (name != NULL && rmp->regprog != NULL) + if (name == NULL || rmp->regprog == NULL) + return NULL; + + // Ignore case when 'fileignorecase' or the argument is set. + rmp->rm_ic = p_fic || ignore_case; + if (vim_regexec(rmp, name, (colnr_T)0)) + match = name; + else if (rmp->regprog != NULL) { - // Ignore case when 'fileignorecase' or the argument is set. - rmp->rm_ic = p_fic || ignore_case; - if (vim_regexec(rmp, name, (colnr_T)0)) + // Replace $(HOME) with '~' and try matching again. + p = home_replace_save(NULL, name); + if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) match = name; - else if (rmp->regprog != NULL) - { - // Replace $(HOME) with '~' and try matching again. - p = home_replace_save(NULL, name); - if (p != NULL && vim_regexec(rmp, p, (colnr_T)0)) - match = name; - vim_free(p); - } + vim_free(p); } return match; @@ -3160,16 +3159,15 @@ wininfo_other_tab_diff(wininfo_T *wip) { win_T *wp; - if (wip->wi_opt.wo_diff) - { - FOR_ALL_WINDOWS(wp) - // return FALSE when it's a window in the current tab page, thus - // the buffer was in diff mode here - if (wip->wi_win == wp) - return FALSE; - return TRUE; - } - return FALSE; + if (!wip->wi_opt.wo_diff) + return FALSE; + + FOR_ALL_WINDOWS(wp) + // return FALSE when it's a window in the current tab page, thus + // the buffer was in diff mode here + if (wip->wi_win == wp) + return FALSE; + return TRUE; } #endif @@ -3198,27 +3196,27 @@ find_wininfo( && (!need_options || wip->wi_optset)) break; + if (wip != NULL) + return wip; + // If no wininfo for curwin, use the first in the list (that doesn't have // 'diff' set and is in another tab page). // If "need_options" is TRUE skip entries that don't have options set, // unless the window is editing "buf", so we can copy from the window // itself. - if (wip == NULL) - { #ifdef FEAT_DIFF - if (skip_diff_buffer) - { - FOR_ALL_BUF_WININFO(buf, wip) - if (!wininfo_other_tab_diff(wip) - && (!need_options || wip->wi_optset - || (wip->wi_win != NULL - && wip->wi_win->w_buffer == buf))) - break; - } - else -#endif - wip = buf->b_wininfo; + if (skip_diff_buffer) + { + FOR_ALL_BUF_WININFO(buf, wip) + if (!wininfo_other_tab_diff(wip) + && (!need_options || wip->wi_optset + || (wip->wi_win != NULL + && wip->wi_win->w_buffer == buf))) + break; } + else +#endif + wip = buf->b_wininfo; return wip; } -- cgit v1.2.3