├── .gitignore ├── LICENSE ├── README.md ├── ReindentOnSave.py └── screenshot.gif /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | 5 | # C extensions 6 | *.so 7 | 8 | # Distribution / packaging 9 | .Python 10 | env/ 11 | bin/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | eggs/ 16 | lib/ 17 | lib64/ 18 | parts/ 19 | sdist/ 20 | var/ 21 | *.egg-info/ 22 | .installed.cfg 23 | *.egg 24 | 25 | # Installer logs 26 | pip-log.txt 27 | pip-delete-this-directory.txt 28 | 29 | # Unit test / coverage reports 30 | htmlcov/ 31 | .tox/ 32 | .coverage 33 | .cache 34 | nosetests.xml 35 | coverage.xml 36 | 37 | # Translations 38 | *.mo 39 | 40 | # Mr Developer 41 | .mr.developer.cfg 42 | .project 43 | .pydevproject 44 | 45 | # Rope 46 | .ropeproject 47 | 48 | # Django stuff: 49 | *.log 50 | *.pot 51 | 52 | # Sphinx documentation 53 | docs/_build/ 54 | 55 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Marchenko Alexandr 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Sublime Text - reindent on save 2 | =============================== 3 | 4 | ![screenshot](https://github.com/mac2000/sublime-reindent-on-save/raw/master/screenshot.gif) 5 | 6 | This is simple plugin to call *reindent* each time you save your file. 7 | 8 | What you should be aware is that sublime's *reindent* is not perfect. 9 | 10 | You can specify file types which you want to be reindented on save: 11 | 12 | "reindent_on_save": ["css", "SCSS", "html", "Js"] 13 | 14 | 15 | Installation 16 | ------------ 17 | 18 | The recommended installation method is via Package Control. Learn more here: https://sublime.wbond.net/. 19 | 20 | 21 | How to add configuration option 22 | ------------------------------- 23 | 24 | In your Sublime navigate to **Preferences** \ **Settings - User** 25 | 26 | Your settings file will be opened. 27 | 28 | In fresh installation of Sublime it probably will be something like this: 29 | 30 | { 31 | "ignored_packages": ["Vintage"] 32 | } 33 | 34 | Or if you have made some changes, they will be saved here, in my case I had something like this: 35 | 36 | { 37 | "color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme", 38 | "convert_tabspaces_on_save": true, 39 | "default_line_ending": "unix", 40 | "draw_white_space": "all", 41 | "ensure_newline_at_eof_on_save": true, 42 | "font_size": 14, 43 | "highlight_line": true, 44 | "highlight_modified_tabs": true, 45 | "ignored_packages": ["Vintage"], 46 | "rulers": [80, 120], 47 | "show_encoding": true, 48 | "show_line_endings": true, 49 | "translate_tabs_to_spaces": true, 50 | "trim_trailing_white_space_on_save": true, 51 | "word_wrap": false 52 | } 53 | 54 | To add new options, just place comma after last option and add new one, here is what it will look like in fresh installation: 55 | 56 | { 57 | "ignored_packages": ["Vintage"], 58 | "reindent_on_save": ["php", "sublime-settings", "json", "html", "css"] 59 | } 60 | 61 | That is important to not forget add comma, or sublime will fail saving changes, and show you error message "Error trying to parse settings: Unexpected character, expected a comma" 62 | -------------------------------------------------------------------------------- /ReindentOnSave.py: -------------------------------------------------------------------------------- 1 | import sublime, sublime_plugin, os 2 | 3 | class ReindentOnSave(sublime_plugin.EventListener): 4 | def on_pre_save(self, view): 5 | cfg = view.settings().get('reindent_on_save', True) 6 | 7 | if not cfg: 8 | return 9 | 10 | path = view.file_name() 11 | 12 | if not path: 13 | return 14 | 15 | if isinstance(cfg, list): 16 | extension = (path.split('.')[-1]).lower() 17 | if extension in [ext.lower() for ext in cfg]: 18 | view.window().run_command('reindent', {"single_line": False}) 19 | else: 20 | view.window().run_command('reindent', {"single_line": False}) 21 | -------------------------------------------------------------------------------- /screenshot.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mac2000/sublime-reindent-on-save/83a4c68c73c4bad58fbb8cc80e815c52868f34cb/screenshot.gif --------------------------------------------------------------------------------