views:

110

answers:

1

I often write classes with a DLL export/import specification, but this seems to confuse emacs' syntax parser. I end up with something like:

class myDllSpec Foo {
 public:
  Foo( void );
};

Notice that the "public:" access spec is indented incorrectly, as well as everything that follows it.

When I ask emacs to describe the syntax at the beginning of the line containing public, I get a return of:

((label 352))

If I remove the myDllSpec, the indentation is correct, and emacs tells me that the syntax there is:

((inclass 352) (access-label 352))

Which seems correct and reasonable. So I conclude that the syntax parser is not able to handle the DLL export spec, and that this is what's causing my indentation trouble.

Unfortunately, I don't know how to teach the parser about my labels. Seems that this is pretty common practice, so I'm hoping there's a way around it.

+1  A: 

From http://www.emacswiki.org/emacs/IndentingC#toc13 you can set up a "microsoft" style.

Drop this into your .emacs:

(c-add-style "microsoft"
             '("stroustrup"
               (c-offsets-alist
                (innamespace . -)
                (inline-open . 0)
                (inher-cont . c-lineup-multi-inher)
                (arglist-cont-nonempty . +)
                (template-args-cont . +))))
(setq c-default-style "microsoft")

or leave the default and set it manually via M-x c-set-style to microsoft.

Your example renders this indentation:

class myDllSpec Foo {
public:
    Foo( void );
};
ayman