[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/dirvish 1ece580035 1/2: fix: respect multibyte string in a
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/dirvish 1ece580035 1/2: fix: respect multibyte string in attributes |
Date: |
Sun, 16 Mar 2025 07:00:25 -0400 (EDT) |
branch: elpa/dirvish
commit 1ece5800352b97eb3faf2ad9f1292a20d10ca58e
Author: Alex Lu <hellosimon1103@hotmail.com>
Commit: Alex Lu <hellosimon1103@hotmail.com>
fix: respect multibyte string in attributes
---
dirvish.el | 2 +-
extensions/dirvish-vc.el | 24 ++++++++++++------------
2 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/dirvish.el b/dirvish.el
index c15072c243..ba31d4d37b 100644
--- a/dirvish.el
+++ b/dirvish.el
@@ -1047,7 +1047,7 @@ When the attribute does not exist, set it with BODY."
('right (setq right (concat v right))))
finally
(prog1 (unless (or left right) (cl-return))
- (let* ((len1 (length right))
+ (let* ((len1 (string-width (or right "")))
(remain (- width len1
(or (get-text-property l-beg 'line-prefix) 0)))
(len2 (min (length left) (max 0 (- remain f-wid 1))))
diff --git a/extensions/dirvish-vc.el b/extensions/dirvish-vc.el
index 1ae74e3d2a..d54e270355 100644
--- a/extensions/dirvish-vc.el
+++ b/extensions/dirvish-vc.el
@@ -181,7 +181,7 @@ This attribute only works on graphic displays."
`(ov . ,ov)))
(dirvish-define-attribute git-msg
- "Append git commit message to filename."
+ "Display short git log."
:when (and (eq (dirvish-prop :vc-backend) 'Git) (not (dirvish-prop :remote)))
:setup (dirvish-prop :gm-chop
(seq-reduce (lambda (acc i) (cl-incf acc (nth 2 i)))
@@ -189,19 +189,19 @@ This attribute only works on graphic displays."
(let* ((msg-raw (dirvish-attribute-cache f-name :git-msg))
(msg (if (>= (length msg-raw) 1) (substring msg-raw 0 -1) ""))
(face (or hl-face 'dirvish-git-commit-message-face))
- (spc (make-string w-width ?\ ))
- (chop (dirvish-prop :gm-chop)) len tail str str-len)
+ (chop (dirvish-prop :gm-chop)) (mlen (length msg)) (stop t)
+ (limit (- (floor (* (if (< w-width 70) 0.48 0.6) w-width)) chop))
+ (count 0) (whole (concat " " msg (make-string w-width ?\ ))) str len)
(cond ((or (not msg-raw) (< w-width 30)) (setq str ""))
((and (>= w-width 30) (< w-width 50)) (setq str (propertize " … ")))
- ((and (>= w-width 50) (< w-width 70))
- (setq len (max 0 (- (floor (* w-width 0.48)) chop))
- tail (if (> (length msg) len) "… " " ")
- str (concat (substring (concat " " msg spc) 0 len) tail)))
- (t (setq len (max 0 (- (floor (* w-width 0.6)) chop))
- tail (if (> (length msg) len) "… " " ")
- str (concat (substring (concat " " msg spc) 0 len) tail))))
- (add-face-text-property 0 (setq str-len (length str)) face t str)
- (add-text-properties 0 str-len `(help-echo ,msg) str)
+ (t (setq str "" stop (<= limit 0))))
+ (while (not stop) ; prevent multibyte string taking too much space
+ (setq str (substring whole 0 count))
+ (if (>= (- limit (string-width str)) 1)
+ (cl-incf count)
+ (setq str (concat str (if (> count mlen) " " "… ")) stop t)))
+ (add-face-text-property 0 (setq len (length str)) face t str)
+ (add-text-properties 0 len `(help-echo ,msg) str)
`(right . ,str)))
(dirvish-define-preview vc-diff (ext)