From 618bc7813b9acfcf1dfccc9c6590f6f5aece86cf Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 10 May 2026 15:37:36 -0500 Subject: refactor(external-open): extract external-open-lib for shared helpers Same shared-helpers split-pattern that ai-vterm/vterm-config use through cj-window-toggle-lib and that calendar-sync uses through cj-org-text-lib. Pull the two pure dispatch helpers out of the external-open feature module into a sibling library so consumers that only need the dispatch don't have to require the whole feature. New `modules/external-open-lib.el' carries: - `cj/external-open-command' - `cj/external-open-launcher-p' `modules/external-open.el' stays as the feature module: the `default-open-extensions' defcustom, the `find-file' advice (`cj/find-file-auto'), and the interactive commands (`cj/xdg-open', `cj/open-this-file-with'). It now requires external-open-lib for the dispatch helpers. Migrate consumers: - system-utils.el used to require `external-open' for `cj/external-open-launcher-p' alone -- now requires `external-open-lib' directly. - dirvish-config.el calls `cj/external-open-command' from `cj/dirvish-open-file-manager-here' -- add an explicit `(require \='external-open-lib)'. Test files renamed to match the system-lib naming pattern (test--.el): - test-external-open-command.el -> test-external-open-lib-command.el - test-external-open-launcher-p.el -> test-external-open-lib-launcher-p.el No behavior change. --- modules/external-open-lib.el | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 modules/external-open-lib.el (limited to 'modules/external-open-lib.el') diff --git a/modules/external-open-lib.el b/modules/external-open-lib.el new file mode 100644 index 00000000..aa90eb67 --- /dev/null +++ b/modules/external-open-lib.el @@ -0,0 +1,42 @@ +;;; external-open-lib.el --- Pure helpers for OS open-with dispatch -*- lexical-binding: t; -*- + +;; Author: Craig Jennings + +;;; Commentary: + +;; Pure helpers for resolving the OS-default "open" command and +;; recognizing desktop launchers. No side effects, no state. The +;; feature module (`external-open.el') uses these helpers; consumers +;; that only need the dispatch (system-utils' "open with command", +;; dirvish's "open file manager here") require this library directly +;; instead of the feature module. +;; +;; Pulled out of `external-open.el' as part of utility-consolidation +;; Phase 4. See `docs/design/utility-consolidation.org'. + +;;; Code: + +(require 'host-environment) + +(defun cj/external-open-command () + "Return the OS-default \"open\" command for this host, or nil if unsupported. +Returns one of \"xdg-open\" (Linux), \"open\" (macOS), \"start\" (Windows). +Callers that require a command should error on nil with a contextual +message so the user sees what feature is unavailable." + (cond + ((env-linux-p) "xdg-open") + ((env-macos-p) "open") + ((env-windows-p) "start") + (t nil))) + +(defun cj/external-open-launcher-p (command) + "Return non-nil when COMMAND is a desktop launcher. +Launchers (xdg-open, open, start) need to be called with `call-process' +and a zero BUFFER argument so they fully detach from Emacs. Other +commands get `start-process-shell-command' so their output is visible." + (and (stringp command) + (member command '("xdg-open" "open" "start")) + t)) + +(provide 'external-open-lib) +;;; external-open-lib.el ends here -- cgit v1.2.3