]> granicus.if.org Git - nethack/commitdiff
more 'rest_on_space'
authorPatR <rankin@nethack.org>
Sat, 22 Jan 2022 08:30:39 +0000 (00:30 -0800)
committerPatR <rankin@nethack.org>
Sat, 22 Jan 2022 08:30:39 +0000 (00:30 -0800)
Honor any key binding for <space> 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, <space> will run #wait
when rest_on_space is On and run #attributes when it's Off.

src/cmd.c

index 474000bed598cf3cc932d3b6623a72943cf662e8..50b3ee862661c92bfee6b02f810a3789f00a95c8 100644 (file)
--- 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 <space> 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"
     };
-
-    g.Cmd.commands[' '] = flags.rest_on_space ? &restonspace : 0;
+    static const struct ext_func_tab *unrestonspace = 0;
+    const struct ext_func_tab *bound_f = g.Cmd.commands[' '];
+
+    /* when 'rest_on_space' is On, <space> will run the #wait command;
+       when it is Off, <space> 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 */