From c6da14417fa258891a988ae9ad242a4ecf5fdd9e Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Wed, 11 Jun 2025 11:14:01 +0200 Subject: [PATCH] Also show value of special variables in help tooltip --- lisp/emacs-lisp/scope.el | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/lisp/emacs-lisp/scope.el b/lisp/emacs-lisp/scope.el index 236e4f8e9a2..9efd7cc5e0f 100644 --- a/lisp/emacs-lisp/scope.el +++ b/lisp/emacs-lisp/scope.el @@ -121,10 +121,14 @@ (scope-define-symbol-type variable () :doc "Variable names." :face 'elisp-free-variable - :help (lambda (beg end def) - (cond ((equal beg def) "Local variable definition") - (def "Local variable") - (t (elisp--help-echo beg end 'variable-documentation "Special variable")))) + :help (lambda (beg end _def) + (if-let ((sym (intern (buffer-substring-no-properties beg end)))) + (lambda (&rest _) + (let ((val (if (boundp sym) (truncate-string-to-width (prin1-to-string (symbol-value sym)) 60 nil nil t) "#"))) + (if-let ((doc (documentation-property sym 'variable-documentation t))) + (format "Special variable `%S'.\n\nValue: %s\n\n%s" sym val doc) + (format "Special variable `%S'.\n\nValue: %s" sym val)))) + "Special variable")) :completion (lambda () (let ((local-vars (elisp-local-variables))) (lambda (sym) (or (elisp--shorthand-aware-boundp sym) @@ -263,12 +267,14 @@ :doc "`condition-case' conditions." :face 'elisp-condition :help (lambda (beg end _def) - (lambda (&rest _) - (let ((msg (get (intern (buffer-substring beg end)) 'error-message))) - (apply #'concat - "`condition-case' condition" - (when (and msg (not (string-empty-p msg))) - `(": " ,msg)))))) + (if-let ((sym (intern (buffer-substring-no-properties beg end)))) + (lambda (&rest _) + (let ((msg (get sym 'error-message))) + (apply #'concat + "`condition-case' condition" + (when (and msg (not (string-empty-p msg))) + `(": " ,msg))))) + "`condition-case' condition")) :completion (constantly (lambda (sym) (get sym 'error-conditions))) :namespace 'condition) -- 2.39.5