emacs-devel
[Top][All Lists]
Advanced

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

Re: cc-mode adds newlines


From: Alan Mackenzie
Subject: Re: cc-mode adds newlines
Date: Sun, 21 Nov 2004 13:52:49 +0000 (GMT)

Hi, Andries!

On Sun, 21 Nov 2004, Andries Brouwer wrote:

>On Sun, Nov 21, 2004 at 11:41:34AM +0000, Alan Mackenzie wrote:

>> I've had a search through the archives.  I found your bug report in
>> gnu.emacs.bug recently, and a previous bug report (strangely enough, with
>> exactly the same subject, "cc-mode adds newlines" ;-), from
>> Heinrich Rommerskirchen <address@hidden> on Thu, 23
>> Jan 2003 13:17:12.  Maybe you've read through that thread already.  That
>> also lead to discussion on the CC Mode mailing list (archived on
>> <http://cc-mode.sourceforge.net> somewhere), which led to the
>> introduction of `c-require-final-newline'.

>> Heinrich Rommerskirchen's complaint was that c-mode silently set
>> require-final-newline to t without him being able to do anything about
>> it.  c-require-final-newline was the answer to that, giving people a way
>> to "do something about it".  It was given the default value ((c-mode . t)
>> (c++-mode .t) (objc-mode .t)) so as not to change the behaviour for users
>> used to the old way.

>Yes, indeed. Heinrich Rommerskirchen wrote:

>    cc-mode tries to be smart and adds newlines to a file without
>    informing the user and without any easily found option to suppress
>    it.

>You see - nobody wants c-require-final-newline.

Untrue - Alfred M. Szmidt, for one, wants it.  If nobody wanted it, it
wouldn't have been implemented.

>It is a misfeature. Heinrich Rommerskirchen hated getting a final
>newline added by emacs behind his back. I hate it.

Yes, I think that's clear by now.  ;-)  The difference is, Heinrich had
no easy way of disabling this "feature".  Thanks to his bug report, you
do (assuming you've got CC Mode >= 5.30.  If you haven't, get 5.30.9 from
<http://cc-mode.sourceforge.net.release.php>).

>One does not become happier if there is a complicated way to make emacs
>not do it. Emacs should not do it in the first place.

It is a simple way.  The only difficult thing about it is discovering its
existence.

>This misfeature was only added because cc-mode had another misfeature:
>it blindly overrides global variable settings.

Yes indeed, but not blindly.  For example, it changes the
paragraph-start and paragraph-separate variables to recognise
comment-prefices (the "* " you have at the beginning of each comment
line), so that when you do M-q in a block comment, it doesn't just jumble
the entire comment into a compact mess.

>That makes life much more difficult for users. If they do something
>globally, they also have to make the same change locally for all
>major modes they will encounter, in order to have a uniform interface.

Users often want these things set differently in different modes.

>require-final-newline is a beautiful variable. Set it to ask by default
>and some people will make it always true, some will make it always false.
>Many will leave it to ask.

And some will want it t in C Mode and nil in Text Mode, and really don't
want to be bothered answering the question "Add one? (y or n)" twenty
times a day.

>c-require-final-newline is an ugly bug. Who will change its value?

_You_ will.  By putting the correct (for you) setting of it in your
.emacs file.

>Only people who have been bitten by the fact that emacs changed their
>files, spent time in debugging, spent time in searching the docs, spent
>time in searching the net. And when c-require-final-newline is just
>equal to require-final-newline and the latter has default ask, then
>nobody is ever bitten.

OK, you've been bitten.  Sorry.  It's happened already and it can't now
be undone.  The criticism in the previous paragraph is fair.  But read
the threads from January 2003, the ones that lead to the creation of that
variable, and see if you can come up with a better solution, given the
conflicting demands of (i) full customizability; (ii) the need to maintain
compatibility with existing behaviour; (iii) the need to keep users
informed about what's being done; (iv) the need not to irritate users
with excessive "are you sure?" type questions; .....

>If you insist that c-require-final-newline must exist, also that
>must have default ask. But there is really no reason why
>anybody would set it differently from require-final-newline.

Yes there is - To have appropriate (but different) values in Text Mode, C
Mode and AWK Mode, to name just three.  And if we changed the default
value to ask, complaints from other people would start rolling in.
That's guaranteed.  ;-(

>If one only edits text files, set require-final-newline to true.
>If one sometimes edits arbitrary files, set it to ask.
>Also an arbitrary file can have a name ending in .c.
>If one always knows what one is doing and never makes mistakes,
>set it to false.

Other people see things differently.  Emacs tries to cater for all
different tastes and preferences, and deciding on the Right defaults is
difficult.  Configure your .emacs file so that you won't get caught out
again.  Other than that, I don't think anybody can offer you much more
help.

>Andries

-- 
Alan Mackenzie (Munich, Germany)






reply via email to

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