2

I like to view pdf file in a dired buffer using xpdf. The following code in my ~/.emacs works fine for emacs-24. Just hitting "v" launches the xpdf with file (I stipulated xpdf in my ~/.mailcap file).

(autoload 'mailcap-parse-mailcaps "mailcap" nil t)
(autoload 'mm-mailcap-command "mm-decode")
(defadvice dired-view-file (around use-mailcap-mime-data activate)
"Use an external viewer to view a file according to `mailcap-mime-data'."
(unless (let ((file (dired-get-file-for-visit))
extension type command)
(and (not (file-directory-p file))
(progn
(mailcap-parse-mailcaps)
(setq extension (file-name-extension file)))
(setq type (mailcap-extension-to-mime extension))
(setq command (mailcap-mime-info type))
(setq command (mm-mailcap-command command file nil))
(prog1
t
(shell-command command))))
ad-do-it))

However it stopped working with emacs-25 (emacs-25.0.5.11) with the error

mm-mailcap-command: Wrong type argument: stringp, doc-view-mode

Of course I can run xpdf via a shell command, but I am curious why emacs-25 does not seem to parse mailcaps. I haven't found any answers on the emacs-devel forums.

  • Just out of curiosity, why would you need to decode a pdf file to open it? Why not just open it directly with the pdf viewer using start-process and dired-get-file-for-visit? I am having difficulty understanding why mailcap, mime, etc. are involved in this scenario ...? None of that mailcap stuff should be needed to open a pdf file. – lawlist Jun 14 '15 at 16:43
  • 1
    @lawlist IIUC, he has a general command for opening files which uses mailcap to decide what command to use on each file. It seems to have stopped working specifically on pdfs. – Malabarba Jun 14 '15 at 17:45
2

What's happening

The reason this is happening is that the mailcap-mime-data variable includes an entry for docview-mode and another for xpdf:

(defvar mailcap-mime-data
  `(("application"
     ;; snip
     ("pdf"
      (viewer . doc-view-mode)
      (type . "application/pdf")
      (test . (eq window-system 'x)))
     ("pdf"
      (viewer . "xpdf %s")
      (type . "application/pdf")
      ("print" . ,(concat "pdftops %s - | " mailcap-print-command))
      (test . (eq window-system 'x)))
     ;; snip
     )))

Both entries are viable on your system, and the function mailcap-viewer-lessp then decides that doc-view-mode is prefereable to xpdf.

However, note how the viewer entry there is a symbol, not a string. Whereas the advice you're using assumes that the viewer is a string (shell-command).

How to fix

One way to work around your problem is to remove the docview entry from mailcap-mime-data (you may also have to remove other non-xpdf entries). But the advice you have might run into the same problem for other file formats.

  • Great. Thanks. The problem is indeed with lisp/gnus/mailcap.el. If lines 155-163 are commented out then the problem goes away. It doesn't effect .ps or .djvu files. – m43cap Jun 15 '15 at 12:41

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.