emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Merge Properties into Template
@ 2011-10-06  9:35 Richard Parsons
  2011-10-06 10:40 ` Merge Properties into Template; [babel] Giovanni Ridolfi
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Richard Parsons @ 2011-10-06  9:35 UTC (permalink / raw)
  To: emacs-orgmode

Hi all

I'm new to emacs and I'm new to org-mode, apologies if I should have
found this myself, but I have searched and come up blank.

I have a node with properties and I would like to merge that data into
a template.  For example:

* Dogs
** Fido
  :PROPERTIES:
  :BREED:    West Highland Terrier
  :COLOR:    White
  :AGE:      2
  :END:
* Templates
** Dog Template
Your dog, called [HEADLINE], is a [COLOR] [BREED], who is [AGE] years old.

I want to merge the item called "Fido" into the template called "Dog Template".

Could someone point me to the right bit of the manual so I can learn
how to do this?  Or should I be looking to use a different elisp
module to achieve this, something that plays nicely with org-mode?

Many thanks
Richard

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

* Re: Merge Properties into Template; [babel]
  2011-10-06  9:35 Merge Properties into Template Richard Parsons
@ 2011-10-06 10:40 ` Giovanni Ridolfi
  2011-10-06 11:35 ` Merge Properties into Template suvayu ali
  2011-10-06 12:50 ` Christian Moe
  2 siblings, 0 replies; 7+ messages in thread
From: Giovanni Ridolfi @ 2011-10-06 10:40 UTC (permalink / raw)
  To: Richard Parsons; +Cc: emacs-orgmode

Richard Parsons <richard.lee.parsons@gmail.com> writes:

 Hi Richard,
>
> I have a node with properties and I would like to merge that data into
> a template.  For example:
>
> * Dogs
> ** Fido
>   :PROPERTIES:
>   :BREED:    West Highland Terrier
>   :COLOR:    White
>   :AGE:      2
>   :END:
> * Templates
> ** Dog Template
> Your dog, called [HEADLINE], is a [COLOR] [BREED], who is [AGE] years old.
>
> I want to merge the item called "Fido" into the template called "Dog Template".
>
> Could someone point me to the right bit of the manual 

I think that the only way to extract the information of a property,
in org, is column view.[1]

However you may be able to use something like perl or awk to extract the info
and babel to use in the org file.

I'm a babel ignorant. CCed Eric Schulte for help ;-)

hth,
Giovanni

[1] But you'll end with this:
* DOGS
** Fido 
  :PROPERTIES:
  :ID: dog 
  :COLUMNS: %dog %ITEM %is %BREED %whos %AGE %old
  :dog: Your dog, called
  :is: , is a
  :BREED:    West Highland Terrier
  :COLOR:    White
  :whos: , who is
  :AGE:      2
  :old: years old.
  :END:
** Templates
*** Dog Template
Your dog, called [HEADLINE], is a [COLOR] [BREED], who is [AGE] years old.
*** Dog column
#+BEGIN: columnview :hlines 1 :id dog
| dog              | ITEM    | is     | BREED                 | whos     | AGE | old        |
|------------------+---------+--------+-----------------------+----------+-----+------------|
| Your dog, called | ** Fido | , is a | West Highland Terrier | , who is |   2 | years old. |
#+END

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

* Re: Merge Properties into Template
  2011-10-06  9:35 Merge Properties into Template Richard Parsons
  2011-10-06 10:40 ` Merge Properties into Template; [babel] Giovanni Ridolfi
@ 2011-10-06 11:35 ` suvayu ali
  2011-10-06 12:50 ` Christian Moe
  2 siblings, 0 replies; 7+ messages in thread
From: suvayu ali @ 2011-10-06 11:35 UTC (permalink / raw)
  To: Richard Parsons; +Cc: emacs-orgmode

On Thu, Oct 6, 2011 at 11:35 AM, Richard Parsons
<richard.lee.parsons@gmail.com> wrote:
> Could someone point me to the right bit of the manual so I can learn
> how to do this?

Maybe some custom lisp function using the property API will do the job?

<http://orgmode.org/manual/Using-the-property-API.html#Using-the-property-API>

-- 
Suvayu

Open source is the future. It sets us free.

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

* Re: Merge Properties into Template
  2011-10-06  9:35 Merge Properties into Template Richard Parsons
  2011-10-06 10:40 ` Merge Properties into Template; [babel] Giovanni Ridolfi
  2011-10-06 11:35 ` Merge Properties into Template suvayu ali
@ 2011-10-06 12:50 ` Christian Moe
  2011-10-06 15:56   ` Richard Parsons
  2 siblings, 1 reply; 7+ messages in thread
From: Christian Moe @ 2011-10-06 12:50 UTC (permalink / raw)
  To: Richard Parsons; +Cc: emacs-orgmode

Hi,

Org doesn't already have a particular way to do this, I think, so a 
little elisp is called for. It's fairly easy with the Org Properties API.

Here's a modest example that will work with your sample document:

#+begin_src emacs-lisp
   (defun cm/org-merge (target)
     "Fill a template headlined TARGET with the properties of the
   entry at point, replacing e.g. `[AGE]' with the contents of
   an :AGE: property. Use `[HEADLINE]' for the text of the entry
   heading."
     (interactive "sTarget template: ")
     (let ((props (org-entry-properties))
           prop
           template)
       (setq props (cons (cons "HEADLINE" (org-get-heading)) props))
       (save-excursion
         (org-open-link-from-string (format "[[*%s]]" target))
         (setq template (org-get-entry)))
       (dolist (p props)
         (setq template
               (replace-regexp-in-string
                (format "\\[%s\\]" (car p))
                (cdr p)
                template t)))
       (message template)))
#+end_src

Evaluate this code. Then place point in the Fido entry, do `M-x 
cm/org-merge', and type `Dog Template' at the prompt.

To improve on that, how do you want to use it?
Once Fido's data are merged with the template, what do you want to do 
with the results? Mail them to someone? Export them to HTML? Make a 
new Org entry with the contents and file it somewhere?

Yours,
Christian




On 10/6/11 11:35 AM, Richard Parsons wrote:
> Hi all
>
> I'm new to emacs and I'm new to org-mode, apologies if I should have
> found this myself, but I have searched and come up blank.
>
> I have a node with properties and I would like to merge that data into
> a template.  For example:
>
> * Dogs
> ** Fido
>    :PROPERTIES:
>    :BREED:    West Highland Terrier
>    :COLOR:    White
>    :AGE:      2
>    :END:
> * Templates
> ** Dog Template
> Your dog, called [HEADLINE], is a [COLOR] [BREED], who is [AGE] years old.
>
> I want to merge the item called "Fido" into the template called "Dog Template".
>
> Could someone point me to the right bit of the manual so I can learn
> how to do this?  Or should I be looking to use a different elisp
> module to achieve this, something that plays nicely with org-mode?
>
> Many thanks
> Richard
>
>

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

* Re: Merge Properties into Template
  2011-10-06 12:50 ` Christian Moe
@ 2011-10-06 15:56   ` Richard Parsons
  2011-10-06 20:52     ` Christian Moe
  2011-10-07  7:04     ` Christian Moe
  0 siblings, 2 replies; 7+ messages in thread
From: Richard Parsons @ 2011-10-06 15:56 UTC (permalink / raw)
  To: mail; +Cc: emacs-orgmode

Hi Christian

On Thu, Oct 6, 2011 at 1:50 PM, Christian Moe <mail@christianmoe.com> wrote:
> Org doesn't already have a particular way to do this, I think, so a little
> elisp is called for. It's fairly easy with the Org Properties API.

Firstly, thank you so much for taking the time to write some code,
which (even as a newbie) I was able to get running quickly and easily.

> Here's a modest example that will work with your sample document:
...<snip>...
> Evaluate this code. Then place point in the Fido entry, do `M-x
> cm/org-merge', and type `Dog Template' at the prompt.
>
> To improve on that, how do you want to use it?

My actual use case is that I want to merge data about letters and
phone calls into documents for printing with TeX.

> Once Fido's data are merged with the template, what do you want to do with
> the results? Mail them to someone? Export them to HTML? Make a new Org entry
> with the contents and file it somewhere?

Of practical benefit to me would be either: (a) make a new Org entry
and file it (as you suggest) or (b) simply put it in the kill ring, so
that I can yank it wherever I want.

Again, thanks so much for your help, and also the other replies I
received.  I'm very impressed by the org-mode community responding so
quickly to my question.

Richard

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

* Re: Merge Properties into Template
  2011-10-06 15:56   ` Richard Parsons
@ 2011-10-06 20:52     ` Christian Moe
  2011-10-07  7:04     ` Christian Moe
  1 sibling, 0 replies; 7+ messages in thread
From: Christian Moe @ 2011-10-06 20:52 UTC (permalink / raw)
  To: Richard Parsons; +Cc: emacs-orgmode

Hi,

On 10/6/11 5:56 PM, Richard Parsons wrote:
(...)
> Firstly, thank you so much for taking the time to write some code,
> which (even as a newbie) I was able to get running quickly and easily.

My pleasure. I'm finding my legs in elisp myself, and I often find a 
better solution to a problem I've been grappling with when I think 
about someone else's request. So it was in this case -- I had worked 
on an insanely complicated mail-merge setup, your post made me realize 
it could be done more simply.

> Of practical benefit to me would be either: (a) make a new Org entry
> and file it (as you suggest) or (b) simply put it in the kill ring, so
> that I can yank it wherever I want.

I enclose a new version (below) that does (b), add to the kill ring.

We could also do (a), make an entry and refile it, but if this is what 
you want to do, I'd be more interested in looking into ways to do it 
with org-capture and avoid reinventing the wheel -- even if setting up 
org-capture templates is a little more involved than what you had in mind.

> Again, thanks so much for your help, and also the other replies I
> received.  I'm very impressed by the org-mode community responding so
> quickly to my question.

Pass it forward!

Yours,
Christian



#+begin_src emacs-lisp
   (defun cm/org-merge (target)
     "Fill a template headlined TARGET with the properties of the
   entry at point, replacing e.g. `[AGE]' with the contents of
   an :AGE: property. Use `[HEADLINE]' for the text of the entry
   heading."
     (interactive "sTarget template: ")
     (let ((props (org-entry-properties))
           prop
           template)
       (setq props (cons (cons "HEADLINE" (org-get-heading)) props))
       (save-excursion
         (org-open-link-from-string (format "[[*%s]]" target) t)
         (setq template (org-get-entry)))
       (dolist (p props)
         (setq template
               (replace-regexp-in-string
                (format "\\[%s\\]" (car p))
                (cdr p)
                template t)))
       (kill-new template)
       (message template)))
#+end_src

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

* Re: Merge Properties into Template
  2011-10-06 15:56   ` Richard Parsons
  2011-10-06 20:52     ` Christian Moe
@ 2011-10-07  7:04     ` Christian Moe
  1 sibling, 0 replies; 7+ messages in thread
From: Christian Moe @ 2011-10-07  7:04 UTC (permalink / raw)
  To: Richard Parsons; +Cc: emacs-orgmode

PS. Note that with the code example I sent, your templates can also 
access the special properties listed in section 7.2 of the manual, 
such as TODO, ALLTAGS, TIMESTAMP, DEADLINE etc.

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

end of thread, other threads:[~2011-10-07  7:02 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-06  9:35 Merge Properties into Template Richard Parsons
2011-10-06 10:40 ` Merge Properties into Template; [babel] Giovanni Ridolfi
2011-10-06 11:35 ` Merge Properties into Template suvayu ali
2011-10-06 12:50 ` Christian Moe
2011-10-06 15:56   ` Richard Parsons
2011-10-06 20:52     ` Christian Moe
2011-10-07  7:04     ` Christian Moe

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