emacs-diffs
[Top][All Lists]
Advanced

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

master 6348ca1: Make pixel-fill-region handle space regions better


From: Lars Ingebrigtsen
Subject: master 6348ca1: Make pixel-fill-region handle space regions better
Date: Wed, 1 Dec 2021 09:03:29 -0500 (EST)

branch: master
commit 6348ca1a888974e7ed8d43e5d78961c81d80b140
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Make pixel-fill-region handle space regions better
    
    * lisp/textmodes/pixel-fill.el (pixel-fill-region): Preserve the
    face on the replacement spaces.
---
 lisp/textmodes/pixel-fill.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/lisp/textmodes/pixel-fill.el b/lisp/textmodes/pixel-fill.el
index 1115ba3..86fdd3c 100644
--- a/lisp/textmodes/pixel-fill.el
+++ b/lisp/textmodes/pixel-fill.el
@@ -90,10 +90,17 @@ prefix on subsequent lines."
         (goto-char (point-min))
         ;; First replace all whitespace with space.
         (while (re-search-forward "[ \t\n]+" nil t)
-          (if (or (= (match-beginning 0) start)
-                  (= (match-end 0) end))
-              (delete-region (match-beginning 0) (match-end 0))
-            (replace-match " ")))
+          (cond
+           ((or (= (match-beginning 0) start)
+                (= (match-end 0) end))
+            (delete-region (match-beginning 0) (match-end 0)))
+           ;; If there's just a single space here, don't replace.
+           ((not (and (= (- (match-end 0) (match-beginning 0)) 1)
+                      (= (char-after (match-beginning 0)) ?\s)))
+            (replace-match
+             ;; We need to use a space that has an appropriate width.
+             (propertize " " 'face
+                         (get-text-property (match-beginning 0) 'face))))))
         (goto-char start)
         (pixel-fill--fill-line pixel-width indentation)
         (goto-char (point-max))



reply via email to

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