MT <[email protected]> writes:

> Thanks for the feedback! Can you try the fixed patches? The test cases work 
> on my local machine now (with the Java etc. test environment enabled).

I applied the two fixed patches onto main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=56768d33b
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=6db7124a5
Thanks!

> From a1e3a212bf643bb8fa7dbfa39d7e001166a28b5f Mon Sep 17 00:00:00 2001
> From: Mingtong Lin <[email protected]>
> Date: Thu, 27 Nov 2025 23:40:17 -0500
> Subject: [PATCH 3/6] ob-core.el: Generate numbered names for unnamed
>  Noweb-referred blocks
> ...
> +(defmacro org-babel-map-count-src-blocks (file counter-var &rest body)
> +  "A variant of `org-babel-map-src-blocks' that also tracks the number of 
> source blocks.
> +The counter records the number of the current source block under
> +current heading.
> +
> +FILE and BODY  see `org-babel-map-src-blocks'
> +COUNTER-VAR    the variable symbol for current counter value."
> +  (declare (indent 2))
> +  (let ((last-heading-pos-var (gensym "last-heading-pos-"))
> +     (current-heading-pos-var (gensym "current-heading-pos-")))

Nitpick. You can use org-with-gensyms.

> +(defun org-babel--generate-block-name (link counter)
> +  "Generate a name for source block.
> +LINK is the link to the source block, COUNTER is the number of the
> +source block, counted under the heading in the search option of LINK."
> +  (let ((loc
> +      (if (string-match "::" link)

This is not reliable.
Do remember that the stored link type can be customized.
And only id: and file: links can have search options.
Other links may have :: appearing in the path with no particular
meaning.

> +          (let ((search-option (substring link (match-end 0)
> +                                          (length link))))
> +            ;; If the source block is not in a subtree, the search
> +            ;; option will become "+begin_src <params>".
> +            (if (or (string-prefix-p "+begin_src" search-option)
> +                    (string-prefix-p "+BEGIN_SRC" search-option))

This is extremely fragile.
For example, when you call org-babel-tangle with prefix argument, with
point in the middle of a block, the point (and the link stored) may or
may not be +begin_src. Not to mention that
`org-create-file-search-functions' can completely change the defaults.

I do not object the patch idea - it is harmless wrt functionality, but I
think we can do a bit better.

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