emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: York Zhao <gtdplatform@gmail.com>
To: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: org-capture with function type target
Date: Sun, 17 Nov 2013 20:32:57 -0500	[thread overview]
Message-ID: <CAD3zm22HZ4j1iLk2F_9EDc8KOCVBUQ-g-G4FB4V0iorcTvckEA@mail.gmail.com> (raw)
In-Reply-To: <CAD3zm20QTWjuHLXAW9JBnFSaXQqp3J+SbBWQ3FBdWaergco2zQ@mail.gmail.com>

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



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
         "Test function type target"
          (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

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

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

  reply	other threads:[~2013-11-18  1:33 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-17  1:13 org-capture with function type target York Zhao
2013-11-18  1:32 ` York Zhao [this message]
2013-11-26  5:29   ` Carsten Dominik
2013-11-27  2:29     ` York Zhao

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:

  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=CAD3zm22HZ4j1iLk2F_9EDc8KOCVBUQ-g-G4FB4V0iorcTvckEA@mail.gmail.com \
    --to=gtdplatform@gmail.com \
    --cc=emacs-orgmode@gnu.org \


* 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


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