emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* using (id "Name") target in org-capture-templates
@ 2010-12-22 19:33 Sullivan, Gregory (US SSA)
  2010-12-23 11:41 ` Giovanni Ridolfi
  0 siblings, 1 reply; 9+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2010-12-22 19:33 UTC (permalink / raw)
  To: Emacs-orgmode@gnu.org

I would like to have a template that will add a TODO below the "Tasks" heading in the current .org file.  From the documentation, I would think that 

(setq org-capture-templates
      `(("t" "Todo (local)" entry (id "Tasks")
	 "* TODO %? %i\n%T\n" :prepend t)
 ))

would work, but org says 

  org-capture-set-target-location: Cannot find target ID "Tasks"

when I do M-x org-capture in a .org file, then choose 't'.
Could someone let me know the correct syntax to say that I'd like to add the captured note below a heading in the current .org file?

Thanks very much

-- Greg
-- 
Greg Sullivan          gregory.sullivan@baesystems.com
(781)262-4553 (office) (978)430-3461 (cell)

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

* Re: using (id "Name") target in org-capture-templates
  2010-12-22 19:33 Sullivan, Gregory (US SSA)
@ 2010-12-23 11:41 ` Giovanni Ridolfi
  2011-01-06 16:54   ` Sullivan, Gregory (US SSA)
  0 siblings, 1 reply; 9+ messages in thread
From: Giovanni Ridolfi @ 2010-12-23 11:41 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA); +Cc: Emacs-orgmode@gnu.org

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> I would like to have a template that will add a TODO below the "Tasks"
> heading in the current .org file.  From the documentation, I would
> think that 
>
> (setq org-capture-templates
>       `(("t" "Todo (local)" entry (id "Tasks")
> 	 "* TODO %? %i\n%T\n" :prepend t)
>  ))
>
> would work, 

Be careful: "heading" is not "id".

from the documentation of the variable in the file org-mode/lisp/org-capture.el

   target: (id \"id of existing org entry\")
                  File as child of this entry, or in the body of the entry


Do you have a tree like the following?

* Tasks
   :PROPERTIES:
   :ID: Tasks            
:END:

If yes, then it works, if the :ID: value is unique.

cheers,
Giovanni

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

* RE: using (id "Name") target in org-capture-templates
  2010-12-23 11:41 ` Giovanni Ridolfi
@ 2011-01-06 16:54   ` Sullivan, Gregory (US SSA)
  2011-02-11 10:21     ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2011-01-06 16:54 UTC (permalink / raw)
  To: Giovanni Ridolfi; +Cc: Emacs-orgmode@gnu.org

Thanks for the note.  I did indeed mean to use headings.

I think it would be nice to be able to have the file dynamic but the heading static in capture templates.  In my case, I always want to find a particular heading in the buffer that the capture originated from. So I had to put the whole target spec in a function, as in:

   (setq org-capture-templates
      `(("t" "Todo (local)" entry
	 (function (lambda ()
		     (set-buffer (org-capture-get :original-buffer))
		     (let ((hd "Tasks"))
		       (goto-char (point-min))
		       (if (re-search-forward
			    (format org-complex-heading-regexp-format (regexp-quote hd))
			    nil t)
			   (beginning-of-line 2)
			 (goto-char (point-max))
			 (or (bolp) (insert "\n"))
			 (insert "* " hd "\n")
			 (beginning-of-line 0)))))
          ...

most of which is copied from the file+heading case in org-capture.el

What I'd like to be able to write in an org-capture-template is something like:

   (setq org-capture-templates
      `(("t" "Todo (local)" entry 
         (function+heading 
             (lambda () (org-capture-get :original-buffer))
             "Tasks"))
     ...

Where the function sets the buffer, but org machinery is used to match the heading.

Another idiom would be to allow a string-returning function wherever a string is currently allowed for the file target, so the above would be instead:

   (setq org-capture-templates
      `(("t" "Todo (local)" entry 
         (file+heading 
             (lambda () (org-capture-get :original-buffer))
             "Tasks"))
     ...

The last is my preferred, as it would apply to all of the "file+headline", "file+olp", "file+regexp", etc. target specifications in allowed for org-capture-templates.

Thanks.

-- Greg
-- 
Greg Sullivan          gregory.sullivan@baesystems.com
(781)262-4553 (office) (978)430-3461 (cell)

-----Original Message-----
From: Giovanni Ridolfi [mailto:giovanni.ridolfi@yahoo.it] 
Sent: Thursday, December 23, 2010 6:42 AM
To: Sullivan, Gregory (US SSA)
Cc: Emacs-orgmode@gnu.org
Subject: Re: [Orgmode] using (id "Name") target in org-capture-templates

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> I would like to have a template that will add a TODO below the "Tasks"
> heading in the current .org file.  From the documentation, I would
> think that 
>
> (setq org-capture-templates
>       `(("t" "Todo (local)" entry (id "Tasks")
> 	 "* TODO %? %i\n%T\n" :prepend t)
>  ))
>
> would work, 

Be careful: "heading" is not "id".

from the documentation of the variable in the file org-mode/lisp/org-capture.el

   target: (id \"id of existing org entry\")
                  File as child of this entry, or in the body of the entry


Do you have a tree like the following?

* Tasks
   :PROPERTIES:
   :ID: Tasks            
:END:

If yes, then it works, if the :ID: value is unique.

cheers,
Giovanni

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

* Re: using (id "Name") target in org-capture-templates
  2011-01-06 16:54   ` Sullivan, Gregory (US SSA)
@ 2011-02-11 10:21     ` Bastien
  2011-02-22 18:55       ` Sullivan, Gregory (US SSA)
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2011-02-11 10:21 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA); +Cc: Emacs-orgmode@gnu.org

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

Hi Gregory,

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> Thanks for the note.  I did indeed mean to use headings.
>
> I think it would be nice to be able to have the file dynamic but the
> heading static in capture templates.  In my case, I always want to
> find a particular heading in the buffer that the capture originated
> from. So I had to put the whole target spec in a function, as in:

I like the idea of being able to tell capture to use the current file.

This patch against latest Org allows you to use (currentfile) like this:

,----
| (setq org-capture-templates
|   '(("j" "Journal" entry (currentfile) "* %a\n\n%i")))
`----

Let me know if you find this useful.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Allow-currentfile-for-capture-templates.patch --]
[-- Type: text/x-patch, Size: 2582 bytes --]

From a276dc40c860e636be7c8d743bd01b401461a8f5 Mon Sep 17 00:00:00 2001
From: Bastien Guerry <bzg@altern.org>
Date: Fri, 11 Feb 2011 11:17:16 +0100
Subject: [PATCH] Allow (currentfile) for capture templates.

* org-capture.el (org-capture-templates): document currentfile
for capture template.
(org-capture-templates): Allow to use currentfile for capture
templates.
(org-capture-set-target-location): Handle currentfile as a way
to setting the capture buffer.

* org.texi (Template elements): document currentfile for
capture templates.
---
 doc/org.texi        |    4 ++++
 lisp/org-capture.el |   12 ++++++++++++
 2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/doc/org.texi b/doc/org.texi
index f8a7493..be66b75 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -6314,6 +6314,10 @@ Valid values are:
 @item (file "path/to/file")
 Text will be placed at the beginning or end of that file.
 
+@item (currentfile)
+Text will be placed at the beginning or end of the file 
+@code{org-capture} is called from.
+
 @item (id "id of existing org entry")
 Filing as child of this entry, or in the body of the entry.
 
diff --git a/lisp/org-capture.el b/lisp/org-capture.el
index e258308..2f9b379 100644
--- a/lisp/org-capture.el
+++ b/lisp/org-capture.el
@@ -120,6 +120,10 @@ target       Specification of where the captured item should be placed.
              (file \"path/to/file\")
                  Text will be placed at the beginning or end of that file
 
+             (currentfile)
+                 Text will be placed at the beginning or end of the file
+                 org-capture is called from
+
              (id \"id of existing org entry\")
                  File as child of this entry, or in the body of the entry
 
@@ -266,6 +270,8 @@ calendar                |  %:type %:date"
 		   (list :tag "File"
 			 (const :format "" file)
 			 (file :tag "  File"))
+		   (list :tag "Current file"
+			 (const :format "" currentfile))
 		   (list :tag "ID"
 			 (const :format "" id)
 			 (string :tag "  ID"))
@@ -632,6 +638,12 @@ already gone.  Any prefix argument will be passed to the refile comand."
 	(set-buffer (org-capture-target-buffer (nth 1 target)))
 	(setq target-entry-p nil))
 
+       ((eq (car target) 'currentfile)
+	(if (not (and (buffer-file-name) (org-mode-p)))
+	    (error "Cannot call this capture template outside of an Org buffer")
+	  (set-buffer (org-capture-target-buffer (buffer-file-name)))
+	  (setq target-entry-p nil)))
+
        ((eq (car target) 'id)
 	(let ((loc (org-id-find (nth 1 target))))
 	  (if (not loc)
-- 
1.7.4


[-- Attachment #3: Type: text/plain, Size: 14 bytes --]


-- 
 Bastien

[-- Attachment #4: Type: text/plain, Size: 201 bytes --]

_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

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

* RE: using (id "Name") target in org-capture-templates
  2011-02-11 10:21     ` Bastien
@ 2011-02-22 18:55       ` Sullivan, Gregory (US SSA)
  2011-02-27 11:37         ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2011-02-22 18:55 UTC (permalink / raw)
  To: Bastien; +Cc: Emacs-orgmode@gnu.org

It would be quite useful if I could use currentfile in place of "path/to/file" in the various Target patterns.  That is, it would be nice to write something like:

(setq org-capture-templates
   '(("j" "Journal" entry (file+headline currentfile "Journal") "* %a\n\n%i"))
     ("t" "To Do" entry (file+headline currentfile "Tasks") "* TODO %? %i\n")))

Thanks.

-- Greg
-- 
Greg Sullivan          gregory.sullivan@baesystems.com
(781)262-4553 (office) (978)430-3461 (cell)


-----Original Message-----
From: Bastien Guerry [mailto:bastienguerry@googlemail.com] On Behalf Of Bastien
Sent: Friday, February 11, 2011 5:22 AM
To: Sullivan, Gregory (US SSA)
Cc: Giovanni Ridolfi; Emacs-orgmode@gnu.org
Subject: Re: [Orgmode] using (id "Name") target in org-capture-templates

Hi Gregory,

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> Thanks for the note.  I did indeed mean to use headings.
>
> I think it would be nice to be able to have the file dynamic but the 
> heading static in capture templates.  In my case, I always want to 
> find a particular heading in the buffer that the capture originated 
> from. So I had to put the whole target spec in a function, as in:

I like the idea of being able to tell capture to use the current file.

This patch against latest Org allows you to use (currentfile) like this:

,----
| (setq org-capture-templates
|   '(("j" "Journal" entry (currentfile) "* %a\n\n%i")))
`----

Let me know if you find this useful.

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

* Re: using (id "Name") target in org-capture-templates
  2011-02-22 18:55       ` Sullivan, Gregory (US SSA)
@ 2011-02-27 11:37         ` Bastien
  2011-02-28  1:38           ` Sullivan, Gregory (US SSA)
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2011-02-27 11:37 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA); +Cc: Emacs-orgmode@gnu.org

Hi Gregory,

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> It would be quite useful if I could use currentfile in place of
> "path/to/file" in the various Target patterns.  That is, it would be
> nice to write something like:

This is already implemented in Org's git version.  See the email you're
replying to, I gave the explanations.

Thanks,

-- 
 Bastien

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

* RE: using (id "Name") target in org-capture-templates
  2011-02-27 11:37         ` Bastien
@ 2011-02-28  1:38           ` Sullivan, Gregory (US SSA)
  0 siblings, 0 replies; 9+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2011-02-28  1:38 UTC (permalink / raw)
  To: Bastien; +Cc: Emacs-orgmode@gnu.org

The way I understood your patch is that I can use (currentfile) as _the_ target expression in a capture template.  What I was requesting was to use 'capturefile' _within_ a file+headline target expressions. Let me re-include a motivating example - as your citation didn't include it:

 (setq org-capture-templates
   '(("j" "Journal" entry (file+headline currentfile "Journal") "* %a\n\n%i"))
     ("t" "To Do" entry (file+headline currentfile "Tasks") "* TODO %? %i\n")))

which does not seem to be implemented in the current git version, unless I've completely messed up my orgmode git checkout.

Possibly this could be done by checking for the symbol 'currentfile in org-capture-target-buffer, and using (buffer-file-name).
Do you think that would work?

Thanks again.
-- Greg
-- 
Greg Sullivan          gregory.sullivan@baesystems.com
(781)262-4553 (office) (978)430-3461 (cell)


-----Original Message-----
From: Bastien Guerry [mailto:bastienguerry@googlemail.com] On Behalf Of Bastien
Sent: Sunday, February 27, 2011 6:37 AM
To: Sullivan, Gregory (US SSA)
Cc: Giovanni Ridolfi; Emacs-orgmode@gnu.org
Subject: Re: [Orgmode] using (id "Name") target in org-capture-templates

Hi Gregory,

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> It would be quite useful if I could use currentfile in place of
> "path/to/file" in the various Target patterns.  That is, it would be
> nice to write something like:

This is already implemented in Org's git version.  See the email you're
replying to, I gave the explanations.

Thanks,

-- 
 Bastien

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

* Re: using (id "Name") target in org-capture-templates
       [not found] <20110228040226.9CDE5EADE@mx.altern.org>
@ 2011-03-06 17:08 ` Bastien
  2011-03-06 19:57   ` Sullivan, Gregory (US SSA)
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2011-03-06 17:08 UTC (permalink / raw)
  To: Sullivan, Gregory (US SSA); +Cc: Emacs-orgmode@gnu.org

Hi Sullivan,

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> The way I understood your patch is that I can use (currentfile) as
> _the_ target expression in a capture template.  What I was requesting
> was to use 'capturefile' _within_ a file+headline target
> expressions. Let me re-include a motivating example - as your citation
> didn't include it:

Sorry, I overlooked your request.

>  (setq org-capture-templates
>    '(("j" "Journal" entry (file+headline currentfile "Journal") "* %a\n\n%i"))
>      ("t" "To Do" entry (file+headline currentfile "Tasks") "* TODO %? %i\n")))

Actually, you can already do this:

(setq org-capture-templates
   '(("j" "Journal" entry (file+headline buffer-file-name "Journal") "* %a\n\n%i"))
     ("t" "To Do" entry (file+headline buffer-file-name "Tasks") "* TODO %? %i\n")))

See the documentation about file specification.

So I removed (currentfile), which is simply (file buffer-file-name)).

HTH,

-- 
 Bastien

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

* RE: using (id "Name") target in org-capture-templates
  2011-03-06 17:08 ` using (id "Name") target in org-capture-templates Bastien
@ 2011-03-06 19:57   ` Sullivan, Gregory (US SSA)
  0 siblings, 0 replies; 9+ messages in thread
From: Sullivan, Gregory (US SSA) @ 2011-03-06 19:57 UTC (permalink / raw)
  To: Bastien; +Cc: Emacs-orgmode@gnu.org

Perfect.  Thanks very much!

-- Greg
-- 
Greg Sullivan          gregory.sullivan@baesystems.com
(781)262-4553 (office) (978)430-3461 (cell)

-----Original Message-----
From: Bastien Guerry [mailto:bastienguerry@googlemail.com] On Behalf Of Bastien
Sent: Sunday, March 06, 2011 12:08 PM
To: Sullivan, Gregory (US SSA)
Cc: Giovanni Ridolfi; Emacs-orgmode@gnu.org
Subject: Re: [Orgmode] using (id "Name") target in org-capture-templates

Hi Sullivan,

"Sullivan, Gregory (US SSA)" <gregory.sullivan@baesystems.com> writes:

> The way I understood your patch is that I can use (currentfile) as
> _the_ target expression in a capture template.  What I was requesting
> was to use 'capturefile' _within_ a file+headline target
> expressions. Let me re-include a motivating example - as your citation
> didn't include it:

Sorry, I overlooked your request.

>  (setq org-capture-templates
>    '(("j" "Journal" entry (file+headline currentfile "Journal") "* %a\n\n%i"))
>      ("t" "To Do" entry (file+headline currentfile "Tasks") "* TODO %? %i\n")))

Actually, you can already do this:

(setq org-capture-templates
   '(("j" "Journal" entry (file+headline buffer-file-name "Journal") "* %a\n\n%i"))
     ("t" "To Do" entry (file+headline buffer-file-name "Tasks") "* TODO %? %i\n")))

See the documentation about file specification.

So I removed (currentfile), which is simply (file buffer-file-name)).

HTH,

-- 
 Bastien

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

end of thread, other threads:[~2011-03-06 20:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20110228040226.9CDE5EADE@mx.altern.org>
2011-03-06 17:08 ` using (id "Name") target in org-capture-templates Bastien
2011-03-06 19:57   ` Sullivan, Gregory (US SSA)
2010-12-22 19:33 Sullivan, Gregory (US SSA)
2010-12-23 11:41 ` Giovanni Ridolfi
2011-01-06 16:54   ` Sullivan, Gregory (US SSA)
2011-02-11 10:21     ` Bastien
2011-02-22 18:55       ` Sullivan, Gregory (US SSA)
2011-02-27 11:37         ` Bastien
2011-02-28  1:38           ` Sullivan, Gregory (US SSA)

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