From c22b735f0c6261b485f0f2afa10ec4c598550b5b Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 27 Oct 2021 14:03:43 -0400 Subject: (string-pixel-width): Rewrite to avoid side effects * src/xdisp.c (Fwindow_text_pixel_size): Allow `window` to be a buffer. * lisp/emacs-lisp/subr-x.el (string-pixel-width): Simplify accordingly. --- lisp/emacs-lisp/subr-x.el | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'lisp/emacs-lisp') diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index f2060814f25..00668d47439 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -446,13 +446,8 @@ is inserted before adjusting the number of empty lines." "Return the width of STRING in pixels." (with-temp-buffer (insert string) - (save-window-excursion - ;; Avoid errors if the selected window is a dedicated one, - ;; and they just want to insert a document into it. - (set-window-dedicated-p nil nil) - (set-window-buffer nil (current-buffer)) - (car (window-text-pixel-size - nil (line-beginning-position) (point)))))) + (car (window-text-pixel-size + (current-buffer) (point-min) (point))))) (provide 'subr-x) -- cgit v1.2.3