]> git.eshelyaron.com Git - emacs.git/commitdiff
Also show value of special variables in help tooltip
authorEshel Yaron <me@eshelyaron.com>
Wed, 11 Jun 2025 09:14:01 +0000 (11:14 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 11 Jun 2025 09:14:01 +0000 (11:14 +0200)
lisp/emacs-lisp/scope.el

index 236e4f8e9a22cd75187c8bc6b39d7ba665546881..9efd7cc5e0f37bc255a483b86ecb18cc45d495b3 100644 (file)
 (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) "#<unbound>")))
+                  (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)
   :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)