all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: emacs-devel@gnu.org
Subject: Reacting to local var changes in mode-hooks and file-local vars
Date: Fri, 10 Dec 2010 15:31:51 -0500	[thread overview]
Message-ID: <jwvmxod5qo9.fsf-monnier+emacs@gnu.org> (raw)

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	other threads:[~2010-12-10 20:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-10 20:31 Stefan Monnier [this message]
2010-12-16  1:24 ` Reacting to local var changes in mode-hooks and file-local vars Chong Yidong
2010-12-17  4:34   ` Stefan Monnier
2010-12-16  1:39 ` Lennart Borgman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvmxod5qo9.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.