Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-12-05 Thread Ihor Radchenko
Andrea  writes:

> Sorry Ihor for the long delay.
> I got the error again for the second source block in the attached file.
> That is a sample of my configuration.

Oddly, I am unable to reproduce the problem using your file.
I tried built-in Org version for Emacs 30, Org main branch, and Org
bugfix branch.

I did:

1. cd /path/to/org/repo
2. make repro REPRO_ARGS="/tmp/example.org"
3. Move to the #+begin_src line of the second code block
4. M-: (org-babel-get-src-block-info 'no-eval)
5. I observe return value

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-11-24 Thread Andrea
Sorry Ihor for the long delay.
I got the error again for the second source block in the attached file.
That is a sample of my configuration.

Hope this helps,

Andrea



example.org
Description: Lotus Organizer


On Fri 13 Oct 2023 at 11:56, Ihor Radchenko  wrote:

> Andrea  writes:
>
>> Thanks Ihor! I found out that there was (likely) an encoding issue on
>> one of the source block. I had something like:
>> :PROPERTIES:
>> :ID: some-id
>> :END:
>>
>> #+being_src emacs-lisp
>>
>> And trying to evaluate (org-babel-get-src-block-info 'no-eval) at the
>> beginning of the source block was returning nil (as if I were outside of it).
>
> This should not happen. It would be nice if you can share a file with
> problematic encoding, so that I could check if we have an edge case
> with Org parser.


Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-10-13 Thread Ihor Radchenko
Andrea  writes:

> Thanks Ihor! I found out that there was (likely) an encoding issue on
> one of the source block. I had something like:
> :PROPERTIES:
> :ID: some-id
> :END:
>
> #+being_src emacs-lisp
>
> And trying to evaluate (org-babel-get-src-block-info 'no-eval) at the
> beginning of the source block was returning nil (as if I were outside of it).

This should not happen. It would be nice if you can share a file with
problematic encoding, so that I could check if we have an edge case
with Org parser.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-10-12 Thread Andrea


On Thu 12 Oct 2023 at 15:29, Ihor Radchenko  wrote:

>
> I recommend trying to shrink the problematic file to the smallest possible.
> Then, try with emacs -Q. If cannot reproduce, you can use
> https://github.com/Malabarba/elisp-bug-hunter to bisect the config
> quickly.


Thanks Ihor! I found out that there was (likely) an encoding issue on
one of the source block. I had something like:
:PROPERTIES:
:ID: some-id
:END:

#+being_src emacs-lisp

And trying to evaluate (org-babel-get-src-block-info 'no-eval) at the
beginning of the source block was returning nil (as if I were outside of it).

Just adding a newline manually removed the issue, so I guessed there was
some special character there (which is weird, but I cannot be sure of my
copy pasting).

Sorry for the noise and thanks for your suggestions, they were useful in
debugging my issue.

Best,

Andrea



Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-10-12 Thread Ihor Radchenko
Andrea  writes:

> Mmm... I run org-lint (and fix unrelated issues, thanks!) and the problem 
> remains.
> It is strange though, this is the block on which the function
> stops working (it is the first actually)
>
> ...
> Must be something wrong with my configuration then.
> I will update this issue if I find that out.

I recommend trying to shrink the problematic file to the smallest possible.
Then, try with emacs -Q. If cannot reproduce, you can use
https://github.com/Malabarba/elisp-bug-hunter to bisect the config
quickly.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-10-12 Thread Andrea


On Thu 12 Oct 2023 at 14:40, Ihor Radchenko  wrote:

> Andrea  writes:
>
>> This is the full trace I get running "emacs --debug-init" (sorry I should 
>> have added it in my bug report):
>>
>>Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>>  string-match("\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'" nil nil)
>>  string-match-p("\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'" nil)
>>  (not (string-match-p lang-re src-lang))
>
> That looks like a malformed src block with missing lang.
> I recommend running M-x org-lint
>

Mmm... I run org-lint (and fix unrelated issues, thanks!) and the problem 
remains.
It is strange though, this is the block on which the function
stops working (it is the first actually)

   #+begin_src emacs-lisp :tangle yes
   (defun my/init-audit-message (string)
 "Print out STRING and calculate length of init."
 (message string)
 (if (not (string= "end" (substring string -3)))
 (setq my/init-audit-message-begin (current-time))
   (message
"It took %s seconds in total."
(time-to-seconds
 (time-subtract
  (current-time)
  my/init-audit-message-begin
 nil)
   #+end_src

Must be something wrong with my configuration then.
I will update this issue if I find that out.



Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-10-12 Thread Ihor Radchenko
Andrea  writes:

> This is the full trace I get running "emacs --debug-init" (sorry I should 
> have added it in my bug report):
>
>Debugger entered--Lisp error: (wrong-type-argument stringp nil)
>  string-match("\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'" nil nil)
>  string-match-p("\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'" nil)
>  (not (string-match-p lang-re src-lang))

That looks like a malformed src block with missing lang.
I recommend running M-x org-lint

I now made Org skip source blocks without defined language when
tangling.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f3de4c3e0

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-10-12 Thread Andrea


Thanks Ihor for the super quick response!

On Thu 12 Oct 2023 at 13:04, Ihor Radchenko  wrote:

> Andrea  writes:
>
>> 
>> Sometimes I get an error on org-babel-load-file saying that
>> org-babel-tangle-collect-blocks was called with target-file set to nil.
>
> May it be possible to provide more details about the error you are
> seeing? You can set `debug-on-error' to t and post the backtrace, which
> will give more details. Or, better, provide a reproducer. See
> https://orgmode.org/manual/Feedback.html#Feedback
>

This is the full trace I get running "emacs --debug-init" (sorry I should have 
added it in my bug report):

   Debugger entered--Lisp error: (wrong-type-argument stringp nil)
 string-match("\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'" nil nil)
 string-match-p("\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'" nil)
 (not (string-match-p lang-re src-lang))
 (and lang-re (not (string-match-p lang-re src-lang)))
 (or (string= src-tfile "no") (and tangle-file (not (equal tangle-file 
src-tfile))) (and lang-re (not (string-match-p lang-re src-lang
 (if (or (string= src-tfile "no") (and tangle-file (not (equal tangle-file 
src-tfile))) (and lang-re (not (string-match-p lang-re src-lang nil (let* 
((block (org-babel-tangle-single-block counter)) (src-tfile (cdr (assq :tangle 
(nth 4 block (file-name (org-babel-effective-tangled-filename (nth 1 block) 
src-lang src-tfile)) (by-fn (assoc file-name blocks))) (if by-fn (setcdr by-fn 
(cons (cons src-lang block) (cdr by-fn))) (setq blocks (cons (cons file-name 
(list (cons src-lang block))) blocks)
 (let* ((info (org-babel-get-src-block-info 'no-eval)) (src-lang (nth 0 
info)) (src-tfile (cdr (assq :tangle (nth 2 info) (if (or (string= 
src-tfile "no") (and tangle-file (not (equal tangle-file src-tfile))) (and 
lang-re (not (string-match-p lang-re src-lang nil (let* ((block 
(org-babel-tangle-single-block counter)) (src-tfile (cdr (assq :tangle (nth 4 
block (file-name (org-babel-effective-tangled-filename (nth 1 block) 
src-lang src-tfile)) (by-fn (assoc file-name blocks))) (if by-fn (setcdr by-fn 
(cons (cons src-lang block) (cdr by-fn))) (setq blocks (cons (cons file-name 
(list ...)) blocks))
 (if (or (org-in-commented-heading-p) (org-in-archived-heading-p)) nil 
(let* ((info (org-babel-get-src-block-info 'no-eval)) (src-lang (nth 0 info)) 
(src-tfile (cdr (assq :tangle (nth 2 info) (if (or (string= src-tfile "no") 
(and tangle-file (not (equal tangle-file src-tfile))) (and lang-re (not 
(string-match-p lang-re src-lang nil (let* ((block 
(org-babel-tangle-single-block counter)) (src-tfile (cdr (assq :tangle ...))) 
(file-name (org-babel-effective-tangled-filename (nth 1 block) src-lang 
src-tfile)) (by-fn (assoc file-name blocks))) (if by-fn (setcdr by-fn (cons 
(cons src-lang block) (cdr by-fn))) (setq blocks (cons (cons file-name ...) 
blocks)))
 (let ((full-block (match-string 0)) (beg-block (match-beginning 0)) 
(end-block (match-end 0)) (lang (match-string 2)) (beg-lang (match-beginning 
2)) (end-lang (match-end 2)) (switches (match-string 3)) (beg-switches 
(match-beginning 3)) (end-switches (match-end 3)) (header-args (match-string 
4)) (beg-header-args (match-beginning 4)) (end-header-args (match-end 4)) (body 
(match-string 5)) (beg-body (match-beginning 5)) (end-body (match-end 5))) 
(ignore full-block beg-block end-block lang beg-lang end-lang switches 
beg-switches end-switches header-args beg-header-args end-header-args body 
beg-body end-body) (let ((current-heading-pos (if (org-element--cache-active-p) 
(or (org-element-property :begin (org-element-lineage ... ... t)) 1) 
(save-excursion (save-restriction (widen) (progn ... ... ... ... ...)) (if 
(eq last-heading-pos current-heading-pos) (setq counter (1+ counter)) (setq 
counter 1) (setq last-heading-pos current-heading-pos))) (if (or 
(org-in-commented-heading-p) (org-in-archived-heading-p)) nil (let* ((info 
(org-babel-get-src-block-info 'no-eval)) (src-lang (nth 0 info)) (src-tfile 
(cdr (assq :tangle (nth 2 info) (if (or (string= src-tfile "no") (and 
tangle-file (not (equal tangle-file src-tfile))) (and lang-re (not 
(string-match-p lang-re src-lang nil (let* ((block 
(org-babel-tangle-single-block counter)) (src-tfile (cdr ...)) (file-name 
(org-babel-effective-tangled-filename ... src-lang src-tfile)) (by-fn (assoc 
file-name blocks))) (if by-fn (setcdr by-fn (cons ... ...)) (setq blocks (cons 
... blocks))) (goto-char end-block))
 (progn (goto-char (match-beginning 0)) (let ((full-block (match-string 0)) 
(beg-block (match-beginning 0)) (end-block (match-end 0)) (lang (match-string 
2)) (beg-lang (match-beginning 2)) (end-lang (match-end 2)) (switches 
(match-string 3)) (beg-switches (match-beginning 3)) (end-switches (match-end 
3)) (header-args (match-string 4)) (beg-header-args (match-beginning 4)) 
(end-header-args (match-end 4)) (body (match-string 5)) (beg-body 

Re: [BUG] org-babel-tangle may fail due to (org-babel-tangle-collect-blocks lang-re tangle-file) [9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)]

2023-10-12 Thread Ihor Radchenko
Andrea  writes:

> 
> Sometimes I get an error on org-babel-load-file saying that
> org-babel-tangle-collect-blocks was called with target-file set to nil.

May it be possible to provide more details about the error you are
seeing? You can set `debug-on-error' to t and post the backtrace, which
will give more details. Or, better, provide a reproducer. See
https://orgmode.org/manual/Feedback.html#Feedback

> Since that seems an effective but senseless action, I just looked into it and 
> there is
> something weird in the code of org-babel-tangle:
>
> Given the header of the function:
>
>   (defun org-babel-tangle ( arg target-file lang-re)
>
> and the docstring section
>
>   "Optional argument TARGET-FILE can be used to specify a default export
>   file for all source blocks.  "
>
> I think this let binding in org-babel-tangle is weird and the cause of my 
> error:
>
>   (tangle-file
>(when (equal arg '(16))
>  (or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 
> 'no-eval
>  (user-error "Point is not in a source code block"
>
> Shouldn't that be:
>
>   (tangle-file
>(or
>(when (equal arg '(16))
>(or (cdr (assq :tangle (nth 2 (org-babel-get-src-block-info 
> 'no-eval
>(user-error "Point is not in a source code
>block")))
>  target-file ;; the target file which was passed as input of 
> org-babel-tangle
>  ))

No, tangle-file being nil should not be a problem.

> Any chance I found a bug?

Likely, but not necessarily in `org-babel-tangle'.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at