From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Marc_D=FCrner?= Newsgroups: gmane.emacs.help Subject: cc-mode and imenu tags for functions and classes Date: Mon, 5 Oct 2009 10:45:27 +0200 Message-ID: <52a7da0f0910050145q4e9d164aje729bb1492d1c414@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=00032555950ea4928c04752c2212 X-Trace: ger.gmane.org 1254732384 4002 80.91.229.12 (5 Oct 2009 08:46:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 5 Oct 2009 08:46:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Oct 05 10:46:20 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MujCr-00012g-Vi for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Oct 2009 10:46:11 +0200 Original-Received: from localhost ([127.0.0.1]:49980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MujCr-0005eg-OV for geh-help-gnu-emacs@m.gmane.org; Mon, 05 Oct 2009 04:46:09 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MujCL-0005df-Vm for help-gnu-emacs@gnu.org; Mon, 05 Oct 2009 04:45:38 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MujCG-0005b3-2i for help-gnu-emacs@gnu.org; Mon, 05 Oct 2009 04:45:36 -0400 Original-Received: from [199.232.76.173] (port=57841 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MujCF-0005aq-R2 for help-gnu-emacs@gnu.org; Mon, 05 Oct 2009 04:45:31 -0400 Original-Received: from mx20.gnu.org ([199.232.41.8]:17779) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MujCF-0007KK-8q for help-gnu-emacs@gnu.org; Mon, 05 Oct 2009 04:45:31 -0400 Original-Received: from mail-fx0-f205.google.com ([209.85.220.205]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MujCD-0000w7-14 for help-gnu-emacs@gnu.org; Mon, 05 Oct 2009 04:45:29 -0400 Original-Received: by fxm1 with SMTP id 1so2310959fxm.31 for ; Mon, 05 Oct 2009 01:45:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=AhbjZynbKxoTm1ZwjT6hbEjpuL+eB7dQd4iNfrVsJ5A=; b=IoDRkBrrERkfbuMlaHzeBMQTauaLUxq0bSB3hJ9Zb1D+x9g99jsyE56p5jRKc+MNbT W06p2uq9u5RQh7mtSKv2r466pE5RaJiu4CRusjedcDRUlMZniBBa49FjakHZYMuVFdrR vhDXYBhbzSh4sY7QSgusltb7YbAx4KBi73U0A= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=cSh3aZYaeK7GDfBZS5qZItrCn2Ve/qPlwjXEUF86ZtNy5KWOqppjzmhJUZltbDTaqj bi705a2v3zaTo/ZAi8SHm0ktL8t3tEDAYlChYH3+FXLNaln5KqCw2vTV+8BtppXhq8lm 5v+4f4CH05dd4UcVslqxvT3MYGcjEp98wHB9w= Original-Received: by 10.204.24.143 with SMTP id v15mr3526640bkb.182.1254732327063; Mon, 05 Oct 2009 01:45:27 -0700 (PDT) X-detected-operating-system: by mx20.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:68677 Archived-At: --00032555950ea4928c04752c2212 Content-Type: text/plain; charset=ISO-8859-1 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 --00032555950ea4928c04752c2212 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello,

In many C and C++ headers it is quite common to use a macro t= o hide special compiler attributes for functions or classes. It would be gr= eat, if support for this could be added to cc-mode. Maybe there is a differ= ent 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 t= he VC compilers or MIN-GW are used the macro expands to the appropriate dec= lspec. 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 t= o make this work. I added this to my .emacs:

(defvar my-c++-class-expression
=A0=A0=A0 `("Class"
=A0= =A0=A0=A0=A0 , (concat
=A0=A0=A0=A0=A0=A0=A0=A0=A0 "^[ \t]*"= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0 ; <<=3D=3D=3D=3D changed to allow macro
=A0=A0=A0=A0=A0=A0= =A0=A0=A0 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there m= ay be a `template <...>'
=A0=A0=A0=A0=A0=A0=A0=A0=A0 "\\(class\\|struct\\)[ \t]+"
=A0= =A0=A0=A0=A0=A0=A0=A0=A0 "\\([A-Z_]+[ \t]+\\)?"=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0 ; there may be a macro
=A0=A0=A0=A0=A0=A0=A0=A0= =A0 "\\("=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ; the string we want to get
=A0=A0=A0=A0=A0=A0=A0=A0=A0 "[" c-alnum "_]+"=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ; class name
=A0=A0=A0= =A0=A0=A0=A0=A0=A0 "\\(<[^>]+>\\)?"=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 ; possibly explicitly specialized=A0=A0=A0=A0=A0=A0=A0=A0=A0 "\\)"
=A0=A0=A0=A0=A0=A0=A0=A0= =A0 "\\([ \t\n]\\|\\\\\n\\)*[:{]"
=A0=A0=A0=A0=A0=A0=A0=A0=A0 ) 4)
=A0=A0=A0=A0=A0 "IMenu expression = for C++ classes.")

=A0(add-hook 'c-mode-common-hook
=A0= =A0=A0=A0 (lambda ()
=A0=A0=A0=A0=A0=A0=A0=A0 (add-to-list 'imenu-ge= neric-expression my-c++-class-expression)))

This seems to work. But I wasn't able to make it work for functions (li= ke 'MY_API void func();' as shown above).

How could the rexe= xp in cc-menus.el be changed to make it work with functions?
Is there a = different way to make it work?=A0 (like telling it to simply ignore "M= Y_API")

regards,
Marc
--00032555950ea4928c04752c2212--