[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 9d17e34 1/3: Preserve newlines at the end of pixel-fill-region
From: |
Lars Ingebrigtsen |
Subject: |
master 9d17e34 1/3: Preserve newlines at the end of pixel-fill-region |
Date: |
Wed, 1 Dec 2021 08:42:43 -0500 (EST) |
branch: master
commit 9d17e346fe15d7afff8a2e520522586c51225a4c
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
Preserve newlines at the end of pixel-fill-region
* lisp/textmodes/pixel-fill.el (pixel-fill-region): Preserve
newlines at the end.
---
lisp/textmodes/pixel-fill.el | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/lisp/textmodes/pixel-fill.el b/lisp/textmodes/pixel-fill.el
index 53aeb0a..1115ba3 100644
--- a/lisp/textmodes/pixel-fill.el
+++ b/lisp/textmodes/pixel-fill.el
@@ -77,20 +77,28 @@ prefix on subsequent lines."
(goto-char start)
(let ((indentation
(car (window-text-pixel-size nil (line-beginning-position)
- (point)))))
+ (point))))
+ (newline-end nil))
(when (> indentation pixel-width)
(error "The indentation (%s) is wider than the fill width (%s)"
indentation pixel-width))
(save-restriction
(narrow-to-region start end)
- (goto-char start)
+ (goto-char (point-max))
+ (when (looking-back "\n[ \t]*" (point-min))
+ (setq newline-end t))
+ (goto-char (point-min))
;; First replace all whitespace with space.
(while (re-search-forward "[ \t\n]+" nil t)
- (if (= (match-beginning 0) start)
+ (if (or (= (match-beginning 0) start)
+ (= (match-end 0) end))
(delete-region (match-beginning 0) (match-end 0))
(replace-match " ")))
(goto-char start)
- (pixel-fill--fill-line pixel-width indentation)))))
+ (pixel-fill--fill-line pixel-width indentation)
+ (goto-char (point-max))
+ (when newline-end
+ (insert "\n"))))))
(defun pixel-fill--goto-pixel (width)
(vertical-motion (cons (/ width (frame-char-width)) 0)))