GNU Emacs (x86_64-pc-linux-gnu, GTK+ Version 3.10.8) of 2016-04-25
Org-mode version 8.2.10 (release_8.2.10 @ /usr/share/emacs/25.1.50/lisp/org/)

opening a pdf file link (f.ex. [[./9.pdf]]) via C-c C-o automatically opens that file in docview-mode.

How can this be disabled? (Or is this a bug? Where to submit?)

  • 2
    I am on emacs-25 branch and using the master branch of org. For me, pdf files open in my system default application: acroread. What do you see on doing C-h v org-file-apps? I see ((auto-mode . emacs) ("\\.mm\\'" . default) ("\\.x?html?\\'" . default) ("\\.pdf\\'" . "acroread %s")) – Kaushal Modi Jun 3 '16 at 16:04
  • Here is a link to the same question, with no accepted answer: emacs.stackexchange.com/q/2856/2287 The question in this current thread is unclear without reading the recent comment underneath @zck answer. – lawlist Jun 3 '16 at 16:34
  • I had an opportunity to try this today with Emacs -Q without any user-configuration on OSX 10.11.5 (El Capitan) and org-mode version 8.2.10. The example works as advertised by opening up the pdf file in my default system-defined application of Skim.app. Please try with Emacs -Q and see if it works correctly. If it works with Emacs -Q, then something in your user configuration has caused the conflict. Recursively bisect your user configuration by commenting stuff out until you find the culprit. – lawlist Jun 3 '16 at 21:25
  • @KaushalModi: org-file-apps’s value is ((auto-mode . emacs) ("\\.mm\\'" . default) ("\\.x?html?\\'" . default) ("\\.pdf\\'" . default)) – serv-inc Jun 4 '16 at 14:43
  • @lawlist: same behavior for emacs -Q this is the snapshot version. The other question asked about configuration. This is about restoring the default. How would you clarify? (feel free to edit, if you wish) – serv-inc Jun 4 '16 at 14:45

It happens because doc-view was added to mailcap-mime-data; I am using

(defun ensc/mailcap-mime-data-filter (filter)
  (mapcar (lambda(major)
        (append (list (car major))
            (remove nil
                (mapcar (lambda(minor)
                      (when (funcall filter (car major) (car minor) (cdr minor))
                    (cdr major)))))

(defun ensc/no-pdf-doc-view-filter (major minor spec)
  (if (and (string= major "application")
       (string= minor "pdf")
       (member '(viewer . doc-view-mode) spec))

(eval-after-load 'mailcap
     (setq mailcap-mime-data
       (ensc/mailcap-mime-data-filter 'ensc/no-pdf-doc-view-filter))))

to remove corresponding entry.

This does not solve only the org-mode problem but allows e.g. to display PDFs in gnus using an external viewer.

  • Thanks. Evaluating this indeed solves the problem for me. However, this seems to be a bit "crazy" to me, why does the mailcap-mime-data variable contain this setting in the beginning? – Christian Herenz Mar 5 '17 at 19:55

I wanted it to use the previous behavior: the system's pdf viewer.

Then restore the original value of the variable org-file-apps to contain:

((auto-mode . emacs)
 ("\\.pdf\\'" . default))

So whatever is the default viewer on your linux system will be used. To go back to doc-view, put this in your init file:

(add-to-list 'auto-mode-alist '("\\.pdf\\'" . doc-view-mode-maybe))

In any case, as others have pointed out, you'll have to bisect your init file to see what or where your defaults are being changed.

  • As far as I can see, this does not work (on Linux) since default wires to system, which calls mailcap and therein, doc-view-mode is hard coded in the starting value of mailcap-mime-data. – Michaël Oct 16 '18 at 12:50

The thing that determines what mode a file opens in is auto-mode-alist. So we just need to add something to that list that will tell Emacs to use a different mode.

What mode do you want .pdf files to open as? For this answer, I'll assume you want to use fundamental-mode. This won't render the pdf well, but you will be able to view the contents of the pdf. Add this code to your init file, and eval it or restart Emacs:

(add-to-list 'auto-mode-alist '("\\.pdf\\'" . fundamental-mode))

As mentioned, you'll want to replace fundamental-mode with the mode you want pdfs to open in.

  • I wanted it to use the previous behavior: the system's pdf viewer. Forgive me if it was unclear. – serv-inc Jun 3 '16 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.