Fix mode detection and single-argument limits (v0.7.0) - #4
Merged
Conversation
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 {} +
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.
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, sorg -l0 pat | xargs -0 mxp --openandfind . -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).-o/--open,-r/--read,-w/--writeoverride all heuristics; multiple positionals are accepted (open mode batches them into a singleemacsclient -ncall) instead of silently keeping only the last;-f/-swith a missing operand produce a usage error rather than an unbound-variable trace.file://tests via a newMXP_UPDATE_URLseam, downgrade refusal, remote version format validation.Breaking changes
mxp <arg>where<arg>is an existing file/directory now opens it instead of writing to a buffer by that name (-wrestores the old behavior). Non-existing names keep their old meaning, so piped regex targets like".*log.*"still work.Verification
shellcheckclean on both scripts; suite green:make test-fast65/65,make test71/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 viascript(1).$name;(x)metachars) throughrg -l0 | xargs -0 -n 100,find -exec {} +, and multi-positional invocations - all files opened, Emacs process count unchanged, zero junk buffers.