mirror of https://github.com/akelge/vim
Fixed up templating system
This commit is contained in:
parent
cf2f06bc21
commit
f11aeb05e4
|
@ -1,3 +1,26 @@
|
||||||
|
" 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
|
" Preserve template files
|
||||||
augroup newfiles
|
augroup newfiles
|
||||||
" First we load templates for the file type
|
" First we load templates for the file type
|
||||||
|
@ -6,8 +29,10 @@ augroup newfiles
|
||||||
" Update of "Last Modified" date on writing
|
" Update of "Last Modified" date on writing
|
||||||
autocmd BufWritePre,FileWritePre * ks|call LastMod()|'s
|
autocmd BufWritePre,FileWritePre * ks|call LastMod()|'s
|
||||||
|
|
||||||
" Protect templates, removing write commands
|
" Protect templates and plugin, removing write commands
|
||||||
autocmd BufRead,BufNewFile ~/.vim/templates/* au! newfiles
|
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
|
" Reload .vimrc, after modifications
|
||||||
autocmd BufWritePost ~/.vimrc so ~/.vimrc
|
autocmd BufWritePost ~/.vimrc so ~/.vimrc
|
||||||
|
@ -16,26 +41,25 @@ augroup newfiles
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Set up python support
|
" Set up python support
|
||||||
"au FileType python source ~/.vim/addon/python.vim
|
|
||||||
augroup END
|
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()
|
function! LastMod()
|
||||||
if line("$") > 20
|
if line("$") > 20
|
||||||
let l = 20
|
let l = 20
|
||||||
else
|
else
|
||||||
let l = line("$")
|
let l = line("$")
|
||||||
endif
|
endif
|
||||||
execute "1," . l . "g/Last modified: /s/Last modified: .*/Last modified: " .
|
execute "1," . l . "s/@@lmdate@@/" .
|
||||||
\ strftime("%d:%b:%Y %H:%M")
|
\ strftime("%FT%X %Z") . "/e"
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Function to open a file and set some defaults
|
" Function to open a file and set some defaults
|
||||||
function! OpenFile()
|
function! OpenFile()
|
||||||
let s:filename=expand("<afile>")
|
let s:filename=expand("<afile>")
|
||||||
let l:ext=fnamemodify(s:filename, ":e")
|
let l:ext=fnamemodify(s:filename, ":e")
|
||||||
let l:skel = "~/.vim/templates/skeleton.".l:ext
|
let l:skel = g:skeletons."/skeleton.".l:ext
|
||||||
if filereadable(fnamemodify(l:skel,":p"))
|
if filereadable(fnamemodify(l:skel,":p"))
|
||||||
execute "0r" l:skel
|
execute "0r" l:skel
|
||||||
let s:syn=input("Synopsis: ")
|
let s:syn=input("Synopsis: ")
|
||||||
|
@ -44,10 +68,14 @@ function! OpenFile()
|
||||||
else
|
else
|
||||||
let l = line("$")
|
let l = line("$")
|
||||||
endif
|
endif
|
||||||
execute "1," . l . "g/First version: /s/First version: .*/First version: ".
|
execute "1," . l . "s/@@DESCR@@/" .
|
||||||
\ strftime("%d:%b:%Y %H:%M")
|
|
||||||
execute "1," . l . "g/Synopsis: /s/Synopsis: .*/Synopsis: ".
|
|
||||||
\ s:syn
|
\ 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
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
/*
|
/*
|
||||||
-*- coding: latin-1 -*-
|
-*- coding: latin-1 -*-
|
||||||
|
|
||||||
Copyright by Andrea Mistrali <am@am.cx>.
|
Copyright by @@LONGNAME@@ <@@EMAIL@@>
|
||||||
First version: <crdate>
|
First version: @@crdate@@
|
||||||
Last modified: <lmdate>
|
Last modified: @@lmdate@@
|
||||||
|
|
||||||
Synopsis: <description>
|
Synopsis: @@DESCR@@
|
||||||
|
|
||||||
$Id$
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/usr/bin/env perl
|
#!/usr/bin/env perl
|
||||||
# -*- coding: latin-1 -*-
|
# -*- coding: latin-1 -*-
|
||||||
|
|
||||||
# Copyright by Andrea Mistrali <am@am.cx>.
|
# Copyright by @@LONGNAME@@ <@@EMAIL@@>
|
||||||
# First version: <crdate>
|
# First version: @@crdate@@
|
||||||
# Last modified: <lmdate>
|
# Last modified: @@lmdate@@
|
||||||
#
|
#
|
||||||
# Synopsis: <description>
|
# Synopsis: @@DESCR@@
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
|
@ -3,18 +3,18 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Copyright by Andrea Mistrali <am@am.cx>.
|
Copyright by @@LONGNAME@@ <@@EMAIL@@>
|
||||||
First version: <crdate>
|
First version: @@crdate@@
|
||||||
Last modified: <lmdate>
|
Last modified: @@lmdate@@
|
||||||
|
|
||||||
Synopsis: <description>
|
Synopsis: @@DESCR@@
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__version__ ='0.1'
|
__version__ ='0.1'
|
||||||
__author__ ='Andrea Mistrali <am@am.cx>'
|
__author__ ='@@LONGNAME@@ <@@EMAIL@@>'
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# -*- coding: latin-1 -*-
|
# -*- coding: latin-1 -*-
|
||||||
|
|
||||||
# Copyright by Andrea Mistrali <am@am.cx>.
|
# Copyright by @@LONGNAME@@ <@@EMAIL@@>
|
||||||
# First version: <crdate>
|
# First version: @@crdate@@
|
||||||
# Last modified: <lmdate>
|
# Last modified: @@lmdate@@
|
||||||
#
|
#
|
||||||
# Synopsis: <description>
|
# Synopsis: @@DESCR@@
|
||||||
#
|
#
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
" General Setup
|
" General Setup
|
||||||
"
|
"
|
||||||
" $Id$
|
" $Id$
|
||||||
|
"
|
||||||
|
|
||||||
set nocompatible " Use Vim defaults (much better!)
|
set nocompatible " Use Vim defaults (much better!)
|
||||||
set backspace=indent,eol,start " allow backspacing over everything
|
set backspace=indent,eol,start " allow backspacing over everything
|
||||||
|
@ -46,6 +47,12 @@ set fileformat=unix
|
||||||
set mouse=a
|
set mouse=a
|
||||||
colorscheme inkpot
|
colorscheme inkpot
|
||||||
|
|
||||||
|
" """""""""
|
||||||
|
" User Info
|
||||||
|
" """""""""
|
||||||
|
let g:fullname = 'Andrea Mistrali'
|
||||||
|
let g:email = 'am@am.cx'
|
||||||
|
|
||||||
|
|
||||||
" """""""""""""""""""""""""
|
" """""""""""""""""""""""""
|
||||||
" COMPLETION & INDENTATION
|
" COMPLETION & INDENTATION
|
||||||
|
|
Loading…
Reference in New Issue