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

* Re: [PATCH] Preserve trailing blank lines
  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
  0 siblings, 1 reply; 9+ messages in thread
From: Carsten Dominik @ 2011-01-08 18:02 UTC (permalink / raw)
  To: Jason Dunsmore; +Cc: emacs-orgmode


On Jan 5, 2011, at 2:24 AM, Jason Dunsmore wrote:

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

These commands treat empty lines as belonging to the entry
below the empty line - which is, I think, the right convention here.

- Carsten


>  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
>
> _______________________________________________
> 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] 9+ messages in thread

* Re: [PATCH] Preserve trailing blank lines
  2011-01-08 18:02 ` Carsten Dominik
@ 2011-01-10 15:58   ` Jason Dunsmore
  2011-01-17 23:13     ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Dunsmore @ 2011-01-10 15:58 UTC (permalink / raw)
  To: Carsten Dominik; +Cc: emacs-orgmode

Carsten Dominik <carsten.dominik@gmail.com> writes:

> On Jan 5, 2011, at 2:24 AM, Jason Dunsmore wrote:
>
>> 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.
>
> These commands treat empty lines as belonging to the entry
> below the empty line - which is, I think, the right convention here.

I now understand this is a formatting convention issue.  Here is an
updated patch that looks at the setting for `heading' in the variable
org-blank-before-new-entry:

diff --git a/lisp/org.el b/lisp/org.el
index 98c85d0..ee3f873 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18477,7 +18477,9 @@ Taken from `count' in cl-seq.el with all keyword
argumen
   "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 (cdr (assoc 'heading org-blank-before-new-entry))
+       (skip-chars-backward " \t\n\r")
+      (forward-line -1))
     (beginning-of-line 2)
     (goto-char (min (point) pos))
     (count-lines (point) pos)))

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

* Re: [PATCH] Preserve trailing blank lines
  2011-01-10 15:58   ` Jason Dunsmore
@ 2011-01-17 23:13     ` Bastien
  2011-01-26 18:52       ` Jason Dunsmore
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2011-01-17 23:13 UTC (permalink / raw)
  To: Jason Dunsmore; +Cc: emacs-orgmode, Carsten Dominik

Jason Dunsmore <jason@dunsmor.com> writes:

> I now understand this is a formatting convention issue.  

I'm trying to figure out when this patch is useful.  I understand this
is when `org-blank-before-new-entry' doesn't set heading to t or auto, 
but I don't understand what it the difference the patch introduces then.

Could you send a _visual_ example, with useless empty lines that you
want to get rid off when org-metaup etc ?

Thanks!

-- 
 Bastien

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

* Re: [PATCH] Preserve trailing blank lines
  2011-01-17 23:13     ` Bastien
@ 2011-01-26 18:52       ` Jason Dunsmore
  2011-02-07  8:17         ` Bastien
  0 siblings, 1 reply; 9+ messages in thread
From: Jason Dunsmore @ 2011-01-26 18:52 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Carsten Dominik

Bastien <bastien.guerry@wikimedia.fr> writes:

> Jason Dunsmore <jason@dunsmor.com> writes:
>
>> I now understand this is a formatting convention issue.  
>
> I'm trying to figure out when this patch is useful.  I understand this
> is when `org-blank-before-new-entry' doesn't set heading to t or auto, 
> but I don't understand what it the difference the patch introduces then.
>
> Could you send a _visual_ example, with useless empty lines that you
> want to get rid off when org-metaup etc ?

Convention 1: Newline above headings

This seems to be used more often when the body does not have delimiting
newlines.

Configuration:

--8<---------------cut here---------------start------------->8---
(setq org-blank-before-new-entry '((heading . t)
                                   (plain-list-item . t)))
--8<---------------cut here---------------end--------------->8---

Org example:

--8<---------------cut here---------------start------------->8---

* Section

** Subsection 1
Body

** Subsection 2
Body
--8<---------------cut here---------------end--------------->8---


Convention 2: Newline after bodies

This seems to be used more often when the body does have delimiting
newlines.

Configuration:

--8<---------------cut here---------------start------------->8---
(setq org-blank-before-new-entry '((heading . nil)
                                   (plain-list-item . nil)))
--8<---------------cut here---------------end--------------->8---

Org example:

--8<---------------cut here---------------start------------->8---
* Section
** Subsection 1

Body

** Subsection 2

Body

--8<---------------cut here---------------end--------------->8---

I've seen both conventions in use on Worg and in Org-mode tutorials.

I just tested these configurations and Org examples out with the patch
and it seems to work well.  I've been using the patch on my systems for
a while now and haven't noticed any bad side-effects.

Let me know if you need any other information.

Regards,
Jason

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

* Re: [PATCH] Preserve trailing blank lines
  2011-01-26 18:52       ` Jason Dunsmore
@ 2011-02-07  8:17         ` Bastien
  2011-02-15 16:31           ` Jason Dunsmore
  0 siblings, 1 reply; 9+ messages in thread
From: Bastien @ 2011-02-07  8:17 UTC (permalink / raw)
  To: Jason Dunsmore; +Cc: emacs-orgmode, Carsten Dominik

Hi Jason,

Jason Dunsmore <emacs-orgmode@dunsmor.com> writes:

> Convention 1: Newline above headings
> Convention 2: Newline after bodies
>
> I just tested these configurations and Org examples out with the patch
> and it seems to work well.  I've been using the patch on my systems for
> a while now and haven't noticed any bad side-effects.

I'm back to this patch -- thanks for the clear explanations.

However, with your patch, I get a weird behavior.

Config:

,----
| (setq org-blank-before-new-entry '((heading . nil)
|                                    (plain-list-item . nil)))
`----

Test file:

,----
| * Section
| 
| ** Subsection 1
| Body
| 
| ** Subsection 2
| Body
`----

Trying to move Subsection 1 down (with org-metadown):

,----
| * Section
| Body              <<<<<< ??
| 
| ** Subsection 2
| 
| ** Subsection 1
| Body
`----

Are you able to reproduce this?  

-- 
 Bastien

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

* Re: [PATCH] Preserve trailing blank lines
  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
  0 siblings, 2 replies; 9+ messages in thread
From: Jason Dunsmore @ 2011-02-15 16:31 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Carsten Dominik

Bastien <bastien.guerry@wikimedia.fr> writes:

> However, with your patch, I get a weird behavior.
>
> Config:
>
> ,----
> | (setq org-blank-before-new-entry '((heading . nil)
> |                                    (plain-list-item . nil)))
> `----
>
> Test file:
>
> ,----
> | * Section
> | 
> | ** Subsection 1
> | Body
> | 
> | ** Subsection 2
> | Body
> `----
>
> Trying to move Subsection 1 down (with org-metadown):
>
> ,----
> | * Section
> | Body              <<<<<< ??
> | 
> | ** Subsection 2
> | 
> | ** Subsection 1
> | Body
> `----
>
> Are you able to reproduce this?  

I finally had a chance to test this out with the latest Org from git and
a vanilla Emacs config, and I was unable to reproduce the behavior you
saw.  Here is what I did:


$ git clone git://orgmode.org/org-mode.git

$ emacs23 -Q &

(Edit org.el to re-introduce patch.)

$ cd org-mode/

$ git diff
diff --git a/lisp/org.el b/lisp/org.el
index 164081c..4329def 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -18507,10 +18507,10 @@ Taken from `count' in cl-seq.el with all keyword argum
   "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 (cdr (assoc 'heading org-blank-before-new-entry))
-    ;;    (skip-chars-backward " \t\n\r")
-    ;;   (forward-line -1))
+    ;;(skip-chars-backward " \t\n\r")
+    (if (cdr (assoc 'heading org-blank-before-new-entry))
+       (skip-chars-backward " \t\n\r")
+      (forward-line -1))
     (beginning-of-line 2)
     (goto-char (min (point) pos))
     (count-lines (point) pos)))


Then I evaluated the following in Emacs:


(delete "/usr/share/emacs/23.2/lisp/org/" load-path)
(add-to-list 'load-path "~/tmp/org-mode/lisp")
(require 'org-install)
(setq org-blank-before-new-entry '((heading . nil)
   (plain-list-item . nil)))


You can see what happened on my screen with the following:


wget http://98.129.169.48/tmp/emacs-testing.time
wget http://98.129.169.48/tmp/emacs-testing.script
scriptreplay emacs-testing.time emacs-testing.script


Would you mind testing it out again?

Regards,
Jason

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

* [Accepted] Preserve trailing blank lines
  2011-02-15 16:31           ` Jason Dunsmore
@ 2011-03-09 10:07             ` Bastien Guerry
  2011-03-09 10:07             ` [PATCH] " Bastien
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien Guerry @ 2011-03-09 10:07 UTC (permalink / raw)
  To: emacs-orgmode

Patch 617 (http://patchwork.newartisans.com/patch/617/) is now "Accepted".

Maintainer comment: none

This relates to the following submission:

http://mid.gmane.org/%3C878vxhgsyy.fsf%40riotblast.dunsmor.com%3E

Here is the original message containing the patch:

> Content-Type: text/plain; charset="utf-8"
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> Subject: [Orgmode] Preserve trailing blank lines
> Date: Tue, 15 Feb 2011 21:31:17 -0000
> From: Jason Dunsmore <emacs-orgmode@deathroller.dunsmor.com>
> X-Patchwork-Id: 617
> Message-Id: <878vxhgsyy.fsf@riotblast.dunsmor.com>
> To: Bastien <bastien.guerry@wikimedia.fr>
> Cc: emacs-orgmode@gnu.org, Carsten Dominik <carsten.dominik@gmail.com>
> 
> Bastien <bastien.guerry@wikimedia.fr> writes:
> 
> > However, with your patch, I get a weird behavior.
> >
> > Config:
> >
> > ,----
> > | (setq org-blank-before-new-entry '((heading . nil)
> > |                                    (plain-list-item . nil)))
> > `----
> >
> > Test file:
> >
> > ,----
> > | * Section
> > | 
> > | ** Subsection 1
> > | Body
> > | 
> > | ** Subsection 2
> > | Body
> > `----
> >
> > Trying to move Subsection 1 down (with org-metadown):
> >
> > ,----
> > | * Section
> > | Body              <<<<<< ??
> > | 
> > | ** Subsection 2
> > | 
> > | ** Subsection 1
> > | Body
> > `----
> >
> > Are you able to reproduce this?  
> 
> I finally had a chance to test this out with the latest Org from git and
> a vanilla Emacs config, and I was unable to reproduce the behavior you
> saw.  Here is what I did:
> 
> 
> $ git clone git://orgmode.org/org-mode.git
> 
> $ emacs23 -Q &
> 
> (Edit org.el to re-introduce patch.)
> 
> $ cd org-mode/
> 
> $ git diff
> 
> 
> Then I evaluated the following in Emacs:
> 
> 
> (delete "/usr/share/emacs/23.2/lisp/org/" load-path)
> (add-to-list 'load-path "~/tmp/org-mode/lisp")
> (require 'org-install)
> (setq org-blank-before-new-entry '((heading . nil)
>    (plain-list-item . nil)))
> 
> 
> You can see what happened on my screen with the following:
> 
> 
> wget http://98.129.169.48/tmp/emacs-testing.time
> wget http://98.129.169.48/tmp/emacs-testing.script
> scriptreplay emacs-testing.time emacs-testing.script
> 
> 
> Would you mind testing it out again?
> 
> Regards,
> Jason
> 
> 
> diff --git a/lisp/org.el b/lisp/org.el
> index 164081c..4329def 100644
> --- a/lisp/org.el
> +++ b/lisp/org.el
> @@ -18507,10 +18507,10 @@ Taken from `count' in cl-seq.el with all keyword argum
>    "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 (cdr (assoc 'heading org-blank-before-new-entry))
> -    ;;    (skip-chars-backward " \t\n\r")
> -    ;;   (forward-line -1))
> +    ;;(skip-chars-backward " \t\n\r")
> +    (if (cdr (assoc 'heading org-blank-before-new-entry))
> +       (skip-chars-backward " \t\n\r")
> +      (forward-line -1))
>      (beginning-of-line 2)
>      (goto-char (min (point) pos))
>      (count-lines (point) pos)))
> 

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

* Re: [PATCH] Preserve trailing blank lines
  2011-02-15 16:31           ` Jason Dunsmore
  2011-03-09 10:07             ` [Accepted] " Bastien Guerry
@ 2011-03-09 10:07             ` Bastien
  1 sibling, 0 replies; 9+ messages in thread
From: Bastien @ 2011-03-09 10:07 UTC (permalink / raw)
  To: Jason Dunsmore; +Cc: emacs-orgmode, Carsten Dominik

Hi Jason,

I finally had a chance to better understand what your patch does and
fix.  I've applied it now -- thanks for it and for your patience!

-- 
 Bastien

^ permalink raw reply	[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).