5

Recently I am indulging in Emacs. I tried to use it as my LaTeX tool, so I installed pdf-tools. If I add

(pdf-tools-install)

in my init file, it will take about 2 seconds to start Emacs. So I want to write a function such that "pdf-tools-install" will run after I open a pdf file. But "add-hook" only works when a major mode is recognized, and we can recognize pdf only after pdf-tools is installed. I think it may relate to regex, but I don't know much about it. Could you help me with this function? Thanks!

  • 2
    Try (add-hook 'doc-view-mode-hook #'pdf-tools-install) – politza Jan 19 '17 at 22:58
  • @politza Sadly it does not work, pdf file is still recognized as Fundamental mode. – Manan Mehta Jan 20 '17 at 5:02
  • 2
    I suggest either install pdf tools in an idle timer, or autoload it and use an eval-after-load. Or both. (Sorry for not providing code I'm on a mobile device) – YoungFrog Jan 20 '17 at 6:42
  • 1
    When I hit C-c C-c in my documents it switches between pdfview and Docview so you could see if pdf-tools is initialize when the pdf is opened after applying politza answer. – Sparx Jan 20 '17 at 8:46
  • 1
    @Manan Mehta But it should be in doc-view-mode. – politza Jan 20 '17 at 21:28
2

Got it to work! Thanks guys!

I added

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

and

(add-hook 'doc-view-mode-hook #'pdf-tools-install)

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.