emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 92a8dec: Give `window-text-pixel-size' optional BUF


From: Paul Eggert
Subject: [Emacs-diffs] master 92a8dec: Give `window-text-pixel-size' optional BUFFER argument.
Date: Sun, 01 Feb 2015 20:06:36 +0000

branch: master
commit 92a8dec54ed3314ca06f40cd0c226c4267a160e8
Author: Martin Rudalics <address@hidden>
Commit: Paul Eggert <address@hidden>

    Give `window-text-pixel-size' optional BUFFER argument.
    
    [This reinstalls commit 1d1162479caf1fdf48564f1486fa84e3cdacaa9b,
    which I mistakenly reverted.  --eggert]
    * xdisp.c (Fwindow_text_pixel_size): Add optional argument BUFFER.
    * display.texi (Size of Displayed Text): Describe optional
    argument BUFFER of `window-text-pixel-size'.
---
 doc/lispref/ChangeLog    |    5 +++++
 doc/lispref/display.texi |    9 ++++++++-
 src/ChangeLog            |    4 ++++
 src/xdisp.c              |   44 +++++++++++++++++++++++++++++---------------
 4 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 2cde2fb..aa4d320 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
+2015-02-01  Martin Rudalics  <address@hidden>
+
+       * display.texi (Size of Displayed Text): Describe optional
+       argument BUFFER of `window-text-pixel-size'.
+
 2015-01-28  Eli Zaretskii  <address@hidden>
 
        * searching.texi (Regexp Search): Add a cross-reference to "Syntax
diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi
index b09b82a..10b17a3 100644
--- a/doc/lispref/display.texi
+++ b/doc/lispref/display.texi
@@ -1880,7 +1880,7 @@ displayed in a given window.  This function is used by
 @code{fit-frame-to-buffer} (@pxref{Size and Position}) to make a window
 exactly as large as the text it contains.
 
address@hidden window-text-pixel-size &optional window from to x-limit y-limit 
mode-and-header-line
address@hidden window-text-pixel-size &optional window from to x-limit y-limit 
mode-and-header-line buffer
 This function returns the size of the text of @var{window}'s buffer in
 pixels.  @var{window} must be a live window and defaults to the selected
 one.  The return value is a cons of the maximum pixel-width of any text
@@ -1919,6 +1919,13 @@ means to not include the height of the mode- or 
header-line of
 @code{mode-line} or @code{header-line}, include only the height of that
 line, if present, in the return value.  If it is @code{t}, include the
 height of both, if present, in the return value.
+
+The optional argument @var{buffer} allows to specify an alternate buffer
+whose text size will be calculated.  If @var{buffer} is @code{nil} or
+omitted, then operate on the buffer of @var{window}.  If it is @code{t},
+then operate on the current buffer as if it were displayed in
address@hidden  If it specifies a live buffer, then operate on that
+buffer as if it were displayed in @var{window}.
 @end defun
 
 
diff --git a/src/ChangeLog b/src/ChangeLog
index 9e564ea..d3f667e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
+2015-02-01  Martin Rudalics  <address@hidden>
+
+       * xdisp.c (Fwindow_text_pixel_size): Add optional argument BUFFER.
+
 2015-01-31  Eli Zaretskii  <address@hidden>
 
        * coding.c (raw_text_coding_system_p): New function.
diff --git a/src/xdisp.c b/src/xdisp.c
index 68c0fa5..8f6695a 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -9650,7 +9650,7 @@ in_display_vector_p (struct it *it)
          && it->dpvec + it->current.dpvec_index != it->dpend);
 }
 
-DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, 
Swindow_text_pixel_size, 0, 6, 0,
+DEFUN ("window-text-pixel-size", Fwindow_text_pixel_size, 
Swindow_text_pixel_size, 0, 7, 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
 return value is a cons of the maximum pixel-width of any text line and
@@ -9683,28 +9683,42 @@ Optional argument MODE-AND-HEADER-LINE nil or omitted 
means do not
 include the height of the mode- or header-line of WINDOW in the return
 value.  If it is either the symbol `mode-line' or `header-line', include
 only the height of that line, if present, in the return value.  If t,
-include the height of both, 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_and_header_line)
+include the height of both, if present, in the return value.
+
+Optional argument BUFFER nil means to return the size of the text of
+WINDOW's buffer.  BUFFER t means to return the size of the text of the
+current buffer as if it were displayed in WINDOW.  Else BUFFER has to
+specify a live buffer and this function returns the size of the text of
+BUFFER as if it were displayed in WINDOW.  */)
+  (Lisp_Object window, Lisp_Object from, Lisp_Object to, Lisp_Object x_limit,
+   Lisp_Object y_limit, Lisp_Object mode_and_header_line, Lisp_Object buffer)
 {
   struct window *w = decode_live_window (window);
-  Lisp_Object buf;
   struct buffer *b;
   struct it it;
-  struct buffer *old_buffer = NULL;
+  struct buffer *old_b = NULL;
   ptrdiff_t start, end, pos;
   struct text_pos startp;
   void *itdata = NULL;
   int c, max_y = -1, x = 0, y = 0;
 
-  buf = w->contents;
-  CHECK_BUFFER (buf);
-  b = XBUFFER (buf);
-
-  if (b != current_buffer)
+  if (EQ (buffer, Qt))
+    b = current_buffer;
+  else
     {
-      old_buffer = current_buffer;
-      set_buffer_internal (b);
+      if (NILP (buffer))
+       buffer = w->contents;
+
+      CHECK_BUFFER (buffer);
+      if (!BUFFER_LIVE_P (XBUFFER (buffer)))
+       error ("Not a live buffer");
+
+      b = XBUFFER (buffer);
+      if (b != current_buffer)
+       {
+         old_b = current_buffer;
+         set_buffer_internal (b);
+       }
     }
 
   if (NILP (from))
@@ -9780,8 +9794,8 @@ include the height of both, if present, in the return 
value.  */)
 
   bidi_unshelve_cache (itdata, 0);
 
-  if (old_buffer)
-    set_buffer_internal (old_buffer);
+  if (old_b)
+    set_buffer_internal (old_b);
 
   return Fcons (make_number (x), make_number (y));
 }



reply via email to

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