summaryrefslogtreecommitdiffhomepage
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/jao-minibuffer.el68
1 files changed, 68 insertions, 0 deletions
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 <mail@jao.io>
+;; 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 <https://www.gnu.org/licenses/>.
+
+;;; 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