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

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

How to get the bounds of the current defun?


From: Michael Heerdegen
Subject: How to get the bounds of the current defun?
Date: Sun, 08 Oct 2017 22:28:29 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux)

Hi,

I need a function that for any elisp mode buffer receives a position as
argument and returns non-nil if inside a defun (i.e. when there is a
top-level expression covering POS).  If this is the case, the return
value is a cons (BEG . END) where BEG and END are the beginning and end
positions of this toplevel sexp.

This seems surprisingly hard, I can only think of solutions that are
really complicated.  The most complicated part is actually to find out
whether the value is non-nil or nil.  Not every toplevel expression
needs to be a list!  If POS is not inside a level of parens, I think I
could use the second element ("character address of start of last
complete sexp terminated") of `syntax-ppss' but that's still a bit of
way from a result.  There are really strange cases like the positions of
space characters in symbol\ with\ spaces.

I want to know if anyone knows some elegant solution I fail to see.


TIA,

Michael.



reply via email to

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