From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id GNpXFbGUYWLkRQEAbAwnHQ (envelope-from ) for ; Thu, 21 Apr 2022 19:30:25 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id +G5HFbGUYWK+xAAAauVa8A (envelope-from ) for ; Thu, 21 Apr 2022 19:30:25 +0200 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 CDA81353E4 for ; Thu, 21 Apr 2022 19:30:23 +0200 (CEST) Received: from localhost ([::1]:40310 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nhadK-0004XZ-VO for larch@yhetil.org; Thu, 21 Apr 2022 13:30:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nhacb-0004Tk-NH for emacs-orgmode@gnu.org; Thu, 21 Apr 2022 13:29:37 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:42764) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nhacZ-0002UG-Et for emacs-orgmode@gnu.org; Thu, 21 Apr 2022 13:29:37 -0400 Received: by mail-oi1-x231.google.com with SMTP id a10so6327921oif.9 for ; Thu, 21 Apr 2022 10:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vicarious-living-com.20210112.gappssmtp.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=LXau1jl02KLR9R/tmz47ahckyn8nApdEuR9r6IBWgho=; b=kQVpqiq/ydlOL7RrIjI63b9Mz3Gs1O2DIa2sUOBbkf737joT1Y/am3ccB/J/65LSZc KlccedYnQeiXLwptk5AM5YXQfdErCAxypvyedTdNNgqrK2G5GvqhvXar/xQbWX4vkbHo 0ApMlq82po5UXV4+ANAV7nGCcxal1KRmNAuFR6Hhsokkjttp9qT9pnMUm5JoTEYqFZdy TgoCI1QLO4wZ6ov3zZ6a8ezHkaM5rIee8WMVCVG3cdb9MsSV13SXXY9mumLFwVRVdddE WXl4PfNidvNkNNZonfbW/mBeXShtuFFDNC8tmrkF8AdZrTMNDxks0GtBL8W6YowjAjfN kjpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=LXau1jl02KLR9R/tmz47ahckyn8nApdEuR9r6IBWgho=; b=B4itigeVo0g63rRLImWAPT33h4+ipp+Pbsu3b+oHbh66udhoTs90SQwL1Q+qlynWEs XRilG129EiYkVkV7San5GDg5QmB8LkBaK1KStV0H0Ly6pYb79rXJvqrhhkqGDuPStbh9 4vP1YbS3MU25EVnjlFIzxyaxPrnZHGS+xSc8qDsiKp8QTKXmwITzLyLnYMHZdkxDVQmI f/9s0tc6kLv1ALMTghXYujKuYjsUf+L/Bbmk4hb9VT8/T7uLkAGrsPDOFqa/Vn2xrV3U gaU+n7R9jm7KZ/2hSvPJzwKuRhzRZc3rw6mUL8IJyhOqkjKeBF/4RbKxm8t6ase5JpYc ORww== X-Gm-Message-State: AOAM532JfeUdX2lAPnWM+n3xtEKgT4M15wAWmsE3UIjAjgu1kPukoXUk JusXnapAStI9LbZYOheDItAytFWbbqOXZ/jcsr9YXQ== X-Google-Smtp-Source: ABdhPJyRyHPwP4kcdVngRKY0erE2PUYQXuh4+qEUIbh4CezcigqIMt6XupcrYBtHn/X/gqT1op1JRzG2CHli3NDIEqM= X-Received: by 2002:a05:6808:1491:b0:2f9:f091:77c2 with SMTP id e17-20020a056808149100b002f9f09177c2mr412707oiw.18.1650562173526; Thu, 21 Apr 2022 10:29:33 -0700 (PDT) MIME-Version: 1.0 References: <981938.1630590273@apollo2.minshall.org> <87czpqjqvw.fsf@localhost> <87zgkey55y.fsf@localhost> In-Reply-To: <87zgkey55y.fsf@localhost> From: Ryan Scott Date: Thu, 21 Apr 2022 10:29:01 -0700 Message-ID: Subject: Re: [PATCH] Re: New source block results option for attaching file to node To: Ihor Radchenko Content-Type: multipart/alternative; boundary="0000000000000876e505dd2d742a" Received-SPF: none client-ip=2607:f8b0:4864:20::231; envelope-from=ryan@vicarious-living.com; helo=mail-oi1-x231.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 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: , Cc: Greg Minshall , emacs-orgmode@gnu.org, Timothy Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1650562224; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=LXau1jl02KLR9R/tmz47ahckyn8nApdEuR9r6IBWgho=; b=ICOA3Kv/u3wRllYlhUnLZXyBH6wfx3wbgXh3Tcn5YC5ikbaplQPFweiQ+xyrSgAtUH1ngK s226LSXTn32IlcGyTdIgQpW6sDz3cL+KbXvirti6+KeT8UA8h+MtdhjhpRQA1LypRju1bR Oe16dZl5HHsK5auAaKw2mLmWzpC8L0/tWL0mr8UnJG1KsS+BXUQ5eX0Ugx+Q7AAyhELDlH kBzrjlW0FM/vH3DXl8xj5laetPTnapB3SZ0reIAcEKtjHnPGXAK3bm0rfQv9eCwWQH7nZm 9SFR8CPsGEX1mFgS8NC86fPU/VwZ4qF0Gpw+RsyM28wnILuCRmStb/PQd0P4Tg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1650562224; a=rsa-sha256; cv=none; b=k1QFWnZ5IDALpqFiT3kwWNmLnhFlyXM7hoqDzU1Nhe8x9lcuHoz2pMVpR/Is3HzLR3vE8g ddwCJQgA93UAdfVh97Dubfu/6i1GY01BrKrzrMmROjBc+y4x3aQGjBjSWIbZ93+rL3usDr gqArTD2XEmhJY/RomNT1EJ7rfdM9X7yE75jq53wnxULte9R7gh9qnAbf/XVXmX4Kx6ADHF XLE8z7iZkIRMPLf65NZ2lIMEMZ5yDFb1x67XaO6im045kaO5wNB7L+GPYS4jgPS1/ubM84 oz1DBJMiP5gsG+y9uJC08JZph5EGjFM9qOjvD6dNNynBpGnxsRB6AjasAwtnXg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=vicarious-living-com.20210112.gappssmtp.com header.s=20210112 header.b="kQVpqiq/"; dmarc=none; 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" X-Migadu-Spam-Score: 1.17 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=vicarious-living-com.20210112.gappssmtp.com header.s=20210112 header.b="kQVpqiq/"; dmarc=none; 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" X-Migadu-Queue-Id: CDA81353E4 X-Spam-Score: 1.17 X-Migadu-Scanner: scn1.migadu.com X-TUID: c4xesvdz1G/X --0000000000000876e505dd2d742a Content-Type: text/plain; charset="UTF-8" Yeah I just recently updated my fourth and realized there were some necessary conflicts to resolve with the latest. I'll take a look at addressing these issues and submit an updated patch. Surprised I missed a calling location and secretly hope that it was added recently for the sake of my poor ego. :) With all of the layers and assumptions/behaviors inherent in the way src block parameters are handled, do you feel like this is an approach that can work, or should it be abandoned? Thanks for looking into this. On Thu, Apr 21, 2022, 05:46 Ihor Radchenko wrote: > Ryan Scott writes: > > > Here's my latest patch. > > Uses special :dir value 'attach to use attachment directory as working > dir. > > Now prompts to create IDs for nodes that are missing. > > Solved a handful of issues with my previous versions of this and I've > been > > using it regularly for a bit now. > > > > I've added documentation and completed the copyright assignment to the > FSF. > > I have consulted Bastien about our merge policy and apparently it is ok > to merge staff into files without maintainer. ob-core.el is one of such > files. > > So, I did a more elaborate testing of your patch. I have some comments. > > Firstly, the patch does not apply onto current main. > > > +Setting =dir= to the symbol ~attach~ or the string ~"'attach"~ will > > ... > > +Passing the symbol ~attach~ or string ='attach= to the =:dir= option > > When I was trying to use your patch, I felt slightly confused about the > "'attach" part. It _looks_ like a type and I first tried to do :dir > "attach" yielding predictable lack of attachment: file link. > > Maybe you can say "or the string ~"'attach"~ (with quote)". > > > + (org-babel-result-to-file > > + result > > + (org-babel--file-desc (nth 2 info) result) > > + 'attachment)))) > > There are only 2 calls to org-babel-result-to-file in the whole Org > codebase. And you did not change the second call, which yield strange > side-effects: > > #+NAME: attr_wrap > #+BEGIN_SRC sh :var data="" :var width="\\textwidth" :results output > echo "#+ATTR_LATEX: :width $width" > echo "$data" > #+END_SRC > > #+begin_src gnuplot :dir 'attach :file test.png > plot x > #+end_src > > #+RESULTS: > [[attachment:test.png]] > > #+begin_src gnuplot :dir 'attach :file test.png :post > attr_wrap(width="5cm", data=*this*) :results drawer > plot x > #+end_src > > #+RESULTS: > :results: > #+ATTR_LATEX: :width 5cm > [[file:data/4d/6a76f8-4016-4edf-9d26-e0b3a634dbc1/test20.png]] <----!!!!! > this is not expected > :end: > > > +If the optional TYPE is passed as 'attachment` and the path is a > > +descendant of the DEFAULT-DIRECTORY, the generated link will be > > +specified as an an \"attachment:\" style link" > > + (in-attach-dir (when (and request-attachment (> (length > result-file-name) attach-dir-len)) > > + (string= > > + (substring result-file-name 0 > attach-dir-len) > > + attach-dir)))) > > This is a risky heuristics. > One can do something like > (setq org-attach-id-dir > "/tmp/alsjkdsalkjdlaskdjklasjdlkasjdlkasjdlkajdklasjdlasjlasdjk/") > and often get your heuristics fail. > Of course, it will require some terribly noncomplying ob-* library that > will create file disregarding default-directory, but still... > > > + (if (y-or-n-p (format "Create ID for entry \"%s\"?" > > + (org-get-heading t t t t))) > > This is a nice dialogue, but note that Emacs can run noninteractively or > execute source block during export (including asynchronous). I would > guard the query after consulting `noninteractive' variable. > > > Best, > Ihor > --0000000000000876e505dd2d742a Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Yeah I just recently updated my fourth and realized there= were some necessary conflicts to resolve with the latest.=C2=A0

I'll take a look at addressing these= issues and submit an updated patch. Surprised I missed a calling location = and secretly hope that it was added recently for the sake of my poor ego. := )

With all of the layers= and assumptions/behaviors inherent in the way src block parameters are han= dled, do you feel like this is an approach that can work, or should it be a= bandoned?

Thanks for loo= king into this.=C2=A0

On Thu, Apr 21, 2022, 05:46 Ihor Radchenko <<= a href=3D"mailto:yantar92@gmail.com">yantar92@gmail.com> wrote:
<= /div>
Ryan Scott <ryan@vicarious-li= ving.com> writes:

> Here's my latest patch.
> Uses special :dir value 'attach to use attachment directory as wor= king dir.
> Now prompts to create IDs for nodes that are missing.
> Solved a handful of issues with my previous versions of this and I'= ;ve been
> using it regularly for a bit now.
>
> I've added documentation and completed the copyright assignment to= the FSF.

I have consulted Bastien about our merge policy and apparently it is ok
to merge staff into files without maintainer. ob-core.el is one of such
files.

So, I did a more elaborate testing of your patch. I have some comments.

Firstly, the patch does not apply onto current main.

> +Setting =3Ddir=3D to the symbol ~attach~ or the string ~"'at= tach"~ will
> ...
> +Passing the symbol ~attach~ or string =3D'attach=3D to the =3D:di= r=3D option

When I was trying to use your patch, I felt slightly confused about the
"'attach" part. It _looks_ like a type and I first tried to d= o :dir
"attach" yielding predictable lack of attachment: file link.

Maybe you can say "or the string ~"'attach"~ (with quote= )".

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-ba= bel-result-to-file
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0result
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-babel--fi= le-desc (nth 2 info) result)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 'a= ttachment))))

There are only 2 calls to org-babel-result-to-file in the whole Org
codebase. And you did not change the second call, which yield strange
side-effects:

#+NAME: attr_wrap
#+BEGIN_SRC sh :var data=3D"" :var width=3D"\\textwidth"= ; :results output
=C2=A0 echo "#+ATTR_LATEX: :width $width"
=C2=A0 echo "$data"
#+END_SRC

#+begin_src gnuplot :dir 'attach :file test.png
plot x
#+end_src

#+RESULTS:
[[attachment:test.png]]

#+begin_src gnuplot :dir 'attach :file test.png=C2=A0 :post attr_wrap(w= idth=3D"5cm", data=3D*this*) :results drawer
plot x
#+end_src

#+RESULTS:
:results:
#+ATTR_LATEX: :width 5cm
[[file:data/4d/6a76f8-4016-4edf-9d26-e0b3a634dbc1/test20.png]] <----!!!!= ! this is not expected
:end:

> +If the optional TYPE is passed as 'attachment` and the path is a<= br> > +descendant of the DEFAULT-DIRECTORY, the generated link will be
> +specified as an an \"attachment:\" style link"
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(in-attach-dir (when (and re= quest-attachment (> (length result-file-name) attach-dir-len))
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 (string=3D
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(substring result-file-name 0 attach-dir= -len)
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0attach-dir))))

This is a risky heuristics.
One can do something like
(setq org-attach-id-dir "/tmp/alsjkdsalkjdlaskdjklasjdlkasjdlkasjdlkaj= dklasjdlasjlasdjk/")
and often get your heuristics fail.
Of course, it will require some terribly noncomplying ob-* library that
will create file disregarding default-directory, but still...

> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(if (y-or-n-p (format= "Create ID for entry \"%s\"?"
> +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0(org-get-heading t = t t t)))

This is a nice dialogue, but note that Emacs can run noninteractively or execute source block during export (including asynchronous). I would
guard the query after consulting `noninteractive' variable.


Best,
Ihor
--0000000000000876e505dd2d742a--