[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 23:30:15 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20071031 Thunderbird/ Mnenhy/

Stefan Monnier wrote:
>>> It sounds like you want it first in the parent's mode hook.
>> Yes, I think I fall for wishfull thinking there.
>> That is some more lines to implement ;-)
> If you can arrange for all the relevant modes to derive from some new
> `universal-parent-mode', then you just need to make it be first on
> `universal-parent-mode-hook'.

But I do not write most of the major modes. They come from all over the
world ...

I just implemented the code:

    ;; Save local variables before switching major
    (mumamo-save-most-buffer-locals major-mode)
    ;; Restore local variables after switching, but do it in the
    ;; greatest ancestor's mode hook (see `run-mode-hooks'):
    (let (ancestor-hook-sym
          (parent major-mode)
          (restore-fun (lambda ()
                         (mumamo-restore-most-buffer-locals major))))
      ;; We want the greatest ancestor's mode hook:
      (setq parent-hook-sym (intern-soft (concat (symbol-name parent)
      (when parent-hook-sym (setq ancestor-hook-sym parent-hook-sym))
      (while (get parent 'derived-mode-parent)
        (setq parent (get parent 'derived-mode-parent))
        (setq parent-hook-sym (intern-soft (concat (symbol-name parent)
        (when parent-hook-sym (setq ancestor-hook-sym parent-hook-sym)))
      (when ancestor-hook-sym
        ;; Put first in local hook to run it first:
        (add-hook ancestor-hook-sym restore-fun nil t))
      (funcall major) ;; <-------------- Change major mode here
      (if (not ancestor-hook-sym)
          (mumamo-restore-most-buffer-locals major)
        (remove-hook ancestor-hook-sym restore-fun t)))

reply via email to

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