emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nafiz Islam <nafiz.islam1001@gmail.com>
To: emacs-orgmode@gnu.org
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	[thread overview]
Message-ID: <CAKjtFcRP1RuBY9ijm4m7Ed1CFN6gTDW7mCiWESqyp6S+72YyzA@mail.gmail.com> (raw)
In-Reply-To: <CAKjtFcTureQ-OxAZsW5xAR=MaLYM4zNiy-cxf4miBXaQnjA_dw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1580 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 2286 bytes --]

  reply	other threads:[~2024-04-28 21:28 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-28 14:58 [FR] Support headline as a function for file+headline target for org-capture-templates Nafiz Islam
2024-04-28 15:48 ` Nafiz Islam
2024-04-28 21:27   ` Nafiz Islam [this message]
2024-04-30 12:32     ` Ihor Radchenko
2024-04-30 19:45       ` Nafiz Islam
2024-05-01 11:11         ` Ihor Radchenko
2024-05-01 12:02           ` Nafiz Islam
2024-05-01 13:50             ` Ihor Radchenko
2024-05-01 23:03               ` Nafiz Islam
2024-05-02 12:34                 ` Ihor Radchenko
     [not found]                   ` <CAKjtFcT0B_CiZ=Gm4WL1Qj-TkzQ1qg+ebcVqdu-4_kzu_OEFcA@mail.gmail.com>
2024-05-02 20:57                     ` Nafiz Islam
2024-05-03 11:08                       ` Ihor Radchenko
2024-05-04  0:10                         ` Nafiz Islam
2024-05-04 12:08                           ` Ihor Radchenko
2024-05-11 16:02                             ` Nafiz Islam
2024-05-11 17:41                               ` Ihor Radchenko
2024-04-30 12:33   ` Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAKjtFcRP1RuBY9ijm4m7Ed1CFN6gTDW7mCiWESqyp6S+72YyzA@mail.gmail.com \
    --to=nafiz.islam1001@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).