-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
AutoSetSyntax.sublime-settings
760 lines (750 loc) · 26.8 KB
/
AutoSetSyntax.sublime-settings
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
{
//////////////////////////////////////////////////////////
// Online Document //
// https://jfcherng-sublime.github.io/ST-AutoSetSyntax/ //
//////////////////////////////////////////////////////////
///////////////////
// User Settings //
///////////////////
// The time (in secondes) to wait for the next event to be triggered.
"debounce": 0.3,
// Enable plugin log (in a dedicated panel)
"enable_log": true,
// Set default syntax for build outputs.
// Can be one of following formats:
// - Syntax top scope: "scope:text.html.markdown"
// - Partial/full syntax file path: "Markdown/Markdown."
// - The name of the syntax: "Markdown" (which is shown in the bottom-right corner of ST)
// - An empty string, which does nothing
"exec_file_syntax": "Packages/AutoSetSyntax/syntaxes/ExecOutput.sublime-syntax",
// Set default syntax for new files. You can use multiple formats as described above.
"new_file_syntax": "",
// Run "auto_set_syntax" command on views which exist before the plugin is loaded?
"run_on_startup_views": false,
// The max lookup size for the file.
// A negative number means no limit, which may have performance issue on large files.
"trim_file_size": 20000, // about 20KB
// The max lookup length for the first line.
// A negative number means no limit, which may have performance issue on a long first line.
"trim_first_line_length": 500,
// Apart from "trim_suffixes", also try to remove every sub-extensions when finding a syntax match.
"trim_suffixes_auto": false,
// Syntax rules that will be checked one by one.
// This plugin will assign the syntax in the first satisfied rule to the view.
// You may want to see "default_syntax_rules" for some examples.
"user_syntax_rules": [],
// Suffixes that will be used to right trim the filename.
// By doing that, the file may be then auto set syntax with a trimmed filename.
"user_trim_suffixes": [],
//////////////////////
// Project Settings //
////////////////////////////////////////////////////////////////////////////
// You shouldn't change these settings here but in your project settings. //
////////////////////////////////////////////////////////////////////////////
// Syntax rules that will be checked one by one.
// This plugin will assign the syntax in the first satisfied rule to the view.
// You may want to see "default_syntax_rules" for some examples.
"project_syntax_rules": [],
// Suffixes that will be used to right trim the filename.
// By doing that, the file may be then auto set syntax with a trimmed filename.
"project_trim_suffixes": [],
//////////////////////
// Default Settings //
////////////////////////////////////////////////////////////////////////////
// If you override default rules, they will not be updated in the future. //
// If you want to add new rules, add them in user settings. //
////////////////////////////////////////////////////////////////////////////
// Syntax rules that will be checked one by one.
// This plugin will assign the syntax in the first satisfied rule to the view.
"default_syntax_rules": [
// syntax rule
{
"syntaxes": "scope:source.python",
"selector": "text.plain",
// match rule
"match": "all", // "any" by default
"rules": [
// constraint rule
{
"constraint": "contains_regex",
"args": ["^(?:def|class)\\s"]
},
{
"constraint": "contains_regex",
"args": ["^import(?!\\s+groovy)(?:$|[\\s(])", "^from\\s+[a-zA-Z.]+\\s+import(?:$|[\\s(])"]
}
]
},
{
"comment": "Basic INI files",
"syntaxes": "scope:source.ini",
"selector": "text.plain",
"rules": [
{
"constraint": "is_name",
"args": [".minttyrc", ".wslconfig"]
}
]
},
{
"comment": "Basic JSON files",
"syntaxes": "scope:source.json",
"selector": "text.plain",
"rules": [
{
"constraint": "is_extension",
"args": [".css.map", ".geojson", ".js.map", ".jsonc", ".webmanifest"]
},
{
"constraint": "is_name",
"args": [
".babelrc",
".bowerrc",
".csslintrc",
".eslintrc",
".jscsrc",
".jshintrc",
".markdownlintrc",
".stylelintrc"
]
}
]
},
{
"comment": "Basic YAML files",
"syntaxes": "scope:source.yaml",
"selector": "text.plain",
"rules": [
{
"constraint": "is_name",
"args": [".clang-format", ".clang-tidy", ".clangd"]
}
]
},
{
"syntaxes": ["scope:source.shell.bash"],
"selector": "text.plain",
"rules": [
{
"constraint": "is_name",
"args": ["profile", ".bash_history"]
},
{
"constraint": "name_contains_regex",
"args": ["\\.(?:bash|z(?:shrc|shenv|profile|login|logout))(?:\\.[^/]*)?$"]
},
{
"constraint": "first_line_contains_regex",
"args": [
// @see https://www.shellcheck.net/wiki/SC2148
"^\\s*#\\s+shellcheck\\s+shell=(?:bash|sh|zsh)"
]
}
]
},
{
"comment": "Linux .env files",
"syntaxes": [
"/DotENV.", // https://packagecontrol.io/packages/DotENV
"scope:source.shell.bash"
],
"selector": "",
"match": "all",
"rules": [
{
"rules": [
{ "constraint": "selector_matches", "args": ["text.plain"] },
{ "constraint": "is_hidden_syntax" }
]
},
{
"rules": [
{
"constraint": "is_name",
"args": [".envrc"]
},
{
"constraint": "name_contains_regex",
"args": ["\\.(?:env)(?:\\.[^/]*)?$"]
}
]
}
]
},
{
"syntaxes": "scope:text.git.config",
"selector": "- text.git.config",
"rules": [
{
"constraint": "path_contains_regex",
"args": ["/\\.?git/config$"]
}
]
},
{
// at least, C++ is a super set of C in ST's syntax aspect
"syntaxes": "scope:source.c++",
"selector": "text.plain",
"rules": [
{
"constraint": "contains_regex",
"args": [
"(?:^|\\s)#include\\s*[<\"]",
"(?:^|\\s)#pragma\\s+(?:once|pack|(?:pop|push)_macro|warning)(?=$|\\s)",
"(?:^|\\s)template\\s*<\\s*(?:class|typename)(?=$|\\s)",
// some strong characteristics of keywords
"\\b(?:const(?:eval|expr|init)|decltype|nullptr|(?:const|dynamic|reinterpret|static)_cast)(?=$|\\s)"
]
}
]
},
{
"syntaxes": "scope:source.cs",
"selector": "text.plain",
"match": "all",
"rules": [
{
"constraint": "contains_regex",
"args": ["^using\\s"]
},
{
"constraint": "contains_regex",
"args": ["^namespace\\s"]
}
]
},
{
"syntaxes": "scope:source.diff",
"selector": "text.plain",
"rules": [
// path headers
{
"match": "all",
"rules": [
{
"constraint": "contains_regex",
"args": ["^\\+{3} "]
},
{
"constraint": "contains_regex",
"args": ["^-{3} "]
}
]
},
// context line numbers
{
"constraint": "contains_regex",
"args": ["^@@ -\\d+,\\d+ \\+\\d+,\\d+ @@"]
}
]
},
{
"syntaxes": "scope:source.go",
"selector": "text.plain",
"match": "all",
"rules": [
{
"constraint": "contains_regex",
"args": ["^(?:package)\\s"]
},
{
"constraint": "contains_regex",
"args": ["^(?:import|func|type)\\s"]
}
]
},
{
"syntaxes": ["Jenkinsfile", "scope:source.groovy"],
"selector": "text.plain",
"rules": [
{
"constraint": "name_contains_regex",
"args": ["^Jenkinsfile(?=\\b|_)"]
}
]
},
{
"syntaxes": "scope:source.java",
"selector": "text.plain",
"rules": [
{
"constraint": "first_line_contains_regex",
"args": ["^\\s*import\\s+java\\."]
},
{
"constraint": "contains_regex",
"args": ["\\bimport\\s+java\\.", "\\bSystem\\.out\\.println\\s*\\("],
"kwargs": { "threshold": 2 }
}
]
},
{
"syntaxes": "scope:source.ts",
"selector": "text.plain",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".cts", ".mts"]
}
]
},
{
"syntaxes": "scope:source.tsx",
"selector": "text.plain",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".ctsx", ".mtsx"]
}
]
},
{
"syntaxes": "scope:source.js",
"selector": "text.plain",
"match": "all",
"rules": [
{
"constraint": "is_magika_enabled",
"inverted": true
},
{
"constraint": "contains_regex",
"args": [
"\\bconsole\\.(?:assert|debug|error|info|log|trace|warn)\\s*\\(",
"(?:^|\\s)export\\s+default\\s"
]
}
]
},
{
"syntaxes": "scope:source.jsx",
"selector": "text.plain",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".cjsx", ".mjsx"]
}
]
},
{
"syntaxes": "scope:source.lua",
"selector": "text.plain",
"rules": [
{
"constraint": "is_name",
"args": [".conkyrc"]
},
{
"constraint": "is_interpreter",
"args": ["lua"]
}
]
},
{
"comment": "Makefile",
"syntaxes": ["scope:source.makefile"],
"selector": "text.plain",
"rules": [
{
"constraint": "name_contains_regex",
"args": ["^Makefile\\."],
"kwargs": { "regex_flags": ["IGNORECASE"] }
},
{
"constraint": "contains_regex",
"args": ["^.PHONY\\s*:"]
}
]
},
{
// use the % regex to detect Matlab files
"syntaxes": "scope:source.matlab",
"selector": "text.plain | source.objc",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".m"]
},
{
"constraint": "contains_regex",
"args": ["^\\s*%"],
"kwargs": { "threshold": 2 }
}
]
},
{
// .m files could be Objective-C or Matlab files
// We first use a rather reliable regex from GitHub
// https://github.com/github/linguist/blob/master/lib/linguist/heuristics.rb#L69
// to apply syntax for Objective-C files
"syntaxes": "scope:source.objc",
"selector": "text.plain | source.matlab",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".m"]
},
{
"constraint": "contains_regex",
"args": [
"^\\s*(?:@(?:interface|class|protocol|property|end|synchronised|selector|implementation)\\b|#import\\s+.+\\.h[\">])"
]
}
]
},
{
"comment": "Python requirements.txt from https://packagecontrol.io/packages/requirementstxt",
"syntaxes": ["scope:source.requirementstxt", "scope:source.pip-requirements"],
"selector": "text.plain",
"rules": [
{
"constraint": "name_contains_regex",
"args": ["^requirements([-_.].+)?\\.(in|txt)$"]
}
]
},
{
"comment": "\"Ruby on Rails\" project",
"syntaxes": "scope:source.ruby.rails",
"selector": "source.ruby",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".rb", ".rake"]
},
{
"constraint": "is_in_ruby_on_rails_project"
}
]
},
{
"syntaxes": "scope:source.ruby",
"selector": "text.plain",
"rules": [
{
"constraint": "is_extension",
"args": [".simplecov"]
},
{
"constraint": "is_name",
"args": ["Cartfile", "Cartfile.private", "Cartfile.resolved", "config.ru", "Dangerfile"],
"kwargs": { "case_insensitive": true }
},
{
"constraint": "is_interpreter",
"args": ["ruby"]
}
]
},
{
"comment": "SSH config from https://packagecontrol.io/packages/SSH%20Config",
"syntaxes": ["scope:source.ssh_config", "scope:source.ssh-config"],
// some syntaxes just aggresively set "config" filename as XML file
"selector": "text.plain | text.xml.config",
"rules": [
{
"constraint": "path_contains_regex",
"args": ["/\\.ssh/config$"]
}
]
},
{
// Meteor templates follow Handlebars syntax, but must end in .html;
// but they also always begin with `<template name=`
"syntaxes": "scope:text.html.handlebars",
"selector": "text.plain | text.html",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".html"]
},
{
"constraint": "first_line_contains_regex",
"args": ["^<template name="]
}
]
},
{
"syntaxes": "scope:source.toml",
"selector": "text.plain",
"rules": [
{
"constraint": "is_name",
"args": ["uv.lock"]
}
]
},
{
"comment": "Django templates",
"syntaxes": ["scope:text.jinja", "scope:text.html.jinja"],
"selector": "text.html.basic",
"match": "all",
"rules": [
{
"constraint": "path_contains",
"args": ["/templates/"]
},
{
"constraint": "is_in_python_django_project"
}
]
},
{
"comment": "Jinja2/Twig HTML files",
"syntaxes": ["scope:text.jinja", "scope:text.html.jinja", "scope:text.html.twig"],
"selector": "text.html.basic",
"rules": [
{
"constraint": "contains_regex",
"args": [
"{{",
// https://jinja.palletsprojects.com/en/latest/templates/
"{%\\s*(?:autoescape|call|elif|else|extends|filter|for|from|if|import|include|macro|set|trans|with)\\b"
],
"kwargs": { "threshold": 4 }
}
]
},
{
"syntaxes": "scope:source.sql",
"selector": "text.plain",
"rules": [
{
"constraint": "first_line_contains",
"args": ["-- phpMyAdmin SQL Dump"]
},
{
"constraint": "contains_regex",
"args": ["\\bCREATE\\s+TABLE\\s+IF\\s+NOT\\s+EXISTS\\b"],
"kwargs": { "regex_flags": ["MULTILINE", "IGNORECASE"] }
}
]
},
{
"syntaxes": "scope:source.typoscript",
"selector": "text.plain",
"rules": [
{
"constraint": "is_name",
"args": ["ext_conf_template.txt", "ext_typoscript_constants.txt", "ext_typoscript_setup.txt"]
},
{
"constraint": "path_contains_regex",
"args": ["^.*/(?:fileadmin|typo3|TypoScript).*/(?:setup|constants)\\.txt$"]
}
]
},
{
"comment": "Apache config",
"syntaxes": "scope:source.apacheconf",
"selector": "text.plain | source.nginx",
"rules": [
{
"constraint": "path_contains_regex",
"args": ["\\b(?i:apache|httpd)(?:\\b|_).*/conf/.*\\.conf$"]
},
{
"constraint": "contains_regex",
"args": ["<(?:VirtualHost|Directory|Macro)(?:$|\\s)"]
}
]
},
{
"comment": "NGINX config",
"syntaxes": "scope:source.nginx",
"selector": "text.plain | source.apacheconf",
"rules": [
{
"constraint": "path_contains_regex",
"args": ["\\b(?i:nginx)(?:\\b|_).*/conf/.*\\.conf$"]
},
{
"constraint": "contains_regex",
"args": ["^\\s*(?:location\\s+(?:[~=/a-zA-Z])|(?:fastcgi_param|charset_map)\\s)"]
}
]
},
{
// @see https://doc.qt.io/qt-5/qt-conf.html
"comment": "Qt's config file",
"syntaxes": "scope:source.ini",
"selector": "- source.ini",
"rules": [
{
"constraint": "is_name",
"args": ["qt.conf"]
}
]
},
{
// @see https://doc.qt.io/qtvstools/qtvstools-translation-files.html
"comment": "Qt's translation file",
"syntaxes": "scope:text.xml",
"selector": "source.ts",
"match": "all",
"rules": [
{
"constraint": "is_extension",
"args": [".ts"]
},
{
"constraint": "first_line_contains_regex",
"args": ["^\\s*<\\?xml(?:$|\\s)"]
}
]
},
{
"comment": "Sublime Text/Merge changelog",
"syntaxes": "scope:text.html.basic",
"selector": "text.plain",
"match": "all",
"rules": [
{
"constraint": "is_name",
"args": ["changelog.txt"]
},
{
"constraint": "relative_exists",
"args": ["sublime_text", "sublime_text.exe", "sublime_merge", "sublime_merge.exe"]
}
]
},
{
"comment": "Package Control: Package installation/update messages",
"syntaxes": "scope:text.html.markdown",
"selector": "text.plain",
"rules": [
{
"constraint": "first_line_contains_regex",
"args": ["^Package Control Messages(?:$|\\s)"]
}
]
}
],
// Suffixes that will be used to right trim the filename.
// By doing that, the file may be then auto set syntax with a trimmed filename.
"default_trim_suffixes": [
"-dev",
"-development",
"-dist",
"-optional",
"-prod",
"-production",
"-qa",
"-test",
".backup",
".bak",
".common",
".default",
".dev",
".dist",
".example",
".in",
".inc",
".include",
".local",
".orig",
".out",
".qa",
".sample",
".shared",
".temp",
".test",
".tmp",
".tpl"
],
///////////////////
// Core Settings //
//////////////////////////////////////////////////////////////////////////////////
// These settings make this plugin function normally. You shouldn't touch them. //
//////////////////////////////////////////////////////////////////////////////////
"core_syntax_rules": [
{
"comment": "AutoSetSyntax Python-Like Views",
"syntaxes": "scope:source.python",
"selector": "text.plain",
"rules": [
{
"constraint": "first_line_contains_regex",
"args": ["^# === [AutoSetSyntax] "]
}
]
},
{
"comment": "AutoSetSyntax JSONC-Like Views",
"syntaxes": "scope:source.autosetsyntax.jsonc",
"selector": "text.plain",
"rules": [
{
"constraint": "first_line_contains_regex",
"args": ["^// [AutoSetSyntax] "]
}
]
}
],
/////////////////////
// Magika settings //
/////////////////////
// To use this feature, you have to install the "magika" library.
// @see https://jfcherng-sublime.github.io/ST-AutoSetSyntax/experimental/dl-based-syntax-detection/#prerequisites
"magika.enabled": false,
"magika.min_confidence": 0.85,
// To list supported file types, run shell command: `$ magika --list-output-content-types`
// @see https://github.com/google/magika/blob/main/docs/supported_content_types_list.md
"magika.syntax_map.appleplist": ["scope:text.xml.plist", "=xml"],
"magika.syntax_map.asm": [
// no good way to do this?
"scope:source.asm.x86_64",
"scope:source.asm.arm",
"scope:source.rvasm",
"scope:source.assembly"
],
"magika.syntax_map.asp": ["scope:source.asp"],
"magika.syntax_map.batch": ["scope:source.dosbatch"],
"magika.syntax_map.c": ["scope:source.c++" /* magika can't distinguish between C and C++ */],
"magika.syntax_map.cs": ["scope:source.cs"],
"magika.syntax_map.css": ["scope:source.scss", "scope:source.css"],
"magika.syntax_map.csv": ["scope:text.advanced_csv", "scope:text.csv"],
"magika.syntax_map.go": ["scope:source.go"],
"magika.syntax_map.html": ["scope:text.html.basic"],
"magika.syntax_map.ini": ["scope:source.ini"],
"magika.syntax_map.java": ["scope:source.java"],
"magika.syntax_map.javascript": [
"scope:source.ts" /* magika can't distinguish between TypeScript and JavaScript */
],
"magika.syntax_map.json": ["scope:source.json"],
"magika.syntax_map.latex": ["scope:text.tex.latex"],
"magika.syntax_map.lisp": ["scope:source.lisp"],
"magika.syntax_map.m3u": ["scope:text.m3u"],
"magika.syntax_map.makefile": ["scope:source.makefile"],
"magika.syntax_map.markdown": ["scope:text.html.markdown"],
"magika.syntax_map.mum": ["=xml"],
"magika.syntax_map.pem": ["scope:text.pem"],
"magika.syntax_map.perl": ["scope:source.perl"],
"magika.syntax_map.php": ["scope:embedding.php", "scope:text.html.php"],
"magika.syntax_map.postscript": ["scope:source.postscript"],
"magika.syntax_map.powershell": ["scope:source.powershell"],
"magika.syntax_map.python": ["scope:source.python"],
"magika.syntax_map.rdf": ["=xml"],
"magika.syntax_map.rst": ["scope:text.restructuredtext"],
"magika.syntax_map.rtf": ["scope:text.rtf"],
"magika.syntax_map.ruby": ["scope:source.ruby"],
"magika.syntax_map.rust": ["scope:source.rust"],
"magika.syntax_map.scala": ["scope:source.scala"],
"magika.syntax_map.shell": ["scope:source.shell.bash"],
"magika.syntax_map.smali": ["scope:source.smali"],
"magika.syntax_map.sql": ["scope:source.sql"],
"magika.syntax_map.svg": ["=xml"],
"magika.syntax_map.txt": ["scope:text.plain"],
"magika.syntax_map.vba": ["scope:source.vbs"],
"magika.syntax_map.winregistry": ["scope:source.reg"],
"magika.syntax_map.xml": ["scope:text.xml"],
"magika.syntax_map.yaml": ["scope:source.yaml"]
}