Skip to content

Commit d647e20

Browse files
committed
Support regex in format-on-save
1 parent 991e7b3 commit d647e20

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

CodeFormatter.sublime-settings

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"codeformatter_go_options":
55
{
66
"syntaxes": "go",
7-
"format_on_save": false // Boolean
7+
"format_on_save": false // Format on save. Either a boolean (true/false) or a string regexp tested on filename. Example : "^((?!.min.|vendor).)*$"
88

99
// Optionless support
1010
},

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ Currently no options are supported:
281281
"codeformatter_go_options":
282282
{
283283
"syntaxes": "go",
284-
"format_on_save": false // Boolean
284+
"format_on_save": false // Format on save. Either a boolean (true/false) or a string regexp tested on filename. Example : "^((?!.min.|vendor).)*$"
285285
}
286286
```
287287

codeformatter/goformatter.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import sublime
24
import subprocess
35

@@ -32,5 +34,7 @@ def format(self, text):
3234
def format_on_save_enabled(self, _):
3335
format_on_save = False
3436
if ('format_on_save' in self.opts and self.opts['format_on_save']):
35-
format_on_save = True
37+
format_on_save = self.opts['format_on_save']
38+
if (isinstance(format_on_save, str)):
39+
format_on_save = re.search(format_on_save, file_name) is not None
3640
return format_on_save

0 commit comments

Comments
 (0)