The following Sublime Text 3 plugin overrides the default detect_indentation
mechanism by a more straightforward approach: the values of translate_tabs_to_spaces
and tab_size
are set depending to the file type of exention.
// stupid_indent.py
import os.path
import fnmatch
import sublime
import sublime_plugin
class StupidIndent(sublime_plugin.EventListener):
def on_load(self, view):
basename = os.path.basename(view.file_name());
settings = view.settings()
for entry in sublime.load_settings('Stupid Indent.sublime-settings').get('configuration'):
for pattern in entry.get('patterns', []):
if fnmatch.fnmatch(basename, pattern):
settings.set('tab_size', entry.get('tab_size', settings.get('tab_size')))
settings.set('translate_tabs_to_spaces', entry.get('translate_tabs_to_spaces', settings.get('translate_tabs_to_spaces')))
return
// Stupid Indent.sublime-settings
{
"configuration":
[
{
"patterns": ["*.html", "*.js", "*.css"],
"tab_size": 2,
"translate_tabs_to_spaces": true
},
{
"patterns": ["*.md", "*.markdown"],
"tab_size": 4,
"translate_tabs_to_spaces": true
},
{
"patterns": ["Makefile"],
"tab_size": 4,
"translate_tabs_to_spaces": false
}
]
}
I put them both in $packages/Stupid Indent
, but it doesn’t seem to work. I also tried to move the .sublime-settings
file to $packages/User
, but this didn’t help.
Why is that? Is there an error on my side or the plugin code should be updated to work in Sublime Text 4?