diff options
author | jao <jao@gnu.org> | 2022-08-09 20:19:17 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2022-08-09 20:19:30 +0100 |
commit | 283f388f014e9f160e8656ea786b88b7d94aeb85 (patch) | |
tree | 4a7c391e519b0f513a94af4189549427f97b24b4 /lib | |
parent | 69c443011df3e6739e20327332917ddc9f4cf7dc (diff) | |
download | elibs-283f388f014e9f160e8656ea786b88b7d94aeb85.tar.gz elibs-283f388f014e9f160e8656ea786b88b7d94aeb85.tar.bz2 |
xmobar.el improvements (split string)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/eos/xmobar.el | 70 |
1 files changed, 42 insertions, 28 deletions
diff --git a/lib/eos/xmobar.el b/lib/eos/xmobar.el index 4d27781..c390533 100644 --- a/lib/eos/xmobar.el +++ b/lib/eos/xmobar.el @@ -32,25 +32,15 @@ (eval-when-compile (require 'cl-lib)) +(require 'tab-bar) (require 'xterm-color nil t) -(defvar xmobar--last-update nil - "The last xmobar update received.") - -(defvar xmobar--process nil - "The running xmobar process, if any.") - -(defvar xmobar-string "" - "The xmobar string displayed in the mode-line.") - -(put 'xmobar-string 'risky-local-variable t) - (defgroup xmobar nil "xmobar status display for Emacs." :version "0.0.1" :group 'mode-line) -(defcustom xmobar-command "xmobar" +(defcustom xmobar-command '("xmobar" "-TAnsi") "The xmobar command and flags." :type '(choice (string :tag "Shell Command") (repeat (string)))) @@ -59,35 +49,59 @@ "Whether to dispaly xmobar output in the tab bar." :type 'boolean) -(defcustom xmobar-tab-bar-format '(tab-bar-format-align-right xmobar-string) +(defcustom xmobar-tab-split nil + "Split on this string for `xmobar-left-string' and `xmobar-right-string'." + :type 'string) + +(defcustom xmobar-tab-bar-format + '(xmobar-left-string tab-bar-format-align-right xmobar-right-string) "Format for the tab bar when `xmobar-tab-bar' is t." :type 'list) +(defvar xmobar--process nil + "The running xmobar process, if any.") + +(defvar xmobar--left-string "") + +(defvar xmobar-string "" + "The xmobar string to be displayed in the mode-line or tab-bar.") + +(put 'xmobar-string 'risky-local-variable t) + (defvar xmobar--colorize-fn (if (featurep 'xterm-color) #'xterm-color-filter #'ansi-color-apply)) +(defvar xmobar--old-tab-format tab-bar-format) + (defun xmobar-string () xmobar-string) +(defun xmobar-right-string () xmobar-string) +(defun xmobar-left-string () xmobar--left-string) ;;;###autoload (define-minor-mode xmobar-mode "Display an xmobar in the mode-line." :global t :group 'xmobar (xmobar--stop) - (when xmobar-mode - (if xmobar-tab-bar - (unless (memq 'xmobar-string tab-bar-format) - (setq tab-bar-format xmobar-tab-bar-format) - (tab-bar-mode)) - (or global-mode-string (setq global-mode-string '(""))) - (unless (memq 'xmobar-string global-mode-string) - (setq global-mode-string (append global-mode-string '(xmobar-string))))) - (xmobar--start))) + (if xmobar-mode + (progn (if xmobar-tab-bar + (unless (equal xmobar-tab-bar-format tab-bar-format) + (setq xmobar--old-tab-format tab-bar-format) + (setq tab-bar-format xmobar-tab-bar-format) + (tab-bar-mode 1)) + (or global-mode-string (setq global-mode-string '(""))) + (unless (memq 'xmobar-string global-mode-string) + (setq global-mode-string + (append global-mode-string '(xmobar-string))))) + (xmobar--start)) + (when xmobar-tab-bar (setq tab-bar-format xmobar--old-tab-format)))) (defun xmobar--update (update) "Apply an UPDATE to the xmobar bar." - (setq xmobar--last-update (funcall xmobar--colorize-fn update)) (when xmobar-mode - (setq xmobar-string xmobar--last-update) + (let* ((str (funcall xmobar--colorize-fn update)) + (strs (and xmobar-tab-split (split-string str xmobar-tab-split)))) + (setq xmobar-string (if strs (cadr strs) str) + xmobar--left-string (or (car strs) ""))) (force-mode-line-update t))) (defun xmobar--process-filter (proc string) @@ -112,8 +126,7 @@ If the process has exited, this function stores the exit STATUS in (setq xmobar--process nil) (let ((buf (process-buffer proc))) (when (and buf (buffer-live-p buf)) (kill-buffer buf))) - (setq xmobar--last-update nil - xmobar-string (format "xmobar: %s" status)))) + (setq xmobar-string (format "xmobar: %s" status) xmobar--left-string ""))) (defun xmobar--start () "Start xmobar." @@ -131,13 +144,14 @@ If the process has exited, this function stores the exit STATUS in :filter #'xmobar--process-filter)) (error (setq xmobar-string - (format "starting xmobar: %s" (error-message-string err)))))) + (format "starting xmobar: %s" (error-message-string err)) + xmobar--left-string "")))) (defun xmobar--stop () "Stop xmobar." (when (and xmobar--process (process-live-p xmobar--process)) (delete-process xmobar--process)) - (setq xmobar-string "" xmobar--last-update nil)) + (setq xmobar-string "" xmobar--left-string "")) ;;;###autoload (defun xmobar-restart () |