* [PATCH] Allow no stripping of blank lines from code
@ 2010-09-06 1:15 Dan Davison
2010-09-21 14:24 ` Dan Davison
0 siblings, 1 reply; 2+ messages in thread
From: Dan Davison @ 2010-09-06 1:15 UTC (permalink / raw)
To: emacs org-mode mailing list
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 <davison@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---
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Allow no stripping of blank lines from code
2010-09-06 1:15 [PATCH] Allow no stripping of blank lines from code Dan Davison
@ 2010-09-21 14:24 ` Dan Davison
0 siblings, 0 replies; 2+ messages in thread
From: Dan Davison @ 2010-09-21 14:24 UTC (permalink / raw)
To: emacs org-mode mailing list
This patch has been applied. Now, if you have set
`org-src-tab-acts-natively', then you can enter a new indented blank
line at the start/end of a src block using e.g. RET TAB or C-j TAB.
It might be nice to make the native indentation happen automatically
with C-j but I haven't looked into that.
Dan
Dan Davison <davison@stats.ox.ac.uk> writes:
> 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
>
> commit 84503c83d143b40bded8122e45ffba703c4035a1
> Author: Dan Davison <davison@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))
>
>
> _______________________________________________
> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-09-21 14:26 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-06 1:15 [PATCH] Allow no stripping of blank lines from code Dan Davison
2010-09-21 14:24 ` Dan Davison
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).