]> git.eshelyaron.com Git - emacs.git/commitdiff
Replace anonymous lambda timers with named functions
authorMatthew Bauer <mjbauer95@gmail.com>
Tue, 4 Mar 2025 01:33:15 +0000 (02:33 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 4 Mar 2025 21:05:01 +0000 (22:05 +0100)
* lisp/emacs-lisp/eldoc.el (eldoc--update, eldoc-schedule-timer):
* lisp/jit-lock.el (jit-lock-context--update)
(jit-lock--antiblink-update): New functions broken out from...
* lisp/emacs-lisp/eldoc.el (eldoc-schedule-timer):
* lisp/jit-lock.el (jit-lock-mode, jit-lock--antiblink-post-command):
...here.  Use them as values for timers, to give them readable names
in 'M-x list-timers'.  (Bug#71354)

(cherry picked from commit ec517d1dcf3260b2cf1684566b5e3bf3979eaceb)

lisp/emacs-lisp/eldoc.el
lisp/jit-lock.el

index 37e398002561337ca3816a8783ae903faf4c339c..6c5e3de5d136365fe84bb168fadc0875cded7245 100644 (file)
@@ -257,6 +257,14 @@ See `eldoc-documentation-strategy' for more detail."
     (eldoc-mode 1)))
 
 \f
+(defun eldoc--update ()
+  (when (or eldoc-mode
+            (and global-eldoc-mode
+                 (eldoc--supported-p)))
+    ;; Don't ignore, but also don't full-on signal errors
+    (with-demoted-errors "eldoc error: %s"
+      (eldoc-print-current-symbol-info)) ))
+
 (defun eldoc-schedule-timer ()
   "Ensure `eldoc-timer' is running.
 
@@ -267,13 +275,7 @@ reflect the change."
       (setq eldoc-timer
             (run-with-idle-timer
             eldoc-idle-delay nil
-            (lambda ()
-               (when (or eldoc-mode
-                         (and global-eldoc-mode
-                              (eldoc--supported-p)))
-                 ;; Don't ignore, but also don't full-on signal errors
-                 (with-demoted-errors "eldoc error: %s"
-                   (eldoc-print-current-symbol-info)) )))))
+             #'eldoc--update)))
 
   ;; If user has changed the idle delay, update the timer.
   (cond ((not (= eldoc-idle-delay eldoc-current-idle-delay))
index 4b2b640905c874d927e57adcd092d67f6cb5b37d..711d7ca8caca912786cc3680d8fa547363f29ac3 100644 (file)
@@ -179,6 +179,10 @@ If nil, contextual fontification is disabled.")
 \f
 ;;; JIT lock mode
 
+(defun jit-lock-context--update ()
+  (unless jit-lock--antiblink-grace-timer
+    (jit-lock-context-fontify)))
+
 (defun jit-lock-mode (arg)
   "Toggle Just-in-time Lock mode.
 Turn Just-in-time Lock mode on if and only if ARG is non-nil.
@@ -255,10 +259,7 @@ If you need to debug code run from jit-lock, see `jit-lock-debug-mode'."
     (when (eq jit-lock-contextually t)
       (unless jit-lock-context-timer
         (setq jit-lock-context-timer
-              (run-with-idle-timer jit-lock-context-time t
-                                   (lambda ()
-                                     (unless jit-lock--antiblink-grace-timer
-                                       (jit-lock-context-fontify))))))
+              (run-with-idle-timer jit-lock-context-time t #'jit-lock-context--update)))
       (add-hook 'post-command-hook #'jit-lock--antiblink-post-command nil t)
       (setq jit-lock-context-unfontify-pos
             (or jit-lock-context-unfontify-pos (point-max))))
@@ -706,6 +707,10 @@ will take place when text is fontified stealthily."
               ;; buffer, only jit-lock-context-* will re-fontify it.
               (min jit-lock-context-unfontify-pos jit-lock-start))))))
 
+(defun jit-lock--antiblink-update ()
+  (jit-lock-context-fontify)
+  (setq jit-lock--antiblink-grace-timer nil))
+
 (defun jit-lock--antiblink-post-command ()
   (let* ((new-l-b-p (copy-marker (syntax--lbp)))
          (l-b-p-2 (syntax--lbp 2))
@@ -722,11 +727,7 @@ will take place when text is fontified stealthily."
            (and same-line
                 (null jit-lock--antiblink-string-or-comment) new-s-o-c)
            (setq jit-lock--antiblink-grace-timer
-                 (run-with-idle-timer jit-lock-antiblink-grace nil
-                                      (lambda ()
-                                        (jit-lock-context-fontify)
-                                        (setq jit-lock--antiblink-grace-timer
-                                              nil)))))
+                 (run-with-idle-timer jit-lock-antiblink-grace nil #'jit-lock--antiblink-update)))
           (;; Closed an unterminated multiline string.
            (and same-line
                 (null new-s-o-c) jit-lock--antiblink-string-or-comment)