[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Updating dired-guess-shell-alist-default

From: Philip K.
Subject: Re: Updating dired-guess-shell-alist-default
Date: Thu, 09 Jul 2020 18:21:48 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

I've tried to implement something that picks xdg-open or an equivalent
default on other systems, and if not found looks for other popular

Note: The database isn't completely updated, but I wanted to check back
and see if anyone would like to comment on the approach.

"Philip K." <philip@warpmail.net> writes:

> Hi,
> I wonder if anyone else shares my point of view: while useful,
> dired-do-shell-command seems somewhat outdated. Certain file formats
> haven't changed much, and their handling is still ok (.patch, .tar.*,
> .sig) but especially image, video files and documents suggest tools
> that don't seem to be installed by default on most systems (xloadimage,
> xpdf, ...).
> Of course this can be mitigated by using dired-guess-shell-alist-user,
> but I think that this shouldn't be necessary. I usually just map all
> images, videos and documents to xdg-open, and changing the values to
> something like this wouldn't be bad a bad idea, if you ask me
> (especially because xdg-open doesn't block).
> So if not xdg-open (at least on GNU/Linux and other XDG-compliant
> systems), should the default value be changed to something that makes
> dired-do-shell-command more useful, out of the box?

        Philip K.

diff --git a/lisp/dired-x.el b/lisp/dired-x.el
index 873d586ca1..a4bb68ae1f 100644
--- a/lisp/dired-x.el
+++ b/lisp/dired-x.el
@@ -834,6 +834,22 @@ dired-shell-command-history
 (autoload 'Man-support-local-filenames "man")
 (autoload 'vc-responsible-backend "vc")
+(defcustom dired-guess-default-media-command
+  (cond ((eq system-type 'windows-nt)   "start")
+        ((eq system-type 'darwin)       "open")
+        ((executable-find "xdg-open")   "xdg-open"))
+  "Default command to use for opening media files."
+  :type '(choice (const :tag "No default command" nil)
+                 (string :tag "Command"))
+  :version "28.1")
+(defun dired-guess-find-command (&rest cmds)
+  (or dired-guess-default-media-command
+      (catch 'exists
+        (dolist (cmd cmds)
+          (when (executable-find cmd)
+            (throw 'exists cmd))))))
 (defvar dired-guess-shell-alist-default
    (list "\\.tar\\'"
@@ -956,7 +972,9 @@ dired-guess-shell-alist-default
                  " " dired-guess-shell-znew-switches))
    '("\\.pod\\'" "perldoc" "pod2man * | nroff -man")
-   '("\\.dvi\\'" "xdvi" "dvips")       ; preview and printing
+   '("\\.dvi\\'"
+     (dired-guess-find-command "evince" "okular" "atril")
+     "xdvi" "dvips")                    ; preview and printing
    '("\\.au\\'" "play")                        ; play Sun audiofiles
    '("\\.mpe?g\\'\\|\\.avi\\'" "xine -p")
    '("\\.ogg\\'" "ogg123")
@@ -967,16 +985,33 @@ dired-guess-shell-alist-default
    '("\\.sh\\'" "sh")                  ; execute shell scripts
    '("\\.xbm\\'" "bitmap")             ; view X11 bitmaps
    '("\\.gp\\'" "gnuplot")
-   '("\\.p[bgpn]m\\'" "xloadimage")
-   '("\\.gif\\'" "xloadimage")         ; view gif pictures
-   '("\\.tif\\'" "xloadimage")
-   '("\\.png\\'" "display")            ; xloadimage 4.1 doesn't grok PNG
-   '("\\.jpe?g\\'" "xloadimage")
+   '("\\.p[bgpn]m\\'"
+     (dired-guess-find-command "eog" "eom" "feh" "shotwell" "ristretto"
+                               "gthumb" "gwenview")
+     "xloadimage")
+   '("\\.gif\\'"
+     (dired-guess-find-command "eog" "eom" "shotwell" "ristretto"
+                               "gthumb" "gwenview")
+     "xloadimage")
+   '("\\.tif\\'"
+     (dired-guess-find-command "eog" "eom" "feh" "shotwell" "ristretto"
+                               "gthumb" "gwenview")
+     "xloadimage")
+   '("\\.png\\'"
+     (dired-guess-find-command "eog" "eom" "feh" "shotwell" "ristretto"
+                               "gthumb" "gwenview")
+     "display")                      ; xloadimage 4.1 doesn't grok PNG
+   '("\\.jpe?g\\'"
+     (dired-guess-find-command "eog" "eom" "feh" "shotwell" "ristretto"
+                               "gthumb" "gwenview")
+     "xloadimage")
    '("\\.fig\\'" "xfig")               ; edit fig pictures
    '("\\.out\\'" "xgraph")             ; for plotting purposes.
    '("\\.tex\\'" "latex" "tex")
    '("\\.texi\\(nfo\\)?\\'" "makeinfo" "texi2dvi")
-   '("\\.pdf\\'" "xpdf")
+   '("\\.pdf\\'"
+     (dired-guess-find-command "evince" "okular" "atril" "mupdf" "zathura")
+     "xpdf")
    '("\\.doc\\'" "antiword" "strings")
    '("\\.rpm\\'" "rpm -qilp" "rpm -ivh")
    '("\\.dia\\'" "dia")
@@ -1069,9 +1104,10 @@ dired-guess-default
     ;; Return commands or nil if flist is still non-nil.
     ;; Evaluate the commands in order that any logical testing will be done.
-    (if (cdr cmds)
-       (delete-dups (mapcar (lambda (cmd) (eval cmd `((file . ,file)))) cmds))
-      (eval (car cmds) `((file . ,file))))))           ; single command
+    (setq cmds (delete-dups (delq nil (mapcar
+                                       (lambda (cmd) (eval cmd `((file . 
+                                       cmds))))
+    (if (cdr cmds) cmds (car cmds))))
 (defun dired-guess-shell-command (prompt files)
   "Ask user with PROMPT for a shell command, guessing a default from FILES."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]