branch: externals/org commit 482bc31565bca67ca5122909376bf67d60992c96 Author: Ihor Radchenko <yanta...@posteo.net> Commit: Ihor Radchenko <yanta...@posteo.net>
org-babel-demarcate-block: Fix keeping BEGIN_SRC/END_SRC case * lisp/ob-core.el (org-babel-demarcate-block): Keep case in #+BEGIN_SRC and #+END_SRC keywords splitting src block. * testing/lisp/test-ob.el (test-ob/keep-case): New test. Reported-by: Rudolf Adamkovič <rud...@adamkovic.org> Link: https://orgmode.org/list/m2y152f8s3....@adamkovic.org --- lisp/ob-core.el | 23 ++++++++++++++++++++--- testing/lisp/test-ob.el | 31 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/lisp/ob-core.el b/lisp/ob-core.el index 0fc8b27a9b..c61f2d4007 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2139,7 +2139,14 @@ block of the same language as the previous." (list (point)))) (n (- (length parts) 2)) ;; 1 or 2 parts in `dolist' below. ;; `post-blank' caches the property before setting it to 0. - (post-blank (org-element-property :post-blank copy))) + (post-blank (org-element-property :post-blank copy)) + (to-uppercase + (lambda (str) + (string-match "^[ \t]*#\\+\\(begin_src\\)" str) + (setq str (replace-match "BEGIN_SRC" t t str 1)) + (string-match "^[ \t]*#\\+\\(end_src\\)" str) + (setq str (replace-match "END_SRC" t t str 1)) + str))) ;; Point or region are within body when parts is in increasing order. (unless (apply #'<= parts) (user-error "Select within the source block body to split it")) @@ -2159,7 +2166,12 @@ block of the same language as the previous." ;; Set `:post-blank' to 0. We take care of spacing between blocks. (org-element-put-property copy :post-blank 0) (org-element-put-property copy :value (car parts)) - (insert (org-element-interpret-data copy)) + (let ((copy-str (org-element-interpret-data copy))) + ;; `org-element-interpret-data' produces lower-case + ;; #+begin_src .. #+end_src + (when upper-case-p + (setq copy-str (funcall to-uppercase copy-str))) + (insert copy-str)) ;; `org-indent-block' may see another `org-element' (e.g. paragraph) ;; immediately after the block. Ensure to indent the inserted block ;; and move point to its end. @@ -2176,7 +2188,12 @@ block of the same language as the previous." (when (= n 0) ;; Use `post-blank' to reset the property of the last block. (org-element-put-property copy :post-blank post-blank)) - (insert (org-element-interpret-data copy)) + (let ((copy-str (org-element-interpret-data copy))) + ;; `org-element-interpret-data' produces lower-case + ;; #+begin_src .. #+end_src + (when upper-case-p + (setq copy-str (funcall to-uppercase copy-str))) + (insert copy-str)) ;; Ensure to indent the inserted block and move point to its end. (org-babel-previous-src-block 1) (org-indent-block) diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el index 544e68267c..49dc1b80f7 100644 --- a/testing/lisp/test-ob.el +++ b/testing/lisp/test-ob.el @@ -2828,6 +2828,37 @@ to upper block (should-not vars) (should (string= "" (nth 3 info))))))) +(ert-deftest test-ob/keep-case () + "Test keeping #+BEGIN_SRC/#+begin_src case." + (org-test-with-temp-text " +#+begin_src any-language +A +<point>B +#+end_src +" + (org-babel-demarcate-block) + (goto-char (point-min)) + (org-babel-next-src-block) + (let ((case-fold-search nil)) + (should (looking-at-p "#\\+begin_src"))) + (org-babel-next-src-block) + (let ((case-fold-search nil)) + (should (looking-at-p "#\\+begin_src")))) + (org-test-with-temp-text " +#+BEGIN_SRC any-language +A +<point>B +#+END_SRC +" + (org-babel-demarcate-block) + (goto-char (point-min)) + (org-babel-next-src-block) + (let ((case-fold-search nil)) + (should (looking-at-p "#\\+BEGIN_SRC"))) + (org-babel-next-src-block) + (let ((case-fold-search nil)) + (should (looking-at-p "#\\+BEGIN_SRC"))))) + (provide 'test-ob) ;;; test-ob ends here