1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-07-14 17:51:28 +02:00

45660: Fix crash setting vi or emacs mode on command line.

Delay setting the option until the module system is set up.
This commit is contained in:
Peter Stephenson 2020-04-09 21:46:20 +01:00
parent c70d734363
commit 66ee4918a1
3 changed files with 29 additions and 8 deletions

View file

@ -1,3 +1,8 @@
2020-04-09 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 45660: Src/builtin,c, Src/init.c: Delay initial setting of
keympa options until module system is active.
2020-04-05 dana <dana@dana.is> 2020-04-05 dana <dana@dana.is>
* 45655: Completion/Darwin/Type/_retrieve_mac_apps: Update * 45655: Completion/Darwin/Type/_retrieve_mac_apps: Update

View file

@ -6119,7 +6119,7 @@ bin_emulate(char *nam, char **argv, Options ops, UNUSED(int func))
savehackchar = keyboardhackchar; savehackchar = keyboardhackchar;
emulate(shname, opt_R, &new_emulation, new_opts); emulate(shname, opt_R, &new_emulation, new_opts);
optlist = newlinklist(); optlist = newlinklist();
if (parseopts(nam, &argv, new_opts, &cmd, optlist, 0)) { if (parseopts(nam, &argv, new_opts, &cmd, optlist, 0, NULL)) {
ret = 1; ret = 1;
goto restore; goto restore;
} }

View file

@ -248,7 +248,8 @@ static int restricted;
/**/ /**/
static void static void
parseargs(char *zsh_name, char **argv, char **runscript, char **cmdptr) parseargs(char *zsh_name, char **argv, char **runscript, char **cmdptr,
int *needkeymap)
{ {
char **x; char **x;
LinkList paramlist; LinkList paramlist;
@ -265,7 +266,7 @@ parseargs(char *zsh_name, char **argv, char **runscript, char **cmdptr)
* matched by code at the end of the present function. * matched by code at the end of the present function.
*/ */
if (parseopts(zsh_name, &argv, opts, cmdptr, NULL, flags)) if (parseopts(zsh_name, &argv, opts, cmdptr, NULL, flags, needkeymap))
exit(1); exit(1);
/* /*
@ -376,7 +377,7 @@ static void parseopts_setemulate(char *nam, int flags)
/**/ /**/
mod_export int mod_export int
parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp, parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp,
LinkList optlist, int flags) LinkList optlist, int flags, int *needkeymap)
{ {
int optionbreak = 0; int optionbreak = 0;
int action, optno; int action, optno;
@ -482,8 +483,14 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp,
return 1; return 1;
} else if (optno == RESTRICTED && toplevel) { } else if (optno == RESTRICTED && toplevel) {
restricted = action; restricted = action;
} else if ((optno == EMACSMODE || optno == VIMODE) && !toplevel) { } else if ((optno == EMACSMODE || optno == VIMODE)
WARN_OPTION("can't change option: %s", *argv); && (!toplevel || needkeymap)){
if (!toplevel) {
WARN_OPTION("can't change option: %s", *argv);
} else {
/* Need to wait for modules to be loadable */
*needkeymap = optno;
}
} else { } else {
if (dosetopt(optno, action, toplevel, new_opts) && if (dosetopt(optno, action, toplevel, new_opts) &&
!toplevel) { !toplevel) {
@ -1707,7 +1714,7 @@ zsh_main(UNUSED(int argc), char **argv)
{ {
char **t, *runscript = NULL, *zsh_name; char **t, *runscript = NULL, *zsh_name;
char *cmd; /* argument to -c */ char *cmd; /* argument to -c */
int t0; int t0, needkeymap = 0;
#ifdef USE_LOCALE #ifdef USE_LOCALE
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
#endif #endif
@ -1753,7 +1760,7 @@ zsh_main(UNUSED(int argc), char **argv)
createoptiontable(); createoptiontable();
/* sets emulation, LOGINSHELL, PRIVILEGED, ZLE, INTERACTIVE, /* sets emulation, LOGINSHELL, PRIVILEGED, ZLE, INTERACTIVE,
* SHINSTDIN and SINGLECOMMAND */ * SHINSTDIN and SINGLECOMMAND */
parseargs(zsh_name, argv, &runscript, &cmd); parseargs(zsh_name, argv, &runscript, &cmd, &needkeymap);
SHTTY = -1; SHTTY = -1;
init_io(cmd); init_io(cmd);
@ -1762,6 +1769,15 @@ zsh_main(UNUSED(int argc), char **argv)
init_signals(); init_signals();
init_bltinmods(); init_bltinmods();
init_builtins(); init_builtins();
if (needkeymap)
{
/* Saved for after module system initialisation */
zleentry(ZLE_CMD_SET_KEYMAP, needkeymap);
opts[needkeymap] = 1;
opts[needkeymap == EMACSMODE ? VIMODE : EMACSMODE] = 0;
}
run_init_scripts(); run_init_scripts();
setupshin(runscript); setupshin(runscript);
init_misc(cmd, zsh_name); init_misc(cmd, zsh_name);