neomacs icon indicating copy to clipboard operation
neomacs copied to clipboard

[Bug]: Pretzel-Q in neomacs quits neomacs as with a crash

Open UselessDetails opened this issue 1 month ago • 7 comments

Bug summary

The key combo I'm expecting to be bound to fill-paragraph instead causes neomacs to quit immediately without warning about unsaved buffers, etc.

Steps to reproduce

Launch.

Pretzel-Q

Expected behavior

I'm expecting pretzel-Q to be M-q, ordinarily bound to fill-paragraph. Note that the menu on mac has the pretzel-Q grayed out, suggesting that it won't be recognized. Also note that pretzel-Q does not go through the usual warnings about unsaved buffers. Instead, unsaved work is lost as with a crash.

Neomacs --version output

emacs-version reports 31.1

[email protected]> /Applications/neomacs.app/Contents/MacOS/neomacs --version
Neomacs 0.0.20
Git commit: 47fa15cc69ae8f8da1ca3fac25e0beb700e8c118
Source date: 2026-10-24T15:13:18.000000000-04:00
Build: release for aarch64-apple-darwin with rustc 1.96.1
Standalone Rust binary for Neomacs (no C dependency)

Platform

Linux (X11)

Install source

Prebuilt release asset (downloaded from Releases)

Extra context

No response

UselessDetails avatar Nov 01 '26 21:11 UselessDetails

Neomacs is unusable at this point. I start to use it... hit fill paragraph, and all my work is lost.

Unusable.

If you go with the above "fix", please make it configurable. I want my M-q to be M-q.

UselessDetails avatar Nov 04 '26 20:11 UselessDetails

😭 Sorry for the unacceptable bug.

Investigating.

eval-exec avatar Nov 04 '26 23:11 eval-exec

@neomacs-agent can neomacs-gui-tests can running on MacOS now?

eval-exec avatar Nov 04 '26 23:11 eval-exec

Yes, the suite builds and can run on macOS, but only a subset is exercised there and the full gui target is not part of an automatic macOS gate.

Verified locally at current main (a529ae5c5a):

  • cargo nextest list --release -p neomacs-gui-tests --test gui → compiles and links the full GUI test binary on macOS (release profile) and lists its tests.
  • cargo nextest run --release -p neomacs-gui-tests --test gui -E 'test(harness_contract)' → 16/16 passed.
  • real_gui_smoke_generates_surface_readback_png with NEOMACS_GUI_TEST_BACKEND=macos and a prebuilt release binary → the app launched on the current desktop and produced a frame snapshot and gui_state (buffer text, window start/end), but the test failed at the PNG surface-readback artifact (PNG artifact was not generated). I did not do a fresh cargo xtask fresh-build --release, so this is not a green run of the smoke test on current main; the manual macOS smoke workflow only requires the snapshot, not the PNG.
  • I did not run macos_native_menus or interaction_geometry. They require scripts/build-macos-gui-driver.sh, a running NeomacsGuiDriver.app, the ABC keyboard layout, Accessibility and Screen Recording grants, and a logged-in unlocked desktop. The driver socket is not set up here, and those tests fail explicitly (rather than skipping) when prerequisites are missing.

CI/platform status:

  • The automatic neomacs-gui-tests job in test-suite.yml is Linux x86_64 only (X11 + Wayland).
  • macOS runs are manual: native-display-contract.yml (workflow_dispatch, macOS matrix entry, runs --test native_display) and tmp_mac_test.yml (manual fresh build plus startup snapshot smoke). The native-display contract has succeeded on macOS in recent manual runs, so the macOS path is real, just not a per-PR requirement.
  • In the suite, GuiBackend::Macos maps to RunnerKind::CurrentDesktopSession; snapshot/geometry tests work on the current desktop, while physical pointer/keyboard tests need the permissioned helper described above.

For #668 specifically, there is currently no s-q / Cmd-Q / quit-chord test in the GUI suite, so even a working macOS run today would not cover it. The macOS driver can send physical key events, so a Cmd-Q regression test is feasible, but it needs the helper permissions. I can investigate/reproduce #668 and add that test if you want.

neomacs-agent[bot] avatar Nov 04 '26 23:11 neomacs-agent[bot]

Follow-up TODO: remaining GNU quit-path deviations (not covered by #677)

#677 fixed the reported data loss: the AppKit Quit item now feeds s-q, so it runs save-buffers-kill-emacs and prompts. Two GNU behaviours are still missing. Evidence is from GNU 31.1 at a360712c9d and from current main (b076e99fba).

1. applicationShouldTerminate: / ns-confirm-quit are inert

GNU:

  • src/nsterm.m:6628-6641 — applicationShouldTerminate: returns NSTerminateNow when ns-confirm-quit is nil; otherwise it runs a native alert, "Exit requested. Would you like to Save Buffers and Exit, or Cancel the request?", and returns NSTerminateNow / NSTerminateCancel.
  • src/nsterm.m:11653-11655 — ns-confirm-quit is a DEFVAR_LISP whose default is nil.

Neomacs:

  • The variable is seeded (crates/neovm-eval/src/emacs_core/runtime/eval/ns_surface.rs:49) and documented, but nothing reads it.
  • There is no NSApplicationDelegate: applicationShouldTerminate does not occur anywhere in the repo, and the only AppKit application use is NSApplication::sharedApplication in crates/neomacs-display-runtime/src/render_thread/macos_quit_redirect.rs:131.
  • The pinned winit fork observes only NSApplicationWillTerminateNotification (winit-appkit/src/event_loop.rs:402-412 → app_state.rs:188-193), which fires after the terminate decision already exists.

Consequence: a system-initiated terminate (logout/restart, osascript -e 'quit app "Neomacs"', Activity Monitor) exits immediately, so (setq ns-confirm-quit t) has no effect. With the default nil GNU also exits immediately, so today the defaults agree; the opt-in confirmation is what is missing.

TODO:

  • [ ] Give Neomacs an NSApplicationDelegate that answers applicationShouldTerminate: on the AppKit main thread: read ns-confirm-quit from the Lisp side, run GNU's alert (or its equivalent), return NSTerminateNow / NSTerminateCancel.
  • [ ] Pick the installation point (macos_quit_redirect::install already runs from handle_resumed); the pinned winit fork sets no delegate itself, so the slot is free.
  • [ ] Manual macOS verification for logout, AppleScript quit, and a modified buffer.

2. Menu Quit routes through the s-q binding instead of an ns-power-off event

GNU:

  • The app menu Quit action is terminate: (src/nsterm.m:6095-6097), and -[EmacsApp terminate:] posts the non-key KEY_NS_POWER_OFF (src/nsterm.m:6588-6604).
  • lisp/term/ns-win.el:177 registers it as a non-key event; :195 binds [ns-power-off] to save-buffers-kill-emacs; :141 binds s-q separately.

Neomacs after #677:

  • The Quit item is retargeted to synthesize super+q (macos_quit_redirect.rs:37-43, installed at :122-165).

Consequence: rebinding s-q also changes what menu Quit and ⌘Q do — e.g. (global-set-key (kbd "s-q") #'fill-paragraph) makes the Quit menu item fill a paragraph — whereas in GNU the two routes are independent. This is closer to the "make it configurable" request in this issue, but it is still a GNU deviation.

TODO:

  • [ ] Route the retargeted menu action through an ns-power-off-style non-key event (or the equivalent internal quit command) instead of s-q, and keep both [?\s-q] and [ns-power-off] bound to save-buffers-kill-emacs as GNU does.
  • [ ] Preserve the current deferral while the input queue is full (PENDING_QUIT / about_to_wait retry).
  • [ ] Add a regression test for the chosen routing; the Lisp side is testable on Linux, the AppKit side needs a manual macOS run.

Verification constraint: the macOS AppKit path is not gated in automatic CI (GUI tests run on Linux; macOS native-display runs are manual). Existing Lisp pins are neo_preload_binds_command_q_like_gnu_on_darwin and the oracle super_q_binding_matches_gnu_per_platform.

eval-exec avatar Nov 14 '26 07:11 eval-exec

Update: the remaining quit-path differences from the earlier follow-up are fixed on main as of 40a4a7bd0e. They now follow GNU Emacs 31.1:

  • ⌘Q is an ordinary key. As in GNU's Cocoa build, the Command key is super by default (ns-command-modifier is super, from src/nsterm.m), so ⌘Q arrives as s-q. s-q is bound to save-buffers-kill-emacs (lisp/term/ns-win.el), so it prompts about unsaved buffers instead of quitting. You can rebind it like any other key.
  • To make ⌘Q mean M-q (fill-paragraph), which is what you expected, do what you would in GNU Emacs and set (setq ns-command-modifier 'meta). ⌘ then acts as Meta.
  • The application menu's Quit item goes through the same confirmation path, so it can no longer drop unsaved work.

Tested on macOS (Apple Silicon): the quit-confirmation tests pass, and so do the key-binding tests, which compare against a GNU Emacs 31.1 build on the same Mac. We could not press a physical ⌘Q in CI, because macOS doesn't allow synthetic input there. It would help a lot if you could try ⌘Q with an unsaved buffer on a build from current main and tell us whether you get the save prompt. This will be in v0.0.21.

eval-exec avatar Nov 21 '26 15:11 eval-exec

Fixed in v0.0.21 (e351332e02 / 0b3a088ccf and follow-ups):

  • ⌘Q arrives as s-q and runs save-buffers-kill-emacs.
  • The menu's Quit item goes through the same confirmation.

Unsaved work is no longer lost. If you want ⌘ to act as Meta (so ⌘Q is M-q), set (setq ns-command-modifier 'meta), the same as in GNU Emacs.

All nine non-physical quit paths are compared against GNU. We could not press a physical ⌘Q in CI, so please reopen if v0.0.21 still quits without the save prompt.

eval-exec avatar Nov 23 '26 01:11 eval-exec