diff --git a/UltiSnips/d.snippets b/UltiSnips/d.snippets index 9495951..7f38c6d 100644 --- a/UltiSnips/d.snippets +++ b/UltiSnips/d.snippets @@ -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} diff --git a/autoload/vim_snippets.vim b/autoload/vim_snippets.vim new file mode 100644 index 0000000..061f171 --- /dev/null +++ b/autoload/vim_snippets.vim @@ -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 diff --git a/snippets/c.snippets b/snippets/c.snippets index 16a86e9..7578024 100644 --- a/snippets/c.snippets +++ b/snippets/c.snippets @@ -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 { diff --git a/snippets/coffee.snippets b/snippets/coffee.snippets index 21c2cc3..8e2f20e 100644 --- a/snippets/coffee.snippets +++ b/snippets/coffee.snippets @@ -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} diff --git a/snippets/cpp.snippets b/snippets/cpp.snippets index 52148e7..e95d353 100644 --- a/snippets/cpp.snippets +++ b/snippets/cpp.snippets @@ -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 */ ## diff --git a/snippets/cs.snippets b/snippets/cs.snippets index d934351..9a915f0 100644 --- a/snippets/cs.snippets +++ b/snippets/cs.snippets @@ -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 diff --git a/snippets/dart.snippets b/snippets/dart.snippets index c7b56da..a745200 100644 --- a/snippets/dart.snippets +++ b/snippets/dart.snippets @@ -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 diff --git a/snippets/erlang.snippets b/snippets/erlang.snippets index 1199e84..0837bb7 100644 --- a/snippets/erlang.snippets +++ b/snippets/erlang.snippets @@ -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). diff --git a/snippets/html.snippets b/snippets/html.snippets index 3615d4b..a83089c 100644 --- a/snippets/html.snippets +++ b/snippets/html.snippets @@ -412,7 +412,7 @@ snippet head - ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`} + ${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`} ${2} snippet header @@ -450,7 +450,7 @@ snippet html5 - ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`} + ${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`} ${2:meta} @@ -795,7 +795,7 @@ snippet thead snippet time snippet title - ${1:`substitute(Filename('', 'Page Title'), '^.', '\u&', '')`} + ${1:`substitute(vim_snippets#Filename('', 'Page Title'), '^.', '\u&', '')`} snippet tr ${1} diff --git a/snippets/java.snippets b/snippets/java.snippets index 4dc6ff0..a36e0f1 100644 --- a/snippets/java.snippets +++ b/snippets/java.snippets @@ -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 diff --git a/snippets/objc.snippets b/snippets/objc.snippets index 3cf5a0a..c819c77 100644 --- a/snippets/objc.snippets +++ b/snippets/objc.snippets @@ -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:} + @protocol ${1:`vim_snippets#Filename('$1Delegate', 'MyProtocol')`} ${2:} ${3} @end snippet @protocol - @protocol ${1:`Filename('$1Delegate', 'MyProtocol')`} ${2:} + @protocol ${1:`vim_snippets#Filename('$1Delegate', 'MyProtocol')`} ${2:} ${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 diff --git a/snippets/perl.snippets b/snippets/perl.snippets index cd3f459..48d3f22 100644 --- a/snippets/perl.snippets +++ b/snippets/perl.snippets @@ -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} diff --git a/snippets/php.snippets b/snippets/php.snippets index 8b071fc..b85d96e 100644 --- a/snippets/php.snippets +++ b/snippets/php.snippets @@ -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) { diff --git a/snippets/puppet.snippets b/snippets/puppet.snippets index b8dbe50..e95b9c7 100644 --- a/snippets/puppet.snippets +++ b/snippets/puppet.snippets @@ -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 diff --git a/snippets/python.snippets b/snippets/python.snippets index e8dade2..d8544cd 100644 --- a/snippets/python.snippets +++ b/snippets/python.snippets @@ -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` diff --git a/snippets/ruby.snippets b/snippets/ruby.snippets index 1d344ac..9c99479 100644 --- a/snippets/ruby.snippets +++ b/snippets/ruby.snippets @@ -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 diff --git a/snippets/vim.snippets b/snippets/vim.snippets index a92cd13..6dd502f 100644 --- a/snippets/vim.snippets +++ b/snippets/vim.snippets @@ -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}