summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modeline.el25
1 files changed, 23 insertions, 2 deletions
diff --git a/modeline.el b/modeline.el
index b93b833..cb06b0d 100644
--- a/modeline.el
+++ b/modeline.el
@@ -5,8 +5,8 @@
"The main mode line format."
(let* ((left (modeline-format-left))
(right (modeline-format-right))
- (left-len (length left))
- (right-len (length right))
+ (left-len (modeline-length left))
+ (right-len (modeline-length right))
(middle (propertize " " 'display
(make-string
(max (- (window-total-width)
@@ -78,6 +78,27 @@
(modeline-format-major-mode)
(modeline-format-vc-mode)))
+;;; Calculate the correct lengths of characters
+
+;;;###autoload
+(defun modeline-length (str)
+ "Return the length of STR.
+Characters that take up more than one column will be counted with
+1.7 columns."
+ (declare (side-effect-free t) (pure t))
+ (let ((len 0))
+ (mapc (lambda (char)
+ (let ((name (get-char-code-property char 'name))
+ (decomposition (get-char-code-property char 'decomposition)))
+ (cond
+ ((or (string-match (rx-to-string '(seq bos "CJK"))
+ name)
+ (eq (car decomposition) 'wide))
+ (setq len (+ len 1.7)))
+ ((setq len (1+ len))))))
+ str)
+ (floor len)))
+
;;; Conveniently add text properties
;;;###autoload