]> git.eshelyaron.com Git - emacs.git/commitdiff
New function shell-command-do-open
authorSean Whitton <spwhitton@spwhitton.name>
Wed, 2 Oct 2024 07:23:06 +0000 (15:23 +0800)
committerEshel Yaron <me@eshelyaron.com>
Thu, 3 Oct 2024 06:42:14 +0000 (08:42 +0200)
* 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
lisp/dired-aux.el

index 39ca829be93dbcb2e4d73d23035d5aa2ed37fe04..ea1aefe00c1aa5a1f7e7c2cd8070406b826c7a42 100644 (file)
--- 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.
+
 \f
 * Changes in Emacs 31.1 on Non-Free Operating Systems
 
index b8dd1a876ce35c16c77b00e3d171dd3b5e88cc91..1be8b9334bdc96333e1d6c1f86bcd31ab4b001db 100644 (file)
@@ -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))))
+
 \f
 ;;; Commands that delete or redisplay part of the dired buffer