emacs-devel
[Top][All Lists]
Advanced

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

Re: beginning-of-defun (again)


From: Oleh Krehel
Subject: Re: beginning-of-defun (again)
Date: Fri, 30 Oct 2015 10:29:58 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

John Wiegley <address@hidden> writes:

>>>>>> Richard Stallman <address@hidden> writes:
>
>> Is there a specific practical reason why it is important for the defuns in
>> init.el not to start in column 0?
>
> They are within macros controlling whether they are evaluated or compiled or
> not, based on available packages on the system.

If they are within macros, they're data and not defuns in my mind. For
me, a defun is a top-level expression with "(" at column 0.  It doesn't
even need to define something callable (like `defun' or `defmacro'), so
a `defcustom' statement is a defun for purposes of `beginning-of-defun'.

> I'm not particularly disturbed by the fact that beginning-of-defun doesn't
> work for these functions, however.

Nor it should, unless we hook up a static code analyzer to Emacs and
make `beginning-of-defun' use that data:

(defun semantic-beginning-of-defun ()
  (interactive)
  (semantic-mode 1)
  (let ((tag-starts
         (mapcar
          (lambda (x)
            (semantic-tag-start x))
          (cl-remove-if-not
           (lambda (x)
             (eq (semantic-tag-class x) 'function))
           (semantic-fetch-tags))))
        pt)
    (while (and tag-starts (< (car tag-starts) (point)))
      (setq pt (pop tag-starts)))
    (goto-char pt)))

But it would be silly to use the above approach unless
`semantic-fetch-tags' is made somehow very fast and very smart.
The column 0 heuristic is a perfectly fine and fast alternative.

Besides, guess where the above function would bring me from this
situation (| is the point):

(defun ...)
(defvar ...)
(defvar ...)
(defvar ...|)

Would anyone actually want that behavior on "C-M-a", which is basically
(re-search-backward "(defun") at this point?









reply via email to

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