From f8bcdf5ce4f0098d4a106a0c307c406f2ce2739a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Wed, 2 Oct 2024 15:23:06 +0800 Subject: [PATCH] New function shell-command-do-open * lisp/dired-aux.el (shell-command-do-open): Factor out of dired-do-open. (dired-do-open): Call shell-command-do-open. * etc/NEWS: Announce the new function. (cherry picked from commit 9e51815265b9837a8311ee28af39e6b78dd18e29) --- etc/NEWS | 7 +++++++ lisp/dired-aux.el | 34 ++++++++++++++++++++-------------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 39ca829be93..ea1aefe00c1 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -531,6 +531,13 @@ the first clause that matches will cause its body to be evaluated. users might find less cryptic. See the Info node "(elisp) cond* Macro" for details. +--- +** New function 'shell-command-do-open'. +This lets a Lisp program access the core functionality of the +'dired-do-open' command. It opens a file or files using an external +program, choosing the program according to the operating system's +conventions. + * Changes in Emacs 31.1 on Non-Free Operating Systems diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index b8dd1a876ce..1be8b9334bd 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -1440,21 +1440,11 @@ This excludes `dired-guess-shell-alist-user' and (declare-function w32-shell-execute "w32fns.c") ;;;###autoload -(defun dired-do-open (&optional arg) - "Open all marked (or next ARG) files using an external program. +(defun shell-command-do-open (files) + "Open each of FILES using an external program. This \"opens\" the file(s) using the external command that is most -appropriate for the file(s) according to the system conventions. -If files are marked, run the command on each marked file. Otherwise, -run it on the next ARG files, or on the file at mouse-click, or on the -file at point. The appropriate command to \"open\" a file on each -system is determined by `shell-command-guess-open'." - (interactive "P" dired-mode) - (let ((files (if (mouse-event-p last-nonmenu-event) - (save-excursion - (mouse-set-point last-nonmenu-event) - (dired-get-marked-files nil arg)) - (dired-get-marked-files nil arg))) - (command shell-command-guess-open)) +appropriate for the file(s) according to the system conventions." + (let ((command shell-command-guess-open)) (when (and (memq system-type '(windows-nt)) (equal command "start")) (setq command "open")) @@ -1477,6 +1467,22 @@ system is determined by `shell-command-guess-open'." (call-process command nil 0 nil file)))) (error "Open not supported on this system")))) +;;;###autoload +(defun dired-do-open (&optional arg) + "Open all marked (or next ARG) files using an external program. +This \"opens\" the file(s) using the external command that is most +appropriate for the file(s) according to the system conventions. +If files are marked, run the command on each marked file. Otherwise, +run it on the next ARG files, or on the file at mouse-click, or on the +file at point. The appropriate command to \"open\" a file on each +system is determined by `shell-command-guess-open'." + (interactive "P" dired-mode) + (shell-command-do-open (if (mouse-event-p last-nonmenu-event) + (save-excursion + (mouse-set-point last-nonmenu-event) + (dired-get-marked-files nil arg)) + (dired-get-marked-files nil arg)))) + ;;; Commands that delete or redisplay part of the dired buffer -- 2.39.2