Emanuel Berg <
moa...@zoho.com> 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.