-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathawesome-tray.el
1374 lines (1198 loc) · 54.9 KB
/
awesome-tray.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
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; awesome-tray.el --- Modular tray bar
;; Filename: awesome-tray.el
;; Description: Modular tray bar
;; Author: Andy Stewart <[email protected]>
;; Maintainer: Andy Stewart <[email protected]>
;; Copyright (C) 2018, Andy Stewart, all rights reserved.
;; Created: 2018-10-07 07:30:16
;; Version: 4.2
;; Last-Updated: 2022-03-01 11:02:39
;; By: Andy Stewart
;; URL: http://www.emacswiki.org/emacs/download/awesome-tray.el
;; Keywords:
;; Compatibility: GNU Emacs 28.1
;;
;; Features that might be required by this library:
;;
;; `cl-lib'
;; `subr-x'
;; `battery'
;;
;;; This file is NOT part of GNU Emacs
;;; License
;;
;; 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, 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; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;; Commentary:
;;
;; Modular tray bar.
;;
;; I don't like mode-line, it's too high, affect me to read the code.
;; With Emacs, we only need to focus on very little information, such as time, current mode, git branch.
;; Excessive information can seriously interfere with our attention.
;;
;;; Installation:
;;
;; Put awesome-tray.el to your load-path.
;; The load-path is usually ~/elisp/.
;; It's set in your ~/.emacs like this:
;; (add-to-list 'load-path (expand-file-name "~/elisp"))
;;
;; And the following to your ~/.emacs startup file.
;;
;; (require 'awesome-tray)
;; (awesome-tray-mode 1)
;;
;; No need more.
;;; Customize:
;;
;; `awesome-tray-mode-line-active-color'
;; `awesome-tray-mode-line-inactive-color'
;; `awesome-tray-active-modules'
;; `awesome-tray-git-update-duration'
;; `awesome-tray-refresh-idle-delay'
;; `awesome-tray-buffer-name-buffer-changed'
;; `awesome-tray-buffer-name-buffer-changed-style'
;; `awesome-tray-input-method-default-style'
;; `awesome-tray-input-method-local-style'
;; `awesome-tray-input-method-local-methods'
;; `awesome-tray-buffer-read-only-style'
;;
;; All of the above can customize by:
;; M-x customize-group RET awesome-tray RET
;;
;;; Change log:
;;
;; 2023/07/06
;; * Make mode-line color indicate buffer state configurable by `awesome-tray-adjust-mode-line-color-enable'.
;;
;; 2023/07/01
;; * Make mode-line color indicate buffer state.
;;
;; 2023/06/30
;; * `awesome-tray-module-location-or-page-info' support EAF PDF Viewer
;;
;; 2023/06/12
;; * Add `awesome-tray-module-location-or-page-info' to show location or pdf page.
;;
;; 2023/06/03
;; * Add `awesome-tray-module-celestial-info' to show moon phase date and sunrise/sunset time.
;; * Add `awesome-tray-location-info-all', `awesome-tray-location-info-top',
;; and `awesome-tray-location-info-bottom' to use custom string for All, Top and Bottom in buffer location info.
;;
;; 2022/03/01
;; * Use overlay re-implement tray information render.
;;
;; 2020/06/18
;; * Shorter date info.
;;
;; 2020/05/06
;; * Just show origin message if got any error, easy to debug.
;;
;; 2020/04/01
;; * Shorter tray info.
;;
;; 2020/02/27
;; * Adapter the latest version of the snails.
;; * Adjust algorithm of `awesome-tray-get-frame-width'.
;;
;; 2020/02/19
;; * Add week info in date.
;;
;; 2020/02/14
;; * Add `awesome-tray-battery-update-duration' to fix `set-mark-command' failed.
;;
;; 2020/02/10
;; * Add battery remaining time.
;;
;; 2020/02/05
;; * Add battery status.
;;
;; 2020/01/05
;; * Hide awesome-tab info if it is too long.
;;
;; 2019/08/20
;; * Use variable `awesome-tray-mode-line-default-height' fix issue #34.
;;
;; 2019/08/14
;; * Remove notify message when toggle awesome-tray status.
;;
;; 2019/08/13
;; * Keep tray info align right when message is very long, thanks QiangF.
;;
;; 2019/07/26
;; * Support snails framework.
;;
;; 2019/07/16
;; * Use `format-mode-line' improve performance of `awesome-tray-module-location-info'.
;;
;; 2019/07/15
;; * Use current-line save value of `line-number-at-pos', improve the performance of `awesome-tray-module-location-info'.
;; * Use `ignore-errors' catch error of awesome-tray.
;;
;; 2019/07/14
;; * Don't wrap awesome-tray info if variable `inhibit-message' is non-nil.
;;
;; 2019/06/23
;; * Support `awesome-tab' group indicator.
;; * Fix crash cause by `awesome-tray-module-awesome-tab-info'
;;
;; 2019/05/08
;; * Disable git modulde default, it have performance when we change buffer too fast.
;;
;; 2019/04/29
;; * Fix position not update when execute command `beginning-of-buffer' or `end-of-buffer'.
;;
;; 2019/04/25
;; * Add 'circe' module displaying circe tracking-buffer modeline info.
;; * The circe module is not activated by default, it's added to `awesome-tray-all-modules'.
;;
;; 2018/11/25
;; * Add `RVM' support.
;; * The rvm module is not activated by default, I move it to `awesome-tray-all-modules'.
;;
;; 2018/11/18
;; * Fix the problem of displaying duplicate information when the mouse is in the minibuffer window.
;;
;; 2018/11/12
;; * Remove Mac color, use hex color instead.
;;
;; 2018/11/03
;; * Add percent information in location module.
;; * Fix error: Not enough arguments for format string.
;;
;; 2018/10/29
;; * Use `unspecified' attribute fix black block of mode-line inactive status.
;; * Add `awesome-tray-git-update-duration' option.
;;
;; 2018/10/21
;; * Use `advice-add' re-implmenet `awesome-tray-message-advice'
;; * Add parent-dir module.
;; * Don't show parent-dir if current mode is `dired-mode'.
;;
;; 2018/10/13
;; * Use `awesome-tray-process-exit-code-and-output' fetch git current branch for better error handling.
;;
;; 2018/10/11
;; * Reimplement `awesome-tray-module-git-info' don't depend on magit.
;; * Add last-command module, handy for debug emacs.
;;
;; 2018/10/09
;; * Add new option `awesome-tray-active-modules'.
;;
;; 2018/10/07
;; * First released.
;; * Add row/column information.
;; * Add `awesome-tray-message-advice' make tray information visible always.
;; * Use `frame-width' instead `window-width' to handle blank characters fill.
;; * Don't fill blank if message string is wider than frame width.
;;
;;; Acknowledgements:
;;
;;
;;
;;; TODO
;;
;;
;;
;;; Require
(require 'cl-lib)
(require 'subr-x)
(require 'battery)
(require 'timer)
(require 'minibuffer)
(require 'overlay)
(require 'vc-git)
(require 'format-spec)
(require 'awesome-tray-faces)
;;; Code:
(defgroup awesome-tray nil
"Modular tray bar."
:group 'awesome-tray)
(defcustom awesome-tray-minibuffer t
"If non-nil, also display the awesome-tray when in the minibuffer."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-second-line nil
"If non-nil, display awesome-tray in a second line.
WARNING! This makes a lot of minibuffer interactions look weird,
disable it if you have any problems with your minibuffer appearence."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-hide-mode-line t
"If non-nil, make the mode-line very thin and highlight it when its active/inactive."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-position 'right
"Position to display awesome-tray.
WARNING! Better to be used with `awesome-tray-second-line' enabled,
This makes a lot of minibuffer interactions look weird,
disable it if you have any problems with your minibuffer appearence."
:group 'awesome-tray
:type 'symbol)
(defcustom awesome-tray-git-show-status t
"If non-nil, display the current file status in the git module."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-evil-show-mode t
"If non-nil, display the current evil mode in the evil module."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-evil-show-macro t
"If non-nil, display the current recording macro in the evil module."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-evil-show-cursor-count t
"If non-nil, display the current multiple cursors count in the evil module."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-meow-show-mode t
"If non-nil, display the current meow mode in the meow module."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-update-interval 1
"Interval in seconds between updating the awesome-tray contents.
If nil, don't update the awesome-tray automatically."
:group 'awesome-tray
:type 'number)
(defcustom awesome-tray-mode-line-active-color "DarkRed"
"Active color."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-mode-line-inactive-color "Gray10"
"Inactive color."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-mode-line-modified-readonly-color "Green"
"Modified + readonly color."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-mode-line-readonly-color "DarkGreen"
"Readonly color."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-mode-line-modified-color "DarkOrange"
"Modified color."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-adjust-mode-line-color-enable nil
"If non-nil, adjust mode-line color when buffer state changes."
:group 'awesome-tray
:type 'boolean)
(defcustom awesome-tray-mode-line-height 0.1
"Height of mode line."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-active-modules
'("location" "belong" "file-path" "mode-name" "battery" "date")
"Default active modules."
:type 'list
:group 'awesome-tray)
(defcustom awesome-tray-essential-modules
'("location" "belong" "file-path")
"Default essential modules, show when minibuffer is too long."
:type 'list
:group 'awesome-tray)
(defcustom awesome-tray-git-update-hooks
'(after-save-hook
after-revert-hook
vc-checkin-hook
text-scale-mode-hook)
"Hook points to update the git module."
:type '(list (hook :tag "HookPoint")
(repeat :inline t (hook :tag "HookPoint"))))
(defcustom awesome-tray-separator " "
"Default string for the separator between modules."
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-location-info-all ""
"Default string indicating buffer all."
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-location-info-top " T"
"Default string indicating buffer top."
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-location-info-bottom " B"
"Default string indicating buffer bottom."
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-ellipsis "…"
"Default string for the ellipsis when something is truncated."
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-date-format "%-m-%-d %-H:%-M %a"
"Format string of the date module."
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-mpd-format "%a - %t"
"Format string of the mpd module.
%t title
%a artist
%A album
%p position on the playlist
%P playlist-length
%f filename without the folder and file extension
%F regular filename"
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-git-format "git:%s"
"Format string of the git module.
%s branch and file status if enabled with `awesome-tray-git-show-status'"
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-location-format "%l:%c %p"
"Format string of the location module.
See `mode-line-format'"
:group 'awesome-tray
:type 'string)
(defcustom awesome-tray-buffer-name-max-length 20
"Max length of buffer name."
:group 'awesome-tray
:type 'int)
(defcustom awesome-tray-mpd-title-max-length 20
"Max length of mpd song title and filename."
:group 'awesome-tray
:type 'int)
(defcustom awesome-tray-file-name-max-length 20
"Max length of file name."
:group 'awesome-tray
:type 'int)
(defcustom awesome-tray-volume-update-duration 5
"Update duration of volume status, in seconds."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-github-update-duration 120
"Update duration of github notification, in seconds."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-github-erase-duration 30
"Github notification time before it gets removed from the bar, in seconds."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-belong-update-duration 5
"Update duration of which class, in seconds."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-battery-update-duration 5
"Update duration of battery status, in seconds.
It will make command `set-mark-command' failed if not use duration."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-refresh-idle-delay 0.5
"Update idle delay of awesome tray, in seconds."
:type 'double
:group 'awesome-tray)
(defcustom awesome-tray-buffer-name-buffer-changed-style "*"
"`awesome-tray-buffer-name-buffer-changed' style."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-buffer-name-buffer-changed nil
"Show the current buffer changes after buffer-name."
:type 'boolean
:group 'awesome-tray)
(defcustom awesome-tray-input-method-default-style ""
"Default input method display style for input-method module."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-input-method-local-style "ZH"
"Local input method display style for input-method module."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-input-method-local-methods
'("rime")
"List of local input methods you want to display `awesome-tray-input-method-local-style'"
:type 'list
:group 'awesome-tray)
(defcustom awesome-tray-buffer-read-only-style "R-O"
"Display style for buffer-read-only module."
:type 'string
:group 'awesome-tray)
(defcustom awesome-tray-file-path-show-filename nil
"Show filename in file-path module or not."
:type 'boolean
:group 'awesome-tray)
(defcustom awesome-tray-file-path-truncated-name-length 1
"In file-path module, how many letters to leave when truncate dirname.
Beginning dots are not counted."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-file-path-full-dirname-levels 2
"In file-path module, how many levels of parent directories should be shown in
their full name."
:type 'integer
:group 'awesome-tray)
(defcustom awesome-tray-info-padding-right 0
"You can customize right padding to avoid awesome-tray wrap sometimes."
:type 'integer
:group 'awesome-tray)
(defvar awesome-tray-text nil
"The text currently displayed in the awesome-tray.")
(defvar awesome-tray-overlays nil
"List of overlays displaying the awesome-tray contents.")
(defvar awesome-tray-before-github-fetch-notification-hook nil
"Hooks before fetching GitHub notifications.
Example:
(add-hook \\='awesome-tray-before-github-fetch-notification-hook
#\\='auth-source-pass-enable)")
(defvar awesome-tray--github-notification-number 0)
(defvar awesome-tray-github-last-time 0)
(defvar awesome-tray-mode-line-colors nil)
(defvar awesome-tray-mpd-command-cache "")
(defvar awesome-tray-git-command-cache "")
(defvar awesome-tray-git-buffer-filename "")
(defvar awesome-tray-belong-last-time 0)
(defvar awesome-tray-belong-last-buffer nil)
(defvar awesome-tray-belong-cache "")
(defvar awesome-tray-battery-status-last-time 0)
(defvar awesome-tray-battery-status-cache "")
(defvar awesome-tray-last-tray-info nil)
(defvar awesome-tray-mode-line-default-height 1)
(defvar awesome-tray-module-alist
'(("awesome-tab" . (awesome-tray-module-awesome-tab-info awesome-tray-module-awesome-tab-face))
("buffer-name" . (awesome-tray-module-buffer-name-info awesome-tray-module-buffer-name-face))
("circe" . (awesome-tray-module-circe-info awesome-tray-module-circe-face))
("date" . (awesome-tray-module-date-info awesome-tray-module-date-face))
("celestial" . (awesome-tray-module-celestial-info awesome-tray-module-celestial-face))
("date" . (awesome-tray-module-date-info awesome-tray-module-date-face))
("evil" . (awesome-tray-module-evil-info awesome-tray-module-evil-face))
("file-path" . (awesome-tray-module-file-path-info awesome-tray-module-file-path-face))
("git" . (awesome-tray-module-git-info awesome-tray-module-git-face))
("last-command" . (awesome-tray-module-last-command-info awesome-tray-module-last-command-face))
("location" . (awesome-tray-module-location-info awesome-tray-module-location-face))
("location-or-page" . (awesome-tray-module-location-or-page-info awesome-tray-module-location-or-page-face))
("parent-dir" . (awesome-tray-module-parent-dir-info awesome-tray-module-parent-dir-face))
("mode-name" . (awesome-tray-module-mode-name-info awesome-tray-module-mode-name-face))
("rvm" . (awesome-tray-module-rvm-info awesome-tray-module-rvm-face))
("battery" . (awesome-tray-module-battery-info awesome-tray-module-battery-face))
("input-method" . (awesome-tray-module-input-method-info awesome-tray-module-input-method-face))
("buffer-read-only" . (awesome-tray-module-buffer-read-only-info awesome-tray-module-buffer-read-only-face))
("belong" . (awesome-tray-module-belong-info awesome-tray-module-belong-face))
("clock" . (awesome-tray-module-clock-info awesome-tray-module-clock-face))
("org-pomodoro" . (awesome-tray-module-org-pomodoro-info awesome-tray-module-org-pomodoro-face))
("pdf-view-page" . (awesome-tray-module-pdf-view-page-info awesome-tray-module-pdf-view-page-face))
("flymake" . (awesome-tray-module-flymake-info nil))
("meow" . (awesome-tray-module-meow-info awesome-tray-module-meow-face))
("mpd" . (awesome-tray-module-mpd-info awesome-tray-module-mpd-face))
("volume" . (awesome-tray-module-volume-info awesome-tray-module-volume-face))
("word-count" . (awesome-tray-module-word-count-info awesome-tray-module-word-count-face))
("anzu" . (awesome-tray-module-anzu-info awesome-tray-module-anzu-face))
("github" . (awesome-tray-module-github-info awesome-tray-module-github-face))
("hostname" . (awesome-tray-module-hostname-info awesome-tray-module-hostname-face))))
(with-eval-after-load 'mu4e-alert
(add-hook 'mu4e-index-updated-hook #'mu4e-alert-update-mail-count-modeline)
(add-hook 'mu4e-message-changed-hook #'mu4e-alert-update-mail-count-modeline)
(advice-add #'mu4e-context-switch :around #'mu4e-alert--context-switch)
(mu4e-alert-update-mail-count-modeline)
(defun awesome-tray-module-mail-info ()
(if (member "all-the-icons" (font-family-list))
(concat (all-the-icons-material "mail" :v-adjust -0.1) ":" (substring mu4e-alert-mode-line 7 -2))
mu4e-alert-mode-line))
(add-to-list 'awesome-tray-module-alist
'("mail" . (awesome-tray-module-mail-info awesome-tray-module-belong-face))))
(defun awesome-tray-module-clock-info ()
(if (org-clocking-p)
(format " [%s] (%s)"
(org-duration-from-minutes
(floor (org-time-convert-to-integer
(org-time-since org-clock-start-time))
60))
org-clock-heading)))
(defun awesome-tray-module-github-info ()
(let ((current-seconds (awesome-tray-current-seconds)))
(if (> (- current-seconds awesome-tray-github-last-time) awesome-tray-github-update-duration)
(progn (setq awesome-tray-github-last-time current-seconds)
(awesome-tray--github-fetch-notifications))
(if (> (- current-seconds awesome-tray-github-last-time) awesome-tray-github-erase-duration)
(setq awesome-tray--github-notification-number 0))
(if (and (numberp awesome-tray--github-notification-number)
(> awesome-tray--github-notification-number 0))
(format "%s github" awesome-tray--github-notification-number)
""))))
(defun awesome-tray--github-fetch-notifications ()
"Fetch GitHub notifications."
(when (require 'async nil t)
(async-start
`(lambda ()
,(async-inject-variables
"\\`\\(load-path\\|auth-sources\\|awesome-tray-before-github-fetch-notification-hook\\)\\'")
(run-hooks 'awesome-tray-before-github-fetch-notification-hook)
(when (require 'ghub nil t)
(with-timeout (10)
(ignore-errors
(when-let* ((username (ghub--username ghub-default-host))
(token (ghub--token ghub-default-host username 'ghub t)))
(ghub-get "/notifications" nil
:query '((notifications . "true"))
:username username
:auth token
:noerror t))))))
(lambda (result)
(message "") ; suppress message
(setq awesome-tray--github-notification-number (length result))))))
(defun awesome-tray-module-hostname-info ()
"Hostname for remote buffers."
(when default-directory
(when-let ((host (file-remote-p default-directory 'host)))
(concat "@" host))))
(defun awesome-tray-module-word-count-info ()
(let ((f-count (count-words (point-min) (point-max))))
(if (region-active-p)
(format "%d/%dW" (count-words-region (region-beginning) (region-end)) f-count)
(format "%dW" f-count))))
(with-eval-after-load 'anzu
(add-hook 'isearch-mode-end-hook #'anzu--reset-status t)
(add-hook 'iedit-mode-end-hook #'anzu--reset-status)
(advice-add #'evil-force-normal-state :after #'anzu--reset-status)
;; Fix matches segment mirroring across all buffers
(mapc #'make-variable-buffer-local
'(anzu--total-matched
anzu--current-position anzu--state anzu--cached-count
anzu--cached-positions anzu--last-command
anzu--last-isearch-string anzu--overflow-p)))
(defun awesome-tray--fix-anzu-count (positions here)
"Calulate anzu count via POSITIONS and HERE."
(cl-loop for (start . end) in positions
collect t into before
when (and (>= here start) (<= here end))
return (length before)
finally return 0))
(defun awesome-tray-module-anzu-info ()
"Show the match index and total number thereof.
Requires `anzu', also `evil-anzu' if using `evil-mode' for compatibility with
`evil-search'."
(if (featurep 'anzu)
(when (and (bound-and-true-p anzu--state)
(not (bound-and-true-p iedit-mode)))
(let ((here anzu--current-position)
(total anzu--total-matched))
(cond ((eq anzu--state 'replace-query)
(format "%d replace" anzu--cached-count))
((eq anzu--state 'replace)
(format "[%d/%d]" here total))
(anzu--overflow-p
(format "%s+" total))
(t
(format "[%s/%d]" here total)))))
""))
(defun awesome-tray-build-active-info ()
(condition-case nil
(mapconcat 'identity (cl-remove-if #'(lambda (n) (equal (length n) 0))
(mapcar 'awesome-tray-get-module-info awesome-tray-active-modules)) awesome-tray-separator)
(format "Awesome Tray broken.")))
(defun awesome-tray-build-essential-info ()
(condition-case nil
(mapconcat 'identity (cl-remove-if #'(lambda (n) (equal (length n) 0))
(mapcar 'awesome-tray-get-module-info awesome-tray-essential-modules)) awesome-tray-separator)
(format "Awesome Tray broken.")))
(defun awesome-tray-get-module-info (module-name)
(let* ((func (ignore-errors (cadr (assoc module-name awesome-tray-module-alist))))
(face-param (ignore-errors (caddr (assoc module-name awesome-tray-module-alist))))
(face (cond ((functionp face-param) (funcall face-param))
((facep face-param) face-param)
(t nil)))
(raw-info (ignore-errors (funcall func)))
(info (ignore-errors (if face (propertize raw-info 'face face) raw-info))))
(if func
(if info
info
(propertize "" 'face face))
(propertize module-name 'face 'awesome-tray-default-face))))
(defun awesome-tray-module-volume-info ()
(if (ignore-errors (require 'volume))
(concat (number-to-string (truncate (volume-get))) "%")
""))
(defun awesome-tray-module-git-info ()
(if (executable-find "git")
(progn
(if (not (string= (buffer-file-name) awesome-tray-git-buffer-filename))
(awesome-tray-git-command-update-cache))
awesome-tray-git-command-cache)
""))
(defun awesome-tray-git-command-update-cache ()
(if (file-exists-p (format "%s" (buffer-file-name)))
(let* ((filename (buffer-file-name))
(status (vc-git-state filename))
(branch (car (vc-git-branches))))
(pcase status
('up-to-date (setq status ""))
('edited (setq status "!"))
('needs-update (setq status "⇣"))
('needs-merge (setq status "⇡"))
('unlocked-changes (setq status ""))
('added (setq status "+"))
('removed (setq status "-"))
('conflict (setq status "="))
('missing (setq status "?"))
('ignored (setq status ""))
('unregistered (setq status "?"))
(_ (setq status "")))
(if (not branch) (setq branch ""))
(setq awesome-tray-git-buffer-filename filename)
(setq awesome-tray-git-command-cache (if awesome-tray-git-show-status
(format awesome-tray-git-format (string-trim (concat branch " " status)))
(format awesome-tray-git-format branch))))
(setq awesome-tray-git-buffer-filename nil
awesome-tray-git-command-cache "")))
(defun awesome-tray-module-circe-info ()
"Display circe tracking buffers"
(if (listp tracking-mode-line-buffers)
(apply 'concat (cl-loop for entry in tracking-mode-line-buffers
collect (or (plist-get entry :propertize) "")))
""))
(defun awesome-tray-module-rvm-info ()
(if (executable-find "rvm-prompt")
(format "rvm:%s" (replace-regexp-in-string
"\n" ""
(nth 1 (awesome-tray-process-exit-code-and-output "rvm-prompt"))))
""))
(defun awesome-tray-module-battery-info ()
(let ((current-seconds (awesome-tray-current-seconds)))
(if (> (- current-seconds awesome-tray-battery-status-last-time) awesome-tray-battery-update-duration)
(let* ((battery-info (funcall battery-status-function))
(battery-type (battery-format "%L" battery-info))
battery-status)
(setq awesome-tray-battery-status-last-time current-seconds)
;; Short battery type.
(cond ((member battery-type '("on-line" "AC"))
(setq battery-type "AC")
(setq battery-status ""))
((member battery-type '("off-line" "BAT" "Battery"))
(setq battery-type "")
(setq battery-status (battery-format
(if (eq system-type 'darwin)
"[%p%%]"
"[%p%% %t]")
battery-info))))
;; Update battery cache.
(setq awesome-tray-battery-status-cache (concat battery-type battery-status)))
awesome-tray-battery-status-cache)))
(defun awesome-tray-module-mode-name-info ()
(car (split-string (format "%s" major-mode) "-mode")))
(defun awesome-tray-module-location-info ()
(if (equal major-mode 'eaf-mode)
""
(string-replace
" All" awesome-tray-location-info-all
(string-replace
" Top" awesome-tray-location-info-top
(string-replace
" Bottom" awesome-tray-location-info-bottom
(format-mode-line awesome-tray-location-format))))))
(defun awesome-tray-module-location-or-page-info ()
"Show Location or PDF page depends on current mode."
(let ((page-info (awesome-tray-module-pdf-view-page-info)))
(if (string= page-info "")
(awesome-tray-module-location-info)
page-info)))
(with-eval-after-load 'libmpdel
(add-hook 'libmpdel-current-playlist-changed-hook 'awesome-tray-mpd-command-update-cache)
(add-hook 'libmpdel-current-song-changed-hook 'awesome-tray-mpd-command-update-cache))
(defun awesome-tray-module-mpd-info ()
(if (and (ignore-errors (require 'libmpdel)) (executable-find "mpd"))
(if (libmpdel-connected-p)
awesome-tray-mpd-command-cache
"not connected to mpd")
""))
(defun awesome-tray-mpd-command-update-cache ()
(let* ((mpd-info (libmpdel-current-song))
(title (or (libmpdel-entity-name mpd-info) ""))
(artist (or (libmpdel-artist-name mpd-info) ""))
(album (or (libmpdel-album-name mpd-info) ""))
(position (or (+ (libmpdel-song-position mpd-info) 1) ""))
(playlist-length (or (libmpdel-playlist-length) ""))
(filename (or (libmpdel-song-file mpd-info) "")))
(setq title (awesome-tray-truncate-string title awesome-tray-mpd-title-max-length))
(setq cut-filename (awesome-tray-truncate-string
(file-name-sans-extension
(replace-regexp-in-string ".*/" "" filename))
awesome-tray-mpd-title-max-length))
(setq filename (awesome-tray-truncate-string filename awesome-tray-mpd-title-max-length))
(setq awesome-tray-mpd-command-cache
(format-spec awesome-tray-mpd-format
(format-spec-make ?t title ?a artist ?A album ?p position
?P playlist-length ?f cut-filename ?F filename)))))
(defun awesome-tray-module-date-info ()
"Displays the date."
(format-time-string awesome-tray-date-format))
(defun awesome-tray-module-celestial-info ()
"Displays lunar phase and sunrise/sunset time."
(with-demoted-errors
""
(if (featurep 'celestial-mode-line)
(substring-no-properties celestial-mode-line-string)
"")))
(defun awesome-tray-module-last-command-info ()
;; Only show last command when user enable `toggle-debug-on-error'.
(when debug-on-error
(format "%s" last-command)))
(defun awesome-tray-module-buffer-name-info ()
(let (bufname)
(setq bufname (if awesome-tray-buffer-name-buffer-changed
(if (and (buffer-modified-p)
(not (eq buffer-file-name nil)))
(concat (buffer-name) awesome-tray-buffer-name-buffer-changed-style)
(buffer-name))
(format "%s" (buffer-name))))
(awesome-tray-truncate-string bufname awesome-tray-buffer-name-max-length t)))
(defun awesome-tray-module-buffer-read-only-info ()
(if (and (eq buffer-read-only t)
(not (eq buffer-file-name nil)))
(format "%s" awesome-tray-buffer-read-only-style)))
(defun awesome-tray-module-input-method-info ()
(format "%s"
(if (eq current-input-method nil)
awesome-tray-input-method-default-style
(if (member current-input-method awesome-tray-input-method-local-methods)
awesome-tray-input-method-local-style
current-input-method-title))))
(defun awesome-tray-module-parent-dir-info ()
(format "%s" (file-name-nondirectory (directory-file-name default-directory))))
(defun awesome-tray-shrink-dir-name (input-string)
(let* ((words (split-string input-string "-"))
(abbreviated-words (mapcar (lambda (word) (substring word 0 (min awesome-tray-file-path-truncated-name-length (length word)))) words)))
(mapconcat 'identity abbreviated-words "-")))
(defun awesome-tray-module-file-path-info ()
(let* ((file-path (split-string (if buffer-file-name buffer-file-name default-directory) "/" t))
(full-num awesome-tray-file-path-full-dirname-levels)
(show-name awesome-tray-file-path-show-filename)
shown-path)
;; Remove file name if `awesome-tray-file-path-show-filename' is nil.
(setq show-path
(if buffer-file-name
(if show-name file-path (butlast file-path))
file-path))
;; Remove redundant directory with `awesome-tray-file-path-full-dirname-levels' value.
(setq show-path (nthcdr (- (length show-path)
(if buffer-file-name
(if show-name (1+ full-num) full-num)
(1+ full-num)))
show-path))
;; Shrink parent directory name to save minibuffer space.
(setq show-path
(append (mapcar #'awesome-tray-shrink-dir-name (butlast show-path))
(last show-path)))
;; Join paths.
(setq show-path (mapconcat #'identity show-path "/"))
show-path))
(defun awesome-tray-module-awesome-tab-info ()
(with-demoted-errors
""
(if (featurep 'awesome-tab)
(let ((tab-info (format "%s" (cdr (awesome-tab-selected-tab (awesome-tab-current-tabset t))))))
(if (> (string-width tab-info) 30)
""
tab-info))
"")))
(defun awesome-tray-module-evil-info ()
(with-demoted-errors
""
(if (featurep 'evil)
(let ((state
(cond ((not awesome-tray-evil-show-mode) "")
((evil-normal-state-p) "<N>")
((evil-emacs-state-p) "<E>")
((evil-insert-state-p) "<I>")
((evil-motion-state-p) "<M>")
((evil-visual-state-p) "<V>")
((evil-operator-state-p) "<O>")
((evil-replace-state-p) "<R>")
(t ""))))
(if awesome-tray-evil-show-macro
(setq state (string-trim (concat (awesome-tray--macro-recording) " " state))))
(if awesome-tray-evil-show-cursor-count
(setq state (string-trim (concat (awesome-tray--count-multiple-cursors) " " state))))
state)
"")))
(defun awesome-tray-module-meow-info ()
(with-demoted-errors
""
(if (and (featurep 'meow) awesome-tray-meow-show-mode)
meow--indicator
"")))
(defun awesome-tray--macro-recording ()
"Display current evil macro being recorded."
(if (featurep 'evil)
(when (or defining-kbd-macro executing-kbd-macro)
(if (bound-and-true-p evil-this-macro)
(format "recording @%s" (char-to-string evil-this-macro))
"Macro"))
""))
(defun awesome-tray--count-multiple-cursors ()
"Show the number of multiple cursors."
(let (count)
(cond ((featurep 'evil-mc) (if (bound-and-true-p evil-mc-cursor-list)
(format "mc:%s" (number-to-string (+ (length evil-mc-cursor-list) 1)))))
((featurep 'multiple-cursors) (if (bound-and-true-p multiple-cursors-mode)
(format "mc:%s" (number-to-string (mc/num-cursors)))))
(t ""))))
(defun awesome-tray-module-belong-info ()
(if (featurep 'treesit)
(let ((current-seconds (awesome-tray-current-seconds)))
(if (or (not (eq (current-buffer) awesome-tray-belong-last-buffer))
(> (- current-seconds awesome-tray-belong-last-time) awesome-tray-belong-update-duration))
(progn
(setq awesome-tray-belong-last-time current-seconds)
(setq awesome-tray-belong-last-buffer (current-buffer))
(awesome-tray-update-belong-cache))
awesome-tray-belong-cache))
""))
(defun awesome-tray-update-belong-cache ()
(setq awesome-tray-belong-cache
(let* ((class-nodes (append (awesome-tray-get-match-nodes '((class_definition name: (symbol) @x)))
(awesome-tray-get-match-nodes '((class_definition name: (identifier) @x)))
(awesome-tray-get-match-nodes '((class_declaration name: (identifier) @x)))
(awesome-tray-get-match-nodes '((class_specifier name: (type_identifier) @x)))))
(function-nodes (append (awesome-tray-get-match-nodes '((function_definition name: (symbol) @x)))
(awesome-tray-get-match-nodes '((function_definition name: (identifier) @x)))
(awesome-tray-get-match-nodes '((function_declarator declarator: (identifier) @x)))
(awesome-tray-get-match-nodes '((method_declaration name: (identifier) @x)))
(awesome-tray-get-match-nodes '((function_declarator declarator: (field_identifier) @x)))))
which-belong-info
which-class-info