;;; jao-minibuffer.el --- using the minibuffer to report status -*- lexical-binding: t; -*- ;; Copyright (C) 2020 jao ;; Author: jao ;; Keywords: extensions ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; Simple asynchronous display of information in the minibuffer. ;;; Code: (defvar jao-minibuffer-info ()) (defvar jao-minibuffer-align-right-p t) (defvar jao-minibuffer-right-margin 2) (defvar jao-minibuffer-maximized-frames-p t) (defconst jao-minibuffer--name " *Minibuf-0*") (defun jao-minibuffer--trim (s w) (if (<= (length s) w) (format (format "%%%ds" w) s) (substring s 0 w))) (defun jao-minibuffer--aligned (&optional w) (let ((msg (format-mode-line jao-minibuffer-info))) (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 (- mw (or w 0) jao-minibuffer-right-margin))) (if (> w 0) (jao-minibuffer--trim msg w) "")) (concat " ยท " msg))))) (defun jao-minibuffer--message (old-func &rest args) (let ((msg (let ((inhibit-message t)) (apply old-func args)))) (when (not inhibit-message) (let ((message-log-max nil) (new-msg (concat msg (jao-minibuffer--aligned (length msg))))) (funcall old-func "%s" new-msg))) msg)) (advice-add #'message :around #'jao-minibuffer--message) ;;;###autoload (defun jao-minibuffer-refresh () (interactive "") (with-current-buffer jao-minibuffer--name (erase-buffer) (insert (or (jao-minibuffer--aligned) "")))) ;;;###autoload (defun jao-minibuffer-add-variable (variable-name &optional append) (add-to-list 'jao-minibuffer-info `(:eval ,variable-name) append)) (provide 'jao-minibuffer) ;;; jao-minibuffer.el ends here