summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-10 13:31:04 -0500
committerCraig Jennings <c@cjennings.net>2026-05-10 13:31:04 -0500
commit32e57be15a48aa24470e9f3bc6a206c7624bd6b0 (patch)
tree02756fd3a3353e509fee2c4c96aa31c68e939b4e /modules
parent6545605fa965d649defc0bb01e8c040afbbcc529 (diff)
downloaddotemacs-32e57be15a48aa24470e9f3bc6a206c7624bd6b0.tar.gz
dotemacs-32e57be15a48aa24470e9f3bc6a206c7624bd6b0.zip
refactor(dirvish): extract cj/--file-manager-program-for helper
`cj/dirvish-open-file-manager-here' had its platform-dispatch -- xdg-open / open / explorer / shell fallback -- inline as a four-arm cond branching on `executable-find' and `system-type'. Lift the choice into `cj/--file-manager-program-for', a pure function from (HAS-XDG-OPEN-P SYSTEM-TYPE) to a program-name string or nil. The wrapper resolves the live values, asks the helper, and either calls the program or falls back to a shell-command. Six Normal/Boundary tests cover the four return shapes (xdg-open across system types, darwin/windows-nt without xdg-open, the nil fallback for plain Linux without xdg-open and for unknown system-types like Haiku).
Diffstat (limited to 'modules')
-rw-r--r--modules/dirvish-config.el37
1 files changed, 22 insertions, 15 deletions
diff --git a/modules/dirvish-config.el b/modules/dirvish-config.el
index 3fce616e..22d3f07c 100644
--- a/modules/dirvish-config.el
+++ b/modules/dirvish-config.el
@@ -194,6 +194,21 @@ Examples:
;;; ----------------------- Dirvish Open File Manager Here ----------------------
+(defun cj/--file-manager-program-for (has-xdg-open-p system-type)
+ "Return the file-manager command for HAS-XDG-OPEN-P + SYSTEM-TYPE, or nil.
+
+Pure helper used by `cj/dirvish-open-file-manager-here'. When
+HAS-XDG-OPEN-P is non-nil, returns \"xdg-open\" regardless of
+SYSTEM-TYPE -- xdg-open works on Linux and many ported environments.
+Without xdg-open, falls back to `darwin' -> \"open\", `windows-nt' ->
+\"explorer\", everything else -> nil so the caller can shell-command
+its way out."
+ (cond
+ (has-xdg-open-p "xdg-open")
+ ((eq system-type 'darwin) "open")
+ ((eq system-type 'windows-nt) "explorer")
+ (t nil)))
+
(defun cj/dirvish-open-file-manager-here ()
"Open system's default file manager in the current dired/dirvish directory.
Always opens the file manager in the directory currently being displayed,
@@ -203,22 +218,14 @@ regardless of what file or subdirectory the point is on."
(if (and current-dir (file-exists-p current-dir))
(progn
(message "Opening file manager in %s..." current-dir)
- ;; Use shell-command with & to run asynchronously and detached
- (let ((process-connection-type nil)) ; Use pipe instead of pty
- (cond
- ;; Linux/Unix with xdg-open
- ((executable-find "xdg-open")
- (call-process "xdg-open" nil 0 nil current-dir))
- ;; macOS
- ((eq system-type 'darwin)
- (call-process "open" nil 0 nil current-dir))
- ;; Windows
- ((eq system-type 'windows-nt)
- (call-process "explorer" nil 0 nil current-dir))
- ;; Fallback to shell-command
- (t
+ ;; Use pipe instead of pty for the async call-process below.
+ (let* ((process-connection-type nil)
+ (program (cj/--file-manager-program-for
+ (executable-find "xdg-open") system-type)))
+ (if program
+ (call-process program nil 0 nil current-dir)
(shell-command (format "xdg-open %s &"
- (shell-quote-argument current-dir)))))))
+ (shell-quote-argument current-dir))))))
(message "Could not determine current directory."))))
(defun cj/--wallpaper-program-for (env)