mirror of
https://github.com/akelge/zsh
synced 2025-08-15 14:28:35 +00:00
Moved to Vundle
Adopted vim-templates plugin, instead of homegrown skeleton
This commit is contained in:
166
vim/bundle/vim-template/README.rst
Normal file
166
vim/bundle/vim-template/README.rst
Normal file
@ -0,0 +1,166 @@
|
||||
=============================
|
||||
Simple Vim templates plugin
|
||||
=============================
|
||||
:Author: Adrian Perez <aperez@igalia.com>
|
||||
|
||||
This is a simple plugin for Vim that will allow you to have a set of
|
||||
templates for certain file types. It is useful to add boilerplate code
|
||||
like guards in C/C++ headers, or license disclaimers.
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
|
||||
The easiest way to install the plugin is to install it as a bundle.
|
||||
For example, using Pathogen__:
|
||||
|
||||
1. Get and install `pathogen.vim <_Pathogen>`__. You can skip this step
|
||||
if you already have it installed.
|
||||
|
||||
2. ``cd ~/.vim/bundle``
|
||||
|
||||
3. ``git clone git://github.com/aperezdc/vim-template.git``
|
||||
|
||||
__ https://github.com/tpope/vim-pathogen
|
||||
|
||||
Bundle installs are known to work fine also when using Vundle__. Other
|
||||
bundle managers are expected to work as well.
|
||||
|
||||
__ https://github.com/gmarik/vundle
|
||||
|
||||
|
||||
Updating
|
||||
========
|
||||
|
||||
Manually
|
||||
--------
|
||||
|
||||
In order to update the plugin, go to its bundle directory and use
|
||||
Git to update it:
|
||||
|
||||
1. ``cd ~/.vim/bundle/vim-template``
|
||||
|
||||
2. ``git pull``
|
||||
|
||||
|
||||
With Vundle
|
||||
-----------
|
||||
|
||||
Use the ``:BundleUpdate`` command provided by Vundle, for example invoking
|
||||
Vim like this::
|
||||
|
||||
% vim +BundleUpdate
|
||||
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
In your vimrc you can put:
|
||||
|
||||
* ``let g:templates_plugin_loaded = 1`` to skip loading of this plugin.
|
||||
|
||||
* ``let g:templates_no_autocmd = 1`` to disable automatic insertion of
|
||||
template in new files.
|
||||
|
||||
* ``let g:templates_directory = '/path/to/directory'`` to specify a directory
|
||||
from where to search for additional global templates. See `template search
|
||||
order`_ below for more details. This can also be a list of paths.
|
||||
|
||||
* ``let g:templates_name_prefix = '.vimtemplate.'`` to change the name of the
|
||||
template files that are searched.
|
||||
|
||||
* ``let g:templates_global_name_prefix = 'template:'`` to change the prefix of the
|
||||
templates in the global template directory.
|
||||
|
||||
* ``let g:templates_debug = 1`` to have vim-template output debug information
|
||||
|
||||
* ``let g:templates_fuzzy_start = 1`` to be able to name templates with
|
||||
implicit fuzzy matching at the start of a template name. For example a
|
||||
template file named ``template:.c`` would match ``test.cpp``.
|
||||
|
||||
* ``let g:templates_tr_in = [ '.', '_', '?' ]`` and
|
||||
``let g:templates_tr_out = [ '\.', '.*', '\?' ]`` would allow you to change
|
||||
how template names are interpretted as regular expressions for matching file
|
||||
names. This might be helpful if hacking on a windows box where ``*`` is not
|
||||
allowed in file names. The above configuration, for example, treates
|
||||
underscores ``_`` as the typical regex wildcard ``.*``.
|
||||
|
||||
* ``let g:templates_no_builtin_templates = 1`` to disable usage of the
|
||||
built-in templates. See `template search order`_ below for more details.
|
||||
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
There are a number of options to use a template:
|
||||
|
||||
|
||||
* Create a new file giving it a name. The suffix will be used to determine
|
||||
which template to use. E.g::
|
||||
|
||||
$ vim foo.c
|
||||
|
||||
* In a buffer, use ``:Template *.foo`` to load the template that would be
|
||||
loaded for file matching the pattern ``*.foo``. E.g. from within Vim::
|
||||
|
||||
:Template *.c
|
||||
|
||||
Template search order
|
||||
---------------------
|
||||
|
||||
The algorithm to search for templates works like this:
|
||||
|
||||
1. A file named ``.vim-template:<pattern>`` in the current directory. If not
|
||||
found, goto *(2)*. If there are multiple template files that match a given
|
||||
suffix in the *same* directory, the one that is most specific is used.
|
||||
|
||||
2. Go up a directory and goto *(1)*, if not possible, goto *(3)*.
|
||||
|
||||
3. Try to use the ``=template=<pattern>`` file from the directory specified
|
||||
using the ``g:templates_directory`` option (only if the option is defined
|
||||
and the directory exists).
|
||||
|
||||
3. Try to use the ``=template=<pattern>`` file supplied with the plugin (only
|
||||
if ``g:templates_no_builtin_templates`` was not defined).
|
||||
|
||||
|
||||
Variables in templates
|
||||
----------------------
|
||||
|
||||
The following variables will be expanded in templates:
|
||||
|
||||
``%DAY%``, ``%YEAR%``, ``%MONTH%``
|
||||
Numerical day of the month, year and month.
|
||||
``%DATE%``
|
||||
Date in ``YYYY-mm-dd`` format
|
||||
``%TIME%``
|
||||
Time in ``HH:MM`` format
|
||||
``%FDATE%``
|
||||
Full date (date + time), in ``YYYY-mm-dd HH:MM`` format.
|
||||
``%FILE%``
|
||||
File name, without extension.
|
||||
``%FFILE%``
|
||||
File name, with extension.
|
||||
``%EXT%``
|
||||
File extension.
|
||||
``%MAIL%``
|
||||
Current user's e-mail address. May be overriden by defining ``g:email``.
|
||||
``%USER%``
|
||||
Current logged-in user name. May be overriden by defining ``g:username``.
|
||||
``%HOST%``
|
||||
Host name.
|
||||
``%GUARD%``
|
||||
A string with alphanumeric characters and underscores, suitable for use
|
||||
in proprocessor guards for C/C++/Objective-C header files.
|
||||
``%CLASS%``
|
||||
File name, without extension, and the first character of every word is
|
||||
capital
|
||||
``%MACROCLASS%``
|
||||
File name, without extension, and all characters are capitals.
|
||||
``%CAMELCLASS%``
|
||||
File name, without extension, the first character of every word is capital,
|
||||
and all underscores are removed.
|
||||
``%HERE%``
|
||||
Expands to nothing, but ensures that the cursor will be placed in its
|
||||
position after expanding the template.
|
||||
|
466
vim/bundle/vim-template/plugin/templates.vim
Normal file
466
vim/bundle/vim-template/plugin/templates.vim
Normal file
@ -0,0 +1,466 @@
|
||||
"
|
||||
" Template system for Vim
|
||||
"
|
||||
" Copyright (C) 2012 Adrian Perez de Castro <aperez@igalia.com>
|
||||
" Copyright (C) 2005 Adrian Perez de Castro <the.lightman@gmail.com>
|
||||
"
|
||||
" Distributed under terms of the MIT license.
|
||||
"
|
||||
|
||||
if exists("g:templates_plugin_loaded")
|
||||
finish
|
||||
endif
|
||||
let g:templates_plugin_loaded = 1
|
||||
|
||||
if !exists('g:templates_name_prefix')
|
||||
let g:templates_name_prefix = ".vim-template:"
|
||||
endif
|
||||
|
||||
if !exists('g:templates_global_name_prefix')
|
||||
let g:templates_global_name_prefix = "=template="
|
||||
endif
|
||||
|
||||
if !exists('g:templates_debug')
|
||||
let g:templates_debug = 0
|
||||
endif
|
||||
|
||||
if !exists('g:templates_tr_in')
|
||||
let g:templates_tr_in = [ '.', '*', '?' ]
|
||||
endif
|
||||
|
||||
if !exists('g:templates_tr_out')
|
||||
let g:templates_tr_out = [ '\.', '.*', '\?' ]
|
||||
endif
|
||||
|
||||
if !exists('g:templates_fuzzy_start')
|
||||
let g:templates_fuzzy_start = 1
|
||||
endif
|
||||
|
||||
if !exists('g:templates_directory')
|
||||
let g:templates_directory = []
|
||||
elseif type(g:templates_directory) == type('')
|
||||
" Convert string value to a list with one element.
|
||||
let s:tmp = g:templates_directory
|
||||
unlet g:templates_directory
|
||||
let g:templates_directory = [ s:tmp ]
|
||||
unlet s:tmp
|
||||
endif
|
||||
|
||||
if !exists('g:templates_no_builtin_templates')
|
||||
let g:templates_no_builtin_templates = 0
|
||||
endif
|
||||
|
||||
" Put template system autocommands in their own group. {{{1
|
||||
if !exists('g:templates_no_autocmd')
|
||||
let g:templates_no_autocmd = 0
|
||||
endif
|
||||
|
||||
if !g:templates_no_autocmd
|
||||
augroup Templating
|
||||
autocmd!
|
||||
autocmd BufNewFile * call <SID>TLoad()
|
||||
augroup END
|
||||
endif
|
||||
|
||||
function <SID>Debug(mesg)
|
||||
if g:templates_debug
|
||||
echom(a:mesg)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" normalize the path
|
||||
" replace the windows path sep \ with /
|
||||
function <SID>NormalizePath(path)
|
||||
return substitute(a:path, "\\", "/", "g")
|
||||
endfunction
|
||||
|
||||
" Template searching. {{{1
|
||||
" Returns a string containing the path of the parent directory of the given
|
||||
" path. Works like dirname(3). It also simplifies the given path.
|
||||
function <SID>DirName(path)
|
||||
let l:tmp = <SID>NormalizePath(a:path)
|
||||
return substitute(l:tmp, "[^/][^/]*/*$", "", "")
|
||||
endfunction
|
||||
|
||||
" Default templates directory
|
||||
let s:default_template_dir = <SID>DirName(<SID>DirName(expand("<sfile>"))) . "templates"
|
||||
|
||||
" Find the target template in windows
|
||||
"
|
||||
" In windows while we clone the symbol link from github
|
||||
" it will turn to normal file, so we use this function
|
||||
" to figure out the destination file
|
||||
function <SID>TFindLink(path, template)
|
||||
if !filereadable(a:path . a:template)
|
||||
return a:template
|
||||
endif
|
||||
|
||||
let l:content = readfile(a:path . a:template, "b")
|
||||
if len(l:content) != 1
|
||||
return a:template
|
||||
endif
|
||||
|
||||
if filereadable(a:path . l:content[0])
|
||||
return <SID>TFindLink(a:path, l:content[0])
|
||||
else
|
||||
return a:template
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Translate a template file name into a regular expression to test for matching
|
||||
" against a given filename. As of writing this behavior is something like this:
|
||||
" (with a g:templates_name_prefix set as 'template.')
|
||||
"
|
||||
" template.py -> ^.*py$
|
||||
"
|
||||
" template.test.py -> ^.*test.py$
|
||||
"
|
||||
function <SID>TemplateToRegex(template, prefix)
|
||||
let l:template_base_name = fnamemodify(a:template,":t")
|
||||
let l:template_glob = strpart(l:template_base_name, len(a:prefix))
|
||||
|
||||
" Translate the template's glob into a normal regular expression
|
||||
let l:in_escape_mode = 0
|
||||
let l:template_regex = ""
|
||||
for l:c in split(l:template_glob, '\zs')
|
||||
if l:in_escape_mode == 1
|
||||
if l:c == '\'
|
||||
let l:template_regex = l:template_regex . '\\'
|
||||
else
|
||||
let l:template_regex = l:template_regex . l:c
|
||||
endif
|
||||
|
||||
let l:in_escape_mode = 0
|
||||
else
|
||||
if l:c == '\'
|
||||
let l:in_escape_mode = 1
|
||||
else
|
||||
let l:tr_index = index(g:templates_tr_in, l:c)
|
||||
if l:tr_index != -1
|
||||
let l:template_regex = l:template_regex . g:templates_tr_out[l:tr_index]
|
||||
else
|
||||
let l:template_regex = l:template_regex . l:c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
if g:templates_fuzzy_start
|
||||
return l:template_regex . '$'
|
||||
else
|
||||
return '^' . l:template_regex . '$'
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" Given a template and filename, return a score on how well the template matches
|
||||
" the given filename. If the template does not match the file name at all,
|
||||
" return 0
|
||||
function <SID>TemplateBaseNameTest(template, prefix, filename)
|
||||
let l:tregex = <SID>TemplateToRegex(a:template, a:prefix)
|
||||
|
||||
" Ensure that we got a valid regex
|
||||
if l:tregex == ""
|
||||
return 0
|
||||
endif
|
||||
|
||||
" For now only use the base of the filename.. this may change later
|
||||
" *Note* we also have to be careful because a:filename may also be the passed
|
||||
" in text from TLoadCmd...
|
||||
let l:filename_chopped = fnamemodify(a:filename,":t")
|
||||
|
||||
" Check for a match
|
||||
let l:regex_result = match(l:filename_chopped,l:tregex)
|
||||
if l:regex_result != -1
|
||||
" For a match return a score based on the regex length
|
||||
return len(l:tregex)
|
||||
else
|
||||
" No match
|
||||
return 0
|
||||
endif
|
||||
|
||||
endfunction
|
||||
|
||||
" Returns the most specific / highest scored template file found in the given
|
||||
" path. Template files are found by using a glob operation on the current path
|
||||
" and the setting of g:templates_name_prefix. If no template is found in the
|
||||
" given directory, return an empty string
|
||||
function <SID>TDirectorySearch(path, template_prefix, file_name)
|
||||
let l:picked_template = ""
|
||||
let l:picked_template_score = 0
|
||||
|
||||
" All template files matching
|
||||
let l:templates = split(glob(a:path . a:template_prefix . "*"), "\n")
|
||||
for template in l:templates
|
||||
" Make sure the template is readable
|
||||
if filereadable(template)
|
||||
let l:current_score =
|
||||
\<SID>TemplateBaseNameTest(template, a:template_prefix, a:file_name)
|
||||
call <SID>Debug("template: " . template . " got scored: " . l:current_score)
|
||||
|
||||
" Pick that template only if it beats the currently picked template
|
||||
" (here we make the assumption that template name length ~= template
|
||||
" specifity / score)
|
||||
if l:current_score > l:picked_template_score
|
||||
let l:picked_template = template
|
||||
let l:picked_template_score = l:current_score
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
if l:picked_template != ""
|
||||
call <SID>Debug("Picked template: " . l:picked_template)
|
||||
else
|
||||
call <SID>Debug("No template found")
|
||||
endif
|
||||
|
||||
return l:picked_template
|
||||
endfunction
|
||||
|
||||
" Searches for a [template] in a given [path].
|
||||
"
|
||||
" If [upwards] is [1] the template is searched only in the given directory;
|
||||
" if it's zero it is searched all along the directory structure, going to
|
||||
" parent directory whenever a template is *not* found for a given [path]. If
|
||||
" it's greater than zero [upwards] is the maximum depth of directories that
|
||||
" will be traversed.
|
||||
"
|
||||
" If no template is found an empty string is returned.
|
||||
"
|
||||
function <SID>TSearch(path, template_prefix, file_name, upwards)
|
||||
" pick a template from the current path
|
||||
let l:picked_template = <SID>TDirectorySearch(a:path, a:template_prefix, a:file_name)
|
||||
|
||||
if l:picked_template != ""
|
||||
if !has("win32") || !has("win64")
|
||||
return l:picked_template
|
||||
else
|
||||
echoerr( "Not yet implemented" )
|
||||
" TODO
|
||||
" return a:path . <SID>TFindLink(a:path, a:template)
|
||||
endif
|
||||
else
|
||||
" File not found/not readable.
|
||||
if (a:upwards == 0) || (a:upwards > 1)
|
||||
" Check wether going upwards results in a different path...
|
||||
let l:pathUp = <SID>DirName(a:path)
|
||||
if l:pathUp != a:path
|
||||
" ...and traverse it.
|
||||
return <SID>TSearch(l:pathUp, a:template_prefix, a:file_name, a:upwards ? a:upwards-1 : 0)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
" Ooops, either we cannot go up in the path or [upwards] reached 1
|
||||
return ""
|
||||
endfunction
|
||||
|
||||
|
||||
" Tries to find valid templates using the global g:templates_name_prefix as a glob
|
||||
" matcher for template files. The search is done as follows:
|
||||
" 1. The [path] passed to the function, [upwards] times up.
|
||||
" 2. The g:templates_directory directory, if it exists.
|
||||
" 3. Built-in templates from s:default_template_dir.
|
||||
" Returns an empty string if no template is found.
|
||||
"
|
||||
function <SID>TFind(path, name, up)
|
||||
let l:tmpl = <SID>TSearch(a:path, g:templates_name_prefix, a:name, a:up)
|
||||
if l:tmpl != ''
|
||||
return l:tmpl
|
||||
endif
|
||||
|
||||
for l:directory in g:templates_directory
|
||||
let l:directory = <SID>NormalizePath(expand(l:directory) . '/')
|
||||
if isdirectory(l:directory)
|
||||
let l:tmpl = <SID>TSearch(l:directory, g:templates_global_name_prefix, a:name, 1)
|
||||
if l:tmpl != ''
|
||||
return l:tmpl
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
if g:templates_no_builtin_templates
|
||||
return ''
|
||||
endif
|
||||
|
||||
return <SID>TSearch(<SID>NormalizePath(expand(s:default_template_dir) . '/'), g:templates_global_name_prefix, a:name, 1)
|
||||
endfunction
|
||||
|
||||
|
||||
" Template variable expansion. {{{1
|
||||
|
||||
" Makes a single [variable] expansion, using [value] as replacement.
|
||||
"
|
||||
function <SID>TExpand(variable, value)
|
||||
silent! execute "%s/%" . a:variable . "%/" . a:value . "/g"
|
||||
endfunction
|
||||
|
||||
" Performs variable expansion in a template once it was loaded {{{2
|
||||
"
|
||||
function <SID>TExpandVars()
|
||||
" Date/time values
|
||||
let l:day = strftime("%d")
|
||||
let l:year = strftime("%Y")
|
||||
let l:month = strftime("%m")
|
||||
let l:time = strftime("%H:%M")
|
||||
let l:date = exists("g:dateformat") ? strftime(g:dateformat) :
|
||||
\ (l:year . "-" . l:month . "-" . l:day)
|
||||
let l:fdate = l:date . " " . l:time
|
||||
let l:filen = expand("%:t:r")
|
||||
let l:filex = expand("%:e")
|
||||
let l:filec = expand("%:t")
|
||||
let l:fdir = expand("%:p:h:t")
|
||||
let l:hostn = hostname()
|
||||
let l:user = exists("g:username") ? g:username :
|
||||
\ (exists("g:user") ? g:user : $USER)
|
||||
let l:email = exists("g:email") ? g:email : (l:user . "@" . l:hostn)
|
||||
let l:guard = toupper(substitute(l:filec, "[^a-zA-Z0-9]", "_", "g"))
|
||||
let l:class = substitute(l:filen, "\\([a-zA-Z]\\+\\)", "\\u\\1\\e", "g")
|
||||
let l:macroclass = toupper(l:class)
|
||||
let l:camelclass = substitute(l:class, "_", "", "g")
|
||||
|
||||
" Finally, perform expansions
|
||||
call <SID>TExpand("DAY", l:day)
|
||||
call <SID>TExpand("YEAR", l:year)
|
||||
call <SID>TExpand("DATE", l:date)
|
||||
call <SID>TExpand("TIME", l:time)
|
||||
call <SID>TExpand("USER", l:user)
|
||||
call <SID>TExpand("FDATE", l:fdate)
|
||||
call <SID>TExpand("MONTH", l:month)
|
||||
call <SID>TExpand("FILE", l:filen)
|
||||
call <SID>TExpand("FFILE", l:filec)
|
||||
call <SID>TExpand("FDIR", l:fdir)
|
||||
call <SID>TExpand("EXT", l:filex)
|
||||
call <SID>TExpand("MAIL", l:email)
|
||||
call <SID>TExpand("HOST", l:hostn)
|
||||
call <SID>TExpand("GUARD", l:guard)
|
||||
call <SID>TExpand("CLASS", l:class)
|
||||
call <SID>TExpand("MACROCLASS", l:macroclass)
|
||||
call <SID>TExpand("CAMELCLASS", l:camelclass)
|
||||
call <SID>TExpand("LICENSE", exists("g:license") ? g:license : "MIT")
|
||||
endfunction
|
||||
|
||||
" }}}2
|
||||
|
||||
" Puts the cursor either at the first line of the file or in the place of
|
||||
" the template where the %HERE% string is found, removing %HERE% from the
|
||||
" template.
|
||||
"
|
||||
function <SID>TPutCursor()
|
||||
0 " Go to first line before searching
|
||||
if search("%HERE%", "W")
|
||||
let l:column = col(".")
|
||||
let l:lineno = line(".")
|
||||
s/%HERE%//
|
||||
call cursor(l:lineno, l:column)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" File name utils
|
||||
"
|
||||
" Ensures that the given file name is safe to be opened and will not be shell
|
||||
" expanded
|
||||
function <SID>NeuterFileName(filename)
|
||||
let l:neutered = fnameescape(a:filename)
|
||||
call <SID>Debug("Neutered " . a:filename . " to " . l:neutered)
|
||||
return l:neutered
|
||||
endfunction
|
||||
|
||||
|
||||
" Template application. {{{1
|
||||
|
||||
" Loads a template for the current buffer, substitutes variables and puts
|
||||
" cursor at %HERE%. Used to implement the BufNewFile autocommand.
|
||||
"
|
||||
function <SID>TLoad()
|
||||
if !line2byte( line( '$' ) + 1 ) == -1
|
||||
return
|
||||
endif
|
||||
|
||||
let l:file_name = expand("%:p")
|
||||
let l:file_dir = <SID>DirName(l:file_name)
|
||||
let l:depth = exists("g:template_max_depth") ? g:template_max_depth : 0
|
||||
|
||||
let l:tFile = <SID>TFind(l:file_dir, l:file_name, l:depth)
|
||||
call <SID>TLoadTemplate(l:tFile)
|
||||
endfunction
|
||||
|
||||
|
||||
" Like the previous one, TLoad(), but intended to be called with an argument
|
||||
" that either is a filename (so the file is loaded as a template) or
|
||||
" a template suffix (and the template is searched as usual). Of course this
|
||||
" makes variable expansion and cursor positioning.
|
||||
"
|
||||
function <SID>TLoadCmd(template)
|
||||
if filereadable(a:template)
|
||||
let l:tFile = a:template
|
||||
else
|
||||
let l:depth = exists("g:template_max_depth") ? g:template_max_depth : 0
|
||||
let l:tName = g:templates_global_name_prefix . a:template
|
||||
let l:file_name = expand("%:p")
|
||||
let l:file_dir = <SID>DirName(l:file_name)
|
||||
|
||||
let l:tFile = <SID>TFind(l:file_dir, a:template, l:depth)
|
||||
endif
|
||||
call <SID>TLoadTemplate(l:tFile)
|
||||
endfunction
|
||||
|
||||
" Load the given file as a template
|
||||
function <SID>TLoadTemplate(template)
|
||||
if a:template != ""
|
||||
" Read template file and expand variables in it.
|
||||
let l:safeFileName = <SID>NeuterFileName(a:template)
|
||||
execute "keepalt 0r " . l:safeFileName
|
||||
call <SID>TExpandVars()
|
||||
" This leaves an extra blank line at the bottom, delete it
|
||||
execute line('$') . "d"
|
||||
call <SID>TPutCursor()
|
||||
setlocal nomodified
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Commands {{{1
|
||||
|
||||
" Just calls the above function, pass either a filename or a template
|
||||
" suffix, as explained before =)
|
||||
"
|
||||
fun ListTemplateSuffixes(A,P,L)
|
||||
let l:templates = split(globpath(s:default_template_dir, g:templates_global_name_prefix . a:A . "*"), "\n")
|
||||
let l:res = []
|
||||
for t in templates
|
||||
let l:suffix = substitute(t, ".*\\.", "", "")
|
||||
call add(l:res, l:suffix)
|
||||
endfor
|
||||
|
||||
return l:res
|
||||
endfun
|
||||
command -nargs=1 -complete=customlist,ListTemplateSuffixes Template call <SID>TLoadCmd("<args>")
|
||||
|
||||
" Syntax autocommands {{{1
|
||||
"
|
||||
" Enable the vim-template syntax for template files
|
||||
" Usually we'd put this in the ftdetect folder, but because
|
||||
" g:templates_name_prefix doesn't get defined early enough we have to add the
|
||||
" template detection from the plugin itself
|
||||
execute "au BufNewFile,BufRead " . g:templates_name_prefix . "* "
|
||||
\. "let b:vim_template_subtype = &filetype | "
|
||||
\. "set ft=vim-template"
|
||||
|
||||
if !g:templates_no_builtin_templates
|
||||
execute "au BufNewFile,BufRead "
|
||||
\. s:default_template_dir . "/" . g:templates_global_name_prefix . "* "
|
||||
\. "let b:vim_template_subtype = &filetype | "
|
||||
\. "set ft=vim-template"
|
||||
endif
|
||||
|
||||
for s:directory in g:templates_directory
|
||||
let s:directory = <SID>NormalizePath(expand(s:directory) . '/')
|
||||
if isdirectory(s:directory)
|
||||
execute "au BufNewFile,BufRead "
|
||||
\. s:directory . "/" . g:templates_global_name_prefix . "* "
|
||||
\. "let b:vim_template_subtype = &filetype | "
|
||||
\. "set ft=vim-template"
|
||||
endif
|
||||
unlet s:directory
|
||||
endfor
|
||||
|
||||
" vim: fdm=marker
|
19
vim/bundle/vim-template/syntax/vim-template.vim
Normal file
19
vim/bundle/vim-template/syntax/vim-template.vim
Normal file
@ -0,0 +1,19 @@
|
||||
" vim-template syntax file
|
||||
" Language: vim-template
|
||||
" Maintainer: Stephen Chandler Paul <thatslyude@gmail.com>
|
||||
" Last Change: 2014 April 21
|
||||
|
||||
if exists("b:current_syntax")
|
||||
finish
|
||||
endif
|
||||
|
||||
if b:vim_template_subtype != ""
|
||||
execute "runtime! syntax/" . b:vim_template_subtype . ".vim"
|
||||
unlet b:current_syntax
|
||||
endif
|
||||
|
||||
syn match vimtemplateVariable "%\%(DAY\|YEAR\|MONTH\|DATE\|TIME\|FILE\|FFILE\|EXT\|MAIL\|USER\|HOST\|GUARD\|CLASS\|MACROCLASS\|CAMELCLASS\|HERE\)%" containedin=ALL
|
||||
|
||||
let b:current_syntax = "vim-template"
|
||||
|
||||
hi def link vimtemplateVariable Constant
|
11
vim/bundle/vim-template/templates/=template=*.c
Normal file
11
vim/bundle/vim-template/templates/=template=*.c
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* %FFILE%
|
||||
* Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
*
|
||||
* Distributed under terms of the %LICENSE% license.
|
||||
*/
|
||||
|
||||
#include "%FILE%.h"
|
||||
|
||||
|
||||
%HERE%
|
1
vim/bundle/vim-template/templates/=template=*.c++
Symbolic link
1
vim/bundle/vim-template/templates/=template=*.c++
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*.c
|
1
vim/bundle/vim-template/templates/=template=*.cc
Symbolic link
1
vim/bundle/vim-template/templates/=template=*.cc
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*.c
|
13
vim/bundle/vim-template/templates/=template=*.cmake
Normal file
13
vim/bundle/vim-template/templates/=template=*.cmake
Normal file
@ -0,0 +1,13 @@
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
|
||||
# projectname is the same as the main-executable
|
||||
project(%HERE%%FDIR%)
|
||||
|
||||
add_definitions('-g')
|
||||
add_definitions('-Wall')
|
||||
#add_definitions('-std=c++11')
|
||||
|
||||
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cpp)
|
||||
|
||||
add_custom_target(${PROJECT_NAME}-symlink ALL ln --force -s ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME} ${CMAKE_SOURCE_DIR}/${PROJECT_NAME} DEPENDS ${PROJECT_NAME})
|
||||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_SOURCE_DIR}/${PROJECT_NAME})
|
1
vim/bundle/vim-template/templates/=template=*.cpp
Symbolic link
1
vim/bundle/vim-template/templates/=template=*.cpp
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*.c
|
12
vim/bundle/vim-template/templates/=template=*.css
Normal file
12
vim/bundle/vim-template/templates/=template=*.css
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* %FFILE%
|
||||
* Copyright (C) %YEAR% %USER%
|
||||
*
|
||||
* Distributed under terms of the %LICENSE% license.
|
||||
*/
|
||||
|
||||
body {
|
||||
%HERE%background: white;
|
||||
color: black;
|
||||
}
|
||||
|
1
vim/bundle/vim-template/templates/=template=*.cxx
Symbolic link
1
vim/bundle/vim-template/templates/=template=*.cxx
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*.c
|
8
vim/bundle/vim-template/templates/=template=*.f
Normal file
8
vim/bundle/vim-template/templates/=template=*.f
Normal file
@ -0,0 +1,8 @@
|
||||
!
|
||||
! %FFILE%
|
||||
! Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
!
|
||||
! Distributed under terms of the %LICENSE% license.
|
||||
!
|
||||
|
||||
%HERE%
|
8
vim/bundle/vim-template/templates/=template=*.f90
Normal file
8
vim/bundle/vim-template/templates/=template=*.f90
Normal file
@ -0,0 +1,8 @@
|
||||
!
|
||||
! %FFILE%
|
||||
! Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
!
|
||||
! Distributed under terms of the %LICENSE% license.
|
||||
!
|
||||
|
||||
%HERE%
|
13
vim/bundle/vim-template/templates/=template=*.h
Normal file
13
vim/bundle/vim-template/templates/=template=*.h
Normal file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* %FFILE%
|
||||
* Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
*
|
||||
* Distributed under terms of the %LICENSE% license.
|
||||
*/
|
||||
|
||||
#ifndef %GUARD%
|
||||
#define %GUARD%
|
||||
|
||||
%HERE%
|
||||
|
||||
#endif /* !%GUARD% */
|
12
vim/bundle/vim-template/templates/=template=*.hs
Normal file
12
vim/bundle/vim-template/templates/=template=*.hs
Normal file
@ -0,0 +1,12 @@
|
||||
#! /usr/bin/env runhugs +l
|
||||
--
|
||||
-- %FFILE%
|
||||
-- Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
--
|
||||
-- Distributed under terms of the %LICENSE% license.
|
||||
--
|
||||
|
||||
module %FILE% where
|
||||
|
||||
|
||||
%HERE%
|
10
vim/bundle/vim-template/templates/=template=*.html
Normal file
10
vim/bundle/vim-template/templates/=template=*.html
Normal file
@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>%FILE%</title>
|
||||
</head>
|
||||
<body>
|
||||
%HERE%
|
||||
</body>
|
||||
</html>
|
16
vim/bundle/vim-template/templates/=template=*.humans.txt
Normal file
16
vim/bundle/vim-template/templates/=template=*.humans.txt
Normal file
@ -0,0 +1,16 @@
|
||||
/* TEAM */
|
||||
Your title: %USER%
|
||||
Site: %MAIL%, link to a contact form, etc.
|
||||
Twitter: your Twitter username.
|
||||
Location: City, Country.
|
||||
|
||||
%HERE%
|
||||
|
||||
/* THANKS */
|
||||
Name: name or url
|
||||
|
||||
/* SITE */
|
||||
Last update: YYYY/MM/DD
|
||||
Standards: HTML5, CSS3,..
|
||||
Components: Modernizr, jQuery, etc.
|
||||
Software: Software used for the development
|
14
vim/bundle/vim-template/templates/=template=*.java
Normal file
14
vim/bundle/vim-template/templates/=template=*.java
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* %FFILE%
|
||||
* Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
*
|
||||
* Distributed under terms of the %LICENSE% license.
|
||||
*/
|
||||
|
||||
public class %FILE%
|
||||
{
|
||||
public %FILE%() {
|
||||
%HERE%
|
||||
}
|
||||
}
|
||||
|
8
vim/bundle/vim-template/templates/=template=*.jl
Normal file
8
vim/bundle/vim-template/templates/=template=*.jl
Normal file
@ -0,0 +1,8 @@
|
||||
#=
|
||||
%FILE%
|
||||
Copyright © %YEAR% %USER% <%MAIL%>
|
||||
|
||||
Distributed under terms of the %LICENSE% license.
|
||||
=#
|
||||
|
||||
%HERE%
|
7
vim/bundle/vim-template/templates/=template=*.js
Normal file
7
vim/bundle/vim-template/templates/=template=*.js
Normal file
@ -0,0 +1,7 @@
|
||||
/*
|
||||
* %FFILE%
|
||||
* Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
*
|
||||
* Distributed under terms of the %LICENSE% license.
|
||||
*/
|
||||
%HERE%
|
4
vim/bundle/vim-template/templates/=template=*.lhs
Normal file
4
vim/bundle/vim-template/templates/=template=*.lhs
Normal file
@ -0,0 +1,4 @@
|
||||
%FILE% by %USER%
|
||||
%FDATE%
|
||||
|
||||
%HERE%
|
9
vim/bundle/vim-template/templates/=template=*.lua
Normal file
9
vim/bundle/vim-template/templates/=template=*.lua
Normal file
@ -0,0 +1,9 @@
|
||||
#! /usr/bin/env lua
|
||||
--
|
||||
-- %FFILE%
|
||||
-- Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
--
|
||||
-- Distributed under terms of the %LICENSE% license.
|
||||
--
|
||||
|
||||
%HERE%
|
1
vim/bundle/vim-template/templates/=template=*.m
Symbolic link
1
vim/bundle/vim-template/templates/=template=*.m
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*.c
|
1
vim/bundle/vim-template/templates/=template=*.mk
Symbolic link
1
vim/bundle/vim-template/templates/=template=*.mk
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*Makefile
|
9
vim/bundle/vim-template/templates/=template=*.ml
Normal file
9
vim/bundle/vim-template/templates/=template=*.ml
Normal file
@ -0,0 +1,9 @@
|
||||
(*
|
||||
* %FFILE%
|
||||
* Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
*
|
||||
* Distributed under terms of the %LICENSE% license.
|
||||
*)
|
||||
|
||||
|
||||
let %HERE%
|
1
vim/bundle/vim-template/templates/=template=*.mm
Symbolic link
1
vim/bundle/vim-template/templates/=template=*.mm
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*.m
|
13
vim/bundle/vim-template/templates/=template=*.php
Normal file
13
vim/bundle/vim-template/templates/=template=*.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* Short description for %FFILE%
|
||||
*
|
||||
* @package %FILE%
|
||||
* @author %USER% <%MAIL%>
|
||||
* @version 0.1
|
||||
* @copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
* @license %LICENSE%
|
||||
*/
|
||||
|
||||
%HERE%
|
||||
?>
|
16
vim/bundle/vim-template/templates/=template=*.pl
Normal file
16
vim/bundle/vim-template/templates/=template=*.pl
Normal file
@ -0,0 +1,16 @@
|
||||
#! /usr/bin/env perl
|
||||
#
|
||||
# Short description for %FFILE%
|
||||
#
|
||||
# Author %USER% <%MAIL%>
|
||||
# Version 0.1
|
||||
# Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
# Modified On %FDATE%
|
||||
# Created %FDATE%
|
||||
#
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
|
||||
|
||||
%HERE%
|
38
vim/bundle/vim-template/templates/=template=*.pm
Normal file
38
vim/bundle/vim-template/templates/=template=*.pm
Normal file
@ -0,0 +1,38 @@
|
||||
package %FILE%;
|
||||
#
|
||||
# Short description for %FFILE%
|
||||
#
|
||||
# Author %USER% <%MAIL%>
|
||||
# Version 0.1
|
||||
# Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
# Modified On %FDATE%
|
||||
# Created %FDATE%
|
||||
#
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
our @ISA = qw(Exporter);
|
||||
our %EXPORT_TAGS = ( 'all' => [ qw() ] );
|
||||
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
||||
our @EXPORT = qw();
|
||||
our $VERSION = '1.00';
|
||||
require Exporter;
|
||||
use AutoLoader qw(AUTOLOAD);
|
||||
|
||||
|
||||
sub new
|
||||
{
|
||||
my $class = shift;
|
||||
my $arg = shift;
|
||||
my $self = {};
|
||||
|
||||
%HERE%
|
||||
|
||||
bless($self, $class);
|
||||
return $self;
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
# __END__
|
||||
# # Below is stub documentation for your module. You'd better edit it!
|
26
vim/bundle/vim-template/templates/=template=*.pro
Normal file
26
vim/bundle/vim-template/templates/=template=*.pro
Normal file
@ -0,0 +1,26 @@
|
||||
PRO %FILE%
|
||||
;+
|
||||
; Name:
|
||||
; %FILE%
|
||||
; Purpose:
|
||||
;
|
||||
; Calling sequence:
|
||||
; %FILE%
|
||||
; Input:
|
||||
;
|
||||
; Output:
|
||||
;
|
||||
; Keywords:
|
||||
;
|
||||
; History:
|
||||
;
|
||||
; Author:
|
||||
; Copyright © %YEAR% %USER% <%MAIL%>
|
||||
; Distributed under terms of the %LICENSE% license.
|
||||
;-
|
||||
|
||||
COMPILE_OPT IDL2 ;Set compile options
|
||||
|
||||
%HERE%
|
||||
|
||||
END
|
14
vim/bundle/vim-template/templates/=template=*.py
Normal file
14
vim/bundle/vim-template/templates/=template=*.py
Normal file
@ -0,0 +1,14 @@
|
||||
#! /usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim:fenc=utf-8
|
||||
#
|
||||
# Copyright © %YEAR% %USER% <%MAIL%>
|
||||
#
|
||||
# Distributed under terms of the %LICENSE% license.
|
||||
#
|
||||
# %CLASS%
|
||||
#
|
||||
|
||||
"""
|
||||
%HERE%
|
||||
"""
|
10
vim/bundle/vim-template/templates/=template=*.rb
Normal file
10
vim/bundle/vim-template/templates/=template=*.rb
Normal file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env ruby
|
||||
#
|
||||
# %FFILE%
|
||||
# Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
#
|
||||
# Distributed under terms of the %LICENSE% license.
|
||||
#
|
||||
|
||||
|
||||
%HERE%
|
6
vim/bundle/vim-template/templates/=template=*.robots.txt
Normal file
6
vim/bundle/vim-template/templates/=template=*.robots.txt
Normal file
@ -0,0 +1,6 @@
|
||||
#
|
||||
# The Web Robots Pages (http://www.robotstxt.org/)
|
||||
#
|
||||
|
||||
User-agent: *
|
||||
Disallow:
|
10
vim/bundle/vim-template/templates/=template=*.sh
Normal file
10
vim/bundle/vim-template/templates/=template=*.sh
Normal file
@ -0,0 +1,10 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# %FFILE%
|
||||
# Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
#
|
||||
# Distributed under terms of the %LICENSE% license.
|
||||
#
|
||||
|
||||
|
||||
%HERE%
|
11
vim/bundle/vim-template/templates/=template=*.sql
Normal file
11
vim/bundle/vim-template/templates/=template=*.sql
Normal file
@ -0,0 +1,11 @@
|
||||
/*
|
||||
* %FFILE%
|
||||
* Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
*
|
||||
* Distributed under terms of the %LICENSE% license.
|
||||
*/
|
||||
|
||||
select %HERE%
|
||||
|
||||
|
||||
-- vim:et
|
17
vim/bundle/vim-template/templates/=template=*.tex
Normal file
17
vim/bundle/vim-template/templates/=template=*.tex
Normal file
@ -0,0 +1,17 @@
|
||||
% vim:ft=tex:
|
||||
%
|
||||
\documentclass[12pt]{article}
|
||||
|
||||
\title{
|
||||
%FILE%
|
||||
}
|
||||
\author{
|
||||
%USER% --- \texttt{%MAIL%}
|
||||
}
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
|
||||
%HERE%
|
||||
|
||||
\end{document}
|
7
vim/bundle/vim-template/templates/=template=*.txt
Normal file
7
vim/bundle/vim-template/templates/=template=*.txt
Normal file
@ -0,0 +1,7 @@
|
||||
%FFILE%
|
||||
|
||||
:Author: %USER%
|
||||
:Email: %MAIL%
|
||||
:Date: %FDATE%
|
||||
|
||||
%HERE%
|
8
vim/bundle/vim-template/templates/=template=*.xml
Normal file
8
vim/bundle/vim-template/templates/=template=*.xml
Normal file
@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<%FILE%>
|
||||
|
||||
%HERE%
|
||||
|
||||
</%FILE%>
|
||||
<!-- vim:fenc=utf-8
|
||||
-->
|
12
vim/bundle/vim-template/templates/=template=*.xsl
Normal file
12
vim/bundle/vim-template/templates/=template=*.xsl
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
%FFILE%
|
||||
Copyright (C) %YEAR% %USER% <%MAIL%>
|
||||
|
||||
Distributed under terms of the %LICENSE% license.
|
||||
-->
|
||||
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
|
||||
%HERE%
|
||||
|
||||
</xsl:stylesheet>
|
8
vim/bundle/vim-template/templates/=template=*.zcml
Normal file
8
vim/bundle/vim-template/templates/=template=*.zcml
Normal file
@ -0,0 +1,8 @@
|
||||
<configure
|
||||
xmlns="http://namespaces.zope.org/zope"
|
||||
xmlns:browser="http://namespaces.zope.org/browser"
|
||||
xmlns:i18n="http://namespaces.zope.org/i18n">
|
||||
|
||||
%HERE%
|
||||
|
||||
</configure>
|
1
vim/bundle/vim-template/templates/=template=*GNUmakefile
Symbolic link
1
vim/bundle/vim-template/templates/=template=*GNUmakefile
Symbolic link
@ -0,0 +1 @@
|
||||
=template=*Makefile
|
11
vim/bundle/vim-template/templates/=template=*Makefile
Normal file
11
vim/bundle/vim-template/templates/=template=*Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
#
|
||||
# %FFILE%
|
||||
# %USER%, %FDATE%
|
||||
#
|
||||
|
||||
all:
|
||||
%HERE%@echo "%FFILE% needs your attention"
|
||||
|
||||
|
||||
# vim:ft=make
|
||||
#
|
Reference in New Issue
Block a user