]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/dired-aux.el (shell-command-guess-open): New defcustom (bug#18132).
authorJuri Linkov <juri@linkov.net>
Thu, 30 Nov 2023 17:39:16 +0000 (19:39 +0200)
committerJuri Linkov <juri@linkov.net>
Thu, 30 Nov 2023 17:39:16 +0000 (19:39 +0200)
(shell-command-guess-open): New function.
(shell-command-guess-functions): Add 'shell-command-guess-open' to choice.

etc/NEWS
lisp/dired-aux.el

index 6661ac70e1be6a18e44c5796cedcbffa9ff9c435..db8a47fd739f51eef94274819abaf92109449049 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -505,9 +505,11 @@ default is nil.
 
 *** New user option 'shell-command-guess-functions'.
 It defines how to populate a list of commands available
-for 'M-!', 'M-&', '!', '&' based on marked files in Dired.
-Possible backends are 'dired-guess-default', MIME types,
-XDG configuration.
+for 'M-!', 'M-&', '!', '&' and the context menu "Open With"
+based on marked files in Dired.  Possible backends are
+'dired-guess-default', MIME types, XDG configuration
+and a universal command such as "open" or "start"
+that delegates to the OS.
 
 ** Ediff
 
index 47e97c96ce10ffd8dec0bcdb21c2d4c6441da0d3..94ca5ddbcc3c0706e93b10eded71a287956d5bf0 100644 (file)
@@ -1329,6 +1329,7 @@ such as added new commands."
           (choice (function-item shell-command-guess-dired)
                   (function-item shell-command-guess-mailcap)
                   (function-item shell-command-guess-xdg)
+                  (function-item shell-command-guess-open)
                   (function :tag "Custom function")))
   :group 'dired
   :version "30.1")
@@ -1380,6 +1381,27 @@ after adding own commands to the composite list."
                   xdg-mime-apps)))
     (append xdg-commands commands)))
 
+(defcustom shell-command-guess-open
+  (cond
+   ((executable-find "xdg-open")
+    "xdg-open")
+   ((memq system-type '(gnu/linux darwin))
+    "open")
+   ((memq system-type '(windows-nt ms-dos))
+    "start")
+   ((eq system-type 'cygwin)
+    "cygstart")
+   ((executable-find "run-mailcap")
+    "run-mailcap"))
+  "A shell command to open a file externally."
+  :type 'string
+  :group 'dired
+  :version "30.1")
+
+(defun shell-command-guess-open (commands _files)
+  "Populate COMMANDS by the `open' command."
+  (append (ensure-list shell-command-guess-open) commands))
+
 \f
 ;;; Commands that delete or redisplay part of the dired buffer