2

Whenever I open a pdf in emacs, I'd like to increase the font size. I thought I would just place (doc-view-enlarge) in a 'doc-view-mode-hook. However, I can't find such a hook.

Yet this source claims the hook exists:

http://www.r-bloggers.com/using-doc-view-with-auto-revert-to-view-latex-pdf-output-in-emacs/

What is the hook I am looking for in this case?

10
  • Unfortunately, that source is 5+ years old, and it looks like that hook no longer exists.
    – Dan
    Jan 19, 2015 at 15:44
  • 1
    @Dan I see that hook reference in lisp/doc-view.el in emacs 24.4 source. Jan 19, 2015 at 16:08
  • @kaushalmodi: weird: the only hook I have is doc-view-clone-buffer-hook, although I'm on 24.3.
    – Dan
    Jan 19, 2015 at 16:09
  • @Dan That's strange.. I have been using that hook forever now for a different purpose though. (add-hook 'doc-view-mode-hook 'auto-revert-mode) Jan 19, 2015 at 16:11
  • @user84207 What happens when you use the hook? Does emacs give an error? Jan 19, 2015 at 16:19

1 Answer 1

6

Mode hooks exist, whether or not they are predefined variables.

If doc-view-mode is a major mode then doc-view-mode-hook is alive and well.

That is to say that the coding conventions call for a major mode to run its mode hook when the mode is turned on. But typically no hook variable is predefined.

The doc for define-derived-mode tells you that the newly defined mode will run a hook that is constructed by derived-mode-hook-name, which interns the hook name.

In other words, no such variable is defined ahead of time, but when you enter the mode its symbol is interned and bound to a local variable, which is run as a hook (the functions in its value are invoked).

If there happens to be a global variable of the same name then that variable is bound (dynamically). But there need not be such a global variable.

From Elisp, Major Mode Conventions:

 Each major mode should have a normal "mode hook" named
 `MODENAME-mode-hook'.  The very last thing the major mode command
 should do is to call `run-mode-hooks'.  This runs the normal hook
 `change-major-mode-after-body-hook', the mode hook, and then the
 normal hook `after-change-major-mode-hook'.
3
  • Awesome. I did not know this. I thought I was at the mercy of the mode's writer's choice to define a hook, including his choice of a naming convention.
    – erjoalgo
    Jan 20, 2015 at 4:07
  • After reading the doc a bit, if you think it could be improved to make this clearer, consider filing an enhancement request: M-x report-emacs-bug.
    – Drew
    Jan 20, 2015 at 5:33
  • Actually, yeah, that is what I forgot to add. That I'm pretty sure I had read that part of the docs before, but my impression was still what I expressed above.
    – erjoalgo
    Jan 20, 2015 at 6:37

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.