emacs-devel
[Top][All Lists]
Advanced

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

Re: regression: filling comments in C++ code (today's CVS)


From: Martin Stjernholm
Subject: Re: regression: filling comments in C++ code (today's CVS)
Date: 09 Feb 2003 02:31:23 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

[Sorry for the late reply.]

"Stefan Monnier" <monnier+gnu/address@hidden> wrote:

> > Well, it's not that Kyle E Jones just was being stupid when he wrote
> > filladapt. He can't do it any better way since there's no hook to
> > replace fill-context-prefix which implements adaptive-fill-mode.
> 
> I don't understand.  Why can't filladapt check (and call)
> fill-paragraph-function before doing anything else ?

I.e. filladapt still overrides fill-paragraph but it checks
fill-paragraph-function earlier itself. You're right, it could do
that.

CC Mode would still have to use fill-paragraph-function in a fairly
convoluted way, though:

1.  fill-paragraph is called.
2.  c-fill-paragraph is called by fill-paragraph-function. It does its
    comment masking etc. Then it dynamically binds
    fill-paragraph-function to nil and calls fill-paragraph again.
3.  fill-paragraph now runs a second time and performs its default
    action.
4.  c-fill-paragraph cleans up the masking, restores
    fill-paragraph-function and returns.
5.  fill-paragraph returns.

That'd be workable, but it's not a very pretty solution. A potential
problem is if fill-paragraph has some recursion detection (it often
has, but in the versions I've checked that wouldn't affect this case).

A cleaner approach would be to make fill-paragraph a function that
only calls fill-paragraph-function and move the current functionality
in it to a function that is installed on fill-paragraph-function by
default. CC Mode could then install a function on
fill-paragraph-function that chains on to the previous one. (Other
packages like filladapt would do the same and some effort would be
necessary in CC Mode to ensure it is installed last, but it's usually
not very difficult for a major mode to do that.)

Anyway, there are compatibility problems with this suggestion, so it's
probably easier just to live with it.

> > It'd be nice if fill.el provided a function that only did the pure
> > text filling between two positions, preferably also with the option to
> 
> Isn't that what fill-region-as-paragraph does ?

It has adaptive-fill-mode stuff hardcoded. Although easy to shut down
by covering the adaptive-fill-mode variable, it'd be cleaner to have
a basic filling function that doesn't have any such "surprises".

It's also line oriented if I remember correctly, so it can affect
parts of the lines that are outside the two positions. A fairly
peculiar case but still something that CC Mode has to do some trickery
for so that code close by a comment doesn't get filled too.

And for some reason it skips empty lines at the beginning of the
region, something that should be up to the caller to do. It might
contain other similar oddities too.

> That would help in the "normal" case, so the question is not "would it
> work with filladapt" but "would it hurt with filladapt".
> AFAIK it can't hurt, but I don't know enough about filladapt (or about
> cc-mode's filling) to be sure.

No, it probably wouldn't. I'll make that change.





reply via email to

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