From b95fb8b95a85399f64232b5ce62200988f1635bb Mon Sep 17 00:00:00 2001 From: Gambhiro Date: Sun, 3 Dec 2017 15:27:16 +0000 Subject: [PATCH] shorten modeline str if longer than max-width --- mu4e/mu4e-utils.el | 16 ++++++++++++++-- mu4e/mu4e-vars.el | 7 +++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 01f9153a..44c764dc 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -1299,8 +1299,20 @@ the view and compose modes." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun mu4e~quote-for-modeline (str) - "Quote a string to be used literally in the modeline." - (replace-regexp-in-string "%" "%%" str t t)) + "Quote a string to be used literally in the modeline. The +string will be shortened to fit if its length exceeds +`mu4e-modeline-max-width'." + (let* (;; Adjust the max-width to include the length of the " ..." string + (width (let ((w (- mu4e-modeline-max-width 4))) + (if (> w 0) w 0))) + (str (let* ((l (length str)) + ;; If the input str is longer than the max-width, then will shorten + (w (if (> l width) width l)) + ;; If the input str is longer than the max-width, then append " ..." + (a (if (> l width) " ..." ""))) + (concat (substring str 0 w) a)))) + ;; Escape the % character + (replace-regexp-in-string "%" "%%" str t t))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/mu4e/mu4e-vars.el b/mu4e/mu4e-vars.el index 3cb77fcb..4da6af5c 100644 --- a/mu4e/mu4e-vars.el +++ b/mu4e/mu4e-vars.el @@ -180,6 +180,13 @@ threads. You can customize the exact fancy characters used with :type 'string :group 'mu4e) +(defcustom mu4e-modeline-max-width 30 + "Determines the maximum length of the string to be used in the +modeline. If the string exeeds this limit, it will be shortened +to fit." + :type 'integer + :group 'mu4e) + (defvar mu4e-debug nil "When set to non-nil, log debug information to the *mu4e-log* buffer.")