From mboxrd@z Thu Jan 1 00:00:00 1970 From: Per Unneberg Subject: refiling as child with function-filing-location Date: Wed, 22 Oct 2014 09:43:56 +0200 Message-ID: <87mw8oblc3.fsf@scilifelab.se> Reply-To: Per Unneberg Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41050) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgqag-00029a-Rh for emacs-orgmode@gnu.org; Wed, 22 Oct 2014 03:44:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgqaX-00055n-Q1 for emacs-orgmode@gnu.org; Wed, 22 Oct 2014 03:44:18 -0400 Received: from mail-lb0-x22e.google.com ([2a00:1450:4010:c04::22e]:34094) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgqaX-00055f-HL for emacs-orgmode@gnu.org; Wed, 22 Oct 2014 03:44:09 -0400 Received: by mail-lb0-f174.google.com with SMTP id p9so2359720lbv.33 for ; Wed, 22 Oct 2014 00:44:07 -0700 (PDT) Received: from ubuntu-VirtualBox (c213-89-139-61.bredband.comhem.se. [213.89.139.61]) by mx.google.com with ESMTPSA id v7sm5447527lbp.44.2014.10.22.00.44.06 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 22 Oct 2014 00:44:06 -0700 (PDT) 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: Emacs-orgmode Hi, I'm writing a custom function for use with a capture template, as described in the section Template elements (sec 9.1.3.1) of the info manual. My function does what I expect in that it finds the correct heading (in my use case "Log") and returns point. However, if the Log heading has no children, the capture template is filed as a sibling, and not a child. I have spent some time now on this seemingly simple problem, but being a newbie on elisp I must admit I'm stuck. Here's an example outline: * Projects ** Prj 1 *** Log *** Tasks **** Clocked entry So, the capture template should end up as a child to Log. From what I could tell by reading the documentation, the capture template is placed at a given level by the org-paste-subtree function, which in term is derived from the *visible* headings. If the Log entry already has a child, capture indeed places the template at the desired level, but how do I acquire this behaviour if there are no children? My function currently looks up the clocked entry, ascends to level 2 and looks for Log among the children: (defun peru/org-capture-project-log nil (org-clock-goto) (while (> (funcall outline-level) 2) (org-up-heading-safe)) (org-goto-first-child) (while (not (string= (nth 4 (org-heading-components)) "Log")) (org-goto-sibling) ) (if (not (string= (nth 4 (org-heading-components)) "Log")) (error "No Log entry under current project; please add")) ;; From org-paste-subtree: ;; if cursor is at beginning of headline, same level used (goto-char (point-at-bol)) ;; Alternatively put at eol; level derived from visible headings ;; (goto-char (point-at-eol)) ) I have thought of an alternative tag-based way of grouping my log entries, but I would still like to understand what I'm missing here. Cheers, Per