I want to open several types of files in Dired by different external applications.
For example:
.doc
files with LibreOffice.pdf
files with evince.jpg
files with pinta- etc...
How do i configure this?
Use Dired-x (standard library dired-x.el
: put (require 'dired-x)
in your init file).
Customize option dired-guess-shell-alist-user
. C-h v
tells you:
dired-guess-shell-alist-user
is a variable defined indired-x.el
.Its value is
nil
Documentation:
User-defined alist of rules for suggested commands.
These rules take precedence over the predefined rules in the variable
dired-guess-shell-alist-default
(to which they are prepended).Each element of this list looks like
(REGEXP COMMAND...)
where each
COMMAND
can either be a string or a Lisp expression that evaluates to a string.If this expression needs to consult the name of the file for which the shell commands are being requested, it can access that file name as the variable
file
.If several
COMMAND
s are given, the first one will be the default and the rest will be added temporarily to the history and can be retrieved withM-x previous-history-element
(M-p
) .The variable
dired-guess-shell-case-fold-search
controls whetherREGEXP
is matched case-sensitively.You can customize this variable.
Then just use !
or &
on files in Dired. Use M-n
to retrieve the default value of the program to run, which will come from your entries in the option value.
Using & from dired prompts to open each file with an external application.
Searching and trying, these elisp lines made it work:
(setq dired-guess-shell-alist-user '(("\\.pdf\\'" "evince")
("\\.doc\\'" "libreoffice")
("\\.docx\\'" "libreoffice")
("\\.ppt\\'" "libreoffice")
("\\.pptx\\'" "libreoffice")
("\\.xls\\'" "libreoffice")
("\\.xlsx\\'" "libreoffice")
("\\.jpg\\'" "pinta")
("\\.png\\'" "pinta")
("\\.java\\'" "idea")))
In 2022, and emacs 28.1, all you have to do is
W
Which runs (browse-url-of-dired-file)
and seems to open the file or directory in the default application.