[Ns-developers] emacs indentation innamespace

Gustavo Carneiro gjcarneiro at gmail.com
Tue Mar 31 04:37:44 PDT 2009


2009/3/31 Nicola Baldo <nbaldo at cttc.es>

> Hi all,
>
> as many of you, I am using emacs for editing ns3 code. The "gnu"
> indentation style mostly conforms to the ns3 coding guidelines, but has a
> few quirks. One of these is that code after "namespace ns3 {" is indented,
> while the ns3 coding style says it should not. This is annoying. Does
> anybody out there have a solution to this problem?
>
> My experience is:
>
> 1) with a ns3 source file already opened, you can type 'C-c C-o innamespace
> <ret> 0 <ret>' and get the desired behavior
>
> 2) I tried to make the setting permanent by adding the following code to my
> ~/.emacs:
>
> (defun my-c-mode-common-hook ()
>  (c-set-offset 'innamespace 0))
> (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
>
> this works for normal C source files, but doesn't work when opening a ns3
> source code file. I think this is due to the option 'c-file-style: "gnu";'
>  in the emacs modeline at the beginning of the source code file: I get the
> impression that it overrides the innamespace setting in .emacs. In fact, if
> I remove 'c-file-style: "gnu";'  from the modeline, the next time I open the
> file I get the desired behavior.
>
> Any hints? It's annoying to do procedure 1) for every file you open...


One option would be to define a new 'ns3' indentation style, adding this to
.emacs:

(c-add-style "ns3"
             '("gnu" (c-offsets-alist . ((innamespace . 0)))))


But then we would have to agree to change all ns-3 source files modelines,
from "gnu" to "ns3"...


-- 
Gustavo J. A. M. Carneiro
INESC Porto, Telecommunications and Multimedia Unit
"The universe is always one step beyond logic." -- Frank Herbert


More information about the Ns-developers mailing list