This repository was archived by the owner on Jul 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevents.py
50 lines (40 loc) · 1.76 KB
/
events.py
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
# encoding: utf-8
import sublime, sublime_plugin
try:
from . import util
except ValueError:
import util
class PerformEventListener(sublime_plugin.EventListener):
"""Suggest subroutine completions for the perform statement."""
def on_query_completions(self, view, prefix, points):
if not util.is_natural_file(view):
return None
texts = util.text_preceding_points(view, points)
if all([text.strip().lower().endswith(u'perform') for text in texts]):
subroutines = util.find_text_by_selector(view,
'entity.name.function.natural')
if not subroutines:
return None
subroutines.sort()
completions = [(sub, sub) for sub in subroutines]
return (completions, sublime.INHIBIT_WORD_COMPLETIONS)
class AddRulerToColumn72Listener(sublime_plugin.EventListener):
"""Add a ruler to column 72 when a Natural file is opened. If the user has
other rulers, they're not messed with."""
def on_load(self, view):
if not util.is_natural_file(view):
return
rulers = view.settings().get(u'rulers')
if 72 not in rulers:
rulers.append(72)
rulers.sort() # why? to be neat.
view.settings().set(u'rulers', rulers)
class FixWordSeparatorsListener(sublime_plugin.EventListener):
"""Fix the `word_separators` setting for a Natural view so that the hyphen
and hash sign can be considered parts of words."""
def on_load(self, view):
if not util.is_natural_file(view):
return
separators = view.settings().get(u'word_separators')
separators = separators.replace(u'-', u'').replace(u'#', u'')
view.settings().set(u'word_separators', separators)