all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Marc Dürner" <marc.duerner@googlemail.com>
To: help-gnu-emacs@gnu.org
Subject: cc-mode and imenu tags for functions and classes
Date: Mon, 5 Oct 2009 10:45:27 +0200	[thread overview]
Message-ID: <52a7da0f0910050145q4e9d164aje729bb1492d1c414@mail.gmail.com> (raw)

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

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

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

                 reply	other threads:[~2009-10-05  8:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52a7da0f0910050145q4e9d164aje729bb1492d1c414@mail.gmail.com \
    --to=marc.duerner@googlemail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.