Added grouping support for snippets (Issue 30)

This commit is contained in:
Zhang Chiyuan 2009-01-28 07:04:27 +00:00
parent 11f4a94680
commit 64e5027d10
82 changed files with 149 additions and 15 deletions

View File

@ -1,4 +1,5 @@
#contributor : Rodrigo Setti <rodrigosetti@gmail.com>
#name : <dd> ... </dd>
#group : list
# --
<dd>$1</dd>

View File

@ -1,5 +1,6 @@
#contributor : Rodrigo Setti <rodrigosetti@gmail.com>
#name : <dl> ... </dl>
#group : list
# --
<dl>
$0

View File

@ -1,5 +1,6 @@
#contributor : Rodrigo Setti <rodrigosetti@gmail.com>
#name : <dl> ... </dl>
#group : list
# --
<dl id="$1">
$0

View File

@ -1,3 +1,4 @@
#name : Doctype HTML 4.01 Strict
#group : meta
# --
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

View File

@ -1,3 +1,4 @@
#name : DocType XHTML 1.0 frameset
#group : meta
# --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">

View File

@ -1,3 +1,4 @@
#name : DocType XHTML 1.1
#group : meta
# --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

View File

@ -1,3 +1,4 @@
#name : DocType XHTML 1.0 Strict
#group : meta
# --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

View File

@ -1,3 +1,4 @@
#name : DocType XHTML 1.0 Transitional
#group : meta
# --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

View File

@ -1,4 +1,5 @@
#contributor : Rodrigo Setti <rodrigosetti@gmail.com>
#name : <dt> ... </dt>
#group : list
# --
<dt>$1</dt>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <h1>...</h1>
#group : header
# --
<h1>$1</h1>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <h2>...</h2>
#group : header
# --
<h2>$1</h2>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <h3>...</h3>
#group : header
# --
<h3>$1</h3>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <h4>...</h4>
#group : header
# --
<h4>$1</h4>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <h5>...</h5>
#group : header
# --
<h5>$1</h5>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <h6>...</h6>
#group : header
# --
<h6>$1</h6>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <li>...</li>
#group : list
# --
<li>$1</li>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <li class="...">...</li>
#group : list
# --
<li class="$1">$2</li>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#group : meta
#name : <meta name="..." content="..." />
# --
<meta name="${1:generator}" content="${2:content}" />

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <meta http-equiv="..." content="..." />
#group : meta
# --
<meta name="${1:Content-Type}" content="${2:text/html; charset=UTF-8}" />

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <ol>...</ol>
#group : list
# --
<ol>
$0

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <ol class="...">...</ol>
#group : list
# --
<ol class="$1">
$0

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <ol id="...">...</ol>
#group : list
# --
<ol id="$1">
$0

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <table ...>...</table>
#group : table
# --
<table width="$1" cellspacing="$2" cellpadding="$3" border="$4">
$0

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <td>...</td>
#group : table
# --
<td$1>$2</td>

View File

@ -1,4 +1,5 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <th>...</th>
#group : table
# --
<th$1>$2</th>

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <tr>...</tr>
#group : table
# --
<tr>
$0

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <ul>...</ul>
#group : list
# --
<ul>
$0

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <ul class="...">...</ul>
#group : list
# --
<ul class="$1">
$0

View File

@ -1,5 +1,6 @@
#contributor : Jimmy Wu <frozenthrone88@gmail.com>
#name : <ul id="...">...</ul>
#group : list
# --
<ul id="$1">
$0

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : DocType XHTML 1.1
#group : meta
# --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : DocType XHTML 1.0 Strict
#group : meta
# --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : DocType XHTML 1.0 Transitional
#group : meta
# --
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : <h1>...</h1>
#group : header
# --
<h1>$1</h1>

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : <h2>...</h2>
#group : header
# --
<h2>$1</h2>

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : <h3>...</h3>
#group : header
# --
<h3>$1</h3>

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : <h4>...</h4>
#group : header
# --
<h4>$1</h4>

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : <h5>...</h5>
#group : header
# --
<h5>$1</h5>

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : <h6>...</h6>
#group : header
# --
<h6>$1</h6>

View File

@ -1,4 +1,5 @@
#contributor : Anders Bach Nielsen <abachn@abachn.net>
#name : <meta name="..." content="..." />
#group : meta
# --
<meta name="${1:generator}" content="${2:content}" />

View File

@ -1,3 +1,4 @@
#name : # =>
#group : general
# --
# =>

View File

@ -1,3 +1,6 @@
#name : =begin rdoc ... =end
#group : general
# --
=begin rdoc
$0
=end

View File

@ -1,4 +1,5 @@
#name : include Comparable; def <=> ... end
#group : definitions
# --
include Comparable

View File

@ -1,3 +1,4 @@
#name : all? { |...| ... }
#group : collections
# --
all? { |${e}| $0 }

View File

@ -1,3 +1,4 @@
#name : alias_method new, old
#group : definitions
# --
alias_method :${new_name}, :${old_name}

View File

@ -1,3 +1,4 @@
#name : any? { |...| ... }
#group : collections
# --
any? { |${e}| $0 }

View File

@ -1,4 +1,5 @@
#name : if __FILE__ == $PROGRAM_NAME ... end
#group : general
# --
if __FILE__ == $PROGRAM_NAME
$0

View File

@ -1,4 +1,5 @@
#name : Benchmark.bmbm(...) do ... end
#group : general
# --
Benchmark.bmbm(${1:10}) do |x|
$0

View File

@ -1,4 +1,5 @@
#name : case ... end
#group : general
# --
case ${1:object}
when ${2:condition}

View File

@ -1,4 +1,5 @@
#name : class << self ... end
#group : definitions
# --
class << ${self}
$0

View File

@ -1,3 +1,4 @@
#name : classify { |...| ... }
#group : collections
# --
classify { |${e}| $0 }

View File

@ -1,5 +1,6 @@
#name : class ... end
#contributor : hitesh <hitesh.jasani@gmail.com>
#group : definitions
# --
class ${1:$
(let ((fn (capitalize (file-name-nondirectory

View File

@ -1,3 +1,4 @@
#name : collect { |...| ... }
#group : collections
# --
collect { |${e}| $0 }

View File

@ -1,3 +1,4 @@
#name : deep_copy(...)
#group : general
# --
Marshal.load(Marshal.dump($0))

View File

@ -1,3 +1,4 @@
#name : delete_if { |...| ... }
#group : collections
# --
delete_if { |${e} $0 }

View File

@ -1,3 +1,4 @@
#name : detect { |...| ... }
#group : collections
# --
detect { |${e}| $0 }

View File

@ -0,0 +1,6 @@
#name : downto(...) { |n| ... }
#group : control structure
# --
downto(${0}) { |${n}|
$0
}

View File

@ -1,3 +1,4 @@
#name : each { |...| ... }
#group : collections
# --
each { |${e}| $0 }

View File

@ -1,3 +1,4 @@
#name : each_cons(...) { |...| ... }
#group : collections
# --
each_cons(${1:2}) { |${group}| $0 }

View File

@ -1,3 +1,4 @@
#name : each_index { |i| ... }
#group : collections
# --
each_index { |${i}| $0 }

View File

@ -1,3 +1,4 @@
#name : each_value { |val| ... }
#group : collections
# --
each_value { |${val}| $0 }

View File

@ -1,3 +1,4 @@
#name : each_with_index { |e, i| ... }
#group : collections
# --
each_with_index { |${e}, ${i}| $0 }

View File

@ -1,4 +1,5 @@
#name : for ... in ...; ... end
#group : control structure
# --
for ${1:element} in ${2:collection}
$0

View File

@ -1,4 +1,5 @@
#name : if ... end
#group : control structure
# --
if ${1:condition}
$0

View File

@ -1,4 +1,5 @@
#name : if ... else ... end
#group : control structure
# --
if ${1:condition}
$2

View File

@ -1,3 +1,4 @@
#name : inject(...) { |...| ... }
#group : collections
# --
inject(${1:0}) { |${2:injection}, ${3:element}| $0 }

View File

@ -1,4 +1,5 @@
#name : def method_missing ... end
#group : definitions
# --
def method_missing(method, *args)
$0

View File

@ -1,3 +1,4 @@
#name : attr_reader ...
#group : definitions
# --
attr_reader :

View File

@ -1,3 +1,4 @@
#name : /usr/bin/ruby -wKU
#group : general
# --
#!/usr/bin/ruby -wKU

View File

@ -1,3 +1,4 @@
#name : reject { |...| ... }
#group : collections
# --
reject { |${1:element}| $0 }

View File

@ -1,3 +1,4 @@
#name : require "..."
#group : general
# --
require "$0"

View File

@ -1,3 +1,4 @@
#name : require File.join(File.dirname(__FILE__), ...)
#group : general
# --
require File.join(File.dirname(__FILE__), $0)

View File

@ -1,3 +1,4 @@
#name : attr_accessor ...
#group : definitions
# --
attr_accessor :

View File

@ -1,3 +1,4 @@
#name : select { |...| ... }
#group : collections
# --
select { |${1:element}| $0 }

View File

@ -0,0 +1,4 @@
#name : times { |n| ... }
#group : control structure
# --
times { |${n}| $0 }

View File

@ -0,0 +1,6 @@
#name : until ... end
#group: control structure
# --
until ${condition}
$0
end

View File

@ -0,0 +1,6 @@
#name : upto(...) { |n| ... }
#group : control structure
# --
upto(${n}) { |${i}|
$0
}

View File

@ -1,3 +1,4 @@
#name : attr_writer ...
#group : definitions
# --
attr_writer :

View File

@ -0,0 +1,6 @@
#name : when ... end
#group : control structure
# --
when ${condition}
$0
end

View File

@ -0,0 +1,6 @@
#name : while ... end
#group : control structure
# --
while ${condition}
$0
end

View File

@ -1,3 +1,4 @@
#name : :yields: arguments (rdoc)
#group : general
# --
:yields: $0

View File

@ -1,3 +1,4 @@
#name : zip(...) { |...| ... }
#group : collections
# --
zip(${enums}) { |${row}| $0 }

View File

@ -900,12 +900,14 @@ Here's a list of currently recognized variables:
* name
* contributor
* condition
* key
* group
#name: #include \"...\"
# --
#include \"$1\""
(goto-char (point-min))
(let ((name file-name) template bound condition key)
(let ((name file-name) template bound condition key group)
(if (re-search-forward "^# --\n" nil t)
(progn (setq template
(buffer-substring-no-properties (point)
@ -917,11 +919,13 @@ Here's a list of currently recognized variables:
(setq name (match-string-no-properties 2)))
(when (string= "condition" (match-string-no-properties 1))
(setq condition (read (match-string-no-properties 2))))
(when (string= "group" (match-string-no-properties 1))
(setq group (match-string-no-properties 2)))
(when (string= "key" (match-string-no-properties 1))
(setq key (match-string-no-properties 2)))))
(setq template
(buffer-substring-no-properties (point-min) (point-max))))
(list key template name condition)))
(list key template name condition group)))
(defun yas/directory-files (directory file?)
"Return directory files or subdirectories in full path."
@ -1074,15 +1078,19 @@ all the parameters:
(insert " ("
(yas/quote-string (car snippet))
" "
(yas/quote-string (cadr snippet))
(yas/quote-string (nth 1 snippet))
" "
(if (caddr snippet)
(yas/quote-string (caddr snippet))
(if (nth 2 snippet)
(yas/quote-string (nth 2 snippet))
"nil")
" "
(if (nth 3 snippet)
(format "'%s" (nth 3 snippet))
"nil")
" "
(if (nth 4 snippet)
(yas/quote-string (nth 4 snippet))
"nil")
")\n"))
(insert " )\n")
(insert (if parent
@ -1154,9 +1162,9 @@ content of the file is the template."
"Define snippets for MODE. SNIPPETS is a list of
snippet definition, of the following form:
(KEY TEMPLATE NAME CONDITION)
(KEY TEMPLATE NAME CONDITION GROUP)
or the NAME and CONDITION may be omitted. The optional 3rd
or the NAME, CONDITION or GROUP may be omitted. The optional 3rd
parameter can be used to specify the parent mode of MODE. That
is, when looking a snippet in MODE failed, it can refer to its
parent mode. The PARENT-MODE may not need to be a real mode."
@ -1181,9 +1189,10 @@ parent mode. The PARENT-MODE may not need to be a real mode."
(dolist (snippet snippets)
(let* ((full-key (car snippet))
(key (file-name-sans-extension full-key))
(name (or (caddr snippet) (file-name-extension full-key)))
(name (or (nth 2 snippet) (file-name-extension full-key)))
(condition (nth 3 snippet))
(template (yas/make-template (cadr snippet)
(group (nth 4 snippet))
(template (yas/make-template (nth 1 snippet)
(or name key)
condition)))
(yas/snippet-table-store snippet-table
@ -1191,10 +1200,24 @@ parent mode. The PARENT-MODE may not need to be a real mode."
key
template)
(when yas/use-menu
(define-key keymap (vector (make-symbol full-key))
`(menu-item ,(yas/template-name template)
,(yas/make-menu-binding (yas/template-content template))
:keys ,(concat key yas/trigger-symbol))))))))
(let ((group-keymap keymap))
(when (and (not (null group))
(not (string= "" group)))
(dolist (subgroup (mapcar #'make-symbol
(split-string group "\\.")))
(let ((subgroup-keymap (lookup-key group-keymap
(vector subgroup))))
(when (null subgroup-keymap)
(setq subgroup-keymap (make-sparse-keymap))
(define-key group-keymap (vector subgroup)
`(menu-item ,(symbol-name subgroup)
,subgroup-keymap)))
(setq group-keymap subgroup-keymap))))
(define-key group-keymap (vector (make-symbol full-key))
`(menu-item ,(yas/template-name template)
,(yas/make-menu-binding (yas/template-content
template))
:keys ,(concat key yas/trigger-symbol)))))))))
(defun yas/set-mode-parent (mode parent)
"Set parent mode of MODE to PARENT."
@ -1206,7 +1229,7 @@ parent mode. The PARENT-MODE may not need to be a real mode."
`(menu-item "parent mode"
,(yas/menu-keymap-for-mode parent)))))
(defun yas/define (mode key template &optional name condition)
(defun yas/define (mode key template &optional name condition group)
"Define a snippet. Expanding KEY into TEMPLATE.
NAME is a description to this template. Also update
the menu if `yas/use-menu' is `t'. CONDITION is the
@ -1214,7 +1237,7 @@ condition attached to this snippet. If you attach a
condition to a snippet, then it will only be expanded
when the condition evaluated to non-nil."
(yas/define-snippets mode
(list (list key template name condition))))
(list (list key template name condition group))))
(defun yas/hippie-try-expand (first-time?)