Skip to content

Commit 4fa8190

Browse files
committed
fix str width
1 parent faa775f commit 4fa8190

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ jobs:
2020
matrix:
2121
os: [ubuntu-latest, macos-latest, windows-latest]
2222
emacs-version:
23-
- 28.2
2423
- 29.3
2524
experimental: [false]
2625
include:

Eask

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
(source 'jcs-elpa)
1414
(source 'melpa)
1515

16-
(depends-on "emacs" "27.1")
16+
(depends-on "emacs" "29.1")
1717
(depends-on "elenv")
1818
(depends-on "moody")
1919
(depends-on "minions")

jcs-modeline.el

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
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.
@@ -84,9 +84,6 @@
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)
@@ -171,18 +168,10 @@
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

Comments
 (0)