浏览代码

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 年之前
父节点
当前提交
cb8366cd21
共有 1 个文件被更改,包括 13 次插入8 次删除
  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
 region is not active then the point is demarcated."
   (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
         (mapc
          (lambda (place)
@@ -1875,9 +1878,10 @@ region is not active then the point is demarcated."
 		 (delete-region (point-at-bol) (point-at-eol)))
                (insert (concat
 			(if (looking-at "^") "" "\n")
-			indent "#+end_src\n"
+			indent (funcall (if lower-case-p 'downcase 'upcase) "#+end_src\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)
 			    (concat " " headers) headers)
 			(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))))
 	(insert (concat (if (looking-at "^") "" "\n")
 			(if arg (concat stars "\n") "")
-			"#+begin_src " lang "\n"
+			(funcall (if lower-case-p 'downcase 'upcase) "#+begin_src ")
+			lang "\n"
 			body
 			(if (or (= (length body) 0)
 				(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)))))
 
 (defvar org-babel-lob-one-liner-regexp)