Browse Source

Merge commit 'babel/ded-indent'

Carsten Dominik 15 năm trước cách đây
mục cha
commit
bf46f6be79
3 tập tin đã thay đổi với 20 bổ sung13 xóa
  1. 10 7
      lisp/org-exp-blocks.el
  2. 3 1
      lisp/org-exp.el
  3. 7 5
      lisp/org-src.el

+ 10 - 7
lisp/org-exp-blocks.el

@@ -166,7 +166,7 @@ specified in BLOCKS which default to the value of
   (save-window-excursion
     (let ((case-fold-search t)
 	  (types '())
-	  indentation type func start)
+	  indentation type func start body headers preserve-indent)
       (flet ((interblock (start end)
 			 (mapcar (lambda (pair) (funcall (second pair) start end))
 				 org-export-interblocks)))
@@ -176,17 +176,20 @@ specified in BLOCKS which default to the value of
 		"^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)[ \t]*\\(.*\\)?[\r\n]\\([^\000]*?\\)[\r\n][ \t]*#\\+end_\\S-+.*" nil t)
           (setq indentation (length (match-string 1)))
 	  (setq type (intern (match-string 2)))
+	  (setq headers (save-match-data (split-string (match-string 3) "[ \t]")))
+	  (setq body (match-string 4))
+	  (setq preserve-indent (or org-src-preserve-indentation (member "-i" headers)))
+	  (unless preserve-indent
+	    (setq body (save-match-data (org-remove-indentation body))))
 	  (unless (memq type types) (setq types (cons type types)))
 	  (save-match-data (interblock start (match-beginning 0)))
 	  (if (setq func (cadr (assoc type org-export-blocks)))
 	      (progn
                 (replace-match (save-match-data
-                                 (if (memq type org-export-blocks-witheld)
-                                     ""
-                                   (apply func (save-match-data (org-remove-indentation (match-string 4)))
-                                          (split-string (match-string 3) " ")))) t t)
-                ;; indent block
-                (indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))
+                                 (if (memq type org-export-blocks-witheld) ""
+                                   (apply func body headers))) t t)
+                (unless preserve-indent
+		  (indent-code-rigidly (match-beginning 0) (match-end 0) indentation))))
 	  (setq start (match-end 0)))
 	(interblock start (point-max))))))
 

+ 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)