From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ihor Radchenko Newsgroups: gmane.emacs.bugs Subject: bug#68418: refill-mode interferes with org-mode headlines Date: Sat, 13 Jan 2024 13:28:16 +0000 Message-ID: <87mst9uzv3.fsf@localhost> References: <87il3yqmkl.fsf@gmail.com> <83le8thchr.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38350"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Rudolf =?UTF-8?Q?Adamkovi=C4=8D?= , 68418@debbugs.gnu.org, Lars Rustand To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 13 14:26:35 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 1rOe1z-0009lx-HV for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 13 Jan 2024 14:26:35 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rOe1V-0008HJ-67; Sat, 13 Jan 2024 08:26: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 1rOe1U-0008H6-6r for bug-gnu-emacs@gnu.org; Sat, 13 Jan 2024 08:26:04 -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 1rOe1T-0002lC-Th for bug-gnu-emacs@gnu.org; Sat, 13 Jan 2024 08:26:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rOe1S-0004aI-9y for bug-gnu-emacs@gnu.org; Sat, 13 Jan 2024 08:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ihor Radchenko Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 13 Jan 2024 13:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68418 X-GNU-PR-Package: emacs Original-Received: via spool by 68418-submit@debbugs.gnu.org id=B68418.170515231217555 (code B ref 68418); Sat, 13 Jan 2024 13:26:02 +0000 Original-Received: (at 68418) by debbugs.gnu.org; 13 Jan 2024 13:25:12 +0000 Original-Received: from localhost ([127.0.0.1]:38730 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOe0d-0004Z3-KH for submit@debbugs.gnu.org; Sat, 13 Jan 2024 08:25:12 -0500 Original-Received: from mout01.posteo.de ([185.67.36.65]:46977) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOe0b-0004Yo-P1 for 68418@debbugs.gnu.org; Sat, 13 Jan 2024 08:25:10 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id C9B13240027 for <68418@debbugs.gnu.org>; Sat, 13 Jan 2024 14:25:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1705152304; bh=6NA5do6yWMLSznrHVuKbPnimNyKmIXr6O8h122hZ8i0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:From; b=Bw620/QSQNFPoTdKcxLcmiBTMr3476qPqy09EH2NhbbFPvCYaAL8fka4oHMhp+7py FEJDkkvAaq00Dli4dtPkGSu8yOtc+mkebZ/HwCDWS/f/GmD0SUSr9Gpbxrr9LyGleS uEjbtajdsPIptDoB8zdNHN1Gl91hf1/guYlBj6FZu4vY432kMwkFtFBV4NC7qecusa nE0K9CMOLY71Vike99CWfK9PCHBdwJKP8kT1IyA1DWr2O9ZcjTmT2v4K2Pmj7aPFek AMjrA3Lqg6OQjOsliLQfmzKXfkP3hI+SBC1iOPJ+43KhxBlzfA/CdErtq9OEukpXyc 21K/zUbeaO/lg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TBzfS0Jzdz6txT; Sat, 13 Jan 2024 14:25:03 +0100 (CET) In-Reply-To: <83le8thchr.fsf@gnu.org> 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:278123 Archived-At: Eli Zaretskii writes: >> > I did some debugging for refill-mode in Org. >> > `refill-post-command-function' calls `refill-fill-paragraph-at', which >> > not only ignores `fill-paragraph-function', but even >> > `fill-forward-paragraph-function'. `forward-paragraph' is hard-coded, >> > I consider to be a bug. >> >> Let me bump this bug report. >> AFAIU, it belongs to emacs. > > I now have second thoughts about this. fill-paragraph-function is > used by fill-paragraph, whereas refill.el calls > fill-region-as-paragraph. fill-region-as-paragraph cannot possibly > call fill-paragraph-function, because the latter is not supposed to be > able to fill more than a single paragraph. The doc string of > fill-paragraph-function actually says so: > > (defvar fill-paragraph-function nil > "Mode-specific function to fill a paragraph, or nil if there is none. > If the function returns nil, then `fill-paragraph' does its normal work. > A value of t means explicitly \"do nothing special\". > Note: This only affects `fill-paragraph' and not `fill-region' > nor `auto-fill-mode', so it is often better to use some other hook, > such as `fill-forward-paragraph-function'.") > > Am I missing something? No. This indeed makes sense. `fill-paragraph-function' is not even passed the region to fill, so it has no way to know what it is supposed to fill and should determine the paragraph boundaries by itself. > If my analysis is correct, then to move forward with this bug, we > could either: > > . add a fill-region-function, make fill-region-as-paragraph call it, > and then make Org set this function to something appropriate This is a bit tangent, but the current design of filling feels chaotic - we have configurable fill-paragraph-function and fill-forward-paragraph-function, while `fill-region-as-paragraph' is hard-coded. And forward-paragraph relies upon regexps... It looks like the notion of paragraph when filling is designed to be different compared to the notion of paragraph in `forward-paragraph'. Is there any reason for such difference? > . modify refill.el to use fill-forward-paragraph-function instead of > a literal forward-paragraph > > I tried the latter (patch below), but I don't know if that gives > good-enough results, as I don't use Org intensively enough, and > certainly don't use refill-mode. Can you try the patch below and > report back? > > diff --git a/lisp/textmodes/refill.el b/lisp/textmodes/refill.el > index 937a8ed..22f67bc 100644 > --- a/lisp/textmodes/refill.el > +++ b/lisp/textmodes/refill.el > @@ -106,10 +106,10 @@ refill-fill-paragraph-at > ;; FIXME: forward-paragraph seems to disregard `use-hard-newlines', > ;; leading to excessive refilling and wrong choice of fill-prefix. > ;; might be a bug in my paragraphs.el. > - (forward-paragraph) > + (fill-forward-paragraph 1) > (skip-syntax-backward "-") > (let ((end (point)) > - (beg (progn (backward-paragraph) (point))) > + (beg (progn (fill-forward-paragraph -1) (point))) This looks like an improvement. Also, it appears to fix the original reproducer. However, there will still be a problem, even with the proposed patch, in the following scenario: 1. emacs -Q 2. Open a new org file * Heading :tag: 3. M-x refill-mode 4. Keep typing * Heading alksjd alkjasd asldkj asdlkj aslldkj aslkdj asldkj asldkj :tag: See how the heading is split into multiple lines. This happens because refill-mode uses `fill-region-as-paragraph', which is impossible to configure by major modes. As the above example demonstrates, not everything is safe to fill without breaking the markup. A similar problem appears in `fill-region' - it completely disregards `fill-paragraph-function' and always calls `fill-region-as-paragraph'. -- Ihor Radchenko // yantar92, Org mode contributor, Learn more about Org mode at . Support Org development at , or support my work at