浏览代码

DONE Allow source blocks to be recognised when #+ are not first characters on the line

Eric Schulte 16 年之前
父节点
当前提交
2f50cb659f
共有 2 个文件被更改,包括 29 次插入10 次删除
  1. 8 3
      lisp/org-babel.el
  2. 21 7
      org-babel.org

+ 8 - 3
lisp/org-babel.el

@@ -98,7 +98,7 @@ then run `org-babel-pop-to-session'."
 (defun org-babel-set-interpreters (var value)
   (set-default var value)
   (setq org-babel-src-block-regexp
-	(concat "#\\+begin_src \\("
+	(concat "^[ \t]*#\\+begin_src \\("
 		(mapconcat 'regexp-quote value "\\|")
 		"\\)[ \t]*"
                 "\\([ \t]+\\([^\n]+\\)\\)?\n" ;; match header arguments
@@ -331,9 +331,14 @@ may be specified in the properties of the current outline entry."
 
 (defun org-babel-parse-src-block-match ()
   (let* ((lang (org-babel-clean-text-properties (match-string 1)))
-         (lang-headers (intern (concat "org-babel-default-header-args:" lang))))
+         (lang-headers (intern (concat "org-babel-default-header-args:" lang)))
+         (body (org-babel-clean-text-properties (match-string 4))))
     (list lang
-	  (org-babel-strip-protective-commas (org-babel-clean-text-properties (match-string 4)))
+          (with-temp-buffer ;; get src block body removing properties, protective commas, and indentation
+            (save-match-data
+              (insert (org-babel-strip-protective-commas body))
+              (org-do-remove-indentation)
+              (buffer-string)))
 	  (org-babel-merge-params
 	   org-babel-default-header-args
            (org-babel-params-from-properties)

+ 21 - 7
org-babel.org

@@ -2743,7 +2743,7 @@ dot("$(2a,0)$",(2,0),N+E);
 *** DONE sh
 
 
-* Bugs [31/40]
+* Bugs [32/40]
 ** TODO export problems when support for a language is missing
 we should come up with a way to gracefully degrade when support for a
 specific language is missing
@@ -2868,12 +2868,6 @@ even a third"
 #+begin_src sh
 size=5
 #+end_src
-
-** TODO Allow source blocks to be recognised when #+ are not first characters on the line
-   I think Carsten has recently altered the core so that #+ can have
-   preceding whitespace, at least for literal/code examples. org-babel
-   should support this.
-
 ** TODO non-orgtbl formatted lists
 for example
 
@@ -2929,6 +2923,26 @@ the same for the other languages. [Dan]
 find . \( -path \*/SCCS -o -path \*/RCS -o -path \*/CVS -o -path \*/MCVS -o -path \*/.svn -o -path \*/.git -o -path \*/.hg -o -path \*/.bzr -o -path \*/_MTN -o -path \*/_darcs -o -path \*/\{arch\} \) -prune -o  -type f \( -iname \*.el \) -exec grep -i -nH -e org-babel-trim {} \;
 #+end_src
 
+** DONE Allow source blocks to be recognised when #+ are not first characters on the line
+   I think Carsten has recently altered the core so that #+ can have
+   preceding whitespace, at least for literal/code examples. org-babel
+   should support this.
+
+#+srcname: testing-indentation
+   #+begin_src emacs-lisp :results silent
+   (message "i'm indented")
+   #+end_src
+
+#+srcname: testing-non-indentation
+#+begin_src emacs-lisp :results silent
+(message "I'm not indented")
+#+end_src
+
+#+srcname: i-resolve-references-to-the-indented
+#+begin_src emacs-lisp :var speech=testing-indentation :results silent
+(message "I said %s" speech)
+#+end_src
+
 ** DONE are the org-babel-trim s necessary?
    at the end of e.g. org-babel-R-evaluate, org-babel-python-evaluate, but
    not org-babel-ruby-evaluate