summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--init.el5
-rw-r--r--lib/eos/xmobar.el70
2 files changed, 45 insertions, 30 deletions
diff --git a/init.el b/init.el
index c674d0c..a5977e4 100644
--- a/init.el
+++ b/init.el
@@ -579,6 +579,7 @@
(use-package xmobar
:init (setq xmobar-tab-bar t
+ xmobar-tab-split "*"
xmobar-command '("xmobar-emacs" "-TAnsi")))
;;; Minibuffer
@@ -3175,8 +3176,8 @@
["Window system" :if jao-window-system-p
("w" "set wallpaper" jao-set-wallpaper)
("W" "set radom wallpaper" jao-set-random-wallpaper)
- ("X" "restart xmobar" xmobar-restart :if jao-exwm-enabled-p)
- ("x" "toggle xmobar" xmobar-mode :if jao-exwm-enabled-p)
+ ("X" "toggle xmobar" xmobar-mode :if jao-exwm-enabled-p)
+ ("x" "restart xmobar" xmobar-restart :if jao-exwm-enabled-p)
("x" "kill xmobar" jao-xmobar-kill :if jao-xmonad-enabled-p)]
["Helpers"
("r" "reveal" jao-reveal)
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 ()