replace Filename by vim_snippets#Filename and document it

It doesn't make sense that all snippet engines have to
keep this function somewhere
This commit is contained in:
Marc Weber 2013-07-08 03:41:11 +02:00
parent 1c74a955b0
commit 80697bea6f
17 changed files with 97 additions and 68 deletions

View File

@ -576,7 +576,7 @@ snippet module "New module (module)" b
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
module ${2}.`!v Filename('$1', 'name')`;
module ${2}.`!v vim_snippets#Filename('$1', 'name')`;
${3}

27
autoload/vim_snippets.vim Normal file
View File

@ -0,0 +1,27 @@
" this is well known Filename found in snipmate (and the other engines), but
" rewritten and documented :)
"
" optional arg1: string in which to replace '$1' by filename with extension
" and path dropped. Defaults to $1
" optional arg2: return this value if buffer has no filename
" But why not use the template in this case, too?
" Doesn't make sense to me
fun! vim_snippets#Filename(...)
let template = get(a:000, 0, "$1")
let arg2 = get(a:000, 1, "")
let basename = expand('%:t:r')
if basename == ''
return arg2
else
return substitute(template, '$1', basename, 'g')
endif
endf
" original code:
" fun! Filename(...)
" let filename = expand('%:t:r')
" if filename == '' | return a:0 == 2 ? a:2 : '' | endif
" return !a:0 || a:1 == '' ? filename : substitute(a:1, '$1', filename, 'g')
" endf

View File

@ -20,7 +20,7 @@ snippet inc
#include <${1:stdio}.h>${2}
# #include "..."
snippet Inc
#include "${1:`Filename("$1.h")`}"${2}
#include "${1:`vim_snippets#Filename("$1.h")`}"${2}
# ifndef...define...endif
snippet ndef
#ifndef $1
@ -41,7 +41,7 @@ snippet #if
#endif
# header include guard
snippet once
#ifndef ${1:`toupper(Filename('$1_H', 'UNTITLED_H'))`}
#ifndef ${1:`toupper(vim_snippets#Filename('$1_H', 'UNTITLED_H'))`}
#define $1
@ -132,14 +132,14 @@ snippet td
typedef ${1:int} ${2:MyCustomType};${3}
# struct
snippet st
struct ${1:`Filename('$1_t', 'name')`} {
struct ${1:`vim_snippets#Filename('$1_t', 'name')`} {
${2:/* data */}
}${3: /* optional variable list */};${4}
# typedef struct
snippet tds
typedef struct ${2:_$1 }{
${3:/* data */}
} ${1:`Filename('$1_t', 'name')`};${4}
} ${1:`vim_snippets#Filename('$1_t', 'name')`};${4}
# typedef enum
snippet tde
typedef enum {

View File

@ -35,19 +35,19 @@ snippet bfun
${2:# body...}
# Class
snippet cla class ..
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
${2}
snippet cla class .. constructor: ..
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
constructor: (${2:args}) ->
${3}
${4}
snippet cla class .. extends ..
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} extends ${2:ParentClass}
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} extends ${2:ParentClass}
${3}
snippet cla class .. extends .. constructor: ..
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} extends ${2:ParentClass}
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} extends ${2:ParentClass}
constructor: (${3:args}) ->
${4}

View File

@ -68,7 +68,7 @@ snippet mu
## Class
# class
snippet cl
class ${1:`Filename('$1', 'name')`}
class ${1:`vim_snippets#Filename('$1', 'name')`}
{
public:
$1(${2});
@ -79,12 +79,12 @@ snippet cl
};
# member function implementation
snippet mfun
${4:void} ${1:`Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) {
${4:void} ${1:`vim_snippets#Filename('$1', 'ClassName')`}::${2:memberFunction}(${3}) {
${5}
}
# namespace
snippet ns
namespace ${1:`Filename('', 'my')`} {
namespace ${1:`vim_snippets#Filename('', 'my')`} {
${2}
} /* namespace $1 */
##

View File

@ -116,49 +116,49 @@ snippet each
}
# interfaces
snippet interface
public interface ${1:`Filename()`} {
public interface ${1:`vim_snippets#Filename()`} {
${2}
}
snippet if+
public interface ${1:`Filename()`} {
public interface ${1:`vim_snippets#Filename()`} {
${2}
}
# class bodies
snippet class
public class ${1:`Filename()`} {
public class ${1:`vim_snippets#Filename()`} {
${2}
}
snippet cls
${2:public} class ${1:`Filename()`} {
${2:public} class ${1:`vim_snippets#Filename()`} {
${3}
}
snippet cls+
public class ${1:`Filename()`} {
public class ${1:`vim_snippets#Filename()`} {
${2}
}
snippet cls+^
public static class ${1:`Filename()`} {
public static class ${1:`vim_snippets#Filename()`} {
${2}
}
snippet cls&
internal class ${1:`Filename()`} {
internal class ${1:`vim_snippets#Filename()`} {
${2}
}
snippet cls&^
internal static class ${1:`Filename()`} {
internal static class ${1:`vim_snippets#Filename()`} {
${2}
}
snippet cls|
protected class ${1:`Filename()`} {
protected class ${1:`vim_snippets#Filename()`} {
${2}
}
snippet cls|%
protected abstract class ${1:`Filename()`} {
protected abstract class ${1:`vim_snippets#Filename()`} {
${2}
}
# constructor
snippet ctor
public ${1:`Filename()`}() {
public ${1:`vim_snippets#Filename()`}() {
${2}
}
# properties - auto properties by default.
@ -342,7 +342,7 @@ snippet ms-
}
# structure
snippet struct
public struct ${1:`Filename()`} {
public struct ${1:`vim_snippets#Filename()`} {
${2}
}
# enumeration

View File

@ -22,9 +22,9 @@ snippet br
snippet th
throw ${1}
snippet cl
class ${1:`Filename("", "untitled")`} ${2}
class ${1:`vim_snippets#Filename("", "untitled")`} ${2}
snippet in
interface ${1:`Filename("", "untitled")`} ${2}
interface ${1:`vim_snippets#Filename("", "untitled")`} ${2}
snippet imp
implements ${1}
snippet ext

View File

@ -1,6 +1,6 @@
# module and export all
snippet mod
-module(${1:`Filename('', 'my')`}).
-module(${1:`vim_snippets#Filename('', 'my')`}).
-compile([export_all]).
@ -66,7 +66,7 @@ snippet %p
%% @private
# OTP application
snippet application
-module(${1:`Filename('', 'my')`}).
-module(${1:`vim_snippets#Filename('', 'my')`}).
-behaviour(application).
@ -84,7 +84,7 @@ snippet application
ok.
# OTP supervisor
snippet supervisor
-module(${1:`Filename('', 'my')`}).
-module(${1:`vim_snippets#Filename('', 'my')`}).
-behaviour(supervisor).
@ -107,7 +107,7 @@ snippet supervisor
{ok, {RestartStrategy, Children}}.
# OTP gen_server
snippet gen_server
-module(${1:`Filename('', 'my')`}).
-module(${1:`vim_snippets#Filename('', 'my')`}).
-behaviour(gen_server).

View File

@ -412,7 +412,7 @@ snippet head
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`}</title>
<title>${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`}</title>
${2}
</head>
snippet header
@ -450,7 +450,7 @@ snippet html5
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`}</title>
<title>${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`}</title>
${2:meta}
</head>
<body>
@ -795,7 +795,7 @@ snippet thead
snippet time
<time datetime="${1}" pubdate="${2:$1}">${3:$1}</time>
snippet title
<title>${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`}</title>
<title>${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`}</title>
snippet tr
<tr>
${1}

View File

@ -39,11 +39,11 @@ snippet j.u
##
## Class
snippet cl
class ${1:`Filename("", "untitled")`} ${2}
class ${1:`vim_snippets#Filename("", "untitled")`} ${2}
snippet in
interface ${1:`Filename("", "untitled")`} ${2:extends Parent}${3}
interface ${1:`vim_snippets#Filename("", "untitled")`} ${2:extends Parent}${3}
snippet tc
public class ${1:`Filename()`} extends ${2:TestCase}
public class ${1:`vim_snippets#Filename()`} extends ${2:TestCase}
##
## Class Enhancements
snippet ext
@ -144,7 +144,7 @@ snippet @au
snippet @br
@brief ${1:Description}
snippet @fi
@file ${1:`Filename()`}.java
@file ${1:`vim_snippets#Filename()`}.java
snippet @pa
@param ${1:param}
snippet @re

View File

@ -3,7 +3,7 @@ snippet Imp
#import <${1:Cocoa/Cocoa.h}>${2}
# #import "..."
snippet imp
#import "${1:`Filename()`.h}"${2}
#import "${1:`vim_snippets#Filename()`.h}"${2}
# @selector(...)
snippet sel
@selector(${1:method}:)${3}
@ -18,7 +18,7 @@ snippet log
NSLog(@"${1:%@}"${2});${3}
# Class
snippet objc
@interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
@interface ${1:`vim_snippets#Filename('', 'someClass')`} : ${2:NSObject}
{
}
@end
@ -28,33 +28,33 @@ snippet objc
@end
# Class Interface
snippet int
@interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
@interface ${1:`vim_snippets#Filename('', 'someClass')`} : ${2:NSObject}
{${3}
}
${4}
@end
snippet @interface
@interface ${1:`Filename('', 'someClass')`} : ${2:NSObject}
@interface ${1:`vim_snippets#Filename('', 'someClass')`} : ${2:NSObject}
{${3}
}
${4}
@end
# Class Implementation
snippet impl
@implementation ${1:`Filename('', 'someClass')`}
@implementation ${1:`vim_snippets#Filename('', 'someClass')`}
${2}
@end
snippet @implementation
@implementation ${1:`Filename('', 'someClass')`}
@implementation ${1:`vim_snippets#Filename('', 'someClass')`}
${2}
@end
# Protocol
snippet pro
@protocol ${1:`Filename('$1Delegate', 'MyProtocol')`} ${2:<NSObject>}
@protocol ${1:`vim_snippets#Filename('$1Delegate', 'MyProtocol')`} ${2:<NSObject>}
${3}
@end
snippet @protocol
@protocol ${1:`Filename('$1Delegate', 'MyProtocol')`} ${2:<NSObject>}
@protocol ${1:`vim_snippets#Filename('$1Delegate', 'MyProtocol')`} ${2:<NSObject>}
${3}
@end
# init Definition
@ -87,7 +87,7 @@ snippet cat
@end
# Category Interface
snippet cath
@interface ${1:`Filename('$1', 'NSObject')`} (${2:MyCategory})
@interface ${1:`vim_snippets#Filename('$1', 'NSObject')`} (${2:MyCategory})
${3}
@end
# Method

View File

@ -84,7 +84,7 @@ snippet fore
${1:expression} foreach @${2:array};${3}
# Package
snippet package
package ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`};
package ${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`};
${2}
@ -93,7 +93,7 @@ snippet package
__END__
# Package syntax perl >= 5.14
snippet packagev514
package ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`} ${2:0.99};
package ${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`} ${2:0.99};
${3}

View File

@ -28,12 +28,12 @@ snippet use
use ${1:Foo\Bar\Baz};
${2}
snippet c
class ${1:`Filename()`}
class ${1:`vim_snippets#Filename()`}
{
${2}
}
snippet i
interface ${1:`Filename()`}
interface ${1:`vim_snippets#Filename()`}
{
${2}
}
@ -57,7 +57,7 @@ snippet sm
*
* @param ${2:$1} $$1 ${3:description}
*
* @return ${4:`Filename()`}
* @return ${4:`vim_snippets#Filename()`}
*/
${5:public} function set${6:$2}(${7:$2 }$$1)
{
@ -214,7 +214,7 @@ snippet interface
* @package ${3:default}
* @author ${4:`g:snips_author`}
*/
interface ${1:`Filename()`}
interface ${1:`vim_snippets#Filename()`}
{
${5}
}
@ -223,7 +223,7 @@ snippet class
/**
* ${1}
*/
class ${2:`Filename()`}
class ${2:`vim_snippets#Filename()`}
{
${3}
/**
@ -237,7 +237,7 @@ snippet class
snippet nc
namespace ${1:`substitute(substitute(expand("%:h"), '\v^\w+\/(\u)', '\1', ''), '\/', '\\\', 'g')`};
${2:abstract }class ${3:`Filename()`}
${2:abstract }class ${3:`vim_snippets#Filename()`}
{
${4}
}
@ -366,7 +366,7 @@ snippet gs
*
* @param $2 $$1 ${5:description}
*
* @return ${6:`Filename()`}
* @return ${6:`vim_snippets#Filename()`}
*/
public function set$3(${7:$2 }$$1)
{

View File

@ -5,11 +5,11 @@
# Language Constructs
snippet class
class ${1:`Filename('', 'name')`} {
class ${1:`vim_snippets#Filename('', 'name')`} {
${2}
}
snippet node
node "${1:`Filename('', 'fqdn')`}" {
node "${1:`vim_snippets#Filename('', 'fqdn')`}" {
${2}
}
snippet case

View File

@ -10,7 +10,7 @@ snippet from
# Module Docstring
snippet docs
"""
File: ${1:`Filename('$1.py', 'foo.py')`}
File: ${1:`vim_snippets#Filename('$1.py', 'foo.py')`}
Author: `g:snips_author`
Email: `g:snips_email`
Github: `g:snips_github`

View File

@ -88,23 +88,23 @@ snippet until
${2}
end
snippet cla class .. end
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
${2}
end
snippet cla class .. initialize .. end
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
def initialize(${2:args})
${3}
end
end
snippet cla class .. < ParentClass .. initialize .. end
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < ${2:ParentClass}
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < ${2:ParentClass}
def initialize(${3:args})
${4}
end
end
snippet cla ClassName = Struct .. do .. end
${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} = Struct.new(:${2:attr_names}) do
${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} = Struct.new(:${2:attr_names}) do
def ${3:method_name}
${4}
end
@ -119,7 +119,7 @@ snippet cla class << self .. end
end
# class .. < DelegateClass .. initialize .. end
snippet cla-
class ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < DelegateClass(${2:ParentClass})
class ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} < DelegateClass(${2:ParentClass})
def initialize(${3:args})
super(${4:del_obj})
@ -127,17 +127,17 @@ snippet cla-
end
end
snippet mod module .. end
module ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
module ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
${2}
end
snippet mod module .. module_function .. end
module ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
module ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
module_function
${2}
end
snippet mod module .. ClassMethods .. end
module ${1:`substitute(Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
module ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`}
module ClassMethods
${2}
end
@ -553,7 +553,7 @@ snippet clafn
snippet sinc
class << self; self end
snippet nam
namespace :${1:`Filename()`} do
namespace :${1:`vim_snippets#Filename()`} do
${2}
end
snippet tas
@ -1070,3 +1070,5 @@ snippet isres
it { should respond_to :${1} }
snippet isresw
it { should respond_to(:${1}).with(${2}).arguments }
snippet super_call
${1:super_class}.instance_method(:${2:method}).bind(self).call

View File

@ -4,7 +4,7 @@ snippet header
" Description: ${3}
${4:" Last Modified: `strftime("%B %d, %Y")`}
snippet guard
if exists('${1:did_`Filename()`}') || &cp${2: || version < 700}
if exists('${1:did_`vim_snippets#Filename()`}') || &cp${2: || version < 700}
finish
endif
let $1 = 1${3}