1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-21 06:55:39 +00:00

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.
This commit is contained in:
Sean Whitton 2024-10-02 15:23:06 +08:00
parent 7aa106b8bf
commit 9e51815265
2 changed files with 27 additions and 14 deletions

View File

@ -572,6 +572,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

View File

@ -1451,21 +1451,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"))
@ -1488,6 +1478,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