From c2f717cd651f215ceb5b1b92083ccc432db26de9 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 17 Jun 2024 04:23:34 -0700 Subject: [PATCH] altmeta vs number_pad While testing a potential fix for issue #1250, I discovered that using the altmeta option, to simulate typing Alt+x to get M-x via typing 'ESC x', didn't work after a count prefixed by 'n' when in number_pad mode. It did work as intended for !number_pad when a repeat count prefix is entered via digits without 'n'. This doesn't solve #1250, which also occurs for number_pad but not for !number_pad. --- doc/fixes3-7-0.txt | 4 ++++ src/cmd.c | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 721aa16a1..4aa08785c 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -1418,6 +1418,10 @@ only honor DEBUGFILES (for activating debugpline() calls) when in wizard mode if hero is on scroll of scare monster or Elbereth, werecreature switching from human to beast form or general monster polymorphing into a susceptible form will become scared right away instead on its next move +'altmeta' option didn't work as intended when 'number_pad' was On; typing + "n ESC c" wasn't treated as "n M-c" because reading + the 'n' changed program_state.input_state from commandInp to otherInp, + preventing special ESC handling; not an issue when number_pad was Off Fixes to 3.7.0-x General Problems Exposed Via git Repository diff --git a/src/cmd.c b/src/cmd.c index af69e19e5..70c5c89e1 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -4716,7 +4716,9 @@ get_count( return key; } - +/* main command input routine when not repeating and not executing canned + commands; input comes via get_count() which collects repeat count if one + is present and returns next non-digit to us */ staticfn int parse(void) { @@ -4728,9 +4730,17 @@ parse(void) flush_screen(1); /* Flush screen buffer. Put the cursor on the hero. */ /* affects readchar() behavior for ESC iff 'altmeta' option is On; - reset to 0 by readchar() */ + is always reset to otherInp by readchar() */ gp.program_state.input_state = commandInp; + if (!gc.Cmd.num_pad || (foo = readchar()) == gc.Cmd.spkeys[NHKF_COUNT]) { + /* if 'num_pad' is On then readchar() has just reset input_state; + set it back to commandInp, so that get_count() supports 'altmeta'; + otherwise "nESC" becomes "nESC" (with + not read from keyboard yet) rather than intended count + and meta keystroke "nM-" */ + gp.program_state.input_state = commandInp; + foo = get_count((char *) 0, '\0', LARGEST_INT, &gc.command_count, GC_NOFLAGS); gl.last_command_count = gc.command_count;