On 03.01.2024 16:11, Ihor Radchenko wrote: > gerard.vermeulen@posteo.net writes: > [...] Attached you'll find a new patch that seems to solve the block indentation problem that you have pointed out, see PS or attached patch-demo.org. test-ob/demarcate-block-split passes. > > This was a bug in `org-element-copy'. Fixed, on main now. > https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=dfeff03c5 > I did not yet pull your change. Nevertheless, the Emergency exit errors have disappeared. > [...] > > I made some adjustments to the patch, making use of org-element API. > See the attached updated version of the patch. > This patch is heavily edited and I think I did not forget any of your changes. I have tried to clean up the code. I have also tried to get `body-beg' and `body-end' marking the text between the #+begin_src and #+end_src lines from the element API, but I failed and had to fall back to `org-babel-where-is-src-block-head'. But only for that. > I am not yet merging it as I found some weirdness with indentation. > Consider the following (indentation is important): > > #+BEGIN_SRC emacs-lisp -n 20 > ;; This exports with line number 20. > (message "This is line 21") > #+END_SRC > > After M-x org-babel-demarcate-block, I am getting > > #+BEGIN_SRC emacs-lisp -n 20 > ;; This exports with line number 20. > #+END_SRC > > #+begin_src emacs-lisp -n 20 > (message "This is line 21") > #+end_src See PS or patch-demo.org: PS (hope you read it with a mono-spaced font): #+begin_src emacs-lisp :results silent (setopt org-adapt-indentation t org-src-preserve-indentation nil org-edit-src-content-indentation 2) #+end_src ******** before C-u org-babel-demarcate-block splitting I put point at the left of the last line in this block before splitting #+BEGIN_SRC emacs-lisp -n 20 ;; this exports with line number 20 (message "This exports with line number 21") #+END_SRC C-u C-c C-v d gets the stars right and the indentation ******** after C-u org-babel-demarcate-block splitting I put point at the left of the last line in this block before splitting #+begin_src emacs-lisp -n 20 ;; this exports with line number 20 #+end_src ******** #+begin_src emacs-lisp -n 20 (message "This exports with line number 21") #+end_src C-u C-c C-v d gets the stars right and the indentation