emacs-diffs
[Top][All Lists]
Advanced

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

master c22b735: (string-pixel-width): Rewrite to avoid side effects


From: Stefan Monnier
Subject: master c22b735: (string-pixel-width): Rewrite to avoid side effects
Date: Wed, 27 Oct 2021 14:03:56 -0400 (EDT)

branch: master
commit c22b735f0c6261b485f0f2afa10ec4c598550b5b
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    (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 ++-------
 src/xdisp.c               | 9 ++++++---
 2 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el
index f206081..00668d4 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)
 
diff --git a/src/xdisp.c b/src/xdisp.c
index bbe7e27..aa01db2 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10628,10 +10628,12 @@ in_display_vector_p (struct it *it)
 
 DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, 
Swindow_text_pixel_size, 0, 6, 0,
        doc: /* Return the size of the text of WINDOW's buffer in pixels.
-WINDOW must be a live window and defaults to the selected one.  The
+WINDOW can be any live window and defaults to the selected one.  The
 return value is a cons of the maximum pixel-width of any text line
 and the pixel-height of all the text lines in the accessible portion
 of buffer text.
+WINDOW can also be a buffer, in which case the selected window is used,
+and the function behaves as if that window was displaying this buffer.
 
 This function exists to allow Lisp programs to adjust the dimensions
 of WINDOW to the buffer text it needs to display.
@@ -10675,8 +10677,9 @@ include the height of any of these, if present, in the 
return value.  */)
   (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit,
    Lisp_Object y_limit, Lisp_Object mode_lines)
 {
-  struct window *w = decode_live_window (window);
-  Lisp_Object buffer = w->contents;
+  struct window *w = BUFFERP (window) ? XWINDOW (selected_window)
+                     : decode_live_window (window);
+  Lisp_Object buffer = BUFFERP (window) ? window : w->contents;
   struct buffer *b;
   struct it it;
   struct buffer *old_b = NULL;



reply via email to

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