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

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

cc-mode and imenu tags for functions and classes


From: Marc Dürner
Subject: cc-mode and imenu tags for functions and classes
Date: Mon, 5 Oct 2009 10:45:27 +0200

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

reply via email to

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