[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Check if inside a function definition
From: |
Alan Mackenzie |
Subject: |
Re: Check if inside a function definition |
Date: |
Thu, 27 Nov 2008 15:46:46 +0000 (UTC) |
User-agent: |
tin/1.6.2-20030910 ("Pabbay") (UNIX) (FreeBSD/4.11-RELEASE (i386)) |
Nordl?w <per.nordlow@gmail.com> 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).