Merge pull request #1161 from gambhiro/modeline-max-width

mu4e: shorten modeline str if longer than max-width
This commit is contained in:
Dirk-Jan C. Binnema 2018-04-25 11:32:15 +03:00 committed by GitHub
commit aeb6718da6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 2 deletions

View File

@ -1303,8 +1303,20 @@ the view and compose modes and will color each signature in digest messages adhe
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(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)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@ -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.")