diff options
-rw-r--r-- | autoload/sonictemplate.vim | 14 | ||||
-rw-r--r-- | template/clojure/base-main.clj | 7 |
2 files changed, 20 insertions, 1 deletions
diff --git a/autoload/sonictemplate.vim b/autoload/sonictemplate.vim index 229d2cb..f411ada 100644 --- a/autoload/sonictemplate.vim +++ b/autoload/sonictemplate.vim @@ -169,9 +169,20 @@ function! sonictemplate#getvar(name) abort return has_key(s:vars[ft], a:name) ? s:vars[ft][a:name] : '' endfunction +function! s:dir() abort + let l:name = expand('%:t:r:') + if empty(l:name) + let l:name = fnamemodify(getcwd(), ':t') + endif + return substitute(l:name, '[^a-zA-Z0-9]', '_', 'g') +endfunction + function! s:name(default) abort let l:name = expand('%:t:r:') - return empty(l:name) ? a:default : l:name + if empty(l:name) + let l:name = a:default + endif + return substitute(l:name, '[^a-zA-Z0-9]', '_', 'g') endfunction function! sonictemplate#apply(name, mode, ...) abort @@ -223,6 +234,7 @@ function! sonictemplate#apply(name, mode, ...) abort let ft = s:get_filetype() let ft = ft != "" ? ft : "_" let c = join(readfile(f), "\n") + let c = substitute(c, '{{_dir_}}', s:dir(), 'g') let c = substitute(c, '{{_name_}}', s:name('Main'), 'g') let c = substitute(c, '{{_name_:\([^}]\+\)}}', '\=s:name(submatch(1))', 'g') let tmp = c diff --git a/template/clojure/base-main.clj b/template/clojure/base-main.clj new file mode 100644 index 0000000..d484225 --- /dev/null +++ b/template/clojure/base-main.clj @@ -0,0 +1,7 @@ +(ns {{_dir_}}.core + (:gen-class)) + +(defn -main + "main." + [& args] + (println "{{_cursor_}}")) |