6
votes

Looking to set a variable under latex mode. The idea is that the value set under latex mode will override the value of the same variable set in the customise section. I am very new to emacs so these are my attempts:

    (add-hook 'LaTeX-mode-hook '(setq line-move-visual t))
    (add-hook 'latex-mode-hook (lambda () (setq line-move-visual t)))

Why do these not work? What should I do instead?

Clarification: looking to set the variable (setq line-move-visual t) as I have it as (setq line-move-visual nil) for all other files

1
The second line should work. How did you set line-move-visual to nil for everything else? Those two settings might be interfering. - legoscia
Sorry, just realised you already mentioned that in your question. Can't think of a reason the second line wouldn't work, then... - legoscia
If you are using the AUCTeX library instead of the built-in tex-mode.el, then how about trying?: (add-hook 'LaTeX-mode-hook (lambda () (setq line-move-visual t))) Everyone who uses AUCTeX gets confused (at the outset) regarding the hooks because they are so similar to the built-in library: gnu.org/software/auctex/manual/auctex/Modes-and-Hooks.html - lawlist
@lawlist Thanks for help everyone, yes you are right, I am using auctex and did not know that a different hook was to be used. I can test this later today. - Saad Attieh

1 Answers

10
votes

If you just setq the variable in your LaTeX-mode-hook it will also have an effect on any other open buffer. It is possible to make the change only effect the current buffer:

(add-hook 'LaTeX-mode-hook
      (lambda ()
        (make-local-variable 'line-move-visual)
        (setq line-move-visual nil)))

Also, please note that the hook for the default mode for LaTeX in Emacs is called latex-mode-hook but the hook when you are using the (far superior) AUCTeX is called LaTeX-mode-hook

EDIT: Changed make-variable-buffer-local to make-local-variable. See comments to this answer.