diff --git a/UltiSnips/html.snippets b/UltiSnips/html.snippets index 31f7cc3..5746feb 100644 --- a/UltiSnips/html.snippets +++ b/UltiSnips/html.snippets @@ -194,7 +194,7 @@ endsnippet snippet head "XHTML " - + ${1:`!p snip.rv = snip.basename or "Page Title"`} $0 diff --git a/UltiSnips/java.snippets b/UltiSnips/java.snippets index 96cc7a9..21be6be 100644 --- a/UltiSnips/java.snippets +++ b/UltiSnips/java.snippets @@ -25,8 +25,13 @@ def getArgs(group): return [i.split(" ") for i in word.findall(group) ] def camel(word): + if not word: return '' return word[0].upper() + word[1:] +def mixedCase(word): + if not word: return '' + return word[0].lower() + word[1:] + endglobal snippet sleep "try sleep catch" b @@ -173,13 +178,13 @@ default: $0 endsnippet -snippet elif "else if" b +snippet elif "else if" else if ($1)`!p nl(snip)`{ $0 } endsnippet -snippet /el(se)?/ "else" br +snippet /el(se)?/ "else" r else`!p nl(snip)`{ $0 } @@ -338,23 +343,23 @@ endsnippet snippet /get(ter)?/ "getter" br public ${1:String} get${2:Name}() { - return `!p snip.rv = t[2].lower()`; + return `!p snip.rv = mixedCase(t[2])`; } endsnippet snippet /set(ter)?/ "setter" br -public void set${1:Name}(${2:String} $1) { - return this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`; +public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) { + this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`; } endsnippet snippet /se?tge?t|ge?tse?t|gs/ "setter and getter" br -public void set${1:Name}(${2:String} `!p snip.rv = t[1].lower()`) { - this.`!p snip.rv = t[1].lower()` = `!p snip.rv = t[1].lower()`; +public void set${1:Name}(${2:String} `!p snip.rv = mixedCase(t[1])`) { + this.`!p snip.rv = mixedCase(t[1])` = `!p snip.rv = mixedCase(t[1])`; } public $2 get$1() { - return `!p snip.rv = t[1].lower()`; + return `!p snip.rv = mixedCase(t[1])`; } endsnippet diff --git a/UltiSnips/proto.snippets b/UltiSnips/proto.snippets new file mode 100644 index 0000000..923be57 --- /dev/null +++ b/UltiSnips/proto.snippets @@ -0,0 +1,52 @@ +priority -50 + +global !p +from vimsnippets import complete + +FIELD_TYPES = [ + 'double', + 'float', + 'int32', + 'int64', + 'uint32', + 'uint64', + 'sint32', + 'sint64', + 'fixed32', + 'fixed64', + 'sfixed32', + 'sfixed64', + 'bool', + 'string', + 'bytes'] +endglobal + +snippet mess "Proto message" b +// ${2:TODO(`whoami`): Describe this message.} +message ${1:Name} { + $0 + + // Next available id: 1 +} +endsnippet + +snippet reqf "Required field" b +// ${4:TODO(`whoami`): Describe this field.} +optional ${1}`!p snip.rv = complete(t[1], FIELD_TYPES)` ${2:name} = ${3:1}; // Required +endsnippet + +snippet optf "Optional field" b +// ${4:TODO(`whoami`): Describe this field.} +optional ${1}`!p snip.rv = complete(t[1], FIELD_TYPES)` ${2:name} = ${3:1}; +endsnippet + +snippet repf "Repeated field" b +// ${4:TODO(`whoami`): Describe this field.} +repeated ${1}`!p snip.rv = complete(t[1], FIELD_TYPES)` ${2:name} = ${3:1}; +endsnippet + +snippet enum "Enumeration" b +// ${2:TODO(`whoami`): Describe this enum.} +enum ${1:Name} { +} +endsnippet diff --git a/UltiSnips/python.snippets b/UltiSnips/python.snippets index 357d01d..64b5cfd 100644 --- a/UltiSnips/python.snippets +++ b/UltiSnips/python.snippets @@ -34,13 +34,30 @@ global !p NORMAL = 0x1 DOXYGEN = 0x2 SPHINX = 0x3 +GOOGLE = 0x4 SINGLE_QUOTES = 0x1 DOUBLE_QUOTES = 0x2 + +class Arg(object): + def __init__(self, arg): + self.arg = arg + self.name = arg.split('=')[0].strip() + + def __str__(self): + return self.name + + def __unicode__(self): + return self.name + + def is_kwarg(self): + return '=' in self.arg + + def get_args(arglist): - args = [arg.split('=')[0].strip() for arg in arglist.split(',') if arg] - args = [arg for arg in args if arg and arg != "self"] + args = [Arg(arg) for arg in arglist.split(',') if arg] + args = [arg for arg in args if arg.name != 'self'] return args @@ -51,7 +68,7 @@ def get_quoting_style(snip): return SINGLE_QUOTES return DOUBLE_QUOTES -def tripple_quotes(snip): +def triple_quotes(snip): if get_quoting_style(snip) == SINGLE_QUOTES: return "'''" return '"""' @@ -61,6 +78,7 @@ def get_style(snip): if style == "doxygen": return DOXYGEN elif style == "sphinx": return SPHINX + elif style == "google": return GOOGLE else: return NORMAL @@ -71,6 +89,8 @@ def format_arg(arg, style): return ":param %s: @todo" % arg elif style == NORMAL: return ":%s: @todo" % arg + elif style == GOOGLE: + return "%s (@todo): @todo" % arg def format_return(style): @@ -78,19 +98,45 @@ def format_return(style): return "@return: @todo" elif style in (NORMAL, SPHINX): return ":returns: @todo" + elif style == GOOGLE: + return "Returns: @todo" def write_docstring_args(args, snip): if not args: - snip.rv += ' {0}'.format(tripple_quotes(snip)) + snip.rv += ' {0}'.format(triple_quotes(snip)) return snip.rv += '\n' + snip.mkline('', indent='') style = get_style(snip) - for arg in args: - snip += format_arg(arg, style) + if style == GOOGLE: + write_google_docstring_args(args, snip) + else: + for arg in args: + snip += format_arg(arg, style) + + +def write_google_docstring_args(args, snip): + kwargs = [arg for arg in args if arg.is_kwarg()] + args = [arg for arg in args if not arg.is_kwarg()] + + if args: + snip += "Args:" + snip.shift() + for arg in args: + snip += format_arg(arg, GOOGLE) + snip.unshift() + snip.rv += '\n' + snip.mkline('', indent='') + + if kwargs: + snip += "Kwargs:" + snip.shift() + for kwarg in kwargs: + snip += format_arg(kwarg, GOOGLE) + snip.unshift() + snip.rv += '\n' + snip.mkline('', indent='') def write_init_body(args, parents, snip): @@ -120,10 +166,10 @@ endglobal snippet class "class with docstrings" b class ${1:MyClass}(${2:object}): - `!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)` + `!p snip.rv = triple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = triple_quotes(snip)` def __init__(self$4): - `!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined1.}`!p + `!p snip.rv = triple_quotes(snip)`${5:@todo: to be defined1.}`!p snip.rv = "" snip >> 2 @@ -132,7 +178,7 @@ args = get_args(t[4]) write_docstring_args(args, snip) if args: snip.rv += '\n' + snip.mkline('', indent='') - snip += '{0}'.format(tripple_quotes(snip)) + snip += '{0}'.format(triple_quotes(snip)) write_init_body(args, t[2], snip) ` @@ -143,7 +189,7 @@ endsnippet snippet slotclass "class with slots and docstrings" b class ${1:MyClass}(${2:object}): - `!p snip.rv = tripple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = tripple_quotes(snip)` + `!p snip.rv = triple_quotes(snip)`${3:Docstring for $1. }`!p snip.rv = triple_quotes(snip)` `!p snip >> 1 args = get_args(t[4]) @@ -151,7 +197,7 @@ write_slots_args(args, snip) ` def __init__(self$4): - `!p snip.rv = tripple_quotes(snip)`${5:@todo: to be defined.}`!p + `!p snip.rv = triple_quotes(snip)`${5:@todo: to be defined.}`!p snip.rv = "" snip >> 2 @@ -160,7 +206,7 @@ args = get_args(t[4]) write_docstring_args(args, snip) if args: snip.rv += '\n' + snip.mkline('', indent='') - snip += tripple_quotes(snip) + snip += triple_quotes(snip) write_init_body(args, t[2], snip) ` @@ -353,7 +399,7 @@ snippet def "function with docstrings" b def ${1:function}(`!p if snip.indent: snip.rv = 'self' + (", " if len(t[2]) else "")`${2:arg1}): - `!p snip.rv = tripple_quotes(snip)`${4:@todo: Docstring for $1.}`!p + `!p snip.rv = triple_quotes(snip)`${4:@todo: Docstring for $1.}`!p snip.rv = "" snip >> 1 @@ -364,7 +410,7 @@ if args: style = get_style(snip) snip += format_return(style) snip.rv += '\n' + snip.mkline('', indent='') -snip += tripple_quotes(snip) ` +snip += triple_quotes(snip) ` ${0:pass} endsnippet @@ -390,7 +436,7 @@ endsnippet snippet rwprop "Read write property" b def ${1:name}(): - `!p snip.rv = tripple_quotes(snip) if t[2] else '' + `!p snip.rv = triple_quotes(snip) if t[2] else '' `${2:@todo: Docstring for $1.}`!p if t[2]: snip >> 1 @@ -399,7 +445,7 @@ if t[2]: snip.rv += '\n' + snip.mkline('', indent='') snip += format_return(style) snip.rv += '\n' + snip.mkline('', indent='') - snip += tripple_quotes(snip) + snip += triple_quotes(snip) else: snip.rv = ""` def fget(self): @@ -518,7 +564,7 @@ endsnippet snippet testcase "pyunit testcase" b class Test${1:Class}(${2:unittest.TestCase}): - `!p snip.rv = tripple_quotes(snip)`${3:Test case docstring.}`!p snip.rv = tripple_quotes(snip)` + `!p snip.rv = triple_quotes(snip)`${3:Test case docstring.}`!p snip.rv = triple_quotes(snip)` def setUp(self): ${4:pass} diff --git a/UltiSnips/r.snippets b/UltiSnips/r.snippets new file mode 100644 index 0000000..d78a1d7 --- /dev/null +++ b/UltiSnips/r.snippets @@ -0,0 +1,144 @@ +priority -50 + +snippet #! "Hashbang for Rscript (#!)" b +#!/usr/bin/env Rscript +endsnippet + +snippet lib "Import a library" +library(${0:package}) +endsnippet + +snippet req "Require a file" +require(${0:package}) +endsnippet + +snippet source "Source a file" +source('${0:file}') +endsnippet + +snippet if "If statement" +if (${1}) { + ${0} +} +endsnippet + +snippet eif "Else-If statement" +else if (${1}) { + ${0} +} + +snippet el "Else statement" +else { + ${0} +} +endsnippet + +snippet ife "if .. else" +if (${1}) { + ${2} +} else { + ${3} +} +endsnippet + +snippet wh "while loop" +while(${1}) { + ${2} +} +endsnippet + +snippet for "for loop" +for ({${1:item} in ${2:list}) { + ${3} +} +endsnippet + +snippet fun "Function definition" +${1:name} <- function (${2}) { + ${0} +} +endsnippet + +snippet ret "Return call" +return(${0}) +endsnippet + +snippet df "Data frame" +${1:name}[${2:rows}, ${0:cols}] +endsnippet + +snippet c "c function" +c(${0:items}) +endsnippet + +snippet li "list function" +list(${0:items}) +endsnippet + +snippet mat "matrix function" +matrix(${1:data}, nrow = ${2:rows}, ncol = ${0:cols}) +endsnippet + +snippet apply "apply function" +apply(${1:array}, ${2:margin}, ${0:function}) +endsnippet + +snippet lapply "lapply function" +lapply(${1:list}, ${0:function}) +endsnippet + +snippet sapply "sapply function" +lapply(${1:list}, ${0:function}) +endsnippet + +snippet vapply "vapply function" +vapply(${1:list}, ${2:function}, ${0:type}) +endsnippet + +snippet mapply "mapply function" +mapply(${1:function}, ${0:...}) +endsnippet + +snippet tapply "tapply function" +tapply(${1:vector}, ${2:index}, ${0:function}) +endsnippet + +snippet rapply "rapply function" +rapply(${1:list}, ${0:function}) +endsnippet + +snippet pl "Plot function" +plot(${1:x}, ${0:y}) +endsnippet + +snippet ggp "ggplot2 plot" +ggplot(${1:data}, aes(${0:aesthetics})) +endsnippet + +snippet fis "Fisher test" +fisher.test(${1:x}, ${0:y}) +endsnippet + +snippet chi "Chi Squared test" +chisq.test(${1:x}, ${0:y}) +endsnippet + +snippet tt "t-test" +t.test(${1:x}, ${0:y}) +endsnippet + +snippet wil "Wilcox test" +wilcox.test(${1:x}, ${0:y}) +endsnippet + +snippet cor "Correlation test" +cor.test(${1:x}, ${0:y}) +endsnippet + +snippet fte "FTE test" +var.test(${1:x}, ${0:y}) +endsnippet + +snippet kvt "KV test" +kv.test(${1:x}, ${0:y}) +endsnippet diff --git a/UltiSnips/rnoweb.snippets b/UltiSnips/rnoweb.snippets new file mode 100644 index 0000000..773b9aa --- /dev/null +++ b/UltiSnips/rnoweb.snippets @@ -0,0 +1,3 @@ +priority -50 + +extends tex, r diff --git a/UltiSnips/rst.snippets b/UltiSnips/rst.snippets index e8aef2b..3763a95 100644 --- a/UltiSnips/rst.snippets +++ b/UltiSnips/rst.snippets @@ -12,6 +12,8 @@ from string import Template import re from collections import Counter +from vimsnippets import complete + #http://docutils.sourceforge.net/docs/ref/rst/roles.html TEXT_ROLES = ['emphasis','literal','code','math', 'pep-reference','rfc-reference', @@ -130,27 +132,6 @@ def get_popular_code_type(): except IndexError: popular_type = "lua" # Don't break default return popular_type - - -def complete(t, opts): - """ - get options that start with t - - :param t: query string - :param opts: list that needs to be completed - - :return: a string that start with t - """ - msg = "({0})" - if t: - opts = [ m[len(t):] for m in opts if m.startswith(t) ] - if len(opts) == 1: - return opts[0] - - if not len(opts): - msg = "{0}" - return msg.format("|".join(opts)) - endglobal snippet part "Part" b diff --git a/UltiSnips/rust.snippets b/UltiSnips/rust.snippets new file mode 100644 index 0000000..98a371f --- /dev/null +++ b/UltiSnips/rust.snippets @@ -0,0 +1,215 @@ +####################################################################### +# Rust Snippets # +####################################################################### + +############### +# Functions # +############### +snippet fn "A function, optionally with arguments and return type." +fn ${1:function_name}(${2})${3/..*/ -> /}${3} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + +snippet test "Test function" +#[test] +fn ${1:test_function_name}() { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + +snippet new "A new function" +pub fn new(${2}) -> ${1:Name} { + ${VISUAL}${0}return $1 { ${3} }; +} +endsnippet + +snippet main "The main function" +pub fn main() { + ${VISUAL}${0} +} +endsnippet + + + +snippet let "A let statement" +let ${1:name}${3} = ${VISUAL}${2}; +endsnippet + +snippet pln "println!(..)" b +println!("${1}"${2/..*/, /}${2}); +endsnippet + + + +snippet ec "extern crate ..." b +extern crate ${1:sync}; +endsnippet + +snippet ecl "...extern crate log;" b +#![feature(phase)] +#[phase(syntax, link)] extern crate log; +endsnippet + +snippet mod "A mod." b +mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} /* $1 */ +endsnippet + +snippet crate "Create header information" b +// Crate ID +#![crate_id = "${1:crate_name}#${2:0.0.1}"] + +// Additional metadata attributes +#![desc = "${3:Descrption.}"] +#![license = "${4:BSD}"] +#![comment = "${5:Comment.}"] + +// Specify the output type +#![crate_type = "${6:lib}"] +endsnippet + +snippet allow "#[allow(..)]" b +#[allow(${1:unused_variable})] +endsnippet + +snippet feat "#![feature(..)]" b +#![feature(${1:macro_rules})] +endsnippet + + +################## +# Common types # +################## +snippet opt "Option<..>" +Option<${1:int}> +endsnippet + +snippet res "Result<.., ..>" +Result<${1:~str}, ${2:()}> +endsnippet + + + + +snippet if "if .. (if)" b +if ${1:/* condition */} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + +snippet mat "match" +match ${1} { + ${2} => ${3}, +} +endsnippet + +snippet while "while .. {}" b +while ${1:condition} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + +snippet for "for .. in .." b +for ${1:i} in ${2:range(0u, 10)} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + +snippet spawn "spawn(proc() { .. });" b +spawn(proc() { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +}); +endsnippet + +snippet chan "A channel" b +let (${1:tx}, ${2:rx}): (Sender<${3:int}>, Receiver<${4:int}>) = channel(); +endsnippet + +snippet duplex "Duplex stream" b +let (${1:from_child}, ${2:to_child}) = sync::duplex(); +endsnippet + +##################### +# TODO commenting # +##################### +snippet todo "A Todo comment" +// [TODO]: ${1:Description} - `!v strftime("%Y-%m-%d %I:%M%P")` +endsnippet + + +############ +# Struct # +############ +snippet st "Struct" b +struct ${1:`!p snip.rv = snip.basename.title() or "name"`} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + +snippet stn "Struct with new constructor." b +pub struct ${1:`!p snip.rv = snip.basename.title() or "name"`} { + ${3:/* code */} +} + +impl $1 { + pub fn new(${2}) -> $1 { + ${4}return $1 { + ${5} + }; + } +} +endsnippet + + +########## +# Enum # +########## +snippet enum "An enum" b +enum ${1:enum_name} { + ${VISUAL}${0}, +} +endsnippet + + +########## +# Impl # +########## +snippet imp "An impl" b +impl ${1:Name} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + +snippet drop "Drop implementation" b +impl Drop for ${1:Name} { + fn drop(&mut self) { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} + } +} +endsnippet + + +############ +# Traits # +############ +snippet trait "Trait block" b +trait ${1:Name} { + ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}} +} +endsnippet + + +############# +# Statics # +############# +snippet ss "A static string." +static ${1}: &'static str = "${VISUAL}${0}"; +endsnippet + +snippet stat "A static variable." +static ${1}: ${2:uint} = ${VISUAL}${0}; +endsnippet + +# vim:ft=snippets: diff --git a/plugin/vimsnippets.vim b/plugin/vimsnippets.vim new file mode 100644 index 0000000..3c3ecf9 --- /dev/null +++ b/plugin/vimsnippets.vim @@ -0,0 +1,37 @@ +if exists("b:done_vimsnippets") + finish +endif +let b:done_vimsnippets = 1 + +" Expanding the path is not needed on Vim 7.4 +if &cp || version >= 704 + finish +endif + +" Add pythonx to the python search path if needed (i.e. <= Vim 7.3). +if !has("python") && !has("python3") + finish +end + +" This will fail if UltiSnips is not installed. +try + call UltiSnips#bootstrap#Bootstrap() +catch /E117/ + finish +endtry + + +" This should have been set by UltiSnips, otherwise something is wrong. +if !exists("g:_uspy") + finish +end + + +" Expand our path +let s:SourcedFile=expand("") +exec g:_uspy "import vim, os, sys" +exec g:_uspy "sourced_file = vim.eval('s:SourcedFile')" +exec g:_uspy "while not os.path.exists(os.path.join(sourced_file, 'pythonx')): + \ sourced_file = os.path.dirname(sourced_file)" +exec g:_uspy "module_path = os.path.join(sourced_file, 'pythonx')" +exec g:_uspy "sys.path.append(module_path)" diff --git a/pythonx/vimsnippets.py b/pythonx/vimsnippets.py new file mode 100644 index 0000000..b00edb1 --- /dev/null +++ b/pythonx/vimsnippets.py @@ -0,0 +1,20 @@ +"""Helper methods used in UltiSnips snippets.""" + +def complete(tab, opts): + """ + get options that start with tab + + :param tab: query string + :param opts: list that needs to be completed + + :return: a string that start with tab + """ + msg = "({0})" + if tab: + opts = [m[len(tab):] for m in opts if m.startswith(tab)] + if len(opts) == 1: + return opts[0] + + if not len(opts): + msg = "{0}" + return msg.format("|".join(opts)) diff --git a/snippets/django.snippets b/snippets/django.snippets index cad80eb..e2a8d6d 100644 --- a/snippets/django.snippets +++ b/snippets/django.snippets @@ -10,6 +10,10 @@ snippet auto ${1:FIELDNAME} = models.AutoField(${0}) +snippet bigint + ${1:FIELDNAME} = models.BigIntegerField(${0}) +snippet binary + ${1:FIELDNAME} = models.BinaryField(${0}) snippet bool ${1:FIELDNAME} = models.BooleanField(${0:default=True}) snippet char @@ -80,7 +84,7 @@ snippet model def __unicode__(self): ${5} - def save(self, force_insert=False, force_update=False): + def save(self, *args, **kwargs): ${6} @models.permalink diff --git a/snippets/erlang.snippets b/snippets/erlang.snippets index 8845870..2a0d1a4 100644 --- a/snippets/erlang.snippets +++ b/snippets/erlang.snippets @@ -120,8 +120,12 @@ snippet gen_server ]). %% gen_server callbacks - -export([init/1, handle_call/3, handle_cast/2, handle_info/2, - terminate/2, code_change/3]). + -export([init/1, + handle_call/3, + handle_cast/2, + handle_info/2, + terminate/2, + code_change/3]). -define(SERVER, ?MODULE). @@ -157,6 +161,320 @@ snippet gen_server code_change(_OldVsn, State, _Extra) -> {ok, State}. + %%%=================================================================== + %%% Internal functions + %%%=================================================================== +# OTP gen_fsm +snippet gen_fsm + -module(${0:`vim_snippets#Filename('', 'my')`}). + + -behaviour(gen_fsm). + + %% API + -export([start_link/0]). + + %% gen_fsm callbacks + -export([init/1, + state_name/2, + state_name/3, + handle_event/3, + handle_sync_event/4, + handle_info/3, + terminate/3, + code_change/4]). + + -record(state, {}). + + %%%=================================================================== + %%% API + %%%=================================================================== + + %%-------------------------------------------------------------------- + %% @doc + %% Creates a gen_fsm process which calls Module:init/1 to + %% initialize. To ensure a synchronized start-up procedure, this + %% function does not return until Module:init/1 has returned. + %% + %% @spec start_link() -> {ok, Pid} | ignore | {error, Error} + %% @end + %%-------------------------------------------------------------------- + start_link() -> + gen_fsm:start_link({local, ?MODULE}, ?MODULE, [], []). + + %%%=================================================================== + %%% gen_fsm callbacks + %%%=================================================================== + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Whenever a gen_fsm is started using gen_fsm:start/[3,4] or + %% gen_fsm:start_link/[3,4], this function is called by the new + %% process to initialize. + %% + %% @spec init(Args) -> {ok, StateName, State} | + %% {ok, StateName, State, Timeout} | + %% ignore | + %% {stop, StopReason} + %% @end + %%-------------------------------------------------------------------- + init([]) -> + {ok, state_name, #state{}}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% There should be one instance of this function for each possible + %% state name. Whenever a gen_fsm receives an event sent using + %% gen_fsm:send_event/2, the instance of this function with the same + %% name as the current state name StateName is called to handle + %% the event. It is also called if a timeout occurs. + %% + %% @spec state_name(Event, State) -> + %% {next_state, NextStateName, NextState} | + %% {next_state, NextStateName, NextState, Timeout} | + %% {stop, Reason, NewState} + %% @end + %%-------------------------------------------------------------------- + state_name(_Event, State) -> + {next_state, state_name, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% There should be one instance of this function for each possible + %% state name. Whenever a gen_fsm receives an event sent using + %% gen_fsm:sync_send_event/[2,3], the instance of this function with + %% the same name as the current state name StateName is called to + %% handle the event. + %% + %% @spec state_name(Event, From, State) -> + %% {next_state, NextStateName, NextState} | + %% {next_state, NextStateName, NextState, Timeout} | + %% {reply, Reply, NextStateName, NextState} | + %% {reply, Reply, NextStateName, NextState, Timeout} | + %% {stop, Reason, NewState} | + %% {stop, Reason, Reply, NewState} + %% @end + %%-------------------------------------------------------------------- + state_name(_Event, _From, State) -> + Reply = ok, + {reply, Reply, state_name, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Whenever a gen_fsm receives an event sent using + %% gen_fsm:send_all_state_event/2, this function is called to handle + %% the event. + %% + %% @spec handle_event(Event, StateName, State) -> + %% {next_state, NextStateName, NextState} | + %% {next_state, NextStateName, NextState, Timeout} | + %% {stop, Reason, NewState} + %% @end + %%-------------------------------------------------------------------- + handle_event(_Event, StateName, State) -> + {next_state, StateName, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Whenever a gen_fsm receives an event sent using + %% gen_fsm:sync_send_all_state_event/[2,3], this function is called + %% to handle the event. + %% + %% @spec handle_sync_event(Event, From, StateName, State) -> + %% {next_state, NextStateName, NextState} | + %% {next_state, NextStateName, NextState, Timeout} | + %% {reply, Reply, NextStateName, NextState} | + %% {reply, Reply, NextStateName, NextState, Timeout} | + %% {stop, Reason, NewState} | + %% {stop, Reason, Reply, NewState} + %% @end + %%-------------------------------------------------------------------- + handle_sync_event(_Event, _From, StateName, State) -> + Reply = ok, + {reply, Reply, StateName, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% This function is called by a gen_fsm when it receives any + %% message other than a synchronous or asynchronous event + %% (or a system message). + %% + %% @spec handle_info(Info,StateName,State)-> + %% {next_state, NextStateName, NextState} | + %% {next_state, NextStateName, NextState, Timeout} | + %% {stop, Reason, NewState} + %% @end + %%-------------------------------------------------------------------- + handle_info(_Info, StateName, State) -> + {next_state, StateName, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% This function is called by a gen_fsm when it is about to + %% terminate. It should be the opposite of Module:init/1 and do any + %% necessary cleaning up. When it returns, the gen_fsm terminates with + %% Reason. The return value is ignored. + %% + %% @spec terminate(Reason, StateName, State) -> void() + %% @end + %%-------------------------------------------------------------------- + terminate(_Reason, _StateName, _State) -> + ok. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Convert process state when code is changed + %% + %% @spec code_change(OldVsn, StateName, State, Extra) -> + %% {ok, StateName, NewState} + %% @end + %%-------------------------------------------------------------------- + code_change(_OldVsn, StateName, State, _Extra) -> + {ok, StateName, State}. + + %%%=================================================================== + %%% Internal functions + %%%=================================================================== +# OTP gen_event +snippet gen_event + -module(${0:`vim_snippets#Filename('', 'my')`}). + + -behaviour(gen_event). + + %% API + -export([start_link/0, + add_handler/2]). + + %% gen_event callbacks + -export([init/1, + handle_event/2, + handle_call/2, + handle_info/2, + terminate/2, + code_change/3]). + + -record(state, {}). + + %%%=================================================================== + %%% gen_event callbacks + %%%=================================================================== + + %%-------------------------------------------------------------------- + %% @doc + %% Creates an event manager + %% + %% @spec start_link() -> {ok, Pid} | {error, Error} + %% @end + %%-------------------------------------------------------------------- + start_link() -> + gen_event:start_link({local, ?MODULE}). + + %%-------------------------------------------------------------------- + %% @doc + %% Adds an event handler + %% + %% @spec add_handler(Handler, Args) -> ok | {'EXIT', Reason} | term() + %% @end + %%-------------------------------------------------------------------- + add_handler(Handler, Args) -> + gen_event:add_handler(?MODULE, Handler, Args). + + %%%=================================================================== + %%% gen_event callbacks + %%%=================================================================== + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Whenever a new event handler is added to an event manager, + %% this function is called to initialize the event handler. + %% + %% @spec init(Args) -> {ok, State} + %% @end + %%-------------------------------------------------------------------- + init([]) -> + {ok, #state{}}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Whenever an event manager receives an event sent using + %% gen_event:notify/2 or gen_event:sync_notify/2, this function is + %% called for each installed event handler to handle the event. + %% + %% @spec handle_event(Event, State) -> + %% {ok, State} | + %% {swap_handler, Args1, State1, Mod2, Args2} | + %% remove_handler + %% @end + %%-------------------------------------------------------------------- + handle_event(_Event, State) -> + {ok, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Whenever an event manager receives a request sent using + %% gen_event:call/3,4, this function is called for the specified + %% event handler to handle the request. + %% + %% @spec handle_call(Request, State) -> + %% {ok, Reply, State} | + %% {swap_handler, Reply, Args1, State1, Mod2, Args2} | + %% {remove_handler, Reply} + %% @end + %%-------------------------------------------------------------------- + handle_call(_Request, State) -> + Reply = ok, + {ok, Reply, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% This function is called for each installed event handler when + %% an event manager receives any other message than an event or a + %% synchronous request (or a system message). + %% + %% @spec handle_info(Info, State) -> + %% {ok, State} | + %% {swap_handler, Args1, State1, Mod2, Args2} | + %% remove_handler + %% @end + %%-------------------------------------------------------------------- + handle_info(_Info, State) -> + {ok, State}. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Whenever an event handler is deleted from an event manager, this + %% function is called. It should be the opposite of Module:init/1 and + %% do any necessary cleaning up. + %% + %% @spec terminate(Reason, State) -> void() + %% @end + %%-------------------------------------------------------------------- + terminate(_Reason, _State) -> + ok. + + %%-------------------------------------------------------------------- + %% @private + %% @doc + %% Convert process state when code is changed + %% + %% @spec code_change(OldVsn, State, Extra) -> {ok, NewState} + %% @end + %%-------------------------------------------------------------------- + code_change(_OldVsn, State, _Extra) -> + {ok, State}. + %%%=================================================================== %%% Internal functions %%%=================================================================== diff --git a/snippets/eruby.snippets b/snippets/eruby.snippets index 9541835..bc13fcb 100644 --- a/snippets/eruby.snippets +++ b/snippets/eruby.snippets @@ -107,6 +107,8 @@ snippet ntc <%= number_to_currency(${1}) %> snippet ofcfs <%= options_from_collection_for_select ${1:collection}, ${2:value_method}, ${3:text_method}, ${0:selected_value} %> +snippet ofs + <%= options_for_select ${1:collection}, ${2:value_method} %> snippet rf <%= render :file => "${1:file}"${0} %> snippet rt diff --git a/snippets/haskell.snippets b/snippets/haskell.snippets index f5f1598..ddb89d9 100644 --- a/snippets/haskell.snippets +++ b/snippets/haskell.snippets @@ -1,5 +1,7 @@ snippet lang {-# LANGUAGE ${0:OverloadedStrings} #-} +snippet haddock + {-# OPTIONS_HADDOCK ${0:hide} #-} snippet info -- | -- Module : ${1:Module.Namespace} diff --git a/snippets/jade.snippets b/snippets/jade.snippets new file mode 100644 index 0000000..55f0af7 --- /dev/null +++ b/snippets/jade.snippets @@ -0,0 +1,18 @@ +# Angular HTML +snippet rep + div(ng-repeat='${1} in ${2}') + +snippet repf + div(ng-repeat='${1} in ${2}' | ${3}) + +snippet repi + div(ng-repeat='${1} in ${2}' track by $index) + +snippet hide + div(ng-hide='${1}') + +snippet show + div(ng-show='${1}') + +snippet if + div(ng-if='${1}') diff --git a/snippets/python.snippets b/snippets/python.snippets index d38df5b..c221f46 100644 --- a/snippets/python.snippets +++ b/snippets/python.snippets @@ -1,5 +1,6 @@ snippet #! #!/usr/bin/env python + # -*- coding: utf-8 -*- snippet imp import ${0:module} snippet uni @@ -200,3 +201,10 @@ snippet epydoc @raise e: ${0: Description} """ +snippet dol + def ${1:__init__}(self, *args, **kwargs): + super(${0:ClassName}, self).$1(*args, **kwargs) +snippet kwg + self.${1:var_name} = kwargs.get('$1', ${2:None}) +snippet lkwg + ${1:var_name} = kwargs.get('$1', ${2:None}) diff --git a/snippets/ruby.snippets b/snippets/ruby.snippets index 1798e08..6ee11d4 100644 --- a/snippets/ruby.snippets +++ b/snippets/ruby.snippets @@ -479,6 +479,8 @@ snippet asne assert_not_equal ${1:unexpected}, ${2:actual} snippet asid assert_in_delta ${1:expected_float}, ${2:actual_float}, ${3:2 ** -20} +snippet asi + assert_includes ${1:collection}, ${2:object} snippet asio assert_instance_of ${1:ExpectedClass}, ${2:actual_instance} snippet asko @@ -749,8 +751,49 @@ snippet mapwo ${1:map}.with_options :${2:controller} => '${3:thing}' do |$3| ${0} end + +############################### +# model callback snippets # +############################### + +# before callback +snippet mbv + before_validation :${0:method} +snippet mbc + before_create :${0:method} +snippet mbu + before_update :${0:method} snippet mbs before_save :${0:method} +snippet mbd + before_destroy :${0:method} + +# after callback +snippet mav + after_validation :${0:method} +snippet maf + after_find :${0:method} +snippet mat + after_touch :${0:method} +snippet macr + after_create :${0:method} +snippet mau + after_update :${0:method} +snippet mas + after_save :${0:method} +snippet mad + after_destroy :${0:method} + +# around callback +snippet marc + around_create :${0:method} +snippet maru + around_update :${0:method} +snippet mars + around_save :${0:method} +snippet mard + around_destroy :${0:method} + snippet mcht change_table :${1:table_name} do |t| ${0} diff --git a/snippets/scala.snippets b/snippets/scala.snippets index 5eddb2c..09d69ad 100644 --- a/snippets/scala.snippets +++ b/snippets/scala.snippets @@ -194,8 +194,9 @@ snippet mhmap snippet as ${1:name}.asInstanceOf[${2:T}] #isInstanceOf[] +snippet is ${1:name}.isInstanceOf[${2:T}] -#end + #collections methods #scope() with one arg