[Top][All Lists]

[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: Sat, 20 Nov 2004 15:14:24 +0000 (GMT)

Hi, Andries!

On Sat, 20 Nov 2004, Andries Brouwer wrote:

>On Fri, Nov 19, 2004 at 08:27:48PM +0000, Alan Mackenzie wrote:
>> On Fri, 19 Nov 2004, Jari Aalto wrote:

>> >| Working with emacs 21.3.
>> >| Struggled for a while to get emacs to save a file without final newline.
>> >| ...The point is: emacs must not start changing my files without
>> >| being asked.

>> >I agree. The problem is not just in CC mode, but also in other modes
>> >as well. Could someone from the dev team address these below.

>> In CC mode, there is the (customisable) variable
>> c-require-final-newline, an association list, which you can set to
>> either t, nil, or "don't touch!" for each language independently.  The
>> thinking is that some languages' syntaxes absolutely require a final
>> newline (I haven't myself checked if this is true), and that only in
>> those languages (C, C++, Objective-C) is c-require-final-newline set
>> to t. 

>But of course this thinking is flawed. In many ways.

?? ;-)

>It is not the goal of an editor to force the user to write syntactically
>correct programs.

Well, that is debateable.  I'd tend to agree with you, whilst pointing
out that in this case, there was no "force" used [see below].

An equally valid argument is that of the programmer who hacks through the
night and sets off a build (which takes several hours to complete), goes
home for some sleep, then comes back into the office the following
afternoon.  He then finds that the build failed for lack of a final
newline in one of the files.  Then he expostulates "FAQ!  Why couldn't
that stupid editor have put that stupid newline in for me?".

>It is excellent if the editor helps the user, warns for things that
>often are mistakes, etc. But the user is the final authority.

You'll note that, for example, CC Mode warns you about unterminated
strings and unterminated comments.  [Don't laugh - before the days of
syntax highlighting, unterminated comments were the utter devil to find -
often the resulting source was syntactically valid, but the "else" bit of
an "if" got commented out, for example.]

>In this case of newlines emacs considers itself as final authority. That
>is a serious bug. It must ask by default.

No.  It is _your_ copy of Emacs, and it is _your_ choice how you
configure it.  You can actually set Emacs up to ask about final-newlines
first (see the Emacs manual, page "Saving", then use that information to
set c-require-final-newline), but you've probably found that out already.

You'd be surprised just how much people's ideas vary about what the
Obviously Right Thing is.  To me, it's inconceivable that anybody would
want scrolling past the end of a file to add new lines to it, but that
was the default Emacs behaviour until recently.  Right at the moment, I'm
having a discussion with somebody on gnu.emacs.help who can't understand
why anybody would _choose_ to use a text console rather than an X windows
display.  This is the reason that Emacs is so highly customizable.

I think your complaint here is that you didn't know about the setting,
and had no reason to suspect it might exist, and therefore no reason to
spend weeks meticulously searching through the manual for anything random
which might mess up your files.  That's a fair complaint.

It's also fair for me to ask, did you suffer any actual damage (as
opposed to having your sense of what's proper put out of joint) from this
terminating newline?   Something like the source file being an input to
some scriptfile, rather than just being compiled, and that script fouling

>It is not true that all dialects of C require a final newline.

Yes, but _some_ of them do, and more importantly the C standard does.

>The introduction of this alist was a bug.
>The introduction of c-require-final-newline was a bug.
>The variable require-final-newline expresses well what the user wants.

Go out and either (i) spend the night at a disco; or (ii) go for a swim,
or a game of squash; or (ii) get blind drunk for the evening.  By the
time you get back home, c-require-final-newline won't seem so important.

All the best!


Alan Mackenzie (Munich, Germany)

reply via email to

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