3
votes

Generally, how can I customize the value of a buffer-local variable in Emacs? For example, the variable w3m-lnum-mode is buffer-local, if I set (setq w3m-lnum-mode t) in .emacs, its value in a w3m mode buffer is still nil. How could I set it to t in w3m major mode?

2

2 Answers

2
votes

Major modes have a hook variable for this sort of thing. Look for w3m-mode-hook.

(defun my-w3m-hook nil
  (setq w3m-lnum-mode t))
(add-hook 'w3m-mode-hook #'my-w3m-hook)

The indirection to hook a separate function is not absolutely necessary, but simplifies the management of the hook functionality (otherwise you'd have to restart Emacs or jump through several hoops to add something to an existing hook; now all you need to do is evaluate a new defun of the function called from the hook).

0
votes

You can set a default like so:

(setq-default w3m-lnum-mode t)

For fine-grained control, use a hook as RNAer suggests. As far as I can tell though, this is not a normal local variable but a minor mode variable. You actually probably want to do (w3m-lnum-mode 1).