Replace anonymous lambda timers with named functions

* 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)
This commit is contained in:
Matthew Bauer 2025-03-04 02:33:15 +01:00 committed by Stefan Kangas
parent d9218651b6
commit ec517d1dcf
2 changed files with 19 additions and 16 deletions

View file

@ -267,6 +267,14 @@ See `eldoc-documentation-strategy' for more detail."
(eldoc-mode 1)))
(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.
@ -277,13 +285,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))

View file

@ -179,6 +179,10 @@ If nil, contextual fontification is disabled.")
;;; 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)