aboutsummaryrefslogtreecommitdiff
path: root/modules/system-utils.el
diff options
context:
space:
mode:
Diffstat (limited to 'modules/system-utils.el')
-rw-r--r--modules/system-utils.el40
1 files changed, 2 insertions, 38 deletions
diff --git a/modules/system-utils.el b/modules/system-utils.el
index e266cd15..008a5396 100644
--- a/modules/system-utils.el
+++ b/modules/system-utils.el
@@ -24,6 +24,7 @@
;;; Code:
(require 'system-lib)
+(require 'external-open)
(declare-function dired-get-file-for-visit "dired" ())
(declare-function dired-file-name-at-point "dired" ())
@@ -57,13 +58,6 @@
;;; ------------------------------- Open File With ------------------------------
;; TASK: Favor this method over cj/open-this-file-with and add to custom buffer funcs
-(defun cj/--open-with-is-launcher-p (command)
- "Return non-nil if 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 (member command '("xdg-open" "open" "start")) t))
-
(defun cj/open-file-with-command (command)
"Open the current file with COMMAND.
Works in both Dired buffers and regular file buffers. Prompts for a
@@ -74,7 +68,7 @@ detached from Emacs."
(read-file-name "File to open: "))))
(unless (and file (file-exists-p file))
(error "No valid file found or selected"))
- (if (cj/--open-with-is-launcher-p command)
+ (if (cj/external-open-launcher-p command)
(progn
(call-process command nil 0 nil file)
(message "Opening %s with %s..."
@@ -90,36 +84,6 @@ detached from Emacs."
(message "Running %s on %s..."
(file-name-nondirectory file) command)))))
-(defun cj/identify-external-open-command ()
- "Return the OS-default \"open\" command for this host.
-Signals an error if the host is unsupported."
- (cond
- ((env-linux-p) "xdg-open")
- ((env-macos-p) "open")
- ((env-windows-p) "start")
- (t (error "External-open: unsupported host environment"))))
-
-(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*."
- (interactive)
- (let* ((file (expand-file-name
- (or (cj/file-from-context filename)
- (user-error "No file associated with this buffer"))))
- (cmd (cj/identify-external-open-command))
- (logbuf (get-buffer-create "*external-open.log*")))
- (with-current-buffer logbuf
- (goto-char (point-max))
- (insert (format-time-string "[%Y-%m-%d %H:%M:%S] "))
- (insert (format "Opening: %s\n" file)))
- (cond
- ((env-windows-p)
- (w32-shell-execute "open" file))
- (t
- (call-process cmd nil 0 nil file)
- (with-current-buffer logbuf
- (insert " → Launched asynchronously\n"))))
- nil))
;;; ------------------------------ Server Shutdown ------------------------------