summaryrefslogtreecommitdiffstats
path: root/ftplugin/mma.vim
blob: b22ce1c9edbce7245b33b2c847d894ec8bf4eb5a (plain) (blame)
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
let files = filter(globpath(&rtp, 'ftplugin/mma.vim', 1, 1), { _, v -> v !~ "vim-polyglot" && v !~ $VIMRUNTIME && v !~ "after" })
if len(files) > 0
  exec 'source ' . files[0]
  finish
endif
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'mathematica') == -1

"Vim filetype plugin
" Language: Mathematica
" Maintainer: R. Menon <rsmenon@icloud.com>
" Last Change: Feb 26, 2013

" Initialization {
if exists("b:did_ftplugin")
  finish
endif
let b:did_ftplugin = 1

let s:cpo_save = &cpo
set cpo&vim
"}

" Syntax completion function {
if exists('&ofu')
	setlocal omnifunc=syntaxcomplete#Complete
	setlocal completefunc=syntaxcomplete#Complete
endif
"}

" Main functions {
if has('python')
	" Random ID generator {
	function! RandomID()

"Python implementation follows; do not alter indentations/whitespace
python << EOF
import random, string, vim
vim.command("let l:id = '" + (''.join(random.sample(string.ascii_uppercase + string.digits, 8))) + "'")
EOF

	return l:id
	endfunction
	"}

	"Unit test template {
	function! Test()
		if exists("*strftime")
			let l:date = strftime("%Y%m%d") . "-"
		else
			let l:date = ""
		endif

		let l:testid = expand("%:t") . "-" . l:date . RandomID()
		let l:template = "Test[\rtest\r,\rresult\r,\rTestID -> \"" . l:testid . "\"\r\b]"
		exe ":normal i" . l:template
	endfunction
	"}
endif
"}

" Cleanup {
let &cpo = s:cpo_save
unlet s:cpo_save
"}

" vim: set foldmarker={,} foldlevel=0 foldmethod=marker:

endif