[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
cc-mode adds newlines
From: |
Luc Teirlinck |
Subject: |
cc-mode adds newlines |
Date: |
Thu, 23 Jan 2003 15:25:27 -0600 (CST) |
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.
The purpose of this reply is threefold:
To point out two ways you can get around this, to agree with you and
to point out what I consider to be another small bug in the process.
First way to solve the problem, exhibiting an unrelated small bug (or
so I believe) in the process. It is the long way, but it shows how
you can figure out stuff like this yourself (with some effort).
Do M-x customize-browse.
Click successively on:
Programming
Languages
"group" next to `C'
Then in that list click on
C Mode Common Hook
Now something interesting happens (at least in my situation): `C Mode
Common Hook' suddenly changes into `CC Mode Common Hook'. I consider
this to be a bug (but maybe I am wrong). Firstly, it is confusing.
Secondly, I have nothing against customize's practice of cosmetically
changing variable names, but should the real names not be easily
recoverable from the "cosmetic" ones? There is a c-mode-common-hook,
but, apparently, no cc-mode-common-hook.
Back to the original problem. Click on INS and then insert:
(lambda () (setq require-final-newline nil))
Save for future sessions.
Other way:
Put:
(add-hook 'c-mode-common-hook '(lambda () (setq require-final-newline nil)))
in your .emacs
In my opinion this behaviour is unacceptable. If for some reason I
choose to create a file with no trailing newline, it is not
emacs's
business to change the file silently behind my back.
I agree. The culprit is c-common-init in cc-mode.el which
unconditionally sets require-final-newline to t without telling so in
the mode documentation you get with C-h m. I believe it should either
use a customizable variable c-require-final-newline and tell about it
in the mode documentation, or, maybe better, set require-final-newline
to t if the global default value is t, and to 'maybe if the global
default value is 'maybe or nil. I believe this would be the best of
both worlds: nobody would inadvertently forget one without being
warned and, at the same time, nothing gets done "behind the user's
back".
Sincerely,
Luc Teirlinck.