Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
Allow for custom elm-format binary names (#15)
Browse files Browse the repository at this point in the history
* Allow for custom elm-format binary names

* Indent JSON files by 4 spaces instead of tabs
  • Loading branch information
mariusbutuc authored and sentience committed May 3, 2017
1 parent dd76038 commit ea36395
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
2. Add the absolute path of the directory containing `elm-oracle` to the `elm_paths` setting in your Elm Language Support User settings
- I have `elm-format` installed, but it's not working
1. Make sure `elm-format` is on your PATH, or
2. Add the absolute path of the directory containing `elm-format` to the `elm_paths` setting in your Elm Language Support User settings. Note that you can combine paths with the above, so an example might be `"elm_paths": "/users/alex/elm-format:/users/alex/elm-oracle"`
2. If using an alternate name for the binary (`elm-format-0.17` or `elm-format-0.18`) add it to the `elm_format_binary` setting in your Elm Language Support User settings; an example might be `"elm_format_binary": "elm-format-0.18",`, or
3. Add the absolute path of the directory containing `elm-format` to the `elm_paths` setting in your Elm Language Support User settings. Note that you can combine paths with the above, so an example might be `"elm_paths": "/users/alex/elm-format:/users/alex/elm-oracle"`
- Elm format automatically runs every time I save a file, but there are some files I don't want it to run on
1. If there are certain Elm source files you don't want to automatically run `elm-format` on, for example elm-css based files, you can set a regex filter which will search the full filename (including the path to the file). If the regex matches, then it will not automatically run `elm-format` on the file when you save. For example, the following filter would prevent automatic `elm-format` on a file named `elm-css/src/Css/TopBar.elm`:
`"elm_format_filename_filter": "elm-css/src/Css/.*\\.elm$"`
Expand Down
11 changes: 6 additions & 5 deletions Settings/Elm Language Support.sublime-settings
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"debug": false,
"enabled": true,
"elm_docs_path": "docs.json",
"elm_format_on_save": true,
"elm_format_filename_filter": "",
"elm_paths": ""
"enabled": true,
"elm_docs_path": "docs.json",
"elm_format_binary": "elm-format",
"elm_format_on_save": true,
"elm_format_filename_filter": "",
"elm_paths": ""
}
7 changes: 4 additions & 3 deletions elm_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,23 @@ def run(self, edit):
path_separator = ';'

settings = sublime.load_settings('Elm Language Support.sublime-settings')
binary = settings.get('elm_format_binary', 'elm-format')
path = settings.get('elm_paths', '')
if path:
old_path = os.environ['PATH']
os.environ['PATH'] = os.path.expandvars(path + path_separator + '$PATH')

command = ['elm-format', self.view.file_name(), '--yes']
command = [binary, self.view.file_name(), '--yes']
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=shell)

if path:
os.environ['PATH'] = old_path

output, errors = p.communicate()

if settings.get('debug', False):
string_settings = sublime.load_settings('Elm User Strings.sublime-settings')
print(string_settings.get('logging.prefix', '') + '(elm-format) ' + str(output.strip()), '\nerrors: ' + str(errors.strip()))
print(string_settings.get('logging.prefix', '') + '(' + binary + ') ' + str(output.strip()), '\nerrors: ' + str(errors.strip()))
if str(errors.strip()):
print('Your PATH is: ', os.environ['PATH'])

Expand Down

0 comments on commit ea36395

Please sign in to comment.