emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* refiling as child with function-filing-location
@ 2014-10-22  7:43 Per Unneberg
  2014-10-26 17:38 ` Eric Abrahamsen
  0 siblings, 1 reply; 3+ messages in thread
From: Per Unneberg @ 2014-10-22  7:43 UTC (permalink / raw)
  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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: refiling as child with function-filing-location
  2014-10-22  7:43 refiling as child with function-filing-location Per Unneberg
@ 2014-10-26 17:38 ` Eric Abrahamsen
  2014-10-27 20:51   ` Per Unneberg
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Abrahamsen @ 2014-10-26 17:38 UTC (permalink / raw)
  To: emacs-orgmode

Per Unneberg <punneberg@gmail.com> writes:

> 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.

I'm messing about with some similar template-placement routines, so I
tried your recipe below, and it worked for me... Capture by default will
create a child of the heading point is on, so I really don't see why
this wouldn't work. You've stepped through the function and confirmed
that the (goto-char (point-at-bol)) line leaves you at the "Log"
heading?

Is the tree structure folded or open at the time? You might try an
(org-reveal) after the (org-clock-goto); I'm still not really clear on
the interaction between visibility and heading insertion.

I think you're note about "if cursor is at beginning of headline, same
level used" doesn't really apply here, as the capture process does a lot
more than just pasting a subtree.

Anyway, I can't reproduce the problem -- do try messing with
visibility...

Eric

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: refiling as child with function-filing-location
  2014-10-26 17:38 ` Eric Abrahamsen
@ 2014-10-27 20:51   ` Per Unneberg
  0 siblings, 0 replies; 3+ messages in thread
From: Per Unneberg @ 2014-10-27 20:51 UTC (permalink / raw)
  To: Eric Abrahamsen; +Cc: emacs-orgmode

Hi Eric,

Eric Abrahamsen <eric@ericabrahamsen.net> writes:

> I'm messing about with some similar template-placement routines, so I
> tried your recipe below, and it worked for me... Capture by default

Odd, as I still can't get it to work. I tried it out with emacs -Q, just
defining that org-capture template and running it on a simple example.

> will create a child of the heading point is on, so I really don't see
> why this wouldn't work. You've stepped through the function and
> confirmed that the (goto-char (point-at-bol)) line leaves you at the
> "Log" heading?

Yes, it leaves point at the very beginnig of that heading. The template
itself is always inserted at point, so it ends up as a sibling just
before the Log heading. Actually, the only way I can get it to work is
if Log has a child, and I add a (org-goto-first-child) after locating
the Log heading.

>
> Is the tree structure folded or open at the time? You might try an
> (org-reveal) after the (org-clock-goto); I'm still not really clear on
> the interaction between visibility and heading insertion.

Me neither, but unfortunately changing visibility doesn't help. 

>
> Anyway, I can't reproduce the problem -- do try messing with
> visibility...

Ok, thanks anyway for your input, I'll figure it out some other way.

Cheers,

Per

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-10-27 20:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-22  7:43 refiling as child with function-filing-location Per Unneberg
2014-10-26 17:38 ` Eric Abrahamsen
2014-10-27 20:51   ` Per Unneberg

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).