[Top][All Lists]

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

Re: Specifying mode in file variables trouble

From: Lennart Borgman (gmail)
Subject: Re: Specifying mode in file variables trouble
Date: Tue, 23 Sep 2008 19:22:50 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071031 Thunderbird/ Mnenhy/

Stefan Monnier wrote:
>>  set to nil (see the sources for `run-mode-hooks'). I have no idea what
>> delayed-mode-hooks is used for so I do not know if setting
> It is used so that the parent mode hook is run at the end of the (child)
> major mode, so that the user's hook functions (placed on the parent
> hook) can take into account the variable values set by the child.

Thanks. I might be beginning to understand. From what you wrote above
and the somewhat scarse documentation I draw the conclusion that in
normal case the child major modes mode hook is run before the parent
major modes mode hook.

So the order of running the hooks is

   childs local mode hook
     which also include running childs global hook (at the `t')
   parents' mode hooks

If this is correct then I think that adding the call to
mumamo-restore-most-buffer-locals first in the childs local mode hook
would be the best.

The values thus restored can then be changed by things coming later in
the mode hooks.

Since it looks like delay-mode-hook is something that we should not
touch in case we are not the macro delay-mode-hook this is nothing we
have to care about.

So this is what I have got now:

    ;; Save local variables before switching major
    (mumamo-save-most-buffer-locals major-mode)
    ;; Restore local variables after switching, but do it in the mode
    ;; hook:
    (let ((mode-hook (intern-soft (concat (symbol-name major) "-hook")))
          (restore-fun (lambda ()
                         (mumamo-restore-most-buffer-locals major))))
      (when mode-hook
        ;; Put first in local hook to run it first:
        (add-hook mode-hook restore-fun nil t))
      (funcall major) ;; <------- This is the major mode change
      (if (not mode-hook)
          (mumamo-restore-most-buffer-locals major)
        (remove-hook mode-hook restore-fun t)))

reply via email to

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