unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to set up a minor mode depending on a major mode?
@ 2009-05-11 11:43 tomas
  2009-05-11 22:13 ` Lennart Borgman
  2009-05-12 10:45 ` [semi-resolved] How to set up a minor mode depending on a major mode? tomas
  0 siblings, 2 replies; 5+ messages in thread
From: tomas @ 2009-05-11 11:43 UTC (permalink / raw)
  To: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi, Emacs-folks

I'd like to set up some minor mode whenever a major mode is switched on.
I gather that the recommended method seems to be to hook into the major
mode hook like so:

    (add-hook 'am-mode-hook '(lambda () (visual-line-mode t)))

(i.e. switch visual-line-mode on whenever am-mode-hook is swiitched on).

However, this doesn't work, and I have tracked it back to the standard
major-mode machinery doing a (kill-all-local-variables) sweeping away
whatever tidbits the minor mode needs to survive.

Now I could look into the minor mode and declare every variable needed
by it as 'permanent-local, but that feels quite awkward.

Is there a better way? Am I missing something?

Thanks
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFKCA9VBcgs9XrR2kYRAiSeAJ41OIXJiRMKZa4E4BQQunmomBNbAgCePBJh
vaNli5R14hH4NKStCtxi4KA=
=QoKS
-----END PGP SIGNATURE-----




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to set up a minor mode depending on a major mode?
  2009-05-11 11:43 How to set up a minor mode depending on a major mode? tomas
@ 2009-05-11 22:13 ` Lennart Borgman
  2009-05-12  6:43   ` Tassilo Horn
       [not found]   ` <791153ba0905111408m6d4b36f4hfbf86b6290b9e75c@mail.gmail.com>
  2009-05-12 10:45 ` [semi-resolved] How to set up a minor mode depending on a major mode? tomas
  1 sibling, 2 replies; 5+ messages in thread
From: Lennart Borgman @ 2009-05-11 22:13 UTC (permalink / raw)
  To: tomas; +Cc: help-gnu-emacs

On Mon, May 11, 2009 at 1:43 PM,  <tomas@tuxteam.de> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi, Emacs-folks
>
> I'd like to set up some minor mode whenever a major mode is switched on.
> I gather that the recommended method seems to be to hook into the major
> mode hook like so:
>
>    (add-hook 'am-mode-hook '(lambda () (visual-line-mode t)))
>
> (i.e. switch visual-line-mode on whenever am-mode-hook is swiitched on).
>
> However, this doesn't work, and I have tracked it back to the standard
> major-mode machinery doing a (kill-all-local-variables) sweeping away
> whatever tidbits the minor mode needs to survive.


Running the major mode hook should be the very last thing a major mode
does. From your description it sounds like am-mode runs the hook
earlier. That would be a bug.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to set up a minor mode depending on a major mode?
  2009-05-11 22:13 ` Lennart Borgman
@ 2009-05-12  6:43   ` Tassilo Horn
       [not found]   ` <791153ba0905111408m6d4b36f4hfbf86b6290b9e75c@mail.gmail.com>
  1 sibling, 0 replies; 5+ messages in thread
From: Tassilo Horn @ 2009-05-12  6:43 UTC (permalink / raw)
  To: help-gnu-emacs

Lennart Borgman <lennart.borgman@gmail.com> writes:

Hi!

>> I'd like to set up some minor mode whenever a major mode is switched
>> on.  I gather that the recommended method seems to be to hook into
>> the major mode hook like so:
>>
>>    (add-hook 'am-mode-hook '(lambda () (visual-line-mode t)))
>>
>> (i.e. switch visual-line-mode on whenever am-mode-hook is swiitched on).
>>
>> However, this doesn't work, and I have tracked it back to the
>> standard major-mode machinery doing a (kill-all-local-variables)
>> sweeping away whatever tidbits the minor mode needs to survive.
>
> Running the major mode hook should be the very last thing a major mode
> does. From your description it sounds like am-mode runs the hook
> earlier. That would be a bug.

Just a blind guess: Maybe the argument t is not sufficient to turn on
v-l-m.  In general, minor modes are enabled if the function is given a
positive argument, and they're disabled if the argument is negative.

Try

  (add-hook 'am-mode-hook '(lambda () (visual-line-mode 1)))

or even better

  (add-hook 'am-mode-hook 'turn-on-visual-line-mode)

Bye,
Tassilo
-- 
Richard Stallman can touch MC Hammer





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Pilot error [was: How to set up a minor mode depending on a major mode?]
       [not found]   ` <791153ba0905111408m6d4b36f4hfbf86b6290b9e75c@mail.gmail.com>
@ 2009-05-12  9:11     ` tomas
  0 siblings, 0 replies; 5+ messages in thread
From: tomas @ 2009-05-12  9:11 UTC (permalink / raw)
  Cc: help-gnu-emacs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Thanks, Peter, Lennart for your answers annd sorry for my chaos.

On digging deeper, it was actually a *minor* mode trying to set up the
visual-lines mode (I wrote that code. Should have known. Onset of
senility? Sorry for that).

I'll try to debug things a bit further and come back.

[Peter:]
> You must be missing something - but I cannot tell what from this
> information.
> The major mode is supposed to run am-mode-hook as the FINAL act as it is
> starting up [...]

Yes, I gather this from the doc. That's why I was surprised. What brogut
me to the conclusion that someone was wiping away the mode (local)
variables was that declaring visual-line-mode 'permanent-local shows up
the mode lighter in the mode line (of course the visual-lines mode
doesn't work properly, since it probably has lost some vital parts on
the way).

[Lennart:]
> Running the major mode hook should be the very last thing a major mode
> does. From your description it sounds like am-mode runs the hook
> earlier. That would be a bug.

Might still hold for a minor mode. As far as it concerns major modes,
I'll take it back. Shame on me and sorry for the noise.

I'll report on my findings.

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFKCT0oBcgs9XrR2kYRAmJZAJ9EEX0LyabPqK54ynvlgtws+nClRwCcDfjr
RMyt2zhqwFWrHIHZTaTEehM=
=oNtx
-----END PGP SIGNATURE-----




^ permalink raw reply	[flat|nested] 5+ messages in thread

* [semi-resolved] How to set up a minor mode depending on a major mode?
  2009-05-11 11:43 How to set up a minor mode depending on a major mode? tomas
  2009-05-11 22:13 ` Lennart Borgman
@ 2009-05-12 10:45 ` tomas
  1 sibling, 0 replies; 5+ messages in thread
From: tomas @ 2009-05-12 10:45 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: tassilo

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

now I know what happens.

Some background: this am-mode is run as a minor mode because it is
hooked into the format-alist trickery: it gets a chance at a file as it
is loaded, munges it and tries to munge it back on its way out. The
format-alist trickery wants a minor mode (which actually makes sense).

But after things happen, fundamental-mode is invoked (no major mode was
set at the file load stage, I think it's just too early), wiping away
everything which hasn't protected itself. Some moons ago I taught
am-mode to put 'permanent-local on all things it needs, but for a
secondary mode, I'd have to look into it to know which variables to
mark.

So it's back to the drawing board. Perhaps I'll have to construct a
major mode to go with this minor mode (instead of fundamental mode).
This makes some sense anyway.

Any ideas as to how I could hook up this?

Here's the sequence of events when I trace the four functions
run-mode-hooks, am-mode, visual-line-mode, fundamental-mode:

  ======================================================================
  1 -> am-mode: arg=1
  | 2 -> visual-line-mode: arg=t
  | 2 <- visual-line-mode: t
  1 <- am-mode: t
  ======================================================================
  1 -> fundamental-mode: 
  1 <- fundamental-mode: nil

And to Tassilo: yes, (visual-line-mode t) does work, as tested
independently. It's this last fundamental-mode nuking away the subtle
infrastructure of visual-line-mode.

Thanks for all the insights

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFKCVMzBcgs9XrR2kYRApeUAJwNTQCuZKET5mzjRXrDsnfH2NLnqQCfWLnm
OvyQADwE2oAwt2DWhWir+LU=
=lYnf
-----END PGP SIGNATURE-----




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-05-12 10:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-11 11:43 How to set up a minor mode depending on a major mode? tomas
2009-05-11 22:13 ` Lennart Borgman
2009-05-12  6:43   ` Tassilo Horn
     [not found]   ` <791153ba0905111408m6d4b36f4hfbf86b6290b9e75c@mail.gmail.com>
2009-05-12  9:11     ` Pilot error [was: How to set up a minor mode depending on a major mode?] tomas
2009-05-12 10:45 ` [semi-resolved] How to set up a minor mode depending on a major mode? tomas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).