Fix 'string-pixel-width' to not reset 'display-line-numbers'

* lisp/emacs-lisp/subr-x.el (string-pixel-width): Use the
'display-line-numbers-disable' property instead of setting the
variable 'display-line-numbers', to avoid global effects.
(Bug#73005)
This commit is contained in:
David Ponce 2024-11-03 22:56:10 +01:00 committed by Eli Zaretskii
parent 17f4f2dec9
commit 8ee14643d2

View file

@ -400,12 +400,6 @@ substring that does not include newlines."
;; Keeping a work buffer around is more efficient than creating a
;; new temporary buffer.
(with-work-buffer
;; If `display-line-numbers' is enabled in internal
;; buffers (e.g. globally), it breaks width calculation
;; (bug#59311). Disable `line-prefix' and `wrap-prefix',
;; for the same reason.
(setq display-line-numbers nil
line-prefix nil wrap-prefix nil)
(if buffer
(setq-local face-remapping-alist
(with-current-buffer buffer
@ -414,10 +408,17 @@ substring that does not include newlines."
;; Avoid deactivating the region as side effect.
(let (deactivate-mark)
(insert string))
;; If `display-line-numbers' is enabled in internal
;; buffers (e.g. globally), it breaks width calculation
;; (bug#59311). Disable `line-prefix' and `wrap-prefix',
;; for the same reason.
(add-text-properties
(point-min) (point-max) '(display-line-numbers-disable t))
;; Prefer `remove-text-properties' to `propertize' to avoid
;; creating a new string on each call.
(remove-text-properties
(point-min) (point-max) '(line-prefix nil wrap-prefix nil))
(setq line-prefix nil wrap-prefix nil)
(car (buffer-text-pixel-size nil nil t)))))
;;;###autoload