emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* org-capture with function type target
@ 2013-11-17  1:13 York Zhao
  2013-11-18  1:32 ` York Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: York Zhao @ 2013-11-17  1:13 UTC (permalink / raw)
  To: emacs-orgmode

Hi list,

I'm been so frustrated when trying to use function as `target' in an
org-capture' template, here is my example:

1. Create a file "~/test.org" and add a line "* Level 1", make sure to add a
newline character after the inserted line
2. Set org-capture-template as:
(setq org-capture-templates
      `(("t"
         "Test"
         entry
         (function
          (lambda ()
            (set-buffer (org-capture-target-buffer "~/test.org"))
            (goto-char (point-max))))
         "* Level 2"
         :immediate-finish t)))
3. Type "C-c c t"
4. The result of "test.org" becomes:

* Level 1
* Level 2

But what I wanted is:

* Level 1
** Level 2

I looked into "org-capture.el" and figured out that it is because when
`:exact-position' is set, function `org-capture-place-entry' never insert
template as a child of current entry. And `:exact-position' is set when Target
is a function.

I don't understand why it is designed this way, does it have to be this way?
what can I do if I want to insert "Level 2" as a child of "Level 1" while using
a function as template target?


Thanks,

York

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

* Re: org-capture with function type target
  2013-11-17  1:13 org-capture with function type target York Zhao
@ 2013-11-18  1:32 ` York Zhao
  2013-11-26  5:29   ` Carsten Dominik
  0 siblings, 1 reply; 4+ messages in thread
From: York Zhao @ 2013-11-18  1:32 UTC (permalink / raw)
  To: emacs-orgmode

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

To whom it may concern,

Please find attached my patch to address this issue. Please let me
know if the patch is acceptable.

Thanks,

York


On Sat, Nov 16, 2013 at 8:13 PM, York Zhao <gtdplatform@gmail.com> wrote:
> Hi list,
>
> I'm been so frustrated when trying to use function as `target' in an
> org-capture' template, here is my example:
>
> 1. Create a file "~/test.org" and add a line "* Level 1", make sure to add a
> newline character after the inserted line
> 2. Set org-capture-template as:
> (setq org-capture-templates
>       `(("t"
>          "Test"
>          entry
>          (function
>           (lambda ()
>             (set-buffer (org-capture-target-buffer "~/test.org"))
>             (goto-char (point-max))))
>          "* Level 2"
>          :immediate-finish t)))
> 3. Type "C-c c t"
> 4. The result of "test.org" becomes:
>
> * Level 1
> * Level 2
>
> But what I wanted is:
>
> * Level 1
> ** Level 2
>
> I looked into "org-capture.el" and figured out that it is because when
> `:exact-position' is set, function `org-capture-place-entry' never insert
> template as a child of current entry. And `:exact-position' is set when Target
> is a function.
>
> I don't understand why it is designed this way, does it have to be this way?
> what can I do if I want to insert "Level 2" as a child of "Level 1" while using
> a function as template target?
>
>
> Thanks,
>
> York

[-- Attachment #2: 0001-org-capture-place-entry-Do-not-special-casing-for-ex.patch --]
[-- Type: application/octet-stream, Size: 1906 bytes --]

From 0c0c71e87a71df3e58bef358b0792cf55cc17d26 Mon Sep 17 00:00:00 2001
From: York Zhao <gtdplatform@gmail.com>
Date: Sun, 17 Nov 2013 18:48:55 -0500
Subject: [PATCH] (org-capture-place-entry): Do not special casing for
 `:exact-position' capture target

Assuming file "test.org" has a single headline "* Level 1" (ended with
newline character), when trying to use function type capture target in
an org-capture template, as shown in the example:

(setq org-capture-templates
      `(("t"
         "Test function type target"
         entry
         (function
          (lambda ()
            (set-buffer (org-capture-target-buffer "test.org"))
            (goto-char (point-max))))
         "* Level 2")))

When this template gets filled, file "test.org" becomes:

* Level 1
* Level 2

Instead of:

* Level 1
** Level 2

This is because when using function type target, `:exact-position' is
used to store buffer position returned by user's function (the lambda
function here), and function `org-capture-place-entry' will never
insert template as a child of current entry when `:exact-position' is
used.

The problem is addressed by not special casing for `:exact-position'
in function `org-capture-place-entry'.

York
---
 lisp/org-capture.el | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index 39804ac..f47a2c5 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -1021,9 +1021,9 @@ may have been stored before."
 	 (target-entry-p (org-capture-get :target-entry-p))
 	 level beg end file)
 
+    (and (org-capture-get :exact-position)
+	 (goto-char (org-capture-get :exact-position)))
     (cond
-     ((org-capture-get :exact-position)
-      (goto-char (org-capture-get :exact-position)))
      ((not target-entry-p)
       ;; Insert as top-level entry, either at beginning or at end of file
       (setq level 1)
-- 
1.8.0


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

* Re: org-capture with function type target
  2013-11-18  1:32 ` York Zhao
@ 2013-11-26  5:29   ` Carsten Dominik
  2013-11-27  2:29     ` York Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: Carsten Dominik @ 2013-11-26  5:29 UTC (permalink / raw)
  To: York Zhao; +Cc: emacs-orgmode

Hi York,

I have applied your patch.  Thank you!

- Carsten
On 18.11.2013, at 02:32, York Zhao <gtdplatform@gmail.com> wrote:

> To whom it may concern,
> 
> Please find attached my patch to address this issue. Please let me
> know if the patch is acceptable.
> 
> Thanks,
> 
> York
> 
> 
> On Sat, Nov 16, 2013 at 8:13 PM, York Zhao <gtdplatform@gmail.com> wrote:
>> Hi list,
>> 
>> I'm been so frustrated when trying to use function as `target' in an
>> org-capture' template, here is my example:
>> 
>> 1. Create a file "~/test.org" and add a line "* Level 1", make sure to add a
>> newline character after the inserted line
>> 2. Set org-capture-template as:
>> (setq org-capture-templates
>>      `(("t"
>>         "Test"
>>         entry
>>         (function
>>          (lambda ()
>>            (set-buffer (org-capture-target-buffer "~/test.org"))
>>            (goto-char (point-max))))
>>         "* Level 2"
>>         :immediate-finish t)))
>> 3. Type "C-c c t"
>> 4. The result of "test.org" becomes:
>> 
>> * Level 1
>> * Level 2
>> 
>> But what I wanted is:
>> 
>> * Level 1
>> ** Level 2
>> 
>> I looked into "org-capture.el" and figured out that it is because when
>> `:exact-position' is set, function `org-capture-place-entry' never insert
>> template as a child of current entry. And `:exact-position' is set when Target
>> is a function.
>> 
>> I don't understand why it is designed this way, does it have to be this way?
>> what can I do if I want to insert "Level 2" as a child of "Level 1" while using
>> a function as template target?
>> 
>> 
>> Thanks,
>> 
>> York
> <0001-org-capture-place-entry-Do-not-special-casing-for-ex.patch>

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

* Re: org-capture with function type target
  2013-11-26  5:29   ` Carsten Dominik
@ 2013-11-27  2:29     ` York Zhao
  0 siblings, 0 replies; 4+ messages in thread
From: York Zhao @ 2013-11-27  2:29 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

Hi Carsten,

Thank you.

York

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

end of thread, other threads:[~2013-11-27  2:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-17  1:13 org-capture with function type target York Zhao
2013-11-18  1:32 ` York Zhao
2013-11-26  5:29   ` Carsten Dominik
2013-11-27  2:29     ` York Zhao

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