In the attached file "test.org", I want to capture new headings above
"Projects" always. To achieve this, I used a file+function target to
move the point above "Projects" like below
(let* ((heading "test")
(file "tttt.pdf")
(org-capture-templates
`(("n" "blah"
entry
(file+function "/tmp/test.org"
,(lambda ()
(goto-char (point-min))
(re-search-forward "^\\* Projects")
(goto-char (match-beginning 0))
(insert "\n")
(forward-char -1)))
,(concat "* " heading "\n"
":PROPERTIES:\n"
":NOTER_DOCUMENT: " file "\n"
":END:\n\n")
:immediate-finish t
:empty-lines-before 1))))
(org-capture nil "n"))
However, when evaluating this sexp, the heading "test" is always
appended to the end of file contrary to what the docstring says:
(file+function "path/to/file" function-finding-location)
A function to find the right location in the file
This is because of the 'else' clause in the cond form in
org-capture-place-entry:
(when exact-position (goto-char exact-position))
(cond
;; Force insertion at point.
(insert-here?
....)
;; Insert as a child of the current entry.
((org-capture-get :target-entry-p)
...)
;; Insert as a top-level entry at the beginning of the file.
(reversed?
...)
;; Otherwise, insert as a top-level entry at the end of the file.
(t (goto-char (point-max))
^^^^^^^^^^^^^^^^^^^^^^^
;; Make sure that last point is not folded.
(org-fold-core-cycle-over-indirect-buffers
(org-fold-region (max 1 (1- (point-max))) (point-max) nil))))
Should this be here? Am I misunderstanding the documentation? After
all, it is too terse (the same text is in the Info manual too). The
documentation for the 'entry' type does not mention this quirk either:
entry an Org node, with a headline. Will be filed
as the child of the target entry or as a
top-level entry. Its default template is:
"* %?\n%a"
The documentation for :prepend does mention that entries will be
inserted at the end if it is nil but I would think that using a function
would rule this out.
Changing the type to 'plain' from 'entry' works as expected though.
* Heading 1
blah blah blah
* Heading 2
AAAAAAAA
* Projects
** Some subheading
something else here
* Glossary
** Some more subheading
something here