From 87679ecdd18f3315a38c81178077bf52c456a1ba Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 24 Jan 2022 01:34:38 +0000 Subject: jao-minibuffer: deal with multi-line msgs --- lib/eos/jao-minibuffer.el | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) (limited to 'lib') diff --git a/lib/eos/jao-minibuffer.el b/lib/eos/jao-minibuffer.el index 47aa3ea..dabd822 100644 --- a/lib/eos/jao-minibuffer.el +++ b/lib/eos/jao-minibuffer.el @@ -71,8 +71,7 @@ (msg (propertize msg :minibuffer-message t))) (when (not (string-empty-p msg)) (let* ((mw (jao-minibuffer--width)) - (w (mod (or w (string-width (or (current-message) ""))) mw)) - (w (- mw w (length jao-minibuffer-right-margin)))) + (w (- mw (mod w mw) (length jao-minibuffer-right-margin) -1))) (if (> w 0) (jao-minibuffer--trim msg w) ""))))) (defun jao-minibuffer--insert (msg) @@ -82,26 +81,18 @@ (insert msg) (when hack (other-window 1) (other-window -1))))) -(defun jao-minibuffer--format-msg (msg) - (let* ((msgs (split-string msg "\n")) - (prefix (when-let (p (string-join (butlast msgs) "\n")) - (unless (string-blank-p p) (concat p "\n")))) - (msg (car (last msgs))) - (msg (string-trim (replace-regexp-in-string "\n" " " msg))) - (msg (if (string-blank-p msg) msg (concat msg " ")))) - (if jao-minibuffer-align-right-p - (concat prefix msg (jao-minibuffer--aligned (string-width (or msg "")))) - (concat prefix - (jao-minibuffer--aligned (+ 3 (string-width (or msg "")))) - " " msg)))) + (defun jao-minibuffer--format-msg (msg) + (let* ((msgs (split-string msg "\n")) + (prefix (when-let (p (string-join (butlast msgs) "\n")) + (unless (string-blank-p p) (concat p "\n")))) + (msg (car (last msgs))) + (msg (if (string-blank-p msg) msg (concat msg " ")))) + (if jao-minibuffer-align-right-p + (concat prefix msg (jao-minibuffer--aligned (length msg))) + (concat prefix (jao-minibuffer--aligned (+ 3 (length msg))) " " msg)))) (defun jao-minibuffer--set-message (msg) - (if (or (not jao-minibuffer-mode) - (and msg - (not (string-blank-p msg)) - (bound-and-true-p current-minibuffer-command))) - msg - (jao-minibuffer--format-msg msg))) + (when jao-minibuffer-mode (jao-minibuffer--format-msg (or msg "")))) (defvar-local w3m-current-title nil) (defvar-local eww-data nil) @@ -183,7 +174,7 @@ (interactive) (advice-add 'select-window :after #'jao-minibuffer-refresh) (advice-add 'force-mode-line-update :after #'jao-minibuffer-refresh) - (setq set-message-function #'jao-minibuffer--format-msg) + (setq set-message-function #'jao-minibuffer--set-message) (setq clear-message-function #'jao-minibuffer-refresh) (jao-minibuffer-refresh)) -- cgit v1.2.3