Re: [O] Merge Properties into Template

2011-10-07 Thread Christian Moe
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.




[O] Merge Properties into Template

2011-10-06 Thread Richard Parsons
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



Re: [O] Merge Properties into Template; [babel]

2011-10-06 Thread Giovanni Ridolfi
Richard Parsons richard.lee.pars...@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





Re: [O] Merge Properties into Template

2011-10-06 Thread suvayu ali
On Thu, Oct 6, 2011 at 11:35 AM, Richard Parsons
richard.lee.pars...@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.



Re: [O] Merge Properties into Template

2011-10-06 Thread Christian Moe

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







Re: [O] Merge Properties into Template

2011-10-06 Thread Richard Parsons
Hi Christian

On Thu, Oct 6, 2011 at 1:50 PM, Christian Moe m...@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



Re: [O] Merge Properties into Template

2011-10-06 Thread Christian Moe

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