emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [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 10:33 Andrea
  2023-10-12 13:04 ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Andrea @ 2023-10-12 10:33 UTC (permalink / raw)
  To: emacs-orgmode


Hello, thanks for maintaining the great Org Mode!

I have been keeping a literate Org Mode configuration for my init file.
This means that I have tons of src blocks looking like

#+begin_src emacs-lisp :tangle yes
...
#+end_src

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.

Not totally sure if this is had something to do with my configuration, I
always solved this by adding some spaces before my blocks (it doesn't
make sense, but strangely tended to work).

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 (&optional 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
             ))

With that my problem seems resolved. I think that code is weird because
using a when clause causes a possible nil value for that binding. But we
may still use the target-file input to save the day, no?

Any chance I found a bug?

Best,

Andrea

Emacs  : GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0)
 of 2022-05-31
Package: Org mode version 9.6.9 ( @ /home/andrea/.emacs.d/elpa/org-9.6.9/)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 10:33 [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/)] Andrea
@ 2023-10-12 13:04 ` Ihor Radchenko
  2023-10-12 14:16   ` Andrea
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2023-10-12 13:04 UTC (permalink / raw)
  To: Andrea; +Cc: emacs-orgmode

Andrea <andrea-dev@hotmail.com> 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 (&optional 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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 13:04 ` Ihor Radchenko
@ 2023-10-12 14:16   ` Andrea
  2023-10-12 14:40     ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Andrea @ 2023-10-12 14:16 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Andrea, emacs-orgmode


Thanks Ihor for the super quick response!

On Thu 12 Oct 2023 at 13:04, Ihor Radchenko <yantar92@posteo.net> wrote:

> Andrea <andrea-dev@hotmail.com> 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 (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 ...) 1) (save-excursion (save-restriction ... ...))))) (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 ...)))) (if (or (string= src-tfile "no") (and tangle-file (not ...)) (and lang-re (not ...))) nil (let* ((block ...) (src-tfile ...) (file-name ...) (by-fn ...)) (if by-fn (setcdr by-fn ...) (setq blocks ...)))))) (goto-char end-block)))
     (if (org-babel-active-location-p) (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 (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 ... 1) (save-excursion ...)))) (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 ...)) (src-lang (nth 0 info)) (src-tfile (cdr ...))) (if (or (string= src-tfile "no") (and tangle-file ...) (and lang-re ...)) nil (let* (... ... ... ...) (if by-fn ... ...))))) (goto-char end-block))))
     (while (re-search-forward org-babel-src-block-regexp nil t) (if (org-babel-active-location-p) (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 (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 ... ... ...))) (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 ...) (src-lang ...) (src-tfile ...)) (if (or ... ... ...) nil (let* ... ...)))) (goto-char end-block)))))
     (progn (if file (progn (find-file file))) (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-src-block-regexp nil t) (if (org-babel-active-location-p) (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 (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 (eq last-heading-pos current-heading-pos) (setq 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* (... ... ...) (if ... nil ...))) (goto-char end-block))))))
     (unwind-protect (progn (if file (progn (find-file file))) (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-src-block-regexp nil t) (if (org-babel-active-location-p) (progn (goto-char (match-beginning 0)) (let ((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 ...)) (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 (...) (if ... ... ... ...)) (if (or ... ...) nil (let* ... ...)) (goto-char end-block)))))) (set-window-configuration wconfig))
     (let ((wconfig (current-window-configuration))) (unwind-protect (progn (if file (progn (find-file file))) (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-src-block-regexp nil t) (if (org-babel-active-location-p) (progn (goto-char (match-beginning 0)) (let (... ... ... ... ... ... ... ... ... ... ... ... ... ... ...) (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 ... ...) (if ... nil ...) (goto-char end-block)))))) (set-window-configuration wconfig)))
     (let* ((case-fold-search t) (file (buffer-file-name)) (visited-p (or (null file) (get-file-buffer (expand-file-name file)))) (point (point)) to-be-removed) (let ((wconfig (current-window-configuration))) (unwind-protect (progn (if file (progn (find-file file))) (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-src-block-regexp nil t) (if (org-babel-active-location-p) (progn (goto-char ...) (let ... ... ... ... ...))))) (set-window-configuration wconfig))) (if visited-p nil (kill-buffer to-be-removed)) (goto-char point))
     (let ((counter 0) last-heading-pos blocks) (let* ((case-fold-search t) (file (buffer-file-name)) (visited-p (or (null file) (get-file-buffer (expand-file-name file)))) (point (point)) to-be-removed) (let ((wconfig (current-window-configuration))) (unwind-protect (progn (if file (progn (find-file file))) (setq to-be-removed (current-buffer)) (goto-char (point-min)) (while (re-search-forward org-babel-src-block-regexp nil t) (if (org-babel-active-location-p) (progn ... ...)))) (set-window-configuration wconfig))) (if visited-p nil (kill-buffer to-be-removed)) (goto-char point)) (mapcar #'(lambda (b) (cons (car b) (nreverse (cdr b)))) (nreverse blocks)))
     org-babel-tangle-collect-blocks("\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'" nil)
     (if (equal arg '(4)) (org-babel-tangle-single-block 1 t) (org-babel-tangle-collect-blocks lang-re tangle-file))
     (mapc #'(lambda (by-fn) (let ((file-name (car by-fn))) (if file-name (progn (let (... ... modes make-dir she-banged lang) (let ... ...)))))) (if (equal arg '(4)) (org-babel-tangle-single-block 1 t) (org-babel-tangle-collect-blocks lang-re tangle-file)))
     (let ((block-counter 0) (org-babel-default-header-args (if target-file (org-babel-merge-params org-babel-default-header-args (list (cons :tangle target-file))) org-babel-default-header-args)) (tangle-file (if (equal arg '(16)) (progn (or (cdr (assq :tangle ...)) (user-error "Point is not in a source code block"))))) path-collector) (mapc #'(lambda (by-fn) (let ((file-name (car by-fn))) (if file-name (progn (let ... ...))))) (if (equal arg '(4)) (org-babel-tangle-single-block 1 t) (org-babel-tangle-collect-blocks lang-re tangle-file))) (message "Tangled %d code block%s from %s" block-counter (if (= block-counter 1) "" "s") (file-name-nondirectory (buffer-file-name (or (buffer-base-buffer) (current-buffer) (and (org-src-edit-buffer-p) (org-src-source-buffer)))))) (if org-babel-post-tangle-hook (progn (mapc #'(lambda (file) (let* (... ... temp-result temp-file) (org-babel-find-file-noselect-refresh temp-path) (setq temp-file ...) (save-current-buffer ... ...) (if visited-p nil ...) temp-result)) path-collector))) (run-hooks 'org-babel-tangle-finished-hook) path-collector)
     (save-excursion (if (equal arg '(4)) (progn (let ((head (org-babel-where-is-src-block-head))) (if head (goto-char head) (user-error "Point is not in a source code block"))))) (let ((block-counter 0) (org-babel-default-header-args (if target-file (org-babel-merge-params org-babel-default-header-args (list (cons :tangle target-file))) org-babel-default-header-args)) (tangle-file (if (equal arg '(16)) (progn (or (cdr ...) (user-error "Point is not in a source code block"))))) path-collector) (mapc #'(lambda (by-fn) (let ((file-name ...)) (if file-name (progn ...)))) (if (equal arg '(4)) (org-babel-tangle-single-block 1 t) (org-babel-tangle-collect-blocks lang-re tangle-file))) (message "Tangled %d code block%s from %s" block-counter (if (= block-counter 1) "" "s") (file-name-nondirectory (buffer-file-name (or (buffer-base-buffer) (current-buffer) (and (org-src-edit-buffer-p) (org-src-source-buffer)))))) (if org-babel-post-tangle-hook (progn (mapc #'(lambda (file) (let* ... ... ... ... ... temp-result)) path-collector))) (run-hooks 'org-babel-tangle-finished-hook) path-collector))
     (save-restriction (save-excursion (if (equal arg '(4)) (progn (let ((head (org-babel-where-is-src-block-head))) (if head (goto-char head) (user-error "Point is not in a source code block"))))) (let ((block-counter 0) (org-babel-default-header-args (if target-file (org-babel-merge-params org-babel-default-header-args (list ...)) org-babel-default-header-args)) (tangle-file (if (equal arg '...) (progn (or ... ...)))) path-collector) (mapc #'(lambda (by-fn) (let (...) (if file-name ...))) (if (equal arg '(4)) (org-babel-tangle-single-block 1 t) (org-babel-tangle-collect-blocks lang-re tangle-file))) (message "Tangled %d code block%s from %s" block-counter (if (= block-counter 1) "" "s") (file-name-nondirectory (buffer-file-name (or (buffer-base-buffer) (current-buffer) (and ... ...))))) (if org-babel-post-tangle-hook (progn (mapc #'(lambda ... ...) path-collector))) (run-hooks 'org-babel-tangle-finished-hook) path-collector)))
     org-babel-tangle(nil "~/workspace/agenda/config.el" "\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'")
     (mapcar #'expand-file-name (org-babel-tangle nil target-file lang-re))
     (save-restriction (widen) (mapcar #'expand-file-name (org-babel-tangle nil target-file lang-re)))
     (save-excursion (save-restriction (widen) (mapcar #'expand-file-name (org-babel-tangle nil target-file lang-re))))
     (save-current-buffer (set-buffer buffer) (save-excursion (save-restriction (widen) (mapcar #'expand-file-name (org-babel-tangle nil target-file lang-re)))))
     (prog1 (save-current-buffer (set-buffer buffer) (save-excursion (save-restriction (widen) (mapcar #'expand-file-name (org-babel-tangle nil target-file lang-re))))) (if visited nil (kill-buffer buffer)))
     (let* ((visited (find-buffer-visiting file)) (buffer (or visited (find-file-noselect file)))) (prog1 (save-current-buffer (set-buffer buffer) (save-excursion (save-restriction (widen) (mapcar #'expand-file-name (org-babel-tangle nil target-file lang-re))))) (if visited nil (kill-buffer buffer))))
     org-babel-tangle-file("~/workspace/agenda/config.org" "~/workspace/agenda/config.el" "\\`\\(?:e\\(?:\\(?:macs-\\)?lisp\\)\\)\\'")
     org-babel-load-file("~/workspace/agenda/config.org")
     (let ((file-name-handler-alist nil) (gc-cons-threshold most-positive-fixnum) (gc-cons-percentage 0.6)) (if window-system (progn (menu-bar-mode -1) (tool-bar-mode -1) (scroll-bar-mode -1) (tooltip-mode -1))) (add-hook 'focus-out-hook #'garbage-collect) (setq inhibit-startup-message t) (setq load-prefer-newer t) (require 'package) '(("melpa-stable" . "https://stable.melpa.org/packages/") ("melpa" . "https://melpa.org/packages/") ("gnu" . "https://elpa.gnu.org/packages/") ("nongnu" . "https://elpa.nongnu.org/nongnu/")) (package-initialize) (require 'cl-lib) (if (package-installed-p 'use-package) nil (package-refresh-contents) (package-install 'use-package)) (setq use-package-always-ensure t use-package-compute-statistics t) (if (package-installed-p 'org-contrib) nil (let* ((package--builtins 'nil) (my-packages '(org diminish)) (missing (remove-if 'package-installed-p my-packages))) (if missing (progn (package-refresh-contents) (mapc 'package-install missing)))) (package-refresh-contents) (package-install 'org-contrib)) (require 'use-package) (require 'diminish) (require 'bind-key) (progn (use-package-ensure-elpa 'use-package-ensure-system-package '(t) 'nil) (defvar use-package--warning0 #'(lambda (keyword err) (let ((msg ...)) (display-warning 'use-package msg :error)))) (condition-case err (if (not (require 'use-package-ensure-system-package nil t)) (display-warning 'use-package (format "Cannot load %s" 'use-package-ensure-system-package) :error) (condition-case err (progn (setq system-packages-package-manager (if ... ... ...)) (setq system-packages-use-sudo t) (defalias 'my/check-package-not-installed-already #'...) (advice-add 'system-packages-install :around #'my/check-package-not-installed-already) t) ((debug error) (funcall use-package--warning0 :config err)))) ((debug error) (funcall use-package--warning0 :catch err)))) (progn (defvar use-package--warning1 #'(lambda (keyword err) (let ((msg ...)) (display-warning 'use-package msg :error)))) (condition-case err (if (not (require 'use-package-chords nil t)) (display-warning 'use-package (format "Cannot load %s" 'use-package-chords) :error) (condition-case err (progn (key-chord-mode 1) t) ((debug error) (funcall use-package--warning1 :config err)))) ((debug error) (funcall use-package--warning1 :catch err)))) (load "server") (if (server-running-p) nil (server-start)) (message "--- Start loading config.el") (setq my/init-file-time (current-time)) (org-babel-load-file "~/workspace/agenda/config.org") (message "--- Finish loading config.el") (message "Config.el took %s seconds in total" (time-to-seconds (time-subtract (current-time) my/init-file-time))))
     eval-buffer(#<buffer  *load*> nil "/home/andrea/.emacs.d/init.el" nil t)  ; Reading at buffer position 3454
     load-with-code-conversion("/home/andrea/.emacs.d/init.el" "/home/andrea/.emacs.d/init.el" t t)
     load("/home/andrea/.emacs.d/init" noerror nomessage)
     startup--load-user-init-file(#f(compiled-function () #<bytecode -0x8411441f899e09c>) #f(compiled-function () #<bytecode -0x1f3c686ddc0cdc35>) t)
     command-line()
     normal-top-level()


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 14:16   ` Andrea
@ 2023-10-12 14:40     ` Ihor Radchenko
  2023-10-12 14:50       ` Andrea
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2023-10-12 14:40 UTC (permalink / raw)
  To: Andrea; +Cc: emacs-orgmode

Andrea <andrea-dev@hotmail.com> 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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 14:40     ` Ihor Radchenko
@ 2023-10-12 14:50       ` Andrea
  2023-10-12 15:29         ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Andrea @ 2023-10-12 14:50 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Andrea, emacs-orgmode


On Thu 12 Oct 2023 at 14:40, Ihor Radchenko <yantar92@posteo.net> wrote:

> Andrea <andrea-dev@hotmail.com> 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.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 14:50       ` Andrea
@ 2023-10-12 15:29         ` Ihor Radchenko
  2023-10-12 15:46           ` Andrea
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2023-10-12 15:29 UTC (permalink / raw)
  To: Andrea; +Cc: emacs-orgmode

Andrea <andrea-dev@hotmail.com> 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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 15:29         ` Ihor Radchenko
@ 2023-10-12 15:46           ` Andrea
  2023-10-13 11:56             ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Andrea @ 2023-10-12 15:46 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Andrea, emacs-orgmode


On Thu 12 Oct 2023 at 15:29, Ihor Radchenko <yantar92@posteo.net> 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


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 15:46           ` Andrea
@ 2023-10-13 11:56             ` Ihor Radchenko
  2023-11-24 13:38               ` Andrea
  0 siblings, 1 reply; 10+ messages in thread
From: Ihor Radchenko @ 2023-10-13 11:56 UTC (permalink / raw)
  To: Andrea; +Cc: emacs-orgmode

Andrea <andrea-dev@hotmail.com> 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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 11:56             ` Ihor Radchenko
@ 2023-11-24 13:38               ` Andrea
  2023-12-05 11:28                 ` Ihor Radchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Andrea @ 2023-11-24 13:38 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: Andrea, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 168 bytes --]

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


[-- Attachment #2: example.org --]
[-- Type: application/vnd.lotus-organizer, Size: 864 bytes --]

[-- Attachment #3: Type: text/plain, Size: 633 bytes --]



On Fri 13 Oct 2023 at 11:56, Ihor Radchenko <yantar92@posteo.net> wrote:

> Andrea <andrea-dev@hotmail.com> 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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* 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 13:38               ` Andrea
@ 2023-12-05 11:28                 ` Ihor Radchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Ihor Radchenko @ 2023-12-05 11:28 UTC (permalink / raw)
  To: Andrea; +Cc: emacs-orgmode

Andrea <andrea-dev@hotmail.com> 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 <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-12-05 11:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-12 10:33 [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/)] Andrea
2023-10-12 13:04 ` Ihor Radchenko
2023-10-12 14:16   ` Andrea
2023-10-12 14:40     ` Ihor Radchenko
2023-10-12 14:50       ` Andrea
2023-10-12 15:29         ` Ihor Radchenko
2023-10-12 15:46           ` Andrea
2023-10-13 11:56             ` Ihor Radchenko
2023-11-24 13:38               ` Andrea
2023-12-05 11:28                 ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).