help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: cc-mode case label brace indentation


From: Pascal J. Bourguignon
Subject: Re: cc-mode case label brace indentation
Date: Wed, 23 Dec 2009 20:48:04 +0100
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux)

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.


reply via email to

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