emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [FR] Support headline as a function for file+headline target for org


From: Nafiz Islam
Subject: Re: [FR] Support headline as a function for file+headline target for org-capture-templates
Date: Sun, 28 Apr 2024 17:27:32 -0400

> Upon closer look at the `org-capture`, `org-capture-set-target-location` and `org-capture-place-entry`, I'm starting to realize that "file+function" can be used for what I'm looking for. I was just worried about the use of `(org-capture-put :exact-position (point))`

My disappointing attempt at using file+function target to replicate my idea

(defun my/diary-capture-find-headline ()
    (let* ((entries (org-map-entries (lambda ()
      (list (org-element-property :title (org-element-at-point))
    (org-element-property :begin (org-element-at-point))))
    "LEVEL=1"))
  (final-pos)
  (final-pos
   (dolist (entry entries final-pos)
     (pcase-let ((`(,title ,begin) entry))
(let* ((diff-time (time-subtract (current-time) (org-time-string-to-time title)))
      (diff-secs (nth 1 diff-time))
      (5-mins-in-secs (* 5 60)))
 (if (< diff-secs 5-mins-in-secs)
     (setq final-pos (goto-char begin))
   final-pos))))))
      (unless final-pos
(goto-char (point-max))
(unless (bolp) (insert "\n"))
(insert "\n* ")
(let ((current-prefix-arg '(16)))
 (call-interactively #'org-time-stamp-inactive))
(beginning-of-line))))

(setopt org-capture-templates
      '(("d" "Diary Template" entry
         (file (lambda () (expand-file-name
   (concat org-directory "Diary" "/" (format-time-string "%Y-%m-%d.org")))))
         "* %U\n%?"
:empty-lines 1)
("p" "Diary Item Capture Test" item
         (file+function (lambda () (expand-file-name
   (concat org-directory "Diary" "/" (format-time-string "%Y-%m-%d.org"))))
       my/diary-capture-find-headline)
"- %?"
:empty-lines 0)))

reply via email to

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