Skip to content

Fix mode detection and single-argument limits (v0.7.0) - #4

Merged
agzam merged 1 commit into
mainfrom
open-mode-fix
Aug 9, 2026
Merged

Fix mode detection and single-argument limits (v0.7.0)#4
agzam merged 1 commit into
mainfrom
open-mode-fix

Conversation

@agzam

@agzam agzam commented Aug 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • [ -t 0 ] is no longer the mode selector: arguments that exist on the filesystem open in Emacs whether or not stdin is a tty, so rg -l0 pat | xargs -0 mxp --open and find . -name '*.org' -exec mxp --open {} + now work - one Emacs instance, every file, filenames with spaces/metachars/leading dashes included. Previously such callers fell into write mode and littered Emacs with empty junk buffers named after files (or erased a file's unsaved buffer with -F).
  • Explicit mode flags -o/--open, -r/--read, -w/--write override all heuristics; multiple positionals are accepted (open mode batches them into a single emacsclient -n call) instead of silently keeping only the last; -f/-s with a missing operand produce a usage error rather than an unbound-variable trace.
  • Self-update hardening: hermetic file:// tests via a new MXP_UPDATE_URL seam, downgrade refusal, remote version format validation.

Breaking changes

  • Piping into mxp <arg> where <arg> is an existing file/directory now opens it instead of writing to a buffer by that name (-w restores the old behavior). Non-existing names keep their old meaning, so piped regex targets like ".*log.*" still work.
  • Open mode is silent on success (was one stdout line per path); missing paths go to stderr, remaining paths still open, exit code 1.

Verification

  • shellcheck clean on both scripts; suite green: make test-fast 65/65, make test 71/71 against a live daemon. Open mode was previously a test stub asserting nothing; it is now covered non-interactively, and tty-dependent detection is tested against a real pty via script(1).
  • End to end: 321 org files (spaces + $name;(x) metachars) through rg -l0 | xargs -0 -n 100, find -exec {} +, and multi-positional invocations - all files opened, Emacs process count unchanged, zero junk buffers.
  • Verified under bash 5.3.15 and stock macOS 3.2.57 (open/read/arg paths; write mode keeps the documented bash >= 4.0 floor).

Open and read modes were only reachable when stdin was a tty, so every
non-interactive caller (xargs, find -exec, make, CI) fell into write
mode: `printf 'a.org\n' | xargs mxp` created empty junk buffers named
after files, or erased a file's unsaved buffer with -F. Positional
arguments also silently overwrote each other, keeping only the last.

- explicit mode flags -o/--open, -r/--read, -w/--write override all
  heuristics; conflicting flags are an error
- mode inference consults the filesystem before stdin: arguments that
  all exist on disk open in Emacs regardless of stdin; path-shaped but
  missing arguments keep their old meaning (open intent on a tty,
  buffer name/regex like ".*log.*" when piped), so pipe workflows stay
  compatible
- open mode accepts any number of paths and opens them in a single
  emacsclient -n call; silent on success; missing paths reported to
  stderr while the rest still open, exit 1
- `--` terminator for leading-dash filenames; dirname/basename/cd
  hardened with -- guards
- -f/--from and -s/--socket-name without an operand die with a usage
  error instead of a set -u unbound-variable trace
- self-update: MXP_UPDATE_URL seam makes the path testable against
  file:// fakes; refuses downgrades; validates remote version format;
  read-mode trap now chains the socket disconnect it used to clobber
- tests: open mode was a stub asserting nothing, which is how the
  defect shipped; now covered non-interactively, tty detection tested
  against a real pty via script(1) reading the typescript file (macOS
  script drops fast-exit output from its stdout pipe), suite cleans up
  every buffer it creates via an EXIT trap

The motivating pipelines now work with one Emacs, every file, any
filename:

  rg -l0 pat | xargs -0 mxp --open
  find . -name '*.org' -exec mxp --open {} +
@agzam
agzam merged commit 8597d95 into main Aug 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant