1

I recently discovered the Emacs Application Framework, which works quite nice for me. The only thing that's bothering me is, that I need to explicitly call eaf-open on a file, to open it with the framework. I tried to associate eaf with the file extension via (add-to-list 'auto-mode-alist '("\\.[pP][dD][fF]\\'" . eaf-mode)) but to no avail.

How can I tell Emacs that it should open PDF files with eaf?

Drew
  • 77,472
  • 10
  • 114
  • 243
Määäxx
  • 13
  • 3
  • 1
    I haven't tested this, but you could create a function that takes the name of the current file and call eaf-open with it. Then add this function in the hook of doc-view-mode. – darcamo Nov 11 '20 at 18:10

1 Answers1

1

You can modify the Emacs file association way by the following code.

(defun adviser-find-file (orig-fn file &rest args)
  (let ((fn (if (commandp 'eaf-open) 'eaf-open orig-fn)))
    (pcase (file-name-extension file)
      ("pdf"  (apply fn file nil))
      ("epub" (apply fn file nil))
      (_      (apply orig-fn file args)))))
(advice-add #'find-file :around #'adviser-find-file)
Muihlinn
  • 2,614
  • 1
  • 15
  • 22