From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Matthew Bauer Newsgroups: gmane.emacs.bugs Subject: bug#71354: Replace anonymous lambda timers with named functions for better tracing Date: Mon, 03 Jun 2024 22:34:18 -0500 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36488"; mail-complaints-to="usenet@ciao.gmane.io" To: 71354@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 04 05:35:09 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sEKx2-0009JJ-3j for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 04 Jun 2024 05:35:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sEKwl-0000qA-JD; Mon, 03 Jun 2024 23:34:51 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEKwj-0000pj-M9 for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 23:34:49 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sEKwj-0006CJ-DU for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 23:34:49 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sEKww-0000Pz-Hy for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 23:35:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Matthew Bauer Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 04 Jun 2024 03:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71354 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17174720831572 (code B ref -1); Tue, 04 Jun 2024 03:35:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 4 Jun 2024 03:34:43 +0000 Original-Received: from localhost ([127.0.0.1]:56105 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sEKwc-0000PI-SB for submit@debbugs.gnu.org; Mon, 03 Jun 2024 23:34:43 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:59768) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sEKwX-0000P3-Hz for submit@debbugs.gnu.org; Mon, 03 Jun 2024 23:34:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sEKwK-0000oV-3T for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 23:34:24 -0400 Original-Received: from mail-il1-x136.google.com ([2607:f8b0:4864:20::136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sEKwI-0006Ar-DW for bug-gnu-emacs@gnu.org; Mon, 03 Jun 2024 23:34:23 -0400 Original-Received: by mail-il1-x136.google.com with SMTP id e9e14a558f8ab-3748aa28d0fso16726835ab.3 for ; Mon, 03 Jun 2024 20:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717472060; x=1718076860; darn=gnu.org; h=mime-version:message-id:date:subject:to:from:from:to:cc:subject :date:message-id:reply-to; bh=phGPk4dFi3c6nCkQpdpPqUUt8wLPVRYx+nD6Iy5Q+uE=; b=NB45SWLu+V6WAFW2ZJRmyhJBMBD3jZhcQT4PjEub0ZkG3ahbOLSNdK/Vu1neTn7mRR UNx8uUXB1rIBNWeQPBjb2IJOMN08M3ZUtpL+R/W+XsSgKlZMZb2z4CSh20/1bBKNiEk7 UQqQd2ga4TnG9bE3wVAI0yEFx0iDUTV3DW7c1A5LHvV3qoCDsRNXwamRxX3oA8LuMpa+ HASHvV7FCNSh2iCPZl/5fZ9IS93nFgIoUEXhoqebMOZzl0y5qHYyejOYJJfen/CrBFsG 5K1lUw74NlSV3k4HQu0gMwrS1quHwu8spL59VwLy/4qp4cx8rKQOPTqFi3uYknf0pTSU +1Pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717472060; x=1718076860; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=phGPk4dFi3c6nCkQpdpPqUUt8wLPVRYx+nD6Iy5Q+uE=; b=Yyf32uL+8w+nJZ5O8AiQMxTQ245Jjz217WQo89mmjiVwnxoBGH43wK/HzXRu5EBCSf DwNi6oUix8FFIbZva8xk9kq36Dxkkv01z3kGbo8FkQ2mgxp0Hq7yqjtVz3A5kmFZa+ru l1N9OGWJeleraknceRn/A3eCv6UErgyOgjs9XJfeHdPypeHsUN08aqFvtWzVU9Rzsy3e ka3hGahF+h0ve9CXIwEwIgbR8hu1uXv/iKRiPaFRcVQUciAQK22elUquFCl4W6d4qXjx zeR043F7eROHeOxvJy0JOXI3E3Z93CpdHPrRF78gfwND8tShBivEqBIQ001hZoF3ZZTE a+SQ== X-Gm-Message-State: AOJu0Yy2VN+IxPjhCPyy4O3zQ8iwXaxwukDZjVhS6TgMvw3UtuyJb3lK crl5IHVHwW2SiFGM8ltL4FsiVKY2wljK9hxUnO4B+moaQhyILWhypXka5g== X-Google-Smtp-Source: AGHT+IFwXsuUh3/ZMgF4ytFoyP0/q7i1pj/GNL3gUvUfAB3rFq2Z7lIFf2dthkJIgW+3ZPlXyFf1Iw== X-Received: by 2002:a05:6e02:1d85:b0:374:a412:3da1 with SMTP id e9e14a558f8ab-374a4124052mr32817275ab.20.1717472059539; Mon, 03 Jun 2024 20:34:19 -0700 (PDT) Original-Received: from Matthews-MacBook-Pro.local ([2605:a601:acd7:b300:94dd:b366:b19c:6f39]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-374ac67c66csm601955ab.42.2024.06.03.20.34.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jun 2024 20:34:18 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::136; envelope-from=mjbauer95@gmail.com; helo=mail-il1-x136.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:286506 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Tags: patch I noticed a few timers found in =E2=80=98M-x list-timers=E2=80=99 were anon= ymous lambdas that show up like this: * 0.5s t # That=E2=80=99s not particularly helpful when trying to figure out what time= rs are being run. I tracked down the two that I have configured to eldoc and jit-lock. This gives them names that can be traced. In GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin23.5.0, NS appkit-2487.60 Version 14.5 (Build 23F79)) Repository revision: 0cb511b33bc96fc30d8e5286a474b4eea54817e3 Repository branch: master Windowing system distributor 'Apple', version 10.3.2487 System Description: macOS 14.5 Configured using: 'configure --prefix=3D/nix/store/bj6mdh15nkgh2xbdzzsly43m9q7mi0zp-emacs-git-20240531.0 --disable-build-details --with-modules --disable-ns-self-contained --with-ns --with-compress-install --with-toolkit-scroll-bars --with-native-compilation --without-imagemagick --with-mailutils --without-small-ja-dic --with-tree-sitter --without-xinput2 --without-xwidgets --without-dbus --without-selinux' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=remove-anonymous-timer-lambdas.patch diff --git a/lisp/emacs-lisp/eldoc.el b/lisp/emacs-lisp/eldoc.el index 24afd03fbe6..68483ab9333 100644 --- a/lisp/emacs-lisp/eldoc.el +++ b/lisp/emacs-lisp/eldoc.el @@ -269,6 +269,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. @@ -279,13 +287,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)) diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el index 05c0bd847b3..c0fc41b5afe 100644 --- a/lisp/jit-lock.el +++ b/lisp/jit-lock.el @@ -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) --=-=-=--