Repository navigation
WIP: bind current-keymap resolution + "${!prefix@}" compound fan-out + read -e test debt (#2386, #2387, #2389) - #2415
Merged
Conversation
GNU ground: builtins/bind.def:205-216 — with -m the named map is installed as the current keymap for the builtin, otherwise every listing, query, unbind and registration runs against rl_get_keymap(). The dumpers and query read _rl_keymap (lib/readline/bind.c:2743 rl_function_dumper, :2753 rl_print_keybinding, :2811 rl_macro_dumper; bind.def:386 unbind_command); sv_editmode (bind.c:2097, 2104) and the keymap variable's setter (bind.c:2517) keep _rl_keymap in step with the variables, and the variable reads back as rl_get_keymap_name(_rl_keymap) (bind.c:3018-3023; first registered name, bind.c:2404-2416). builtins/set.def:424-447 set_edit_mode: a FLAG_ON of set -o vi/emacs is an rl_variable_bind of editing-mode. rubash passed the -m name (or None) straight through, and the registry read None as emacs-standard, so in a vi-mode shell bind -p dumped the 497-line emacs factory table instead of the 424-line vi-insert one, queries answered from the wrong map, registrations landed in emacs, and removals tombstoned the wrong map (or floated across mode flips). - bind_dispatch resolves the effective keymap once (-m name normalized, else the registry keymap variable) and threads it through the whole invocation. - BindRegistry resolves a None keymap to its current keymap (the keymap variable, the _rl_keymap mirror) in register / record_removal / is_removed / entries_for_keymap / unbind_keyseq_for_keymap / unbind_function_for_keymap / invoking_keyseqs; register() stamps keymap-less entries with the map current at bind time and record_removal() stores the resolved map, so neither floats across editing-mode flips. - The keymap variable stores its canonical readback value (vi-movement -> "vi", emacs-standard -> "emacs"). - set -o vi/emacs FLAG_ON transitions (the set builtin and Executor::set_shell_option) bridge into the registry's editing-mode variable, per set.def:427. Regression pins compare dump STRUCTURE (per-keymap line counts, static in the engine tables and byte-matched to the GNU bash 5.3.20 oracle capture) plus spot entries rather than embedding the 497-line dump. Refs #2386
GNU ground: subst.c:9978-10007 parameter_brace_expand — the
${!prefix@} arm builds all_variables_matching_prefix's list
(strcmp order, variables.c:4250-4262) and returns it with
string_list_dollar_at semantics; arrayfunc.c:557
expand_compound_array_assignment expands each compound word
independently, so inside a=(...) the list contributes one
element per name and an empty match contributes zero elements,
like "$@".
rubash's compound-assignment dispatch had arms for ${!arr[@]}
keys and ${!ref} indirection but none for the name-list form:
the token fell through to the scalar String path
(expand_braced_special), which joins the names with IFS[0]
into a single element. Command-argument position already had
the fan-out (command_prepare.rs); assignment position did not.
That single joined element is the whole ble.sh teardown
divergence: names=("${!_ble_decode_@}") captures one
space-joined word, unset "${names[@]}" then receives one
invalid identifier and every variable survives (unset itself
is byte-identical in both shells given the same word — the
join is born at capture time, so the fix belongs here, not
in unset).
The new dispatch arm mirrors the ${!arr[@]} arm: a whole-word
!PREFIX@ body (any of the token's storage shapes) expands to
one stored element per matching shell name, strcmp-sorted.
The * form stays on the generic path (string_list_dollar_star
is one joined word in every context), and scalar contexts are
unchanged.
Refs #2387
Test-only; no product changes. #2339 (read -e) landed in PR #2364 without a named integration regression file. This ports the 17 shapes from the hunt probe (fix-r4-bind-read/probes/read_e_pty.py, r35 rs01-rs29 shapes) into a Rust PTY harness (openpty, 0.35s termios settle, keys, read-to-exit with deadline) with the probe's GNU expectations. Verdicts recorded against master before this port: GNU bash 5.3.20 17/17, rubash 16/17. The one divergence, rs24 (C-d on an empty buffer), keeps its GNU expectation (<> rc=1) under an #[ignore] marker naming the residual — the read -e editor (src/readline_editor.rs) does not return EOF for C-d on an empty buffer; fixing that is a product cluster's job, not this test-debt item's. Refs #2389 Refs #2339
This was referenced Nov 1, 2026
…low-up) Batch verification of the first #2386 commit found the five set -o pins still red: after `set -o vi`, bind -p still dumped the 497-line emacs table and bind -q still listed "\C-b", while bind 'set editing-mode vi' flipped correctly (424). Root cause: the editing-mode VARIABLE path works because apply_readline_variable keeps the registry's editing-mode/keymap rows cross-consistent (the mirror of sv_editmode, lib/readline/bind.c:2092-2110, moving _rl_keymap). The set -o path never reached its bridge: execute_set_command tries apply_set_positional_operands first, whose -o branch applies the option straight into env_vars (with hooks for history/ignoreeof only) — and when that returns false, the slow path's prior-transition bridge in execute_set reads the option as already-on and never fires. `set -o vi` is the canonical -o shape, so the bridge was dead code for exactly its own commands. GNU has one funnel: every -o write goes through set_minus_o_option (builtins/set.def:476-491) into the option table's setter, and for vi/emacs that setter IS set_edit_mode (set.def:200,235), whose FLAG_ON arm is rl_variable_bind("editing-mode", name) (set.def:424-431). Fix by the same mechanism — run the bind at the application sites that bypass the funnel: - shell_options.rs -o branch: bind editing-mode on a vi/emacs FLAG_ON, beside the existing history/ignoreeof hooks. - function_locals.rs apply_options_bitmap: a differing vi/emacs flip runs the option's set function in GNU too (set_current_options, set.def:358-386, SET_BINARY_O_OPTION_VALUE on the differing entries), so bind on a FLAG_ON flip there as well, beside the existing ignoreeof mirror. FLAG_OFF never binds (set.def:432-446): `set -o vi; set +o vi` leaves editing-mode vi, verified against the oracle. Warning-face adjudication (no change): GNU prints "bind: warning: line editing not enabled" on EVERY bind call when no_line_editing (builtins/bind.def:122-123, unconditional) — oracle 5.3.20 prints it 3x for 3 binds in both -c and script-file faces, matching the branch binary. The once-only reading was a probe artifact. Verification (foreground runs, artifacts checked on disk): - scrubbed issue2386 pins: 9/9 (was 4/9) - issue2387 pins 7/7, issue2339 pins 16 passed + 1 ignored (both unchanged) - cargo test --lib -- bind: 45/45; cargo check --tests clean - probes vs oracle: set -o vi / -q / script-file faces match; local - bitmap save/restore faces match GNU outcomes Refs #2386
caomengxuan666
marked this pull request as ready for review
November 1, 2026 03:57
This was referenced Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cluster PR for #2386, #2387, #2389 (one commit per issue, Refs-only; main session batch-verifies the pins before merge).
#2386 — bind operates on the current keymap
GNU: bind.def:205-216 (no
-m= rl_get_keymap()); bind.c:2743/2753/2811 dumpers read_rl_keymap; bind.c:2097/2104 sv_editmode; bind.c:2517 keymap setter; bind.c:3018-3023 canonical readback; set.def:424-447 set_edit_mode. Master dumped the 497-line emacs factory table in vi mode; the fix resolves the effective keymap once in bind_dispatch and makes the registry resolve None -> current everywhere (registrations/removals stamped with the map current at bind time), stores the canonical keymap-variable readback, and bridgesset -o vi/emacsFLAG_ON into editing-mode. Pins compare dump structure (per-keymap line counts vs the oracle capture) + spot entries.#2387 — "${!PREFIX@}" fans out in compound assignments
GNU: subst.c:9978-10007 (parameter_brace_expand name-list arm, string_list_dollar_at), variables.c:4250-4262 (strcmp sort), arrayfunc.c:557 (expand_compound_array_assignment). Master joined the names into ONE element in
a=("${!p@}"), which is what makes ble.sh teardown feed unset one space-joined invalid identifier. New dispatch arm beside the ${!arr[@]} arm;*form and scalar contexts unchanged. (Adjacent, NOT fixed here: glued pre"${arr[@]}"post forms collapse in master for plain arrays too — separate pre-existing gap.)#2389 — test-only: read -e PTY pins for #2339
Ports the 17 probe shapes (read_e_pty.py, rs01-rs29) into tests/issue2339_read_e_regressions.rs. Finding: GNU 17/17, rubash master 16/17 — rs24 (C-d on empty buffer) diverges; its pin keeps the GNU expectation under #[ignore] naming the residual. No product changes for this item.
Local: cargo check --all-targets clean (code-first posture; pins are main-session batch verification).