From unknown Fri Jun 20 07:19:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#69733: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers Resent-From: Daniel Pettersson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Mar 2024 14:39:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 69733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 69733@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.171016791712755 (code B ref -1); Mon, 11 Mar 2024 14:39:01 +0000 Received: (at submit) by debbugs.gnu.org; 11 Mar 2024 14:38:37 +0000 Received: from localhost ([127.0.0.1]:40962 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjgnV-0003Jf-3T for submit@debbugs.gnu.org; Mon, 11 Mar 2024 10:38:37 -0400 Received: from lists.gnu.org ([209.51.188.17]:43344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rjgnT-0003JX-MD for submit@debbugs.gnu.org; Mon, 11 Mar 2024 10:38:36 -0400 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 1rjgmv-0001fE-DH for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 10:38:01 -0400 Received: from mail-lf1-f54.google.com ([209.85.167.54]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rjgmt-0002UM-MR for bug-gnu-emacs@gnu.org; Mon, 11 Mar 2024 10:38:01 -0400 Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-51344bebe2fso2963502e87.2 for ; Mon, 11 Mar 2024 07:37:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710167877; x=1710772677; h=mime-version:message-id:date:subject:to:from:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TfAu5gTQjUhEkpodiX0TY3i+zY1u8HdvFH3miQYl43Q=; b=iiwqZUuEf8I0UDPjjjfb5ZXUZIrbPuDqMYklrnrnfcASofYwLobeWhmjp4K6aIceaB WyPnIWgbcd7+AofZA/2oN9K49sPqBpStwsQMi4qYppS+QTCzZSV3XNWj4YCHywjUHGwl XK5GijgWfffOibHDijvtfhfV57cB7UiZcl5f0AmoR6Q7mK9p+eYV1pmq5XYfAsopbNh4 /CWBlndx9PNgrsR37lAad7sQcfl5lrNNo6KTcGWGCivFyfoj27XrkQG3oNRxAwjMrjHW 0ieUqJqaiCdiG+XiTXVmLZ5NR0vLJfhhbih0s/a2xMq9tnAI0XVlE1OtxMrVjIkgFMiW TOHg== X-Gm-Message-State: AOJu0Yy7kVeyfPJy75WNJdtbjF1uG/0x19mY53vJ49frz4Q6yioqQjNe xH3my4WSfEsgHhRY6HESo0fAV4K3IvWPFUThSfH6ps+JwvwYjrCVYW9C6RwQ X-Google-Smtp-Source: AGHT+IGoq36xCMD0muOluDs83jCemwp49INwzrjVLjzmPaSV9UvGjK6gGsrWlpXmkn4lgTiy+3DTzA== X-Received: by 2002:a05:6512:32c7:b0:513:b001:61e4 with SMTP id f7-20020a05651232c700b00513b00161e4mr1352648lfg.66.1710167876460; Mon, 11 Mar 2024 07:37:56 -0700 (PDT) Received: from Daniels-Air (c-72cde455.027-357-6d6c6d4.bbcust.telenor.se. [85.228.205.114]) by smtp.gmail.com with ESMTPSA id i13-20020a056512340d00b005129e5d7f11sm1113157lfr.125.2024.03.11.07.37.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 07:37:55 -0700 (PDT) From: Daniel Pettersson Date: Mon, 11 Mar 2024 15:37:55 +0100 Message-ID: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=209.85.167.54; envelope-from=daniel.dpettersson.net@gmail.com; helo=mail-lf1-f54.google.com X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_FORGED_FROMDOMAIN=0.001, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.1 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.1 (--) --=-=-= Content-Type: text/plain Tags: patch As I understand the manual there is nothing that states that one should assume that you cant move the point in buffer with timers. This is of course impossible to guarantee as any code can be calling accept-process-output. But it seams like an good idea to have code that is triggered by post-command-hook to not impose such conditions. This might seam like an mole whacking activity, and it most definitely is. In GNU Emacs 30.0.50 (build 1, aarch64-apple-darwin23.1.0, NS appkit-2487.20 Version 14.1.1 (Build 23B81)) of 2023-12-20 built on Daniels-Air Repository revision: 281be72422f42fcc84d43f50723a3e91b7d03cbc Repository branch: master Windowing system distributor 'Apple', version 10.3.2487 System Description: macOS 14.1.1 --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Flyspell-flyspell-word-do-not-force-save-excursion-o.patch >From 56bdf4df8048b4053719e33d08753a2eb088dc57 Mon Sep 17 00:00:00 2001 From: Daniel Pettersson Date: Mon, 11 Mar 2024 15:01:32 +0100 Subject: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers * lisp/textmode/flyspell.el (flyspell-word): Do not force save-excursion on timers. This especially needed here as flyspell-word is fired from an post command hook. --- lisp/textmodes/flyspell.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/textmodes/flyspell.el b/lisp/textmodes/flyspell.el index de59294e9f0..5dfe0f17aef 100644 --- a/lisp/textmodes/flyspell.el +++ b/lisp/textmodes/flyspell.el @@ -1150,7 +1150,9 @@ flyspell-word (set-process-query-on-exit-flag ispell-process nil) ;; Wait until ispell has processed word. (while (progn - (accept-process-output ispell-process) + ;; don't force save-excursion to timers. + ;; only accept output from ispell-process. + (accept-process-output ispell-process nil nil t) (not (string= "" (car ispell-filter))))) ;; (ispell-send-string "!\n") ;; back to terse mode. -- 2.39.3 (Apple Git-145) --=-=-=-- From unknown Fri Jun 20 07:19:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#69733: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Mar 2024 13:21:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Daniel Pettersson Cc: 69733@debbugs.gnu.org Received: via spool by 69733-submit@debbugs.gnu.org id=B69733.171024965621854 (code B ref 69733); Tue, 12 Mar 2024 13:21:01 +0000 Received: (at 69733) by debbugs.gnu.org; 12 Mar 2024 13:20:56 +0000 Received: from localhost ([127.0.0.1]:42054 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rk23r-0005gQ-L2 for submit@debbugs.gnu.org; Tue, 12 Mar 2024 09:20:55 -0400 Received: from eggs.gnu.org ([209.51.188.92]:38364) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rk23p-0005gD-Gv for 69733@debbugs.gnu.org; Tue, 12 Mar 2024 09:20:54 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rk23B-0007pD-E3; Tue, 12 Mar 2024 09:20:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=WEn0d+ijC0WyWcJ00w8Xlq0e6Xjm/6zBVKMgOuxDv7M=; b=SpfcsIZQzsQy xPtyOk2AKkUFuxhT9urJ+qGiecOG2yO2vF1C9FUpytG9kqnSlBNhKzvP33q4DfRfnzzInzRRsKN6h z+hzyh1VLxn4MujlyBvE0WyQxS6xuDnSndkmF/bQ03jvX4nnICPGhquD8fhVS2Fd2m2D5FagRKONi U3kcy6l7MKX4hREYPtfMBKS1uZDBF/GTdxCF1eSroSFvc9X3pSE4R9xEUS06yFXh+6Q1a7UR0KZd+ Ki9uej6vojR11bLV7gT9y7f5yYj7+weF/m8pboLDvFu6zx1b9dR1+dNDoV+xUdjUCBm6SxTGy56EB rWgz3iAHw1WoB3VZH1GlTg==; Date: Tue, 12 Mar 2024 15:20:10 +0200 Message-Id: <86ttlbtwmt.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Pettersson on Mon, 11 Mar 2024 15:37:55 +0100) References: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Daniel Pettersson > Date: Mon, 11 Mar 2024 15:37:55 +0100 > > As I understand the manual there is nothing that states that one should > assume that you cant move the point in buffer with timers. This is of > course impossible to guarantee as any code can be calling > accept-process-output. But it seams like an good idea to have code that > is triggered by post-command-hook to not impose such conditions. Thanks, but I don't think I understand the relation between what you say above (and in the comments in your patch below) and the code change you propose: > (while (progn > - (accept-process-output ispell-process) > + ;; don't force save-excursion to timers. > + ;; only accept output from ispell-process. > + (accept-process-output ispell-process nil nil t) Where's save-excursion and point moving to which you allude here? More importantly, why is it a good idea to stop running timers during this accept-process-output call and ignore output from other subprocesses? From unknown Fri Jun 20 07:19:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#69733: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers Resent-From: Daniel Pettersson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 12 Mar 2024 14:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 69733@debbugs.gnu.org Received: via spool by 69733-submit@debbugs.gnu.org id=B69733.17102537478082 (code B ref 69733); Tue, 12 Mar 2024 14:30:02 +0000 Received: (at 69733) by debbugs.gnu.org; 12 Mar 2024 14:29:07 +0000 Received: from localhost ([127.0.0.1]:43320 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rk37q-00026I-Sn for submit@debbugs.gnu.org; Tue, 12 Mar 2024 10:29:07 -0400 Received: from mail-lf1-f45.google.com ([209.85.167.45]:43462) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rk37o-00025j-Qm for 69733@debbugs.gnu.org; Tue, 12 Mar 2024 10:29:06 -0400 Received: by mail-lf1-f45.google.com with SMTP id 2adb3069b0e04-51325c38d10so4893e87.1 for <69733@debbugs.gnu.org>; Tue, 12 Mar 2024 07:28:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710253704; x=1710858504; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ha36D9xm+R/pdSGDTPS43vOZeulZPdTUBuN02n1Rr1s=; b=wEcY7nJsPaLXCTVFtYvoOgiOHctI7I301Kw8J3ecHt4GgkA+WL9gXaSC+Ml+nxCzri pNJcVyradFNvqMLLBcf8J8PCPqgI6ROhASterZutQIYXdCW2q1Td6+uVkWWNBs0TEEgA oWSkxk106WSyDalRli4+j3ZlFkA1ZDW+v3u8DZk93+m57Sv4dWBzU/oPz7NoFWCqj9g7 qg9osTVP94Yu7EL/lzBtOXmbQCd4aENvhdVCyFOwa6j1cY7vSqHxtQ1Q/r3n9sJrR27E SoGia+M4NOKFmvd5Cv8Tnz+5eMm6tt6g9x8vjwVYjGjqf32jNXaExWvBSRb2YWVQsZAK GXJA== X-Gm-Message-State: AOJu0Yy6gWCCVyuEI8+dIXhAArGHRNZfKB3nKGKUQK+FaoYxq0dGnU8b 37GgmuSm7mOtWWHQXhPFyEO2SdFQAksr2fsLrO4IKvZv174TlJNo/50h+VDW X-Google-Smtp-Source: AGHT+IH4uzMxwxdC83rl/VtNxCcdYyEvmnw4W2D80RWon3EhCbj5zdnbZ45HNNjkhLw1ivg172d0/w== X-Received: by 2002:ac2:5b47:0:b0:513:d1:770d with SMTP id i7-20020ac25b47000000b0051300d1770dmr3711545lfp.7.1710253703929; Tue, 12 Mar 2024 07:28:23 -0700 (PDT) Received: from Daniels-Air (c-72cde455.027-357-6d6c6d4.bbcust.telenor.se. [85.228.205.114]) by smtp.gmail.com with ESMTPSA id c1-20020a197601000000b00513c142f6a7sm238464lff.132.2024.03.12.07.28.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Mar 2024 07:28:23 -0700 (PDT) From: Daniel Pettersson In-Reply-To: <86ttlbtwmt.fsf@gnu.org> (Eli Zaretskii's message of "Tue, 12 Mar 2024 15:20:10 +0200") References: <86ttlbtwmt.fsf@gnu.org> Date: Tue, 12 Mar 2024 15:28:22 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.2 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.8 (/) Eli Zaretskii writes: > Thanks, but I don't think I understand the relation between what you > say above (and in the comments in your patch below) and the code > change you propose: flyspell-word wraps it's body inside an `save-excursion'. (defun flyspell-word (&optional following known-misspelling) ... (save-excursion ... >> (while (progn >> - (accept-process-output ispell-process) >> + ;; don't force save-excursion to timers. >> + ;; only accept output from ispell-process. >> + (accept-process-output ispell-process nil nil t) > Where's save-excursion and point moving to which you allude here? See above and for point moving I think that the stack trace at the bottom of the email highlights my point. > More importantly, why is it a good idea to stop running timers during > this accept-process-output call and ignore output from other > subprocesses? I don't think that is the optimal solution. But this does not ignore output right, it just delays timers and filter functions. If flyspell is active in an comit buffer it might also screw up the point if process outputs stuff during `accept-process-output'. The best solution would be to run `accept-process-output' outside of the body of save-excursion, but that would require a bit more mangling, which might be worth the effort. Let's create an simple example to illustrate the issue with current implementation. This is a highly construed example but there is always the chance that flyspell has unexpected interactions with all buffers that filter functions and timer functions modify the point of. (defun timer-goto-point-min () (goto-char (point-min))) (defun some-command () (interactive) ;; flyspell needs point to have been and at word. (goto-char (point-min)) (re-search-forward "word.") ;; Goto top of buffer with timer (run-with-timer 0 0 'timer-goto-point-min)) (trace-function #'timer-goto-point-min) (trace-function 'flyspell-word) (trace-function 'accept-process-output) ;; Prepare buffer (with-current-buffer (get-buffer-create "buffer") (save-excursion (insert "Some sentence with words.")) (flyspell-mode)) ;; Open buffer M-x some-command expects point to be at the start of ;; buffer ;; 1 -> (flyspell-word) -- start of save-excursion ;; | 2 -> (accept-process-output #) ;; | | 3 -> (timer-goto-point-min) -- moves point ;; | | 3 <- timer-goto-point-min: 1 ;; | 2 <- accept-process-output: t ;; 1 <- flyspell-word: nil -- end of save-excursion ;; resets the point /Daniel From unknown Fri Jun 20 07:19:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#69733: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 14 Mar 2024 10:37:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Daniel Pettersson Cc: 69733@debbugs.gnu.org Received: via spool by 69733-submit@debbugs.gnu.org id=B69733.171041261414211 (code B ref 69733); Thu, 14 Mar 2024 10:37:01 +0000 Received: (at 69733) by debbugs.gnu.org; 14 Mar 2024 10:36:54 +0000 Received: from localhost ([127.0.0.1]:48411 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rkiSE-0003h6-6H for submit@debbugs.gnu.org; Thu, 14 Mar 2024 06:36:54 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46326) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rkiSB-0003gr-F8 for 69733@debbugs.gnu.org; Thu, 14 Mar 2024 06:36:52 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rkiRW-0004CB-5N; Thu, 14 Mar 2024 06:36:10 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=ZzGHzXLKjgb+dBGUWqHxoJJxVggkS9Bb3EBlRwnMoeU=; b=AHv9xreyl1kM c2eMycvizZpXdu7dGZZQ4HdJ9BV6jTmnQmLk9h0GFcwHzbOrPzS9DO4oSAxovvweeIBJP7It91WCs urhH+LM3okpQLBjMPEPuS6ZNn+uRU+33spWjpLoV3VYhG+UmQ3lY0zTsoQhEVlPLAwm2DrVzc+ChG fEIUaZRrM4LLPP0S+kp9YJvHfZO4vmHzwD778WQ18N5Q5Mtas0cw9ATzJWoICfS9/qslJPMCCxAxB yIIt3q+wj2DHnRXHAIjJL6NgOwq03lgKBvBslwn1AR+PQZDvNqd7Jj9whAHry889pQWALiMIc4HD6 nnIUdbo6T6tvCYfDJ+NIXw==; Date: Thu, 14 Mar 2024 12:36:02 +0200 Message-Id: <86ttl99k31.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Pettersson on Tue, 12 Mar 2024 15:28:22 +0100) References: <86ttlbtwmt.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Daniel Pettersson > Cc: 69733@debbugs.gnu.org > Date: Tue, 12 Mar 2024 15:28:22 +0100 > > Eli Zaretskii writes: > > > Thanks, but I don't think I understand the relation between what you > > say above (and in the comments in your patch below) and the code > > change you propose: > > flyspell-word wraps it's body inside an `save-excursion'. > > (defun flyspell-word (&optional following known-misspelling) > ... > (save-excursion > ... > >> (while (progn > >> - (accept-process-output ispell-process) > >> + ;; don't force save-excursion to timers. > >> + ;; only accept output from ispell-process. > >> + (accept-process-output ispell-process nil nil t) > > > Where's save-excursion and point moving to which you allude here? > > See above and for point moving I think that the stack trace at the > bottom of the email highlights my point. > > > More importantly, why is it a good idea to stop running timers during > > this accept-process-output call and ignore output from other > > subprocesses? > > I don't think that is the optimal solution. But this does not ignore > output right, it just delays timers and filter functions. If flyspell > is active in an comit buffer it might also screw up the point if process > outputs stuff during `accept-process-output'. > > The best solution would be to run `accept-process-output' outside of the > body of save-excursion, but that would require a bit more mangling, > which might be worth the effort. > > Let's create an simple example to illustrate the issue with current > implementation. This is a highly construed example but there is always > the chance that flyspell has unexpected interactions with all buffers > that filter functions and timer functions modify the point of. > > (defun timer-goto-point-min () > (goto-char (point-min))) > > (defun some-command () > (interactive) > ;; flyspell needs point to have been and at word. > (goto-char (point-min)) > (re-search-forward "word.") > ;; Goto top of buffer with timer > (run-with-timer 0 0 'timer-goto-point-min)) > > (trace-function #'timer-goto-point-min) > (trace-function 'flyspell-word) > (trace-function 'accept-process-output) > > ;; Prepare buffer > (with-current-buffer (get-buffer-create "buffer") > (save-excursion > (insert "Some sentence with words.")) > (flyspell-mode)) > > ;; Open buffer M-x some-command expects point to be at the start of > ;; buffer > > ;; 1 -> (flyspell-word) -- start of save-excursion > ;; | 2 -> (accept-process-output #) > ;; | | 3 -> (timer-goto-point-min) -- moves point > ;; | | 3 <- timer-goto-point-min: 1 > ;; | 2 <- accept-process-output: t > ;; 1 <- flyspell-word: nil -- end of save-excursion > ;; resets the point Thanks, but I'm still confused regarding what you are trying to fix and why you are trying to fix it with the patch you proposed. First, AFAIU, save-excursion is there because flyspell-get-word might move point. So this is justified. Next, you seem to be saying that it is for some reason bad to run timers under save-excursion, but you haven't explained why. IMO, if a timer that runs during post-command-hook moves point, that can have negative effect on UX. Also, code that runs from a timer cannot possibly rely on Emacs leaving point where the timer moves it. Are there any examples of timers that run like this which _must_ be able to move point and make sure point stays where the timer moved it? From unknown Fri Jun 20 07:19:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#69733: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers Resent-From: Daniel Pettersson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Mar 2024 11:31:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Eli Zaretskii Cc: 69733@debbugs.gnu.org Received: via spool by 69733-submit@debbugs.gnu.org id=B69733.171050223230946 (code B ref 69733); Fri, 15 Mar 2024 11:31:02 +0000 Received: (at 69733) by debbugs.gnu.org; 15 Mar 2024 11:30:32 +0000 Received: from localhost ([127.0.0.1]:52143 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rl5lf-000821-VR for submit@debbugs.gnu.org; Fri, 15 Mar 2024 07:30:32 -0400 Received: from mail-lf1-f43.google.com ([209.85.167.43]:46213) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rl5le-0007ir-Ee for 69733@debbugs.gnu.org; Fri, 15 Mar 2024 07:30:31 -0400 Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-512e39226efso1910824e87.0 for <69733@debbugs.gnu.org>; Fri, 15 Mar 2024 04:29:54 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710502188; x=1711106988; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nxATrIh/EacaUEeAabtqOyyFHqQ7g+bwCu90QEvdKtI=; b=rqpj0Nhj9x2gkr3ipUVqMEiWXm7YZV2/ZLPFPROZPP+WJ39SVFzym5IpDGdfUtDxvt vQ6+4JWgmtZM22ijpCHw7bfJW0VnBve82uCVla31relQQRAtMv/wBqbOsw7JYnOcMn/N 7W5fmGSY4QLqpc4T7hR1RUQSF8B9uj4WORUOte0vxvHplJkvuo4CDLagztveAafwMRAj Kdt+LdkKsi67o6vora1RqUUMvjyzI8DNEIYGl3F8/V6cvycR4M8H/zdBaIrx2oCzSwMd nGXKi4Slx9/Stn+dy92b3UUQJH98KW7XwsOW0UxoSTV/SU2M3SmrgI/R3qjSe1Q8TXt3 yeWQ== X-Gm-Message-State: AOJu0YzhEt7YDGczGzWEsBUmxzJ2YVuoQ58WDayMwHu78WtObb/ydJay cWzOxVCC9LcRCQHC4M97Nmfo/zn3be5F+FOa5pAHnqVEC5u+G/uF6CxNslXS X-Google-Smtp-Source: AGHT+IELvt2GhWs3GtpGvejgsfb4eEx9EAa6YwVP7rzo6tXvax0IUpYa1mzaJbIj9S+hM4gDAxG3HQ== X-Received: by 2002:ac2:5b44:0:b0:513:d1cd:b90c with SMTP id i4-20020ac25b44000000b00513d1cdb90cmr2972026lfp.30.1710502187690; Fri, 15 Mar 2024 04:29:47 -0700 (PDT) Received: from Daniels-Air (c-72cde455.027-357-6d6c6d4.bbcust.telenor.se. [85.228.205.114]) by smtp.gmail.com with ESMTPSA id q5-20020ac25145000000b00512e594e235sm616686lfd.242.2024.03.15.04.29.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 04:29:47 -0700 (PDT) From: Daniel Pettersson In-Reply-To: <86ttl99k31.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 14 Mar 2024 12:36:02 +0200") References: <86ttlbtwmt.fsf@gnu.org> <86ttl99k31.fsf@gnu.org> Date: Fri, 15 Mar 2024 12:29:46 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.2 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.8 (/) Eli Zaretskii writes: > Thanks, but I'm still confused regarding what you are trying to fix > and why you are trying to fix it with the patch you proposed. Lets just preface with that for accept-process-output non idle timers and process filters are the same thing, right? So any filter or timer might run inside of accept-process-output if JUST-THIS-ONE is nil. The issue was noticed with the elpa package dape, with flyspell-prog-mode. But I was able to reproduce it in gdb-mi.el (gud-next) as well. The common denominator here is moving the point from filter/timer functions, in both cases source buffers. It's definitely a bit more rare for this to happen for gdb-mi.el as it moves it's point to the beginning of the line where it's highly unlikely for there to be a word which flyspell-prog-mode sends of to ispell-process to spell (and waits with accept-process-output), additionally it depends on the speed of gdb and the ispell program. If ispell stdouts before gdb, flyspell-word finishes before gud-filter is evaled. > First, AFAIU, save-excursion is there because flyspell-get-word might > move point. So this is justified. No doubt that the save-excursion is justified but it surly does not need to wrap everything, one could be a bit more exact (wrap those parts) that actually move the point. > Next, you seem to be saying that it is for some reason bad to run > timers under save-excursion, but you haven't explained why. This has the chance to break both gdb-mi.el, dape and all other packages that moves a point from filter and timer functions. I say chance here because it all depends the timing of the process output and If the buffer that the point is moved in is checked by flyspell think I gave my explanation to what could break above. > Also, code that runs from a timer cannot > possibly rely on Emacs leaving point where the timer moves it. I have a feeling that there are a lot of other code, except dape and gud that do. As this is not only timers but any code that is called from an process filter. > Are there any examples of timers that run like this which _must_ be > able to move point and make sure point stays where the timer moved it? See above. After some thinking I it might be impossible to impose anything on the caller of accept-process-output. And the bug is in dape and gdb-mi.el that gud should call gud-display-line inside of an idle timer to ensure that the point is moved, if I understand how idle timers are called which might be false. Maybe it would be a good idea if "(elisp) Timers" would mention these things. Would that be an good idea? I could be up for writing something up, even if don't consider myself to be that good at writing documentation. /Daniel From unknown Fri Jun 20 07:19:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#69733: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Mar 2024 12:38:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Daniel Pettersson Cc: 69733@debbugs.gnu.org Received: via spool by 69733-submit@debbugs.gnu.org id=B69733.171050623630973 (code B ref 69733); Fri, 15 Mar 2024 12:38:01 +0000 Received: (at 69733) by debbugs.gnu.org; 15 Mar 2024 12:37:16 +0000 Received: from localhost ([127.0.0.1]:52245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rl6oF-00083U-ER for submit@debbugs.gnu.org; Fri, 15 Mar 2024 08:37:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:47726) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rl6oA-00083C-BS for 69733@debbugs.gnu.org; Fri, 15 Mar 2024 08:37:14 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rl6nU-0008HE-B4; Fri, 15 Mar 2024 08:36:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=cpdAPude7oXe3slJx5nxTwnlHT7Gsl0j3OLZO4XlsSQ=; b=l9YUf+4aV+Wq X7XHgc1p9Nh6g+25qq4D/kN9uvJk4BiBkXyEtxcfGETRgwI1zTJ+dkldlXzuCl940GGugpaLdgj8O urzotKewZHwGeQtpNZynAUzcnjvsqoK9glnrMXQTwjKOAhBMIASefBk1w8olbe7NZ9kt+QZ25856E yKrRpCtTttt6TtwW5A+T4ovHgKaeLn1sAM7ElnkImQZqE4JutliNaOjvVh4z3dJQeEVHjWZRsIpge /l8cz2A6bgVEnQEyQfHH/Omg2dEc+Kl3nkhp7HgcDxZ50GhskpEaMp9miIlFvrbbOywAy2nFha4kS rQStT7X4oKGzeht2mlRqOA==; Date: Fri, 15 Mar 2024 14:36:23 +0200 Message-Id: <86edcb8yew.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: (message from Daniel Pettersson on Fri, 15 Mar 2024 12:29:46 +0100) References: <86ttlbtwmt.fsf@gnu.org> <86ttl99k31.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Daniel Pettersson > Cc: 69733@debbugs.gnu.org > Date: Fri, 15 Mar 2024 12:29:46 +0100 > > Eli Zaretskii writes: > > > Thanks, but I'm still confused regarding what you are trying to fix > > and why you are trying to fix it with the patch you proposed. > > Lets just preface with that for accept-process-output non idle timers > and process filters are the same thing, right? So any filter or timer > might run inside of accept-process-output if JUST-THIS-ONE is nil. > > The issue was noticed with the elpa package dape, with > flyspell-prog-mode. But I was able to reproduce it in gdb-mi.el > (gud-next) as well. The common denominator here is moving the point > from filter/timer functions, in both cases source buffers. I think (and you agree below) that these are bugs in these packages. Non-idle timer cannot safely move point, and neither can a process filter. It basically means we move point while the user might be typing something, which would be a terrible misfeature! > > First, AFAIU, save-excursion is there because flyspell-get-word might > > move point. So this is justified. > > No doubt that the save-excursion is justified but it surly does not need > to wrap everything, one could be a bit more exact (wrap those parts) > that actually move the point. That's correct, so if you want to move save-excursion closer to flyspell-get-word, it would be fine. > After some thinking I it might be impossible to impose anything on the > caller of accept-process-output. And the bug is in dape and gdb-mi.el > that gud should call gud-display-line inside of an idle timer to ensure > that the point is moved, if I understand how idle timers are called > which might be false. Exactly. Idle timers can move point, provided that they wait a reasonable amount of idleness time, to avoid interpreting a 0.01 sec gap in user typing as "idle". > Maybe it would be a good idea if "(elisp) Timers" would mention these > things. Would that be an good idea? Yes, I think so. We already advise not to do certain things in a timer function, so this could be an addition to those parts. > I could be up for writing something up, even if don't consider > myself to be that good at writing documentation. Thanks, please do. From unknown Fri Jun 20 07:19:29 2025 X-Loop: help-debbugs@gnu.org Subject: bug#69733: [PATCH] Flyspell (flyspell-word): do not force 'save-excursion' on timers Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Mar 2024 16:01:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: Daniel Pettersson , 69733@debbugs.gnu.org Received: via spool by 69733-submit@debbugs.gnu.org id=B69733.171051841831990 (code B ref 69733); Fri, 15 Mar 2024 16:01:01 +0000 Received: (at 69733) by debbugs.gnu.org; 15 Mar 2024 16:00:18 +0000 Received: from localhost ([127.0.0.1]:53621 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rl9yj-0008Jt-Jj for submit@debbugs.gnu.org; Fri, 15 Mar 2024 12:00:17 -0400 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]:58085) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rl9ye-0008IQ-MT for 69733@debbugs.gnu.org; Fri, 15 Mar 2024 12:00:16 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 4D24F3200A0A; Fri, 15 Mar 2024 11:59:29 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Fri, 15 Mar 2024 11:59:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gutov.dev; h=cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1710518368; x=1710604768; bh=ZsZ+71X0q1wraiymlBg71Fk/O9uP2HxtORm6BfaxWjU=; b= XiX4S6MP3GVo9fGiLRISjfsUe9R8VxTyuNKvPyNHWDXgD1XLYAngLLhfSa9fN8PP I6LvAZFtLG/QZROSYVFxl3OWCRMXsuP86DxmCUkY3hazLkmh0EIrhOn0VzZMOGn4 spKlkazfJ5jkXmYdALHX0e/WFcA/JQikieMGnKxqKTXx+Pc7zhrUC6yEK5xHsSL8 k8Uw8xltNCRqigu3NFHhlst8UH1a5CUMmaeoSoyS0xcFRBeWOCrPyrLe5gLjRXN6 7TEv4I2Z4a4oi6Ck0NySknGJakRP2hKFuxsaXG2C/GfeOzICacxEHFn5BEk//vK6 BP7WEW90//iFznE/xJvQ4g== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1710518368; x= 1710604768; bh=ZsZ+71X0q1wraiymlBg71Fk/O9uP2HxtORm6BfaxWjU=; b=N X3qFjHYMQi5z40LIxzvSh1PuBfEAIgSa6EtnA1j0poPEhXvX8SL5oOzu8Grqr9GP 3KSm1n6MEeDPsZcezuJLEuqye0ODIoqtVSeGAGsz/18CzYcLdDQ2Q4eLzy4OBiyh XchsI/osm9aAYLPeQ03MhCHOqg5ESULk7fitbgWHp+7QAkhnUxlmkRDXEGgW3l7J 4WfJVXQeWfZg1cJyzTfgIK75IkMKnBzQ0q2Hcd+D4llLCSTKKho7k/+MOL1Fu4yY SfIAIWg0SLvs5iBhZ5apbSHX7vVqBCPS0jArcztGE5+zGzMMTV+DXSdvAYt/sdSU X1mj0lztfoEme8/JiEFCw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjeelgdekvdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefkffggfgfuvfhfhfgjtgfgsehtjeertddtvdejnecuhfhrohhmpeffmhhithhr hicuifhuthhovhcuoegumhhithhrhiesghhuthhovhdruggvvheqnecuggftrfgrthhtvg hrnheptdfhuedvtdevleegueelvedvjeevheffveevhedvuefftdefhfdvueeggfetgfdt necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepughmih htrhihsehguhhtohhvrdguvghv X-ME-Proxy: Feedback-ID: i0e71465a:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 15 Mar 2024 11:59:27 -0400 (EDT) Message-ID: <9e13cdcf-8591-4a55-ad1f-7ddc553f93cd@gutov.dev> Date: Fri, 15 Mar 2024 17:59:25 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US References: From: Dmitry Gutov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: -0.7 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) On 11/03/2024 16:37, Daniel Pettersson wrote: > As I understand the manual there is nothing that states that one should > assume that you cant move the point in buffer with timers. This is of > course impossible to guarantee as any code can be calling > accept-process-output. But it seams like an good idea to have code that > is triggered by post-command-hook to not impose such conditions. > > This might seam like an mole whacking activity, and it most definitely > is. Speaking of mole whacking, a long-time potential FIXME here has been to rewrite flyspell in terms of timers, rather than sit-for. Dropping unnecessary save-excusion-s would either happen automatically, or would be in the same general area anyway.