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 21:16:56 +0100 Message-ID: References: <87cyirbfpd.fsf@alternateved.com> <86bjybta3i.fsf@gnu.org> <861pz7t4yb.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="33397"; 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 21:17:37 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 1tDUfI-0008X2-Tk for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 19 Nov 2024 21:17:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tDUen-00036Z-0c; Tue, 19 Nov 2024 15:17: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 1tDUel-000366-6U for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 15:17:03 -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 1tDUek-0000hN-Uh for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 15:17: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=4JnzgfsdAxZsgxBUGP1SiAn0veEeBpDZCBfK8c2/Cgo=; b=sh4lnJkLSH3U3lUfQt9OwHp0g3ct47dQ1RywCMAtJbQXoUDHu9r6n4WMwDt9kcTgpCFOhUMUM14VOHkXQf7et1wCeoV+LXouXcRI514cfaJJlPgD/DlvRiwwoS82mxxTpDnYJlVaQceN/Iz1EfjzZFpbaqcvK7lZKm2SIaEGf/HKv1MQy7aYzxitGjfOLLvd1FIfRMtqG2NHrSNsjchxu4sLm0mrzP5vObPo3tH9QSXXGl/C06R3pY+okb7XyxNzDOMuKAuEpnezCYKPLXqR4e1F8dFB3GVTOky7TD3ddsVviKBZLJj5VPa9eraqoYJ1yBqO3HIgB54KBFv4E7GgMw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tDUek-0007yz-Gj for bug-gnu-emacs@gnu.org; Tue, 19 Nov 2024 15:17:02 -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 20:17:02 +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.173204742130675 (code B ref 74437); Tue, 19 Nov 2024 20:17:02 +0000 Original-Received: (at 74437) by debbugs.gnu.org; 19 Nov 2024 20:17:01 +0000 Original-Received: from localhost ([127.0.0.1]:44157 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDUej-0007yg-24 for submit@debbugs.gnu.org; Tue, 19 Nov 2024 15:17:01 -0500 Original-Received: from mail.eshelyaron.com ([107.175.124.16]:37574 helo=eshelyaron.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tDUeg-0007yX-Uc for 74437@debbugs.gnu.org; Tue, 19 Nov 2024 15:16:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=eshelyaron.com; s=mail; t=1732047418; bh=4fMPcMVek4o0X8soKfVASrh6dUvgHJIBIZBjV0Zxfl8=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=iHNzZkoQ0DbKVFEoU0KRNCZpj6vVcjV8tHGrq99C8k2f9gbDdI9z+yMwDwEhMp9Aj 1glopd5tpMhJ80FVq2w+ou9B08iQtHf998WLEjSpkbECgPRKvf0yQr0H0/M6s7HiCP fIpvYtbXdS/me5KInePah/dAVxotOA9ZyLSOMCjKbK3g9vyh8wlli0054BnjtvANnf ledDPppWZBtrZn7jaXUi+bXsytMQsIGmObgZIgxnu0kkrEL5JifBVR6RM/q6YDyZim S4N++7tFENKdUt0ss+0rGnlcFTD+XZ1jFDeLk3J7rzhYdjSOHxw2SBRnVeCv7tbof1 eyodUNZp9PBIw== In-Reply-To: <861pz7t4yb.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 19 Nov 2024 21:10:36 +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:295659 Archived-At: Eli Zaretskii writes: >> From: Eshel Yaron >> Cc: 74437@debbugs.gnu.org, mail@alternateved.com >> Date: Tue, 19 Nov 2024 19:40:07 +0100 >> >> +(defcustom flyspell-blocking-delay t > > I'd name this flyspell-use-timer or somesuch. OK, will do. Actually, how about flyspell-delay-use-timer? Just flyspell-use-timer feels a bit too general: Flyspell might use timers for other purposes regardless of this option. >> + "Whether to block Emacs while Flyspell waits after a delayed command." >> + :type 'boolean >> + :version "30.1") > ^^^^^^^^^^^^^^ > You are an optimist ;-) Oh well, 31.1 it is then :) >> - (accept-process-output ispell-process) >> + (accept-process-output ispell-process 1) > > Does this really work reliably from a timer? I don't immediately see why it shouldn't, and the tests I tried so far seem to work, but your skepticism makes me wonder if there's anything I'm missing. Do you have any particular potential issue in mind? > You _are_ aware that this call to accept-process-output will run > timers while we wait? Yes. If that's a cause for concern, we can inhibit running timers here when we're calling flyspell-word from a timer, like in the patch below. > Also, what happens if there are other async > subprocesses running in parallel, like maybe Grep or compilation or > url-retrieve? They make progress, which seems to work as expected, at least with Grep. That is if we use the previous patch, with the one below we pass non-nil JUST-THIS-ONE argument to accept-process-output when called from a timer so other processes shouldn't see new output during this call. Either way works, AFAICT. diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index 7bf9cb1ae9d..5442b46cd1d 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-delay-use-timer nil + "Whether to use a timer for waiting after a delayed command." + :type 'boolean + :version "31.1") + +(defvar flyspell--timer nil) + ;;*---------------------------------------------------------------------*/ ;;* flyspell-check-word-p ... */ ;;*---------------------------------------------------------------------*/ @@ -844,7 +851,16 @@ 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 (not flyspell-delay-use-timer) + (sit-for flyspell-delay) + (setq flyspell--timer + (run-with-idle-timer + flyspell-delay nil + (lambda (buffer) + (when (eq (current-buffer) buffer) + (flyspell-word nil nil t))) + (current-buffer))) + nil))) (t t))) (t t)))) @@ -955,6 +971,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) @@ -1095,13 +1112,14 @@ flyspell-word ;;*---------------------------------------------------------------------*/ ;;* flyspell-word ... */ ;;*---------------------------------------------------------------------*/ -(defun flyspell-word (&optional following known-misspelling) +(defun flyspell-word (&optional following known-misspelling block-timers) "Spell check a word. If the optional argument FOLLOWING, or, when called interactively `ispell-following-word', is non-nil, checks the following (rather than preceding) word when the cursor is not over a word. If optional argument KNOWN-MISSPELLING is non-nil considers word a -misspelling and skips redundant spell-checking step. +misspelling and skips redundant spell-checking step. Non-nil optional +argument BLOCK-TIMERS says not to run timers while spell-checking. See `flyspell-get-word' for details of how this finds the word to spell-check." @@ -1179,7 +1197,8 @@ 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 nil + (when block-timers 0)) (not (string= "" (car ispell-filter))))) ;; (ispell-send-string "!\n") ;; back to terse mode.