From b01f6773aeb9bc58e55d71e86f9c0afdb66ae8aa Mon Sep 17 00:00:00 2001 From: jao Date: Mon, 19 Oct 2020 23:59:04 +0100 Subject: jao-minibuffer: new utilities to display status in minibuffer --- misc/jao-minibuffer.el | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 misc/jao-minibuffer.el (limited to 'misc') diff --git a/misc/jao-minibuffer.el b/misc/jao-minibuffer.el new file mode 100644 index 0000000..9f28390 --- /dev/null +++ b/misc/jao-minibuffer.el @@ -0,0 +1,68 @@ +;;; 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) + +;; (setq jao-minibuffer-align-right-p t) + +(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 ((w (- (frame-width) (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 " *Minibuf-0*" + (erase-buffer) + (insert (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 -- cgit v1.2.3