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 22:52:13 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0

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



reply via email to

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