瀏覽代碼

Allow code indentation to be preserved on export

This is controlled on a per-block basis with a new src block flag
-i. It can be controlled globally using the variable
org-src-preserve-indentation.
Dan Davison 15 年之前
父節點
當前提交
d9447ad7b0
共有 2 個文件被更改,包括 10 次插入6 次删除
  1. 3 1
      lisp/org-exp.el
  2. 7 5
      lisp/org-src.el

+ 3 - 1
lisp/org-exp.el

@@ -2273,6 +2273,8 @@ INDENT was the original indentation of the block."
 	    rpllbl (string-match "-r\\>" opts)
 	    keepp (string-match "-k\\>" opts)
 	    textareap (string-match "-t\\>" opts)
+	    preserve-indentp (or org-src-preserve-indentation
+				 (string-match "-i\\>" opts))
 	    cols (if (string-match "-w[ \t]+\\([0-9]+\\)" opts)
 		     (string-to-number (match-string 1 opts))
 		   80)
@@ -2285,7 +2287,7 @@ INDENT was the original indentation of the block."
 	;; we cannot use numbering or highlighting.
 	(setq num nil cont nil lang nil))
       (if keepp (setq rpllbl 'keep))
-      (setq rtn (org-remove-indentation code))
+      (setq rtn (if preserve-indentp code (org-remove-indentation code)))
       (when (string-match "^," rtn)
 	(setq rtn (with-temp-buffer
 		    (insert rtn)

+ 7 - 5
lisp/org-src.el

@@ -87,11 +87,13 @@ These are the regions where each line starts with a colon."
 
 (defcustom org-src-preserve-indentation nil
   "If non-nil, leading whitespace characters in source code
-  blocks are preserved. Otherwise, after editing with
-  \\[org-edit-src-code], the minimum (across-lines) number of
-  leading whitespace characters are removed from all lines, and
-  the code block is then uniformly indented according to the
-  value of `org-edit-src-content-indentation'."
+  blocks are preserved on export, and when switching between the
+  org buffer and the language mode edit buffer. If this variable
+  is nil then, after editing with \\[org-edit-src-code], the
+  minimum (across-lines) number of leading whitespace characters
+  are removed from all lines, and the code block is uniformly
+  indented according to the value of
+  `org-edit-src-content-indentation'."
   :group 'org-edit-structure
   :type 'boolean)