summaryrefslogtreecommitdiffstats
path: root/emacs/.emacs.d/site-lisp/my-smt.el
blob: 4c4f6ee0d360e5095cd2c071f3158f2774b3b9a3 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
;;; my-smt.el --- My SVG mode-line theme             -*- lexical-binding: t; -*-

;; Copyright (C) 2014  Tom Willemse

;; Author: Tom Willemse <tom@ryuslash.org>
;; Keywords: faces

;; 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 <http://www.gnu.org/licenses/>.

;;; Commentary:

;;

;;; Code:

(require 'svg-mode-line-themes)
(require 'flycheck)
(require 'cl)

(defun oni-smt-flycheck-errors-text (_)
  "Show an indicator of the number of errors and warnings from flycheck."
  (when flycheck-mode
    (let* ((counts (flycheck-count-errors flycheck-current-errors))
           (err-color (if (smt/window-active-p) "#a85454" "#969696"))
           (warn-color (if (smt/window-active-p) "#a88654" "#969696"))
           (info-color (if (smt/window-active-p) "#5476a8" "#969696"))
           (err-count (alist-get 'error counts 0))
           (warn-count (alist-get 'warning counts 0))
           (info-count (alist-get 'info counts 0)))
      `(tspan " " (tspan :fill ,err-color ,err-count)
              "/" (tspan :fill ,warn-color ,warn-count)
              "/" (tspan :fill ,info-color ,info-count)))))

(smt/defwidget oni-smt-flycheck-errors
  :text #'oni-smt-flycheck-errors-text)

(smt/defwidget my-smt-jabber-activity
  :text (lambda (widget)
          (ignore widget)
          (if (and (smt/window-active-p)
                   (boundp 'jabber-activity-mode-string)
                   (not (equal jabber-activity-mode-string "")))
              (concat jabber-activity-mode-string " "))))

;;; TODO Turn:
;;    #("message: (FORMAT-STRING &rest ARGS)"
;;       0  7 (face font-lock-function-name-face)
;;      10 23 (face eldoc-highlight-function-argument))
;;; into:
;;;  (tspan (tspan :fill (fg-color font-lock-function-name-face) "message:")
;;;         " ("
;;;         (tspan :fill (fg-color highlight-function-argument) "FORMAT-STRING")
;;;         " &rest ARGS)")
(defun my-smt-eldoc-minibuffer-message (format-string &rest args)
  (if (minibufferp)
      (progn
        (add-hook 'minibuffer-exit-hook
                  (lambda () (setq my-smt-eldoc-message nil
                              eldoc-mode-line-string nil
                              eldoc-last-message nil))
                  nil t)
        (setq my-smt-eldoc-message
              (when (stringp format-string)
                (apply 'format format-string args)))
        (force-mode-line-update t))
    (apply 'message format-string args)))

(defvar my-smt-eldoc-message nil)
(smt/defwidget my-smt-eldoc-message
  :text (lambda (widget)
          (ignore widget)
          (when my-smt-eldoc-message
            `(tspan :fill "#bfbfbf" " (" (tspan :fill "#5476a8" ,my-smt-eldoc-message) ")"))))

(defun my-smt-yoshi-title-style (widget)
  "Fill color for either active or inactive windows.

WIDGET is ignored."
  (ignore widget)
  (list :fill (if (smt/window-active-p)
                  "#a85454"
                "#969696")))

(smt/defwidget my-smt-po-counters
  :text (lambda (widget)
          (ignore widget)
          (when (eql major-mode 'po-mode)
            (format " %dt+%df+%du+%do" po-translated-counter
                    po-fuzzy-counter po-untranslated-counter
                    po-obsolete-counter))))

(smt/defwidget my-smt-buffer-identification
  :style 'my-smt-yoshi-title-style
  :text (lambda (widget)
          (ignore widget)
          (concat
           (s-trim
            (substring-no-properties
             (format-mode-line mode-line-buffer-identification)))
           (when (and (or buffer-file-name
                          buffer-offer-save)
                      (buffer-modified-p))
             "*"))))

(smt/defwidget my-smt-current-dictionary
  :text (lambda (widget)
          (ignore widget)
          (if flyspell-mode
              (concat " " (or ispell-current-dictionary
                              ispell-local-dictionary
                              flyspell-default-dictionary)))))

(smt/defwidget my-smt-position
  :text (lambda (widget)
          (ignore widget)
          (format-mode-line "%l/%c:%p")))

(defun my-smt-extra-minor-modes (minor-modes)
  "Add some more info to MINOR-MODES."
  (if (boundp 'evil-state)
      (let ((l (capitalize (elt (symbol-name evil-state) 0))))
        `(tspan ,minor-modes (tspan :fill "#54a875" ,(char-to-string l))))
    minor-modes))

(add-function
 :filter-return
 (symbol-function 'smt/minor-mode-indicator-text)
 #'my-smt-extra-minor-modes)

(smt/defrow my-smt-right
  :prototype 'default-right
  :widgets '(my-smt-jabber-activity
             major-mode
             my-smt-current-dictionary
             oni-smt-flycheck-errors
             version-control minor-modes)
  :margin 16)

(smt/defrow my-smt-left
  :prototype 'default-left
  :widgets '(buffer-info my-smt-buffer-identification my-smt-po-counters
                         which-function my-smt-eldoc-message))

(smt/defrow my-smt-position
  :prototype 'default-position
  :widgets '(my-smt-position))

(defun my-smt-major-mode-style (widget)
  (ignore widget)
  '(:fill "#ccc" :font-family "Fantasque Sans" :filter nil
          :font-weight "bold" :font-style "italic"))

(smt/deftheme my-smt
  :prototype 'black-crystal
  :local-widgets (list (cons 'major-mode
                             (smt/make-widget
                              :prototype 'major-mode
                              :style 'my-smt-major-mode-style)))
  :rows '(my-smt-left my-smt-position my-smt-right))

(add-function :override (symbol-function 'eldoc-minibuffer-message)
              #'my-smt-eldoc-minibuffer-message)

(provide 'my-smt)
;;; my-smt.el ends here