diff options
author | jao <jao@gnu.org> | 2020-12-07 11:00:03 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2020-12-07 11:00:03 +0000 |
commit | 083587496020d0332c9f568dc374d47c01c5c649 (patch) | |
tree | f042b9ac161e0f2392bc05ed7e696a5e07b6d974 | |
parent | df829e7db9145ae7095eca54b309a2da3e368be1 (diff) | |
download | elibs-083587496020d0332c9f568dc374d47c01c5c649.tar.gz elibs-083587496020d0332c9f568dc374d47c01c5c649.tar.bz2 |
minibuffer: left alignment
-rw-r--r-- | sys/jao-minibuffer.el | 47 |
1 files changed, 31 insertions, 16 deletions
diff --git a/sys/jao-minibuffer.el b/sys/jao-minibuffer.el index 157ca0f..ed31af9 100644 --- a/sys/jao-minibuffer.el +++ b/sys/jao-minibuffer.el @@ -28,7 +28,7 @@ (defvar jao-minibuffer-notification nil) (defvar jao-minibuffer-align-right-p t) (defvar jao-minibuffer-right-margin (if window-system 0 1)) -(defvar jao-minibuffer-maximized-frames-p t) +(defvar jao-minibuffer-maximized-frames-p nil) (defvar jao-minibuffer-notification-timeout 5) (defvar jao-minibuffer-enabled-p t) @@ -36,32 +36,47 @@ (defun jao-minibuffer--trim (s w) (if (<= (length s) w) - (format (format "%%%ds" w) s) + (format (format "%%%ds" (if jao-minibuffer-align-right-p w (- w))) s) (substring s 0 w))) (defun jao-minibuffer--current () (with-current-buffer jao-minibuffer--name (buffer-substring (point-min) (point-max)))) +(defun jao-minibuffer--width () + (if jao-minibuffer-maximized-frames-p + (frame-width) + (window-width (minibuffer-window)))) + +(defun jao-minibuffer--format-info () + (mapconcat 'identity + (seq-filter (lambda (s) (not (string-blank-p s))) + (mapcar 'format-mode-line + (if jao-minibuffer-align-right-p + jao-minibuffer-info + (reverse jao-minibuffer-info)))) + " ")) + (defun jao-minibuffer--aligned (&optional w currentp) - (let* ((msg (if currentp - (jao-minibuffer--current) - (format-mode-line (or jao-minibuffer-notification - jao-minibuffer-info)))) - (msg (propertize (string-trim msg) :minibuffer-message t))) + (let* ((msg (cond (currentp (jao-minibuffer--current)) + (jao-minibuffer-notification + (format-mode-line jao-minibuffer-notification)) + (t (jao-minibuffer--format-info)))) + (msg (if jao-minibuffer-align-right-p + (string-trim msg) + (string-trim-left msg))) + (msg (propertize msg :minibuffer-message t))) (when (not (string-empty-p msg)) - (if jao-minibuffer-align-right-p - (let* ((mw (if jao-minibuffer-maximized-frames-p - (frame-width) - (window-width (minibuffer-window)))) - (w (mod (or w (length (current-message))) mw)) - (w (- mw w jao-minibuffer-right-margin))) - (if (> w 0) (jao-minibuffer--trim msg w) "")) - (concat " ยท " msg))))) + (let* ((mw (jao-minibuffer--width)) + (w (mod (or w (length (current-message))) mw)) + (w (- mw w jao-minibuffer-right-margin))) + (if (> w 0) (jao-minibuffer--trim msg w) ""))))) (defun jao-minibuffer--set-message (msg) (let ((msg (string-trim (replace-regexp-in-string "\n" " " msg)))) - (concat msg (jao-minibuffer--aligned (length msg) t)))) + (if jao-minibuffer-align-right-p + (concat msg (jao-minibuffer--aligned (length msg) t)) + (concat (jao-minibuffer--aligned (+ 3 (length msg)) t) " " msg)))) (defun jao-minibuffer--insert (msg) (with-current-buffer jao-minibuffer--name |