diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-12-01 06:18:12 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-12-01 14:41:42 +0100 |
commit | 9d17e346fe15d7afff8a2e520522586c51225a4c (patch) | |
tree | 818809193e2da7dcd28b84431d1f11154403f223 /lisp/textmodes/pixel-fill.el | |
parent | bab29694047d060bb58ff88e1a4d2cc7ef05df2a (diff) | |
download | emacs-9d17e346fe15d7afff8a2e520522586c51225a4c.tar.gz emacs-9d17e346fe15d7afff8a2e520522586c51225a4c.tar.bz2 emacs-9d17e346fe15d7afff8a2e520522586c51225a4c.zip |
Preserve newlines at the end of pixel-fill-region
* lisp/textmodes/pixel-fill.el (pixel-fill-region): Preserve
newlines at the end.
Diffstat (limited to 'lisp/textmodes/pixel-fill.el')
-rw-r--r-- | lisp/textmodes/pixel-fill.el | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lisp/textmodes/pixel-fill.el b/lisp/textmodes/pixel-fill.el index 53aeb0a2d6d..1115ba303ea 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))) |