-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathload.vim
223 lines (216 loc) · 6.57 KB
/
load.vim
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
" Utils
function! s:deep_extend(d, e)
for [k, V] in items(a:e)
if type(V) == type({})
let a:d[k] = s:deep_extend(get(a:d, k, {}), V)
else
let a:d[k] = V
endif
unlet V
endfor
return a:d
endfunction
" Default interpreters
function! s:pp_remove_fat_arrow(line)
" Strip fat arrows
return substitute(a:line, '=> ', '', 'g')
endfunction
function! s:pp_remove_esc(line)
" Strip [?2004l
return substitute(a:line, '[?2004l', '', 'g')
endfunction
function! s:pp_ml(line)
" If the line is a prompt
if a:line =~ '^# '
" In ocaml, the number of characters before value divided by 2 is
" the number of newlines.
let val = match(a:line, '[^# ]')
return '# '.repeat("\n# ", val / 2 - 1)."\n".a:line[val:]
else
return a:line
endif
endfunction
function! s:pp_r(line)
" Just return everything after the braces
return substitute(a:line, '\s*\[\d\+\]\s*\(.*\)$', '\1', '')
endfunction
let s:pp_purs_state = {}
function! s:pp_purs(line)
let l = a:line
let rgx_prompt = s:codi_default_interpreters.purescript.prompt
if exists('g:codi#interpreters.purescript.prompt')
" Prompt regex overridden by user
let rgx_prompt = g:codi#interpreters.purescript.prompt
endif
let rgxs_ignore = [
\ '\s*See https://github.com/purescript.* for more information,',
\ '\s*or to contribute content related to this error.',
\ ]
let rgx_trimlast = '\s*See https://github.com/purescript.* for more information,'
if l =~ rgx_prompt
" If line saved, send through before next prompt
if exists('s:pp_purs_state.lastline')
let l = s:pp_purs_state.lastline . "\n" . l
unlet s:pp_purs_state.lastline
endif
else
let tmp = ''
if exists('s:pp_purs_state.lastline')
if l =~ rgx_trimlast
" Trim (un-indent) last saved line if special regex matches
let s:pp_purs_state.lastline = substitute(s:pp_purs_state.lastline, '^\s*', '', '')
endif
let tmp = s:pp_purs_state.lastline
endif
if max(map(copy(rgxs_ignore), 'l =~ v:val'))
" Send empty-string if line matched regexes to ignore
let l = ''
endif
if len(l)
let s:pp_purs_state.lastline = l
let l = tmp
endif
unlet tmp
endif
return l
endfunction
" Default rephrasers
function! s:rp_purs(buf)
let b = a:buf
" Alternative to Ctrl-d, ":endpaste" will terminate
" multi-line continuations in psci
let b = substitute(b, ':endpaste\>', '', 'g')
" Remove comments. In PSCi they produce an error
" (Multi-line comments not supported here)
let b = substitute(b, '\%(^\|[\n\r\x00]\)\s*--[^\n\r\x00]*', '', 'g')
" Extra newline to flush any remaining 'lastline' from preprocess
return b . "\n"
endfunction
" Haskell rephrasers
function! s:rp_hs(buf)
let printer = 'let codiPrettyPrint = putStrLn . take 50 . show'
let setprint = ':set -interactive-print codiPrettyPrint'
let prompt1 = ':set prompt "Codi Prompt"'
return printer."\n".setprint."\n".prompt1."\n".a:buf
endfunction
" Php rephrasers
function! s:rp_php(buf)
if a:buf[0:4] ==# '<?php'
let b = a:buf[5:]
else
let b = a:buf
endif
return b
endfunction
" Python rephrasers
function! s:rp_py(buf)
let b = a:buf
" Insert # in the blank lines above Python's indention line to avoid
" `IndentationError`.
let b = substitute(b, '\(\s*\n\)\+\(\n\s\+\w\+\)\@=', '\=substitute(submatch(0), "\s*\n", "\r#", "g")', 'g')
return b
endfunction
let s:codi_default_interpreters = {
\ 'python': {
\ 'bin': has('win32') ? ['python']
\ : ['env', 'PYTHONSTARTUP=', 'python'],
\ 'prompt': '^\(>>>\|\.\.\.\) ',
\ 'rephrase': function('s:rp_py'),
\ 'quitcmd': 'exit()',
\ },
\ 'javascript': {
\ 'bin': ['node', '-e', 'require("repl").start({ignoreUndefined: true, useGlobal: true})'],
\ 'prompt': '^\(>\|\.\.\.\+\) ',
\ 'quitcmd': '.exit',
\ },
\ 'typescript': {
\ 'bin': ['tsun', '--ignore-undefined'],
\ 'prompt': '^\(>\|\.\.\.\+\) ',
\ },
\ 'coffee': {
\ 'bin': 'coffee',
\ 'prompt': '^coffee> ',
\ },
\ 'haskell': {
\ 'bin': ['ghci', '-ignore-dot-ghci'],
\ 'prompt': '^Codi Prompt',
\ 'rephrase': function('s:rp_hs'),
\ },
\ 'purescript': {
\ 'bin': ['pulp', 'psci'],
\ 'prompt': '^[^>…]*[>…] ',
\ 'rephrase': function('s:rp_purs'),
\ 'preprocess': function('s:pp_purs'),
\ 'quitcmd': ':q',
\ },
\ 'ruby': {
\ 'bin': ['irb', '-f', '--nomultiline'],
\ 'prompt': '^irb(\w\+):\d\+:\d\+. ',
\ 'preprocess': function('s:pp_remove_fat_arrow'),
\ },
\ 'ocaml': {
\ 'bin': 'ocaml',
\ 'prompt': '^# ',
\ 'preprocess': function('s:pp_ml'),
\ },
\ 'r': {
\ 'bin': 'R',
\ 'prompt': '^> ',
\ 'preprocess': function('s:pp_r'),
\ },
\ 'clojure': {
\ 'bin': ['planck', '--verbose', '--dumb-terminal'],
\ 'prompt': '^.\{-}=> ',
\ },
\ 'php': {
\ 'bin': ['psysh'],
\ 'prompt': '^\(>>>\|\.\.\.\) ',
\ 'rephrase': function('s:rp_php'),
\ 'preprocess': function('s:pp_remove_fat_arrow'),
\ },
\ 'lua': {
\ 'bin': ['lua'],
\ 'prompt': '^\(>\|>>\) ',
\ },
\ 'cpp': {
\ 'bin': 'cling',
\ 'prompt': '^\[cling\]\$ ?\?',
\ 'quitcmd': '.q',
\ },
\ 'julia': {
\ 'bin': ['julia', '-qi', '--color=no', '--history-file=no'],
\ 'prompt': '\(julia> \)',
\ 'preprocess': function('s:pp_remove_esc'),
\ },
\ 'elm': {
\ 'bin': ['elm', 'repl'],
\ 'prompt': '^> '
\ },
\ 'elixir': {
\ 'bin': ['iex'],
\ 'prompt': '^iex(\d\+). '
\ },
\ 'mathjs': {
\ 'bin': ['mathjs'],
\ 'prompt': '^\(>\|\.\.\.\+\) ',
\ },
\ 'haxe': {
\ 'bin': ['haxelib', 'run', 'ihx', '-codi'],
\ 'prompt': '>> ',
\ 'quitcmd': 'exit',
\ },
\ 'nim': {
\ 'bin': ['inim'],
\ 'prompt': '^\(nim>\|\.\.\.\) ',
\ },
\ }
function! codi#load#interpreters()
return s:deep_extend(s:codi_default_interpreters, g:codi#interpreters)
endfunction
" Default aliases
let s:codi_default_aliases = {
\ 'javascript.jsx': 'javascript',
\ }
function! codi#load#aliases()
return s:deep_extend(s:codi_default_aliases, g:codi#aliases)
endfunction