From unknown Sat Aug 16 21:21:58 2025 X-Loop: help-debbugs@gnu.org Subject: bug#77244: 30.1; compile.el: `compilation-filter-hook` applied to wrong region with carriage motion Resent-From: Erik Arvstedt Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 Mar 2025 04:40:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 77244 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 77244@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.17428775752853 (code B ref -1); Tue, 25 Mar 2025 04:40:02 +0000 Received: (at submit) by debbugs.gnu.org; 25 Mar 2025 04:39:35 +0000 Received: from localhost ([127.0.0.1]:35274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tww4c-0000jv-W7 for submit@debbugs.gnu.org; Tue, 25 Mar 2025 00:39:35 -0400 Received: from lists.gnu.org ([2001:470:142::17]:45462) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1twoVS-0006wB-Sb for submit@debbugs.gnu.org; Mon, 24 Mar 2025 16:34:47 -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 1twoVN-0002g7-Ej for bug-gnu-emacs@gnu.org; Mon, 24 Mar 2025 16:34:41 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1twoVL-0006lf-NH for bug-gnu-emacs@gnu.org; Mon, 24 Mar 2025 16:34:41 -0400 Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2ff187f027fso10482165a91.1 for ; Mon, 24 Mar 2025 13:34:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1742848477; x=1743453277; darn=gnu.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=g1fIVS7rGE7X+X00RaEJbqypmgVVVBhwYH1MC/zyMt0=; b=LP3VuHz1rrScRETzheWpCrs5iLj7XBC3lGNf2zqz/RJSnyFw9AMjo4iyEvypNBmKPT HQpqvWQAK2RBjUeucJ0YPFBlcS5mNd89/flwOahns4ZebHqzrMcKSb0Yu63Qa1r68e5x jWtBbq6Pv5sAXLX+PI1f9o24gLLvRGdpZ48r2kfSFA12u05ghnjGgtuq8T6SH/oLTn0j hToRqITNEFAJRUqoaAkwf80JQ/OnTHEbH85E9z6cs/I8Sp/QgdveD4MaqFUK+VhR5S6u OUERA6zt8YodWu5/OjdUciGPmZbrzZUtTTjem3c/bVQFoV9kMUX8lj4opiPCi8ToUWf/ e7GQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742848477; x=1743453277; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=g1fIVS7rGE7X+X00RaEJbqypmgVVVBhwYH1MC/zyMt0=; b=Oh5wutiNhpkMy+TynMFYTcLHIVzBTfOsPgjCZKV4obkrgsKskuO4dsjVnGX7cxhUrz 0bZDy5DzjgoGg6yP8/UJ2MHqKB8VPIjwlBAJ/cQz/8n3rBEYjrNSpOwtF+S6SWw8Z7ob 5Vtq1hChjt0xWvRrq0qiR0gmI04xtZnZUuGnLapV/3q78dr2yTrMcM38HMoGq++yjsIc T33psuHm9QQzRxaOitwRqZuR+yUQ0zNlWOG6L354PlfeaX9MbcmBTQUpAbnqtKFPVkJd O1h01uA3Cg0enQO3Wt9CwwoWPsWWkwRhpK51lZcW0kWFj149tTzS9N0UVbmcam8ZzaSr G3bA== X-Gm-Message-State: AOJu0Yz+iS4r6MGYOS0OL8tedGTklC5JK5BENG5c8ue+xAIPLEqU/YN3 2NyAbokmI24rqlPeMQdcJwR6RfD1FphFbhBKYShP3t2ubG8ZnIkMEWpeeXY/IM4yybdDkE3ssHo LQQm9zVfNwE2bTV8Idrwlpr7DQcCHUYo2 X-Gm-Gg: ASbGncufBpRzSX1u5TEz0z1spRbsDfhpuhTTxdcBabtzWYWzN5G1AEnPCzlg83N/Atk MtKem3TOuEBrzqnUv4gKnCFMfiyK6pdRzBaHLS9m2hZEWYkZwpwbfEwiZqQobCBoZ20x3yYitVu 2GsGyAGdFQLvHsXeKnq2pCsPHwPQexJGv0YuDwi6TKBeyxlvvXrrtuWtcRLA== X-Google-Smtp-Source: AGHT+IEfIoNh7GENML5dUWR0NUpw0hK8zQi6+ZDcVa0bcYzzdbf0vpePW5R9RkrhCnSehVfeHozlywtkeqxGeUO1D3w= X-Received: by 2002:a17:90b:2882:b0:2fa:1e56:5d82 with SMTP id 98e67ed59e1d1-3030f3f2e16mr22496436a91.17.1742848476710; Mon, 24 Mar 2025 13:34:36 -0700 (PDT) MIME-Version: 1.0 From: Erik Arvstedt Date: Mon, 24 Mar 2025 21:34:25 +0100 X-Gm-Features: AQ5f1Jq9xpyjkzMz10SlT1o4zFofYbfzChvDGlghnFtWU6fy5I6VmuZtYq2MkWc Message-ID: Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=erik.arvstedt@gmail.com; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: 1.0 (+) X-Mailman-Approved-At: Tue, 25 Mar 2025 00:39:32 -0400 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.0 (/) See here for a markdown-rendered version of this message: https://gist.github.com/erikarvstedt/a0d838ca38a601da1b04985b01189dc6 When a carriage motion (`comint-carriage-motion`) happens before the call to `compilation-filter-hook`, the value of `compilation-filter-start` can sometimes have an obsolete, too large value, causing the hook not to filter all of the new input. Affected Emacs versions: - 31.0.50 - 30.1 I haven't tested other versions. Example ======= Let the following be the last line of the compilation buffer, before the call to `comint-carriage-motion`: ``` aabb\rcccc ^ compilation-filter-start, (process-mark proc) point to this location ``` `aa` is the existing content of the line, before the current call to `compilation-filter`. The rest of the line, beginning with `bb...` was just inserted by `compilation-filter`. When `comint-carriage-motion` is called, it removes all chars from the carriage return (`\r`) to the beginning of the line, but leaves variable `compilation-filter-start` unchanged: ``` cccc ^ compilation-filter-start ``` `compilation-filter-start` now still points to the old location, but to correctly point to the start of new input to filter, it should instead point to the beginning of the line. Because `compilation-filter-start` marks the start of new input for `compilation-filter-hook`, the hook subsequently doesn't filter all of the new input. Reproduce ======== ```elisp (add-hook 'compilation-filter-hook 'ansi-color-compilation-filter) (compilation-start "bash -c \"echo -n aaa; sleep 0.1; echo '\x0d\x1b[Kbbb'\"") ``` The compilation Bash script outputs the common sequence of a carriage return (`\x0d`) followed by an "Erase the line" ANSI escape sequence (`\x1b[K`). This is often used by terminal apps to clear the last output line. Compilation output: ``` ^[[Kbbb ``` Expected output: ``` bbb ``` Here, the ANSI escape sequence is correctly deleted. The sequence isn't deleted because the value of `compilation-filter-start` is too large, causing `ansi-color-compilation-filter` to not process the whole output. Workaround ========== Implemented here: https://github.com/erikarvstedt/emacs-compilation-carriage-motion-workaround/blob/master/comint-carriage-motion-fixed.el Diff: https://github.com/erikarvstedt/emacs-compilation-carriage-motion-workaround/commit/450afa4594a260b47143859546f78689f2ce629a This fixes the bug for me, but I haven't checked it for correctness in all use cases.