aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ex_cmds2.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-12-31 06:41:23 +0800
committerGitHub <noreply@github.com>2022-12-31 06:41:23 +0800
commit99cf111289bfcd14981255e805da43bac5139141 (patch)
tree54e0f84d10b39603e20c841174585af69cb8f54c /src/nvim/ex_cmds2.c
parent6a45360de99b1a7d0d3d9ca1060d5212717c7578 (diff)
downloadrneovim-99cf111289bfcd14981255e805da43bac5139141.tar.gz
rneovim-99cf111289bfcd14981255e805da43bac5139141.tar.bz2
rneovim-99cf111289bfcd14981255e805da43bac5139141.zip
vim-patch:9.0.1115: code is indented more than needed (#21598)
Problem: Code is indented more than needed. Solution: Use an early return to reduce indenting. (Yegappan Lakshmanan, closes vim/vim#11758) https://github.com/vim/vim/commit/ed0c1d5d4b30d03b26ff08841f6da2ddf44025a7 Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'src/nvim/ex_cmds2.c')
-rw-r--r--src/nvim/ex_cmds2.c153
1 files changed, 78 insertions, 75 deletions
diff --git a/src/nvim/ex_cmds2.c b/src/nvim/ex_cmds2.c
index b6489e97b2..7020747cf6 100644
--- a/src/nvim/ex_cmds2.c
+++ b/src/nvim/ex_cmds2.c
@@ -705,54 +705,56 @@ void ex_compiler(exarg_T *eap)
// List all compiler scripts.
do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.vim')"); // NOLINT
do_cmdline_cmd("echo globpath(&rtp, 'compiler/*.lua')"); // NOLINT
+ return;
+ }
+
+ size_t bufsize = strlen(eap->arg) + 14;
+ buf = xmalloc(bufsize);
+
+ if (eap->forceit) {
+ // ":compiler! {name}" sets global options
+ do_cmdline_cmd("command -nargs=* CompilerSet set <args>");
} else {
- size_t bufsize = strlen(eap->arg) + 14;
- buf = xmalloc(bufsize);
- if (eap->forceit) {
- // ":compiler! {name}" sets global options
- do_cmdline_cmd("command -nargs=* CompilerSet set <args>");
- } else {
- // ":compiler! {name}" sets local options.
- // To remain backwards compatible "current_compiler" is always
- // used. A user's compiler plugin may set it, the distributed
- // plugin will then skip the settings. Afterwards set
- // "b:current_compiler" and restore "current_compiler".
- // Explicitly prepend "g:" to make it work in a function.
- old_cur_comp = (char *)get_var_value("g:current_compiler");
- if (old_cur_comp != NULL) {
- old_cur_comp = xstrdup(old_cur_comp);
- }
- do_cmdline_cmd("command -nargs=* -keepscript CompilerSet setlocal <args>");
+ // ":compiler! {name}" sets local options.
+ // To remain backwards compatible "current_compiler" is always
+ // used. A user's compiler plugin may set it, the distributed
+ // plugin will then skip the settings. Afterwards set
+ // "b:current_compiler" and restore "current_compiler".
+ // Explicitly prepend "g:" to make it work in a function.
+ old_cur_comp = (char *)get_var_value("g:current_compiler");
+ if (old_cur_comp != NULL) {
+ old_cur_comp = xstrdup(old_cur_comp);
}
- do_unlet(S_LEN("g:current_compiler"), true);
- do_unlet(S_LEN("b:current_compiler"), true);
+ do_cmdline_cmd("command -nargs=* -keepscript CompilerSet setlocal <args>");
+ }
+ do_unlet(S_LEN("g:current_compiler"), true);
+ do_unlet(S_LEN("b:current_compiler"), true);
- snprintf(buf, bufsize, "compiler/%s.vim", eap->arg);
+ snprintf(buf, bufsize, "compiler/%s.vim", eap->arg);
+ if (source_runtime(buf, DIP_ALL) == FAIL) {
+ // Try lua compiler
+ snprintf(buf, bufsize, "compiler/%s.lua", eap->arg);
if (source_runtime(buf, DIP_ALL) == FAIL) {
- // Try lua compiler
- snprintf(buf, bufsize, "compiler/%s.lua", eap->arg);
- if (source_runtime(buf, DIP_ALL) == FAIL) {
- semsg(_("E666: compiler not supported: %s"), eap->arg);
- }
+ semsg(_("E666: compiler not supported: %s"), eap->arg);
}
- xfree(buf);
+ }
+ xfree(buf);
- do_cmdline_cmd(":delcommand CompilerSet");
+ do_cmdline_cmd(":delcommand CompilerSet");
- // Set "b:current_compiler" from "current_compiler".
- p = (char *)get_var_value("g:current_compiler");
- if (p != NULL) {
- set_internal_string_var("b:current_compiler", p);
- }
+ // Set "b:current_compiler" from "current_compiler".
+ p = (char *)get_var_value("g:current_compiler");
+ if (p != NULL) {
+ set_internal_string_var("b:current_compiler", p);
+ }
- // Restore "current_compiler" for ":compiler {name}".
- if (!eap->forceit) {
- if (old_cur_comp != NULL) {
- set_internal_string_var("g:current_compiler", old_cur_comp);
- xfree(old_cur_comp);
- } else {
- do_unlet(S_LEN("g:current_compiler"), true);
- }
+ // Restore "current_compiler" for ":compiler {name}".
+ if (!eap->forceit) {
+ if (old_cur_comp != NULL) {
+ set_internal_string_var("g:current_compiler", old_cur_comp);
+ xfree(old_cur_comp);
+ } else {
+ do_unlet(S_LEN("g:current_compiler"), true);
}
}
}
@@ -847,45 +849,46 @@ void ex_drop(exarg_T *eap)
// edited in a window yet. It's like ":tab all" but without closing
// windows or tabs.
ex_all(eap);
- } else {
- // ":drop file ...": Edit the first argument. Jump to an existing
- // window if possible, edit in current window if the current buffer
- // can be abandoned, otherwise open a new window.
- buf = buflist_findnr(ARGLIST[0].ae_fnum);
+ return;
+ }
- FOR_ALL_TAB_WINDOWS(tp, wp) {
- if (wp->w_buffer == buf) {
- goto_tabpage_win(tp, wp);
- curwin->w_arg_idx = 0;
- if (!bufIsChanged(curbuf)) {
- const int save_ar = curbuf->b_p_ar;
-
- // reload the file if it is newer
- curbuf->b_p_ar = 1;
- buf_check_timestamp(curbuf);
- curbuf->b_p_ar = save_ar;
- }
- return;
+ // ":drop file ...": Edit the first argument. Jump to an existing
+ // window if possible, edit in current window if the current buffer
+ // can be abandoned, otherwise open a new window.
+ buf = buflist_findnr(ARGLIST[0].ae_fnum);
+
+ FOR_ALL_TAB_WINDOWS(tp, wp) {
+ if (wp->w_buffer == buf) {
+ goto_tabpage_win(tp, wp);
+ curwin->w_arg_idx = 0;
+ if (!bufIsChanged(curbuf)) {
+ const int save_ar = curbuf->b_p_ar;
+
+ // reload the file if it is newer
+ curbuf->b_p_ar = 1;
+ buf_check_timestamp(curbuf);
+ curbuf->b_p_ar = save_ar;
}
+ return;
}
+ }
- // Check whether the current buffer is changed. If so, we will need
- // to split the current window or data could be lost.
- // Skip the check if the 'hidden' option is set, as in this case the
- // buffer won't be lost.
- if (!buf_hide(curbuf)) {
- emsg_off++;
- split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD);
- emsg_off--;
- }
+ // Check whether the current buffer is changed. If so, we will need
+ // to split the current window or data could be lost.
+ // Skip the check if the 'hidden' option is set, as in this case the
+ // buffer won't be lost.
+ if (!buf_hide(curbuf)) {
+ emsg_off++;
+ split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD);
+ emsg_off--;
+ }
- // Fake a ":sfirst" or ":first" command edit the first argument.
- if (split) {
- eap->cmdidx = CMD_sfirst;
- eap->cmd[0] = 's';
- } else {
- eap->cmdidx = CMD_first;
- }
- ex_rewind(eap);
+ // Fake a ":sfirst" or ":first" command edit the first argument.
+ if (split) {
+ eap->cmdidx = CMD_sfirst;
+ eap->cmd[0] = 's';
+ } else {
+ eap->cmdidx = CMD_first;
}
+ ex_rewind(eap);
}