Skip to main content
(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))
                    minor))
                    (cdr major)))))
      mailcap-mime-data))

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

(eval-after-load 'mailcap
  '(progn
     (setq mailcap-mime-data
       (ensc/mailcap-mime-data-filter 'ensc/no-pdf-doc-view-filter))))
(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))
                    minor))
                    (cdr major)))))
      mailcap-mime-data))

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

(eval-after-load 'mailcap
  '(progn
     (setq mailcap-mime-data
       (ensc/mailcap-mime-data-filter 'ensc/no-pdf-doc-view-filter))))
(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))
                    minor))
                    (cdr major)))))
      mailcap-mime-data))

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

(eval-after-load 'mailcap
  '(progn
     (setq mailcap-mime-data
       (ensc/mailcap-mime-data-filter 'ensc/no-pdf-doc-view-filter))))
(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))
                    minor))
                    (cdr major)))))
      mailcap-mime-data))

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

(eval-after-load 'mailcap
  '(progn
     (setq mailcap-mime-data
       (ensc/mailcap-mime-data-filter 'ensc/no-pdf-doc-view-filter))))
Source Link
ensc
  • 178
  • 5

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))
                    minor))
                    (cdr major)))))
      mailcap-mime-data))

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

(eval-after-load 'mailcap
  '(progn
     (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.