From 4fa8190ec72a0ed5dcfa3b8e92d1ecd3e35e16c2 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sun, 16 Jun 2024 22:15:44 -0700 Subject: [PATCH] fix str width --- .github/workflows/test.yml | 1 - Eask | 2 +- jcs-modeline.el | 23 ++++++----------------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 10cd625..9994bac 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,6 @@ jobs: matrix: os: [ubuntu-latest, macos-latest, windows-latest] emacs-version: - - 28.2 - 29.3 experimental: [false] include: diff --git a/Eask b/Eask index 2a00857..efc6b12 100644 --- a/Eask +++ b/Eask @@ -13,7 +13,7 @@ (source 'jcs-elpa) (source 'melpa) -(depends-on "emacs" "27.1") +(depends-on "emacs" "29.1") (depends-on "elenv") (depends-on "moody") (depends-on "minions") diff --git a/jcs-modeline.el b/jcs-modeline.el index 10f6efd..dece7f5 100644 --- a/jcs-modeline.el +++ b/jcs-modeline.el @@ -6,7 +6,7 @@ ;; Maintainer: Shen, Jen-Chieh ;; URL: https://github.com/jcs-emacs/jcs-modeline ;; Version: 0.1.1 -;; 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")) +;; 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")) ;; Keywords: faces mode-line ;; This file is not part of GNU Emacs. @@ -84,9 +84,6 @@ ;; (@* "Externals" ) ;; -(declare-function string-pixel-width "subr-x.el") ; TODO: remove this after 29.1 -(declare-function shr-string-pixel-width "shr.el") ; TODO: remove this after 29.1 - (defvar buffer-undo-tree) (defvar undo-tree-visualizer-buffer-name) (defvar undo-tree-visualizer-parent-buffer) @@ -171,18 +168,10 @@ (puthash char result jcs-modeline--char-displayable-cache) (and result str-or-char))) -;; TODO: Use function `string-pixel-width' after 29.1 -(defun jcs-modeline--string-pixel-width (str) - "Return the width of STR in pixels." - (if (fboundp #'string-pixel-width) - (string-pixel-width str) - (require 'shr) - (shr-string-pixel-width str))) - -(defun jcs-modeline--str-len (str) +(defun jcs-modeline--str-width (str) "Calculate STR in pixel width." (let ((width (frame-char-width)) - (len (jcs-modeline--string-pixel-width str))) + (len (string-pixel-width str))) (+ (/ len width) (if (zerop (% len width)) 0 1)))) ; add one if exceeed @@ -235,7 +224,7 @@ Position argument ARG0." (let* ((item (nth (if is-left left-index right-index) (if is-left jcs-modeline-left right-list))) (format (format-mode-line item)) - (width (jcs-modeline--str-len format)) + (width (jcs-modeline--str-width format)) (new-width (+ current-width width))) ;; Can the new item added to the list? (when (<= new-width (window-width)) ; can be displayed properly! @@ -262,8 +251,8 @@ Position argument ARG0." (defun jcs-modeline-render (left right) "Render mode line with LEFT and RIGHT alignment." - (let* ((len-left (jcs-modeline--str-len (format-mode-line left))) - (len-right (jcs-modeline--str-len (format-mode-line right))) + (let* ((len-left (jcs-modeline--str-width (format-mode-line left))) + (len-right (jcs-modeline--str-width (format-mode-line right))) (available-width (- (window-width) (+ len-left len-right))) (available-width (+ available-width (jcs-modeline--adjust-pad)))) (append left