emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Merge Properties into Template


From: Christian Moe
Subject: Re: [O] Merge Properties into Template
Date: Thu, 06 Oct 2011 14:50:55 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0

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






reply via email to

[Prev in Thread] Current Thread [Next in Thread]