Skip to content

Commit

Permalink
[Compatibility] Define string-pixel-width function for <29.
Browse files Browse the repository at this point in the history
string-pixel-width is introduced in 29.
Close #546.
  • Loading branch information
seagle0128 committed Jun 28, 2022
1 parent c78d45b commit 2ff72d7
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions doom-modeline-core.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@

(require 'all-the-icons nil t)


;;
;; Compatibility
;;

;; `string-pixel-width' is introduced in 29
(unless (fboundp 'string-pixel-width)
(defun string-pixel-width (string)
"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))))))


;;
;; Externals
Expand Down

0 comments on commit 2ff72d7

Please sign in to comment.