From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id gEIzKGq+imDShgAAgWs5BA (envelope-from ) for ; Thu, 29 Apr 2021 16:10:50 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id ACHeI2q+imAiRgAA1q6Kng (envelope-from ) for ; Thu, 29 Apr 2021 14:10:50 +0000 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 E225928B22 for ; Thu, 29 Apr 2021 16:10:49 +0200 (CEST) Received: from localhost ([::1]:45070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lc7NQ-000372-QN for larch@yhetil.org; Thu, 29 Apr 2021 10:10:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lc7LU-00021w-V6 for emacs-orgmode@gnu.org; Thu, 29 Apr 2021 10:08:48 -0400 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]:55989) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lc7LR-0001a9-CI for emacs-orgmode@gnu.org; Thu, 29 Apr 2021 10:08:48 -0400 Received: by mail-wm1-x331.google.com with SMTP id n127so24120757wmb.5 for ; Thu, 29 Apr 2021 07:08:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=C7pJ8YVCPi9bF6NYXPUQ+OqJ9W4Fq7b34rwibwdC3pE=; b=Ckox5Y5ivabM2qCQcT2E9uWpGSKmsiKYksGeckB+n+99oKVtZXF9/g5PIeNAJ9UU70 PjzuIk5Mwzmfh6DHSiaswy2H/TYjHtI2zEfh4kN6OibcZSPldRpCyB1CaJC77y5mQLIg gvon+ZZFgkL+u89FpE1s55Zvnn+5DRmkjywDxhkjCguZ7/TG6OEPSDT486mf/vfqL1vr qWktG+s/oWmFPdd3/Tb/aNhwdztribAI3EJHgXq76+OJhDMKH6r8yTCQOrg/SqTpvhPl p4H7UazQlGvq03+CDUOCe/eWdiaZpC1yczglD41Cl0hi6n7mgesMj6JzA82Z+M/wZMdf Plfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=C7pJ8YVCPi9bF6NYXPUQ+OqJ9W4Fq7b34rwibwdC3pE=; b=Mu4Vppbd2445Sc5w4XHNNY9g2dRrUGFJM46x7cZ+mbr0f5xrho24xkj+ZNqoJAB7ro Yz3htIJRub4avCaUXhEoJ2jBj03emNZgscRL1KGYc+qaRpPshEBQiVlRuwGw3mAgSs96 7JhNHS1QgBsVwCwWY8pJ1wsNYSRhWQHvOeuSFhG0P2Ra5gT6ry3d2MlQ8vlYyOyAGbja OcIWj4/JWIOASZv0P4vkpeXT5qjsbLIJv6eBwYQy7IkRdJANZetxmArlyAZN72wI9P7R Hns2bjyKGwHbndZuhvaVmr8TPn464qgX0HaGy8W/XbIMVABs4QekHwWmkcPwh9XYXRMW VaMQ== X-Gm-Message-State: AOAM531r3k+NnhGrDQQruLDpCMxJGuIoTqSvHvFVA3PQCeO3oPhaBA5H tQT6PKyPOhjF64+9Wve6/hIezebMu9wqZubIV+MUr5ZsaMKvRw== X-Google-Smtp-Source: ABdhPJwQlAUPOUcOdNY4AedCbmWQMd5K9whMXNJ0puvX4Vby7apbbYfPvfmTYljWMdmqHDbkLEepfDBGEneQLF7WszE= X-Received: by 2002:a1c:f60a:: with SMTP id w10mr10744300wmc.5.1619705322867; Thu, 29 Apr 2021 07:08:42 -0700 (PDT) MIME-Version: 1.0 From: Tim Visher Date: Thu, 29 Apr 2021 10:08:06 -0400 Message-ID: Subject: org-attach-attach in an org-capture template? To: Emacs Org Mode mailing list Content-Type: multipart/alternative; boundary="000000000000690ec905c11d08ef" Received-SPF: pass client-ip=2a00:1450:4864:20::331; envelope-from=tim.visher@gmail.com; helo=mail-wm1-x331.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_FROM=0.001, HTML_MESSAGE=0.001, HTML_OBFUSCATE_05_10=0.26, 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.23 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" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1619705450; 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:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=C7pJ8YVCPi9bF6NYXPUQ+OqJ9W4Fq7b34rwibwdC3pE=; b=KSXlNNqb8drEjA05NaJMMtVCjSoVZ1RwMWjy3LZxcHxTaaRBUly6jFmcRuceybSS3TgxVI HgMRdVDBOV87mJTfjcIG+loGb6M9AUZr3d6x1cQwLGOXaiLh+wk2E+TKLH8Ljgc37LcQnQ erhqwjRETIfJXlnZXWMMA3RI1vw8DhIJjbX1H1qq5Nn0EIDiR+3jcrkfzjh5FaRLwW8z0n 3cAfVKm2jlpctfvRHRz6Vcz8+WFzF+9lGjkLfYFaclgt1Z8aLbxjJx3HRpV9cglWJdLzEk FVqloz+HCRMc6A7loVHQpKs95P5SGZQNMzEDKX0wzRVe3OzEvojUjJ/js2SkpQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1619705450; a=rsa-sha256; cv=none; b=BWy4639ketlvxw7ibilJ7ghKFlCVSgwRoDt1LAgVOlF8YYpV0cxO6QUd/PDab51LM7p3ty LJzVwncIZcZcWckZF6ZSUEsHWtULl85Yxd97xOzdPmHnB8x8bmVs15zFHupVvxThyvnS7s 33bEB8j4ncm/q7HgUhbe8PF2GUDOoe9anx5tmshIX84g9PdWFkh4IE75BIHmF1mcre882B 5Paz44/qD5Vt8adgz00UJ5xfqP36A/y2mDZmFdYxwJHBSGoYoLDNI4i1qkyMxvJyw0UOLc fYsEa+SdyU9mPDBdmSo/7VlEsFCtAWu4a1s+ntcYOyfzFEQt7UPfaQIFdzxRow== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=Ckox5Y5i; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Spam-Score: -2.16 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=Ckox5Y5i; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Migadu-Queue-Id: E225928B22 X-Spam-Score: -2.16 X-Migadu-Scanner: scn0.migadu.com X-TUID: YrB0ld28QNAg --000000000000690ec905c11d08ef Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Everyone, *TL;DR:* I've recently started using org-capture and I'd like to run org-attach-attach during the expansion of a few of my templates. Doing so from a template function seems not to work (meaning a function in a template string called with %(=E2=80=A6)). What's the best way to go about = this? ------------------------------ I've recently started to explore org-capture and it's pretty great. I'm interested in having one of my templates search for a file somewhere and, if it finds one, add it to the current template as an attachment. My initial test template looks something like: (defun attach-file () (org-attach-attach (expand-file-name "a file") nil 'cp)) (setq org-capture-templates '("T" "TEST" entry (file+headline "~/x.org" "Inbox") "* TODO Foo%(attach-file) %U")) The idea being that attach-file would call org-attach-attach if it could find a file and always expand to nothing. Upon testing that I see the following (org 9.4.5-g287af2, emacs 27.2 (build 1, x86_64-apple-darwin18.7.0)): ** TODO Foo%![Error: (error bug: org-id-get expects a file-visiting buffer)= ] :PROPERTIES: :ID: 05837793-5A4F-42FC-AB50-5165FA7ECC4B :END: [2021-04-29 Thu 09:52] If I then call org-attach manually on the resulting entry I can attach a file fine to it. I'm aware that I can make the template an elisp function and do the work all internally. That's probably what I'll start doing presently. But it's a little annoying that I then need to reimplement org-capture's built-in template expansion in some way (like %U for the current inactive timestamp)= . I also believe I could do this with one of the org-capture hooks but examining them I didn't see the obvious right one to add my function to. I would think it would be the org-capture-prepare-finalize-hook and I may just give that a try. I further assume then that I'd need to to apply the advice here and check for what template I'm in with (plist-get org-capture-plist :key) or similar. So my question is whether there's anything I can do to get org-attach-attac= h to recognize the file it's in. I'm assuming that when it's expanding it's in a temporary buffer of some kind which is why it's failing. All thoughts and advice are most welcome. Thanks in advance! :) -- In Christ, Timmy V. https://blog.twonegatives.com http://five.sentenc.es --000000000000690ec905c11d08ef Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Everyone,

TL;DR:=C2=A0I've r= ecently started using=C2=A0org-capture=C2=A0and I'd like t= o run=C2=A0org-attach-attach=C2=A0during the expansion of a fe= w of my templates. Doing so from a template function seems not to work (mea= ning a function in a template string called with=C2=A0%(=E2=80=A6)). What's the best way to go about this?


I've recently started to explore=C2=A0org-capture=C2=A0and it's pretty great. I'm interested in h= aving one of my templates search for a file somewhere and, if it finds one,= add it to the current template as an attachment.

My initial test template looks some= thing like:

(defun =
attach-file
    ()
  (org-attach-attach (expand-file-name "a file")
                     nil
                     'cp))

(setq org-capture-templates
      '("T" "TEST" entry
        (file+headline "~/x.org" "Inbox")
        "* TODO Foo%(attach-file)

  %U"))

T= he idea being that=C2=A0attach-file=C2=A0would call=C2=A0org-attach-attach=C2=A0if it could find a file and always expand to= nothing.

= Upon testing that I see the following (org 9.4.5-g287af2,=C2= =A0emacs 27.2 (build 1, x86_64-apple-darwin18.7.0)):

=
** TODO Fo=
o%![Error: (error bug: org-id-get expects a file-visiting buffer)]
   :PROPERTIES:
   :ID:       05837793-5A4F-42=
FC-AB50-5165FA7ECC4B
   :END:

   [20=
21-04-29 Thu 09:52]

I= f I then call=C2=A0org-attach=C2=A0manually on the resulting e= ntry I can attach a file fine to it.

I'm aware that I can make the template an el= isp function and do the work all internally. That's probably what I'= ;ll start doing presently. But it's a little annoying that I then need = to reimplement=C2=A0org-capture's built-in template expans= ion in some way (like=C2=A0%U=C2=A0for the current inactive ti= mestamp).

= I also believe I could do this with one of the=C2=A0org-capture=C2=A0hooks but examining them I didn't see the obvious right one to a= dd my function to. I would think it would be the=C2=A0org-capture-pre= pare-finalize-hook=C2=A0and I may just give that a try. I further as= sume then that I'd need to to apply the advice=C2=A0here=C2=A0and check for what template I'm in with= =C2=A0(plist-get org-capture-plist :key)=C2=A0or similar.

<= p style=3D"font-size:small;font-weight:400;text-align:start">So my question= is whether there's anything I can do to get=C2=A0org-attach-atta= ch=C2=A0to recognize the file it's in. I'm assuming that whe= n it's expanding it's in a temporary buffer of some kind which is w= hy it's failing.

All thoughts and advice are most welcome. Thanks in advance! :)<= /p>

--

= In Christ,

Timmy V.

https://blog.twonegatives.com
ht= tp://five.sentenc.es

--000000000000690ec905c11d08ef--