emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Reacting to local var changes in mode-hooks and file-local vars


From: Stefan Monnier
Subject: Reacting to local var changes in mode-hooks and file-local vars
Date: Fri, 10 Dec 2010 15:31:51 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Some major modes currently do things like

   (defun my-mode ()
     ...
     (kill-all-local-variables)
     ...
     (run-mode-hooks 'my-mode-hook)
     ...set up some more vars...)

The "set up some more vars" code is there because those vars may depend
on some other vars that are likely to be changed by the user in the
my-mode-hook.
This is actually a hack.  It works in some cases but has several
downsides, such as:
- can't use define-derived-mode to define such a mode.
- can't derive from this mode since the "set up some more vars" would
  then be run before the child mode hook.
- does not react properly to file-local variable settings.

Currently, the best fix I know is to do:

  (define-derived-mode my-mode nil "My"
    ...
    (add-hook 'hack-local-variables-hook
              (lambda () ...set up some more vars...)
              nil t))

but this also has some downsides:
- hack-local-variables-hook is not run if enable-local-variables is nil.
- hack-local-variables-hook is not run for non-file-modes
  (e.g. comint modes) or when the user does M-x my-mode RET

Another option is to use something like after-change-major-mode-hook.
But that one tends to be called before file-local vars.

I'd like to find a good solution to this problem.  I think part of the
solution is to make it so that M-x my-mode RET will also run
hack-local-variables.

My current idea is to try and make it so that, just before running
after-change-major-mode-hook, we either call hack-local-variables or
hack-dir-local-variables-non-file-buffer.


        Stefan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]