emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/compat db53afa3a7 18/84: Add buffer-text-pixel-size fro


From: ELPA Syncer
Subject: [elpa] externals/compat db53afa3a7 18/84: Add buffer-text-pixel-size from Emacs 29
Date: Tue, 3 Jan 2023 08:57:32 -0500 (EST)

branch: externals/compat
commit db53afa3a7fc17f826de047551ecee39b3ee493c
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>

    Add buffer-text-pixel-size from Emacs 29
---
 compat-29.el | 24 ++++++++++++++++++++++++
 compat.texi  | 20 ++++++++++++++++++++
 2 files changed, 44 insertions(+)

diff --git a/compat-29.el b/compat-29.el
index 5ec5680311..8b14b23a43 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -58,6 +58,30 @@ the properties at POSITION."
          (eq (car properties) prop))
     (cadr properties))))
 
+;;* UNTESTED
+(compat-defun buffer-text-pixel-size
+    (&optional buffer-or-name window x-limit y-limit)
+  "Return size of whole text of BUFFER-OR-NAME in WINDOW.
+BUFFER-OR-NAME must specify a live buffer or the name of a live buffer
+and defaults to the current buffer.  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 the pixel-height of all the text lines
+of the buffer specified by BUFFER-OR-NAME.
+
+The optional arguments X-LIMIT and Y-LIMIT have the same meaning as with
+`window-text-pixel-size'.
+
+Do not use this function if the buffer specified by BUFFER-OR-NAME is
+already displayed in WINDOW.  `window-text-pixel-size' is cheaper in
+that case because it does not have to temporarily show that buffer in
+WINDOW."
+  :realname compat--buffer-text-pixel-size
+  (setq buffer-or-name (or buffer-or-name (current-buffer)))
+  (setq window (or window (selected-window)))
+  (save-window-excursion
+    (set-window-buffer window buffer-or-name)
+    (window-text-pixel-size window nil nil x-limit y-limit)))
+
 ;;;; Defined in fns.c
 
 (compat-defun ntake (n list)
diff --git a/compat.texi b/compat.texi
index cdf089125c..80077f1bcb 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2359,6 +2359,26 @@ display purposes; use @code{truncate-string-to-width} or
 (@pxref{Size of Displayed Text,Size of Displayed Text,,elisp,}).
 @end defun
 
+@c copied from lispref/display.texi
+@defun buffer-text-pixel-size &optional buffer-or-name window x-limit y-limit
+This is much like @code{window-text-pixel-size}, but can be used when
+the buffer isn't shown in a window.  (@code{window-text-pixel-size} is
+faster when it is, so this function shouldn't be used in that case.)
+
+@var{buffer-or-name} must specify a live buffer or the name of a live
+buffer and defaults to the current buffer.  @var{window} must be a
+live window and defaults to the selected one; the function will
+compute the text dimensions as if @var{buffer} is displayed in
+@var{window}.  The return value is a cons of the maximum pixel-width
+of any text line and the pixel-height of all the text lines of the
+buffer specified by @var{buffer-or-name}.
+
+The optional arguments @var{x-limit} and @var{y-limit} have the same
+meaning as with @code{window-text-pixel-size}.
+
+@xref{Size of Displayed Text,,,elisp}.
+@end defun
+
 
 
 



reply via email to

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