66; ; Maintainer: Shen, Jen-Chieh <jcs090218@gmail.com>
77; ; URL: https://github.com/jcs-emacs/jcs-modeline
88; ; Version: 0.1.1
9- ; ; Package-Requires: ((emacs "28 .1") (moody "0.7.1") (minions "0.3.7") (elenv "0.1.0") (nerd-icons "0.0.1") (reveal-in-folder "0.1.2"))
9+ ; ; Package-Requires: ((emacs "29 .1") (moody "0.7.1") (minions "0.3.7") (elenv "0.1.0") (nerd-icons "0.0.1") (reveal-in-folder "0.1.2"))
1010; ; Keywords: faces mode-line
1111
1212; ; This file is not part of GNU Emacs.
8484; ; (@* "Externals" )
8585; ;
8686
87- (declare-function string-pixel-width " subr-x.el" ) ; TODO: remove this after 29.1
88- (declare-function shr-string-pixel-width " shr.el" ) ; TODO: remove this after 29.1
89-
9087(defvar buffer-undo-tree )
9188(defvar undo-tree-visualizer-buffer-name )
9289(defvar undo-tree-visualizer-parent-buffer )
171168 (puthash char result jcs-modeline--char-displayable-cache)
172169 (and result str-or-char)))
173170
174- ; ; TODO: Use function `string-pixel-width' after 29.1
175- (defun jcs-modeline--string-pixel-width (str )
176- " Return the width of STR in pixels."
177- (if (fboundp #'string-pixel-width )
178- (string-pixel-width str)
179- (require 'shr )
180- (shr-string-pixel-width str)))
181-
182- (defun jcs-modeline--str-len (str )
171+ (defun jcs-modeline--str-width (str )
183172 " Calculate STR in pixel width."
184173 (let ((width (frame-char-width ))
185- (len (jcs-modeline-- string-pixel-width str)))
174+ (len (string-pixel-width str)))
186175 (+ (/ len width)
187176 (if (zerop (% len width)) 0 1 )))) ; add one if exceeed
188177
@@ -235,7 +224,7 @@ Position argument ARG0."
235224 (let* ((item (nth (if is-left left-index right-index)
236225 (if is-left jcs-modeline-left right-list)))
237226 (format (format-mode-line item))
238- (width (jcs-modeline--str-len format))
227+ (width (jcs-modeline--str-width format))
239228 (new-width (+ current-width width)))
240229 ; ; Can the new item added to the list?
241230 (when (<= new-width (window-width )) ; can be displayed properly!
@@ -262,8 +251,8 @@ Position argument ARG0."
262251
263252(defun jcs-modeline-render (left right )
264253 " Render mode line with LEFT and RIGHT alignment."
265- (let* ((len-left (jcs-modeline--str-len (format-mode-line left)))
266- (len-right (jcs-modeline--str-len (format-mode-line right)))
254+ (let* ((len-left (jcs-modeline--str-width (format-mode-line left)))
255+ (len-right (jcs-modeline--str-width (format-mode-line right)))
267256 (available-width (- (window-width ) (+ len-left len-right)))
268257 (available-width (+ available-width (jcs-modeline--adjust-pad))))
269258 (append left
0 commit comments