Skip to content

Commit dc4daa3

Browse files
yegappanbrammool
authored andcommitted
patch 9.0.1132: code is indented more than needed
Problem: Code is indented more than needed. Solution: Use an early return to reduce indentation. (Yegappan Lakshmanan, closes vim#11769)
1 parent a2942c7 commit dc4daa3

File tree

13 files changed

+629
-624
lines changed

13 files changed

+629
-624
lines changed

src/arglist.c

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -693,56 +693,56 @@ do_argfile(exarg_T *eap, int argn)
693693
emsg(_(e_cannot_go_before_first_file));
694694
else
695695
emsg(_(e_cannot_go_beyond_last_file));
696+
697+
return;
696698
}
697-
else
698-
{
699-
setpcmark();
699+
700+
setpcmark();
700701
#ifdef FEAT_GUI
701-
need_mouse_correct = TRUE;
702+
need_mouse_correct = TRUE;
702703
#endif
703704

704-
// split window or create new tab page first
705-
if (*eap->cmd == 's' || cmdmod.cmod_tab != 0)
706-
{
707-
if (win_split(0, 0) == FAIL)
708-
return;
709-
RESET_BINDING(curwin);
710-
}
711-
else
705+
// split window or create new tab page first
706+
if (*eap->cmd == 's' || cmdmod.cmod_tab != 0)
707+
{
708+
if (win_split(0, 0) == FAIL)
709+
return;
710+
RESET_BINDING(curwin);
711+
}
712+
else
713+
{
714+
// if 'hidden' set, only check for changed file when re-editing
715+
// the same buffer
716+
other = TRUE;
717+
if (buf_hide(curbuf))
712718
{
713-
// if 'hidden' set, only check for changed file when re-editing
714-
// the same buffer
715-
other = TRUE;
716-
if (buf_hide(curbuf))
717-
{
718-
p = fix_fname(alist_name(&ARGLIST[argn]));
719-
other = otherfile(p);
720-
vim_free(p);
721-
}
722-
if ((!buf_hide(curbuf) || !other)
723-
&& check_changed(curbuf, CCGD_AW
724-
| (other ? 0 : CCGD_MULTWIN)
725-
| (eap->forceit ? CCGD_FORCEIT : 0)
726-
| CCGD_EXCMD))
727-
return;
719+
p = fix_fname(alist_name(&ARGLIST[argn]));
720+
other = otherfile(p);
721+
vim_free(p);
728722
}
729-
730-
curwin->w_arg_idx = argn;
731-
if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist)
732-
arg_had_last = TRUE;
733-
734-
// Edit the file; always use the last known line number.
735-
// When it fails (e.g. Abort for already edited file) restore the
736-
// argument index.
737-
if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
738-
eap, ECMD_LAST,
739-
(buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0)
740-
+ (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
741-
curwin->w_arg_idx = old_arg_idx;
742-
// like Vi: set the mark where the cursor is in the file.
743-
else if (eap->cmdidx != CMD_argdo)
744-
setmark('\'');
723+
if ((!buf_hide(curbuf) || !other)
724+
&& check_changed(curbuf, CCGD_AW
725+
| (other ? 0 : CCGD_MULTWIN)
726+
| (eap->forceit ? CCGD_FORCEIT : 0)
727+
| CCGD_EXCMD))
728+
return;
745729
}
730+
731+
curwin->w_arg_idx = argn;
732+
if (argn == ARGCOUNT - 1 && curwin->w_alist == &global_alist)
733+
arg_had_last = TRUE;
734+
735+
// Edit the file; always use the last known line number.
736+
// When it fails (e.g. Abort for already edited file) restore the
737+
// argument index.
738+
if (do_ecmd(0, alist_name(&ARGLIST[curwin->w_arg_idx]), NULL,
739+
eap, ECMD_LAST,
740+
(buf_hide(curwin->w_buffer) ? ECMD_HIDE : 0)
741+
+ (eap->forceit ? ECMD_FORCEIT : 0), curwin) == FAIL)
742+
curwin->w_arg_idx = old_arg_idx;
743+
// like Vi: set the mark where the cursor is in the file.
744+
else if (eap->cmdidx != CMD_argdo)
745+
setmark('\'');
746746
}
747747

748748
/*

src/buffer.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,19 @@ read_buffer(
146146
void
147147
buffer_ensure_loaded(buf_T *buf)
148148
{
149-
if (buf->b_ml.ml_mfp == NULL)
150-
{
151-
aco_save_T aco;
149+
if (buf->b_ml.ml_mfp != NULL)
150+
return;
152151

153-
// Make sure the buffer is in a window. If not then skip it.
154-
aucmd_prepbuf(&aco, buf);
155-
if (curbuf == buf)
156-
{
157-
if (swap_exists_action != SEA_READONLY)
158-
swap_exists_action = SEA_NONE;
159-
open_buffer(FALSE, NULL, 0);
160-
aucmd_restbuf(&aco);
161-
}
152+
aco_save_T aco;
153+
154+
// Make sure the buffer is in a window. If not then skip it.
155+
aucmd_prepbuf(&aco, buf);
156+
if (curbuf == buf)
157+
{
158+
if (swap_exists_action != SEA_READONLY)
159+
swap_exists_action = SEA_NONE;
160+
open_buffer(FALSE, NULL, 0);
161+
aucmd_restbuf(&aco);
162162
}
163163
}
164164
#endif
@@ -3582,18 +3582,18 @@ buf_set_name(int fnum, char_u *name)
35823582
buf_T *buf;
35833583

35843584
buf = buflist_findnr(fnum);
3585-
if (buf != NULL)
3586-
{
3587-
if (buf->b_sfname != buf->b_ffname)
3588-
vim_free(buf->b_sfname);
3589-
vim_free(buf->b_ffname);
3590-
buf->b_ffname = vim_strsave(name);
3591-
buf->b_sfname = NULL;
3592-
// Allocate ffname and expand into full path. Also resolves .lnk
3593-
// files on Win32.
3594-
fname_expand(buf, &buf->b_ffname, &buf->b_sfname);
3595-
buf->b_fname = buf->b_sfname;
3596-
}
3585+
if (buf == NULL)
3586+
return;
3587+
3588+
if (buf->b_sfname != buf->b_ffname)
3589+
vim_free(buf->b_sfname);
3590+
vim_free(buf->b_ffname);
3591+
buf->b_ffname = vim_strsave(name);
3592+
buf->b_sfname = NULL;
3593+
// Allocate ffname and expand into full path. Also resolves .lnk
3594+
// files on Win32.
3595+
fname_expand(buf, &buf->b_ffname, &buf->b_sfname);
3596+
buf->b_fname = buf->b_sfname;
35973597
}
35983598

35993599
/*
@@ -5921,14 +5921,14 @@ buf_get_fname(buf_T *buf)
59215921
void
59225922
set_buflisted(int on)
59235923
{
5924-
if (on != curbuf->b_p_bl)
5925-
{
5926-
curbuf->b_p_bl = on;
5927-
if (on)
5928-
apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf);
5929-
else
5930-
apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
5931-
}
5924+
if (on == curbuf->b_p_bl)
5925+
return;
5926+
5927+
curbuf->b_p_bl = on;
5928+
if (on)
5929+
apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf);
5930+
else
5931+
apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf);
59325932
}
59335933

59345934
/*

src/clientserver.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -191,38 +191,38 @@ static char_u *build_drop_cmd(int filec, char **filev, int tabs, int sendReply);
191191
void
192192
exec_on_server(mparm_T *parmp)
193193
{
194-
if (parmp->serverName_arg == NULL || *parmp->serverName_arg != NUL)
195-
{
194+
if (parmp->serverName_arg != NULL && *parmp->serverName_arg == NUL)
195+
return;
196+
196197
# ifdef MSWIN
197-
// Initialise the client/server messaging infrastructure.
198-
serverInitMessaging();
198+
// Initialise the client/server messaging infrastructure.
199+
serverInitMessaging();
199200
# endif
200201

201-
/*
202-
* When a command server argument was found, execute it. This may
203-
* exit Vim when it was successful. Otherwise it's executed further
204-
* on. Remember the encoding used here in "serverStrEnc".
205-
*/
206-
if (parmp->serverArg)
207-
{
208-
cmdsrv_main(&parmp->argc, parmp->argv,
209-
parmp->serverName_arg, &parmp->serverStr);
210-
parmp->serverStrEnc = vim_strsave(p_enc);
211-
}
202+
/*
203+
* When a command server argument was found, execute it. This may
204+
* exit Vim when it was successful. Otherwise it's executed further
205+
* on. Remember the encoding used here in "serverStrEnc".
206+
*/
207+
if (parmp->serverArg)
208+
{
209+
cmdsrv_main(&parmp->argc, parmp->argv,
210+
parmp->serverName_arg, &parmp->serverStr);
211+
parmp->serverStrEnc = vim_strsave(p_enc);
212+
}
212213

213-
// If we're still running, get the name to register ourselves.
214-
// On Win32 can register right now, for X11 need to setup the
215-
// clipboard first, it's further down.
216-
parmp->servername = serverMakeName(parmp->serverName_arg,
217-
parmp->argv[0]);
214+
// If we're still running, get the name to register ourselves.
215+
// On Win32 can register right now, for X11 need to setup the
216+
// clipboard first, it's further down.
217+
parmp->servername = serverMakeName(parmp->serverName_arg,
218+
parmp->argv[0]);
218219
# ifdef MSWIN
219-
if (parmp->servername != NULL)
220-
{
221-
serverSetName(parmp->servername);
222-
vim_free(parmp->servername);
223-
}
224-
# endif
220+
if (parmp->servername != NULL)
221+
{
222+
serverSetName(parmp->servername);
223+
vim_free(parmp->servername);
225224
}
225+
# endif
226226
}
227227

228228
/*

0 commit comments

Comments
 (0)