all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how to disable C++ namespace indentation
@ 2010-01-27 20:53 chun
  2010-01-28  3:44 ` Nevo
  0 siblings, 1 reply; 4+ messages in thread
From: chun @ 2010-01-27 20:53 UTC (permalink / raw)
  To: help-gnu-emacs

In C++, I want to keep other indentations intact except for namespace
brackets, e.g.
namespace a {
struct A {
  int b;
};

void c {
  int d;
}
}

The above is what I want.  I tried (c-set-offset 'innamespace 0).
However it disables automatic indentation at every line when I hit
return.


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

* Re: how to disable C++ namespace indentation
  2010-01-27 20:53 how to disable C++ namespace indentation chun
@ 2010-01-28  3:44 ` Nevo
  2010-01-28  3:53   ` Nevo
       [not found]   ` <mailman.340.1264650842.14305.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Nevo @ 2010-01-28  3:44 UTC (permalink / raw)
  To: chun; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1450 bytes --]

I think the below is probably what you need. "c-offsets-alist" will be read
to add to the base indentation which is default to zero if  I remembered
right.

;; your coding style
(c-add-style "mycodingstyle"
         '((c-basic-offset . 3)
           (c-comment-only-line-offset . 0)
           (c-hanging-braces-alist . ((substatement-open before after)))
           (c-offsets-alist . ((topmost-intro        . 0)
                   (topmost-intro-cont   . 0)
                   (substatement         . 3)
                   (substatement-open    . 0)
                   (statement-case-open  . 3)
                   (statement-cont       . 3)
                   (access-label         . -3)
                   (inclass              . 3)
                   (inline-open          . 3)
                   (innamespace          . 0)
                   ))))

;; treat all tabs to spaces
(defun my-c-mode-hook ()
  (setq c-basic-offset 4)
  (setq indent-tabs-mode nil)
  (setq show-trailing-whitespace t))
;; c++ uses mycodingstyle
(defun my-c++-mode-hook ()
  (c-set-style "mycodingstyle"))

Nevo

2010/1/28 chun <riverofdreams@gmail.com>

> In C++, I want to keep other indentations intact except for namespace
> brackets, e.g.
> namespace a {
> struct A {
>  int b;
> };
>
> void c {
>  int d;
> }
> }
>
> The above is what I want.  I tried (c-set-offset 'innamespace 0).
> However it disables automatic indentation at every line when I hit
> return.
>

[-- Attachment #2: Type: text/html, Size: 1892 bytes --]

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

* Re: how to disable C++ namespace indentation
  2010-01-28  3:44 ` Nevo
@ 2010-01-28  3:53   ` Nevo
       [not found]   ` <mailman.340.1264650842.14305.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: Nevo @ 2010-01-28  3:53 UTC (permalink / raw)
  To: chun; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1763 bytes --]

2010/1/28 Nevo <sakur.deagod@gmail.com>

> I think the below is probably what you need. "c-offsets-alist" will be read
> to add to the base indentation which is default to zero if  I remembered
> right.
>

 Sorry,  forget my last words . "c-offsets-alist" will be read to find a
match for offset to add to the base indentation which is the last anchor
position of the last syntactic element.

>
> ;; your coding style
> (c-add-style "mycodingstyle"
>          '((c-basic-offset . 3)
>            (c-comment-only-line-offset . 0)
>            (c-hanging-braces-alist . ((substatement-open before after)))
>            (c-offsets-alist . ((topmost-intro        . 0)
>                    (topmost-intro-cont   . 0)
>                    (substatement         . 3)
>                    (substatement-open    . 0)
>                    (statement-case-open  . 3)
>                    (statement-cont       . 3)
>                    (access-label         . -3)
>                    (inclass              . 3)
>                    (inline-open          . 3)
>                    (innamespace          . 0)
>                    ))))
>
> ;; treat all tabs to spaces
> (defun my-c-mode-hook ()
>   (setq c-basic-offset 4)
>   (setq indent-tabs-mode nil)
>   (setq show-trailing-whitespace t))
> ;; c++ uses mycodingstyle
> (defun my-c++-mode-hook ()
>   (c-set-style "mycodingstyle"))
>
> Nevo
>
> 2010/1/28 chun <riverofdreams@gmail.com>
>
> In C++, I want to keep other indentations intact except for namespace
>> brackets, e.g.
>> namespace a {
>> struct A {
>>  int b;
>> };
>>
>> void c {
>>  int d;
>> }
>> }
>>
>> The above is what I want.  I tried (c-set-offset 'innamespace 0).
>> However it disables automatic indentation at every line when I hit
>> return.
>>
>
>

[-- Attachment #2: Type: text/html, Size: 2626 bytes --]

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

* Re: how to disable C++ namespace indentation
       [not found]   ` <mailman.340.1264650842.14305.help-gnu-emacs@gnu.org>
@ 2010-01-28  4:16     ` chun
  0 siblings, 0 replies; 4+ messages in thread
From: chun @ 2010-01-28  4:16 UTC (permalink / raw)
  To: help-gnu-emacs

Brilliant. It works. I did a quick merge into my existing .emacs
format like this:

(c-add-style "mycodingstyle"
             '((c-comment-only-line-offset . 0)
               (c-hanging-braces-alist . ((substatement-open before
after)))
               (c-offsets-alist . ((topmost-intro        . 0)
                                   (topmost-intro-cont   . 0)
                                   (substatement         . 3)
                                   (substatement-open    . 0)
                                   (statement-case-open  . 3)
                                   (statement-cont       . 3)
                                   (access-label         . -3)
                                   (inclass              . 3)
                                   (inline-open          . 3)
                                   (innamespace          . 0)
                                   ))))

;; c/c++ mode
(add-hook 'c-mode-common-hook
          '(lambda()
             (c-set-style "mycodingstyle")
             (setq tab-width 2)
             (setq c-basic-offset tab-width)))


Thanks so much for help!!!

Chun


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

end of thread, other threads:[~2010-01-28  4:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-27 20:53 how to disable C++ namespace indentation chun
2010-01-28  3:44 ` Nevo
2010-01-28  3:53   ` Nevo
     [not found]   ` <mailman.340.1264650842.14305.help-gnu-emacs@gnu.org>
2010-01-28  4:16     ` chun

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.