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

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

Re: How to get the bounds of the current defun?


From: Michael Heerdegen
Subject: Re: How to get the bounds of the current defun?
Date: Mon, 09 Oct 2017 00:21:36 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.60 (gnu/linux)

Emanuel Berg <address@hidden> writes:

> (defun is-defun ()
>   (interactive)
>   (save-excursion
>     (let ((pos   (point))
>           (start (progn (beginning-of-defun) (point)))
>           (end   (progn (end-of-defun)       (point))) )
>       (when (and (<= start pos)
>                  (<=   pos end) )
>         (cons start end) ))))

If it only would be so simple.  But that doesn't work for non-list
top-level expressions - try with point over a number, for example - your
function returns nil.  That is because AFAIK `beginning-of-defun' and
`end-of-defun' only work for listp toplevel expressions.

Hmm, but I guess when paren depth at POS is 0 (syntax-ppss can tell you
that), `scan-sexps' could be used in the way you use
`beginning-of-defun' and `end-of-defun' above to find whether we are
between an expression beginning and the according expression end.


Thanks,

Michael.



reply via email to

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