I can confirm from trying Paul's reproducer that this totally can
swallow someone's data and should be fixed!
Attached is a quick and simple fix but looking into this makes me
question the function quite a bit. 'org-babel-examplify-region'
quotes completly different depending on the quoting style.
Block quotes quote the exact region passed to it while the inline
quoting will quote every line that is in the region (even
partially). See the code blocks at the end of this email for
examples. Notice how the last one manages to swallow a newline.
It doesn't do that if you apply the attached patch
#+begin_src elisp
(with-temp-buffer
(insert "before inside after")
(org-babel-examplify-region 8 15)
(buffer-string))
#+end_src
#+RESULTS:
: : before inside after
#+begin_src elisp
(with-temp-buffer
(insert "before\ninside\n\nafter")
(org-babel-examplify-region 8 15)
(buffer-string))
#+end_src
#+RESULTS:
: before
: : inside
:
: after
#+begin_src elisp
(let ((org-babel-min-lines-for-block-output 0))
(with-temp-buffer
(insert "before inside after")
(org-babel-examplify-region 8 15)
(buffer-string)))
#+end_src
#+RESULTS:
: before
: #+begin_example
: inside
: #+end_example
: after
#+begin_src elisp
(let ((org-babel-min-lines-for-block-output 0))
(with-temp-buffer
(insert "before\ninside\n\nafter")
(org-babel-examplify-region 8 15)
(buffer-string)))
#+end_src
#+RESULTS:
: before
: #+begin_example
: inside
: #+end_example
: after
>From 57073e985725aa67321dd4726321fe0c77480a5b Mon Sep 17 00:00:00 2001
From: Morgan Smith <[email protected]>
Date: Sat, 31 Oct 2026 14:58:00 -0400
Subject: [PATCH] org-babel-examplify-region: Do not swallow newlines after the
region
* lisp/ob-core.el (org-babel-examplify-region): Insert a newline after
"#+end_example".
---
lisp/ob-core.el | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 3e218c418..4683c98aa 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -3010,7 +3010,7 @@ org-babel-examplify-region
(org-escape-code-in-region p (point)))
(unless (bolp) (insert "\n"))
(insert (funcall maybe-cap "#+end_example"))
- (unless (eolp) (insert "\n")))))))))
+ (insert "\n"))))))))
(defun org-babel-update-block-body (new-body)
"Update the body of the current code block to NEW-BODY."
--
2.55.0