emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master b4d3a88: Enable sorting paragraphs when the final p


From: Lars Ingebrigtsen
Subject: [Emacs-diffs] master b4d3a88: Enable sorting paragraphs when the final paragraph has no newline
Date: Thu, 22 Aug 2019 21:43:49 -0400 (EDT)

branch: master
commit b4d3a882a8423e81c418fc56b7a9677f5582fcc7
Author: Lars Ingebrigtsen <address@hidden>
Commit: Lars Ingebrigtsen <address@hidden>

    Enable sorting paragraphs when the final paragraph has no newline
    
    * lisp/sort.el (sort-paragraphs): Ensure that when sorting
    paragraphs, the final paragraph ends with a newline (bug#21785).
---
 lisp/sort.el | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/lisp/sort.el b/lisp/sort.el
index 6ea1c44..6ceda8e 100644
--- a/lisp/sort.el
+++ b/lisp/sort.el
@@ -225,11 +225,17 @@ the sort order."
       (narrow-to-region beg end)
       (goto-char (point-min))
       (sort-subr reverse
-                (function
-                 (lambda ()
-                   (while (and (not (eobp)) (looking-at paragraph-separate))
-                     (forward-line 1))))
-                'forward-paragraph))))
+                (lambda ()
+                  (while (and (not (eobp)) (looking-at paragraph-separate))
+                    (forward-line 1)))
+                (lambda ()
+                   (forward-paragraph)
+                   ;; If the buffer doesn't end with a newline, add a
+                   ;; newline to avoid having paragraphs being
+                   ;; concatenated after sorting.
+                   (when (and (eobp)
+                              (not (bolp)))
+                     (insert "\n")))))))
 
 ;;;###autoload
 (defun sort-pages (reverse beg end)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]