Browse Source

ob-core.el (org-babel-demarcate-block): Fix case

* ob-core.el (org-babel-demarcate-block): Upcase or downcase
the inserted #+begin_src and #+end_src depending on the
current case of #+begin_src and #+end_src.

Thanks to Alexander Baier for reporting this.
Bastien Guerry 11 years ago
parent
commit
cb8366cd21
1 changed files with 13 additions and 8 deletions
  1. 13 8
      lisp/ob-core.el

+ 13 - 8
lisp/ob-core.el

@@ -1858,10 +1858,13 @@ split.  When called from outside of a code block a new code block
 is created.  In both cases if the region is demarcated and if the
 is created.  In both cases if the region is demarcated and if the
 region is not active then the point is demarcated."
 region is not active then the point is demarcated."
   (interactive "P")
   (interactive "P")
-  (let ((info (org-babel-get-src-block-info 'light))
-	(headers (progn (org-babel-where-is-src-block-head)
-			(match-string 4)))
-	(stars (concat (make-string (or (org-current-level) 1) ?*) " ")))
+  (let* ((info (org-babel-get-src-block-info 'light))
+	 (block (progn (org-babel-where-is-src-block-head) (match-string 0)))
+	 (headers (progn (org-babel-where-is-src-block-head) (match-string 4)))
+	 (stars (concat (make-string (or (org-current-level) 1) ?*) " "))
+	 lower-case-p)
+    (if (let (case-fold-search) (string-match "#\\+begin_src" block))
+	(setq lower-case-p t))
     (if info
     (if info
         (mapc
         (mapc
          (lambda (place)
          (lambda (place)
@@ -1875,9 +1878,10 @@ region is not active then the point is demarcated."
 		 (delete-region (point-at-bol) (point-at-eol)))
 		 (delete-region (point-at-bol) (point-at-eol)))
                (insert (concat
                (insert (concat
 			(if (looking-at "^") "" "\n")
 			(if (looking-at "^") "" "\n")
-			indent "#+end_src\n"
+			indent (funcall (if lower-case-p 'downcase 'upcase) "#+end_src\n")
 			(if arg stars indent) "\n"
 			(if arg stars indent) "\n"
-			indent "#+begin_src " lang
+			indent (funcall (if lower-case-p 'downcase 'upcase) "#+begin_src ")
+			lang
 			(if (> (length headers) 1)
 			(if (> (length headers) 1)
 			    (concat " " headers) headers)
 			    (concat " " headers) headers)
 			(if (looking-at "[\n\r]")
 			(if (looking-at "[\n\r]")
@@ -1897,11 +1901,12 @@ region is not active then the point is demarcated."
 		   (if (org-region-active-p) (mark) (point)) (point))))
 		   (if (org-region-active-p) (mark) (point)) (point))))
 	(insert (concat (if (looking-at "^") "" "\n")
 	(insert (concat (if (looking-at "^") "" "\n")
 			(if arg (concat stars "\n") "")
 			(if arg (concat stars "\n") "")
-			"#+begin_src " lang "\n"
+			(funcall (if lower-case-p 'downcase 'upcase) "#+begin_src ")
+			lang "\n"
 			body
 			body
 			(if (or (= (length body) 0)
 			(if (or (= (length body) 0)
 				(string-match "[\r\n]$" body)) "" "\n")
 				(string-match "[\r\n]$" body)) "" "\n")
-			"#+end_src\n"))
+			(funcall (if lower-case-p 'downcase 'upcase) "#+end_src\n")))
 	(goto-char start) (move-end-of-line 1)))))
 	(goto-char start) (move-end-of-line 1)))))
 
 
 (defvar org-babel-lob-one-liner-regexp)
 (defvar org-babel-lob-one-liner-regexp)