diff options
| author | Craig Jennings <c@cjennings.net> | 2026-07-18 17:28:58 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-07-18 17:29:05 -0500 |
| commit | c3720afd638270dc3fcc2b6ee4f7d26bdde634e8 (patch) | |
| tree | 72d8b89a2c96fd6f04e8aa80142d3be5180f59eb /modules/external-open.el | |
| parent | 4727c52aa3fcc1ac734d6cd6d4e44a3194984179 (diff) | |
| download | dotemacs-c3720afd638270dc3fcc2b6ee4f7d26bdde634e8.tar.gz dotemacs-c3720afd638270dc3fcc2b6ee4f7d26bdde634e8.zip | |
refactor: launch external processes with argv lists, not shells
- open-this-file-with splits the typed command and calls call-process.
- media-play-it resolves streams via a yt-dlp capture, then start-process.
- Paths, URLs, and player args never meet a shell.
- yt-dlp stderr is captured separately so warnings can't parse as URLs.
- Stream resolution now blocks briefly. mpv (the default) is unaffected.
Diffstat (limited to 'modules/external-open.el')
| -rw-r--r-- | modules/external-open.el | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/modules/external-open.el b/modules/external-open.el index 811c32c2..306db94f 100644 --- a/modules/external-open.el +++ b/modules/external-open.el @@ -142,6 +142,18 @@ Logs output and exit code to buffer *external-open.log*." ;; ------------------------------- Open File With ------------------------------ +(defun cj/--open-with-argv (command file) + "The argv list to open FILE with the user-typed COMMAND. +COMMAND may carry arguments (\"mpv --fs\"); `split-string-and-unquote' +splits it so a double-quoted argument survives as one word. FILE is +appended as the final element, so paths with spaces or shell +metacharacters never meet a shell. Signals a `user-error' when COMMAND +is empty or whitespace." + (let ((argv (split-string-and-unquote command))) + (unless argv + (user-error "No program given")) + (append argv (list file)))) + (defun cj/open-this-file-with (command) "Open this buffer's file with COMMAND, detached from Emacs." (interactive "MOpen with program: ") @@ -152,12 +164,12 @@ Logs output and exit code to buffer *external-open.log*." ;; Windows: launch via ShellExecute so the child isn't tied to Emacs. ((env-windows-p) (w32-shell-execute "open" command (format "\"%s\"" file))) - ;; POSIX: disown with nohup + background. No child remains. + ;; POSIX: argv launch, DESTINATION 0 detaches with no shell in between. (t - (call-process-shell-command - (format "nohup %s %s >/dev/null 2>&1 &" - command (shell-quote-argument file)) - nil 0))))) + (let ((argv (cj/--open-with-argv command file))) + (unless (executable-find (car argv)) + (user-error "Program not found: %s" (car argv))) + (apply #'call-process (car argv) nil 0 nil (cdr argv))))))) ;; -------------------------- Open Videos On Repeat ---------------------------- |
