Sublime Forum

How to check detected tab type and size?

#1

I was create plugin for auto convert indentaion to tabs on load file.

[code]import sublime, sublime_plugin

class ConvertToTabsOnLoad(sublime_plugin.EventListener):
def on_load(self, view):
if view.settings().get(ā€˜convert_to_tabs_on_loadā€™) == 1:
view.run_command(ā€˜unexpand_tabsā€™, {ā€˜argsā€™: {ā€˜set_translate_tabsā€™: True}})
[/code]
but always file status set to modified status after open file.
I want check detected tab type and size and convert if detected indentation type is space only.
can I check detected indentation type?

0 Likes

#2

Check view settings:

  • tab_size
  • translate_tabs_to_spaces
0 Likes

#3

change on_load to on_modified_async event
if use on_modified event then crashed :frowning:

[code]import sublime, sublime_plugin

class ConvertToTabsOnModify(sublime_plugin.EventListener):
updated = False

def on_modified_async(self, view):
	if view.settings().get('convert_to_tabs_on_modify') == True and self.updated == False:
		view.run_command('unexpand_tabs', {'args': {'set_translate_tabs': True}})
		self.updated = True

def on_post_save(self, view):
	self.updated = False[/code]

// add user setting
ā€œconvert_to_tabs_on_modifyā€: true

0 Likes