From: "Philip K." <philip@warpmail.net>
To: emacs-devel@gnu.org
Subject: Re: Updating dired-guess-shell-alist-default
Date: Thu, 09 Jul 2020 18:21:48 +0200 [thread overview]
Message-ID: <87mu483bhf.fsf@warpmail.net> (raw)
In-Reply-To: <87imezhfoo.fsf@warpmail.net> (Philip K.'s message of "Tue, 07 Jul 2020 10:50:31 +0200")
[-- Attachment #1: Type: text/plain, Size: 1243 bytes --]
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
applications.
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.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-x-guess.patch --]
[-- Type: text/x-diff, Size: 3783 bytes --]
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
(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 . ,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."
next prev parent reply other threads:[~2020-07-09 16:21 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-07 8:50 Updating dired-guess-shell-alist-default Philip K.
2020-07-07 14:19 ` Eli Zaretskii
2020-07-07 16:10 ` Philip K.
2020-07-07 18:37 ` Eli Zaretskii
2020-07-07 19:05 ` Philip K.
2020-07-07 19:24 ` Eli Zaretskii
2020-07-07 19:48 ` Stefan Monnier
2020-07-08 2:25 ` Eli Zaretskii
2020-07-08 4:12 ` Stefan Monnier
2020-07-07 19:52 ` Yuri Khan
2020-07-08 2:26 ` Eli Zaretskii
2020-07-08 2:48 ` Michael Welsh Duggan
2020-07-08 7:52 ` tomas
2020-07-07 20:38 ` Philip K.
2020-07-08 2:28 ` Eli Zaretskii
2020-07-08 4:15 ` Stefan Monnier
2020-07-08 14:21 ` Eli Zaretskii
2020-07-08 15:08 ` Stefan Monnier
2020-07-08 8:28 ` Philip K.
2020-07-08 14:24 ` Eli Zaretskii
2020-07-08 14:33 ` Philip K.
2020-07-09 16:21 ` Philip K. [this message]
2020-07-11 10:07 ` Eli Zaretskii
2020-07-11 11:07 ` Philip K.
2020-07-11 11:15 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mu483bhf.fsf@warpmail.net \
--to=philip@warpmail.net \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.