From: Alan Mackenzie <acm@muc.de>
Subject: Re: marrying braket for ?: operator
Date: Sun, 31 Jul 2005 12:20:59 +0000 [thread overview]
Message-ID: <bnficd.46.ln@acm.acm> (raw)
In-Reply-To: 87ll3qaunx.fsf@wash.edu
Baloff <washdc@wash.edu> wrote on 29 Jul 2005 18:22:26 +1000:
[ .... ]
> now that you know my .emacs and the lot how can I get
> enum colors { to go to a new line and indent like when I type say
> main(){ or for(...) {
First remark: this works only when you've got "Auto Newline Mode"
enabled, which you obviously already have. C-c C-a will toggle this
mode.
Second remark: The stuff here is documented in the CC Mode manual on the
pages "Auto-newline Insertion" and "Hanging Braces".
Third remark: Have a look at a C or C++ source file, and type C-c C-s on
a few lines. This will show you the "syntactic context", i.e. CC Mode's
syntactic analysis of the line. Put the { of "enum colors {" on its own
line, and do C-c C-s there. It will tell you that this sort of brace is
a "brace-list-open".
In your CC Mode configuration, you need to change the setting
`c-hanging-brace-alist'. While in a C/C++ buffer, do C-h C-v and have a
look at the value of that variable. It will be something like this:
((brace-list-open) <===================
(block-open after)
(defun-open after)
(substatement-open after)
(block-close . c-snug-do-while))
Each element of this list is itself a list. The first element (e.g.
defun-open) gives the type of the brace, and the other elements (either
"before", "after", both or none[*]), say where CC Mode is to insert the
newlines for this sort of brace.
[*] For advanced uses, a function can be specified here instead.
For your brace-list-open element, I think you want "after", but you can
change that yourself if need be.
OK! Let's now go to your Lisp. Where you've got
(c-add-style "mc394-style"
'("cc-mode"
(c-basic-offset . 3) ; In general, indent 3 spaces
(c-hanging-braces-alist
, you're creating a style called "mc394-style" which inherits from the
style called "cc-mode". Since you're changing the style, you probably
want to give it a new name, say "baloff-style", in a new file called
baloff-style.el. So copy the file and change these lines to this:
(c-add-style "baloff-style"
'("cc-mode"
(c-basic-offset . 3) ; In general, indent 3 spaces
(c-hanging-braces-alist
. A bit lower down, where you've got:
(c-hanging-braces-alist
; These determine whether a newline appears before
; and/or after a brace in various situations.
(brace-list-open)
(block-open after) ; statement block open brace
(defun-open after) ; brace that opens a function definition
(substatement-open after); the brace that opens a substatement block
(block-close . c-snug-do-while))
, change "(brace-list-open)" to "(brace-list-open after)".
Load this new file (M-x load-file), Then from a C++ buffer, do C-c .
(that's "control-C dot"), check your new style has been loaded, and set
your buffer to this style. Check it does what you want, and if it
doesn't, play around with it till it does. Then go through your .emacs,
replacing all references to "mc394-style" with "baloff-style".
Have fun!
--
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").
prev parent reply other threads:[~2005-07-31 12:20 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-07-28 5:20 marrying braket for ?: operator Baloff
2005-07-28 7:48 ` Alan Mackenzie
2005-07-28 20:06 ` Robert Marshall
2005-07-28 20:37 ` Kevin Rodgers
2005-07-28 22:04 ` Alan Mackenzie
2005-07-29 8:22 ` Baloff
2005-07-31 12:20 ` Alan Mackenzie [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bnficd.46.ln@acm.acm \
--to=acm@muc.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).