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!

Manan Mehta
  • 179
  • 3
  • 2
    Try `(add-hook 'doc-view-mode-hook #'pdf-tools-install)` – politza Jan 19 '17 at 22:58
  • 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 06: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 08:46
  • @politza Sadly it does not work, pdf file is still recognized as Fundamental mode. – Manan Mehta Jan 20 '17 at 05:02
  • 1
    @Manan Mehta But it should be in `doc-view-mode`. – politza Jan 20 '17 at 21:28
  • Do you need to install it every time you start Emacs? I thought the installation is only needed once and you can use it immediately ever after. I could be wrong though. – xji Jan 25 '17 at 20:15

1 Answers1

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)
Manan Mehta
  • 179
  • 3