From fe4ae913cc3dfb2719eefd50a0a29de66d06a8d2 Mon Sep 17 00:00:00 2001 From: PatR Date: Sat, 22 Jan 2022 00:30:39 -0800 Subject: [PATCH] more 'rest_on_space' Honor any key binding for when rest_on_space is Off. Toggling it On and Off remembers the key binding if there is one. So if the RC file has BIND=\32:attributes, will run #wait when rest_on_space is On and run #attributes when it's Off. --- src/cmd.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cmd.c b/src/cmd.c index 474000bed..50b3ee862 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -3577,6 +3577,10 @@ reset_commands(boolean initial) update_rest_on_space(); } +/* called when 'rest_on_space' is toggled, also called by reset_commands() + from initoptions_init() which takes place before key bindings have been + processed, and by initoptions_finish() after key bindings so that we + can remember anything bound to in 'unrestonspace' */ void update_rest_on_space(void) { @@ -3588,8 +3592,16 @@ update_rest_on_space(void) ' ', "wait", "rest one move via 'rest_on_space' option", donull, (IFBURIED | CMD_M_PREFIX), "waiting" }; + static const struct ext_func_tab *unrestonspace = 0; + const struct ext_func_tab *bound_f = g.Cmd.commands[' ']; - g.Cmd.commands[' '] = flags.rest_on_space ? &restonspace : 0; + /* when 'rest_on_space' is On, will run the #wait command; + when it is Off, will use 'unrestonspace' which will either + be Null and elicit "Unknown command ' '." or have some non-Null + command bound in player's RC file */ + if (bound_f != 0 && bound_f != &restonspace) + unrestonspace = bound_f; + g.Cmd.commands[' '] = flags.rest_on_space ? &restonspace : unrestonspace; } /* commands which accept 'm' prefix to request menu operation */