Package: emacs;
Reported by: Stefan Monnier <monnier <at> iro.umontreal.ca>
Date: Fri, 5 Apr 2024 20:00:02 UTC
Severity: wishlist
Tags: patch
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Stefan Monnier <monnier <at> iro.umontreal.ca> To: bug-gnu-emacs <at> gnu.org Subject: [PATCH] New function `funcall-later` Date: Fri, 05 Apr 2024 15:56:40 -0400
[Message part 1 (text/plain, inline)]
Tags: patch In the patch(es) below I suggest the addition of a new function `funcall-later` which exposes the already existing `pending_funcalls` mechanism to ELisp and fixes it so those are processed in the correct order and so they're not just thrown away when used in batch mode. `run-with-timer` does largely the same thing when passed a 0 timeout and no repetition, but it is a bit more costly and relies on the timers, which don't work as well in batch mode. Stefan In GNU Emacs 30.0.50 (build 1, i686-pc-linux-gnu, GTK+ Version 3.24.41, cairo version 1.18.0) of 2024-03-27 built on lechazo Repository revision: a13cfe9bb17448e104dc86b7a33761ca60297871 Repository branch: work Windowing system distributor 'The X.Org Foundation', version 11.0.12101011 System Description: Debian GNU/Linux trixie/sid Configured using: 'configure -C --enable-checking --enable-check-lisp-object-type --with-modules --with-cairo --with-tiff=ifavailable 'CFLAGS=-Wall -g3 -Og -Wno-pointer-sign' --without-native-compilation PKG_CONFIG_PATH=/home/monnier/lib/pkgconfig'
[0001-Ffuncall_later-New-function-to-expose-pending_funcal.patch (text/patch, attachment)]
[0002-lisp-Prefer-funcall-later-over-run-with-timer.patch (text/patch, inline)]
From 24d444a272bd4b42739a1883c4d5f0545dfce58a Mon Sep 17 00:00:00 2001 From: Stefan Monnier <monnier <at> iro.umontreal.ca> Date: Fri, 5 Apr 2024 15:49:34 -0400 Subject: [PATCH 2/2] lisp: Prefer 'funcall-later' over 'run-with-timer' * lisp/subr.el (do-after-load-evaluation): * lisp/server.el (server-goto-toplevel): * lisp/progmodes/compile.el (compilation-error-properties): * lisp/menu-bar.el (menu-bar-mode): * lisp/jit-lock.el (jit-lock-fontify-now): * lisp/emacs-lisp/edebug.el (edebug-kill-buffer) (edebug-unload-function): Use 'funcall-later' i.s.o 'run-with-timer'. --- lisp/emacs-lisp/edebug.el | 4 ++-- lisp/jit-lock.el | 6 +++--- lisp/menu-bar.el | 6 +++--- lisp/progmodes/compile.el | 4 ++-- lisp/server.el | 2 +- lisp/subr.el | 3 +-- 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/lisp/emacs-lisp/edebug.el b/lisp/emacs-lisp/edebug.el index b27ffbca908..fc76552312f 100644 --- a/lisp/emacs-lisp/edebug.el +++ b/lisp/emacs-lisp/edebug.el @@ -4023,7 +4023,7 @@ edebug-mode (defun edebug-kill-buffer () "Used on `kill-buffer-hook' when Edebug is operating in a buffer of Lisp code." - (run-with-timer 0 nil #'top-level)) + (funcall-later #'top-level)) ;;; edebug eval list mode @@ -4597,7 +4597,7 @@ edebug-unload-function (unwind-protect (abort-recursive-edit) ;; We still want to run unload-feature to completion - (run-with-idle-timer 0 nil #'(lambda () (unload-feature 'edebug))))) + (funcall-later #'unload-feature 'edebug))) (remove-hook 'called-interactively-p-functions #'edebug--called-interactively-skip) (edebug-uninstall-read-eval-functions) diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el index 05c0bd847b3..14c172c1e6a 100644 --- a/lisp/jit-lock.el +++ b/lisp/jit-lock.el @@ -478,9 +478,9 @@ jit-lock-fontify-now ;; eagerly extend the refontified region with ;; jit-lock-after-change-extend-region-functions. (when (< loose-beg orig-start) - (run-with-timer 0 nil #'jit-lock-force-redisplay - (copy-marker loose-beg) - (copy-marker orig-start))) + (funcall-later #'jit-lock-force-redisplay + (copy-marker loose-beg) + (copy-marker orig-start))) ;; Skip to the end of the fully refontified part. (setq start tight-end))) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 320fabb54cf..7a4de133b74 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2632,9 +2632,9 @@ menu-bar-mode ;; directly. The minor-mode message "Menu Bar mode disabled" comes ;; after this function returns, overwriting any message we do here. (when (and (called-interactively-p 'interactive) (not menu-bar-mode)) - (run-with-idle-timer 0 nil 'message - (substitute-command-keys - "Menu Bar mode disabled. \ + (funcall-later #'message + (substitute-command-keys + "Menu Bar mode disabled. \ Use \\[menu-bar-mode] to make the menu bar appear.")))) ;;;###autoload diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 11d400e145a..952f03d3155 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -1402,8 +1402,8 @@ compilation-error-properties (when (and compilation-auto-jump-to-next (>= type compilation-skip-threshold)) (kill-local-variable 'compilation-auto-jump-to-next) - (run-with-timer 0 nil 'compilation-auto-jump - (current-buffer) (match-beginning 0))) + (funcall-later #'compilation-auto-jump + (current-buffer) (match-beginning 0))) (compilation-internal-error-properties file line end-line col end-col type fmt rule)))) diff --git a/lisp/server.el b/lisp/server.el index b65053267a6..8e3c1d0a467 100644 --- a/lisp/server.el +++ b/lisp/server.el @@ -1031,7 +1031,7 @@ server-goto-toplevel ;; to open a frame on a new display, we might end up with an unusable ;; frame because input from that display will be blocked (until exiting ;; the minibuffer). Better exit this minibuffer right away. - (run-with-timer 0 nil (lambda () (server-execute-continuation proc))) + (funcall-later #'server-execute-continuation proc) (top-level))) ;; We use various special properties on process objects: diff --git a/lisp/subr.el b/lisp/subr.el index fba70342154..20fdf8deded 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -5981,8 +5981,7 @@ do-after-load-evaluation byte-compile-current-file byte-compile-root-dir))) (byte-compile-warn "%s" msg))) - (noninteractive (funcall fun msg)) ;; No timer will be run! - (t (run-with-idle-timer 0 nil fun msg)))))) + (t (funcall-later fun msg)))))) ;; Finally, run any other hook. (run-hook-with-args 'after-load-functions abs-file)) -- 2.43.0
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.