forked from mattiasnordin/StataEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CompletionsPlugin.py
132 lines (121 loc) · 6.55 KB
/
CompletionsPlugin.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import sublime, sublime_plugin
import Pywin32.setup
import win32com.client
import win32api
import os
import re
settings_file = "StataEditor.sublime-settings"
def plugin_loaded():
global settings
settings = sublime.load_settings(settings_file)
class VariableCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if view.scope_name(view.sel()[0].a) != 'source.stata ': # Only work in
return # do files
else:
if settings.get('variable_completions'): # Get all vars. in the
try: # current dataset
varlist = sublime.stata.VariableNameArray()
complist = []
for i in varlist:
complist.append([i + "\tVariable", i])
return complist
except AttributeError:
return
else:
return
class FunctionCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if view.scope_name(view.sel()[0].a) != 'source.stata ':
return
else:
if settings.get('function_completions'):
funclist = [
'ceil', 'exp', 'floor', 'int', 'ln', 'log', 'logit', 'max',
'min', 'mod', 'round', 'sign', 'sqrt', 'sum', 'Ftail',
'invF', 'invFtail', 'normal', 'invnormal', 'poisson',
'ttail', 'invt', 'invttail', 'char', 'length', 'lower',
'proper', 'real', 'regexm', 'reverse', 'strcat', 'string',
'strlen', 'strlower', 'strmatch', 'strpos', 'strproper',
'strreverse', 'strtoname', 'strtrim', 'strupper',
'subinstr', 'subinword', 'substr', 'trim', 'upper', 'word',
'wordcount', 'float', 'inlist', 'inrange', 'matrix',
'missing', 'recode', 'return', 'scalar', 'det', 'trace',
'cholesky', 'corr', 'diag', 'hadamard', 'inv'
] # Only auto-complete frequently used funcs.
complist = []
for i in funclist:
complist.append([i + "\tFunction", i + "($1)$0"])
return complist
else:
return
class CommandCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if view.scope_name(view.sel()[0].a) != 'source.stata ':
return
else:
if settings.get("command_completions") == True:
cmdlist = [
"append", "areg", "binreg", "bootstrap", "break", "by",
"capture", "char", "chdir", "class", "clear", "cluster",
"codebook", "collapse", "compress", "continue", "copy",
"correlate", "count", "cross", "describe", "destring",
"dfgls", "dfuller", "dir", "display", "do", "duplicates",
"dydx", "edit", "egen", "encode", "erase", "error", "estat",
"estimates", "estimates_notes", "exit", "export", "factor",
"file", "filefilter", "findit", "foreach", "forecast",
"format", "forvalues", "generate", "glm", "gmm", "graph",
"gsort", "hausman", "heckman", "help", "histogram", "if",
"import", "impute", "include", "infile", "infix", "input",
"insheet", "ipolate", "isid", "ivreg", "ivregress",
"jackknife", "javacall", "joinby", "kdensity", "ksm",
"ksmirnov", "label", "levelsof", "lfit", "lincom", "line",
"list", "log", "logistic", "logit", "lowess", "lpoly",
"lrtest", "macro", "margins", "marginsplot", "mata",
"mata_clear", "mata_describe", "mata_drop", "mata_matsave",
"mata_memory", "mata_mlib", "mata_mosave", "mata_rename",
"mata_which", "matalabel", "matlist", "matrix", "mean",
"merge", "mkdir", "mkmat", "mlogit", "newey", "notes",
"numlist", "odbc", "ologit", "oprobit", "order", "palette",
"pause", "pca", "pcorr", "pctile", "permute", "plot",
"plugin", "poisson", "post", "power", "pperron", "predict",
"predictnl", "preserve", "probit", "program", "quietly",
"range", "recast", "recode", "regress", "rename", "reshape",
"return", "rmdir", "save", "scalar", "scatter", "shell",
"sleep", "sort", "spearman", "split", "ssc", "statsby",
"stfill", "stptime", "streg", "sts", "stset", "stsplit",
"stsum", "suest", "sum", "summarize", "sureg", "svy",
"svy_estat", "svydescribe", "svygen", "svyset", "svytest",
"syntax", "sysdir", "sysuse", "table", "tabstat",
"tabulate", "teffects", "test", "testnl", "timer", "tobit",
"total", "tsfill", "tsline", "tsset", "ttest", "update",
"use", "var", "vce", "webuse", "which", "while", "xpose",
"xtdata", "xtdescribe", "xtgls", "xtivreg", "xtline",
"xtlogit", "xtreg", "xtset", "xtsum", "xttab", "xttobit",
"zip", "reghdfe"]
complist = []
for i in cmdlist:
complist.append([i + "\tCommand", i])
return complist
else:
return
class FileCompletions(sublime_plugin.EventListener):
def on_query_completions(self, view, prefix, locations):
if view.scope_name(view.sel()[0].a) != 'source.stata ':
return
else:
if settings.get("file_completions") != False:
complist = []
global_map = {r'^\d*_*[cC]ode/': '\$code/',
r'^\d*_*[dD]ata/': '\$data/',
r'^\d*_*[rR]awdata/': '\$rawdata/',
r'^\d*_*[tT]emp/': '\$temp/',
r'^\d*_*[fF]igure/': '\$fig/',
r'^\d*_*[tT]able/': '\$tab/'}
for i in sublime.file_list:
for key in global_map:
filename = re.sub(key, global_map[key], i)
complist.append([i + "\tfile", '"' + filename + '"'])
return complist
else:
return