Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: don't load ZLE early to set keymap
- X-seq: zsh-workers 53399
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: zsh-workers@xxxxxxx
- Subject: Re: PATCH: don't load ZLE early to set keymap
- Date: Sun, 02 Mar 2025 01:20:07 +0100
- Archived-at: <https://zsh.org/workers/53399>
- In-reply-to: <CAH+w=7Z5zAjf6zykQbQpgez8W6ZfHh6PcBrm_wmmdrLqynTFBg@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <42572-1740099942.836692@_3BM.v5Iz.JqiS> <F07C8421-2663-440A-82AD-0748D39511B1@kba.biglobe.ne.jp> <CAH+w=7a9hye-2BxQUjkHw-=zFo5T7vXjVwQRnKnKEoZ3W0-_ug@mail.gmail.com> <40483-1740433325.086036@2QZo.3hhS.-9FG> <CAH+w=7Zf3vL6BYg0t61uskLmDD_gOwE7XhuwxB9SSwv+z0qOKw@mail.gmail.com> <69272-1740474756.308875@TCCj.PrGv.2vsI> <CAH+w=7ZJNRy2zV7t4wRhzcnW1jn2LgRKbMByCOrtbr9VVM2emw@mail.gmail.com> <5355-1740527169.384113@fufd.0HLy.otw9> <CAH+w=7ZxuY9tcuQmD0BdTDzUxdOsdagBJxDh7_ONxMU2Vy56QQ@mail.gmail.com> <65954-1740610146.926596@The9.bEhv.rrrz> <98831-1740873534.244102@TAre.-eUK.mBh1> <CAH+w=7Z2RMCBMDDvyVA4qLCp-fU9UgVDzjai2C=k5NK=jde+Fw@mail.gmail.com> <CAH+w=7Z5zAjf6zykQbQpgez8W6ZfHh6PcBrm_wmmdrLqynTFBg@mail.gmail.com>
Bart Schaefer wrote:
> > Yes, that's intentional. See for example the comment I just wrote in
> > workers/53368
Fine.
Adjusted patch follows.
> To elaborate a bit, they both start OFF, and "changing" an option from
> OFF to OFF should not magically turn ON something else.
Ok, I can see the sense there.
Oliver
diff --git a/Src/Zle/zle_keymap.c b/Src/Zle/zle_keymap.c
index ce52abe66..7f31f837c 100644
--- a/Src/Zle/zle_keymap.c
+++ b/Src/Zle/zle_keymap.c
@@ -1452,7 +1452,10 @@ default_bindings(void)
linkkeymap(oppmap, "viopp", 0);
linkkeymap(vismap, "visual", 0);
linkkeymap(smap, ".safe", 1);
- linkkeymap(emap, "main", 0);
+ if (isset(VIMODE))
+ linkkeymap(vmap, "main", 0);
+ else
+ linkkeymap(emap, "main", 0);
/* the .safe map cannot be modified or deleted */
smap->flags |= KM_IMMUTABLE;
diff --git a/Src/builtin.c b/Src/builtin.c
index 6bdaddff0..5563bdba9 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -6333,7 +6333,7 @@ bin_emulate(char *nam, char **argv, Options ops, UNUSED(int func))
savehackchar = keyboardhackchar;
emulate(shname, opt_R, &new_emulation, new_opts);
optlist = newlinklist();
- if (parseopts(nam, &argv, new_opts, &cmd, optlist, 0, NULL)) {
+ if (parseopts(nam, &argv, new_opts, &cmd, optlist, 0)) {
ret = 1;
goto restore;
}
diff --git a/Src/init.c b/Src/init.c
index 75d9dd136..76de0b449 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -255,8 +255,7 @@ static char *argv0;
/**/
static void
-parseargs(char *zsh_name, char **argv, char **runscript, char **cmdptr,
- int *needkeymap)
+parseargs(char *zsh_name, char **argv, char **runscript, char **cmdptr)
{
char **x;
LinkList paramlist;
@@ -273,7 +272,7 @@ parseargs(char *zsh_name, char **argv, char **runscript, char **cmdptr,
* matched by code at the end of the present function.
*/
- if (parseopts(zsh_name, &argv, opts, cmdptr, NULL, flags, needkeymap))
+ if (parseopts(zsh_name, &argv, opts, cmdptr, NULL, flags))
exit(1);
/*
@@ -384,7 +383,7 @@ static void parseopts_setemulate(char *nam, int flags)
/**/
mod_export int
parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp,
- LinkList optlist, int flags, int *needkeymap)
+ LinkList optlist, int flags)
{
int optionbreak = 0;
int action, optno;
@@ -490,14 +489,8 @@ parseopts(char *nam, char ***argvp, char *new_opts, char **cmdp,
return 1;
} else if (optno == RESTRICTED && toplevel) {
restricted = action;
- } else if ((optno == EMACSMODE || optno == VIMODE)
- && (!toplevel || needkeymap)){
- if (!toplevel) {
- WARN_OPTION("can't change option: %s", *argv);
- } else {
- /* Need to wait for modules to be loadable */
- *needkeymap = optno;
- }
+ } else if ((optno == EMACSMODE || optno == VIMODE) && !toplevel) {
+ WARN_OPTION("can't change option: %s", *argv);
} else {
if (dosetopt(optno, action, toplevel, new_opts) &&
!toplevel) {
@@ -1864,7 +1857,7 @@ zsh_main(UNUSED(int argc), char **argv)
{
char **t, *runscript = NULL, *zsh_name;
char *cmd; /* argument to -c */
- int t0, needkeymap = 0;
+ int t0;
#ifdef USE_LOCALE
setlocale(LC_ALL, "");
#endif
@@ -1910,7 +1903,7 @@ zsh_main(UNUSED(int argc), char **argv)
createoptiontable();
/* sets emulation, LOGINSHELL, PRIVILEGED, ZLE, INTERACTIVE,
* SHINSTDIN and SINGLECOMMAND */
- parseargs(zsh_name, argv, &runscript, &cmd, &needkeymap);
+ parseargs(zsh_name, argv, &runscript, &cmd);
SHTTY = -1;
init_io(cmd);
@@ -1919,15 +1912,6 @@ zsh_main(UNUSED(int argc), char **argv)
init_signals();
init_bltinmods();
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();
setupshin(runscript);
init_misc(cmd, zsh_name);
diff --git a/Src/options.c b/Src/options.c
index 8b37ab5e8..ecc4268fd 100644
--- a/Src/options.c
+++ b/Src/options.c
@@ -889,7 +889,8 @@ dosetopt(int optno, int value, int force, char *new_opts)
} else if ((optno == EMACSMODE || optno == VIMODE) && value) {
if (sticky && sticky->emulation)
return -1;
- zleentry(ZLE_CMD_SET_KEYMAP, optno);
+ if (zle_load_state == 1)
+ zleentry(ZLE_CMD_SET_KEYMAP, optno);
new_opts[(optno == EMACSMODE) ? VIMODE : EMACSMODE] = 0;
} else if (optno == SUNKEYBOARDHACK) {
/* for backward compatibility */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author