mirror of
https://github.com/akelge/zsh
synced 2025-07-03 21:19:06 +00:00
Fixed up templating system
This commit is contained in:
@ -1,53 +1,81 @@
|
||||
" Copyright by Andrea Mistrali <am@am.cx>
|
||||
" First version: Who knows?
|
||||
" Last modified: 2009-04-01T16:55:05 CEST
|
||||
"
|
||||
" Synopsis: Templating system for vim
|
||||
"
|
||||
" $Id$
|
||||
"
|
||||
" Remember to define in your vimrc the following var
|
||||
" let g:fullname = 'Your Full Name'
|
||||
" let g:email = 'your.email@address'
|
||||
"
|
||||
" Skeleton files could contain (in the first 20 lines) the following
|
||||
" 'vars':
|
||||
" @@LONGNAME@@ - replaced by g:fullname
|
||||
" @@EMAIL@@ - replaced by g:email
|
||||
" @@DESCR@@ - Synopsis of file (asked by this plugin
|
||||
" @@crdate@@ - replaced by creation date
|
||||
" 2009-04-01T17:03:00 CEST - replaced by last modification date
|
||||
|
||||
" Define template directory
|
||||
let g:skeletons = '~/.vim/templates'
|
||||
|
||||
" Preserve template files
|
||||
augroup newfiles
|
||||
" First we load templates for the file type
|
||||
autocmd BufNewFile * ks|call OpenFile()|'s
|
||||
" First we load templates for the file type
|
||||
autocmd BufNewFile * ks|call OpenFile()|'s
|
||||
|
||||
" Update of "Last Modified" date on writing
|
||||
autocmd BufWritePre,FileWritePre * ks|call LastMod()|'s
|
||||
" Update of "Last Modified" date on writing
|
||||
autocmd BufWritePre,FileWritePre * ks|call LastMod()|'s
|
||||
|
||||
" Protect templates, removing write commands
|
||||
autocmd BufRead,BufNewFile ~/.vim/templates/* au! newfiles
|
||||
" Protect templates and plugin, removing write commands
|
||||
autocmd BufRead,BufNewFile ~/.vim/templates/* au! newfiles
|
||||
autocmd BufRead,BufNewFile */skeleton.vim au! newfiles
|
||||
autocmd BufWritePre,FileWritePre */skeleton.vim au! newfiles
|
||||
|
||||
" Reload .vimrc, after modifications
|
||||
autocmd BufWritePost ~/.vimrc so ~/.vimrc
|
||||
if has("gui_running")
|
||||
autocmd BufWritePost ~/.gvimrc so ~/.gvimrc
|
||||
endif
|
||||
" Reload .vimrc, after modifications
|
||||
autocmd BufWritePost ~/.vimrc so ~/.vimrc
|
||||
if has("gui_running")
|
||||
autocmd BufWritePost ~/.gvimrc so ~/.gvimrc
|
||||
endif
|
||||
|
||||
" Set up python support
|
||||
"au FileType python source ~/.vim/addon/python.vim
|
||||
" Set up python support
|
||||
augroup END
|
||||
|
||||
|
||||
" Function to modify "Last Modified" date. Works on first 10 lines
|
||||
" Function to modify "Last Modified" date. Works on first N lines
|
||||
function! LastMod()
|
||||
if line("$") > 20
|
||||
let l = 20
|
||||
else
|
||||
let l = line("$")
|
||||
endif
|
||||
execute "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .
|
||||
\ strftime("%d:%b:%Y %H:%M")
|
||||
if line("$") > 20
|
||||
let l = 20
|
||||
else
|
||||
let l = line("$")
|
||||
endif
|
||||
execute "1," . l . "s/@@lmdate@@/" .
|
||||
\ strftime("%FT%X %Z") . "/e"
|
||||
endfunction
|
||||
|
||||
" Function to open a file and set some defaults
|
||||
function! OpenFile()
|
||||
let s:filename=expand("<afile>")
|
||||
let l:ext=fnamemodify(s:filename, ":e")
|
||||
let l:skel = "~/.vim/templates/skeleton.".l:ext
|
||||
if filereadable(fnamemodify(l:skel,":p"))
|
||||
execute "0r" l:skel
|
||||
let s:syn=input("Synopsis: ")
|
||||
if line("$") > 20
|
||||
let l = 20
|
||||
else
|
||||
let l = line("$")
|
||||
endif
|
||||
execute "1," . l . "g/First version: /s/First version: .*/First version: ".
|
||||
\ strftime("%d:%b:%Y %H:%M")
|
||||
execute "1," . l . "g/Synopsis: /s/Synopsis: .*/Synopsis: ".
|
||||
\ s:syn
|
||||
endif
|
||||
let s:filename=expand("<afile>")
|
||||
let l:ext=fnamemodify(s:filename, ":e")
|
||||
let l:skel = g:skeletons."/skeleton.".l:ext
|
||||
if filereadable(fnamemodify(l:skel,":p"))
|
||||
execute "0r" l:skel
|
||||
let s:syn=input("Synopsis: ")
|
||||
if line("$") > 20
|
||||
let l = 20
|
||||
else
|
||||
let l = line("$")
|
||||
endif
|
||||
execute "1," . l . "s/@@DESCR@@/" .
|
||||
\ s:syn
|
||||
execute "1," . l . "s/@@crdate@@/" .
|
||||
\ strftime("%FT%X %Z") . "/e"
|
||||
execute "1," . l . "s/@@LONGNAME@@/" .
|
||||
\ g:fullname . "/e"
|
||||
execute "1," . l . "s/@@EMAIL@@/" .
|
||||
\ g:email . "/e"
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
Reference in New Issue
Block a user