On 25.02.2024 13:21, Ihor Radchenko wrote:
gerard.vermeu...@posteo.net writes:

I added the caveat:
This patch is incompatible with `org-babel-edit-prep:<LANG>' functions
that signal `user-error's.
to the commit message and cleaned it up a bit.

You may wrap `org-indent-block' into `condition-case' to catch

The caveat is not a real constraint, since Org has limited support for
source block editing in an Org mode buffer when an
`org-babel-edit-prep:<LANG>' function signals an user-error.

I show that in the attached no-user-errors-in-edit-prep.org.

I also attach condition-case.diff that I use to try to argue that
condition-case never gets into its error-handler (I am running the
code with the condition-case now), because I never see the signal of
~(user-error "Error in `org-babel-edit-prep:<LANG>'?")~ (I needed to
read the condition-case documentation, because this is the first time
I am trying to use it).

#+begin_src emacs-lisp -n :results silent
;; Fails with org-babel-demarcate-block in patch.
(defun edit-prep-user-error (_info)
  (user-error "Signaling user-errors is harmfull"))

(defun org-babel-edit-prep:python (info)
  (edit-prep-user-error info))

(message "Harm-FULL edit-prep:python")

#+begin_src emacs-lisp -n :results silent
;; Works with org-babel-demarcate-block in patch.
(defun edit-prep-message (_info)
  (message "Displaying messages is harmless"))

(defun org-babel-edit-prep:python (info)
  (edit-prep-message info))

(message "Harm-LESS edit-prep:python")

~org-babel-demarcate-blocks~ works with "Harm-LESS edit-prep:python"
but fails with "Harm-FULL edit-prep:python" and it leaves the Org mode
buffer in a state similar to shown in no-user-errors-in-edit-prep.org
(I have to pass through org-edit-src-code to be able to edit the block
in the Org mode buffer).

But I only can do that after interrupting (C-g C-g) an infinite stream
of warnings "Warning (org-element): ‘org-element-at-point’ cannot be
used in non-Org buffer #<buffer *Org Src mail.org[ python ]*>
(python-mode)" which should come from the `org-element-at-point' call
indicated by ;; <= HERE? in condition-case.diff.

Test block below:

#+begin_src python -i -n :results silent

Regards -- Gerard

Attachment: no-user-errors-in-edit-prep.org
Description: Binary data

Attachment: condition-case.diff
Description: Binary data

Reply via email to