-
Notifications
You must be signed in to change notification settings - Fork 15
/
orginternalhelpers.py
883 lines (822 loc) · 27 KB
/
orginternalhelpers.py
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
import sublime
import sublime_plugin
import datetime
import re
from pathlib import Path
import os
import fnmatch
import logging
import sys
import traceback
import yaml
import json
#from jsoncomment import JsonComment
import ast
import OrgExtended.orgxmlthemeparser as tp
import glob
varre = re.compile(r'var\((?P<name>[^)]+)\)')
colorre = re.compile(r'#(?P<r>[A-Fa-f0-9][A-Fa-f0-9])(?P<g>[A-Fa-f0-9][A-Fa-f0-9])(?P<b>[A-Fa-f0-9][A-Fa-f0-9])(?P<a>[A-Fa-f0-9][A-Fa-f0-9])?')
template = """
- match: '{{{{beginsrc}}}}(({match})\s*)'
captures:
1: constant.other orgmode.fence.sourceblock
2: orgmode.fence.sourceblock
3: keyword orgmode.fence.language
4: orgmode.fence.sourceblock
embed: scope:{source}
escape: '{{{{endsrc}}}}'
embed_scope: orgmode.sourceblock.content markup.raw.block orgmode.raw.block
escape_captures:
1: constant.other orgmode.fence.sourceblock
- match: '(src_({match}))(\[[^\]]+\])?(\{{)'
captures:
1: keyword orgmode.fence.language
3: markup.raw.block comment
4: constant.other
embed: scope:{source}
scope: orgmode.sourceblock.inline
escape: '(\}})'
escape_captures:
1: constant.other
embed_scope: markup.raw.block orgmode.raw.block orgmode.sourceblock.content.inline"""
introBlock = """
// GENERATED: By OrgExtended
//
// The generator adds a subset of the orgmode specific scopes.
// The scopes that it has added tend to play an important role
// in making an orgmode buffer operational.
//
// That said, orgmode offers a wide variety of syntax elements for
// you to style as needed. Please see blow for more information
// on some of these scopes.
//
// The preamble scope is one of the more important scopes. In the
// future I hope to produce some ligature fonts that will make the preamble
// scope a thing of the past. For now, the preamble is the scope that hides
// leading stars in your buffer. I find those visually disturbing and
// appreciate working with them being invisible.
//
// The preamble used the pre-defined background color of your theme to
// ensure the stars are invisible.
"""
# TODO Create blocks for each of the relevant blocks of markers
# Create a set of useful markers with comments about how you can customize them
commentBlock = """
// GENERATED: By Org Extended
//
// The generator has added a bunch of useful extensions to the color scheme
// That said there is much more than can be done by you to tweak your scheme
// to your hearts content. The following comment block is here to give you
// ideas of what is possible.
//
// On a windows box type Ctrl + Alt + Shift + P
// to get a view of what scopes are in play on the thing you want to style
// This table can help you tweak what you would like to see change
//
// {
// "scope": "orgmode.break",
// "foreground": "#ed188a",
// },
// {
// "scope": "orgmode.page",
// "foreground": "#f5eebf",
// },
// {
// "scope": "orgmode.headline",
// "foreground": "#14adfa",
// "background": "#172822",
// "font_style": "bold italic",
// },
// {
// "scope": "orgmode.headline2",
// "background": "#172822",
// "foreground": "#bb86fc",
// "font_style": "bold underline",
// },
// {
// "scope": "orgmode.headline3",
// "foreground": "#03dac5",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.headline4",
// "foreground": "#dfe6a1",
// "font_style": "italic",
// },
// {
// "scope": "orgmode.headline5",
// "foreground": "#018786",
// "font_style": "italic",
// },
// {
// "scope": "orgmode.headline6",
// "foreground": "#afe3de",
// "font_style": "italic",
// },
// // Links can target these
// {
// "scope": "orgmode.target",
// "foreground": "#7c004a",
// "font_style": "italic",
// },
// // Links can target these
// {
// "scope": "orgmode.target.bracket",
// "foreground": "#7c004a",
// "font_style": "bold",
// },
// // [[LINK]] This is the entire link block
// {
// "scope": "orgmode.link",
// "foreground": "#3cd7fa",
// "font_style": "",
// },
// {
// "scope": "orgmode.link.href",
// "foreground": "#9999aa",
// "font_style": "italic",
// },
// {
// "scope": "orgmode.link.text",
// "foreground": "#4ce7fd",
// "font_style": "bold",
// },
// // Special coloring for email addresses
// {
// "scope": "orgmode.email",
// "foreground": "#a188b3",
// "font_style": "italic",
// },
// {
// "scope": "orgmode.deadline",
// "foreground": "#d1771d",
// "font_style": "italic",
// },
// {
// "scope": "orgmode.scheduled",
// "foreground": "#d1771d",
// "font_style": "italic",
// },
// // #+PRIORITIES: A B C
// {
// "scope": "orgmode.controltag",
// "foreground": "#aaaaaa",
// },
// // controltag.text also exists
// {
// "scope": "orgmode.controltag.tag",
// "foreground": "#aaaaaa",
// "font_style": "italic",
// },
// // < DATETIME >
// {
// "scope": "orgmode.datetime",
// "foreground": "#b0a497",
// },
// // [ DATETIME ]
// {
// "scope": "orgmode.unscheddatetime",
// "foreground": "#b0a497",
// },
// // CLOSED: SCHEDULED: DEADLINE:
// {
// "scope": "orgmode.statekeyword",
// "foreground": "#d1771d",
// "font_style": "italic",
// },
// {
// "scope": "orgmode.checkbox",
// "foreground": "#c9be7b",
// },
// {
// "scope": "orgmode.checkbox.checked",
// "foreground": "#00FF00",
// },
// {
// "scope": "orgmode.checkbox.blocked",
// "foreground": "#FF0000",
// },
// {
// "scope": "orgmode.tags",
// "foreground": "#ded49b",
// },
// {
// "scope": "orgmode.tags.headline",
// "foreground": "#deff9b",
// },
// {
// "scope": "orgmode.tack",
// "foreground": "#c993c4",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.numberedlist",
// "foreground": "#c993c4",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.definition",
// "foreground": "#A2E8E4",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.definition.marker",
// "foreground": "#E1A2E8",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.follow_up",
// "foreground": "#FF0000",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.fence",
// "background": "#322830",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.fence.language",
// "background": "#322830",
// "foreground": "#f1bff2",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.raw.block",
// "background": "#252520",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.table.block",
// "background": "#272828",
// },
// {
// "scope": "orgmode.bold",
// "foreground": "#aaffaa",
// "font_style": "bold",
// },
// {
// "scope": "orgmode.italics",
// "foreground": "#aaffff",
// "font_style": "italic",
// },
// {
// "scope": "orgmode.underline",
// "foreground": "#aaaaff",
// "font_style": "underline",
// },
// {
// "scope": "orgmode.strikethrough",
// "foreground": "#aaaaaa",
// },
// {
// "scope": "orgmode.code",
// "foreground": "#ffaaff",
// },
// {
// "scope": "orgmode.verbatim",
// "foreground": "#ffaaaa",
// },
"""
stateBlock = """
// GENERATED: By OrgExtended
//
// States are the build in state flow. While org
// allows you to define your own state flows
// I do not yet have a good way of automatically
// adding those to the syntax and color scheme.
// (I hope to one day have a way to do that)
//
// For now the pre-defined state flows have automatic
// highlighting and any new ones you define will have
// the default. I can of course extend the syntax if desired.
"""
priorityBlock = """
// GENERATED: By OrgExtended
//
// Much like states I do not have a way to extend the syntax with
// new priorities at this time. I hope to devise a good scheme in
// the future.
//
// That said there is a default set of priorities A,B,C,D,E that
// have automatic coloring. These are the color scheme elements that
// add that coloring.
"""
fenceBlock = """
// GENERATED: By OrgExtended
//
// Code blocks have a heading BEGIN_SRC and an ending END_SRC
// I find it visually appealing to make these stand out.
// You may have different preferences. NOTE: I use a luminance
// shift expression to make the chosen color work with your color scheme.
"""
datePickerBlock = """
// GENERATED: By OrgExtended
// ====== DATE PICKER =====
//
// The date picker is the calendar view widget for selecting dates
// this view has its own color scheme. The defaults are reasonable
// with most color schemes. You may however want to tweak one of these.
//
// {
// "scope": "orgdatepicker.weekendheader",
// "foreground": "#5b96f5",
// "font_style": "bold italic",
// },
// {
// "scope": "orgdatepicker.weekdayheader",
// "foreground": "#0762a3",
// "font_style": "bold italic",
// },
// {
// "scope": "orgdatepicker.monthheader",
// "foreground": "#7e4794",
// "font_style": "bold italic",
// },
// {
// "scope": "orgdatepicker.time",
// "foreground": "#aaaaaa",
// "font_style": "bold italic",
// },
"""
agendaIntroBlock = """
// GENERATED: By OrgExtended
// ====== AGENDA =====
//
// The agenda has a few unique requirements. It builds some of the blocky
// diagrams using colors that have the same foreground as background.
//
// You can change these colors.
"""
agendaHabitBlock = """
// GENERATED: By OrgExtended
//
// Habits are a means of tracking repeated tasks in orgmode. The
// agena has limited support for habits. The display shows how often
// you are achieving your habit.
"""
agendaWeekEmptyBlock = """
// GENERATED: By OrgExtended
//
// The weekly empty scope is how we fill the time blocks
// that are empty in the weekly view. Usually I fill these with
// grey blocks per hour. You may choose otherwise.
// The foreground and background should be the same color
// to avoid showing the control characters.
"""
agendaWeekColorsBlock = """
// GENERATED: By OrgExtended
//
// The week view uses these numeric week colors to randomly highlight
// tasks to make them appear unique. You can change this pallete as desired.
"""
agendaDayColorBlocks = """
// GENERATED: By OrgExtended
//
// The day color blocks are used in the day view
// to show how scheduled todos overlap. This is a range
// of colors that show visually how todos fit into your day.
// You can choose the color palette although it is best if
// these colors have the same foreground and background color.
"""
agendaNowBlock = """
// GENERATED: By OrgExtended
//
// orgagenda.now is the cursor. It is not used by the syntax
// but rather to dynamically insert cursor markers in various
// locations in the agenda. Color as you see fit.
"""
agendaScopesBlock = """
// GENERATED: By OrgExtended
//
// There are more colors you can override in the agenda:
//
// {
// "scope": "orgagenda.header",
// "foreground": "#5b96f5",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.dateheader",
// "foreground": "#5b96f5",
// "font_style": "bold italic underline",
// },
// {
// "scope": "orgagenda.weekendheader",
// "foreground": "#ab96f5",
// "font_style": "bold italic underline",
// },
// {
// "scope": "orgagenda.timeseparator",
// "foreground": "#7c7c7d",
// },
// {
// "scope": "orgagenda.now",
// "foreground": "#a88cd4",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.filename",
// "foreground": "#76b3ae",
// },
// {
// "scope": "orgagenda.todo",
// "foreground": "#a63229",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.doing",
// "foreground": "#d2a2e0",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.blocked",
// "foreground": "#FF0000",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.waiting",
// "foreground": "#ffff00",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.cancelled",
// "foreground": "#bab9b8",
// "font_style": "italic",
// },
// {
// "scope": "orgagenda.inprogress",
// "foreground": "#d2a2e0",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.next",
// "foreground": "#3fd9d7",
// "font_style": "bold italic",
// },
// { // Hide the week markup in the buffer
// "scope": "orgagenda.week",
// "foreground": "var(bgcol)",
// },
// {
// "scope": "orgagenda.week.something",
// "foreground": "#ffffff",
// "background": "#007700",
// },
// {
// "scope": "orgagenda.week.today",
// "foreground": "#f89cf4",
// "font_style": "bold",
// },
// {
// "scope": "orgagenda.week.active",
// "foreground": "#f8fc00",
// "font_style": "bold",
// },
// {
// "scope": "orgagenda.week.activetoday",
// "foreground": "#f89cf4",
// "background": "#485c00",
// "font_style": "bold",
// },
// {
// "scope": "orgagenda.projecttitle",
// "foreground": "#a87932",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.blockseparator",
// "foreground": "#4a4a37",
// "font_style": "bold italic",
// },
// {
// "scope": "orgagenda.monthheader",
// "foreground": "#a87932",
// "font_style": "bold italic",
// },
"""
class OrgRegenSyntaxTemplateCommand(sublime_plugin.TextCommand):
def run(self, edit):
templateFile = os.path.join(sublime.packages_path(),"OrgExtended","OrgExtended.sublime-syntax-template")
outputFile = os.path.join(sublime.packages_path(),"OrgExtended","OrgExtended.sublime-syntax")
languageList = os.path.join(sublime.packages_path(),"OrgExtended","languagelist.yaml")
templates = ""
with open(languageList) as file:
documents = yaml.full_load(file)
for item in documents:
if 'text' in item:
item['source'] = "text." + item['text']
elif not 'source' in item:
item['source'] = "source." + item['language']
else:
item['source'] = "source." + item['source']
if not 'match' in item:
item['match'] = item['language']
templates += template.format(**item)
templates += "\n"
with open(templateFile) as tfile:
with open(outputFile, 'w') as ofile:
for line in tfile.readlines():
if("{{INSERT_LANGUAGES_HERE}}" in line):
ofile.write(templates)
else:
ofile.write(line)
#print(templates)
def findscope(cs, name):
if(name == None):
return None
for i in cs['rules']:
if 'scope' in i and i['scope'] == name:
return i
return None
def replaceVar(cs,val):
m = varre.match(val)
while(m):
name = m.group('name')
data = cs['variables'][name]
val = varre.sub(val,data)
m = varre.match(val)
return val
def expandColor(cs, val):
return replaceVar(cs,val)
def getBackground(cs, scope = None):
i = findscope(cs, scope)
if(i):
if('background' in i):
return expandColor(cs, i['background'])
bg = cs['globals']['background']
if(not bg):
return expandColor(cs, "#ffffff")
return expandColor(cs, bg)
class OrgCreateColorSchemeFromActiveCommand(sublime_plugin.TextCommand):
def addstates(self, cs):
cs['rules'].append({"COMMENT ORGMODE STATES COMMENT HERE":""})
self.addscope(cs,"orgmode.state.todo", "#e6ab4c")
self.addscope(cs,"orgmode.state.blocked", "#FF0000")
self.addscope(cs,"orgmode.state.done", "#47c94f")
self.addscope(cs,"orgmode.state.cancelled", "#bab9b8")
self.addscope(cs,"orgmode.state.meeting", "#dec7fc")
self.addscope(cs,"orgmode.state.phone", "#77ebed")
self.addscope(cs,"orgmode.state.note", "#d2a2e0")
self.addscope(cs,"orgmode.state.doing", "#9c9c17")
self.addscope(cs,"orgmode.state.inprogress","#9c9c17")
self.addscope(cs,"orgmode.state.next", "#37dae6")
self.addscope(cs,"orgmode.state.reassigned","#bab9b8")
self.addscope(cs,"orgmode.state.flag" ,"#77ebed")
self.addscope(cs,"orgmode.state.cleanup" ,"#e6ab4f")
self.addscope(cs,"orgmode.state.fixed" ,"#47d04f")
def addpriorities(self, cs):
cs['rules'].append({"COMMENT ORGMODE PRIORITIES COMMENT HERE":""})
self.addscope(cs,"orgmode.priority","#c27532")
self.addscope(cs,"orgmode.priority.value","#f5a55f")
self.addscope(cs,"orgmode.priority.value.a","#e05a7b")
self.addscope(cs,"orgmode.priority.value.b","#f59a76")
self.addscope(cs,"orgmode.priority.value.c","#fab978")
self.addscope(cs,"orgmode.priority.value.d","#f5d976")
self.addscope(cs,"orgmode.priority.value.e","#bcbfae")
self.addscope(cs,"orgmode.priority.value.general","#b59eb5")
def addagenda(self,cs):
cs['rules'].append({"COMMENT ORGMODE DAYBLOCKS HERE":""})
self.addscope(cs,"orgagenda.block.1","#623456","#623456")
self.addscope(cs,"orgagenda.block.2","#007777","#007777")
self.addscope(cs,"orgagenda.block.3","#999900","#999900")
self.addscope(cs,"orgagenda.block.4","#007700","#007700")
self.addscope(cs,"orgagenda.block.5","#aa5522","#aa5522")
self.addscope(cs,"orgagenda.block.6","#f89cf4","#f89cf4")
self.addscope(cs,"orgagenda.block.7","#0000ee","#0000ee")
cs['rules'].append({"COMMENT ORGMODE HABITS HERE":""})
self.addscope(cs,"orgagenda.habit.didit","#ffffff","#007700")
self.addscope(cs,"orgagenda.habit.scheduled","#333300","#550000")
self.addscope(cs,"orgagenda.habit.nothing","#000066","#000066")
bg = getBackground(cs)
weekEmpty = "color(" + bg + " l(+ 5%))"
cs['rules'].append({"COMMENT ORGMODE WEEKEMPTY HERE":""})
self.addscope(cs,"orgagenda.week.empty", weekEmpty, weekEmpty)
cs['rules'].append({"COMMENT ORGMODE AGENDA WEEKCOLORS HERE":""})
self.addscope(cs,"orgagenda.week.done.0","#4f4f4f")
self.addscope(cs,"orgagenda.week.done.1","#666666")
self.addscope(cs,"orgagenda.week.0","#550000")
self.addscope(cs,"orgagenda.week.1","#007700")
self.addscope(cs,"orgagenda.week.2","#770077")
self.addscope(cs,"orgagenda.week.3","#0000ff")
self.addscope(cs,"orgagenda.week.4","#999900")
self.addscope(cs,"orgagenda.week.5","#007777")
self.addscope(cs,"orgagenda.week.6","#aa5522")
self.addscope(cs,"orgagenda.week.7","#cc99cc")
self.addscope(cs,"orgagenda.week.8","#225522")
self.addscope(cs,"orgagenda.week.9","#623456")
self.addscope(cs,"orgmode.deadline.warning","#999900",bg)
self.addscope(cs,"orgmode.deadline.overdue","#880088",bg)
self.addscope(cs,"orgmode.deadline.due","#007700",bg)
now = "#aaaa00"
if('find_highlight' in cs['globals']):
now = cs['globals']['find_highlight']
cs['rules'].append({"COMMENT ORGMODE AGENDA NOW HERE":""})
self.addscope(cs,"orgagenda.now",now)
cs['rules'].append({"COMMENT ORGMODE AGENDA SCOPES HERE":""})
def addfences(self, cs):
cs['rules'].append({"COMMENT ORGMODE FENCE COMMENT HERE":""})
bg = getBackground(cs, 'markup.raw.block')
bg = "color(" + bg + " l(+ 6%))"
self.addscope(cs,"orgmode.fence",None, bg,"bold")
def addscope(self, cs, name, fg, bg=None, style=None):
if(not findscope(cs, name)):
scope = {"scope": name}
if(fg):
scope['foreground'] = fg
if(bg):
scope['background'] = bg
if(style):
scope['font_style'] = style
cs['rules'].append(scope)
def addpreamble(self, cs):
if(not findscope(cs, 'orgmode.preamble')):
bg = cs['globals']['background']
cs['rules'].append({"scope": "orgmode.preamble","foreground": bg, "background": bg})
if('globals' in cs and 'line_highlight' not in cs['globals']):
# Patch up lineHighlight, I have no idea why the themes seem to be using
# Camel case for this but this ensures that if the CamelCase version is there
# we use a color scheme compatible snake case version
if 'lineHighlight' in cs['globals']:
cs['globals']['line_highlight'] = cs['globals']['lineHighlight']
def run(self, edit):
self.settings = sublime.load_settings('Preferences.sublime-settings')
self.origColorScheme = self.settings.get("color_scheme",None)
if(self.origColorScheme):
self.colorSchemeData = sublime.load_resource(self.origColorScheme)
cs = None
if(".tmTheme" in self.origColorScheme):
try:
p = tp.XMLThemeParser(self.colorSchemeData)
cs = p.cs
except:
print("Failed to parse tmTheme file: \n" + traceback.format_exc())
else:
try:
csDat = self.colorSchemeData.replace("\r","").split('\n')
out = []
for o in csDat:
if(o.strip().startswith('//') or o.strip() == ""):
continue
out.append(o)
self.colorSchemeData = '\n'.join(out)
cs = ast.literal_eval(self.colorSchemeData)
except:
print("ERROR: Failed to parse color scheme data")
print(traceback.format_exc())
print(self.colorSchemeData)
if(not cs):
print("FAILED TO GENERATE NEW COLOR SCHEME COULD NOT PARSE SCHEME")
return
path = os.path.join(sublime.packages_path(),"User","OrgColorSchemes")
if(not os.path.exists(path)):
os.mkdir(path)
cs['rules'].append({"COMMENT ORGMODE INTRO HERE":""})
self.addpreamble(cs)
self.addstates(cs)
self.addfences(cs)
self.addpriorities(cs)
scheme = os.path.basename(self.origColorScheme)
scheme = os.path.splitext(scheme)[0]
schemeName = scheme + "_Org.sublime-color-scheme"
outputFile = os.path.join(path, schemeName)
# ===========================================================
cs['rules'].append({"COMMENT ORGMODE SCOPES HERE":""})
# ===========================================================
cs['rules'].append({"COMMENT ORGMODE DATEPICKER SCOPES HERE":""})
# ===========================================================
cs['rules'].append({"COMMENT ORGMODE AGENDA INTRO HERE":""})
self.addagenda(cs)
jsonStr = json.dumps(cs, sort_keys=True, indent=4)
jsonStr = jsonStr.replace('"COMMENT ORGMODE SCOPES HERE": ""',commentBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE INTRO HERE": ""',introBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE FENCE COMMENT HERE": ""',fenceBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE PRIORITIES COMMENT HERE": ""',priorityBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE STATES COMMENT HERE": ""',stateBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE DATEPICKER SCOPES HERE": ""',datePickerBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE AGENDA INTRO HERE": ""',agendaIntroBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE WEEKEMPTY HERE": ""',agendaWeekEmptyBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE DAYBLOCKS HERE": ""',agendaDayColorBlocks)
jsonStr = jsonStr.replace('"COMMENT ORGMODE HABITS HERE": ""',agendaHabitBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE AGENDA WEEKCOLORS HERE": ""',agendaWeekColorsBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE AGENDA SCOPES HERE": ""',agendaScopesBlock)
jsonStr = jsonStr.replace('"COMMENT ORGMODE AGENDA NOW HERE": ""',agendaNowBlock)
with open(outputFile,'w') as ofile:
ofile.write(jsonStr)
ofile.flush()
newColorScheme = "Packages/User/OrgColorSchemes/" + schemeName
print("CHANGING ORIGINAL COLOR SCHEME: " + self.origColorScheme)
print("TO COLOR SCHEME: " + newColorScheme)
# We need some time for that file to hit the disk before we try to
# load from them. Sublime is fast so give us a little time here.
sublime.set_timeout(self.setColorSchemes(newColorScheme), 1000)
def setColorSchemes(self, newColorScheme):
self.mysettings = sublime.load_settings('OrgExtended.sublime-settings')
self.mysettings.set("color_scheme", newColorScheme)
sublime.save_settings('OrgExtended.sublime-settings')
self.mysettings = sublime.load_settings('orgdatepicker.sublime-settings')
self.mysettings.set("color_scheme", newColorScheme)
sublime.save_settings('orgdatepicker.sublime-settings')
self.mysettings = sublime.load_settings('orgagenda.sublime-settings')
self.mysettings.set("color_scheme", newColorScheme)
sublime.save_settings('orgagenda.sublime-settings')
class OrgSelectExistingColorSchemeCommand(sublime_plugin.TextCommand):
def on_done_st4(self, index, modifiers):
self.on_done(index)
def on_done(self, index):
if(index < 0):
return
newColorScheme = self.files[index]
self.mysettings = sublime.load_settings('OrgExtended.sublime-settings')
self.mysettings.set("color_scheme", newColorScheme)
sublime.save_settings('OrgExtended.sublime-settings')
self.mysettings = sublime.load_settings('orgdatepicker.sublime-settings')
self.mysettings.set("color_scheme", newColorScheme)
sublime.save_settings('orgdatepicker.sublime-settings')
self.mysettings = sublime.load_settings('orgagenda.sublime-settings')
self.mysettings.set("color_scheme", newColorScheme)
sublime.save_settings('orgagenda.sublime-settings')
def run(self, edit):
path = os.path.join(sublime.packages_path(),"User","OrgColorSchemes")
self.files = glob.glob(os.path.join(path,"*.sublime-color-scheme"))
temp = []
for file in self.files:
file = file.replace(sublime.packages_path(),"")
file = "Packages" + file.replace("\\","/")
temp.append(file)
self.files = temp
self.files.append("Packages/OrgExtended/OrgExtended.sublime-color-scheme")
self.files.append("Packages/OrgExtended/OrgExtended-Light.sublime-color-scheme")
if(int(sublime.version()) >= 4096):
self.view.window().show_quick_panel(self.files, self.on_done_st4, -1, -1)
else:
self.view.window().show_quick_panel(self.files, self.on_done, -1, -1)
class OrgCreateKeymapDocCommand(sublime_plugin.TextCommand):
def run(self, edit):
commandsData = sublime.load_resource("Packages/OrgExtended/OrgExtended.sublime-commands")
commandsData = re.sub(r"//.*\n","\n",commandsData)
com = ast.literal_eval(commandsData)
keymapData = sublime.load_resource("Packages/OrgExtended/Default.sublime-keymap")
keymapData = re.sub(r"//.*\n","",keymapData)
keymapData = re.sub(r"\n\s*\n","\n",keymapData)
keymapData = re.sub(r"\r\s*\r","",keymapData)
keys = json.loads(keymapData)
coms = {}
for c in com:
cmd = c['command']
cap = c['caption']
coms[cmd] = {'cap': cap}
for k in keys:
kks = k['keys']
cmd = k['command']
cntx = "everywhere"
vi = False
if('context' in k):
for i in k['context']:
if('key' in i and 'vi_command_mode_aware' == i['key']):
vi = True
if('operand' in i):
if(isinstance(i['operand'],str)):
cntx = i['operand']
if(cmd in coms):
if(not 'keys' in coms[cmd]):
coms[cmd]['keys'] = {}
if(vi):
coms[cmd]['keys']['vi'] = kks
else:
coms[cmd]['keys']['norm'] = kks
coms[cmd]['cntx'] = cntx
coms[cmd]['vi'] = vi
else:
if(vi):
coms[cmd] = {'keys': {'vi': kks}, 'cntx': cntx}
else:
coms[cmd] = {'keys': {'norm': kks}, 'cntx': cntx}
out = ""
contexts = {"Date Picker": "orgdateeditor", "Org File":"orgmode", "Org Agenda":"orgagenda", "Unbound":"","Everywhere":"everywhere", "Quick Input": "orginput" }
for name,con in contexts.items():
out += "* " + name + "\n"
out += " |Normal Keys| Vim Keys | Command|Operation| \n"
out +="|-\n"
for k,i in coms.items():
if(not k.startswith("org_")):
continue
if(('cntx' in i and con != "" and con in i['cntx']) or ('cntx' not in i and con == "")):
if('keys' in i):
if('norm' in i['keys']):
out += "|" + str(i['keys']['norm']).replace('[','').replace(']','').replace("'",'')
else:
out += "|"
if('vi' in i['keys']):
out += "|" + str(i['keys']['vi']).replace('[','').replace(']','').replace("' '","<space>").replace("'",'')
else:
out += "|"
else:
out += "||"
if('cap' in i):
out += "|" + i['cap']
else:
out += "|"
out += "|" + k + "|\n"
out += "\n\n"
self.view.insert(edit,0,out)
pass