diff options
author | Eli Zaretskii <eliz@gnu.org> | 2024-02-03 06:49:53 -0500 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2024-02-03 06:49:53 -0500 |
commit | 25bf8d3cdc6ce31e97b124a27be8c550d5525a55 (patch) | |
tree | 711622e955c85c3d8b1fddf384a4809d27509c80 /lisp/textmodes | |
parent | 8080c7895b8613664754243bc88fa56cd5636360 (diff) | |
parent | b91f0ee2fcc52b6ef2d747c5fc7f37573adc7ca5 (diff) | |
download | emacs-25bf8d3cdc6ce31e97b124a27be8c550d5525a55.tar.gz |
Merge from origin/emacs-29
b91f0ee2fcc ; Fix last change
2f69353e4a7 Fix incompatibility with tree-sitter-javascript >= 0.20.2
d49124fc14b Avoid signaling errors from 'pixel-fill-region'
a3987127618 eglot: Add nushell language server
5f56bc1cdfc eglot: Add php-ts-mode to eglot-server-programs
c14c978e3b1 Support kotlin-ts-mode in Eglot
Diffstat (limited to 'lisp/textmodes')
-rw-r--r-- | lisp/textmodes/pixel-fill.el | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/lisp/textmodes/pixel-fill.el b/lisp/textmodes/pixel-fill.el index 25c0b46cee9..d26eaec2111 100644 --- a/lisp/textmodes/pixel-fill.el +++ b/lisp/textmodes/pixel-fill.el @@ -73,39 +73,41 @@ lines that are visually wider than PIXEL-WIDTH. If START isn't at the start of a line, the horizontal position of START, converted to pixel units, will be used as the indentation prefix on subsequent lines." - (save-excursion - (goto-char start) - (let ((indentation - (car (window-text-pixel-size nil (line-beginning-position) - (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 (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) - (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)) - (when newline-end - (insert "\n")))))) + (save-window-excursion + (set-window-buffer nil (current-buffer)) + (save-excursion + (goto-char start) + (let ((indentation + (car (window-text-pixel-size nil (line-beginning-position) + (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 (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) + (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)) + (when newline-end + (insert "\n"))))))) (defun pixel-fill--goto-pixel (width) (vertical-motion (cons (/ width (frame-char-width)) 0))) |