diff options
| author | Jakob L. Kreuze | 2019-09-28 14:03:34 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze | 2019-09-28 14:03:34 -0400 |
| commit | 5bdbbccdc5401c29acb803605cd8042e956f9c72 (patch) | |
| tree | 815e0a470a929d2b5c546ea46fb1aff624d6a969 /jakob.org | |
| parent | 5efba782541569a28ac073aa8c97f4eb213ee1fb (diff) | |
Update modeline to show EXWM window title.
Diffstat (limited to 'jakob.org')
| -rw-r--r-- | jakob.org | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -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)) |