Revert the changes to lisp-current-defun-name

* lisp/emacs-lisp/lisp-mode.el (lisp-current-defun-name): Revert
back to the old version before bug#49592.  The new approach just
doesn't work well enough -- we don't really have the data to know
that, say, `make-obsolete-variable' is about the second symbol and
not the first.
This commit is contained in:
Lars Ingebrigtsen 2022-08-23 12:26:24 +02:00
parent 9d9798521e
commit 48b0f2606b

View file

@ -728,67 +728,30 @@ font-lock keywords will not be case sensitive."
len)))) len))))
(defun lisp-current-defun-name () (defun lisp-current-defun-name ()
"Return the name of the defun at point. "Return the name of the defun at point, or nil."
If there is no defun at point, return the first symbol from the
top-level form. If there is no top-level form, return nil.
(\"defun\" here means \"form that defines something\", and is
decided heuristically.)"
(save-excursion (save-excursion
(let ((location (point)) (let ((location (point)))
name)
;; If we are now precisely at the beginning of a defun, make sure ;; If we are now precisely at the beginning of a defun, make sure
;; beginning-of-defun finds that one rather than the previous one. ;; beginning-of-defun finds that one rather than the previous one.
(unless (eobp) (or (eobp) (forward-char 1))
(forward-char 1))
(beginning-of-defun) (beginning-of-defun)
;; Make sure we are really inside the defun found, not after it. ;; Make sure we are really inside the defun found, not after it.
(when (and (looking-at "(") (when (and (looking-at "\\s(")
(progn (progn (end-of-defun)
(end-of-defun)
(< location (point))) (< location (point)))
(progn (progn (forward-sexp -1)
(forward-sexp -1)
(>= location (point)))) (>= location (point))))
(when (looking-at "(") (if (looking-at "\\s(")
(forward-char 1)) (forward-char 1))
;; Read the defining construct name, typically "defun" or ;; Skip the defining construct name, typically "defun" or
;; "defvar". ;; "defvar".
(let ((symbol (ignore-errors (read (current-buffer))))) (forward-sexp 1)
(when (and symbol (not (symbolp symbol))) ;; The second element is usually a symbol being defined. If it
(setq symbol nil)) ;; is not, use the first symbol in it.
;; If there's an edebug spec, use that to determine what the (skip-chars-forward " \t\n'(")
;; name is. (buffer-substring-no-properties (point)
(when symbol (progn (forward-sexp 1)
(let ((spec (or (get symbol 'edebug-form-spec) (point)))))))
(and (eq (get symbol 'lisp-indent-function) 'defun)
(get 'defun 'edebug-form-spec)))))
(save-excursion
(when (and (eq (car-safe spec) '&define)
(memq 'name spec))
(pop spec)
(while (and spec (not name))
(let ((candidate (ignore-errors (read (current-buffer)))))
(when (eq (pop spec) 'name)
(when (and (consp candidate)
(symbolp (car (delete 'quote candidate))))
(setq candidate (car (delete 'quote candidate))))
(setq name candidate
spec nil))))))))
;; We didn't have an edebug spec (or couldn't find the
;; name). If the symbol starts with \"def\", then it's
;; likely that the next symbol is the name.
(when (and (not name)
(string-match-p "\\(\\`\\|-\\)def" (symbol-name symbol)))
(when-let ((candidate (ignore-errors (read (current-buffer)))))
(cond
((symbolp candidate)
(setq name candidate))
((and (consp candidate)
(symbolp (car (delete 'quote candidate))))
(setq name (car (delete 'quote candidate)))))))
(when-let ((result (or name symbol)))
(and (symbolp result) (symbol-name result))))))))
(defvar-keymap lisp-mode-shared-map (defvar-keymap lisp-mode-shared-map
:doc "Keymap for commands shared by all sorts of Lisp modes." :doc "Keymap for commands shared by all sorts of Lisp modes."