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: Sun, 11 Feb 2018 20:13:09 +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> <87r2prbrgd.fsf@nicolasgoaziou.fr> <87inb3bjyw.fsf@nicolasgoaziou.fr> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="089e082678b49284700564f564f8" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54683) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eky03-0000Mu-Rd for emacs-orgmode@gnu.org; Sun, 11 Feb 2018 15:13:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eky01-0006fq-Ud for emacs-orgmode@gnu.org; Sun, 11 Feb 2018 15:13:23 -0500 Received: from mail-yw0-x22a.google.com ([2607:f8b0:4002:c05::22a]:36971) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eky01-0006eN-Ld for emacs-orgmode@gnu.org; Sun, 11 Feb 2018 15:13:21 -0500 Received: by mail-yw0-x22a.google.com with SMTP id v139so8613641ywg.4 for ; Sun, 11 Feb 2018 12:13:21 -0800 (PST) In-Reply-To: <87inb3bjyw.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 --089e082678b49284700564f564f8 Content-Type: text/plain; charset="UTF-8" On Sun, Feb 11, 2018 at 10:54 AM Nicolas Goaziou wrote: > > Would you mind adding a test to `test-org/auto-fill-function' for good > measure? I was actually adding a test for org-return as the commit doesn't modify the org-auto-fill-function. The test I added was this.. but doesn't work. Can you please help? Interactively, the org-return change works as expected, but the test fails with this: Test test-org/return condition: (ert-test-failed ((should (equal "* Heading :PROPERTIES: :SOME_PROP:This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled. :END:" (org-test-with-temp-text "* Heading :PROPERTIES: :SOME_PROP:This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled. :END:" ... ... ... ...))) :form (equal "* Heading :PROPERTIES: :SOME_PROP:This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled. :END:" "* Heading :PROPERTIES: :SOME_PROP:This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled. :END:") :value nil :explanation (array-elt 38 (different-atoms (32 "#x20" "? ") (10 "#xa" "? "))))) FAILED 741/764 test-org/return Here's the patch with test included: >From 416be7c4b7adddffc0c41bba2a070c8849e16d82 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Sun, 11 Feb 2018 14:37:10 -0500 Subject: [PATCH] Do not auto-fill when point is in Org property drawer * lisp/org.el (org-return): Set auto-fill-function to nil when point is in an Org property drawer. * testing/lisp/test-org.el (test-org/return): Add test. --- lisp/org.el | 8 +++++++- testing/lisp/test-org.el | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lisp/org.el b/lisp/org.el index b45cc06187d..b9daba84e6a 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -21111,7 +21111,13 @@ 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 + ;; Do not auto-fill when point is in an Org property drawer. + (let ((auto-fill-function (and (not (org-at-property-p)) + auto-fill-function))) + (if indent + (newline-and-indent) + (newline))))))) (defun org-return-indent () "Goto next table row or insert a newline and indent. diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el index 17e7a223c48..1792950bba6 100644 --- a/testing/lisp/test-org.el +++ b/testing/lisp/test-org.el @@ -1190,6 +1190,14 @@ (should (equal "| a |\n\n| b |" (org-test-with-temp-text "| a |\n| b |" + (org-return) + (buffer-string)))) + ;; Do not auto-fill on hitting inside a property drawer. + (should + (equal "* Heading\n:PROPERTIES:\n:SOME_PROP:This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n\n:END:" + (org-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP:This is a very long property value that goes beyond the fill-column. But this is inside a property drawer, so the auto-filling should be disabled.\n:END:" + (setq-local fill-column 10) + (auto-fill-mode 1) (org-return) (buffer-string))))) -- 2.15.0 -- Kaushal Modi --089e082678b49284700564f564f8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, Feb 11= , 2018 at 10:54 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:

Would you mind adding a test to `test-org/auto-fill-function' for good<= br> measure?

I was actually adding a test for o= rg-return as the commit doesn't modify the org-auto-fill-function.
<= br>
The test I added was this.. but doesn't work. Can you ple= ase help?

Interactively, the org-return change works as e= xpected, but the test fails with this:

Test test-org/return conditio= n:
=C2=A0=C2=A0=C2=A0 (ert-test-failed
=C2=A0=C2=A0=C2=A0=C2=A0 ((sho= uld
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (equal "* Heading
:PROP= ERTIES:
:SOME_PROP:This is a very long property value that goes beyond t= he fill-column. But this is inside a property drawer, so the auto-filling s= hould be disabled.

:END:"
=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 (org-test-with-temp-text &quo= t;* Heading
:PROPERTIES:
:SOME_PROP:This is a very long property valu= e that goes beyond the fill-column. But this is inside a property drawer, s= o the auto-filling should be disabled.<point>
:END:" ... ... = ... ...)))
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 :form
=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0 (equal "* Heading
:PROPERTIES:
:SOME_PROP:This is a ve= ry long property value that goes beyond the fill-column. But this is inside= a property drawer, so the auto-filling should be disabled.

:END:&qu= ot; "* Heading
:PROPERTIES:
:SOME_PROP:This
is a very
long=
property
value that
goes
beyond the
fill-column. But
thi= s is
inside a
property
drawer, so
the
auto-filling
should= be
disabled.

:END:")
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 :val= ue nil :explanation
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (array-elt 38
=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 (different-atoms
=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 (32 &quo= t;#x20" "? ")
=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 (10 "#xa&= quot; "?
")))))
=C2=A0=C2=A0 FAILED=C2=A0 741/764=C2=A0 tes= t-org/return

Here's the patch with test included:
From 416be7c4b7adddffc0c41bba2a070c8849e16d82 Mon Sep 17 00:00:00 2001=
From: Kaushal Modi <kausha= l.modi@gmail.com>
Date: Sun, 11 Feb 2018 14:37:10 -0500
Subjec= t: [PATCH] Do not auto-fill when point is in Org property drawer

* l= isp/org.el (org-return): Set auto-fill-function to nil when point
=C2=A0= is in an Org property drawer.
* testing/lisp/test-org.el (test-org/retu= rn): Add test.

<http://lists.gnu.org/r/emacs-orgmode/2018-02/msg00102= .html>
---
=C2=A0lisp/org.el=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 | 8 +++++++-
=C2=A0testing= /lisp/test-org.el | 8 ++++++++
=C2=A02 files changed, 15 insertions(+), = 1 deletion(-)

diff --git a/lisp/org.el b/lisp/org.el
index b45cc0= 6187d..b9daba84e6a 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -= 21111,7 +21111,13 @@ object (e.g., within a comment).=C2=A0 In these case, = you need to use
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 (delet= e-and-extract-region (point) (line-end-position))))
=C2=A0=C2=A0=C2=A0= =C2=A0 (newline-and-indent)
=C2=A0=C2=A0=C2=A0=C2=A0 (save-excursion (in= sert trailing-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
+=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 ;; Do not auto-fill when point is in an Org property dra= wer.
+=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (let ((auto-fill-function (and (not= (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 auto-fill-function)))=
+=C2=A0=C2=A0=C2=A0 (if indent
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 (newline-and-indent)
+=C2=A0=C2=A0=C2=A0 =C2=A0 (newline)))))))
= =C2=A0
=C2=A0(defun org-return-indent ()
=C2=A0=C2=A0 "Goto next= table row or insert a newline and indent.
diff --git a/testing/lisp/tes= t-org.el b/testing/lisp/test-org.el
index 17e7a223c48..1792950bba6 10064= 4
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@= -1190,6 +1190,14 @@
=C2=A0=C2=A0 (should
=C2=A0=C2=A0=C2=A0 (equal &= quot;| a |\n\n| b |"
=C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0 (org-test-with= -temp-text "| a |<point>\n| b |"
+=C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 (org-return)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (buf= fer-string))))
+=C2=A0 ;; Do not auto-fill on hitting <RET> inside= a property drawer.
+=C2=A0 (should
+=C2=A0=C2=A0 (equal "* Head= ing\n:PROPERTIES:\n:SOME_PROP:This is a very long property value that goes = beyond the fill-column. But this is inside a property drawer, so the auto-f= illing should be disabled.\n\n:END:"
+=C2=A0=C2=A0=C2=A0 =C2=A0 (or= g-test-with-temp-text "* Heading\n:PROPERTIES:\n:SOME_PROP:This is a v= ery long property value that goes beyond the fill-column. But this is insid= e a property drawer, so the auto-filling should be disabled.<point>\n= :END:"
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (setq-local fill-colu= mn 10)
+=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (auto-fill-mode 1)
=C2= =A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 (org-return)
=C2=A0=C2=A0=C2=A0= =C2=A0 =C2=A0=C2=A0=C2=A0 (buffer-string)))))
=C2=A0
--
2.15.0

--

Kaushal Modi

--089e082678b49284700564f564f8--