From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eshel Yaron via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74437: 30.0.92; completion-preview-idle-delay is delayed by flyspell Date: Tue, 19 Nov 2024 19:40:07 +0100 Message-ID: References: <87cyirbfpd.fsf@alternateved.com> <86bjybta3i.fsf@gnu.org> Reply-To: Eshel Yaron Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34227"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 74437@debbugs.gnu.org, mail@alternateved.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 19 19:41:30 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 1tDTAH-0008hJ-2T for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Nov 2024 19:41:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDT9t-0006nb-JI; Tue, 19 Nov 2024 13:41:05 -0500 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 1tDT9q-0006nA-Tz for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 13:41:02 -0500 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 1tDT9q-0004YO-5y for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 13:41:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=5EyioJtyCwZVKz7BXXVcV2B5GBQdOeis739c6b5SmLE=; b=fcaOPoEJQpfSGycqFrzCodCbL1LoCuFP0MtkqbN1kKH4UVbeSrvjLgw66op0JGolJDz7SPWpLA6QgjJZC8/Lt0yJ3sFR3kSqkOPkPPr2RZD5DbSEsfWn+1cUnOFQ/lvRcdgqWYnk199ao3bHG5CG23kMAGrkJUnIeyJMF3QW76Nh9oC60lalbsCUcaTTfUxgktx27P+hxmPMYnjPITvYg+SB5DggeqLq2G2nViNy340MStoAR/cCYDPsUIngCYCWjTz0o7yiUCaNpSYa5MFi/a6EXwQFub/IH2dhxfcmw7IRcYy+elHs5QKSgb+Wujjtvr0WKfUYuuwowc84sykRiQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tDT9p-0003mJ-Lg for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 13:41:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eshel Yaron Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 19 Nov 2024 18:41:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74437 X-GNU-PR-Package: emacs Original-Received: via spool by 74437-submit@debbugs.gnu.org id=B74437.173204161314448 (code B ref 74437); Tue, 19 Nov 2024 18:41:01 +0000 Original-Received: (at 74437) by debbugs.gnu.org; 19 Nov 2024 18:40:13 +0000 Original-Received: from localhost ([127.0.0.1]:43996 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDT92-0003kv-AG for submit@debbugs.gnu.org; Tue, 19 Nov 2024 13:40:12 -0500 Original-Received: from mail.eshelyaron.com ([107.175.124.16]:42794 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDT8z-0003kV-VV for 74437@debbugs.gnu.org; Tue, 19 Nov 2024 13:40:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1732041609; bh=8SK3p01z2pbev0B0hPz6hpsvp/Riy2UCahLv6SKlUrk=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=Qy13cBDDEY8XB9EfuOqv4PQSR204tTVpYLYN7EzCPfQlDmNsqTw4CfDw06b1FfDQ0 Yorv9ET65DNd5tc1xU/NkINd5AVGoWtJPWldl4y2sLXiA+gB+0JnYo39981hGoRNBL vLQdODRtpZroxcfXck9ZlJhsNHIwKmDBfm5bwRyupwlbps8s9x7nRnckDfHYmMgPGo sqSkA27Vpi1/T7eeyqLHUKtUb1FwLz3LGdpZom0COZe5ufEeo2U9B2tzA5euU9Wl+2 ivrMLC3pCF1mpGyMfhJwBSxEvUK1zfxWMCmaJ9H0rsII+VdvpBHJJZ5LEaRyDQCxDO eYXOItrMdk7Xg== In-Reply-To: <86bjybta3i.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 19 Nov 2024 19:19:29 +0200") 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:295652 Archived-At: Hi, Eli Zaretskii writes: >> Cc: mail@alternateved.com >> Date: Tue, 19 Nov 2024 17:13:16 +0100 >> From: Eshel Yaron via "Bug reports for GNU Emacs, >> the Swiss army knife of text editors" >> >> The root cause is a peculiarity of flyspell-mode: it calls sit-for and >> blocks Emacs for 3 whole seconds (by default, see flyspell-delay) after >> certain commands, including after (org-)self-insert-command. This also >> blocks the idle timer that Completion Preview mode uses, unfortunately. >> >> A quick search shows that this behavior of flyspell affects other >> features as well. For example, IIUC, auto completion in Corfu switched >> to using run-at-time instead of run-with-idle-timer due to this issue. >> >> I think flyspell should be modified to use a timer instead of sit-for, >> so as to avoid blocking idle timers. I can come up with such a patch, >> but it's not quite trivial, so I wonder what others think about this >> issue and how it should be addressed. > > This is likely to cause differences in behavior that some users will > be unhappy about (how do you support delaying only after some > commands? and how do you interact with async subprocess from an idle > timer?). So if you want to install such a patch, it must be an opt-in > feature, so we could let users try it for some time before we decide > whether to retire the old behavior based on sit-for. All right, something like this? diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 7bf9cb1ae9d..7ba5bb871ea 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -810,6 +810,13 @@ flyspell-check-changed-word-p (let ((pos (point))) (or (>= pos start) (<= pos stop) (= pos (1+ stop)))))))) +(defcustom flyspell-blocking-delay t + "Whether to block Emacs while Flyspell waits after a delayed command." + :type 'boolean + :version "30.1") + +(defvar flyspell--timer nil) + ;;*---------------------------------------------------------------------*/ ;;* flyspell-check-word-p ... */ ;;*---------------------------------------------------------------------*/ @@ -844,7 +851,15 @@ flyspell-check-word-p ;; The current command is not delayed, that ;; is that we must check the word now. (and (not unread-command-events) - (sit-for flyspell-delay))) + (if flyspell-blocking-delay + (sit-for flyspell-delay) + (setq flyspell--timer + (run-with-idle-timer + flyspell-delay nil + (lambda (buffer) + (when (eq (current-buffer) buffer) (flyspell-word))) + (current-buffer))) + nil))) (t t))) (t t)))) @@ -955,6 +970,7 @@ flyspell-debug-signal-changed-checked (defun flyspell-post-command-hook () "The `post-command-hook' used by flyspell to check a word on-the-fly." (interactive) + (when (timerp flyspell--timer) (cl-callf cancel-timer flyspell--timer)) (when flyspell-mode (with-local-quit (let ((command this-command) @@ -1179,7 +1195,7 @@ flyspell-word (set-process-query-on-exit-flag ispell-process nil) ;; Wait until ispell has processed word. (while (progn - (accept-process-output ispell-process) + (accept-process-output ispell-process 1) (not (string= "" (car ispell-filter))))) ;; (ispell-send-string "!\n") ;; back to terse mode.