From: Eshel Yaron Date: Sat, 17 Aug 2024 11:08:07 +0000 (+0200) Subject: Some ElDoc simplifications X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=384fb8657866d2a5a4d08d99a9bb088c3388b251;p=emacs.git Some ElDoc simplifications --- diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index b3fcd43328b..ef28386fa73 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el @@ -246,19 +246,9 @@ expression point is on." :lighter eldoc-minor-mode-string #'eldoc--eval-expression-setup))) (defun eldoc--eval-expression-setup () - ;; Setup `eldoc', similar to `emacs-lisp-mode'. FIXME: Call - ;; `emacs-lisp-mode' itself? - (cond ((<= emacs-major-version 27) - (declare-function elisp-eldoc-documentation-function "elisp-mode") - (with-no-warnings - (add-function :before-until (local 'eldoc-documentation-function) - #'elisp-eldoc-documentation-function))) - (t (add-hook 'eldoc-documentation-functions - #'elisp-eldoc-var-docstring nil t) - (add-hook 'eldoc-documentation-functions - #'elisp-eldoc-funcall nil t) - (setq-local eldoc-documentation-strategy - 'eldoc-documentation-default))) + (add-hook 'eldoc-documentation-functions #'elisp-eldoc-var-docstring nil t) + (add-hook 'eldoc-documentation-functions #'elisp-eldoc-funcall nil t) + (setq-local eldoc-documentation-strategy 'eldoc-documentation-default) (eldoc-mode +1)) ;;;###autoload @@ -731,27 +721,7 @@ This is meant to be used as a value for `eldoc-documentation-strategy'." nil))) t) -;; JT@2020-07-10: ElDoc is pre-loaded, so in Emacs < 28 we can't -;; make the "old" `eldoc-documentation-function' point to the new -;; `eldoc-documentation-strategy', so we do the reverse. This allows -;; for ElDoc to be loaded in those older Emacs versions and work with -;; whomever (major-modes, extensions, user) sets one or the other -;; variable. -(defmacro eldoc--documentation-strategy-defcustom - (main secondary value docstring &rest more) - "Defcustom helper macro for sorting `eldoc-documentation-strategy'." - (declare (indent 2)) - `(if (< emacs-major-version 28) - (progn - (defcustom ,secondary ,value ,docstring ,@more) - (define-obsolete-variable-alias ',main ',secondary "eldoc-1.1.0")) - (progn - (defcustom ,main ,value ,docstring ,@more) - (defvaralias ',secondary ',main ,docstring)))) - -(eldoc--documentation-strategy-defcustom eldoc-documentation-strategy - eldoc-documentation-function - #'eldoc-documentation-default +(defcustom eldoc-documentation-strategy #'eldoc-documentation-default "How to collect and display results of `eldoc-documentation-functions'. This variable controls how to call the functions in the special hook diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index a7cf5c256b7..4322d210152 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -384,11 +384,12 @@ happens in interactive invocations." (scope (lambda (type sym len bind) (if (null bind) - (put-text-property sym (+ sym len) 'face - (cl-case type - (variable 'elisp-free-variable) - (function 'font-lock-function-call-face) - (defun 'font-lock-function-name-face))) + (when-let ((face (cl-case type + (variable 'elisp-free-variable) + (function 'font-lock-function-call-face) + (defun 'font-lock-function-name-face) + (defvar 'font-lock-variable-name-face)))) + (put-text-property sym (+ sym len) 'face face)) (put-text-property sym (+ sym len) 'face (if (equal sym bind) 'elisp-binding-variable @@ -635,7 +636,6 @@ It can be quoted, or be inside a quoted form." (save-excursion (let ((state (syntax-ppss pos))) (or (nth 8 state) ; Code inside strings usually isn't evaluated. - ;; FIXME: The 9th element is undocumented. (let ((nesting (cons (point) (reverse (nth 9 state)))) res) (while (and nesting (not res)) @@ -1938,31 +1938,6 @@ Elements are as follows: or argument string for functions. 2 - `function' if function args, `variable' if variable documentation.") -(defun elisp--documentation-one-liner () - (let* (str - (callback (lambda (doc &rest plist) - (when doc - (setq str - (format "%s: %s" - (propertize (prin1-to-string - (plist-get plist :thing)) - 'face (plist-get plist :face)) - doc)))))) - (or (progn (elisp-eldoc-var-docstring callback) str) - (progn (elisp-eldoc-funcall callback) str)))) - -(defalias 'elisp-eldoc-documentation-function #'elisp--documentation-one-liner - "Return Elisp documentation for the thing at point as one-line string. -This is meant as a backward compatibility aide to the \"old\" -Elisp eldoc behavior. Consider variable docstrings and function -signatures only, in this order. If none applies, returns nil. -Changes to `eldoc-documentation-functions' and -`eldoc-documentation-strategy' are _not_ reflected here. As such -it is preferable to use ElDoc's interfaces directly.") - -(make-obsolete 'elisp-eldoc-documentation-function - "use ElDoc's interfaces instead." "28.1") - (defun elisp-eldoc-funcall (callback &rest _ignored) "Document function call at point by calling CALLBACK. Intended for `eldoc-documentation-functions' (which see)." diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 31152ce11b0..d7a1c90f8a6 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -5676,7 +5676,7 @@ back to t in the affected buffer." :version "25.1") (defun python-eldoc-function (&rest _ignored) - "`eldoc-documentation-function' for Python. + "`eldoc-documentation-functions' entry for Python. For this to work as best as possible you should call `python-shell-send-buffer' from time to time so context in inferior Python process is updated properly. @@ -7094,15 +7094,7 @@ implementations: `python-mode' and `python-ts-mode'." (current-column)))) (^ '(- (1+ (current-indentation)))))) - (with-no-warnings - ;; suppress warnings about eldoc-documentation-function being obsolete - (if (null eldoc-documentation-function) - ;; Emacs<25 - (setq-local eldoc-documentation-function #'python-eldoc-function) - (if (boundp 'eldoc-documentation-functions) - (add-hook 'eldoc-documentation-functions #'python-eldoc-function nil t) - (add-function :before-until (local 'eldoc-documentation-function) - #'python-eldoc-function)))) + (add-hook 'eldoc-documentation-functions #'python-eldoc-function nil t) ;; TODO: Use tree-sitter to figure out the block in `python-ts-mode'. (dolist (mode '(python-mode python-ts-mode))