emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christian Moe <mail@christianmoe.com>
To: Richard Parsons <richard.lee.parsons@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: Merge Properties into Template
Date: Thu, 06 Oct 2011 14:50:55 +0200	[thread overview]
Message-ID: <4E8DA42F.6040306@christianmoe.com> (raw)
In-Reply-To: <CAB+=1LF4uFw4BFfZXa4S6-dma4DOCi5H-7j571ZcLPOVBt_thg@mail.gmail.com>

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

  parent reply	other threads:[~2011-10-06 12:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2011-10-06 15:56   ` Richard Parsons
2011-10-06 20:52     ` Christian Moe
2011-10-07  7:04     ` Christian Moe

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  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=4E8DA42F.6040306@christianmoe.com \
    --to=mail@christianmoe.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=richard.lee.parsons@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* 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

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