Browse Source

Provide control over stripping of leading/trailing blank lines from code blocks

    * org-src.el (org-src-strip-leading-and-trailing-blank-lines):
    New variable allowing prevention of automatic stripping of
    leading and trailing blank lines when exiting edit buffer.
    (org-edit-src-exit): Respect value of
    `org-src-strip-leading-and-trailing-blank-lines'
    (org-src-native-tab-command-maybe): Bind
    `org-src-strip-leading-and-trailing-blank-lines' to nil during
    this function.
Dan Davison 14 years ago
parent
commit
ca4391f9b5
1 changed files with 12 additions and 6 deletions
  1. 12 6
      lisp/org-src.el

+ 12 - 6
lisp/org-src.el

@@ -109,6 +109,10 @@ editing it with \\[org-edit-src-code].  Has no effect if
   :group 'org-edit-structure
   :group 'org-edit-structure
   :type 'integer)
   :type 'integer)
 
 
+(defvar org-src-strip-leading-and-trailing-blank-lines nil
+  "If non-nil, blank lines are removed when exiting the code edit
+buffer.")
+
 (defcustom org-edit-src-persistent-message t
 (defcustom org-edit-src-persistent-message t
   "Non-nil means show persistent exit help message while editing src examples.
   "Non-nil means show persistent exit help message while editing src examples.
 The message is shown in the header-line, which will be created in the
 The message is shown in the header-line, which will be created in the
@@ -580,11 +584,12 @@ the language, a switch telling if the content should be in a single line."
 	 (delta 0) code line col indent)
 	 (delta 0) code line col indent)
     (when allow-write-back-p
     (when allow-write-back-p
       (unless preserve-indentation (untabify (point-min) (point-max)))
       (unless preserve-indentation (untabify (point-min) (point-max)))
-      (save-excursion
-	(goto-char (point-min))
-	(if (looking-at "[ \t\n]*\n") (replace-match ""))
-	(unless macro
-	  (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match "")))))
+      (if org-src-strip-leading-and-trailing-blank-lines
+	  (save-excursion
+	    (goto-char (point-min))
+	    (if (looking-at "[ \t\n]*\n") (replace-match ""))
+	    (unless macro
+	      (if (re-search-forward "\n[ \t\n]*\\'" nil t) (replace-match ""))))))
     (setq line (if (org-bound-and-true-p org-edit-src-force-single-line)
     (setq line (if (org-bound-and-true-p org-edit-src-force-single-line)
 		   1
 		   1
 		 (org-current-line))
 		 (org-current-line))
@@ -739,7 +744,8 @@ issued in the language major mode buffer.")
 Alter code block according to effect of TAB in the language major
 Alter code block according to effect of TAB in the language major
 mode."
 mode."
   (and org-src-tab-acts-natively
   (and org-src-tab-acts-natively
-       (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB"))))
+       (let ((org-src-strip-leading-and-trailing-blank-lines nil))
+	 (org-babel-do-key-sequence-in-edit-buffer (kbd "TAB")))))
 
 
 (add-hook 'org-tab-first-hook 'org-src-native-tab-command-maybe)
 (add-hook 'org-tab-first-hook 'org-src-native-tab-command-maybe)