mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 8.1.0438: the ex_make() function is too long
Problem: The ex_make() function is too long. Solution: Split it into several functions. (Yegappan Lakshmanan)
This commit is contained in:
parent
95892c27b2
commit
b434ae2a1f
247
src/quickfix.c
247
src/quickfix.c
@ -148,7 +148,6 @@ static win_T *qf_find_win(qf_info_T *qi);
|
||||
static buf_T *qf_find_buf(qf_info_T *qi);
|
||||
static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last);
|
||||
static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last);
|
||||
static char_u *get_mef_name(void);
|
||||
static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir);
|
||||
static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start);
|
||||
static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start);
|
||||
@ -4480,119 +4479,21 @@ grep_internal(cmdidx_T cmdidx)
|
||||
}
|
||||
|
||||
/*
|
||||
* Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd"
|
||||
* Return the make/grep autocmd name.
|
||||
*/
|
||||
void
|
||||
ex_make(exarg_T *eap)
|
||||
static char_u *
|
||||
make_get_auname(cmdidx_T cmdidx)
|
||||
{
|
||||
char_u *fname;
|
||||
char_u *cmd;
|
||||
char_u *enc = NULL;
|
||||
unsigned len;
|
||||
win_T *wp = NULL;
|
||||
qf_info_T *qi = &ql_info;
|
||||
int res;
|
||||
char_u *au_name = NULL;
|
||||
int_u save_qfid;
|
||||
|
||||
/* Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal". */
|
||||
if (grep_internal(eap->cmdidx))
|
||||
switch (cmdidx)
|
||||
{
|
||||
ex_vimgrep(eap);
|
||||
return;
|
||||
case CMD_make: return (char_u *)"make";
|
||||
case CMD_lmake: return (char_u *)"lmake";
|
||||
case CMD_grep: return (char_u *)"grep";
|
||||
case CMD_lgrep: return (char_u *)"lgrep";
|
||||
case CMD_grepadd: return (char_u *)"grepadd";
|
||||
case CMD_lgrepadd: return (char_u *)"lgrepadd";
|
||||
default: return NULL;
|
||||
}
|
||||
|
||||
switch (eap->cmdidx)
|
||||
{
|
||||
case CMD_make: au_name = (char_u *)"make"; break;
|
||||
case CMD_lmake: au_name = (char_u *)"lmake"; break;
|
||||
case CMD_grep: au_name = (char_u *)"grep"; break;
|
||||
case CMD_lgrep: au_name = (char_u *)"lgrep"; break;
|
||||
case CMD_grepadd: au_name = (char_u *)"grepadd"; break;
|
||||
case CMD_lgrepadd: au_name = (char_u *)"lgrepadd"; break;
|
||||
default: break;
|
||||
}
|
||||
if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
|
||||
curbuf->b_fname, TRUE, curbuf))
|
||||
{
|
||||
#ifdef FEAT_EVAL
|
||||
if (aborting())
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
#ifdef FEAT_MBYTE
|
||||
enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc;
|
||||
#endif
|
||||
|
||||
if (is_loclist_cmd(eap->cmdidx))
|
||||
wp = curwin;
|
||||
|
||||
autowrite_all();
|
||||
fname = get_mef_name();
|
||||
if (fname == NULL)
|
||||
return;
|
||||
mch_remove(fname); /* in case it's not unique */
|
||||
|
||||
/*
|
||||
* If 'shellpipe' empty: don't redirect to 'errorfile'.
|
||||
*/
|
||||
len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(eap->arg) + 1;
|
||||
if (*p_sp != NUL)
|
||||
len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3;
|
||||
cmd = alloc(len);
|
||||
if (cmd == NULL)
|
||||
return;
|
||||
sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)eap->arg,
|
||||
(char *)p_shq);
|
||||
if (*p_sp != NUL)
|
||||
append_redir(cmd, len, p_sp, fname);
|
||||
/*
|
||||
* Output a newline if there's something else than the :make command that
|
||||
* was typed (in which case the cursor is in column 0).
|
||||
*/
|
||||
if (msg_col == 0)
|
||||
msg_didout = FALSE;
|
||||
msg_start();
|
||||
MSG_PUTS(":!");
|
||||
msg_outtrans(cmd); /* show what we are doing */
|
||||
|
||||
/* let the shell know if we are redirecting output or not */
|
||||
do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0);
|
||||
|
||||
#ifdef AMIGA
|
||||
out_flush();
|
||||
/* read window status report and redraw before message */
|
||||
(void)char_avail();
|
||||
#endif
|
||||
|
||||
res = qf_init(wp, fname, (eap->cmdidx != CMD_make
|
||||
&& eap->cmdidx != CMD_lmake) ? p_gefm : p_efm,
|
||||
(eap->cmdidx != CMD_grepadd
|
||||
&& eap->cmdidx != CMD_lgrepadd),
|
||||
qf_cmdtitle(*eap->cmdlinep), enc);
|
||||
if (wp != NULL)
|
||||
{
|
||||
qi = GET_LOC_LIST(wp);
|
||||
if (qi == NULL)
|
||||
goto cleanup;
|
||||
}
|
||||
if (res >= 0)
|
||||
qf_list_changed(qi, qi->qf_curlist);
|
||||
|
||||
// Remember the current quickfix list identifier, so that we can
|
||||
// check for autocommands changing the current quickfix list.
|
||||
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
|
||||
if (au_name != NULL)
|
||||
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
|
||||
curbuf->b_fname, TRUE, curbuf);
|
||||
if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid))
|
||||
// display the first error
|
||||
qf_jump_first(qi, save_qfid, FALSE);
|
||||
|
||||
cleanup:
|
||||
mch_remove(fname);
|
||||
vim_free(fname);
|
||||
vim_free(cmd);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -4626,7 +4527,7 @@ get_mef_name(void)
|
||||
if (*p == NUL)
|
||||
return vim_strsave(p_mef);
|
||||
|
||||
/* Keep trying until the name doesn't exist yet. */
|
||||
// Keep trying until the name doesn't exist yet.
|
||||
for (;;)
|
||||
{
|
||||
if (start == -1)
|
||||
@ -4642,7 +4543,7 @@ get_mef_name(void)
|
||||
STRCAT(name, p + 2);
|
||||
if (mch_getperm(name) < 0
|
||||
#ifdef HAVE_LSTAT
|
||||
/* Don't accept a symbolic link, it's a security risk. */
|
||||
// Don't accept a symbolic link, it's a security risk.
|
||||
&& mch_lstat((char *)name, &sb) < 0
|
||||
#endif
|
||||
)
|
||||
@ -4652,6 +4553,128 @@ get_mef_name(void)
|
||||
return name;
|
||||
}
|
||||
|
||||
/*
|
||||
* Form the complete command line to invoke 'make'/'grep'. Quote the command
|
||||
* using 'shellquote' and append 'shellpipe'. Echo the fully formed command.
|
||||
*/
|
||||
static char_u *
|
||||
make_get_fullcmd(char_u *makecmd, char_u *fname)
|
||||
{
|
||||
char_u *cmd;
|
||||
unsigned len;
|
||||
|
||||
len = (unsigned)STRLEN(p_shq) * 2 + (unsigned)STRLEN(makecmd) + 1;
|
||||
if (*p_sp != NUL)
|
||||
len += (unsigned)STRLEN(p_sp) + (unsigned)STRLEN(fname) + 3;
|
||||
cmd = alloc(len);
|
||||
if (cmd == NULL)
|
||||
return NULL;
|
||||
sprintf((char *)cmd, "%s%s%s", (char *)p_shq, (char *)makecmd,
|
||||
(char *)p_shq);
|
||||
|
||||
// If 'shellpipe' empty: don't redirect to 'errorfile'.
|
||||
if (*p_sp != NUL)
|
||||
append_redir(cmd, len, p_sp, fname);
|
||||
|
||||
// Display the fully formed command. Output a newline if there's something
|
||||
// else than the :make command that was typed (in which case the cursor is
|
||||
// in column 0).
|
||||
if (msg_col == 0)
|
||||
msg_didout = FALSE;
|
||||
msg_start();
|
||||
MSG_PUTS(":!");
|
||||
msg_outtrans(cmd); // show what we are doing
|
||||
|
||||
return cmd;
|
||||
}
|
||||
|
||||
/*
|
||||
* Used for ":make", ":lmake", ":grep", ":lgrep", ":grepadd", and ":lgrepadd"
|
||||
*/
|
||||
void
|
||||
ex_make(exarg_T *eap)
|
||||
{
|
||||
char_u *fname;
|
||||
char_u *cmd;
|
||||
char_u *enc = NULL;
|
||||
win_T *wp = NULL;
|
||||
qf_info_T *qi = &ql_info;
|
||||
int res;
|
||||
char_u *au_name = NULL;
|
||||
int_u save_qfid;
|
||||
|
||||
// Redirect ":grep" to ":vimgrep" if 'grepprg' is "internal".
|
||||
if (grep_internal(eap->cmdidx))
|
||||
{
|
||||
ex_vimgrep(eap);
|
||||
return;
|
||||
}
|
||||
|
||||
au_name = make_get_auname(eap->cmdidx);
|
||||
if (au_name != NULL && apply_autocmds(EVENT_QUICKFIXCMDPRE, au_name,
|
||||
curbuf->b_fname, TRUE, curbuf))
|
||||
{
|
||||
#ifdef FEAT_EVAL
|
||||
if (aborting())
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
#ifdef FEAT_MBYTE
|
||||
enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc;
|
||||
#endif
|
||||
|
||||
if (is_loclist_cmd(eap->cmdidx))
|
||||
wp = curwin;
|
||||
|
||||
autowrite_all();
|
||||
fname = get_mef_name();
|
||||
if (fname == NULL)
|
||||
return;
|
||||
mch_remove(fname); // in case it's not unique
|
||||
|
||||
cmd = make_get_fullcmd(eap->arg, fname);
|
||||
if (cmd == NULL)
|
||||
return;
|
||||
|
||||
// let the shell know if we are redirecting output or not
|
||||
do_shell(cmd, *p_sp != NUL ? SHELL_DOOUT : 0);
|
||||
|
||||
#ifdef AMIGA
|
||||
out_flush();
|
||||
// read window status report and redraw before message
|
||||
(void)char_avail();
|
||||
#endif
|
||||
|
||||
res = qf_init(wp, fname, (eap->cmdidx != CMD_make
|
||||
&& eap->cmdidx != CMD_lmake) ? p_gefm : p_efm,
|
||||
(eap->cmdidx != CMD_grepadd
|
||||
&& eap->cmdidx != CMD_lgrepadd),
|
||||
qf_cmdtitle(*eap->cmdlinep), enc);
|
||||
if (wp != NULL)
|
||||
{
|
||||
qi = GET_LOC_LIST(wp);
|
||||
if (qi == NULL)
|
||||
goto cleanup;
|
||||
}
|
||||
if (res >= 0)
|
||||
qf_list_changed(qi, qi->qf_curlist);
|
||||
|
||||
// Remember the current quickfix list identifier, so that we can
|
||||
// check for autocommands changing the current quickfix list.
|
||||
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
|
||||
if (au_name != NULL)
|
||||
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
|
||||
curbuf->b_fname, TRUE, curbuf);
|
||||
if (res > 0 && !eap->forceit && qflist_valid(wp, save_qfid))
|
||||
// display the first error
|
||||
qf_jump_first(qi, save_qfid, FALSE);
|
||||
|
||||
cleanup:
|
||||
mch_remove(fname);
|
||||
vim_free(fname);
|
||||
vim_free(cmd);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the number of valid entries in the current quickfix/location list.
|
||||
*/
|
||||
|
@ -794,6 +794,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
438,
|
||||
/**/
|
||||
437,
|
||||
/**/
|
||||
|
Loading…
x
Reference in New Issue
Block a user