From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kaushal Modi Subject: Re: Prevent auto-fill-mode from filling Property values in drawers Date: Mon, 05 Feb 2018 21:59:40 +0000 Message-ID: References: <87shaiuoxe.fsf@nicolasgoaziou.fr> <87d11muofz.fsf@nicolasgoaziou.fr> <87372i82p5.fsf@alphaville.usersys.redhat.com> <874lmxvhwb.fsf@nicolasgoaziou.fr> <87y3k8h034.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="94eb2c19b44679decd05647e2e9d" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eionq-0005i4-JT for emacs-orgmode@gnu.org; Mon, 05 Feb 2018 16:59:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eionp-0004ot-DX for emacs-orgmode@gnu.org; Mon, 05 Feb 2018 16:59:54 -0500 Received: from mail-yw0-x230.google.com ([2607:f8b0:4002:c05::230]:37619) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eionp-0004of-70 for emacs-orgmode@gnu.org; Mon, 05 Feb 2018 16:59:53 -0500 Received: by mail-yw0-x230.google.com with SMTP id v139so19523079ywg.4 for ; Mon, 05 Feb 2018 13:59:52 -0800 (PST) In-Reply-To: <87y3k8h034.fsf@nicolasgoaziou.fr> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Nicolas Goaziou Cc: Nick Dokos , emacs-orgmode@gnu.org --94eb2c19b44679decd05647e2e9d Content-Type: text/plain; charset="UTF-8" On Sun, Feb 4, 2018 at 5:16 PM Nicolas Goaziou wrote: > `org-return' doesn't call any auto fill function. > It sort of does, indirectly, via (newline). Please see the proposed patch at the end of this email. Yet, it doesn't break properties drawers. > I agree. Though this patch fixes what shouldn't do when point is in the property drawer. If someone has: ===== * Headline :PROPERTY: :FOO: some long line that goes beyond fill column :END: ===== It would be highly unlikely that some would want to save that file as (assuming it got formatted as below because of auto filling): ===== * Headline :PROPERTY: :FOO: some long line that goes beyond fill column :END: ===== So the below patch prevents from doing the above > I don't think tweaking `org-return' is a good solution. This is not the > only way to break a line (e.g. "C-q C-j", or "C-M-o"), so it would not > be a panacea. > I tried C-q C-j and C-M-o, and both don't allow the auto-filling to happen, even without the below patch. > You may want to use fill-nobreak-predicate variable instead, e.g. with > `org-at-property-p'. > I gave that a try, by tweaking fill-nobreak-predicate inside the org-setup-filling function. But that doesn't work. Looks like the predicate is evaluated *after* `newline' inserts the newline.. and so `org-at-property-p' would evaluate to nil. ** The patch ** Looking at the source code of `newline' defun, I came up with this and it works! diff --git a/lisp/org.el b/lisp/org.el index 688e48bcc1d..9367304e900 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20471,7 +20471,10 @@ object (e.g., within a comment). In these case, you need to use (delete-and-extract-region (point) (line-end-position)))) (newline-and-indent) (save-excursion (insert trailing-data)))) - (t (if indent (newline-and-indent) (newline)))))) + (t (let ((auto-fill-function (if (org-at-property-p) + nil + auto-fill-function))) + (if indent (newline-and-indent) (newline))))))) (defun org-return-indent () "Goto next table row or insert a newline and indent. -- Kaushal Modi --94eb2c19b44679decd05647e2e9d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Feb 4,= 2018 at 5:16 PM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
`org-return' doesn't call any auto fill function.
<= div>
It sort of does, indirectly, via (newline). Please see t= he proposed patch at the end of this email.

Yet, it doesn't break properties drawers.

I agree. Though this patch fixes what <RET> shouldn't do w= hen point is in the property drawer.

If someone has:
<= br>=3D=3D=3D=3D=3D
* Headline
:PROPERTY:
:FOO: some long line that goes beyond fill column
:EN= D:
=3D=3D=3D=3D=3D

It would be highly unlikely that so= me would want to save that file as (assuming it got formatted as below beca= use of auto filling):

=3D=3D=3D=3D=3D
* Headline<= br>
:PROPERTY:
:FOO: some long line that goes beyon= d
fill column
:END:
=3D=3D=3D=3D=3D

So the below patch prevents <RET> from doin= g the above
=C2=A0
I don't think tweaking `org-return' is a good solution. This is not= the
only way to break a line (e.g. "C-q C-j", or "C-M-o"), = so it would not
be a panacea.

I tried C-q C-j and C-M-o= , and both don't allow the auto-filling to happen, even without the bel= ow patch.
=C2=A0
You may want to use fill-nobreak-predicate variable instead, e.g. with
`org-at-property-p'.

I gave that a = try, by tweaking fill-nobreak-predicate inside the org-setup-filling functi= on. But that doesn't work. Looks like the predicate is evaluated *after= * `newline' inserts the newline.. and so `org-at-property-p' would = evaluate to nil.

** The patch **

Lookin= g at the source code of `newline' defun, I came up with this and it wor= ks!

diff --git a/lisp/org.el b/lisp/org.el
index 688e48bcc1d..936= 7304e900 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20471,7 +2= 0471,10 @@ object (e.g., within a comment).=C2=A0 In these case, you need t= o use
=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (delete-and-extr= act-region (point) (line-end-position))))
=C2=A0=C2=A0=C2=A0 =C2=A0(newl= ine-and-indent)
=C2=A0=C2=A0=C2=A0 =C2=A0(save-excursion (insert trailin= g-data))))
-=C2=A0=C2=A0=C2=A0=C2=A0 (t (if indent (newline-and-indent) = (newline))))))
+=C2=A0=C2=A0=C2=A0=C2=A0 (t (let ((auto-fill-function (i= f (org-at-property-p)
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 nil
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 auto-fill-function)))
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0 (if indent (newline-and-indent) (newline)))))))=C2=A0
=C2=A0(defun org-return-indent ()
=C2=A0=C2=A0 "Goto nex= t table row or insert a newline and indent.


--=

Kaushal Modi

--94eb2c19b44679decd05647e2e9d--