Now that we can issue TAB in a code block and have it act according to language [see org-src-tab-acts-natively], the following is a minor frustration: if you try to insert a blank line at the beginning/end of the block (perhaps to introduce a new first/last line), then on TAB it disappears because org-edit-src-exit strips leading and trailing blank lines. This patch introduces a variable that turns off that behaviour.
The default is still to strip lines. I am slightly wondering what the reason for that default was. I can see it could be useful for artist-mode, but for genuine code blocks should the default be to give the user responsibility for curating leading/trailing blank lines? Dan --8<---------------cut here---------------start------------->8--- commit 84503c83d143b40bded8122e45ffba703c4035a1 Author: Dan Davison <davi...@stats.ox.ac.uk> Date: Sun Sep 5 18:55:06 2010 -0400 Optionally prevent stripping of blank lines from code blocks * org-src.el (org-edit-src-exit): Only strip leading and trailing blank lines if `org-src-strip-leading-and-trailing-blank-lines' is non-nil (org-src-strip-leading-and-trailing-blank-lines): New variable diff --git a/lisp/org-src.el b/lisp/org-src.el index f11eec2..d877925 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -109,6 +109,12 @@ editing it with \\[org-edit-src-code]. Has no effect if :group 'org-edit-structure :type 'integer) +(defcustom org-src-strip-leading-and-trailing-blank-lines t + "If non-nil, blank lines are removed when exiting the code edit +buffer." + :group 'org-edit-structure + :type 'boolean) + (defcustom org-edit-src-persistent-message t "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 @@ -577,11 +583,12 @@ the language, a switch telling if the content should be in a single line." (delta 0) code line col indent) (when allow-write-back-p (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) 1 (org-current-line)) --8<---------------cut here---------------end--------------->8--- _______________________________________________ Emacs-orgmode mailing list Please use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode