I want to open a pdf with evince instead of DocView mode. Is there a possibility to open a file with a specific command like 'evince'?
8 Answers
Yes. Use !
while in dired to run a shell command on a file.
In the case of evince
, it's smarter to use &
, though, which will run the command asynchronously, so emacs will still be usable while you have the PDF open.

- 75,757
- 21
- 156
- 151
-
4Note that you can customize the default command used by `!` via `dired-guess-shell-alist-user` from `dired-x`: `(setq dired-guess-shell-alist-user '(("\\.pdf\\'" "evince")))` – Resigned June 2023 Apr 02 '18 at 21:30
-
i wish i have read through before I tried it. :-) appending & in the end works well – Boson Bear Jul 26 '20 at 12:33
There is more then one way to do that. I suggest OpenWith library. Setup for your case may look like that:
(add-to-list 'load-path "/path/to/downloaded/openwith.el")
(require 'openwith)
(setq openwith-associations '(("\\.pdf\\'" "evince" (file))))
(openwith-mode t)
It sets file handler that will work from both dired
and find-file
.

- 11,895
- 1
- 29
- 38
-
4At least in Mac OSX, I replaced `evince` with `open`, and then it uses the default software (`Skim` in my case). – Dror Aug 22 '13 at 09:27
-
3Note that in this case you would just hit `RET` on the file name in dired instead of using `!` or `&` to run a shell command. You also lose all the built in associations by using setq on openwith-associations. Might there be a better way to change only the pdf association while leaving in associations for .mp3, .jpg, ... ? – Stefan Avey Oct 22 '14 at 15:06
-
Yes, there is an easy way to change the pdf association without losing the others: M-x customize-group RET openwith RET – Jorge Feb 07 '15 at 10:57
-
1In my OS 10.11, after substituting `evince` with `open`, PDF files are opened by Preview. – Zoe Rowa Nov 09 '15 at 02:41
Try this.
(defun dired-open-file ()
"In dired, open the file named on this line."
(interactive)
(let* ((file (dired-get-filename nil t)))
(message "Opening %s..." file)
(call-process "gnome-open" nil 0 nil file)
(message "Opening %s done" file)))

- 1,156
- 1
- 9
- 14
-
5This worked nicely. I replace `gnome-open` with `xdg-open`, in case of use in another GUI such as KDE. – Brady Trainor Mar 23 '14 at 20:02
Note that you can keep the process alive after exiting Emacs by using nohup
[Wikipedia], so put the point on a single file in dired
:
C-u ! nohup evince ? &
which creates a Persistent Processes [EmacsWiki].

- 6,848
- 7
- 37
- 46
(defun dired-open()
(interactive)
(setq file (dired-get-file-for-visit))
(setq ext (file-name-extension file))
(cond ((string= ext "pdf")
;; shell-quote-argument escapes white spaces on the file name
(async-shell-command (concat "zathura " (shell-quote-argument file))))
((string= ext "epub")
(async-shell-command (concat "zathura " (shell-quote-argument file))))
((string= ext "rar")
(async-shell-command (concat "file-roller " (shell-quote-argument file))))
((string= ext "zip")
(async-shell-command (concat "file-roller " (shell-quote-argument file))))
(t (dired-find-file))))

- 327
- 1
- 3
- 11
Another windows OS solution using explorer.exe
to open single/multiple files. To open multiple files, mark the file using m
in dired
and then hit o
to open multiple files. To just open a single file under point hit o
. I have tested it in Emacs 28.2 GUI running natively on windows (no WSL/Cygwin/Linux-on-Windows).
(use-package dired
:bind (:map dired-mode-map
("o" . jr/dired-open))
:config
(defun jr/dired-open ()
(interactive)
(if-let ((marks (dired-get-marked-files)))
(dolist (file marks)
(shell-command (format "explorer.exe %s" (file-name-nondirectory file))))
(user-error "No marked files; aborting"))))

- 1,813
- 17
- 23