This commit is contained in:
Gert 2015-03-26 16:53:50 +01:00
commit 9987d5e053
17 changed files with 394 additions and 113 deletions

View File

@ -205,7 +205,7 @@ to maintain snippets for a language, please get in touch.
Notes: People are interested in snippets - and their interest may wane again. Notes: People are interested in snippets - and their interest may wane again.
This list is kept up-to-date on a best effort basis. This list is kept up-to-date on a best effort basis.
* Elixir - [iurifq](https://github.com/iurifq) * Elixir - [lpil](https://github.com/lpil), [iurifq](https://github.com/iurifq)
* Falcon - [steveno](https://github.com/steveno) * Falcon - [steveno](https://github.com/steveno)
* HTML Django - [honza](http://github.com/honza) * HTML Django - [honza](http://github.com/honza)
* Javascript - [honza](http://github.com/honza) * Javascript - [honza](http://github.com/honza)

View File

@ -89,7 +89,8 @@ endsnippet
snippet bbox "A nice box over the full width" b snippet bbox "A nice box over the full width" b
`!p `!p
width = int(vim.eval("&textwidth")) or 71 if not snip.c:
width = int(vim.eval("&textwidth - (virtcol('.') == 1 ? 0 : virtcol('.'))")) or 71
box = make_box(len(t[1]), width) box = make_box(len(t[1]), width)
snip.rv = box[0] snip.rv = box[0]
snip += box[1] snip += box[1]

View File

@ -1,3 +1,33 @@
priority -50 priority -50
extends html extends html
snippet % "<% %>" w
<% $0 %>
endsnippet
snippet = "<%= %>" w
<%= $0 %>
endsnippet
snippet end "<% end %>" w
<% end %>
endsnippet
snippet ft "form_tag" w
<%= form_tag(${1:"${2:/users}"}, method: ${3::post}) %>
$0
</form>
endsnippet
snippet lin "link" w
<%= link ${1:"${2:Submit}"}, to: ${3:"${4:/users}"}, method: ${5::delete} %>
endsnippet
snippet ff "form_for" w
<%= form_for @changeset, ${1:"${2:/users}"}, fn f -> %>
$0
<%= submit "Submit" %>
<% end %>
endsnippet

View File

@ -111,6 +111,12 @@ func ${1:name}(${2:params})${3/(.+)/ /}${3:type} {
} }
endsnippet endsnippet
snippet funch "HTTP handler" b
func ${1:handler}(${2:w} http.ResponseWriter, ${3:r} *http.Request) {
${0:${VISUAL}}
}
endsnippet
# types and variables # types and variables
snippet map "Map type" b snippet map "Map type" b
map[${1:keytype}]${2:valtype} map[${1:keytype}]${2:valtype}
@ -135,3 +141,10 @@ snippet json "JSON field"
endsnippet endsnippet
# vim:ft=snippets: # vim:ft=snippets:
# error handling
snippet err "Basic error handling" b
if err != nil {
log.${1:Fatal}(err)
}
endsnippet

View File

@ -198,6 +198,18 @@ snippet h1 "XHTML <h1>" w
<h1>$0</h1> <h1>$0</h1>
endsnippet endsnippet
snippet h2 "XHTML <h2>" w
<h2>$0</h2>
endsnippet
snippet h3 "XHTML <h3>" w
<h3>$0</h3>
endsnippet
snippet h4 "XHTML <h4>" w
<h4>$0</h4>
endsnippet
snippet head "XHTML <head>" snippet head "XHTML <head>"
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">

View File

@ -4,12 +4,34 @@
priority -50 priority -50
snippet fn "A function, optionally with arguments and return type." b snippet let "let variable declaration" b
let ${1:name}${2:: ${3:type}} = ${4};
endsnippet
snippet letm "let mut variable declaration" b
let mut ${1:name}${2:: ${3:type}} = ${4};
endsnippet
snippet fn "A function, optionally with arguments and return type."
fn ${1:function_name}(${2})${3/..*/ -> /}${3} { fn ${1:function_name}(${2})${3/..*/ -> /}${3} {
${VISUAL}${0} ${VISUAL}${0}
} }
endsnippet endsnippet
snippet arg "Function Arguments" i
${1:a}: ${2:T}${3:, arg}
endsnippet
snippet || "Closure, anonymous function (inline)" i
${1:move }|${2}| { $3 }
endsnippet
snippet |} "Closure, anonymous function (block)" i
${1:move }|${2}| {
$3
}
endsnippet
snippet pri "print!(..)" b snippet pri "print!(..)" b
print!("${1}"${2/..*/, /}${2}); print!("${1}"${2/..*/, /}${2});
endsnippet endsnippet
@ -52,18 +74,27 @@ struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
} }
endsnippet endsnippet
# TODO: fancy dynamic field mirroring like Python slotclass
snippet stn "Struct with new constructor." b snippet stn "Struct with new constructor." b
pub struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} { pub struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
${3} fd${0}
} }
impl $1 { impl $1 {
pub fn new(${2}) -> $1 { pub fn new(${2}) -> $1 {
${4}return $1 { $1 { ${3} };
${5}
};
} }
} }
endsnippet endsnippet
snippet fd "Struct field definition" w
${1:name}: ${2:Type},
endsnippet
snippet impl "Struct/Trait implementation" b
impl ${1:Type/Trait}${2: for ${3:Type}} {
${0}
}
endsnippet
# vim:ft=snippets: # vim:ft=snippets:

View File

@ -71,7 +71,7 @@ snippet simc
} }
# if condition # if condition
snippet if snippet if
if (${1}) { if (${1:True}) {
${0} ${0}
} }
snippet el snippet el
@ -90,7 +90,7 @@ snippet ?
snippet do snippet do
do { do {
${0} ${0}
} while (${1}); } while (${1:True});
# while loop # while loop
snippet wh snippet wh
while (${1}) { while (${1}) {
@ -101,17 +101,21 @@ snippet for
for (int ${1:i} = 0; $1 < ${2:count}; $1${3:++}) { for (int ${1:i} = 0; $1 < ${2:count}; $1${3:++}) {
${0} ${0}
} }
snippet forr
for (int ${1:i} = ${2:length}; $1 >= 0; $1--) {
${0}
}
# foreach # foreach
snippet fore snippet fore
foreach (var ${1:entry} in ${2}) { foreach (${1:var} ${2:entry} in ${3}) {
${0} ${0}
} }
snippet foreach snippet foreach
foreach (var ${1:entry} in ${2}) { foreach (${1:var} ${2:entry} in ${3}) {
${0} ${0}
} }
snippet each snippet each
foreach (var ${1:entry} in ${2}) { foreach (${1:var} ${2:entry} in ${3}) {
${0} ${0}
} }
# interfaces # interfaces
@ -347,6 +351,11 @@ snippet struct
} }
# enumeration # enumeration
snippet enum snippet enum
enum ${1} {
${0}
}
snippet enum+
public enum ${1} { public enum ${1} {
${0} ${0}
} }
@ -372,3 +381,39 @@ snippet <rem
<remarks>${1}</remarks> <remarks>${1}</remarks>
snippet <c snippet <c
<code>${1}</code> <code>${1}</code>
snippet cw
Console.WriteLine(${1});
# equals override
snippet eq
public override bool Equals(object obj){
if (obj == null || GetType() != obj.GetType()){
return false;
}
${0:throw new NotImplementedException();}
return base.Equals(obj);
}
# exception snippet
snippet exc
public class ${1:MyException} : ${2:Exception}{
public $1() { }
public $1(string message) : base(message) { }
public $1(string message, Exception inner) : base(message, inner) { }
protected $1(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
# indexer snippet
snippet index
public ${1:object} this[${2:int} index]{
get { ${3:} }
set { ${0:} }
}
# eventhandler snippet
snippet inv
EventHandler temp = ${1:MyEvent};
if (${2:temp} != null){
$2();
}

View File

@ -1,6 +1,23 @@
snippet % snippet %
<% ${0} %> <% ${0} %>
snippet = snippet =
<%= ${1} %> <%= ${0} %>
snippet end snippet end
<% end %> <% end %>
snippet ft
<%= form_tag(${1:"/users"}, method: ${2::post}) %>
${0}
</form>
snippet lin
<%= link "${1:Submit}", to: ${2:"/users"}, method: ${3::delete} %>
snippet ff
<%= form_for @changeset, ${1:"/users"}, fn f -> %>
${0}
<%= submit "Submit" %>
<% end %>

View File

@ -592,6 +592,10 @@ snippet link:rss
<link rel="alternate" href="${1:rss.xml}" title="RSS" type="application/atom+xml" /> <link rel="alternate" href="${1:rss.xml}" title="RSS" type="application/atom+xml" />
snippet link:touch snippet link:touch
<link rel="apple-touch-icon" href="${1:favicon.png}" /> <link rel="apple-touch-icon" href="${1:favicon.png}" />
snippet main
<main role="main">
${0}
</main>
snippet map snippet map
<map name="${1}"> <map name="${1}">
${0} ${0}

View File

@ -1,3 +1,5 @@
snippet #!
#!/usr/bin/env node
# module exports # module exports
snippet ex snippet ex
module.exports = ${1}; module.exports = ${1};

View File

@ -257,6 +257,10 @@ snippet cdir
# Misc # Misc
# 'use strict';
snippet us
'use strict';
# setTimeout function # setTimeout function
snippet timeout snippet timeout
setTimeout(function () {${0}}${2}, ${1:10}); setTimeout(function () {${0}}${2}, ${1:10});

View File

@ -138,10 +138,10 @@ snippet pdbbb
# remote python debugger (rpdb) # remote python debugger (rpdb)
snippet rpdb snippet rpdb
import rpdb; rpdb.set_trace() import rpdb; rpdb.set_trace()
# python_prompt_toolkit # ptpython
snippet ppt snippet ptpython
from prompt_toolkit.contrib.repl import embed from ptpython.repl import embed
embed(globals(), locals(), vi_mode=${1:default=False}, history_filename=${2:default=None}) embed(globals(), locals(), vi_mode=${1:False}, history_filename=${2:None})
# python console debugger (pudb) # python console debugger (pudb)
snippet pudb snippet pudb
import pudb; pudb.set_trace() import pudb; pudb.set_trace()

View File

@ -36,7 +36,7 @@ snippet crw
cattr_accessor :${0:attr_names} cattr_accessor :${0:attr_names}
snippet defcreate snippet defcreate
def create def create
@${1:model_class_name} = ${2:ModelClassName}.new(params[:$1]) @${1:model_class_name} = ${2:ModelClassName}.new($1_params)
respond_to do |format| respond_to do |format|
if @$1.save if @$1.save
@ -95,7 +95,7 @@ snippet defupdate
@${1:model_class_name} = ${2:ModelClassName}.find(params[:id]) @${1:model_class_name} = ${2:ModelClassName}.find(params[:id])
respond_to do |format| respond_to do |format|
if @$1.update_attributes(params[:$1]) if @$1.update($1_params)
flash[:notice] = '$2 was successfully updated.' flash[:notice] = '$2 was successfully updated.'
format.html { redirect_to(@$1) } format.html { redirect_to(@$1) }
format.xml { head :ok } format.xml { head :ok }
@ -105,6 +105,10 @@ snippet defupdate
end end
end end
end end
snippet defparams
def ${1:model_class_name}_params
params.require(:$1).permit()
end
snippet dele delegate .. to snippet dele delegate .. to
delegate :${1:methods}, to: :${0:object} delegate :${1:methods}, to: :${0:object}
snippet dele delegate .. to .. prefix .. allow_nil snippet dele delegate .. to .. prefix .. allow_nil

View File

@ -3,11 +3,11 @@
################# #################
# Functions # Functions
snippet fn snippet fn "Function definition"
fn ${1:function_name}(${2})${3} { fn ${1:function_name}(${2})${3} {
${0} ${0}
} }
snippet test snippet test "Unit test function"
#[test] #[test]
fn ${1:test_function_name}() { fn ${1:test_function_name}() {
${0} ${0}
@ -19,32 +19,51 @@ snippet bench "Bench function" b
${0} ${0}
}) })
} }
snippet new snippet new "Constructor function"
pub fn new(${2}) -> ${1:Name} { pub fn new(${2}) -> ${1:Name} {
${0}return $1 { ${3} }; $1 { ${3} };
} }
snippet main snippet main "Main function"
pub fn main() { pub fn main() {
${0} ${0}
} }
snippet let snippet let "let variable declaration"
let ${1:name: type} = ${2}; let ${1:name}${2:: ${3:type}} = ${4};
snippet let snippet letm "let mut variable declaration"
let mut ${1:name: type} = ${2}; let mut ${1:name}${2:: ${3:type}} = ${4};
snippet pln snippet pln "println!"
println!("${1}"); println!("${1}");
snippet pln, snippet pln, "println! with format param"
println!("${1}", ${2}); println!("${1}", ${2});
snippet ec # Modules
snippet ec "extern crate"
extern crate ${1:sync}; extern crate ${1:sync};
snippet ecl snippet ecl "extern crate log"
#![feature(phase)] #[macro_use]
#[phase(plugin, link)] extern crate log; extern crate log;
snippet mod snippet mod
mod ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} { mod ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0} ${0}
} /* $1 */ } /* $1 */
snippet crate snippet testmod "Test module" b
#[cfg(test)]
mod tests {
use super::${1:*};
test${0}
}
# Attributes
snippet allow "allow lint attribute" b
#[allow(${1:unused_variable})]
snippet cfg "cfg attribute" b
#[cfg(${1:target_os = "linux"})]
snippet feat "feature attribute" b
#![feature(${1:plugin})]
snippet der "#[derive(..)]" b
#[derive(${1:Debug})]
snippet attr "#[..]" b
#[${1:inline}]
snippet crate "Define create meta attributes"
// Crate name // Crate name
#![crate_name = "${1:crate_name}"] #![crate_name = "${1:crate_name}"]
// Additional metadata attributes // Additional metadata attributes
@ -53,110 +72,107 @@ snippet crate
#![comment = "${4:Comment.}"] #![comment = "${4:Comment.}"]
// Specify the output type // Specify the output type
#![crate_type = "${5:lib}"] #![crate_type = "${5:lib}"]
snippet allow
#[allow(${1:unused_variable})]
snippet feat
#![feature(${1:macro_rules})]
snippet der "#[deriving(..)]" b
#[deriving(${1:Show})]
snippet attr "#[..]" b
#[${1:inline}]
# Common types # Common types
snippet opt snippet opt "Option<T>"
Option<${1:int}> Option<${1:i32}>
snippet res snippet res "Result<T, E>"
Result<${1:~str}, ${2:()}> Result<${1:~str}, ${2:()}>
# Control structures
snippet if snippet if
if ${1} { if ${1} {
${0} ${0}
} }
snippet ife snippet ife "if / else"
if ${1} { if ${1} {
${2} ${2}
} else { } else {
${0} ${0}
} }
snippet el snippet el "else"
else { else {
${0} ${0}
} }
snippet eli snippet eli "else if"
else if ${1} { else if ${1} {
${0} ${0}
} }
snippet mat snippet mat "match pattern"
match ${1} { match ${1} {
${2} => ${3}, ${2} => ${3}
} }
snippet case "Case clause of pattern match"
${1:_} => ${2:expression}
snippet loop "loop {}" b snippet loop "loop {}" b
loop { loop {
${0} ${0}
} }
snippet while snippet while "while loop"
while ${1:condition} { while ${1:condition} {
${0} ${0}
} }
snippet for snippet for "for ... in ... loop"
for ${1:i} in ${2:0u..10} { for ${1:i} in ${2:0u..10} {
${0} ${0}
} }
snippet spawn
spawn(proc() {
${0}
});
snippet chan
let (${1:tx}, ${2:rx}): (Sender<${3:int}>, Receiver<${4:int}>) = channel();
snippet duplex
let (${1:from_child}, ${2:to_child}) = sync::duplex();
# TODO commenting # TODO commenting
snippet todo snippet todo "TODO comment"
// [TODO]: ${0:Description} // [TODO]: ${0:Description}
snippet fixme "FIXME comment" snippet fixme "FIXME comment"
// FIXME: $0 // FIXME: $0
# Struct # Struct
snippet st snippet st "Struct definition"
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} { struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0} ${0}
} }
snippet stn snippet impl "Struct/Trait implementation"
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} { impl ${1:Type/Trait}${2: for ${3:Type}} {
${0}
}
snippet stn "Struct with new constructor"
pub struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0} ${0}
} }
impl $1 { impl $1 {
pub fn new(${2}) -> $1 { pub fn new(${2}) -> $1 {
${4}return $1 { $1 { ${3} };
${5}
};
} }
} }
snippet typ snippet type "Type alias"
type ${1:NewName} = $0; type ${1:NewName} = $2;
# Enum snippet enum "enum definition"
snippet enum
enum ${1:Name} { enum ${1:Name} {
${0}, ${2},
} }
# Impl # Traits
snippet imp snippet trait "Trait definition"
impl ${1:Name} { trait ${1:Name} {
${0} ${0}
} }
snippet drop snippet drop "Drop trait implementation (destructor)"
impl Drop for ${1:Name} { impl Drop for ${1:Name} {
fn drop(&mut self) { fn drop(&mut self) {
${0} ${0}
} }
} }
# Traits
snippet trait
trait ${1:Name} {
${0}
}
# Statics # Statics
snippet ss snippet ss "static string declaration"
static ${1}: &'static str = "${0}"; static ${1}: &'static str = "${0}";
snippet stat snippet stat "static item declaration"
static ${1}: ${2:usize} = ${0}; static ${1}: ${2:usize} = ${0};
# Concurrency
snippet scoped "spawn a scoped thread"
thread::scoped(${1:move }|| {
${0}
});
snippet spawn "spawn a thread"
thread::spawn(${1:move }|| {
${0}
});
snippet chan "Declare (Sender, Receiver) pair of asynchronous channel()"
let (${1:tx}, ${2:rx}): (Sender<${3:i32}>, Receiver<${4:i32}>) = channel();
# Testing
snippet as "assert!"
assert!(${1:predicate})
snippet ase "assert_eq!"
assert_eq!(${1:expected}, ${2:actual})

View File

@ -92,28 +92,3 @@ snippet fun
function ${1:function_name}() { function ${1:function_name}() {
${0:#function_body} ${0:#function_body}
} }
snippet funtitle
#=== FUNCTION ===============================================================
# NAME: ${1:function_name}
# DESCRIPTION: ${0:One line to give a brief description.}
#==============================================================================
snippet GPL2
#=== LICENSE ================================================================
# ${1:One line to give the program's name and a brief description.}
# Copyright (C) `strftime("%Y")` ${2:`g:snips_author`}
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
#==============================================================================

View File

@ -0,0 +1,127 @@
# if statement
snippet if
if (${1}) begin
${0}
end
# If/else statements
snippet ife
if (${1}) begin
${2}
end
else begin
${1}
end
# Else if statement
snippet eif
else if (${1}) begin
${0}
end
#Else statement
snippet el
else begin
${0}
end
# While statement
snippet wh
while (${1}) begin
${0}
end
# Repeat Loop
snippet rep
repeat (${1}) begin
${0}
end
# Foreach Loopo
snippet fe
foreach (${1}) begin
${0}
end
# Do-while statement
snippet dowh
do begin
${0}
end while (${1});
# Case statement
snippet case
case (${1})
{$2}: begin
${0}
end
default: begin
end
endcase
# CaseZ statement
snippet casez
casez (${1})
{$2}: begin
${0}
end
default: begin
end
endcase
# Combinational always block
snippet alc
always_comb begin ${1:: statement_label}
${0}
end $1
# Sequential logic
snippet alff
always_ff @(posedge ${1:clk}) begin ${2:: statement_label}
${0}
end $2
# Latched logic
snippet all
always_latch begin ${1:: statement_label}
${0}
end $1
# Module block
snippet mod
module ${1:module_name} (${2});
${0}
endmodule : $1
# Class
snippet cl
class ${1:class_name};
// data or class properties
${0}
// initialization
function new();
endfunction : new
endclass : $1
# Typedef structure
snippet types
typedef struct {
${0}
} ${1:name_t};
# Program block
snippet prog
program ${1:program_name} ();
${0}
endprogram : $1
# Interface block
snippet intf
interface ${1:program_name} ();
// nets
${0}
// clocking
// modports
endinterface : $1
# Clocking Block
snippet clock
clocking ${1:clocking_name} @(${2:posedge} ${3:clk});
${0}
endclocking : $1
# Covergroup construct
snippet cg
covergroup ${1:group_name} @(${2:posedge} ${3:clk});
${0}
endgroup : $1
# Package declaration
snippet pkg
package ${1:package_name};
${0}
endpackage : $1