[Top][All Lists]

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

Re: Reify the cc-mode-common into an actual parent mode

From: Alan Mackenzie
Subject: Re: Reify the cc-mode-common into an actual parent mode
Date: Sun, 29 May 2016 10:00:20 +0000
User-agent: Mutt/1.5.24 (2015-08-30)

Hello, Stefan.

On Sat, May 28, 2016 at 02:08:47PM -0400, Stefan Monnier wrote:
> > The canonical way to create a mode derived from CC Mode is to derive
> > from, say, `c-mode', call `c-add-language', then specify the values
> > of the language variables which differ from those of `c-mode'.

> Hmm... you don't seem to preach by example here: none of CC-mode's
> predefined modes inherit from another.

Indeed not.  In this sense, they are "special" modes.

> So I'm not sure "canonical" is the appropriate word.

I think it is.  Although it is certainly open to a mode hacker to go
through cc-langs.el adding in values for every language variable for her
new mode, it is far less troublesome to use `c-add-language', which uses
an existing mode (not necessarily one of the seven "blessed" modes) as a

I'm not aware of anybody attempting to modify CC Mode itself to add an
eigth language into it.

> I also looked at some of the externally maintained major modes that rely
> on CC-mode, and they generally don't seem to derive from any of your
> predefined modes either.

By the way, thanks for listing out these modes in cc-mode.el.  I've only
looked at one or two of them.  csharp-mode.el, for example, does use

> > There's nothing coherent about `c-mode-common'; it isn't sensible to set
> > a buffer to this mode, and it would be erroneous to attempt to derive a
> > mode (other than the seven within CC Mode) directly from it, since the
> > language variables for the new mode wouldn't get initialised.

> Currently all CC modes seem to either derive from prog-mode or from
> fundamental-mode, so they all have the same need to explicitly call
> things like (c-init-language-vars-for <mymode>).  Using c-mode-common
> doesn't make any difference in this respect.

Yes.  `c-init-language-vars-for' is a large part of what distinguishes
one CC mode from another.  This is a bit like how buffer local variables
distinguish between major modes, more or less.

> > modes that have them.  It so happens that, at the moment, those two
> > functions don't affect `c-update-modeline', so things work, but this
> > executing in the wrong order is storing up trouble for the future, should
> > some form in `c-mode''s :after-hook position need executing before
> > `c-update-modeline'.

> The fact that they don't interfere is not an accident, IMO.

Possibly not.

> [ BTW, I notice that define-derived-mode doesn't document the relative
>   order of execution of inherited :after-hooks.  It's probably better
>   that way, admittedly.  ]

A fine point, but maybe you're right.

>         Stefan

Alan Mackenzie (Nuremberg, Germany).

reply via email to

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