emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: Nick Dokos <ndokos@gmail.com>, emacs-orgmode@gnu.org
Subject: Re: Prevent auto-fill-mode from filling Property values in drawers
Date: Sun, 11 Feb 2018 20:13:09 +0000	[thread overview]
Message-ID: <CAFyQvY2Hr=D5zCBO=cPS6h5MddeQWoeNt-4YE_XxHn3d9TORdg@mail.gmail.com> (raw)
In-Reply-To: <87inb3bjyw.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: text/plain, Size: 3899 bytes --]

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
> 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.<point>
: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 <kaushal.modi@gmail.com>
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.

<http://lists.gnu.org/r/emacs-orgmode/2018-02/msg00102.html>
---
 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 |<point>\n| b |"
+        (org-return)
+        (buffer-string))))
+  ;; Do not auto-fill on hitting <RET> 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.<point>\n:END:"
+        (setq-local fill-column 10)
+        (auto-fill-mode 1)
         (org-return)
         (buffer-string)))))

-- 
2.15.0


-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 5169 bytes --]

  reply	other threads:[~2018-02-11 20:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-30 16:50 Prevent auto-fill-mode from filling Property values in drawers Kaushal Modi
2018-02-03 14:16 ` Kaushal Modi
2018-02-03 14:29   ` Nicolas Goaziou
2018-02-03 14:33     ` Kaushal Modi
2018-02-03 14:40       ` Nicolas Goaziou
2018-02-03 14:55         ` Kaushal Modi
2018-02-03 16:16           ` Nicolas Goaziou
2018-02-03 16:20           ` Nick Dokos
2018-02-03 17:41             ` Kaushal Modi
2018-02-03 18:11               ` Nick Dokos
2018-02-03 22:16               ` Nicolas Goaziou
2018-02-04 15:52                 ` Kaushal Modi
2018-02-04 22:16                   ` Nicolas Goaziou
2018-02-05 21:59                     ` Kaushal Modi
2018-02-11 13:12                       ` Nicolas Goaziou
2018-02-11 13:24                         ` Kaushal Modi
2018-02-11 15:54                           ` Nicolas Goaziou
2018-02-11 20:13                             ` Kaushal Modi [this message]
2018-02-11 20:22                               ` Nicolas Goaziou
2018-02-11 20:29                                 ` Kaushal Modi
2018-02-11 20:33                                   ` Nicolas Goaziou
2018-02-11 20:23                               ` Kaushal Modi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAFyQvY2Hr=D5zCBO=cPS6h5MddeQWoeNt-4YE_XxHn3d9TORdg@mail.gmail.com' \
    --to=kaushal.modi@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=mail@nicolasgoaziou.fr \
    --cc=ndokos@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).