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: Mon, 05 Feb 2018 21:59:40 +0000	[thread overview]
Message-ID: <CAFyQvY1c1hNf7b_j8i5EPPZEttEyHOVnxjSddwSYtK1kMHSHzA@mail.gmail.com> (raw)
In-Reply-To: <87y3k8h034.fsf@nicolasgoaziou.fr>

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

On Sun, Feb 4, 2018 at 5:16 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
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 <RET> 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 <RET> 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

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

  reply	other threads:[~2018-02-05 21:59 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 [this message]
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
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=CAFyQvY1c1hNf7b_j8i5EPPZEttEyHOVnxjSddwSYtK1kMHSHzA@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).