|
|
|
@ -29,20 +29,14 @@
@@ -29,20 +29,14 @@
|
|
|
|
|
(require 'timer) |
|
|
|
|
(require 'face-remap) |
|
|
|
|
|
|
|
|
|
;;; Code: |
|
|
|
|
;; ============================================================================ |
|
|
|
|
;; customizations |
|
|
|
|
;; ============================================================================ |
|
|
|
|
|
|
|
|
|
(defgroup fg42/statusbar nil |
|
|
|
|
"Modular tray bar." |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-mode-line-active-color "DarkRed" |
|
|
|
|
"Active color." |
|
|
|
|
:type 'string |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-mode-line-inactive-color "Gray10" |
|
|
|
|
"Inactive color." |
|
|
|
|
:type 'string |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-components |
|
|
|
|
'("random" (buffer-name)) |
|
|
|
@ -50,6 +44,7 @@
@@ -50,6 +44,7 @@
|
|
|
|
|
:type 'list |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-truncate-p t |
|
|
|
|
"Truncates fg42/statusbar or not." |
|
|
|
|
:type 'boolean |
|
|
|
@ -73,10 +68,22 @@ Nil means current selected frame."
@@ -73,10 +68,22 @@ Nil means current selected frame."
|
|
|
|
|
:type 'sexp |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
(defface fg42/statusbar-default-face '((t :inherit default)) |
|
|
|
|
"Face for string constant ouside modules." |
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-display-gui-line t |
|
|
|
|
"Display thin line at the bottom of the window." |
|
|
|
|
:type 'boolean |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-face-attr `(:background ,(face-attribute 'mode-line :background)) |
|
|
|
|
"Plist of face attribute/value pair for fg42/statusbar." |
|
|
|
|
:type '(plist) |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
;; ============================================================================ |
|
|
|
|
;; Faces |
|
|
|
|
;; ============================================================================ |
|
|
|
|
|
|
|
|
|
(defface fg42/statusbar-mode-line |
|
|
|
|
'((((background light)) |
|
|
|
|
:background "#55ced1" :height 0.14 :box nil) |
|
|
|
@ -94,40 +101,42 @@ Nil means current selected frame."
@@ -94,40 +101,42 @@ Nil means current selected frame."
|
|
|
|
|
"Modeline face for inactive window." |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;;###autoload |
|
|
|
|
(define-minor-mode fg42/statusbar-mode |
|
|
|
|
"Modular status bar." |
|
|
|
|
:require 'fg42/statusbar-mode |
|
|
|
|
:lighter "SB" |
|
|
|
|
:global t |
|
|
|
|
(if fg42/statusbar-mode |
|
|
|
|
(fg42/statusbar-enable) |
|
|
|
|
(fg42/statusbar-disable))) |
|
|
|
|
|
|
|
|
|
;; ============================================================================ |
|
|
|
|
;; Vars |
|
|
|
|
;; ============================================================================ |
|
|
|
|
(defvar fg42/statusbar-info-padding-right 0) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-mode-line-colors nil) |
|
|
|
|
(defvar fg42/statusbar--msg nil) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-timer nil) |
|
|
|
|
(defvar fg42/statusbar--msg-message nil |
|
|
|
|
"Store the string from `message'.") |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-active-p nil) |
|
|
|
|
(defvar fg42/statusbar--last-update (current-time)) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-belong-last-time 0) |
|
|
|
|
(defvar fg42/statusbar--last-change-size (current-time)) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar--last-echoed nil) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-belong-last-buffer nil) |
|
|
|
|
(defvar fg42/statusbar-timer nil) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-belong-cache "") |
|
|
|
|
(defvar fg42/statusbar-active-p nil) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar--cache nil) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-mode-line-default-height 1) |
|
|
|
|
(defvar fg42/statusbar--orig-resize-mini-windows resize-mini-windows) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar--minibuffer nil) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar--echo-keystrokes echo-keystrokes) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar-command-state 'begin |
|
|
|
|
"The state of current executed command begin -> [exec exec-read] -> end.") |
|
|
|
|
|
|
|
|
|
(defvar-local fg42/statusbar--orig-mode-line mode-line-format) |
|
|
|
|
|
|
|
|
|
;; ============================================================================ |
|
|
|
|
;; Definitions |
|
|
|
|
;; ============================================================================ |
|
|
|
|
(defmacro fg42/statusbar-wrap (func &rest body) |
|
|
|
|
"Add an advice around FUNC with name fg42/statusbar--%s. |
|
|
|
|
BODY will be supplied with orig-func and args." |
|
|
|
@ -142,70 +151,34 @@ BODY will be supplied with orig-func and args."
@@ -142,70 +151,34 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
"Pre command hook of fg42/statusbar." |
|
|
|
|
(setq fg42/statusbar-command-state 'begin)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defsubst fg42/statusbar-post-cmd () |
|
|
|
|
"Post command hook of fg42/statusbar." |
|
|
|
|
(setq fg42/statusbar-command-state 'end |
|
|
|
|
echo-keystrokes fg42/statusbar--echo-keystrokes)) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar--orig-resize-mini-windows resize-mini-windows) |
|
|
|
|
|
|
|
|
|
(defsubst fg42/statusbar-enter-minibuffer () |
|
|
|
|
"`minibuffer-setup-hook' of fg42/statusbar." |
|
|
|
|
(fg42/statusbar--set-buffer-face) |
|
|
|
|
(setq resize-mini-windows 'grow-only)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defsubst fg42/statusbar-exit-minibuffer () |
|
|
|
|
"`minibuffer-exit-hook' of fg42/statusbar." |
|
|
|
|
(with-current-buffer fg42/statusbar--minibuffer |
|
|
|
|
(fg42/statusbar--set-buffer-face)) |
|
|
|
|
(setq resize-mini-windows nil)) |
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-display-gui-line t |
|
|
|
|
"Display thin line at the bottom of the window." |
|
|
|
|
:type 'boolean |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
(defvar-local fg42/statusbar--orig-mode-line mode-line-format) |
|
|
|
|
|
|
|
|
|
(defcustom fg42/statusbar-face-attr `(:background ,(face-attribute 'mode-line :background)) |
|
|
|
|
"Plist of face attribute/value pair for fg42/statusbar." |
|
|
|
|
:type '(plist) |
|
|
|
|
:group 'fg42/statusbar) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun fg42/statusbar--set-buffer-face () |
|
|
|
|
"Set buffer default face for current buffer." |
|
|
|
|
(setq fg42/statusbar--face-cookie |
|
|
|
|
(face-remap-add-relative 'default fg42/statusbar-face-attr))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun fg42/statusbar-enable () |
|
|
|
|
"Enable the statusbar." |
|
|
|
|
;; Save mode-line colors when first time. |
|
|
|
|
;; Don't change `fg42/statusbar-mode-line-colors' anymore. |
|
|
|
|
;; (unless fg42/statusbar-mode-line-colors |
|
|
|
|
;; (setq fg42/statusbar-mode-line-colors |
|
|
|
|
;; (list (face-attribute 'mode-line :foreground) |
|
|
|
|
;; (face-attribute 'mode-line :background) |
|
|
|
|
;; (face-attribute 'mode-line :family) |
|
|
|
|
;; (face-attribute 'mode-line :box) |
|
|
|
|
;; (face-attribute 'mode-line-inactive :foreground) |
|
|
|
|
;; (face-attribute 'mode-line-inactive :background) |
|
|
|
|
;; (face-attribute 'mode-line-inactive :family) |
|
|
|
|
;; (face-attribute 'mode-line-inactive :box)))) |
|
|
|
|
|
|
|
|
|
;; (setq fg42/statusbar-mode-line-default-height (face-attribute 'mode-line :height)) |
|
|
|
|
|
|
|
|
|
;; ;; Disable mode line. |
|
|
|
|
;; (set-face-attribute 'mode-line nil |
|
|
|
|
;; :foreground fg42/statusbar-mode-line-active-color |
|
|
|
|
;; :background fg42/statusbar-mode-line-active-color |
|
|
|
|
;; :height 0.1 |
|
|
|
|
;; :box nil) |
|
|
|
|
;; (set-face-attribute 'mode-line-inactive nil |
|
|
|
|
;; :foreground fg42/statusbar-mode-line-inactive-color |
|
|
|
|
;; :background fg42/statusbar-mode-line-inactive-color |
|
|
|
|
;; :height 0.1 |
|
|
|
|
;; :box nil |
|
|
|
|
;; :inherit 'unspecified) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Hide modeline for terminal, or use empty modeline for GUI. |
|
|
|
|
(setq-default fg42/statusbar--orig-mode-line mode-line-format) |
|
|
|
@ -250,9 +223,6 @@ BODY will be supplied with orig-func and args."
@@ -250,9 +223,6 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
(redisplay) |
|
|
|
|
|
|
|
|
|
(advice-add #'message :around #'fg42/statusbar-message-advice) |
|
|
|
|
;; (advice-add #'current-message :around #'fg42/statusbar-current-message-advice) |
|
|
|
|
;; (advice-add #'end-of-buffer :around #'fg42/statusbar-end-of-buffer-advice) |
|
|
|
|
;; (advice-add #'beginning-of-buffer :around #'fg42/statusbar-beginning-of-buffer-advice) |
|
|
|
|
|
|
|
|
|
;; Add update timer. |
|
|
|
|
(setq fg42/statusbar-timer |
|
|
|
@ -265,7 +235,6 @@ BODY will be supplied with orig-func and args."
@@ -265,7 +235,6 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
(add-hook 'post-command-hook #'fg42/statusbar-post-cmd) |
|
|
|
|
|
|
|
|
|
;;(add-hook 'focus-in-hook 'fg42/statusbar-show-info) |
|
|
|
|
;;(add-function :after after-focus-change-function #'fg42/statusbar-show-info) |
|
|
|
|
(add-function :after after-focus-change-function #'fg42/statusbar-display) |
|
|
|
|
|
|
|
|
|
;; read-key-sequence |
|
|
|
@ -292,21 +261,6 @@ BODY will be supplied with orig-func and args."
@@ -292,21 +261,6 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
(defun fg42/statusbar-disable () |
|
|
|
|
"Disable the status bar." |
|
|
|
|
|
|
|
|
|
;; ;; Restore mode-line colors. |
|
|
|
|
;; (set-face-attribute 'mode-line nil |
|
|
|
|
;; :foreground (nth 0 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :background (nth 1 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :family (nth 2 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :box (nth 3 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :height fg42/statusbar-mode-line-default-height) |
|
|
|
|
|
|
|
|
|
;; (set-face-attribute 'mode-line-inactive nil |
|
|
|
|
;; :foreground (nth 4 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :background (nth 5 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :family (nth 6 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :box (nth 7 fg42/statusbar-mode-line-colors) |
|
|
|
|
;; :height fg42/statusbar-mode-line-default-height) |
|
|
|
|
|
|
|
|
|
(setq-default mode-line-format (default-value 'fg42/statusbar--orig-mode-line)) |
|
|
|
|
(when (display-graphic-p) |
|
|
|
|
(let ((face-remaps (default-value 'face-remapping-alist))) |
|
|
|
@ -336,9 +290,6 @@ BODY will be supplied with orig-func and args."
@@ -336,9 +290,6 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
(redisplay) |
|
|
|
|
|
|
|
|
|
(advice-remove #'message #'fg42/statusbar-message-advice) |
|
|
|
|
;; (advice-remove #'current-message #'fg42/statusbar-current-message-advice) |
|
|
|
|
;; (advice-remove #'end-of-buffer #'fg42/statusbar-end-of-buffer-advice) |
|
|
|
|
;; (advice-remove #'beginning-of-buffer #'fg42/statusbar-beginning-of-buffer-advice) |
|
|
|
|
(advice-remove #'read-key-sequence 'fg42/statusbar--read-key-sequence) |
|
|
|
|
(advice-remove #'read-key-sequence-vector 'fg42/statusbar--read-key-sequence-vector) |
|
|
|
|
|
|
|
|
@ -351,8 +302,6 @@ BODY will be supplied with orig-func and args."
@@ -351,8 +302,6 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
(when (timerp fg42/statusbar-timer) |
|
|
|
|
(cancel-timer fg42/statusbar-timer)) |
|
|
|
|
|
|
|
|
|
;;(remove-hook 'focus-in-hook 'fg42/statusbar-show-info) |
|
|
|
|
;;(remove-function after-focus-change-function #'fg42/statusbar-show-info) |
|
|
|
|
(remove-function after-focus-change-function #'fg42/statusbar-display) |
|
|
|
|
|
|
|
|
|
;; Update mode-line. |
|
|
|
@ -367,7 +316,6 @@ BODY will be supplied with orig-func and args."
@@ -367,7 +316,6 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
|
|
|
|
|
(defun fg42/statusbar-build-active-info () |
|
|
|
|
"Collect the information from active components." |
|
|
|
|
|
|
|
|
|
(mapconcat |
|
|
|
|
(lambda (form) |
|
|
|
|
(let ((result (eval form))) |
|
|
|
@ -380,13 +328,6 @@ BODY will be supplied with orig-func and args."
@@ -380,13 +328,6 @@ BODY will be supplied with orig-func and args."
|
|
|
|
|
" ")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; (defun fg42/statusbar-show-info () |
|
|
|
|
;; "Display the status bar when there in no message in echo area." |
|
|
|
|
;; ;; Only flush tray info when current message is empty. |
|
|
|
|
;; (unless (current-message) |
|
|
|
|
;; (fg42/statusbar-flush-info))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun fg42/statusbar-get-frame-width () |
|
|
|
|
"Only calculating a main Frame width, to avoid wrong width when new frame, such |
|
|
|
|
as `snails'." |
|
|
|
@ -396,22 +337,6 @@ as `snails'."
@@ -396,22 +337,6 @@ as `snails'."
|
|
|
|
|
(frame-width))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; (defun fg42/statusbar-flush-info () |
|
|
|
|
;; "Create the string of data for the status bar." |
|
|
|
|
;; (let* ((info (fg42/statusbar-build-active-info))) |
|
|
|
|
;; (with-current-buffer " *Minibuf-0*" |
|
|
|
|
;; (erase-buffer) |
|
|
|
|
;; (insert |
|
|
|
|
;; (concat |
|
|
|
|
;; (make-string (max 0 |
|
|
|
|
;; (- (fg42/statusbar-get-frame-width) |
|
|
|
|
;; (string-width info) |
|
|
|
|
;; fg42/statusbar-info-padding-right)) |
|
|
|
|
;; ?\ ) |
|
|
|
|
;; info))))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun fg42/statusbar-get-echo-format-string (info message-string) |
|
|
|
|
(let* ((blank-length (- (fg42/statusbar-get-frame-width) |
|
|
|
|
(string-width info) |
|
|
|
@ -428,7 +353,6 @@ as `snails'."
@@ -428,7 +353,6 @@ as `snails'."
|
|
|
|
|
(string-width info) |
|
|
|
|
fg42/statusbar-info-padding-right)) ?\ ) |
|
|
|
|
info)))) |
|
|
|
|
|
|
|
|
|
(t message-string)))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -436,13 +360,6 @@ as `snails'."
@@ -436,13 +360,6 @@ as `snails'."
|
|
|
|
|
"Check if time already pass DURATION from SINCE." |
|
|
|
|
(>= (float-time (time-since since)) duration)) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar--msg-message nil |
|
|
|
|
"Store the string from `message'.") |
|
|
|
|
(defvar fg42/statusbar--last-update (current-time)) |
|
|
|
|
(defvar fg42/statusbar--last-change-size (current-time)) |
|
|
|
|
(defvar fg42/statusbar--last-echoed nil) |
|
|
|
|
|
|
|
|
|
(defvar fg42/statusbar--msg nil) |
|
|
|
|
|
|
|
|
|
(defun fg42/statusbar--log (&rest args) |
|
|
|
|
"Log message into message buffer with ARGS as same parameters in `message'." |
|
|
|
@ -515,48 +432,9 @@ When ARG is:
@@ -515,48 +432,9 @@ When ARG is:
|
|
|
|
|
(fg42/statusbar--log "fg42/statusbar: %s\n" err)))))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Wrap `message' make status bar information visible always |
|
|
|
|
;; even other plugins call `message' to flush minibufer. |
|
|
|
|
(defun fg42/statusbar-message-advice (f &rest args) |
|
|
|
|
;; (let ((ret |
|
|
|
|
;; (condition-case err |
|
|
|
|
;; ;; Ignore the errors because collecting the info might raise an error |
|
|
|
|
;; ;; which should not interfier with `message' |
|
|
|
|
;; (cond |
|
|
|
|
;; ;; Don't wrap status info if `fg42/statusbar-active-p' is nil or |
|
|
|
|
;; ;; if variable `inhibit-message' is non-nil. |
|
|
|
|
;; ((or (not fg42/statusbar-active-p) inhibit-message) |
|
|
|
|
;; (apply old-message (cons "E %s" arguments))) |
|
|
|
|
|
|
|
|
|
;; ;; Just flush the bar info if message string is empty. |
|
|
|
|
;; ((not (car arguments)) |
|
|
|
|
;; (progn |
|
|
|
|
;; (apply old-message (cons "A %s" arguments)) |
|
|
|
|
;; (fg42/statusbar-flush-info))) |
|
|
|
|
|
|
|
|
|
;; ;; Otherwise, wrap message string with the info and show it in echo area, |
|
|
|
|
;; ;; logging origin message at `*Messages*' buffer if allowed. |
|
|
|
|
;; (t |
|
|
|
|
;; ;; To debug: just run the below expression in a shell |
|
|
|
|
;; (apply |
|
|
|
|
;; old-message |
|
|
|
|
;; "%s" |
|
|
|
|
;; (list |
|
|
|
|
;; (fg42/statusbar-get-echo-format-string (apply 'format arguments))))))))) |
|
|
|
|
|
|
|
|
|
;; ;; (with-current-buffer (window-buffer (minibuffer-window)) |
|
|
|
|
;; ;; (apply old-message '("here")) |
|
|
|
|
;; ;; (erase-buffer) |
|
|
|
|
;; ;; (insert ret)) |
|
|
|
|
;; (apply #'format (cons "Err %s" arguments)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; ;; Return origin message string. if not, `message' function will always return `nil'. |
|
|
|
|
|
|
|
|
|
;; ;; (when (car arguments) |
|
|
|
|
;; ;; (apply 'format (cons "bla " arguments))) |
|
|
|
|
;; ;; (apply old-message (cons "Err" arguments)) |
|
|
|
|
;; ) |
|
|
|
|
"Wrap `message' make status bar information visible always |
|
|
|
|
even other plugins call `message' to flush minibufer." |
|
|
|
|
(if inhibit-message |
|
|
|
|
(apply f args) |
|
|
|
|
(let* ((inhibit-message t) |
|
|
|
@ -565,23 +443,15 @@ When ARG is:
@@ -565,23 +443,15 @@ When ARG is:
|
|
|
|
|
fg42/statusbar--msg-message))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; (defun fg42/statusbar-current-message-advice (old-func &rest arguments) |
|
|
|
|
;; (let ((message-string (apply old-func arguments))) |
|
|
|
|
;; (if (and message-string fg42/statusbar-last-info) |
|
|
|
|
;; (progn |
|
|
|
|
;; (string-trim-right (replace-regexp-in-string fg42/statusbar-last-info "" message-string))) |
|
|
|
|
;; message-string))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; (defun fg42/statusbar-end-of-buffer-advice (old-func &rest arguments) |
|
|
|
|
;; (apply old-func arguments) |
|
|
|
|
;; (message "")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; (defun fg42/statusbar-beginning-of-buffer-advice (old-func &rest arguments) |
|
|
|
|
;; (apply old-func arguments) |
|
|
|
|
;; (message "")) |
|
|
|
|
;;;###autoload |
|
|
|
|
(define-minor-mode fg42/statusbar-mode |
|
|
|
|
"Super simple status bar for FG42." |
|
|
|
|
:require 'fg42/statusbar-mode |
|
|
|
|
:lighter "SB" |
|
|
|
|
:global t |
|
|
|
|
(if fg42/statusbar-mode |
|
|
|
|
(fg42/statusbar-enable) |
|
|
|
|
(fg42/statusbar-disable))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(provide 'fg42/statusbar) |
|
|
|
|