Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set variable under specific mode emacs

Tags:

emacs

latex

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

like image 907
Saad Attieh Avatar asked Jul 25 '16 10:07

Saad Attieh


People also ask

How do I change modes in Emacs?

Usually, the major mode is automatically set by Emacs, when you first visit a file or create a buffer (see Choosing File Modes). You can explicitly select a new major mode by using an M-x command.

How do I change the value of a variable in a lisp?

The usual way to change the value of a variable is with the special form setq . When you need to compute the choice of variable at run time, use the function set . This special form is the most common method of changing a variable's value.


1 Answers

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.

like image 179
Stefan Kamphausen Avatar answered Sep 28 '22 15:09

Stefan Kamphausen