On 29.02.2024 12:56, Ihor Radchenko wrote:
gerard.vermeu...@posteo.net writes:
That includes `org-babel-demarcate-block' splitting with the patch.
I do not understand why it works and why I never see the user-error
re-signalled by `org-babel-edit-prep:sql' (even as demoted message).
[...]
I have reduced my version of `org-babel-demarcate-block' to a minimal
function to locate the bug stemming from edit-prep signaling an
user-error or not. In case edit-prep signals an user-error the call
chain `org-indent-block', `org-indent-region', `org-element-at-point'
triggers an infinite list of warnings (major mode is Python when run
on the test block).
#+begin_src emacs-lisp -n :results silent
(defun oeap-test ()
"Test `org-element-at-point': call with point at block."
(interactive)
(let* ((info (org-babel-get-src-block-info 'noeval))
(start (org-babel-where-is-src-block-head))
(body (and start (match-string 5))))
(if (and info start)
(let* ((copy (org-element-copy (org-element-at-point)))
(before (org-element-begin copy))
(beyond (org-element-end copy)))
(org-element-put-property copy :value body)
(delete-region before beyond)
(insert (org-element-interpret-data copy))
(org-babel-previous-src-block 1)
(message "Mode derived from: %S" (derived-mode-p 'org-mode))
;; Triggers list of warnings and condition-case is no
solution:
(org-indent-block)))))
#+end_src
Working edit-prep:
#+begin_src emacs-lisp -n :results silent
(defun harm-full-edit-prep (_info)
(user-error "Harm-FULL edit-prep"))
(defun org-babel-edit-prep:python (info)
(condition-case nil
(harm-full-edit-prep info)
(t nil)))
(message "Working edit-prep:python")
#+end_src
Failing edit-prep:
#+begin_src emacs-lisp -n :results silent
(defun harm-full-edit-prep (_info)
(user-error "Harm-FULL edit-prep"))
(defun org-babel-edit-prep:python (info)
(harm-full-edit-prep info))
(message "Failing edit-prep:python")
#+end_src
Test block:
#+begin_src python -i -n :results silent
11
22
#+end_src
I do not like to put extra constraints on edit-prep functions. Maybe,
it is better to cancel the patch.
Regards -- Gerard