blob: e55e5a2c7e5783e4a320ade351b35abdc0e53f9f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
;;; 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)
(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 (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 (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
|