]> git.eshelyaron.com Git - emacs.git/commitdiff
Enable sorting paragraphs when the final paragraph has no newline
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 23 Aug 2019 01:43:41 +0000 (03:43 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 23 Aug 2019 01:43:41 +0000 (03:43 +0200)
* lisp/sort.el (sort-paragraphs): Ensure that when sorting
paragraphs, the final paragraph ends with a newline (bug#21785).

lisp/sort.el

index 6ea1c44060577ac0a759937adbccc46356a93769..6ceda8e448c1cfc8a1bb1177f917fb60d3ea4a69 100644 (file)
@@ -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)