-
Notifications
You must be signed in to change notification settings - Fork 1
/
BunchCompletions.py
67 lines (48 loc) · 2.05 KB
/
BunchCompletions.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sublime
import sublime_plugin
import os
import re
from subprocess import check_output
import operator
class AppCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], "entity.name.function.app.bunch"):
return []
def trim_App(iter_in):
result = str(re.sub('.*/([^/]+).app\'', '\\1', str(iter_in)))
if len(result):
return result
all_apps = check_output(['/usr/bin/mdfind', 'kMDItemContentType = "com.apple.application-bundle" && kMDItemDisplayName = "*.app"cd'])
available_completions = map(trim_App, all_apps.split(b"\n"))
prefix = prefix.lower()
out = []
for comp in available_completions:
if comp.lower().startswith(prefix):
out.append(comp)
return (out, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)
class ChainedActionsCommand(sublime_plugin.TextCommand):
def run(self, edit, actions, args):
for i, action in enumerate(actions):
self.view.run_command(action, args[i])
def getFragmentIds(view, name=''):
frags = []
frags.extend(view.find_all(r"^(?:-{2,}|[=>#])[\-=># ]*\[([^\]]+)\]", 0))
regions = frags
ids = []
for reg in regions:
name = view.substr(reg).strip()
name = str(re.sub('^(?:-{2,}|[=>#])[\\-=># ]*\\[([^\\]]+)\\].*$', '\\1', name))
ids.append(name)
return ids
class SnippetFragmentCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if not view.match_selector(locations[0], "meta.snippet.fragment.bunch"):
return []
print(prefix)
available_completions = getFragmentIds(view)
prefix = prefix.lower()
out = []
for comp in available_completions:
if comp.lower().startswith(prefix):
out.append(comp)
return (out, sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS)