diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-12-01 15:03:16 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-12-01 15:03:24 +0100 |
commit | 6348ca1a888974e7ed8d43e5d78961c81d80b140 (patch) | |
tree | 487af728c552bf7182dcb3f62ac83de0c046e9c0 /lisp | |
parent | ddaedb1910cd9a6ea394754b0e98502170316e23 (diff) | |
download | emacs-6348ca1a888974e7ed8d43e5d78961c81d80b140.tar.gz emacs-6348ca1a888974e7ed8d43e5d78961c81d80b140.tar.bz2 emacs-6348ca1a888974e7ed8d43e5d78961c81d80b140.zip |
Make pixel-fill-region handle space regions better
* lisp/textmodes/pixel-fill.el (pixel-fill-region): Preserve the
face on the replacement spaces.
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/textmodes/pixel-fill.el | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lisp/textmodes/pixel-fill.el b/lisp/textmodes/pixel-fill.el index 1115ba303ea..86fdd3c2ff4 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)) |