emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Allow more control over inserted whitespace in capture templates
@ 2012-02-13 12:26 Toby Cubitt
  2012-04-16 13:21 ` Toby Cubitt
  2012-04-20 11:58 ` Bastien
  0 siblings, 2 replies; 4+ messages in thread
From: Toby Cubitt @ 2012-02-13 12:26 UTC (permalink / raw)
  To: emacs-orgmode

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

When capturing an item as a subheading, the capture template :empty-lines
property is not sufficient to ensure the correct document layout is
maintained after capturing.

This patch fixes the capture behaviour to insert new subheadings
immediately after the previous heading (rather than immediately before
the next one). And it adds new :empty-lines-before and :empty-lines-after
capture template properties. (I can split these two changes into
separated patches, if desired.)

When set, the new :empty-lines-before and :empty-lines-after properties
take precedence over :empty-lines in determining the amount of whitespace
to add before or after the captured item, respectively. Together, these
changes allow the correct document layout to be achieved after capturing,
without any manual editing.

(Since the whole idea of org-capture is to rapidly capture new ideas or
todos, having to manually edit whitespace after capturing to fix the
document layout is far from ideal.)


To give a more detailed example of why I think these changes are needed,
consider for example an org-mode document in which headings are separated
by two empty lines, and subheadings are separated by a single empty
line. (This is a natural layout if one wants headings to be separated by
whitespace when folded, but subheadings not to be separated when folded):

------------------------
* heading 1
** subheading 1.1

** subheading 1.2


* heading 2
** subheading 2.1
------------------------

Let's say I want add a captured item as a new "subheading 1.3" under
"heading 1", preserving this layout structure. Then we need to add the
new item immediately after "subheading 1.2", inserting one empty line
before and two empty lines after. There appears to be no way to do this
using :empty-lines.

In fact, the existing implementation adds the new capture item
immediately *before* the *following* heading ("heading 2" in this case),
which seems to be altogether wrong, as it effectively forces two empty
lines before the new item, regardless of the :empty-lines setting.

Currently, setting :empty-lines to 0 leaves the document looking like
this:

------------------------
* heading 1
** subheading 1.1

** subheading 1.2


** subheading 1.3
* heading 2
** subheading 2.1
------------------------

whilst setting :empty-lines to 1 leaves the document looking like this:

------------------------
* heading 1
** subheading 1.1

** subheading 1.2



** subheading 1.3

* heading 2
** subheading 2.1
------------------------

neither of which are likely to ever be what we want.

With this patch, setting the new :empty-lines-before to 1 and
:empty-lines-after to 2 results in the correct structure after capturing:

------------------------
* heading 1
** subheading 1.1

** subheading 1.2

** subheading 1.3


* heading 2
** subheading 2.1
------------------------


I think this patch is largely orthogonal to the recent "removing
whitespace from new captures" patch (currently in patchwork). That patch
causes `whitespace-cleanup' to be called in the CAPTURE buffer before
finalizing, which doesn't affect the additional whitespace inserted later
on by the :empty-lines property. This patch allows more control over the
latter, by providing a fairly simple extension of the existing
:empty-lines property.

Toby
-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

[-- Attachment #2: 0001-Capture-Allow-more-control-over-inserted-whitespace-.patch --]
[-- Type: text/x-patch, Size: 3667 bytes --]

From 37cfa6214f0875ed7ddceae27948394cf78d18d6 Mon Sep 17 00:00:00 2001
From: Toby S. Cubitt <tsc25@cantab.net>
Date: Sun, 29 Jan 2012 16:52:08 +0100
Subject: [PATCH] Capture: Allow more control over inserted whitespace in capture templates

* lisp/org-capture.el (org-capture-place-entry): Place captured entry
immediately after last subheading of target, instead of just before
next heading at same level as target.
* lisp/org-capture.el (org-capture-templates): Document new capture
template properties.
* lisp/org-capture.el (org-capture-place-entry,
org-capture-empty-lines-before): Make new :empty-lines-before property
override :empty-lines when inserting empty lines before captured
captured entry.
* lisp/org-capture.el (org-capture-finalize,
org-capture-empty-lines-after): Make new :empty-lines-after property
override :empty-lines when inserting empty lines after captured
captured entry.
---
 lisp/org-capture.el |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 01ec85d..d79c5a4 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -183,6 +183,14 @@ properties are:
                      before and after the new item.  Default 0, only common
                      other value is 1.
 
+ :empty-lines-before Set this to the number of lines the should be inserted
+                     before the new item. Overrides :empty-lines for the
+                     number lines inserted before.
+
+ :empty-lines-after  Set this to the number of lines the should be inserted
+                     after the new item. Overrides :empty-lines for the
+                     number of lines inserted after.
+
  :clock-in           Start the clock in this item.
 
  :clock-keep         Keep the clock running when filing the captured entry.
@@ -574,7 +582,8 @@ captured item after finalizing."
 	  (goto-char end)
 	  (or (bolp) (newline))
 	  (org-capture-empty-lines-after
-	   (or (org-capture-get :empty-lines 'local) 0))))
+	   (or (org-capture-get :empty-lines-after 'local)
+	       (org-capture-get :empty-lines 'local) 0))))
       ;; Postprocessing:  Update Statistics cookies, do the sorting
       (when (eq major-mode 'org-mode)
 	(save-excursion
@@ -890,7 +899,7 @@ it.  When it is a variable, retrieve the value.  Return whatever we get."
 	  (progn
 	    (outline-next-heading)
 	    (or (bolp) (insert "\n")))
-	(org-end-of-subtree t t)
+	(org-end-of-subtree t nil)
 	(or (bolp) (insert "\n")))))
     (org-capture-empty-lines-before)
     (setq beg (point))
@@ -1125,7 +1134,8 @@ Of course, if exact position has been required, just put it there."
 (defun org-capture-empty-lines-before (&optional n)
   "Arrange for the correct number of empty lines before the insertion point.
 Point will be after the empty lines, so insertion can directly be done."
-  (setq n (or n (org-capture-get :empty-lines) 0))
+  (setq n (or n (org-capture-get :empty-lines-before)
+	      (org-capture-get :empty-lines) 0))
   (let ((pos (point)))
     (org-back-over-empty-lines)
     (delete-region (point) pos)
@@ -1134,7 +1144,8 @@ Point will be after the empty lines, so insertion can directly be done."
 (defun org-capture-empty-lines-after (&optional n)
   "Arrange for the correct number of empty lines after the inserted string.
 Point will remain at the first line after the inserted text."
-  (setq n (or n (org-capture-get :empty-lines) 0))
+  (setq n (or n (org-capture-get :empty-lines-after)
+	      (org-capture-get :empty-lines) 0))
   (org-back-over-empty-lines)
   (while (looking-at "[ \t]*\n") (replace-match ""))
   (let ((pos (point)))
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Allow more control over inserted whitespace in capture templates
  2012-02-13 12:26 [PATCH] Allow more control over inserted whitespace in capture templates Toby Cubitt
@ 2012-04-16 13:21 ` Toby Cubitt
  2012-04-17 23:28   ` Bernt Hansen
  2012-04-20 11:58 ` Bastien
  1 sibling, 1 reply; 4+ messages in thread
From: Toby Cubitt @ 2012-04-16 13:21 UTC (permalink / raw)
  To: emacs-orgmode

Was there any feedback on this patch, or did it get lost in the noise?

At least for me, org-capture breaks the document heading layout by
inserting incorrect amounts of whitespace. And there's no way to
configure capture templates to make it work correctly.

The patch I posted fixes this behaviour.

(Or am I missing some already-existing way of doing this? See below for a
detailed description of the problem.)

Toby




On Mon, Feb 13, 2012 at 01:26:09PM +0100, Toby Cubitt wrote:
> When capturing an item as a subheading, the capture template :empty-lines
> property is not sufficient to ensure the correct document layout is
> maintained after capturing.
> 
> This patch fixes the capture behaviour to insert new subheadings
> immediately after the previous heading (rather than immediately before
> the next one). And it adds new :empty-lines-before and :empty-lines-after
> capture template properties. (I can split these two changes into
> separated patches, if desired.)
> 
> When set, the new :empty-lines-before and :empty-lines-after properties
> take precedence over :empty-lines in determining the amount of whitespace
> to add before or after the captured item, respectively. Together, these
> changes allow the correct document layout to be achieved after capturing,
> without any manual editing.
> 
> (Since the whole idea of org-capture is to rapidly capture new ideas or
> todos, having to manually edit whitespace after capturing to fix the
> document layout is far from ideal.)
> 
> 
> To give a more detailed example of why I think these changes are needed,
> consider for example an org-mode document in which headings are separated
> by two empty lines, and subheadings are separated by a single empty
> line. (This is a natural layout if one wants headings to be separated by
> whitespace when folded, but subheadings not to be separated when folded):
> 
> ------------------------
> * heading 1
> ** subheading 1.1
> 
> ** subheading 1.2
> 
> 
> * heading 2
> ** subheading 2.1
> ------------------------
> 
> Let's say I want add a captured item as a new "subheading 1.3" under
> "heading 1", preserving this layout structure. Then we need to add the
> new item immediately after "subheading 1.2", inserting one empty line
> before and two empty lines after. There appears to be no way to do this
> using :empty-lines.
> 
> In fact, the existing implementation adds the new capture item
> immediately *before* the *following* heading ("heading 2" in this case),
> which seems to be altogether wrong, as it effectively forces two empty
> lines before the new item, regardless of the :empty-lines setting.
> 
> Currently, setting :empty-lines to 0 leaves the document looking like
> this:
> 
> ------------------------
> * heading 1
> ** subheading 1.1
> 
> ** subheading 1.2
> 
> 
> ** subheading 1.3
> * heading 2
> ** subheading 2.1
> ------------------------
> 
> whilst setting :empty-lines to 1 leaves the document looking like this:
> 
> ------------------------
> * heading 1
> ** subheading 1.1
> 
> ** subheading 1.2
> 
> 
> 
> ** subheading 1.3
> 
> * heading 2
> ** subheading 2.1
> ------------------------
> 
> neither of which are likely to ever be what we want.
> 
> With this patch, setting the new :empty-lines-before to 1 and
> :empty-lines-after to 2 results in the correct structure after capturing:
> 
> ------------------------
> * heading 1
> ** subheading 1.1
> 
> ** subheading 1.2
> 
> ** subheading 1.3
> 
> 
> * heading 2
> ** subheading 2.1
> ------------------------
> 
> 
> I think this patch is largely orthogonal to the recent "removing
> whitespace from new captures" patch (currently in patchwork). That patch
> causes `whitespace-cleanup' to be called in the CAPTURE buffer before
> finalizing, which doesn't affect the additional whitespace inserted later
> on by the :empty-lines property. This patch allows more control over the
> latter, by providing a fairly simple extension of the existing
> :empty-lines property.
> 
> Toby


-- 
Dr T. S. Cubitt
Mathematics and Quantum Information group
Department of Mathematics
Complutense University
Madrid, Spain

email: tsc25@cantab.net
web:   www.dr-qubit.org

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Allow more control over inserted whitespace in capture templates
  2012-04-16 13:21 ` Toby Cubitt
@ 2012-04-17 23:28   ` Bernt Hansen
  0 siblings, 0 replies; 4+ messages in thread
From: Bernt Hansen @ 2012-04-17 23:28 UTC (permalink / raw)
  To: Toby Cubitt; +Cc: emacs-orgmode

This patch is sitting on the patchwork server.  It's not lost.

http://patchwork.newartisans.com/project/org-mode/list/

-Bernt

Toby Cubitt <tsc25@cantab.net> writes:

> Was there any feedback on this patch, or did it get lost in the noise?
>
> At least for me, org-capture breaks the document heading layout by
> inserting incorrect amounts of whitespace. And there's no way to
> configure capture templates to make it work correctly.
>
> The patch I posted fixes this behaviour.
>
> (Or am I missing some already-existing way of doing this? See below for a
> detailed description of the problem.)
>
> Toby
>
>
>
>
> On Mon, Feb 13, 2012 at 01:26:09PM +0100, Toby Cubitt wrote:
>> When capturing an item as a subheading, the capture template :empty-lines
>> property is not sufficient to ensure the correct document layout is
>> maintained after capturing.
>> 
>> This patch fixes the capture behaviour to insert new subheadings
>> immediately after the previous heading (rather than immediately before
>> the next one). And it adds new :empty-lines-before and :empty-lines-after
>> capture template properties. (I can split these two changes into
>> separated patches, if desired.)
>> 
>> When set, the new :empty-lines-before and :empty-lines-after properties
>> take precedence over :empty-lines in determining the amount of whitespace
>> to add before or after the captured item, respectively. Together, these
>> changes allow the correct document layout to be achieved after capturing,
>> without any manual editing.
>> 
>> (Since the whole idea of org-capture is to rapidly capture new ideas or
>> todos, having to manually edit whitespace after capturing to fix the
>> document layout is far from ideal.)
>> 
>> 
>> To give a more detailed example of why I think these changes are needed,
>> consider for example an org-mode document in which headings are separated
>> by two empty lines, and subheadings are separated by a single empty
>> line. (This is a natural layout if one wants headings to be separated by
>> whitespace when folded, but subheadings not to be separated when folded):
>> 
>> ------------------------
>> * heading 1
>> ** subheading 1.1
>> 
>> ** subheading 1.2
>> 
>> 
>> * heading 2
>> ** subheading 2.1
>> ------------------------
>> 
>> Let's say I want add a captured item as a new "subheading 1.3" under
>> "heading 1", preserving this layout structure. Then we need to add the
>> new item immediately after "subheading 1.2", inserting one empty line
>> before and two empty lines after. There appears to be no way to do this
>> using :empty-lines.
>> 
>> In fact, the existing implementation adds the new capture item
>> immediately *before* the *following* heading ("heading 2" in this case),
>> which seems to be altogether wrong, as it effectively forces two empty
>> lines before the new item, regardless of the :empty-lines setting.
>> 
>> Currently, setting :empty-lines to 0 leaves the document looking like
>> this:
>> 
>> ------------------------
>> * heading 1
>> ** subheading 1.1
>> 
>> ** subheading 1.2
>> 
>> 
>> ** subheading 1.3
>> * heading 2
>> ** subheading 2.1
>> ------------------------
>> 
>> whilst setting :empty-lines to 1 leaves the document looking like this:
>> 
>> ------------------------
>> * heading 1
>> ** subheading 1.1
>> 
>> ** subheading 1.2
>> 
>> 
>> 
>> ** subheading 1.3
>> 
>> * heading 2
>> ** subheading 2.1
>> ------------------------
>> 
>> neither of which are likely to ever be what we want.
>> 
>> With this patch, setting the new :empty-lines-before to 1 and
>> :empty-lines-after to 2 results in the correct structure after capturing:
>> 
>> ------------------------
>> * heading 1
>> ** subheading 1.1
>> 
>> ** subheading 1.2
>> 
>> ** subheading 1.3
>> 
>> 
>> * heading 2
>> ** subheading 2.1
>> ------------------------
>> 
>> 
>> I think this patch is largely orthogonal to the recent "removing
>> whitespace from new captures" patch (currently in patchwork). That patch
>> causes `whitespace-cleanup' to be called in the CAPTURE buffer before
>> finalizing, which doesn't affect the additional whitespace inserted later
>> on by the :empty-lines property. This patch allows more control over the
>> latter, by providing a fairly simple extension of the existing
>> :empty-lines property.
>> 
>> Toby

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Allow more control over inserted whitespace in capture templates
  2012-02-13 12:26 [PATCH] Allow more control over inserted whitespace in capture templates Toby Cubitt
  2012-04-16 13:21 ` Toby Cubitt
@ 2012-04-20 11:58 ` Bastien
  1 sibling, 0 replies; 4+ messages in thread
From: Bastien @ 2012-04-20 11:58 UTC (permalink / raw)
  To: emacs-orgmode

Hi Toby,

Toby Cubitt <tsc25@cantab.net> writes:

> When capturing an item as a subheading, the capture template :empty-lines
> property is not sufficient to ensure the correct document layout is
> maintained after capturing.
>
> This patch fixes the capture behaviour to insert new subheadings
> immediately after the previous heading (rather than immediately before
> the next one). And it adds new :empty-lines-before and :empty-lines-after
> capture template properties. (I can split these two changes into
> separated patches, if desired.)

Applied in master, thanks.

-- 
 Bastien

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-20 11:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-02-13 12:26 [PATCH] Allow more control over inserted whitespace in capture templates Toby Cubitt
2012-04-16 13:21 ` Toby Cubitt
2012-04-17 23:28   ` Bernt Hansen
2012-04-20 11:58 ` Bastien

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).