aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2022-08-23 12:26:24 +0200
committerLars Ingebrigtsen2022-08-23 12:26:24 +0200
commit48b0f2606b91dd2a063bef992a2beb13e0f6281b (patch)
treeddb1988890418adee67206f6806c3b3d5d898d0f
parent9d9798521e3457506c08ff9cb6c0d3069c30af00 (diff)
downloademacs-48b0f2606b91dd2a063bef992a2beb13e0f6281b.tar.gz
emacs-48b0f2606b91dd2a063bef992a2beb13e0f6281b.zip
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.
-rw-r--r--lisp/emacs-lisp/lisp-mode.el73
1 files changed, 18 insertions, 55 deletions
diff --git a/lisp/emacs-lisp/lisp-mode.el b/lisp/emacs-lisp/lisp-mode.el
index c56a9660e7c..c906ee6e31d 100644
--- a/lisp/emacs-lisp/lisp-mode.el
+++ b/lisp/emacs-lisp/lisp-mode.el
@@ -728,67 +728,30 @@ font-lock keywords will not be case sensitive."
728 len)))) 728 len))))
729 729
730(defun lisp-current-defun-name () 730(defun lisp-current-defun-name ()
731 "Return the name of the defun at point. 731 "Return the name of the defun at point, or nil."
732If there is no defun at point, return the first symbol from the
733top-level form. If there is no top-level form, return nil.
734
735(\"defun\" here means \"form that defines something\", and is
736decided heuristically.)"
737 (save-excursion 732 (save-excursion
738 (let ((location (point)) 733 (let ((location (point)))
739 name)
740 ;; If we are now precisely at the beginning of a defun, make sure 734 ;; If we are now precisely at the beginning of a defun, make sure
741 ;; beginning-of-defun finds that one rather than the previous one. 735 ;; beginning-of-defun finds that one rather than the previous one.
742 (unless (eobp) 736 (or (eobp) (forward-char 1))
743 (forward-char 1))
744 (beginning-of-defun) 737 (beginning-of-defun)
745 ;; Make sure we are really inside the defun found, not after it. 738 ;; Make sure we are really inside the defun found, not after it.
746 (when (and (looking-at "(") 739 (when (and (looking-at "\\s(")
747 (progn 740 (progn (end-of-defun)
748 (end-of-defun) 741 (< location (point)))
749 (< location (point))) 742 (progn (forward-sexp -1)
750 (progn 743 (>= location (point))))
751 (forward-sexp -1) 744 (if (looking-at "\\s(")
752 (>= location (point)))) 745 (forward-char 1))
753 (when (looking-at "(") 746 ;; Skip the defining construct name, typically "defun" or
754 (forward-char 1))
755 ;; Read the defining construct name, typically "defun" or
756 ;; "defvar". 747 ;; "defvar".
757 (let ((symbol (ignore-errors (read (current-buffer))))) 748 (forward-sexp 1)
758 (when (and symbol (not (symbolp symbol))) 749 ;; The second element is usually a symbol being defined. If it
759 (setq symbol nil)) 750 ;; is not, use the first symbol in it.
760 ;; If there's an edebug spec, use that to determine what the 751 (skip-chars-forward " \t\n'(")
761 ;; name is. 752 (buffer-substring-no-properties (point)
762 (when symbol 753 (progn (forward-sexp 1)
763 (let ((spec (or (get symbol 'edebug-form-spec) 754 (point)))))))
764 (and (eq (get symbol 'lisp-indent-function) 'defun)
765 (get 'defun 'edebug-form-spec)))))
766 (save-excursion
767 (when (and (eq (car-safe spec) '&define)
768 (memq 'name spec))
769 (pop spec)
770 (while (and spec (not name))
771 (let ((candidate (ignore-errors (read (current-buffer)))))
772 (when (eq (pop spec) 'name)
773 (when (and (consp candidate)
774 (symbolp (car (delete 'quote candidate))))
775 (setq candidate (car (delete 'quote candidate))))
776 (setq name candidate
777 spec nil))))))))
778 ;; We didn't have an edebug spec (or couldn't find the
779 ;; name). If the symbol starts with \"def\", then it's
780 ;; likely that the next symbol is the name.
781 (when (and (not name)
782 (string-match-p "\\(\\`\\|-\\)def" (symbol-name symbol)))
783 (when-let ((candidate (ignore-errors (read (current-buffer)))))
784 (cond
785 ((symbolp candidate)
786 (setq name candidate))
787 ((and (consp candidate)
788 (symbolp (car (delete 'quote candidate))))
789 (setq name (car (delete 'quote candidate)))))))
790 (when-let ((result (or name symbol)))
791 (and (symbolp result) (symbol-name result))))))))
792 755
793(defvar-keymap lisp-mode-shared-map 756(defvar-keymap lisp-mode-shared-map
794 :doc "Keymap for commands shared by all sorts of Lisp modes." 757 :doc "Keymap for commands shared by all sorts of Lisp modes."