From 16396d25c2795bd7f8822a695de111d07f588b26 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 10 May 2026 14:42:04 -0500 Subject: refactor(external-open): consolidate OS-open dispatch in external-open.el Phase 4 of utility-consolidation. Three previously-overlapping helpers (system-utils' `cj/identify-external-open-command' and `cj/--open-with-is-launcher-p', plus the dirvish-only `cj/--file-manager-program-for' shipped earlier today) all answered "which OS-open program should I run?". Pull the answer into one place: external-open.el. Move and rename: - `cj/--open-with-is-launcher-p' (system-utils) -> `cj/external-open-launcher-p' (external-open). Public name now matches its module. - `cj/identify-external-open-command' (system-utils) -> `cj/external-open-command' (external-open). Returns nil for unsupported hosts instead of signaling -- callers that need a command must handle nil explicitly. The wrapper `cj/xdg-open' (also moved into external-open) converts nil to a `user-error' with a clear message, preserving the user-facing failure shape. - Delete dirvish's `cj/--file-manager-program-for' helper. `cj/dirvish-open-file-manager-here' now calls `cj/external-open-command' directly. The shell-command fallback for nil-program preserves the previous escape hatch. Break the system-utils <-> external-open recursive require by moving `cj/xdg-open' (the only system-utils function that external-open used) into external-open along with the dispatch. Tests reorganized to match the move. Two new test files (`test-external-open-command.el', `test-external-open-launcher-p.el') replace the two system-utils-named test files. The dirvish file-manager-program test goes away with the helper. 11 tests covering Normal/Boundary/Error for the dispatch (plus the new "unsupported host returns nil" contract). Add `(require \='external-open)' to system-utils.el and `(require \='system-lib)' to external-open.el (for `cj/file-from-context' which xdg-open uses). --- tests/test-dirvish-config-file-manager-program.el | 54 ----------------------- 1 file changed, 54 deletions(-) delete mode 100644 tests/test-dirvish-config-file-manager-program.el (limited to 'tests/test-dirvish-config-file-manager-program.el') diff --git a/tests/test-dirvish-config-file-manager-program.el b/tests/test-dirvish-config-file-manager-program.el deleted file mode 100644 index bfd4cad9..00000000 --- a/tests/test-dirvish-config-file-manager-program.el +++ /dev/null @@ -1,54 +0,0 @@ -;;; test-dirvish-config-file-manager-program.el --- Tests for the file-manager dispatch -*- lexical-binding: t; -*- - -;;; Commentary: -;; `cj/--file-manager-program-for' is the pure dispatch behind -;; `cj/dirvish-open-file-manager-here'. Given whether xdg-open is -;; present and the running `system-type', it returns the program name -;; the wrapper should call -- or nil to signal the wrapper should fall -;; back to a shell-command. Keeping `executable-find' and `system-type' -;; outside lets the helper be tested without faking the live machine. - -;;; Code: - -(require 'ert) -(require 'package) - -(setq package-user-dir (expand-file-name "elpa" user-emacs-directory)) -(package-initialize) -(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory)) -(add-to-list 'load-path (expand-file-name "elpa/dirvish-2.3.0/extensions" - user-emacs-directory)) -(require 'user-constants) -(require 'keybindings) -(require 'dirvish-config) - -(ert-deftest test-cj--file-manager-program-for-xdg-open-on-linux () - "Normal: xdg-open present on Linux returns xdg-open." - (should (equal (cj/--file-manager-program-for t 'gnu/linux) - "xdg-open"))) - -(ert-deftest test-cj--file-manager-program-for-xdg-open-wins-on-macos () - "Boundary: xdg-open present even on macOS returns xdg-open (Linux-isms ported)." - (should (equal (cj/--file-manager-program-for t 'darwin) - "xdg-open"))) - -(ert-deftest test-cj--file-manager-program-for-darwin-no-xdg () - "Normal: macOS without xdg-open returns open." - (should (equal (cj/--file-manager-program-for nil 'darwin) - "open"))) - -(ert-deftest test-cj--file-manager-program-for-windows-no-xdg () - "Normal: Windows without xdg-open returns explorer." - (should (equal (cj/--file-manager-program-for nil 'windows-nt) - "explorer"))) - -(ert-deftest test-cj--file-manager-program-for-linux-without-xdg-falls-back () - "Boundary: Linux without xdg-open returns nil so the wrapper shells out." - (should-not (cj/--file-manager-program-for nil 'gnu/linux))) - -(ert-deftest test-cj--file-manager-program-for-unknown-system-falls-back () - "Boundary: an unknown `system-type' with no xdg-open returns nil." - (should-not (cj/--file-manager-program-for nil 'haiku))) - -(provide 'test-dirvish-config-file-manager-program) -;;; test-dirvish-config-file-manager-program.el ends here -- cgit v1.2.3