Skip to content

Commit

Permalink
compat-29: Drop broken string-pixel-width and window-pixel-width (Fix #8
Browse files Browse the repository at this point in the history
)

These functions seem to hangup from time to time on 28.2
(seagle0128/doom-modeline#601). By dropping the functions the hangup in
doom-modeline is resolved, since doom-modeline contains a runtime check for
string-pixel-width.

The compatibility function implementations do not contain any loops, this means
there is an underlying bug in `window-text-pixel-size' in 28.2 exposed by the
compatibility function. Either the compatibility function must be written in a
different form or we cannot provide them at all.
  • Loading branch information
minad committed Jan 7, 2023
1 parent 32c0bdb commit 7c17c96
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 61 deletions.
33 changes: 0 additions & 33 deletions compat-29.el
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,6 @@ the properties at POSITION."
(eq (car properties) prop))
(cadr properties))))

(compat-defun buffer-text-pixel-size ;; <UNTESTED>
(&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."
(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) ;; <OK>
Expand Down Expand Up @@ -307,17 +285,6 @@ than this function."
(end (substring string (- (length string) length)))
(t (substring string 0 length)))))

(compat-defun string-pixel-width (string) ;; <UNTESTED>
"Return the width of STRING in pixels."
(if (zerop (length string))
0
;; Keeping a work buffer around is more efficient than creating a
;; new temporary buffer.
(with-current-buffer (get-buffer-create " *string-pixel-width*")
(delete-region (point-min) (point-max))
(insert string)
(car (buffer-text-pixel-size nil nil t)))))

(compat-defmacro with-buffer-unmodified-if-unchanged (&rest body) ;; <UNTESTED>
"Like `progn', but change buffer-modified status only if buffer text changes.
If the buffer was unmodified before execution of BODY, and
Expand Down
28 changes: 0 additions & 28 deletions compat.texi
Original file line number Diff line number Diff line change
Expand Up @@ -2146,26 +2146,6 @@ 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

@c copied from lispref/strings.texi
@defun string-equal-ignore-case string1 string2
@code{string-equal-ignore-case} compares strings ignoring case
Expand Down Expand Up @@ -2240,14 +2220,6 @@ optional @code{buffer-list} argument. Optional third argument
@xref{Buffer List,,,elisp}.
@end defun

@c copied from lispref/display.texi
@defun string-pixel-width string
This is a convenience function that uses @code{window-text-pixel-size}
to compute the width of @var{string} (in pixels).

@xref{Size of Displayed Text,,,elisp}.
@end defun

@c copied from lispref/display.texi
@defun string-glyph-split string
When character compositions are in effect, sequence of characters can
Expand Down

2 comments on commit 7c17c96

@seagle0128
Copy link

@seagle0128 seagle0128 commented on 7c17c96 Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minad
Copy link
Member Author

@minad minad commented on 7c17c96 Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes of course. Therefore I removed these functions again.

Please sign in to comment.