-
Notifications
You must be signed in to change notification settings - Fork 2
/
bts.el
4659 lines (4143 loc) · 205 KB
/
bts.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
;;; bts.el --- A unified UI for various bug tracking systems -*- coding: utf-8; -*-
;; Copyright (C) 2015 Hiroaki Otsu
;; Author: Hiroaki Otsu <[email protected]>
;; Keywords: convenience
;; URL: https://github.com/aki2o/emacs-bts
;; Version: 0.1.0
;; Package-Requires: ((widget-mvc "0.0.2") (log4e "0.3.0") (yaxception "0.3.3") (dash "2.9.0") (s "1.9.0") (pos-tip "0.4.5"))
;; 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 file 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:
;;
;; This extension features are
;; - Easily and quickly edit ticket of various bug tracking systems using a unified widget interface
;; - List up ticket summaries with the combination of multiple conditions at one time
;; - Edit the listed multiple tickets at one time
;;
;; You are able to create/update the tickets of a bug tracking system by the following steps.
;; 1. create projects for the system
;; 2. create queries belongs to the project
;; 3. List up the summaries of the fetched tickets from the queries
;; 4. Open details of the tickets, change the properties, and submit them.
;;
;; * Project means a access configuration for the system stores target tickets data
;; * Query means a configuration detects the fetched tickets in the tickets belongs to the project
;; * For handling project, there are `bts:project-new'/`bts:project-update'
;; * For handling query, there are `bts:query-new'/`bts:query-update'
;; * For handling ticket, there are `bts:ticket-new'/`bts:summary-open'
;; * For key binding in widget buffer, see `bts:widget-common-keymap'
;; * For checking other functions, see API section below
;; * For use of this extension, it needs to install the system package (eg. bts-github is for GitHub).
;;
;; For more infomation, see <https://github.com/aki2o/emacs-bts/blob/master/README.md>
;;; Dependencies:
;;
;; - widget-mvc.el ( see <https://github.com/kiwanami/emacs-widget-mvc> )
;; - log4e.el ( see <https://github.com/aki2o/log4e> )
;; - yaxception.el ( see <https://github.com/aki2o/yaxception> )
;; - dash.el ( see <https://github.com/magnars/dash.el> )
;; - s.el ( see <https://github.com/magnars/s.el> )
;; - pos-tip.el
;;; Installation:
;;
;; Put this to your load-path.
;; And put the following lines in your .emacs or site-start.el file.
;;
;; (require 'bts)
;;; Configuration:
;;
;; ;; Key Binding
;; (global-unset-key (kbd "M-b"))
;; (global-set-key (kbd "M-b n") 'bts:ticket-new)
;; (global-set-key (kbd "M-b s") 'bts:summary-open)
;; (global-set-key (kbd "M-b p n") 'bts:project-new)
;; (global-set-key (kbd "M-b p u") 'bts:project-update)
;; (global-set-key (kbd "M-b p d") 'bts:project-remove)
;; (global-set-key (kbd "M-b p D") 'bts:project-remove-all)
;; (global-set-key (kbd "M-b q n") 'bts:query-new)
;; (global-set-key (kbd "M-b q u") 'bts:query-update)
;; (global-set-key (kbd "M-b q d") 'bts:query-remove)
;; (global-set-key (kbd "M-b q D") 'bts:query-remove-all)
;;
;; ;; About other config item, see Customization or eval the following sexp.
;; ;; (customize-group "bts")
;;; Customization:
;;
;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "bts:[^:]" :docstring t)
;; `bts:project-cache-file'
;; Filepath stores user project configurations.
;; `bts:query-cache-file'
;; Filepath stores user query configurations.
;; `bts:preferred-selection-method'
;; Symbol for a preferred feature used for various selection flow.
;; `bts:widget-menu-minibuffer-flag'
;; Value for `widget-menu-minibuffer-flag' in BTS widget buffer.
;; `bts:widget-label-format'
;; Format of label part in BTS widget buffer.
;; `bts:widget-label-prefix'
;; Prefix of label part in BTS widget buffer.
;; `bts:widget-label-suffix'
;; Suffix of label part in BTS widget buffer.
;; `bts:widget-require-mark'
;; String as a mark of requirement in BTS widget buffer.
;; `bts:ticket-fetch-check-interval'
;; Seconds as interval to check the finish of fetching ticket.
;; `bts:ticket-multi-view-preferred'
;; Whether to open a multi view if marked entry is multiple in summary buffer.
;;
;; *** END auto-documentation
;;; API:
;;
;; [EVAL] (autodoc-document-lisp-buffer :type 'function :prefix "bts:[^:]" :docstring t)
;; `bts:show-message'
;; Show message. Arguments are passed to `message'.
;; `bts:make-message'
;; Return a message string. Arguments are passed to `format'.
;; `bts:get-message'
;; Return a message string of MSG-ID registed by `bts:regist-message'.
;; `bts:regist-message'
;; Regist message.
;; `bts:internal-symbol-p'
;; Whether SYM_OR_NAME is a dedicated symbol for BTS.
;; `bts:merge-alist'
;; Merge with ALIST2 overwrite ALIST1.
;; `bts:conv-symbol-to-keyword'
;; Return a keyword of SYMBOL. eg. 'hoge -> :hoge
;; `bts:conv-keyward-to-symbol'
;; Return a symbol of KEYWORD. eg. :hoge -> 'hoge
;; `bts:make-seconds'
;; Return a float number of seconds since the epoch
;; `bts:make-alist-from-plist'
;; Return the alist made from PLIST using include/exclude option.
;; `bts:make-plist-from-alist'
;; Return the plist made from ALIST using include/exclude option.
;; `bts:widget-get-local-attribute'
;; Return a local attribute identified by NAME.
;; `bts:widget-get-local-attributes'
;; Return all local attributes.
;; `bts:widget-set-local-attribute'
;; Set VALUE to a local attribute identified by NAME.
;; `bts:widget-goto'
;; Move to a widget identified by NAME.
;; `bts:widget-get-by-name'
;; Return a widget identified by NAME.
;; `bts:widget-get-name-at'
;; Return name of a widget at POS.
;; `bts:widget-get-index-at'
;; Return index of a widget at POS.
;; `bts:widget-get-name-by-index'
;; Return name of a widget identified by INDEX.
;; `bts:widget-exist-p'
;; Whether a widget exists identified by NAME.
;; `bts:widget-exist-flex-p'
;; Whether a flex widget exists identified by NAME in flex INDEX.
;; `bts:widget-get-model'
;; Return current model.
;; `bts:widget-get-flex-models'
;; Return current flex models.
;; `bts:widget-get-value'
;; Return value of a widget identified by NAME.
;; `bts:widget-get-init-value'
;; Return initialized value of a widget identified by NAME.
;; `bts:widget-get-flex-value'
;; Return value of a flex widget identified by NAME in flex INDEX.
;; `bts:widget-get-flex-init-value'
;; Return initialized value of a flex widget identified by NAME in flex INDEX.
;; `bts:widget-get-flex-last-index'
;; Return current max value of flex index.
;; `bts:widget-get-flex-current-index'
;; Return current value of flex index.
;; `bts:widget-expand-flex-layout'
;; Compile flex layout and return the result.
;; `bts:widget-build-buffer'
;; Setup a widget buffer.
;; `bts:widget-update-buffer'
;; Re build a widget buffer of BUFFER-OR-NAME.
;; `bts:widget-validation-uniq'
;; Validate widget value is uniq.
;; `bts:system-regist'
;; Regist SYSTEM as a bug tracking system.
;; `bts:system-get'
;; Return a structure of `bts:system' from SYSNM.
;; `bts:project-p'
;; Whether PROJECT is a project configuration.
;; `bts:project-get-config-all'
;; Return all project configurations.
;; `bts:project-get-config-by-id'
;; Return a project configuration of PROJID.
;; `bts:project-get-config-by-name'
;; Return a project configuration of PROJNM/SYSNM.
;; `bts:project-get-config-name'
;; Return a name of PROJECT.
;; `bts:project-get-system'
;; Return a `bts:system' object of PROJECT.
;; `bts:project-get-unique-string'
;; Return a unique string of PROJECT.
;; `bts:project-store-config'
;; Store a project configuration as PROP of PROJID into `bts:project-cache-file'.
;; `bts:project-delete-config'
;; Delete a project configuration of PROJNM/SYSNM in `bts:project-cache-file'.
;; `bts:query-p'
;; Whether QUERY is a query configuration.
;; `bts:query-get-config-all'
;; Return all query configurations belongs to all projects or PROJECT.
;; `bts:query-get-config-by-id'
;; Return a query configuration of QUERYID.
;; `bts:query-get-config-by-name'
;; Return a query configuration of QUERYNM belongs to PROJECT.
;; `bts:query-get-config-name'
;; Return a name of QUERY.
;; `bts:query-get-project'
;; Return a project configuration of QUERY.
;; `bts:query-get-unique-string'
;; Return a unique string of QUERY.
;; `bts:query-get-description'
;; Return a description string of QUERY.
;; `bts:query-store-config'
;; Store a query configuration as QUERY of QUERYID belongs to PROJECT into `bts:query-cache-file'.
;; `bts:query-delete-config'
;; Delete a query configuration of QUERYNM belongs to PROJECT in `bts:query-cache-file'.
;; `bts:query-delete-config-all'
;; Delete all query configurations belongs to PROJECT in `bts:query-cache-file'.
;; `bts:ticket-p'
;; Whether TICKET is a ticket data.
;; `bts:ticket-get-project'
;; Return the project configuration TICKET belongs to.
;; `bts:ticket-get-system'
;; Return a `bts:system' object TICKET belongs to.
;; `bts:ticket-get-unique-string'
;; Return a unique string of TICKET.
;; `bts:ticket-belong-to-same-project-p'
;; Whether all of TICKETS belongs to same project.
;; `bts:ticket-get-latest'
;; Return a latest data of TICKET.
;; `bts:ticket-simple-update'
;; Update TICKET about all non-nil properties in MODEL.
;; `bts:ticket-multi-update'
;; Update TICKET about non-nil and not empty properties in MODEL.
;; `bts:ticket-setup-conflict-buffer'
;; Setup a conflict display buffer.
;; `bts:ticket-resolve-conflict'
;; Update TICKET by asking user how to handle the property in CONFLICTS.
;; `bts:ticket-open-add-view'
;; Popup a widget buffer for creating a new ticket of PROJECT.
;; `bts:ticket-open-update-view'
;; Popup a widget buffer for updating TICKETS.
;; `bts:ticket-fetch'
;; Start to fetch ticket using QUERIES and the task checkes the finish.
;; `bts:ticket-fetch-failed'
;; Inform the fail of fetching ticket using QUERY to the task checkes the finish.
;; `bts:ticket-fetch-complete'
;; Inform the complete of fetching ticket using QUERY to the task checkes the finish.
;; `bts:complex-condition-compile'
;; Return a `bts:complex-condition' object or a string made from V.
;; `bts:complex-condition-match-to-list'
;; Whether to match any entry of CHECK-VALUES to CONDITION.
;; `bts:complex-condition-match-to-string'
;; Whether to match CHECK-VALUE to CONDITION.
;; `bts:complex-condition-validation'
;; Validate widget value is a complex condition.
;;
;; *** END auto-documentation
;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "bts:[^:]" :docstring t)
;; `bts:widget-forward'
;; Move to a forward widget using `pophint:do' or `widget-forward'.
;; `bts:widget-backward'
;; Move to a backward widget using `pophint:do' or `widget-backward'.
;; `bts:widget-jump'
;; Jump to any widget using `pophint:do'.
;; `bts:widget-submit'
;; Press a submit button.
;; `bts:widget-cancel'
;; Press a cancel button.
;; `bts:project-new'
;; Popup a widget buffer for creating a new project configuration for SYSTEM.
;; `bts:project-update'
;; Popup a widget buffer for updating PROJECT.
;; `bts:project-remove'
;; Remove PROJECT with confirm.
;; `bts:project-remove-all'
;; Remove all project configurations with confirm.
;; `bts:query-new'
;; Popup a widget buffer for creating a new query configuration belongs to PROJECT.
;; `bts:query-update'
;; Popup a widget buffer for updating QUERY.
;; `bts:query-remove'
;; Remove QUERY with confirm.
;; `bts:query-remove-all'
;; Remove all query configurations with confirm.
;; `bts:ticket-fetch-quit'
;; Quit the running tasks fetches ticket.
;; `bts:summary-right-column'
;; Move to right column.
;; `bts:summary-left-column'
;; Move to left column.
;; `bts:summary-reload-all'
;; Re fetch and setup current buffer.
;; `bts:summary-reload-ticket'
;; Update marked entries or current entry to the latest data.
;; `bts:summary-view-ticket'
;; Popup a widget buffer for updating marked entries or current entry.
;; `bts:summary-mark-ticket'
;; Put a mark to current entry.
;; `bts:summary-unmark-ticket'
;; Remove a mark of current entry.
;; `bts:summary-toggle-ticket-marking'
;; Switch a mark situation of current entry.
;; `bts:summary-mark-all-tickets'
;; Put marks to all entries.
;; `bts:summary-unmark-all-tickets'
;; Remove the marks of all entries.
;; `bts:summary-toggle-all-tickets-marking'
;; Switch the mark situations of all entries.
;; `bts:summary-open'
;; Setup a summary buffer for QUERIES and switch current buffer to that.
;; `bts:ticket-new'
;; Regist a new ticket of PROJECT.
;;
;; *** END auto-documentation
;; [Note] Functions and variables other than listed above, Those specifications may be changed without notice.
;;; Tested On:
;;
;; - Emacs ... GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.4.2) of 2014-02-22 on chindi10, modified by Debian
;; - widget-mvc.el ... Version 0.0.2
;; - log4e.el ... Version 0.3.0
;; - yaxception.el ... Version 0.3.3
;; - dash.el ... Version 2.9.0
;; - s.el ... Version 1.9.0
;; - pos-tip.el ... Version 0.4.5
;; Enjoy!!!
;;; Code:
(require 'cl-lib)
(require 'plstore)
(require 'wid-edit)
(require 'tabulated-list)
(require 'hl-line)
(require 'widget-mvc)
(require 'log4e)
(require 'yaxception)
(require 'dash)
(require 's)
(require 'pos-tip)
(require 'pophint-config nil t)
(defgroup bts nil
"A unified UI for various bug tracking systems."
:group 'convenience
:prefix "bts:")
(defcustom bts:project-cache-file (concat user-emacs-directory ".bts-project")
"Filepath stores user project configurations."
:type 'string
:group 'bts)
(defcustom bts:query-cache-file (concat user-emacs-directory ".bts-query")
"Filepath stores user query configurations."
:type 'string
:group 'bts)
(defcustom bts:preferred-selection-method 'helm
"Symbol for a preferred feature used for various selection flow."
:type '(choice (const helm)
(const anything)
(const default)
(const nil))
:group 'bts)
(defcustom bts:widget-menu-minibuffer-flag t
"Value for `widget-menu-minibuffer-flag' in BTS widget buffer."
:type 'boolean
:group 'bts)
(defcustom bts:widget-label-format " %s "
"Format of label part in BTS widget buffer."
:type 'string
:group 'bts)
(defcustom bts:widget-label-prefix " "
"Prefix of label part in BTS widget buffer."
:type 'string
:group 'bts)
(defcustom bts:widget-label-suffix " "
"Suffix of label part in BTS widget buffer."
:type 'string
:group 'bts)
(defcustom bts:widget-require-mark "*"
"String as a mark of requirement in BTS widget buffer."
:type 'string
:group 'bts)
(defcustom bts:ticket-fetch-check-interval 3
"Seconds as interval to check the finish of fetching ticket."
:type 'number
:group 'bts)
(defcustom bts:ticket-multi-view-preferred t
"Whether to open a multi view if marked entry is multiple in summary buffer.
View means a widget buffer for create/update of ticket.
Multi view is able to update multiple tickets by only one submit.
If this value is nil or multi view is not defined in `bts:system',
instead open views for each of selected tickets."
:type 'boolean
:group 'bts)
(defface bts:widget-button-face
'((((type x w32 ns) (class color))
:box (:line-width 2 :style released-button)
:background "lightgrey" :foreground "black"))
"Face for `widget-button-face' in BTS widget buffer."
:group 'bts)
(defface bts:widget-button-pressed-face
'((((type x w32 ns) (class color))
:box (:line-width 2 :style pressed-button)
:background "lightgrey" :foreground "black")
(t
:inverse-video t))
"Face for `widget-button-pressed-face' in BTS widget buffer."
:group 'bts)
(defface bts:widget-mouse-face
'((((type x w32 ns) (class color))
:box (:line-width 2 :style released-button)
:background "grey90" :foreground "black")
(t
:inverse-video t))
"Face for `widget-mouse-face' in BTS widget buffer."
:group 'bts)
(defface bts:widget-link-face
'((t :inherit link))
"Face for a link part in BTS widget buffer."
:group 'bts)
(defface bts:widget-documentation-face
'((t nil))
"Face for `widget-documentation-face' in BTS widget buffer."
:group 'bts)
(defface bts:widget-label-face
'((((class color) (background dark)) (:background "azure" :foreground "black" :box "sky blue"))
(((class color) (background light)) (:background "gray10" :foreground "white" :box "white"))
(t (:background "azure" :foreground "black" :box "sky blue")))
"Face for a label part in BTS widget buffer."
:group 'bts)
(defface bts:widget-require-face
'((t (:foreground "red")))
"Face for `bts:widget-require-mark' in BTS widget buffer."
:group 'bts)
(defface bts:widget-const-face
'((t nil))
"Face for a const widget in BTS widget buffer."
:group 'bts)
(defface bts:widget-tip-face
'((t (:foreground "black" :background "khaki1")))
"Face for a popup tip in BTS widget buffer."
:group 'bts)
(defface bts:summary-condition-warn-part-face
'((t (:foreground "red" :bold t)))
"Face for a warning notice in mode line of summary buffer."
:group 'bts)
(defface bts:summary-condition-fetch-part-face
'((t (:foreground "tomato" :bold t)))
"Face for a fetching notice in mode line of summary buffer."
:group 'bts)
(defface bts:summary-condition-grep-part-face
'((t (:foreground "black" :background "sky blue")))
"Face for a grepping notice in mode line of summary buffer."
:group 'bts)
(defface bts:summary-condition-marked-part-face
'((t (:foreground "black" :background "misty rose")))
"Face for a marking notice in mode line of summary buffer."
:group 'bts)
(defface bts:summary-condition-query-part-face
'((t (:foreground "black" :background "misty rose")))
"Face for a queries notice in mode line of summary buffer."
:group 'bts)
(defface bts:summary-mark-face
'((t (:background "forest green")))
"Face for a mark in summary buffer."
:group 'bts)
(defface bts:summary-closed-ticket-face
'((t (:inherit font-lock-comment-face)))
"Face for a closed ticket entry in summary buffer."
:group 'bts)
(defface bts:summary-ignored-ticket-face
'((t (:inherit dired-ignored)))
"Face for a ignored ticket entry in summary buffer."
:group 'bts)
(defface bts:ticket-regist-message-succeed-face
'((t (:foreground "lime green" :bold t)))
"Face for a succeed counts in a finish notice of all registrations."
:group 'bts)
(defface bts:ticket-regist-message-skipped-face
'((t (:foreground "khaki" :bold t)))
"Face for a skipped counts in a finish notice of all registrations."
:group 'bts)
(defface bts:ticket-regist-message-failed-face
'((t (:foreground "red" :bold t)))
"Face for a failed counts in a finish notice of all registrations."
:group 'bts)
(log4e:deflogger "bts" "%t [%l] %m" "%H:%M:%S" '((fatal . "fatal")
(error . "error")
(warn . "warn")
(info . "info")
(debug . "debug")
(trace . "trace")))
;; WARN: trace level might happen high memory consumption
(bts--log-set-level 'info)
;;;;;;;;;;;;;
;; Utility
(defvar bts::max-specpdl-size-bkup nil)
(defmacro bts::set-alist-value (alist key value)
(declare (indent 0))
`(setq ,alist (loop for (k . v) in ,alist
if (eq k ,key) collect (cons k ,value)
else collect (cons k v))))
(defmacro bts:awhen (test &rest body)
(declare (indent 1))
`(let ((it ,test)) (when it ,@body)))
(defmacro bts:aif (test then &rest else)
(declare (indent 2))
`(let ((it ,test)) (if it ,then ,@else)))
(defun bts:show-message (msg &rest args)
"Show message. Arguments are passed to `message'."
(apply 'message (concat "[BTS] " msg) args)
nil)
(defun bts:make-message (msg &rest args)
"Return a message string. Arguments are passed to `format'."
(apply 'format (concat "[BTS] " msg) args))
(defun bts:get-message (msg-id &rest args)
"Return a message string of MSG-ID registed by `bts:regist-message'."
(apply 'wmvc:get-text nil msg-id args))
(defun bts:regist-message (msg-id &rest lang-values)
"Regist message.
MSG-ID is a symbol which is passed to `bts:get-message'.
LANG-VALUES is a pair list of lang-id/lang-message.
- lang-id is a symbol to pass to `wmvc:lang-register-messages'.
- lang-message is a string as a shown value.
Example:
(bts:regist-message 'hello t \"Hello!\" 'Japanese \"こんにちは\" ...)"
(declare (indent 1))
;; No check msg-id exists
;; (when (assq msg-id (assq t wmvc:lang-messages))
;; (error "failed regist messages : id is already registed"))
(loop for (lang-id value) on lang-values by 'cddr
do (wmvc:lang-register-messages lang-id (list msg-id value))))
(yaxception:deferror 'bts:error nil "%s" 'msg)
(yaxception:deferror 'bts:invalid-argument 'bts:error 'bts::invalid-argument-msg)
(bts:regist-message 'bts-invalid-argument
t "Invalid argument. For check the reason, enable and open log"
'Japanese "不正な引数が渡されました。詳細はログを有効にして確認して下さい")
(defun bts::invalid-argument-msg ()
(bts:get-message 'bts-invalid-argument))
(bts:regist-message 'bts-no-candidates
t "Any %s is nothing"
'Japanese "%sが一つもありません")
(defun* bts::select-something (&key description candidates method multiple require default no-error)
(bts--debug* "start select something. description[%s] method[%s] multiple[%s] require[%s] default[%s] no-error[%s]"
description method multiple require default no-error)
(when (and (not no-error)
(not candidates))
(yaxception:throw
'bts:error
:msg (bts:get-message 'bts-no-candidates (downcase description))))
(let* ((pref (or method bts:preferred-selection-method))
(mtd (or (when (and (eq pref 'helm) (featurep 'helm)) 'helm)
(when (and (eq pref 'anything) (featurep 'anything)) 'anything)
(when (eq pref 'default) 'completing-read)
(when (featurep 'helm) 'helm)
(when (featurep 'anything) 'anything)
'completing-read))
(src `((name . ,description)
(candidates . ,candidates)
(candidate-number-limit . 999)
(action . (lambda (cand)
(or (when (not ,multiple) cand)
(when (eq ',mtd 'helm) (helm-marked-candidates))
(when (eq ',mtd 'anything) (anything-marked-candidates))
(list cand))))))
(args (case mtd
(helm `(:sources ,src))
(anything `(:sources ,src))
(completing-read `(,(concat description ": ") ,candidates nil t nil '() ,default))))
(selected (loop while t
for selected = (apply mtd args)
if selected return selected
if (not require) return selected
do (progn (bts:show-message "Have to select something")
(sleep-for 2)))))
(bts--info "finished select something : %s" selected)
(if (and multiple
(not (listp selected)))
(progn (bts--debug "convert result of select something to list")
(list selected))
selected)))
(defvar bts::regexp-secret-property "\\`:secret-")
(defun bts::has-secret-property (plist)
(loop for (k v) on plist by 'cddr
for s = (symbol-name k)
if (string-match bts::regexp-secret-property s)
return t))
(defun bts::pick-up-normal-properties (plist)
(loop for (k v) on plist by 'cddr
for s = (symbol-name k)
if (not (string-match bts::regexp-secret-property s))
append (progn (bts--trace "picked up normal property : %s" k)
(list k v))))
(defun bts::pick-up-secret-properties (plist)
(loop for (k v) on plist by 'cddr
for s = (symbol-name k)
for real-name = (replace-regexp-in-string bts::regexp-secret-property "" s)
if (not (string= s real-name))
append (progn (bts--trace "picked up secret property : %s" k)
`(,(intern (concat ":" real-name)) ,v))))
(defsubst bts::plstore-load (plstore-sym store-file &optional force)
(when (or force
(not (symbol-value plstore-sym))
(not (buffer-live-p (plstore--get-buffer (symbol-value plstore-sym)))))
(yaxception:$
(yaxception:try
(bts--debug "try to load plstore from %s into %s" store-file plstore-sym)
(bts:aif (symbol-value plstore-sym)
(progn (bts--info "revert current plstore : %s" plstore-sym)
(plstore-revert it))
(bts--info "open plstore from %s" store-file)
(set plstore-sym (plstore-open (expand-file-name store-file)))
(bts--debug "loaded plstore from %s into %s" store-file plstore-sym)))
(yaxception:catch 'end-of-buffer e
(bts--warn "try to init %s because it's broken" store-file)
(bts:awhen (symbol-value plstore-sym)
(plstore-close it)
(set plstore-sym nil))
(delete-file store-file)
(set plstore-sym (plstore-open (expand-file-name store-file)))
(bts--debug "loaded inited plstore from %s into %s" store-file plstore-sym)))))
(defsubst bts::plstore-save (plstore key value)
(bts--debug "start plstore save value of %s into %s"
key (ignore-errors (plstore-get-file plstore)))
(let* ((normal-value (bts::pick-up-normal-properties value))
(secret-value (bts::pick-up-secret-properties value)))
(plstore-put plstore key normal-value secret-value)
(plstore-save plstore)
(bts--info "finished plstore save value of %s into %s"
key (plstore-get-file plstore))))
(defsubst bts::plstore-remove (plstore key)
(bts--debug "start plstore remove value of %s from %s"
key (ignore-errors (plstore-get-file plstore)))
(plstore-delete plstore key)
(plstore-save plstore)
(bts--info "finished plstore remove value of %s from %s"
key (plstore-get-file plstore)))
(defsubst bts::plstore-clear (plstore-sym)
(bts--debug "start plstore clear and delete %s"
(ignore-errors (plstore-get-file (symbol-value plstore-sym))))
(when (symbol-value plstore-sym)
(let ((file (ignore-errors
(expand-file-name (plstore-get-file (symbol-value plstore-sym))))))
(plstore-close (symbol-value plstore-sym))
(set plstore-sym nil)
(when (file-exists-p file)
(bts--debug "try to delete %s" file)
(delete-file file))
(bts--info "finished plstore clear and delete %s" file))))
(defun bts:internal-symbol-p (sym_or_name)
"Whether SYM_OR_NAME is a dedicated symbol for BTS."
(string-match "\\`bts-" (if (symbolp sym_or_name)
(symbol-name sym_or_name)
sym_or_name)))
(defun bts:merge-alist (alist1 alist2)
"Merge with ALIST2 overwrite ALIST1."
(append (loop for e in alist1
for k = (car e)
if (not (assq k alist2)) collect e)
alist2))
(defun bts:conv-symbol-to-keyword (symbol)
"Return a keyword of SYMBOL. eg. 'hoge -> :hoge"
(intern (concat ":" (symbol-name symbol))))
(defun bts:conv-keyward-to-symbol (keyword)
"Return a symbol of KEYWORD. eg. :hoge -> 'hoge"
(intern (replace-regexp-in-string "\\`:" "" (symbol-name keyword))))
(defun bts:make-seconds (decoded-time duration &optional backward)
"Return a float number of seconds since the epoch
as the time away DURATION from DECODED-TIME.
DECODED-TIME is a list as argument for `encode-time'. If nil, means `current-time'.
DURATION is a string as argument for `timer-duration'. If nil, means '0sec'.
If BACKWARD is non-nil, time calculation is done to backward."
(bts--trace "start make seconds. decoded-time[%s] duration[%s] backward[%s]"
decoded-time duration backward)
(let* ((seconds (float-time (bts:awhen decoded-time
(apply 'encode-time it))))
(duration-seconds (if duration
(timer-duration duration)
0))
(seconds-calculator (if backward '- '+))
(ret (funcall seconds-calculator seconds duration-seconds)))
(bts--trace "made seconds : %s" ret)
ret))
(defun* bts:make-alist-from-plist (plist &key
includes include-regexp include-function
excludes exclude-regexp exclude-function)
"Return the alist made from PLIST using include/exclude option.
PLIST is a plist like project/query/ticket.
For including,
INCLUDES is a list of symbols as property.
INCLUDE-REGEXP is the regexp matches property name.
INCLUDE-FUNCTION is the function receives a symbol as property and should return non-nil if it's a included one.
For excluding ( prior than include options ),
EXCLUDES is a list of symbols as property.
EXCLUDE-REGEXP is the regexp matches property name.
EXCLUDE-FUNCTION is the function receives a symbol as property and should return non-nil if it's a excluded one.
If any options is nothing, all properties is included."
(loop for k in (loop for (p v) on plist by 'cddr
collect (bts:conv-keyward-to-symbol p))
for s = (symbol-name k)
for p = (bts:conv-symbol-to-keyword k)
for exclude-p = (or (bts:internal-symbol-p s)
(and excludes (memq k excludes))
(and exclude-regexp (string-match exclude-regexp s))
(and exclude-function (funcall exclude-function k)))
for include-p = (or (and includes (memq k includes))
(and include-regexp (string-match include-regexp s))
(and include-function (funcall include-function k))
(and (not includes)
(not include-regexp)
(not include-function)))
if (and (not exclude-p) include-p)
collect (cons k (plist-get plist p))))
(defun* bts:make-plist-from-alist (alist &key
includes include-regexp include-function
excludes exclude-regexp exclude-function)
"Return the plist made from ALIST using include/exclude option.
ALIST is a alist like model.
For including,
INCLUDES is a list of symbols as key.
INCLUDE-REGEXP is the regexp matches key name.
INCLUDE-FUNCTION is the function receives a symbol as key and should return non-nil if it's a included one.
For excluding ( prior than include options ),
EXCLUDES is a list of symbols as key.
EXCLUDE-REGEXP is the regexp matches key name.
EXCLUDE-FUNCTION is the function receives a symbol as key and should return non-nil if it's a excluded one.
If any options is nothing, all keys is included."
(loop for k in (mapcar 'car alist)
for s = (if k (symbol-name k) "")
for p = (bts:conv-symbol-to-keyword k)
for exclude-p = (or (string= s "")
(bts:internal-symbol-p s)
(and excludes (memq k excludes))
(and exclude-regexp (string-match exclude-regexp s))
(and exclude-function (funcall exclude-function k)))
for include-p = (or (and includes (memq k includes))
(and include-regexp (string-match include-regexp s))
(and include-function (funcall include-function k))
(and (not includes)
(not include-regexp)
(not include-function)))
if (and (not exclude-p) include-p)
append (list p (assoc-default k alist))))
;;;;;;;;;;;;
;; Widget
(defvar bts:widget-common-keymap
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-n") 'bts:widget-forward)
(define-key map (kbd "C-p") 'bts:widget-backward)
(define-key map (kbd "C-M-j") 'bts:widget-jump)
(define-key map (kbd "M-RET") 'bts:widget-submit)
(define-key map (kbd "M-DEL") 'bts:widget-cancel)
map)
"Keymap as base for any widget keymaps.")
(defvar bts:widget-keymap nil)
(defvar bts:widget-field-keymap nil)
(defvar bts:widget-text-keymap nil)
(defvar bts:widget-date-keymap nil)
(defun bts::wid-setup-keymap ()
(loop for (kmap . parentmap) in '((bts:widget-keymap . widget-keymap)
(bts:widget-field-keymap . widget-field-keymap)
(bts:widget-text-keymap . widget-text-keymap)
(bts:widget-date-keymap . date-field-keymap))
if (and (not (keymapp (symbol-value kmap)))
(boundp parentmap)
(keymapp (symbol-value parentmap)))
do (let ((map (copy-keymap bts:widget-common-keymap)))
(bts--debug "start setup keymap %s from %s" kmap parentmap)
(set-keymap-parent map (symbol-value parentmap))
(set kmap map))))
(defun bts::wid-show-help (value)
(yaxception:$
(yaxception:try
(bts--trace "start wid show help.\nvalue... %s" value)
(cond ((bufferp value)
(display-buffer value))
((stringp value)
(pos-tip-show value 'bts:widget-tip-face nil nil 300))))
(yaxception:catch 'error e
(bts--error "failed wid show help : %s\n%s"
(yaxception:get-text e) (yaxception:get-stack-trace-string e))
(bts:show-message "Failed to show widget help : %s" (yaxception:get-text e)))))
(defsubst bts::wid-parts-p (parts)
(and (listp parts)
(bts:awhen (plist-get parts :type)
(symbolp it))))
(defsubst bts::wid-named-parts-p (parts)
(and (bts::wid-parts-p parts)
(bts:awhen (plist-get parts :name)
(symbolp it))))
(defsubst bts::wid-wmvc-widget-item-p (e)
(and (consp e)
(bts:awhen (ignore-errors (plist-get (cdr e) :name))
(symbolp it))))
(defsubst bts::wid-get-wmvc-widget-property (e)
(cdr e))
(defun bts::wid-get-label-max-width (clayout)
(loop with maxwidth = 0
for e in clayout
for width = (cond ((not (bts::wid-parts-p e))
0)
((plist-get e :unarrayed)
0)
((plist-get e :label-width)
(plist-get e :label-width))
((eq (plist-get e :type) 'label)
(string-width (or (plist-get e :value) "")))
((not (plist-get e :label))
0)
(t
(string-width (plist-get e :label))))
if (> width maxwidth) do (setq maxwidth width)
finally return maxwidth))
(defun bts::wid-format-label (parts label fmtwidth)
(let* ((prefix (or (plist-get parts :label-prefix) bts:widget-label-prefix))
(suffix (or (plist-get parts :label-suffix) bts:widget-label-suffix))
(face (or (plist-get parts :label-face) 'bts:widget-label-face))
(fmt (or (plist-get parts :label-format) bts:widget-label-format))
(array-fmt (concat "%" (if fmtwidth (number-to-string fmtwidth) "") "s"))
(arrayed-label (format array-fmt label))
(fmt-label (propertize (format fmt arrayed-label) 'face face))
(required (plist-get parts :require))
(req-mark (or (plist-get parts :require-mark) bts:widget-require-mark))
(req-face (or (plist-get parts :require-face) 'bts:widget-require-face))
(fmt-req (if required
(propertize req-mark 'face req-face)
;; put a space padding for the width of require mark
(let* ((req-width (string-width req-mark))
(padd-fmt (concat "%" (number-to-string req-width) "s")))
(format padd-fmt "")))))
(concat prefix fmt-label fmt-req suffix)))
(defun bts::wid-get-wmvc-common-arguments (parts &rest excludes)
(loop for k in '(:name :action :help)
for v = (plist-get parts k)
for k = (case k
(:help :help-echo)
(t k))
if (and v
(not (memq (bts:conv-keyward-to-symbol k) excludes)))
append (list k v)))
(defun bts::wid-make-label (parts fmtwidth)
(let ((label (or (plist-get parts :value) ""))
(fmtwidth (when (not (plist-get parts :unarrayed)) fmtwidth)))
`(,(bts::wid-format-label parts label fmtwidth))))
(defun bts::wid-make-wmvc-widget-with-label (parts fmtwidth &rest defs)
(let ((label (plist-get parts :label))
(fmtwidth (when (not (plist-get parts :unarrayed)) fmtwidth)))
(if label
`(,(bts::wid-format-label parts label fmtwidth) ,@defs)
defs)))
(defun bts::wid-make-wmvc-const (parts fmtwidth)
(let* ((face (or (plist-get parts :face) 'bts:widget-const-face))
(value (plist-get parts :value))
(def `(input :type const ,@(bts::wid-get-wmvc-common-arguments parts)
:face ,face :value ,value)))
(bts::wid-make-wmvc-widget-with-label parts fmtwidth def)))
(defun bts::wid-make-wmvc-textbox (parts fmtwidth)
(let* ((secret (plist-get parts :secret))
(area (plist-get parts :area))
(size (when (not area)
(or (plist-get parts :size)
(if secret 20 30))))
(prefix (when (and (plist-get parts :label)
area)
'BR))
(keymap (if area bts:widget-text-keymap bts:widget-field-keymap))
(def `(input :type text ,@(bts::wid-get-wmvc-common-arguments parts) :secret ,secret
:size ,size :area ,area :keymap ,keymap)))
(bts::wid-make-wmvc-widget-with-label parts fmtwidth prefix def)))
(defun bts::wid-make-wmvc-checkbox (parts fmtwidth)
(let* ((prefix (plist-get parts :prefix))
(suffix (or (plist-get parts :suffix)
(when (not prefix) "On")))
(tick (when (plist-get parts :tick) t))
(def `(input :type checkbox ,@(bts::wid-get-wmvc-common-arguments parts) :value ,tick)))
(bts::wid-make-wmvc-widget-with-label parts fmtwidth prefix def suffix)))
(defun bts::wid-make-wmvc-selectlist (parts fmtwidth)
(let* ((name (plist-get parts :name))
(opts (plist-get parts :options))
(cargs (bts::wid-get-wmvc-common-arguments parts))
(multiple (plist-get parts :multiple))
(horizontal (plist-get parts :horizontal))
(radio (plist-get parts :radio))
(format (cond (radio "%b%v")
(multiple "%b%v")
(t "%[ %v %]")))
(type (if radio 'radio 'select))
(def `(input :type ,type ,@cargs :options ,opts :multiple ,multiple
:format ,format :horizontal ,horizontal)))
(bts::wid-make-wmvc-widget-with-label parts fmtwidth def)))
(defun bts::wid-make-wmvc-link (parts fmtwidth)
(lexical-let* ((cargs (bts::wid-get-wmvc-common-arguments parts 'action))
(url (plist-get parts :url))
(info (plist-get parts :info))
(file (plist-get parts :file))