From 5bdbbccdc5401c29acb803605cd8042e956f9c72 Mon Sep 17 00:00:00 2001 From: Jakob L. Kreuze Date: Sat, 28 Sep 2019 14:03:34 -0400 Subject: Update modeline to show EXWM window title. --- jakob.org | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/jakob.org b/jakob.org index 17a1f9a..a2bbe77 100644 --- a/jakob.org +++ b/jakob.org @@ -732,19 +732,35 @@ sequences, the percent symbol has to be escaped twice -- once for Use an =:eval= form to align modeline contents. #+BEGIN_SRC elisp +(cl-defun maybe-elide (s &optional (max-length 30)) + "Return a string derived from S, possible elided, that is at +most MAX-LENGTH characters long." + (if (> (length s) max-length) + (concat (substring s 0 (- max-length 4)) " ...") + s)) + +(defun escape-mode-line-construct (s) + "Ensure that no part of S will be interpreted as a modeline +format specifier." + (s-replace "%" "%%" s)) + (defun mode-line-render (left right) "Return a string of `window-width' length containing LEFT, and RIGHT aligned respectively." - (let* ((padding (- (window-width) (length (format-mode-line left)) - (length right) 1)) - (padding (make-string padding ?\ ))) - (concat " " left padding right))) + (let* ((right (format-mode-line right)) + (left (maybe-elide (format-mode-line left) + (- (window-width) (length right) 1))) + (padding (- (window-width) (length left) (length right) 1)) + (padding (if (wholenump padding) (make-string padding ?\ )))) + (if padding + (escape-mode-line-construct (concat " " left padding right)) + (concat " " left right)))) (setq-default mode-line-format '((:eval (mode-line-render (cond ((eq major-mode 'exwm-mode) - "%b") + (concat "%b: " exwm-title)) ((eq major-mode 'pdf-view-mode) (concat "%b [" (number-to-string (pdf-view-current-page)) -- cgit v1.3