Merge pull request #1 from honza/master

pull from master
This commit is contained in:
Gert 2015-03-24 11:47:10 +01:00
commit eef619e313
16 changed files with 347 additions and 86 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.
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)
* HTML Django - [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
`!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)
snip.rv = box[0]
snip += box[1]

View File

@ -1,3 +0,0 @@
priority -50
extends html

View File

@ -0,0 +1,33 @@
priority -50
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
snippet funch "HTTP handler" b
func ${1:handler}(${2:w} http.ResponseWriter, ${3:r} *http.Request) {
${0:${VISUAL}}
}
endsnippet
# types and variables
snippet map "Map type" b
map[${1:keytype}]${2:valtype}
@ -135,3 +141,10 @@ snippet json "JSON field"
endsnippet
# 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>
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>"
<head>
<meta charset="utf-8">

View File

@ -29,5 +29,5 @@ snippet textarea
endsnippet
snippet img
<img src="$1"${2: alt="$3"}/>
<img src="$1"${2: alt="$3"}/>
endsnippet

View File

@ -4,12 +4,34 @@
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} {
${VISUAL}${0}
}
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
print!("${1}"${2/..*/, /}${2});
endsnippet
@ -30,7 +52,7 @@ macro_rules! ${1:name} (
)
endsnippet
snippet mod "A module" b
snippet mod "A module" b
mod ${1:`!p snip.rv = snip.basename.lower() or "name"`} {
${VISUAL}${0}
}
@ -52,18 +74,27 @@ struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
}
endsnippet
# TODO: fancy dynamic field mirroring like Python slotclass
snippet stn "Struct with new constructor." b
pub struct ${1:`!p snip.rv = snip.basename.title() or "Name"`} {
${3}
fd${0}
}
impl $1 {
pub fn new(${2}) -> $1 {
${4}return $1 {
${5}
};
$1 { ${3} };
}
}
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:

View File

@ -1,6 +1,23 @@
snippet %
<% ${0} %>
snippet =
<%= ${1} %>
<%= ${0} %>
snippet 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" />
snippet link:touch
<link rel="apple-touch-icon" href="${1:favicon.png}" />
snippet main
<main role="main">
${0}
</main>
snippet map
<map name="${1}">
${0}

View File

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

View File

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

View File

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

View File

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

View File

@ -3,11 +3,11 @@
#################
# Functions
snippet fn
snippet fn "Function definition"
fn ${1:function_name}(${2})${3} {
${0}
}
snippet test
snippet test "Unit test function"
#[test]
fn ${1:test_function_name}() {
${0}
@ -19,32 +19,51 @@ snippet bench "Bench function" b
${0}
})
}
snippet new
snippet new "Constructor function"
pub fn new(${2}) -> ${1:Name} {
${0}return $1 { ${3} };
$1 { ${3} };
}
snippet main
snippet main "Main function"
pub fn main() {
${0}
}
snippet let
let ${1:name: type} = ${2};
snippet let
let mut ${1:name: type} = ${2};
snippet pln
snippet let "let variable declaration"
let ${1:name}${2:: ${3:type}} = ${4};
snippet letm "let mut variable declaration"
let mut ${1:name}${2:: ${3:type}} = ${4};
snippet pln "println!"
println!("${1}");
snippet pln,
snippet pln, "println! with format param"
println!("${1}", ${2});
snippet ec
# Modules
snippet ec "extern crate"
extern crate ${1:sync};
snippet ecl
#![feature(phase)]
#[phase(plugin, link)] extern crate log;
snippet ecl "extern crate log"
#[macro_use]
extern crate log;
snippet mod
mod ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0}
} /* $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 = "${1:crate_name}"]
// Additional metadata attributes
@ -53,110 +72,107 @@ snippet crate
#![comment = "${4:Comment.}"]
// Specify the output type
#![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
snippet opt
Option<${1:int}>
snippet res
snippet opt "Option<T>"
Option<${1:i32}>
snippet res "Result<T, E>"
Result<${1:~str}, ${2:()}>
# Control structures
snippet if
if ${1} {
${0}
}
snippet ife
snippet ife "if / else"
if ${1} {
${2}
} else {
${0}
}
snippet el
snippet el "else"
else {
${0}
}
snippet eli
snippet eli "else if"
else if ${1} {
${0}
}
snippet mat
snippet mat "match pattern"
match ${1} {
${2} => ${3},
${2} => ${3}
}
snippet case "Case clause of pattern match"
${1:_} => ${2:expression}
snippet loop "loop {}" b
loop {
${0}
}
snippet while
snippet while "while loop"
while ${1:condition} {
${0}
}
snippet for
snippet for "for ... in ... loop"
for ${1:i} in ${2:0u..10} {
${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
snippet todo
snippet todo "TODO comment"
// [TODO]: ${0:Description}
snippet fixme "FIXME comment"
// FIXME: $0
# Struct
snippet st
snippet st "Struct definition"
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0}
}
snippet stn
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
snippet impl "Struct/Trait implementation"
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}
}
impl $1 {
pub fn new(${2}) -> $1 {
${4}return $1 {
${5}
};
$1 { ${3} };
}
}
snippet typ
type ${1:NewName} = $0;
# Enum
snippet enum
snippet type "Type alias"
type ${1:NewName} = $2;
snippet enum "enum definition"
enum ${1:Name} {
${0},
${2},
}
# Impl
snippet imp
impl ${1:Name} {
# Traits
snippet trait "Trait definition"
trait ${1:Name} {
${0}
}
snippet drop
snippet drop "Drop trait implementation (destructor)"
impl Drop for ${1:Name} {
fn drop(&mut self) {
${0}
}
}
# Traits
snippet trait
trait ${1:Name} {
${0}
}
# Statics
snippet ss
snippet ss "static string declaration"
static ${1}: &'static str = "${0}";
snippet stat
snippet stat "static item declaration"
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

@ -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