Hi Ihor,

I’m resending this email because I realized I forgot to include
emacs-orgmode. Apologies.

> Instead, we can handle `org-babel-tangle-use-relative-file-links' in
> `org-babel-tangle-single-block' itself, post-processing the link there.
> Then, we can, say, store the processed link in PARAMS as
> :ob-tangle--link when calling `org-babel-expand-noweb-references' and
> make `org-babel-tangle-comment-links' check for :ob-tangle--link
> parameter instead of calling `org-babel-tangle--unbracketed-link' to
> generate the link.

Yes, this definitely makes sense, but we need to get rid of the
`only-this-block` parameter here, since the result of
`org-babel-tangle-single-block` needs to be a nested list. This must
be a breaking change that we discussed before.

I'll address the other issues you mentioned in the last email.

Regards
Zhe Lei
On Thu, May 22, 2025 at 10:19 AM Lei Zhe <lzhe...@gmail.com> wrote:
>
> Hi Ihor,
>
> I was busy recently. Sorry for the late response.
>
> > Instead, we can handle `org-babel-tangle-use-relative-file-links' in
> > `org-babel-tangle-single-block' itself, post-processing the link there.
> > Then, we can, say, store the processed link in PARAMS as
> > :ob-tangle--link when calling `org-babel-expand-noweb-references' and
> > make `org-babel-tangle-comment-links' check for :ob-tangle--link
> > parameter instead of calling `org-babel-tangle--unbracketed-link' to
> > generate the link.
>
> Yes, this definitely makes sense, but we need to get rid of the
> `only-this-block` parameter here, since the result of
> `org-babel-tangle-single-block` needs to be a nested list. This must
> be a breaking change that we discussed before.
>
> I'll address the other issues you mentioned in the last email.
>
> Regards
> Zhe Lei
>
> On Sun, Apr 13, 2025 at 4:39 PM Ihor Radchenko <yanta...@posteo.net> wrote:
> >
> > Lei Zhe <lzhe...@gmail.com> writes:
> >
> > >> I'd rather avoid such non-deterministic return value.
> > >> Having different return values depending on the :tangle parameter is,
> > >> IMHO, not the best design. I'd rather go with my idea of adding a new
> > >> optional argument that will turn on the new return value convention and
> > >> fall back to legacy by default.
> >
> > > I agree with what you suggested. However, I’m currently struggling to
> > > implement it in a way that cleanly addresses a couple of issues:
> > > 1. When `only-this-block' is nil and :tangle has multiple targets, the
> > > link in the return result becomes ambiguous.
> >
> > It is ambiguous even when only-this-block is non-nil -
> > `org-babel-tangle--unbracketed-link' uses :tangle value directly,
> > assuming that it is a path to tangled file.
> >
> > > 2. As I mentioned, I'm unsure how to handle the output of
> > > org-babel-tangle--unbracketed-link for its use in
> > > org-babel-tangle-comment-links.
> > > I'm open to suggestions.
> >
> > `org-babel-tangle-comment-links' is used in
> > `org-babel-expand-noweb-references', which, in turn, is called by
> > `org-babel-tangle-single-block'.
> >
> > That's complicated...
> >
> > I think that the root problem here is
> > `org-babel-tangle--unbracketed-link' trying to account for
> > `org-babel-tangle-use-relative-file-links'. If not this,
> > `org-babel-tangle--unbracketed-link' would not care about :tangle
> > parameter.
> >
> > The easiest solution is thus getting rid of the
> > `org-babel-tangle-use-relative-file-links' branch in
> > `org-babel-tangle--unbracketed-link'.
> >
> > Instead, we can handle `org-babel-tangle-use-relative-file-links' in
> > `org-babel-tangle-single-block' itself, post-processing the link there.
> > Then, we can, say, store the processed link in PARAMS as
> > :ob-tangle--link when calling `org-babel-expand-noweb-references' and
> > make `org-babel-tangle-comment-links' check for :ob-tangle--link
> > parameter instead of calling `org-babel-tangle--unbracketed-link' to
> > generate the link.
> >
> > Does it make sense?
> >
> > > +(defun org-babel-tangle--concat-targets (buffer-fn info)
> > > +  "Compute the list of target file paths for tangling a source block.
> > > +The BUFFER-FN is the absolute file name of the buffer, INFO the source
> > > + block information, as returned by `org-babel-get-src-block-info'."
> > > +  (let* ((params (nth 2 info))
> > > +         (src-lang (nth 0 info))
> > > +         (src-tdirectories (cdr (assq :tangle-directory params)))
> > > +      (src-tfiles (cdr (assq :tangle params))))
> > > +    (unless (or (not src-tdirectories)
> > > +                (consp src-tdirectories))
> > > +      (setq src-tdirectories (list src-tdirectories)))
> >
> > You can just use `ensure-list' here.
> >
> > > +    (unless (consp src-tfiles)
> > > +      (setq src-tfiles
> > > +            (list (cond ((string= src-tfiles "yes")
> > > +                         (file-name-nondirectory
> > > +                          (org-babel-effective-tangled-filename 
> > > buffer-fn src-lang src-tfiles)))
> > > +                        ((string= src-tfiles "no") nil)
> > > +                        (t src-tfiles)))))
> > > +    (when (and src-tdirectories
> > > +               (not (equal src-tfiles '(nil))))
> >
> > '(nil) looks fishy. Are you sure that it is right?
> >
> > > +      (setq src-tfiles
> > > +            (apply 'append
> > > +                   (mapcar (lambda (src-tdirectory)
> > > +                             (mapcar (lambda (src-tfile)
> > > +                                       (expand-file-name src-tfile 
> > > src-tdirectory))
> > > +                                     src-tfiles))
> > > +                           src-tdirectories))))
> >
> > This may be problematic if src-tfiles contains absolute paths.
> > You will get duplicates.
> > Also, src-tdirectory might contain duplicates.
> >
> > --
> > Ihor Radchenko // yantar92,
> > Org mode maintainer,
> > Learn more about Org mode at <https://orgmode.org/>.
> > Support Org development at <https://liberapay.com/org-mode>,
> > or support my work at <https://liberapay.com/yantar92>

Reply via email to