From cf828fc14c3fbef09f4f569482d820aa53f34ef7 Mon Sep 17 00:00:00 2001 From: jao Date: Fri, 3 Dec 2021 02:08:03 +0000 Subject: jao-minibuffer: better padding --- lib/eos/jao-minibuffer.el | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/eos/jao-minibuffer.el b/lib/eos/jao-minibuffer.el index ec7fa8d..a6420c7 100644 --- a/lib/eos/jao-minibuffer.el +++ b/lib/eos/jao-minibuffer.el @@ -38,6 +38,15 @@ (defconst jao-minibuffer--name " *Minibuf-0*") +(defun jao-minibuffer--text-with-padding (text) + "Return TEXT with padding on the left. +The padding pushes TEXT to the right edge of the mode-line." + (let* ((len (- (string-pixel-width text) jao-minibuffer-right-margin)) + (padding (propertize + "-" 'display + `(space :align-to (- (+ right right-margin) (,len)))))) + (concat padding text))) + (defun jao-minibuffer--trim (s w) (if (<= (string-width (or s "")) w) (format (format "%%%ds" (if jao-minibuffer-align-right-p w (- w))) s) @@ -71,10 +80,12 @@ (string-trim-left msg))) (msg (propertize msg :minibuffer-message t))) (when (not (string-empty-p msg)) - (let* ((mw (jao-minibuffer--width)) - (w (mod (or w (string-pixel-width (or (current-message) ""))) mw)) - (w (- mw w jao-minibuffer-right-margin))) - (if (> w 0) (jao-minibuffer--trim msg w) ""))))) + (if (and window-system jao-minibuffer-align-right-p) + (jao-minibuffer--text-with-padding msg) + (let* ((mw (jao-minibuffer--width)) + (w (mod (or w (string-width (or (current-message) ""))) mw)) + (w (- mw w jao-minibuffer-right-margin))) + (if (> w 0) (jao-minibuffer--trim msg w) "")))))) (defun jao-minibuffer--insert (msg) (with-current-buffer jao-minibuffer--name -- cgit v1.2.3