Skip to content

Commit 66ea1ca

Browse files
azizkprincemaple
authored andcommitted
Commands: recognize more file types for mix format (#51)
1 parent c3a3f5b commit 66ea1ca

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

commands/mix_format.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run(self, _edit, **kwargs):
2626
call_mix_format(window, file_path=file_path)
2727

2828
def is_enabled(self):
29-
return is_elixir_syntax(self.view)
29+
return is_formattable_syntax(self.view)
3030

3131
class MixFormatToggleAutoFormatCommand(sublime_plugin.TextCommand):
3232
def description(self):
@@ -40,11 +40,11 @@ def run(self, _edit, **_kwargs):
4040
print_status_msg('%s auto-formatting!' % ['Disabled', 'Enabled'][on_save])
4141

4242
def is_enabled(self):
43-
return is_elixir_syntax(self.view)
43+
return is_formattable_syntax(self.view)
4444

4545
class MixFormatOnSaveListener(sublime_plugin.EventListener):
4646
def is_elixir_file(self, view):
47-
return is_elixir_syntax(view)
47+
return is_formattable_syntax(view)
4848

4949
def on_post_save(self, view):
5050
if not self.is_elixir_file(view):

commands/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,16 @@ def expand_scope_right(view, begin_point, scope):
2121
)
2222
return sublime.Region(begin_point, end_point)
2323

24+
def is_one_of_syntaxes(view, syntaxes):
25+
view_syntax_path = view.settings().get('syntax')
26+
return any(basename + '.sublime-syntax' in view_syntax_path for basename in syntaxes)
27+
2428
def is_elixir_syntax(view):
25-
return 'Elixir.sublime-syntax' in view.settings().get('syntax')
29+
return is_one_of_syntaxes(view, ['Elixir'])
30+
31+
def is_formattable_syntax(view):
32+
syntaxes = ['Elixir', 'EEx', 'Elixir (EEx)', 'HTML (EEx)', 'HTML (HEEx)', 'HTML (Surface)']
33+
return is_one_of_syntaxes(view, syntaxes)
2634

2735
def reverse_find_root_folder(bottom_path):
2836
bottom_path = Path(bottom_path)

keymaps/Default.sublime-keymap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
{ "keys": ["alt+shift+r"], "command": "mix_test_repeat" },
1010
// Formats the source file.
1111
{ "keys": ["alt+shift+f"], "command": "mix_format_file",
12-
"context": [ { "key": "selector", "operator": "equal", "operand": "source.elixir" } ]
12+
"context": [ { "key": "selector", "operator": "equal", "operand": "source.elixir | source.elixir.eex | text.eex | text.html.eex | text.html.heex | text.html.surface" } ]
1313
},
1414
]

0 commit comments

Comments
 (0)