-
Notifications
You must be signed in to change notification settings - Fork 1
/
emybar.el
98 lines (83 loc) · 2.95 KB
/
emybar.el
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
;;; emybar.el --- -*- lexical-binding: t; -*-
;; Filename: emybar.el
;; Author: Arne Brasseur <[email protected]>
;; Maintainer: Arne Brasseur <[email protected]>
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change Log:
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Copyright (C) 2019 Arne Brasseur
;;
;; 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 GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:
(setq emybar-colors '())
(setq emybar-procs '())
(defun embybar-set (port color)
"Set the COLOR of an emybar based on the PORT"
(setf (cdr (assoc port emybar-colors)) color)
(force-mode-line-update :all))
;; TODO: question, exclamation, quit
(defun emybar-filter (proc color)
"Process filter
Listen to UDP process PROC for a given COLOR. "
(let* ((port (cadr (process-contact proc))))
(emybar-set port color)))
(defun emybar-add-dot (mode-line-format port)
"Prepend the emybar dot to a modeline
Given a MODE_LINE_FORMAT and a PORT, add the dot in the current
color."
(cons
`(:eval
`(:propertize " ●"
font-lock-face
(:foreground ,(map-elt emybar-colors ,port))))
mode-line-format))
(defun emybar (port)
"Start the emybar on a given PORT
Adds the dot to all new and existing buffers, and starts a UDP
server to listen for color updates."
(setq-default mode-line-format
(emybar-add-dot (default-value 'mode-line-format) port))
(mapcar
(lambda (buffer)
(setf (buffer-local-value 'mode-line-format buffer)
(emybar-add-dot (buffer-local-value 'mode-line-format buffer) port)))
(buffer-list))
(setq emybar-colors
(map-insert emybar-colors port "white"))
(setq emybar-procs
(map-insert emybar-procs
port
(make-network-process
:name "emybar"
:type 'datagram
:server t
:family 'ipv4
:service port
:filter #'emybar-filter))))
;; (pop mode-line-format)
;; (mapcar #'delete-process (a-vals emybar-procs))
(provide 'emybar)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; emybar.el ends here