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: Emanuel Berg
Subject: Re: How to get the bounds of the current defun?
Date: Sun, 08 Oct 2017 23:00:51 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux)

Michael Heerdegen wrote:

> 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.

(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) ))))

Hm, it seems `end-of-defun' is a bit too
generous - perhaps that can be replaced...

-- 
underground experts united
http://user.it.uu.se/~embe8573




reply via email to

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