From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id 2FW3Loq/LmZUOQAA62LTzQ:P1 (envelope-from ) for ; Sun, 28 Apr 2024 23:28:42 +0200 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id 2FW3Loq/LmZUOQAA62LTzQ (envelope-from ) for ; Sun, 28 Apr 2024 23:28:42 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XXsGzURs; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Seal: i=1; s=key1; d=yhetil.org; t=1714339722; a=rsa-sha256; cv=none; b=kCl7BACkcYTVKwYDSpLBmeNn1VK3lh8ICHoGUEzcZjsJoCU76/nNwBm38lVk4N3qpvHIGx 7oHmX6WW+GiZ9+y6+Kf4PpBLefRDrAZx4dDwUaGWTa2GP3X6if5Acn6VuGPkklXZqsUpUo gMA2vuaQWPTkF8emsLNA8yQgUZfnU3QHuSawWBx3EhuuwNuqQOWEz3Drp2/M5L1gCpJFMr /eU0jMBEpSP4w6zYsfaTpow0iUWSSVpnAoL1KLWXsVKAZVS4Rprdc4AHe5Ti/o8r4RrpEU FUExLc8n+g2UcCazp6VvWZh68wNRRMhu6MA2KNfAweWhwIgft5JOelgwzcUjHg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=XXsGzURs; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1714339722; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=n+ZTgs/IQrrGFoThNUHBToxkj0YaCk49oTkXhVr0gBM=; b=fFGcHVifLDUtzbSMcH3okyp46FAXK1lmqbnqm/+GBsHVRoY4g8XTEEqp9jo1U7HfUXyCZh MynFSRG85nTK7MNFSc6ssQTy2nJodXUlvvTvByNJXlpk1tMi898dHRSj4vZLrhFucgsycl ublGSN+MN8FEh7A/47dPGVVMzqatDUi5ZSHNj+kyNRN5dxY+SWPXscKBbkMVXVxu9CSGKk BWvITG0KaW05JybroXSyiCeZCO8KtqZH+L6dnoYlKYVhiMhOXqiqJoabWA0yzkggjS6dZB gPNgVjHRkSTmuO413X4U2cj6mSeIj41USwrm7Xvb9nFpx1fynmhysI3A1lPZlw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 78273251BC for ; Sun, 28 Apr 2024 23:28:42 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s1C3q-0008Uw-6L; Sun, 28 Apr 2024 17:27:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s1C3o-0008Uo-Cl for emacs-orgmode@gnu.org; Sun, 28 Apr 2024 17:27:48 -0400 Received: from mail-ed1-x531.google.com ([2a00:1450:4864:20::531]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1s1C3k-0006N2-VV for emacs-orgmode@gnu.org; Sun, 28 Apr 2024 17:27:47 -0400 Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-56e477db7fbso6192088a12.3 for ; Sun, 28 Apr 2024 14:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714339663; x=1714944463; darn=gnu.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=n+ZTgs/IQrrGFoThNUHBToxkj0YaCk49oTkXhVr0gBM=; b=XXsGzURsXYWAsQfn2XFm8QkMASA0odfNFJG1qQpb8eDxtTyAK6hkjvSANeeKRD6Rnl 5Vx3ZwEGbI3r0XSCJAreSE7OTWRP+OvUpuKb6MNDrEiqeXDnQKpimlJVADSlTUKKESNK P8pOih60cvhNcvoMw5vJUnKHw4G9aE+6zdDavQ+7KGTNSm/nsC+Uvfq9ovoxe5n0Ahya Mb5U8lHL0rHTBVB8D1jzUYr4mL9iXLNZU3geNZmffODJTCO0Q7R5NZ5e1xxQ4OSmTvud nY+VQpfwRrWAWZmbd2zTlY311Ap7UmmHmQxOrcPYiXjofWJu7CxrjzyJ47pBXhfRWcsH B0Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714339663; x=1714944463; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=n+ZTgs/IQrrGFoThNUHBToxkj0YaCk49oTkXhVr0gBM=; b=u4JnGilyVMZIGfMnHzz8VC0HHCHkGjQ6H8CXCnSOgA7in6LtV1AxaeYpMTgyUgIJEx URtxiEx6yau9bMysTj35T7lYajrEd7aFEE5qeYz5CFSO+fuH5/aVJGZ3JefeMNfDaEQ0 nUUkrxHtXQRO0XDyayyBb4DRyPA/abKhPAnGf8ubDRAecPuvzW2k4qM/YZ+1+i1bxp/A kFiTF8GtVTbiHw4Oat7nXV8AFxrdn6t9JaWywXN7YO48Lx6WSyBzHnOWZ83VumNnSfyb 22baB8CL8g5uwnhWyxuxNEgZt6EEafQUPgakvkB1tqEeFjwcPFyh6zDNtUw8xJIpJEs7 b+Tg== X-Gm-Message-State: AOJu0YwZUdbM0G3+oIx66OzntYYyXyfqvwrB0trYYWmy5/oLAz/aVP8t 1AnQL30hhkHJ0c9dokl/h8x6w+l141/T3O6/bxT2VjV3EBfXFFK4/q+51XwDsu9873aLr+AnjEo +i311uos5PWzirfPTMPgH6C6CLdAgYXRS X-Google-Smtp-Source: AGHT+IGb2RTMjoeh7kpF1t8XZ366T+2JW5oCgBs7afFC//dlnkRWMbERW6vsw0glxGfJbKS9Pmf9qFygR5X8C8TAIkI= X-Received: by 2002:a05:6402:4344:b0:572:71b3:3c4d with SMTP id n4-20020a056402434400b0057271b33c4dmr3194078edc.34.1714339662965; Sun, 28 Apr 2024 14:27:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Nafiz Islam Date: Sun, 28 Apr 2024 17:27:32 -0400 Message-ID: Subject: Re: [FR] Support headline as a function for file+headline target for org-capture-templates To: emacs-orgmode@gnu.org Content-Type: multipart/alternative; boundary="000000000000a2b50206172ece7d" Received-SPF: pass client-ip=2a00:1450:4864:20::531; envelope-from=nafiz.islam1001@gmail.com; helo=mail-ed1-x531.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: emacs-orgmode-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: 78273251BC X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -7.92 X-Spam-Score: -7.92 X-TUID: uluOfrubtYPJ --000000000000a2b50206172ece7d Content-Type: text/plain; charset="UTF-8" > 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))) --000000000000a2b50206172ece7d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> Upon closer look at the `org-capture`, `org-capt= ure-set-target-location` and `org-capture-place-entry`, I'm starting to realize that=20 "file+function" can be used for what I'm looking for. I was j= ust worried about the use of `(org-capture-put :exact-position (point))`
My disappointing attempt at using file+function target to repli= cate my idea

(defun my/diary-capture-find-headline ()
=C2=A0 =C2=A0 (let* ((entr= ies (org-map-entries (lambda ()
=C2=A0 =C2=A0 =C2=A0 (list (org-ele= ment-property :title (org-element-at-point))
=C2=A0 =C2=A0 (org-el= ement-property :begin (org-element-at-point))))
=C2=A0 =C2=A0 "= ;LEVEL=3D1"))
=C2=A0 (final-pos)
=C2=A0 (final-pos
=C2= =A0 =C2=A0(dolist (entry entries final-pos)
=C2=A0 =C2=A0 =C2=A0(pcase= -let ((`(,title ,begin) entry))
(let* ((diff-time (time-subtract (curr= ent-time) (org-time-string-to-time title)))
=C2=A0 =C2=A0 =C2=A0 (dif= f-secs (nth 1 diff-time))
=C2=A0 =C2=A0 =C2=A0 (5-mins-in-secs (* 5 6= 0)))
=C2=A0(if (< diff-secs 5-mins-in-secs)
=C2=A0 =C2=A0 = =C2=A0(setq final-pos (goto-char begin))
=C2=A0 =C2=A0final-pos))))))=
=C2=A0 =C2=A0 =C2=A0 (unless final-pos
(goto-char (point-max))
= (unless (bolp) (insert "\n"))
(insert "\n* ")
(= let ((current-prefix-arg '(16)))
=C2=A0(call-interactively #'o= rg-time-stamp-inactive))
(beginning-of-line))))

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