Hello,
In many C and C++ headers it is quite common to use a macro to hide special compiler attributes for functions or classes. It would be great, if support for this could be added to cc-mode. Maybe there is a different solution to this problem.
For example:
class MY_API MyClass
{};
MY_API void func();
For gcc MY_API expands to __attribute__ for visiblity, or when the VC compilers or MIN-GW are used the macro expands to the appropriate declspec. Unfortunately, the imenu regexps in cc-menus.el fail to detect such attributed classes and functions. I could modify the regexp in cc-menu.el to make this work. I added this to my .emacs:
(defvar my-c++-class-expression
`("Class"
, (concat
"^[ \t]*" ; <<==== changed to allow macro
"\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>'
"\\(class\\|struct\\)[ \t]+"
"\\([A-Z_]+[ \t]+\\)?" ; there may be a macro
"\\(" ; the string we want to get
"[" c-alnum "_]+" ; class name
"\\(<[^>]+>\\)?" ; possibly explicitly specialized
"\\)"
"\\([ \t\n]\\|\\\\\n\\)*[:{]"
) 4)
"IMenu expression for C++ classes.")
(add-hook 'c-mode-common-hook
(lambda ()
(add-to-list 'imenu-generic-expression my-c++-class-expression)))
This seems to work. But I wasn't able to make it work for functions (like 'MY_API void func();' as shown above).
How could the rexexp in cc-menus.el be changed to make it work with functions?
Is there a different way to make it work? (like telling it to simply ignore "MY_API")
regards,
Marc