Patchwork [O] org-capture, removing whitespace from new captures

login
register
Submitter paulusm@telstra.com
Date 2011-09-13 21:19:26
Message ID <20110913211926.GB15861@shift>
Download mbox | patch
Permalink /patch/945/
State Superseded
Delegated to: David Maus
Headers show

Comments

paulusm@telstra.com - 2011-09-13 21:19:26
I found myself manually "cleaning" most CAPTURE buffers of whitespace
prior to committing them with C-c C-c.  The attached patch adds a new
property :whitespace-cleanup to the org-capture-templates.

--
Paul.
Olaf Dietsche - 2011-09-14 08:44:07
paulusm@telstra.com writes:

> I found myself manually "cleaning" most CAPTURE buffers of whitespace
> prior to committing them with C-c C-c.  The attached patch adds a new
> property :whitespace-cleanup to the org-capture-templates.

Thanks for pointing to whitespace-cleanup, I've done this manually
cleaning as well.

You could use org-capture-before-finalize-hook for this:

(add-hook 'org-capture-before-finalize-hook 'whitespace-cleanup)

Regards, Olaf
Paul - 2011-09-14 11:14:15
# olaf+list.orgmode@olafdietsche.de, Wed, 14 Sep 2011 18:44:07 +1000:
> paulusm@telstra.com writes:
> 
> > I found myself manually "cleaning" most CAPTURE buffers of whitespace
> > prior to committing them with C-c C-c.  The attached patch adds a new
> > property :whitespace-cleanup to the org-capture-templates.
> 
> Thanks for pointing to whitespace-cleanup, I've done this manually
> cleaning as well.

My pleasure.  I just had it pointed out to me a couple of days ago!


> You could use org-capture-before-finalize-hook for this:
> 
> (add-hook 'org-capture-before-finalize-hook 'whitespace-cleanup)


In fact adding whitespace-cleanup to org-capture-before-finalize-hook
was what I tried first, but it didn't do what I wanted.  This hook is
called _after_ the buffer is widened - making whitespace-cleanup
operate on the _entire_ buffer, not just the newly added capture.

I believe the patch is still required - I should have explained
org-capture-before-finalize-hook's behaviour more explicitly in my
original submission.


Further to this, can anybody suggest a better documentation string for
org-capture-before-finalize-hook?  (Preferably in tandem with my
proposed patch.)  Currently it is:

    Hook that is run right before a capture process is finalized.
    The capture buffer is still current when this hook runs.

I feel the "finalized" part is somewhat ambiguous.  What it means is
"after the capture buffer is widened, and before it is saved".  I
expected it to mean "BEFORE the capture buffer is widened".

Maybe:
    Hook that is run after the capture buffer is widened and prior to
    being finalized.  The capture buffer is still current when this
    hook runs.


--
Paul.
Olaf Dietsche - 2011-09-14 12:59:17
Paul <emacs-orgmode@lookmumnohands.net> writes:

> # olaf+list.orgmode@olafdietsche.de, Wed, 14 Sep 2011 18:44:07 +1000:
>> paulusm@telstra.com writes:
>> 
>> > I found myself manually "cleaning" most CAPTURE buffers of whitespace
>> > prior to committing them with C-c C-c.  The attached patch adds a new
>> > property :whitespace-cleanup to the org-capture-templates.
>> 
>> Thanks for pointing to whitespace-cleanup, I've done this manually
>> cleaning as well.
>
> My pleasure.  I just had it pointed out to me a couple of days ago!
>
>> You could use org-capture-before-finalize-hook for this:
>> 
>> (add-hook 'org-capture-before-finalize-hook 'whitespace-cleanup)
>
> In fact adding whitespace-cleanup to org-capture-before-finalize-hook
> was what I tried first, but it didn't do what I wanted.  This hook is
> called _after_ the buffer is widened - making whitespace-cleanup
> operate on the _entire_ buffer, not just the newly added capture.
>
> I believe the patch is still required - I should have explained
> org-capture-before-finalize-hook's behaviour more explicitly in my
> original submission.
>
> Further to this, can anybody suggest a better documentation string for
> org-capture-before-finalize-hook?  (Preferably in tandem with my
> proposed patch.)  Currently it is:
>
>     Hook that is run right before a capture process is finalized.
>     The capture buffer is still current when this hook runs.
>
> I feel the "finalized" part is somewhat ambiguous.  What it means is
> "after the capture buffer is widened, and before it is saved".  I
> expected it to mean "BEFORE the capture buffer is widened".
>
> Maybe:
>     Hook that is run after the capture buffer is widened and prior to
>     being finalized.  The capture buffer is still current when this
>     hook runs.

Thanks again for this explanation. I haven't noticed this. For me this
isn't bad though, since I capture everything into an inbox.org.

Regards, Olaf
Bastien Guerry - 2011-10-29 12:08:52
Hi Paul,

Paul <emacs-orgmode@lookmumnohands.net> writes:

> In fact adding whitespace-cleanup to org-capture-before-finalize-hook
> was what I tried first, but it didn't do what I wanted.  This hook is
> called _after_ the buffer is widened - making whitespace-cleanup
> operate on the _entire_ buffer, not just the newly added capture.
>
> I believe the patch is still required - I should have explained
> org-capture-before-finalize-hook's behaviour more explicitly in my
> original submission.

I'm willing to apply this patch -- could you provide it with a
well-formatted ChangeLog entry?

Thanks!

> Further to this, can anybody suggest a better documentation string for
> org-capture-before-finalize-hook?  (Preferably in tandem with my
> proposed patch.)  Currently it is:
>
>     Hook that is run right before a capture process is finalized.
>     The capture buffer is still current when this hook runs.
>
> I feel the "finalized" part is somewhat ambiguous.  What it means is
> "after the capture buffer is widened, and before it is saved".  I
> expected it to mean "BEFORE the capture buffer is widened".
>
> Maybe:
>     Hook that is run after the capture buffer is widened and prior to
>     being finalized.  The capture buffer is still current when this
>     hook runs.

Thanks for the suggestion -- I've updated the docstring like this:

  "Hook that is run right before a capture process is finalized.
   The capture buffer is still current when this hook runs and it is
   widened to the entire buffer."

The convention is that the first sentence should be readable on one
single line.  

Best,

Patch

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index a7dc92b..ae5af6d 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -205,6 +205,9 @@  properties are:
                      capture was invoked, kill the buffer again after capture
                      is finalized.
 
+ :whitespace-cleanup When set, call `whitespace-cleanup' prior to
+                     widening the buffer.
+
 The template defines the text to be inserted.  Often this is an
 org-mode entry (so the first line should start with a star) that
 will be filed as a child of the target headline.  It can also be
@@ -329,7 +332,8 @@  calendar                |  %:type %:date"
 			    ((const :format "%v " :clock-keep) (const t))
 			    ((const :format "%v " :clock-resume) (const t))
 			    ((const :format "%v " :unnarrowed) (const t))
-			    ((const :format "%v " :kill-buffer) (const t))))))))
+			    ((const :format "%v " :kill-buffer) (const t))
+			    ((const :format "%v " :whitespace-cleanup) (const t))))))))
 
 (defcustom org-capture-before-finalize-hook nil
   "Hook that is run right before a capture process is finalized.
@@ -544,6 +548,9 @@  captured item after finalizing."
 	  (org-clock-in)))
       (message "Interrupted clock has been resumed")))
 
+  (when (org-capture-get :whitespace-cleanup 'local)
+    (whitespace-cleanup))
+
   (let ((beg (point-min))
 	(end (point-max))
 	(abort-note nil))