global !p
def complete(t, opts):
	if t:
		opts = [m[len(t):] for m in opts if m.startswith(t)]
	if len(opts) == 1:
		return opts[0]
	return "(" + '|'.join(opts) + ")"
endglobal

snippet fun "F function insert"
$1 <- function($2){
	$0
}
endsnippet


snippet template.shiny "This creates a basic shiny app"

$1 <- fluidPage(title="My quick app",
	tags$h1($2)
)

$3 <- function (input,output,session) {
$4
}
shinyApp($1,$3)
endsnippet

snippet csv "read.csv"
read.csv($1, stringsAsFactors=FALSE)
endsnippet

snippet lsf "list.files"
list.files($1)
endsnippet

snippet head "head"
head($1)
$0
endsnippet


snippet hist "head"
head($1)
$0
endsnippet

snippet äđĐ "An intelligent Doxygen -- I'll improve it further" A
`!p
if snip.c == "":
	curr_row = int(vim.eval('line(\'.\')'))
	fun_name = vim.eval('getline({},{})'.format(curr_row+8, curr_row+8))[0]
	result = fun_name.split('<-')[0]
	snip.rv  = f"\
#' {result}"
`
#' 
#' ${1: Description}
#'
#' @param ${2: first parameter}
#' @usage ...
#' @export 
$0
endsnippet

snippet "(#' @param.*)" "new param" r
`!p snip.rv = match.group(1) + '\n' + '#\' @param'` $0
endsnippet

snippet "(#' .*)\.\.\." "doxygen new line" r
`!p snip.rv = match.group(1) + '\n' + '#\''` $0
endsnippet

snippet today
`date +%Y-%m-%d` $0
endsnippet



