summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/dirvish-config.el1
-rw-r--r--modules/external-open-lib.el42
-rw-r--r--modules/external-open.el23
-rw-r--r--modules/system-utils.el2
4 files changed, 45 insertions, 23 deletions
diff --git a/modules/dirvish-config.el b/modules/dirvish-config.el
index d5834dac..bf91ae2e 100644
--- a/modules/dirvish-config.el
+++ b/modules/dirvish-config.el
@@ -27,6 +27,7 @@
(eval-when-compile (require 'system-utils))
(require 'host-environment)
(require 'system-lib)
+(require 'external-open-lib)
;; mark files in dirvish, attach in mu4e
(add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
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 <c@cjennings.net>
+
+;;; 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
diff --git a/modules/external-open.el b/modules/external-open.el
index c9b5f1f6..0d6ec520 100644
--- a/modules/external-open.el
+++ b/modules/external-open.el
@@ -23,6 +23,7 @@
(require 'host-environment) ;; environment information functions
(require 'system-lib) ;; for cj/file-from-context
+(require 'external-open-lib) ;; pure dispatch helpers
(require 'cl-lib)
;; Declare platform-specific functions
@@ -89,28 +90,6 @@
:type '(repeat (regexp :tag "File extension regexp"))
:group 'external-open)
-;; ----------------------- External-Open Command Resolution -------------------
-
-(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))
-
(defun cj/xdg-open (&optional filename)
"Open FILENAME (or the file at point) with the OS default handler.
Logs output and exit code to buffer *external-open.log*."
diff --git a/modules/system-utils.el b/modules/system-utils.el
index 008a5396..43200403 100644
--- a/modules/system-utils.el
+++ b/modules/system-utils.el
@@ -24,7 +24,7 @@
;;; Code:
(require 'system-lib)
-(require 'external-open)
+(require 'external-open-lib)
(declare-function dired-get-file-for-visit "dired" ())
(declare-function dired-file-name-at-point "dired" ())