unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* cc-mode case label brace indentation
@ 2009-12-23 19:17 David Spain
  2009-12-23 19:48 ` Pascal J. Bourguignon
  0 siblings, 1 reply; 2+ messages in thread
From: David Spain @ 2009-12-23 19:17 UTC (permalink / raw)
  To: help-gnu-emacs

I would like to go from this form of indentation of
braces within a case labe in cc-mode:

   switch (arg) {
       case 0:
       {
           item1;
           item2;
           item3;
           break;
       }
       ...
       default:
       {
           item1;
           item2;
           break;
       }


to this:

   switch (arg) {
       case 0: {
           item1;
           item2;
           item3;
           break;
       }
       ...
       default: {
           item1;
           item2;
           break;
       }


Any easy way to customize cc-mode to do this?

Dave


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: cc-mode case label brace indentation
  2009-12-23 19:17 cc-mode case label brace indentation David Spain
@ 2009-12-23 19:48 ` Pascal J. Bourguignon
  0 siblings, 0 replies; 2+ messages in thread
From: Pascal J. Bourguignon @ 2009-12-23 19:48 UTC (permalink / raw)
  To: help-gnu-emacs

David Spain <nospam@127.0.0.1> writes:

> I would like to go from this form of indentation of
> braces within a case labe in cc-mode:
>
>    switch (arg) {
>        case 0:
>        {
>            item1;
>            item2;
>            item3;
>            break;
>        }
>        ...
>        default:
>        {
>            item1;
>            item2;
>            break;
>        }
>
>
> to this:
>
>    switch (arg) {
>        case 0: {
>            item1;
>            item2;
>            item3;
>            break;
>        }
>        ...
>        default: {
>            item1;
>            item2;
>            break;
>        }
>
>
> Any easy way to customize cc-mode to do this?

No, but you can write easily an emacs command to do that.

(defun beautify-case-braces ()
  (interactive)
  (beginning-of-buffer)
  (while (re-search-forward "\\<\\(case .*:\\|default[ \t\n]*:\\)[ \t\n]*{" nil t)
     (let ((case-text (buffer-substring (match-beginning 1) (match-end 1))))
       (delete-region (match-beginning 0) (match-end 0))
       (insert case-text " {"))))


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
The rule for today:
Touch my tail, I shred your hand.
New rule tomorrow.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-12-23 19:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-23 19:17 cc-mode case label brace indentation David Spain
2009-12-23 19:48 ` Pascal J. Bourguignon

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).