emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Preserve trailing blank lines
@ 2011-01-05  1:24 Jason Dunsmore
  2011-01-08 18:02 ` Carsten Dominik
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Dunsmore @ 2011-01-05  1:24 UTC (permalink / raw)
  To: emacs-orgmode

I like to leave a blank line at the end of items that have bodies, but I
found functions like org-metaup, org-metadown, and org-refile were
leaving that blank line behind.  Here's a patch to fix that:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org.el b/lisp/org.el
index 5eb0bc8..e3d71b7 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18448,7 +18448,7 @@ Taken from `count' in cl-seq.el with all keyword arguments
   "Move backwards over whitespace, to the beginning of the first empty line.
 Returns the number of empty lines passed."
   (let ((pos (point)))
-    (skip-chars-backward " \t\n\r")
+    (forward-line -1)
     (beginning-of-line 2)
     (goto-char (min (point) pos))
     (count-lines (point) pos)))
--8<---------------cut here---------------end--------------->8---

I can't think of a reason you would want to leave trailing blank lines
behind, but in case some people rely on that behavior, here's an
alternate patch that creates an option called
org-preserve-trailing-blank-lines:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/org.el b/lisp/org.el
index 5eb0bc8..e90798c 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1098,6 +1098,11 @@ breaking the list structure."
                        (const :tag "Always" t)
                        (const :tag "Auto" auto)))))
 
+(defcustom org-preserve-trailing-blank-lines t
+  "Non-nil means preserve blank lines at the end of an item."
+  :group 'org-edit-structure
+  :type 'boolean)
+
 (defcustom org-insert-heading-hook nil
   "Hook being run after inserting a new heading."
   :group 'org-edit-structure
@@ -18448,7 +18453,9 @@ Taken from `count' in cl-seq.el with all keyword arguments
   "Move backwards over whitespace, to the beginning of the first empty line.
 Returns the number of empty lines passed."
   (let ((pos (point)))
-    (skip-chars-backward " \t\n\r")
+    (if org-preserve-trailing-blank-lines
+       (forward-line -1)
+      (skip-chars-backward " \t\n\r"))
     (beginning-of-line 2)
     (goto-char (min (point) pos))
     (count-lines (point) pos)))
--8<---------------cut here---------------end--------------->8---

If this is accepted, perhaps the function org-back-over-empty-lines
should be renamed to org-back-over-lines.

Regards,
Jason

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2011-03-09 10:08 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-05  1:24 [PATCH] Preserve trailing blank lines Jason Dunsmore
2011-01-08 18:02 ` Carsten Dominik
2011-01-10 15:58   ` Jason Dunsmore
2011-01-17 23:13     ` Bastien
2011-01-26 18:52       ` Jason Dunsmore
2011-02-07  8:17         ` Bastien
2011-02-15 16:31           ` Jason Dunsmore
2011-03-09 10:07             ` [Accepted] " Bastien Guerry
2011-03-09 10:07             ` [PATCH] " Bastien

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