From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Moe Subject: Re: Merge Properties into Template Date: Thu, 06 Oct 2011 22:52:13 +0200 Message-ID: <4E8E14FD.2010409@christianmoe.com> References: <4E8DA42F.6040306@christianmoe.com> Reply-To: mail@christianmoe.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:38354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RButR-0005hl-Nx for emacs-orgmode@gnu.org; Thu, 06 Oct 2011 16:50:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RButQ-0003xv-R3 for emacs-orgmode@gnu.org; Thu, 06 Oct 2011 16:50:13 -0400 Received: from mars.hitrost.net ([91.185.211.18]:17741) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RButQ-0003po-BK for emacs-orgmode@gnu.org; Thu, 06 Oct 2011 16:50:12 -0400 In-Reply-To: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Richard Parsons Cc: emacs-orgmode@gnu.org 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