-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathLineEndings.py
More file actions
59 lines (45 loc) · 1.91 KB
/
LineEndings.py
File metadata and controls
59 lines (45 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import sublime, sublime_plugin
s = sublime.load_settings('LineEndings.sublime-settings')
class Pref:
def load(self):
Pref.show_line_endings_on_status_bar = s.get('show_line_endings_on_status_bar', True)
Pref.alert_when_line_ending_is = s.get('alert_when_line_ending_is', [])
Pref = Pref()
Pref.load()
s.add_on_change('reload', lambda:Pref.load())
class SetLineEndingsOnLoad(sublime_plugin.EventListener):
def on_load(self, view):
line_ending_type = view.settings().get('set_line_ending_on_load')
if line_ending_type:
view.run_command('set_line_ending', {"type":line_ending_type})
class StatusBarLineEndings(sublime_plugin.EventListener):
def on_load(self, view):
if view.line_endings() in Pref.alert_when_line_ending_is:
sublime.message_dialog(u''+view.line_endings()+' line endings detected on file:\n\n'+view.file_name());
if Pref.show_line_endings_on_status_bar:
self.show(view)
def on_activated(self, view):
if Pref.show_line_endings_on_status_bar:
self.show(view)
def show(self, view):
if view is not None:
if view.is_loading():
sublime.set_timeout(lambda:self.show(view), 100)
else:
view.set_status('line_endings', view.line_endings())
sublime.set_timeout(lambda:view.set_status('line_endings', view.line_endings()), 400)
class SetLineEndingWindowCommand(sublime_plugin.TextCommand):
def run(self, view, type):
for view in sublime.active_window().views():
view.run_command('set_line_ending', {"type":type})
def is_enabled(self):
return len(sublime.active_window().views())
class ConvertIndentationWindowCommand(sublime_plugin.TextCommand):
def run(self, view, type):
for view in sublime.active_window().views():
if type == 'spaces':
view.run_command('expand_tabs', {"set_translate_tabs":True})
else:
view.run_command('unexpand_tabs', {"set_translate_tabs":True})
def is_enabled(self):
return len(sublime.active_window().views())