summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-03-04 03:35:18 +0000
committerjao <jao@gnu.org>2022-03-04 03:35:18 +0000
commit6220f588defdea40c3ead9a8b3d4f59d3977fddf (patch)
tree0bb74d2ead3b70ac0da6ea555f1ce65086f29a91
parent1b46616b076a5b9ef0e2d6214553877d931e46f4 (diff)
downloadelibs-6220f588defdea40c3ead9a8b3d4f59d3977fddf.tar.gz
elibs-6220f588defdea40c3ead9a8b3d4f59d3977fddf.tar.bz2
jao-minibuffer: back to no overlays and mode-line lib
-rw-r--r--init.org9
-rw-r--r--lib/eos/jao-minibuffer-mode-line.el106
-rw-r--r--lib/eos/jao-minibuffer.el138
-rw-r--r--lib/themes/jao-dark-theme.el2
-rw-r--r--lib/themes/jao-light-theme.el2
5 files changed, 146 insertions, 111 deletions
diff --git a/init.org b/init.org
index b1d68ee..acf6601 100644
--- a/init.org
+++ b/init.org
@@ -704,9 +704,12 @@
jao-minibuffer-inactive-buffer-line-color "grey65"))
:commands (jao-minibuffer-add-variable
jao-minibuffer-refresh
- jao-minibuffer-add-mode-line
jao-minibuffer-mode))
+ (use-package jao-minibuffer-mode-line
+ :commands (jao-minibuffer-add-mode-line
+ jao-minibuffer-remove-mode-line))
+
(setq enable-recursive-minibuffers t)
(require 'mb-depth)
(minibuffer-depth-indicate-mode 1)
@@ -715,9 +718,11 @@
(minibuffer-electric-default-mode 1)
(jao-minibuffer-mode 1)
+
(when jao-modeline-in-minibuffer-p
(add-hook 'display-time-hook #'jao-minibuffer-refresh)
- (jao-minibuffer-add-mode-line 90))
+ (add-hook 'after-init-hook
+ (lambda () (jao-minibuffer-add-mode-line 90))))
#+end_src
*** Mode line format
#+begin_src emacs-lisp
diff --git a/lib/eos/jao-minibuffer-mode-line.el b/lib/eos/jao-minibuffer-mode-line.el
new file mode 100644
index 0000000..6f69630
--- /dev/null
+++ b/lib/eos/jao-minibuffer-mode-line.el
@@ -0,0 +1,106 @@
+;;; jao-minibuffer-mode-line.el --- mode-line info in the minibuffer -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: convenience
+
+;; 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:
+
+;; Using jao-minibuffer to display mode-line info in the minibuffer.
+
+;;; Code:
+
+(require 'jao-minibuffer)
+
+(defvar exwm-class-name nil)
+
+(defvar jao-minibuffer--mode-line-position
+ '(exwm-class-name
+ ("")
+ ("%n %2c %l " (:eval (format "%d" (line-number-at-pos (point-max)))))))
+
+(defvar jao-minibuffer--mode-line-bid
+ '(:eval (cond ((derived-mode-p 'gnus-group-mode
+ 'gnus-article-mode
+ 'gnus-summary-mode)
+ mode-line-buffer-identification)
+ ((derived-mode-p 'circe-channel-mode)
+ (format "%s [%d]" (buffer-name) (length (circe-channel-nicks))))
+ (t "%b"))))
+
+(defvar jao-minibuffer--mode-line-format
+ `("%[" (:propertize ,jao-minibuffer--mode-line-bid face jao-themes-f00) "%]"
+ (:propertize " (" face jao-themes-dimm)
+ (:propertize mode-name face jao-themes-f00)
+ (:propertize ("" minor-mode-alist) face jao-themes-f11)
+ (:propertize ")" face jao-themes-dimm)
+ (:propertize (vc-mode vc-mode) face jao-themes-f10)
+ (:propertize mode-line-position face jao-themes-f12)
+ " "
+ global-mode-string
+ (:propertize (" %Z%*%+ " (current-input-method current-input-method-title))
+ face jao-themes-warning)
+ (:propertize "·" display "")))
+
+(defvar jao-minibuffer--original-modeline nil)
+(defvar jao-minibuffer--original-line-face nil)
+(defvar jao-minibuffer--original-line-inactive-face nil)
+
+(defun jao-minibuffer-mode-line-adjust-faces ()
+ (let ((bg (frame-parameter nil 'background-color)))
+ (set-face-attribute 'mode-line nil :box nil :height 1
+ :background bg :foreground bg
+ :overline jao-minibuffer-active-buffer-line-color
+ :underline jao-minibuffer-inactive-buffer-line-color
+ :extend t)
+ (set-face-attribute 'mode-line-inactive nil :box nil :height 1
+ :background bg :foreground bg
+ :overline bg
+ :underline jao-minibuffer-inactive-buffer-line-color
+ :extend t)))
+
+;;;###autoload
+(defun jao-minibuffer-add-mode-line (&optional order)
+ (interactive)
+ (setq jao-minibuffer--original-line-face
+ (get 'mode-line 'saved-face))
+ (setq jao-minibuffer--original-line-inactive-face
+ (get 'mode-line-inactive 'saved-face))
+ (setq jao-minibuffer--original-modeline mode-line-format)
+ (setq-default mode-line-format '(" "))
+ (setq-default mode-line-position jao-minibuffer--mode-line-position)
+ (dolist (b (buffer-list))
+ (with-current-buffer b (setq-local mode-line-format '(" "))))
+ (jao-minibuffer-add-variable 'jao-minibuffer--mode-line-format (or order 90))
+ (jao-minibuffer-mode-line-adjust-faces))
+
+;;;###autoload
+(defun jao-minibuffer-remove-mode-line ()
+ (interactive)
+ (face-spec-set 'mode-line jao-minibuffer--original-line-face)
+ (face-spec-set 'mode-line-inactive jao-minibuffer--original-line-inactive-face)
+ (setq-default mode-line-format jao-minibuffer--original-modeline)
+ (dolist (b (buffer-list))
+ (with-current-buffer b (setq-local mode-line-format
+ jao-minibuffer--original-modeline)))
+ (setq jao-minibuffer-info
+ (remove '(:eval jao-minibuffer--mode-line-format)
+ jao-minibuffer-info)))
+
+
+(provide 'jao-minibuffer-mode-line)
+;;; jao-minibuffer-mode-line.el ends here
diff --git a/lib/eos/jao-minibuffer.el b/lib/eos/jao-minibuffer.el
index 515f31b..2e58f24 100644
--- a/lib/eos/jao-minibuffer.el
+++ b/lib/eos/jao-minibuffer.el
@@ -20,7 +20,7 @@
;;; Commentary:
-;; Simple asynchronous display of information in the minibuffer and echo area.
+;; Simple asynchronous display of information in the minibuffer.
;;; Code:
@@ -34,37 +34,6 @@
(defvar jao-minibuffer-inactive-buffer-line-color "grey25")
(defconst jao-minibuffer--name " *Minibuf-0*")
-(defvar jao-minibuffer--overlays nil)
-
-(defun jao-minibuffer--create-overlays ()
- (dolist (buf '(" *Echo Area 0*" " *Echo Area 1*"))
- (with-current-buffer buf
- (remove-overlays (point-min) (point-max))
- (push (make-overlay (point-min) (point-max) nil nil t)
- jao-minibuffer--overlays))))
-
-(defun jao-minibuffer--remove-overlays ()
- (mapc 'delete-overlay jao-minibuffer--overlays)
- (setq jao-minibuffer--overlays nil))
-
-(defun jao-minibuffer--set-overlays (txt)
- (let* ((txt (concat txt jao-minibuffer-right-margin))
- (wid (string-width txt))
- (align `(space :align-to (- right-fringe ,wid)))
- (spc (propertize " " 'cursor 1 'display align))
- (txt (concat spc txt)))
- ;; Remove any dead overlays from the minibuffer from the beginning of the list
- (while (null (overlay-buffer (car jao-minibuffer--overlays)))
- (pop jao-minibuffer--overlays))
-
- ;; Add the correct text to each echo bar overlay
- (dolist (o jao-minibuffer--overlays)
- (when (overlay-buffer o) (overlay-put o 'after-string txt)))))
-
-(defun jao-minibuffer--minibuffer-setup ()
- (push (make-overlay (point-max) (point-max) nil t t) jao-minibuffer--overlays)
- (overlay-put (car jao-minibuffer--overlays) 'priority 1)
- (jao-minibuffer-refresh))
(defun jao-minibuffer--trim (s w)
(if (<= (string-width (or s "")) w)
@@ -85,22 +54,21 @@
(reverse (or info jao-minibuffer-info)))))
" "))
-(defun jao-minibuffer--aligned (left msg)
- (let* ((msg (or msg (jao-minibuffer--format-info)))
+(defun jao-minibuffer--aligned (&optional w)
+ (let* ((msg (jao-minibuffer--format-info))
(msg (cond (jao-minibuffer-align-right-p (string-trim msg))
(t (string-trim-left msg))))
- (w (string-width left)))
- (unless (and (string-empty-p left) (string-empty-p msg))
+ (msg (propertize msg :minibuffer-message t)))
+ (unless (string-empty-p msg)
(let* ((mw (jao-minibuffer--width))
- (w (- mw (mod w mw) (string-width jao-minibuffer-right-margin) -1))
- (right (if (> w 0) (jao-minibuffer--trim msg w) "")))
- (concat left right jao-minibuffer-right-margin)))))
+ (w (- mw (mod w mw) (string-width jao-minibuffer-right-margin) -1)))
+ (if (> w 0) (jao-minibuffer--trim msg w) "")))))
(defun jao-minibuffer--insert (msg)
- (let ((hack (and nil (derived-mode-p 'pdf-view-mode 'doc-view-mode))))
+ (let ((hack (derived-mode-p 'pdf-view-mode 'doc-view-mode)))
(with-current-buffer jao-minibuffer--name
(delete-region (point-min) (point-max))
- (insert (or msg ""))
+ (insert msg)
(when hack (other-window 1) (other-window -1)))))
(defun jao-minibuffer--strip-prev (msg)
@@ -109,37 +77,21 @@
(string-trim (substring msg 0 n))
msg))
-(defvar exwm-class-name nil)
-
-(defvar jao-minibuffer--mode-line-position
- '(exwm-class-name
- ("")
- ("%n %2c %l " (:eval (format "%d" (line-number-at-pos (point-max)))))))
-
-(defvar jao-minibuffer--mode-line-bid
- '(:eval (cond ((derived-mode-p 'gnus-group-mode
- 'gnus-article-mode
- 'gnus-summary-mode)
- mode-line-buffer-identification)
- ((derived-mode-p 'circe-channel-mode)
- (format "%s [%d]" (buffer-name) (length (circe-channel-nicks))))
- (t "%b"))))
-
-(defvar jao-minibuffer--mode-line-format
- `("%[" (:propertize ,jao-minibuffer--mode-line-bid face jao-themes-f00) "%]"
- (:propertize " (" face jao-themes-dimm)
- (:propertize mode-name face jao-themes-f00)
- (:propertize ("" minor-mode-alist) face jao-themes-f11)
- (:propertize ")" face jao-themes-dimm)
- (:propertize (vc-mode vc-mode) face jao-themes-f10)
- (:propertize mode-line-position face jao-themes-f12)
- " "
- global-mode-string
- (:propertize (" %Z%*%+ " (current-input-method current-input-method-title))
- face jao-themes-warning)
- (:propertize "·" display "")))
-
-(defvar jao-minibuffer--original-modeline nil)
+(defun jao-minibuffer--format-msg (msg)
+ (let* ((msgs (mapcar #'jao-minibuffer--strip-prev (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 " ")))
+ (w (string-width msg)))
+ (if jao-minibuffer-align-right-p
+ (concat prefix msg (jao-minibuffer--aligned w))
+ (concat prefix (jao-minibuffer--aligned (+ 3 w)) " " msg))))
+
+(defun jao-minibuffer--set-message (msg)
+ (when jao-minibuffer-mode (jao-minibuffer--format-msg (or msg ""))))
+
+(setq set-message-function #'jao-minibuffer--set-message)
(defun jao-minibuffer--add-variable (list-name variable-name &optional order)
(let ((v `(:eval ,variable-name)))
@@ -154,29 +106,6 @@
(defun jao-minibuffer-add-msg-variable (variable-name &optional order)
(jao-minibuffer--add-variable 'jao-minibuffer-msg-info variable-name order))
-(defun jao-minibuffer-adjust-mode-line-faces ()
- (let ((bg (frame-parameter nil 'background-color)))
- (set-face-attribute 'mode-line nil :box nil :height 1
- :background bg :foreground bg
- :overline jao-minibuffer-active-buffer-line-color
- :underline jao-minibuffer-inactive-buffer-line-color
- :extend t)
- (set-face-attribute 'mode-line-inactive nil :box nil :height 1
- :background bg :foreground bg
- :overline bg
- :underline jao-minibuffer-inactive-buffer-line-color
- :extend t)))
-
-;;;###autoload
-(defun jao-minibuffer-add-mode-line (order)
- (setq jao-minibuffer--original-modeline mode-line-format)
- (setq-default mode-line-format '(" "))
- (setq-default mode-line-position jao-minibuffer--mode-line-position)
- (dolist (b (buffer-list))
- (with-current-buffer b (setq-local mode-line-format '(" "))))
- (jao-minibuffer-add-variable 'jao-minibuffer--mode-line-format order)
- (jao-minibuffer-adjust-mode-line-faces))
-
;;;###autoload
(define-minor-mode jao-minibuffer-mode
"Show minibuffer status"
@@ -184,27 +113,22 @@
(if jao-minibuffer-mode
(progn (advice-add 'select-window :after #'jao-minibuffer-refresh)
(advice-add 'force-mode-line-update :after #'jao-minibuffer-refresh)
- (jao-minibuffer--create-overlays)
- ;; (add-hook 'minibuffer-setup-hook #'jao-minibuffer--minibuffer-setup)
+ (setq clear-message-function #'jao-minibuffer-refresh)
(jao-minibuffer-refresh))
(advice-remove 'select-window #'jao-minibuffer-refresh)
(advice-remove 'force-mode-line-update #'jao-minibuffer-refresh)
- (remove-hook 'minibuffer-setup-hook #'jao-minibuffer--minibuffer-setup)
- (jao-minibuffer--remove-overlays)
+ (setq set-message-function nil)
+ (setq clear-message-function nil)
(jao-minibuffer--insert "")))
;;;###autoload
(defun jao-minibuffer-refresh (&rest _ignore)
(interactive)
(when jao-minibuffer-mode
- (let ((jao-minibuffer-mode nil)
- (window-selection-change-functions nil)
- (right (jao-minibuffer--format-info))
- (left (jao-minibuffer--format-info jao-minibuffer-msg-info)))
- (jao-minibuffer--set-overlays right)
- (jao-minibuffer--insert (jao-minibuffer--aligned left right)))))
-
-;; (add-hook 'window-selection-change-functions #'jao-minibuffer-refresh)
+ (let* ((jao-minibuffer-mode nil)
+ (msg (jao-minibuffer--format-info jao-minibuffer-msg-info))
+ (msg (jao-minibuffer--format-msg (or msg ""))))
+ (jao-minibuffer--insert (or msg "")))))
(provide 'jao-minibuffer)
;;; jao-minibuffer.el ends here
diff --git a/lib/themes/jao-dark-theme.el b/lib/themes/jao-dark-theme.el
index 83dba9d..608806a 100644
--- a/lib/themes/jao-dark-theme.el
+++ b/lib/themes/jao-dark-theme.el
@@ -128,7 +128,7 @@
(w3m-bold (c yellow))))
;; (enable-theme 'jao-dark)
-;; (jao-minibuffer-adjust-mode-line-faces)
+;; (jao-minibuffer-mode-line-adjust-faces)
(provide 'jao-dark-theme)
diff --git a/lib/themes/jao-light-theme.el b/lib/themes/jao-light-theme.el
index a807e28..fe31bed 100644
--- a/lib/themes/jao-light-theme.el
+++ b/lib/themes/jao-light-theme.el
@@ -117,6 +117,6 @@
(widget-button (~ default) nit (ul "grey80"))))
;; (enable-theme 'jao-light)
-;; (jao-minibuffer-adjust-mode-line-faces)
+;; (jao-minibuffer-mode-line-adjust-faces)
(provide 'jao-light-theme)