From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.help Subject: Re: Check if inside a function definition Date: Thu, 27 Nov 2008 15:46:46 +0000 (UTC) Organization: muc.de e.V. Message-ID: References: <85e7f1c1-c5d7-4f8e-ab2a-d248d4566063@f20g2000yqg.googlegroups.com> NNTP-Posting-Host: lo.gmane.org X-Trace: ger.gmane.org 1227804046 10101 80.91.229.12 (27 Nov 2008 16:40:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Nov 2008 16:40:46 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 27 17:41:50 2008 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 1L5jw4-00071j-Sp for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Nov 2008 17:41:49 +0100 Original-Received: from localhost ([127.0.0.1]:41043 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5juv-0005bE-3a for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Nov 2008 11:40:37 -0500 Original-Path: news.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newsfeed.freenet.de!news.space.net!news.muc.de!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 40 Original-NNTP-Posting-Host: marvin.muc.de Original-X-Trace: colin2.muc.de 1227800806 11878 2001:608:1000::2 (27 Nov 2008 15:46:46 GMT) Original-X-Complaints-To: news-admin@muc.de Original-NNTP-Posting-Date: Thu, 27 Nov 2008 15:46:46 +0000 (UTC) User-Agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (FreeBSD/4.11-RELEASE (i386)) Original-Xref: news.stanford.edu gnu.emacs.help:164830 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:60159 Archived-At: Nordl?w wrote: > Is there a function that check whether I am standing inside a function > in C/C++? Yes. > Is c-in-function-trailer-p the best Emacs can currently do? No. :-) The function you want is `c-where-wrt-brace-construct', the very next function after `c-in-function-trailer-p' in cc-cmds.el. It returns a symbol as detailed in the function's header comment: ;; Return one of these symbols: ;; at-header : we're at the start of a function's header. ;; in-header : we're inside a function's header, this extending right ;; up to the brace. This bit includes any k&r declarations. ;; in-block : we're inside a function's brace block. ;; in-trailer : we're in the area between the "}" and ";" of something ;; like "struct foo {...} bar, baz;". ;; at-function-end : we're just after the closing brace (or semicolon) that ;; terminates the function. ;; outwith-function: we're not at or in any function. Being inside a ;; non-brace construct also counts as 'outwith-function'. 'at-header, 'at-function-end and 'outwith-function, I think, all count as not being being inside a function, though depending on what you want, you might prefer either or both of these boundary symbols to cound as "in". This function is not currently regarded as being in the "public interface" part of CC Mode, but I think I'm likely to make it such a function soon. > /Nordl?w -- Alan Mackenzie (Nuremberg, Germany).