global !p
import subprocess, vim
def _parse_comments(s):
""" Parses vim's comments option to extract comment format """
i = iter(s.split(","))
rv = []
try:
while True:
# get the flags and text of a comment part
flags, text = next(i).split(':', 1)
if len(flags) == 0:
rv.append((text, text, text, ""))
# parse 3-part comment, but ignore those with O flag
elif 's' in flags and 'O' not in flags:
ctriple = []
indent = ""
if flags[-1] in string.digits:
indent = " " * int(flags[-1])
ctriple.append(text)
flags,text = next(i).split(':', 1)
assert(flags[0] == 'm')
ctriple.append(text)
flags,text = next(i).split(':', 1)
assert(flags[0] == 'e')
ctriple.append(text)
ctriple.append(indent)
rv.append(ctriple)
elif 'b' in flags and 'f' not in flags:
if len(text) == 1:
rv.insert(0, (text,text,text, ""))
except StopIteration:
return rv
def _get_comment_format():
""" Returns a 4-element tuple representing the comment format for
the current file. """
return _parse_comments(vim.eval("&comments"))[0]
b, m, e, i = _get_comment_format()
def _git_user_name():
try:
snip.rv = subprocess.check_output(["git", "config", "user.name"]).strip()
except CalledProcessError:
snip.rv = "John Doe"
def _git_user_email():
try:
snip.rv = subprocess.check_output(["git", "config", "user.email"]).strip()
except CalledProcessError:
snip.rv = "jdoe@example.com"
endglobal
snippet GPL2 "GPL2 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:One line to give the program's name and a brief description.}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is free software; you can redistribute it and/or modify
`!p snip.rv = i + m` it under the terms of the GNU General Public License as published by
`!p snip.rv = i + m` the Free Software Foundation; either version 2 of the License, or
`!p snip.rv = i + m` (at your option) any later version.
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is distributed in the hope that it will be useful,
`!p snip.rv = i + m` but WITHOUT ANY WARRANTY; without even the implied warranty of
`!p snip.rv = i + m` MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
`!p snip.rv = i + m` GNU General Public License for more details.
`!p snip.rv = i + m`
`!p snip.rv = i + m` You should have received a copy of the GNU General Public License
`!p snip.rv = i + m` along with this program; if not, see .
`!p snip.rv = i + e`
${0}
endsnippet
snippet LGPL2 "LGPL2 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:One line to give the program's name and a brief description.}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` This library is free software; you can redistribute it and/or modify
`!p snip.rv = i + m` it under the terms of the GNU Lesser General Public License as published
`!p snip.rv = i + m` by the Free Software Foundation; either version 2.1 of the License, or
`!p snip.rv = i + m` (at your option) any later version.
`!p snip.rv = i + m`
`!p snip.rv = i + m` This library is distributed in the hope that it will be useful,
`!p snip.rv = i + m` but WITHOUT ANY WARRANTY; without even the implied warranty of
`!p snip.rv = i + m` MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
`!p snip.rv = i + m` GNU Lesser General Public License for more details.
`!p snip.rv = i + m`
`!p snip.rv = i + m` You should have received a copy of the GNU Lesser General Public License
`!p snip.rv = i + m` along with this library; if not, see .
`!p snip.rv = i + e`
${0}
endsnippet
snippet GPL3 "GPL3 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description.}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is free software: you can redistribute it and/or modify
`!p snip.rv = i + m` it under the terms of the GNU General Public License as published by
`!p snip.rv = i + m` the Free Software Foundation, either version 3 of the License, or
`!p snip.rv = i + m` (at your option) any later version.
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is distributed in the hope that it will be useful,
`!p snip.rv = i + m` but WITHOUT ANY WARRANTY; without even the implied warranty of
`!p snip.rv = i + m` MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
`!p snip.rv = i + m` GNU General Public License for more details.
`!p snip.rv = i + m`
`!p snip.rv = i + m` You should have received a copy of the GNU General Public License
`!p snip.rv = i + m` along with this program. If not, see .
`!p snip.rv = i + e`
${0}
endsnippet
snippet LGPL3 "LGPL3 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:One line to give the program's name and a brief description.}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` This library is free software; you can redistribute it and/or modify
`!p snip.rv = i + m` it under the terms of the GNU Lesser General Public License as published
`!p snip.rv = i + m` by the Free Software Foundation; either version 3 of the License, or
`!p snip.rv = i + m` (at your option) any later version.
`!p snip.rv = i + m`
`!p snip.rv = i + m` This library is distributed in the hope that it will be useful,
`!p snip.rv = i + m` but WITHOUT ANY WARRANTY; without even the implied warranty of
`!p snip.rv = i + m` MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
`!p snip.rv = i + m` GNU Lesser General Public License for more details.
`!p snip.rv = i + m`
`!p snip.rv = i + m` You should have received a copy of the GNU Lesser General Public License
`!p snip.rv = i + m` along with this library; if not, see .
`!p snip.rv = i + e`
${0}
endsnippet
snippet AGPL3 "AGPL3 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description.}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is free software: you can redistribute it and/or modify
`!p snip.rv = i + m` it under the terms of the GNU Affero General Public License as
`!p snip.rv = i + m` published by the Free Software Foundation, either version 3 of the
`!p snip.rv = i + m` License, or (at your option) any later version.
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is distributed in the hope that it will be useful,
`!p snip.rv = i + m` but WITHOUT ANY WARRANTY; without even the implied warranty of
`!p snip.rv = i + m` MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
`!p snip.rv = i + m` GNU Affero General Public License for more details.
`!p snip.rv = i + m`
`!p snip.rv = i + m` You should have received a copy of the GNU Affero General Public License
`!p snip.rv = i + m` along with this program. If not, see .
`!p snip.rv = i + e`
${0}
endsnippet
snippet GMGPL "GMGPL linking exception License" b
`!p snip.rv = b`
`!p snip.rv = i + m` As a special exception, if other files instantiate generics from
`!p snip.rv = i + m` this unit, or you link this unit with other files to produce an
`!p snip.rv = i + m` executable, this unit does not by itself cause the resulting
`!p snip.rv = i + m` executable to be covered by the GNU General Public License.
`!p snip.rv = i + m` This exception does not however invalidate any other reasons why the
`!p snip.rv = i + m` executable file might be covered by the GNU Public License.
`!p snip.rv = i + e`
${0}
endsnippet
snippet BSD2 "BSD2 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m` All rights reserved.
`!p snip.rv = i + m`
`!p snip.rv = i + m` Redistribution and use in source and binary forms, with or without
`!p snip.rv = i + m` modification, are permitted provided that the following conditions are met:
`!p snip.rv = i + m` 1. Redistributions of source code must retain the above copyright
`!p snip.rv = i + m` notice, this list of conditions and the following disclaimer.
`!p snip.rv = i + m` 2. Redistributions in binary form must reproduce the above copyright
`!p snip.rv = i + m` notice, this list of conditions and the following disclaimer in the
`!p snip.rv = i + m` documentation and/or other materials provided with the distribution.
`!p snip.rv = i + m`
`!p snip.rv = i + m` THIS SOFTWARE IS PROVIDED BY $2 ''AS IS'' AND ANY
`!p snip.rv = i + m` EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
`!p snip.rv = i + m` WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
`!p snip.rv = i + m` DISCLAIMED. IN NO EVENT SHALL $2 BE LIABLE FOR ANY
`!p snip.rv = i + m` DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
`!p snip.rv = i + m` (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
`!p snip.rv = i + m` LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
`!p snip.rv = i + m` ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
`!p snip.rv = i + m` (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
`!p snip.rv = i + m` SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
`!p snip.rv = i + m`
`!p snip.rv = i + m`
`!p snip.rv = i + m` The views and conclusions contained in the software and documentation
`!p snip.rv = i + m` are those of the authors and should not be interpreted as representing
`!p snip.rv = i + m` official policies, either expressedor implied, of $2.
`!p snip.rv = i + e`
${0}
endsnippet
snippet BSD3 "BSD3 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m` All rights reserved.
`!p snip.rv = i + m`
`!p snip.rv = i + m` Redistribution and use in source and binary forms, with or without
`!p snip.rv = i + m` modification, are permitted provided that the following conditions are met:
`!p snip.rv = i + m` 1. Redistributions of source code must retain the above copyright
`!p snip.rv = i + m` notice, this list of conditions and the following disclaimer.
`!p snip.rv = i + m` 2. Redistributions in binary form must reproduce the above copyright
`!p snip.rv = i + m` notice, this list of conditions and the following disclaimer in the
`!p snip.rv = i + m` documentation and/or other materials provided with the distribution.
`!p snip.rv = i + m` 3. Neither the name of the ${4:organization} nor the
`!p snip.rv = i + m` names of its contributors may be used to endorse or promote products
`!p snip.rv = i + m` derived from this software without specific prior written permission.
`!p snip.rv = i + m`
`!p snip.rv = i + m` THIS SOFTWARE IS PROVIDED BY $2 ''AS IS'' AND ANY
`!p snip.rv = i + m` EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
`!p snip.rv = i + m` WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
`!p snip.rv = i + m` DISCLAIMED. IN NO EVENT SHALL $2 BE LIABLE FOR ANY
`!p snip.rv = i + m` DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
`!p snip.rv = i + m` (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
`!p snip.rv = i + m` LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
`!p snip.rv = i + m` ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
`!p snip.rv = i + m` (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
`!p snip.rv = i + m` SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
`!p snip.rv = i + e`
${0}
endsnippet
snippet BSD4 "BSD4 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m` All rights reserved.
`!p snip.rv = i + m`
`!p snip.rv = i + m` Redistribution and use in source and binary forms, with or without
`!p snip.rv = i + m` modification, are permitted provided that the following conditions are met:
`!p snip.rv = i + m` 1. Redistributions of source code must retain the above copyright
`!p snip.rv = i + m` notice, this list of conditions and the following disclaimer.
`!p snip.rv = i + m` 2. Redistributions in binary form must reproduce the above copyright
`!p snip.rv = i + m` notice, this list of conditions and the following disclaimer in the
`!p snip.rv = i + m` documentation and/or other materials provided with the distribution.
`!p snip.rv = i + m` 3. All advertising materials mentioning features or use of this software
`!p snip.rv = i + m` must display the following acknowledgement:
`!p snip.rv = i + m` This product includes software developed by the ${4:organization}.
`!p snip.rv = i + m` 4. Neither the name of the $4 nor the
`!p snip.rv = i + m` names of its contributors may be used to endorse or promote products
`!p snip.rv = i + m` derived from this software without specific prior written permission.
`!p snip.rv = i + m`
`!p snip.rv = i + m` THIS SOFTWARE IS PROVIDED BY $2 ''AS IS'' AND ANY
`!p snip.rv = i + m` EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
`!p snip.rv = i + m` WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
`!p snip.rv = i + m` DISCLAIMED. IN NO EVENT SHALL $2 BE LIABLE FOR ANY
`!p snip.rv = i + m` DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
`!p snip.rv = i + m` (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
`!p snip.rv = i + m` LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
`!p snip.rv = i + m` ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
`!p snip.rv = i + m` (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
`!p snip.rv = i + m` SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
`!p snip.rv = i + e`
${0}
endsnippet
snippet MIT "MIT License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` Permission is hereby granted, free of charge, to any person obtaining
`!p snip.rv = i + m` a copy of this software and associated documentation files (the "Software"),
`!p snip.rv = i + m` to deal in the Software without restriction, including without limitation
`!p snip.rv = i + m` the rights to use, copy, modify, merge, publish, distribute, sublicense,
`!p snip.rv = i + m` and/or sell copies of the Software, and to permit persons to whom the
`!p snip.rv = i + m` Software is furnished to do so, subject to the following conditions:
`!p snip.rv = i + m`
`!p snip.rv = i + m` The above copyright notice and this permission notice shall be included
`!p snip.rv = i + m` in all copies or substantial portions of the Software.
`!p snip.rv = i + m`
`!p snip.rv = i + m` THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
`!p snip.rv = i + m` EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
`!p snip.rv = i + m` OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
`!p snip.rv = i + m` IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
`!p snip.rv = i + m` DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
`!p snip.rv = i + m` TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
`!p snip.rv = i + m` OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
`!p snip.rv = i + e`
${0}
endsnippet
snippet APACHE "APACHE License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` Licensed under the Apache License, Version 2.0 (the "License");
`!p snip.rv = i + m` you may not use this file except in compliance with the License.
`!p snip.rv = i + m` You may obtain a copy of the License at
`!p snip.rv = i + m`
`!p snip.rv = i + m` http://www.apache.org/licenses/LICENSE-2.0
`!p snip.rv = i + m`
`!p snip.rv = i + m` Unless required by applicable law or agreed to in writing, software
`!p snip.rv = i + m` distributed under the License is distributed on an "AS IS" BASIS,
`!p snip.rv = i + m` WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
`!p snip.rv = i + m` See the License for the specific language governing permissions and
`!p snip.rv = i + m` limitations under the License.
`!p snip.rv = i + e`
${0}
endsnippet
snippet BEERWARE "BEERWARE License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:one line to give the program's name and a brief description}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` Licensed under the "THE BEER-WARE LICENSE" (Revision 42):
`!p snip.rv = i + m` $2 wrote this file. As long as you retain this notice you
`!p snip.rv = i + m` can do whatever you want with this stuff. If we meet some day, and you think
`!p snip.rv = i + m` this stuff is worth it, you can buy me a beer or coffee in return
`!p snip.rv = i + e`
${0}
endsnippet
snippet WTFPL "WTFPL License" b
`!p snip.rv = b`
`!p snip.rv = i + m` DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
`!p snip.rv = i + m` Version 2, December 2004
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v strftime("%Y")` ${1:`!p _git_user_name()`} <${2:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` Everyone is permitted to copy and distribute verbatim or modified
`!p snip.rv = i + m` copies of this license document, and changing it is allowed as long
`!p snip.rv = i + m` as the name is changed.
`!p snip.rv = i + m`
`!p snip.rv = i + m` DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
`!p snip.rv = i + m` TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
`!p snip.rv = i + m`
`!p snip.rv = i + m` 0. You just DO WHAT THE FUCK YOU WANT TO.
`!p snip.rv = i + m`
`!p snip.rv = i + e`
${0}
endsnippet
snippet MPL2 "MPL2 License" b
`!p snip.rv = b`
`!p snip.rv = i + m` This Source Code Form is subject to the terms of the Mozilla Public
`!p snip.rv = i + m` License, v. 2.0. If a copy of the MPL was not distributed with this
`!p snip.rv = i + m` file, You can obtain one at http://mozilla.org/MPL/2.0/.
`!p snip.rv = i + e`
${0}
endsnippet
snippet AGPL "AGPL License" b
`!p snip.rv = b`
`!p snip.rv = i + m` ${1:One line to give the program's name and a brief description.}
`!p snip.rv = i + m`
`!p snip.rv = i + m` Copyright `!v &enc[:2] == "utf" ? "©" : "(c)"` `!v strftime("%Y")` ${2:`!p _git_user_name()`} <${3:`!p _git_user_email()`}>
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is free software: you can redistribute it and/or modify
`!p snip.rv = i + m` it under the terms of the GNU Affero General Public License as
`!p snip.rv = i + m` published by the Free Software Foundation, either version 3 of the
`!p snip.rv = i + m` License, or (at your option) any later version.
`!p snip.rv = i + m`
`!p snip.rv = i + m` This program is distributed in the hope that it will be useful,
`!p snip.rv = i + m` but WITHOUT ANY WARRANTY; without even the implied warranty of
`!p snip.rv = i + m` MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
`!p snip.rv = i + m` GNU Affero General Public License for more details.
`!p snip.rv = i + m`
`!p snip.rv = i + m` You should have received a copy of the GNU Affero General Public License
`!p snip.rv = i + m` along with this program. If not, see .
`!p snip.rv = i + e`
endsnippet