* Fixed the "direct-keymaps" bug with `emulation-mode-map-alists'

* Fixed a bug when evaluating primary field expressions

* Completed importation of TextMate HTML snippets, some TextMate HTML commands missing.
This commit is contained in:
capitaomorte 2009-11-04 15:51:43 +00:00
parent 73bad7366f
commit 477f7c99e4
30 changed files with 111 additions and 82 deletions

View File

@ -17,7 +17,7 @@
(setq word-begin (point)) (setq word-begin (point))
(forward-word 1) (forward-word 1)
(setq word-end (point))) (setq word-end (point)))
(when (and (> word-end word-begin) (when (and (< word-begin orig-point)
(>= word-end (point))) (>= word-end (point)))
(setq retval (setq retval
(cons (cons
@ -57,12 +57,19 @@
(defun yas/html-wrap-each-line-in-openclose-tag () (defun yas/html-wrap-each-line-in-openclose-tag ()
(let* ((mirror "${1:$(yas/html-first-word yas/text)}") (let* ((mirror "${1:$(yas/html-first-word yas/text)}")
(yas/html-wrap-newline (when (string-match "\n" yas/selected-text) "\n"))
(template (concat (format "<${1:%s}>" (or yas/html-default-tag "p")) (template (concat (format "<${1:%s}>" (or yas/html-default-tag "p"))
yas/selected-text yas/selected-text
"</" mirror ">"))) "</" mirror ">")))
(setq template (replace-regexp-in-string "\n" (concat "</" mirror ">\n<" mirror ">") template)) (setq template (replace-regexp-in-string "\n" (concat "</" mirror ">\n<$1>") template))
(yas/expand-snippet template))) (yas/expand-snippet template)))
(defun yas/html-wrap-selection-if-not-wrapped-already (wrapping)
(if (string-match (format "<%s>.*</%s>" wrapping wrapping) yas/selected-text)
(insert yas/selected-text)
(insert (format "<%s>%s</%s>" wrapping yas/selected-text wrapping))))
(defun yas/html-between-tag-pair-p () (defun yas/html-between-tag-pair-p ()
(save-excursion (save-excursion
(backward-word) (backward-word)

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: Internet Explorer 5.0 only # name: IE Conditional Comment: Internet Explorer 5.0 only
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if IE 5.0]>${1:${TM_SELECTED_TEXT: IE Conditional Comment: Internet Explorer 5.0 only }}<![endif]-->$0 <!--[if IE 5.0]>${1:`(or yas/selected-text " IE Conditional Comment: Internet Explorer 5.0 only ")`}<![endif]-->$0

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: Internet Explorer 5.5 only # name: IE Conditional Comment: Internet Explorer 5.5 only
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if IE 5.5000]>${1:${TM_SELECTED_TEXT: IE Conditional Comment: Internet Explorer 5.5 only }}<![endif]-->$0 <!--[if IE 5.5000]>${1:`(or yas/selected-text " IE Conditional Comment: Internet Explorer 5.5 only ")`}<![endif]-->$0

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: Internet Explorer 5.x # name: IE Conditional Comment: Internet Explorer 5.x
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if lt IE 6]>${1:${TM_SELECTED_TEXT: IE Conditional Comment: Internet Explorer 5.x }}<![endif]-->$0 <!--[if lt IE 6]>${1:`(or yas/selected-text " IE Conditional Comment: Internet Explorer 5.x ")`}<![endif]-->$0

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: Internet Explorer 6 and below # name: IE Conditional Comment: Internet Explorer 6 and below
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if lte IE 6]>${1:${TM_SELECTED_TEXT: IE Conditional Comment: Internet Explorer 6 and below }}<![endif]-->$0 <!--[if lte IE 6]>${1:`(or yas/selected-text " IE Conditional Comment: Internet Explorer 6 and below ")`}<![endif]-->$0

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: Internet Explorer 6 only # name: IE Conditional Comment: Internet Explorer 6 only
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if IE 6]>${1:${TM_SELECTED_TEXT: IE Conditional Comment: Internet Explorer 6 only }}<![endif]-->$0 <!--[if IE 6]>${1:`(or yas/selected-text " IE Conditional Comment: Internet Explorer 6 only ")`}<![endif]-->$0

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: Internet Explorer 7 and above # name: IE Conditional Comment: Internet Explorer 7 and above
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if gte IE 7]>${1:${TM_SELECTED_TEXT: IE Conditional Comment: Internet Explorer 7 and above }}<![endif]-->$0 <!--[if gte IE 7]>${1:`(or yas/selected-text " IE Conditional Comment: Internet Explorer 7 and above ")`}<![endif]-->$0

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: Internet Explorer # name: IE Conditional Comment: Internet Explorer
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if IE]>${1:${TM_SELECTED_TEXT: IE Conditional Comment: Internet Explorer }}<![endif]-->$0 <!--[if IE]>${1:`(or yas/selected-text " IE Conditional Comment: Internet Explorer ")`}<![endif]-->$0

View File

@ -4,4 +4,4 @@
# name: IE Conditional Comment: NOT Internet Explorer # name: IE Conditional Comment: NOT Internet Explorer
## condition: "text.html" ## condition: "text.html"
# -- # --
<!--[if !IE]><!-->${1:${TM_SELECTED_TEXT: IE Conditional Comment: NOT Internet Explorer }}<!-- <![endif]-->$0 <!--[if !IE]><!-->${1:`(or yas/selected-text " IE Conditional Comment: NOT Internet Explorer ")`}<!-- <![endif]-->$0

View File

@ -1,7 +1,8 @@
# -*- mode: snippet -*- # -*- mode: snippet -*-
# contributor: Translated from TextMate Snippet # contributor: Translated from TextMate Snippet
# name: Non-Breaking Space # name: Non-Breaking Space
## binding: "~ " # key: nbsp
## binding: " "
## condition: "text.html" ## condition: "text.html"
# -- # --
&nbsp; &nbsp;

View File

@ -1,7 +1,7 @@
# -*- mode: snippet -*- # -*- mode: snippet -*-
# contributor: Translated from TextMate Snippet # type: command
# name: Emphasize # name: Emphasize
# binding: "A-i" # binding: A-i
## condition: "text.html" ## condition: "text.html"
# -- # --
(yas/html-wrap-selection-if-not-wrapped-already "em") (yas/html-wrap-selection-if-not-wrapped-already "em")

View File

@ -1,8 +1,7 @@
# -*- mode: snippet -*- # -*- mode: snippet -*-
# type: command # type: command
# contributor: Translated from TextMate Snippet
# name: Strong # name: Strong
# binding: "A-b" # binding: A-b
## condition: "text.html" ## condition: "text.html"
# -- # --
(yas/html-wrap-selection-if-not-wrapped-already "strong") (yas/html-wrap-selection-if-not-wrapped-already "strong")

View File

@ -5,13 +5,13 @@
## condition: "text.html" ## condition: "text.html"
# -- # --
<object width="$2" height="$3" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab"> <object width="$2" height="$3" classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab">
<param name="src" value="$1"${TM_XHTML}> <param name="src" value="$1"`yas/html-xhtml-attr`>
<param name="controller" value="$4"${TM_XHTML}> <param name="controller" value="$4"`yas/html-xhtml-attr`>
<param name="autoplay" value="$5"${TM_XHTML}> <param name="autoplay" value="$5"`yas/html-xhtml-attr`>
<embed src="${1:movie.mov}" <embed src="${1:movie.mov}"
width="${2:320}" height="${3:240}" width="${2:320}" height="${3:240}"
controller="${4:true}" autoplay="${5:true}" controller="${4:true}" autoplay="${5:true}"
scale="tofit" cache="true" scale="tofit" cache="true"
pluginspage="http://www.apple.com/quicktime/download/" pluginspage="http://www.apple.com/quicktime/download/"`(when (and yas/html-xhtml-attr (not (string= "" yas/html-xhtml-attr)))
${TM_XHTML}> (concat "\n" yas/html-xhtml-attr))`>
</object> </object>

View File

@ -4,7 +4,7 @@
# name: Fieldset # name: Fieldset
## condition: "text.html" ## condition: "text.html"
# -- # --
<fieldset id="${1/[[:alpha:]]+|( )/(?1:_:\L$0)/g}" ${2:class="${3:}"}> <fieldset id="${1:$(yas/html-id-from-string yas/text)}" ${2:class="$3"}>
<legend>${1:`yas/selected-text`}</legend> <legend>${1:`yas/selected-text`}</legend>
$0 $0

View File

@ -4,4 +4,6 @@
# name: Input with Label # name: Input with Label
## condition: "text.html" ## condition: "text.html"
# -- # --
<label for="${2:${1/[[:alpha:]]+|( )/(?1:_:\L$0)/g}}">$1</label><input type="${3:text/submit/hidden/button}" name="${4:$2}" value="$5"${6: id="${7:$2}"}${TM_XHTML}> <label for="${2:id$(yas/get-field-once 1 #'yas/html-id-from-string)}">$1</label><input type="${3:$$(yas/choose-value '("text" "submit" "hidden" "button"))}" name="${4:name$(
yas/get-field-once 2)}" value="$5"${6: id="${7:id$(
yas/get-field-once 2)}"}`yas/html-xhtml-attr`>

View File

@ -4,4 +4,4 @@
# name: Option # name: Option
## condition: "text.html" ## condition: "text.html"
# -- # --
<option${1: value="${2:option}"}>${3:$2}</option> <option${1: value="${2:option}"}>${3:option$(unless yas/modified-p (yas/field-value 2))}</option>

View File

@ -4,8 +4,8 @@
# name: Select Box # name: Select Box
## condition: "text.html" ## condition: "text.html"
# -- # --
<select name="${1:some_name}" id="${2:$1}"${3:${4: multiple}${5: onchange="${6:}"}${7: size="${8:1}"}}> <select name="${1:some_name}" id="${2:id$(yas/get-field-once 1)}"${3:${4: multiple}${5: onchange="$6"}${7: size="${8:1}"}}>
<option${9: value="${10:option1}"}>${11:$10}</option> <option${9: value="${10:option1}"}>${11:$$(yas/get-field-once 10)}</option>
<option${12: value="${13:option2}"}>${14:$13}</option>${15:} <option${12: value="${13:option2}"}>${14:$$(yas/get-field-once 13)}</option>$15
$0 $0
</select> </select>

View File

@ -4,4 +4,4 @@
# name: Base # name: Base
## condition: "text.html" ## condition: "text.html"
# -- # --
<base href="$1"${2: target="$3"}${TM_XHTML}> <base href="$1"${2: target="$3"}`yas/html-xhtml-attr`>

View File

@ -4,6 +4,8 @@
# name: Body # name: Body
## condition: "text.html" ## condition: "text.html"
# -- # --
<body id="${1:${TM_FILENAME/(.*)\..*/\L$1/}}"${2: onload="$3"}> <body id="${1:`(or (and buffer-file-name
(downcase (file-name-sans-extension (file-name-nondirectory buffer-file-name))))
"some_id")`}"${2: onload="$3"}>
$0 $0
</body> </body>

View File

@ -1,7 +1,7 @@
# -*- mode: snippet -*- # -*- mode: snippet -*-
# contributor: Translated from TextMate Snippet # contributor: Translated from TextMate Snippet
# name: Br # name: Br
## binding: "^ " # binding: M-RET
## condition: "text.html" ## condition: "text.html"
# -- # --
<br${TM_XHTML}> <br`yas/html-xhtml-attr`>

View File

@ -4,8 +4,11 @@
# name: Form # name: Form
## condition: "text.html" ## condition: "text.html"
# -- # --
<form action="${1:${TM_FILENAME/(.*?)\..*/$1_submit/}}" method="${2:get}" accept-charset="utf-8"> <form action="${1:`(or (and buffer-file-name
(concat (file-name-sans-extension (file-name-nondirectory buffer-file-name))
"_submit"))
"some_action")`}" method="${2:get}" accept-charset="utf-8">
$0 $0
<p><input type="submit" value="Continue &rarr;"${TM_XHTML}></p> <p><input type="submit" value="Continue &rarr;"`yas/html-xhtml-attr`></p>
</form> </form>

View File

@ -4,4 +4,4 @@
# name: Heading # name: Heading
## condition: "text.html" ## condition: "text.html"
# -- # --
<h1 id="${1/[[:alpha:]]+|( )/(?1:_:\L$0)/g}">${1:`yas/selected-text`}</h1> <h1 id="${1:$(yas/html-id-from-string yas/text)}">${1:`yas/selected-text`}</h1>

View File

@ -5,7 +5,9 @@
## condition: "text.html - text.html source" ## condition: "text.html - text.html source"
# -- # --
<head> <head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8"${TM_XHTML}> <meta http-equiv="Content-type" content="text/html; charset=utf-8"`yas/html-xhtml-attr`>
<title>${1:${TM_FILENAME/((.+)\..*)?/(?2:$2:Page Title)/}}</title> <title>${1:`(or (and buffer-file-name
(file-name-sans-extension (file-name-nondirectory buffer-file-name)))
"Page Title")`}</title>
$0 $0
</head> </head>

View File

@ -1,7 +1,6 @@
# -*- mode: snippet -*- # -*- mode: snippet -*-
# key: input # key: input
# contributor: Translated from TextMate Snippet
# name: Input # name: Input
## condition: "text.html" ## condition: "text.html"
# -- # --
<input type="${1:text/submit/hidden/button}" name="${2:some_name}" value="$3"${4: id="${5:$2}"}${TM_XHTML}> <input type="${1:$$(yas/choose-value '("text" "submit" "hidden" "button"))}" name="${2:some_name}" value="$3"${4: id="${5:$$(yas/get-field-once 2)}"}`yas/html-xhtml-attr`>

View File

@ -4,4 +4,4 @@
# name: Link # name: Link
## condition: "text.html" ## condition: "text.html"
# -- # --
<link rel="${1:stylesheet}" href="${2:/css/master.css}" type="text/css" media="${3:screen}" title="${4:no title}" charset="${5:utf-8}"${TM_XHTML}> <link rel="${1:stylesheet}" href="${2:/css/master.css}" type="text/css" media="${3:screen}" title="${4:no title}" charset="${5:utf-8}"`yas/html-xhtml-attr`>

View File

@ -4,4 +4,4 @@
# name: Meta # name: Meta
## condition: "text.html" ## condition: "text.html"
# -- # --
<meta name="${1:name}" content="${2:content}"${TM_XHTML}> <meta name="${1:name}" content="${2:content}"`yas/html-xhtml-attr`>

View File

@ -4,4 +4,6 @@
# name: Title # name: Title
## condition: "text.html - text.blog" ## condition: "text.html - text.blog"
# -- # --
<title>${1:${TM_FILENAME/((.+)\..*)?/(?2:$2:Page Title)/}}</title> <title>${1:`(or (and buffer-file-name
(file-name-sans-extension (file-name-nondirectory buffer-file-name)))
"Page Title")`}</title>

View File

@ -1,7 +1,7 @@
# -*- mode: snippet -*- # -*- mode: snippet -*-
# contributor: Translated from TextMate Snippet # contributor: Translated from TextMate Snippet
# name: Special: Return Inside Empty Open/Close Tags # name: Special: Return Inside Empty Open/Close Tags
# binding: "C-M" # binding: RET
# condition: (yas/html-between-tag-pair-p) # condition: (yas/html-between-tag-pair-p)
# -- # --

View File

@ -1,7 +1,8 @@
# -*- mode: snippet -*- # -*- mode: snippet -*-
# contributor: joaotavora, adapted from TextMate HTML bundle # contributor: joaotavora, adapted from TextMate HTML bundle
# name: Wrap Selection in Open/Close Tag # name: Wrap Selection in Open/Close Tag
# binding: "C-S-w" # binding: C-S-w
# condition: mark-active # condition: mark-active
# expand-env: ((yas/html-wrap-newline (when (string-match "\n" yas/selected-text) "\n")))
# -- # --
<${1:p}>`yas/selected-text`</${1:$(yas/html-first-word yas/text)}> <${1:p}>`(concat yas/html-wrap-newline yas/selected-text yas/html-wrap-newline)`</${1:$(yas/html-first-word yas/text)}>

View File

@ -710,7 +710,7 @@ With optional UNBIND-KEY, try to unbind that key from
(defvar yas/snippet-tables (make-hash-table) (defvar yas/snippet-tables (make-hash-table)
"A hash table of MAJOR-MODE symbols to `yas/snippet-table' objects.") "A hash table of MAJOR-MODE symbols to `yas/snippet-table' objects.")
(defvar yas/snippet-keymaps nil (defvar yas/direct-keymaps (list)
"Keymap alist supporting direct snippet keybindings. "Keymap alist supporting direct snippet keybindings.
This variable is is placed `emulation-mode-map-alists'. This variable is is placed `emulation-mode-map-alists'.
@ -721,17 +721,28 @@ set buffer-locally when entering `yas/minor-mode'. KEYMAP binds
all defined direct keybindings to the command all defined direct keybindings to the command
`yas/expand-from-keymap', which acts similarly to `yas/expand'") `yas/expand-from-keymap', which acts similarly to `yas/expand'")
(defun yas/snippet-keymaps-reload () (defun yas/direct-keymaps-reload ()
"Force reload the direct keybinding for active snippet tables."
(interactive) (interactive)
(setq yas/snippet-keymaps nil) (setq yas/direct-keymaps nil)
(maphash #'(lambda (name table) (maphash #'(lambda (name table)
(mapc #'(lambda (table) (mapc #'(lambda (table)
(push (cons name (push (cons (intern (format "yas//direct-%s" name))
(yas/snippet-table-keymap table)) (yas/snippet-table-direct-keymap table))
yas/snippet-keymaps)) yas/direct-keymaps))
(cons table (yas/snippet-table-get-all-parents table)))) (cons table (yas/snippet-table-get-all-parents table))))
yas/snippet-tables)) yas/snippet-tables))
(defun yas/direct-keymaps-set-vars ()
(let ((modes-to-activate (list major-mode))
(mode major-mode))
(while (setq mode (get mode 'derived-mode-parent))
(push mode modes-to-activate))
(dolist (mode modes-to-activate)
(let ((name (intern (format "yas//direct-%s" mode))))
(set-default name nil)
(set (make-local-variable name) t)))))
;;;###autoload ;;;###autoload
(define-minor-mode yas/minor-mode (define-minor-mode yas/minor-mode
"Toggle YASnippet mode. "Toggle YASnippet mode.
@ -764,26 +775,19 @@ Key bindings:
;; Install the direct keymaps in `emulation-mode-map-alists' ;; Install the direct keymaps in `emulation-mode-map-alists'
;; (we use `add-hook' even though it's not technically a hook, ;; (we use `add-hook' even though it's not technically a hook,
;; but it works). Then define variables named after modes to ;; but it works). Then define variables named after modes to
;; index `yas/snippet-keymaps'. ;; index `yas/direct-keymaps'.
;; ;;
;; FIXME: this is quite wrong and breaks cua-mode for ;; FIXME: this is quite wrong and breaks cua-mode for
;; example. It is either `yas/snippet-keymaps' that needs to ;; example. It is either `yas/direct-keymaps' that needs to
;; have a buffer-local value, or those little indicator vars ;; have a buffer-local value, or those little indicator vars
;; need to be set and unset buffer-locally (preferred). ;; need to be set and unset buffer-locally (preferred).
;; ;;
(add-hook 'emulation-mode-map-alists 'yas/snippet-keymaps nil 'local) (add-hook 'emulation-mode-map-alists 'yas/direct-keymaps)
(let ((modes-to-activate (list major-mode)) (yas/direct-keymaps-set-vars))
(mode major-mode))
(while (setq mode (get mode 'derived-mode-parent))
(push mode modes-to-activate))
(dolist (mode modes-to-activate)
(unless (and (boundp mode)
(symbol-value mode))
(set (make-local-variable mode) t)))))
(t (t
;; Uninstall the direct keymaps. ;; Uninstall the direct keymaps.
;; ;;
(remove-hook 'emulation-mode-map-alists 'yas/snippet-keymaps 'local)))) (remove-hook 'emulation-mode-map-alists 'yas/direct-keymaps))))
(defvar yas/dont-activate #'(lambda () (defvar yas/dont-activate #'(lambda ()
(and yas/root-directory (and yas/root-directory
@ -892,7 +896,7 @@ Has the following fields:
A hash table, known as the \"keyhash\" where key is a string or A hash table, known as the \"keyhash\" where key is a string or
a vector. In case of a string its the snippet trigger key, a vector. In case of a string its the snippet trigger key,
whereas a vector means its a direct keybinding. The value is whereas a vector means it's a direct keybinding. The value is
yet another hash of (NAME . TEMPLATE), known as the yet another hash of (NAME . TEMPLATE), known as the
\"namehash\", where NAME is the snippet name and TEMPLATE is a \"namehash\", where NAME is the snippet name and TEMPLATE is a
`yas/template' object. `yas/template' object.
@ -902,7 +906,7 @@ Has the following fields:
A list of tables considered parents of this table: i.e. when A list of tables considered parents of this table: i.e. when
searching for expansions they are searched as well. searching for expansions they are searched as well.
`yas/snippet-keymap' `yas/snippet-table-direct-keymap'
A keymap for the snippets in this table that have direct A keymap for the snippets in this table that have direct
keybindings. This is kept in sync with the keyhash, i.e., all keybindings. This is kept in sync with the keyhash, i.e., all
@ -912,7 +916,7 @@ Has the following fields:
name name
(hash (make-hash-table :test 'equal)) (hash (make-hash-table :test 'equal))
(parents nil) (parents nil)
(keymap (make-sparse-keymap))) (direct-keymap (make-sparse-keymap)))
;; Apropos storing/updating, this is works with two steps: ;; Apropos storing/updating, this is works with two steps:
;; ;;
@ -968,7 +972,7 @@ Has the following fields:
(when (= 0 (hash-table-count (cdr elem))) (when (= 0 (hash-table-count (cdr elem)))
(remhash (car elem) (yas/snippet-table-hash table)) (remhash (car elem) (yas/snippet-table-hash table))
(when (vectorp (car elem)) (when (vectorp (car elem))
(define-key (yas/snippet-table-keymap table) (car elem) nil)))))) (define-key (yas/snippet-table-direct-keymap table) (car elem) nil))))))
(defun yas/add-snippet (table name key template) (defun yas/add-snippet (table name key template)
"Store in TABLE the snippet NAME indexed by KEY and expanding TEMPLATE. "Store in TABLE the snippet NAME indexed by KEY and expanding TEMPLATE.
@ -987,7 +991,7 @@ keybinding)."
(make-hash-table :test 'equal) (make-hash-table :test 'equal)
(yas/snippet-table-hash table)))) (yas/snippet-table-hash table))))
(when (vectorp key) (when (vectorp key)
(define-key (yas/snippet-table-keymap table) key 'yas/expand-from-keymap)))) (define-key (yas/snippet-table-direct-keymap table) key 'yas/expand-from-keymap))))
(defun yas/fetch (table key) (defun yas/fetch (table key)
"Fetch snippets in TABLE by KEY. " "Fetch snippets in TABLE by KEY. "
@ -1053,13 +1057,7 @@ conditions to filter out potential expansions."
(let* ((requirement (or requirement (let* ((requirement (or requirement
(yas/require-template-specific-condition-p))) (yas/require-template-specific-condition-p)))
(result (or (null condition) (result (or (null condition)
(yas/eval-condition (yas/eval-condition condition))))
(condition-case err
(read condition)
(error (progn
(message (format "[yas] error reading condition: %s"
(error-message-string err))))
nil))))))
(cond ((eq requirement t) (cond ((eq requirement t)
result) result)
(t (t
@ -1182,7 +1180,9 @@ already have such a property."
yas/snippet-tables))) yas/snippet-tables)))
(unless table (unless table
(setq table (yas/make-snippet-table (symbol-name mode))) (setq table (yas/make-snippet-table (symbol-name mode)))
(puthash mode table yas/snippet-tables)) (puthash mode table yas/snippet-tables)
(aput 'yas/direct-keymaps (intern (format "yas//direct-%s" mode))
(yas/snippet-table-direct-keymap table)))
table)) table))
(defun yas/get-snippet-tables (&optional mode-symbol dont-search-parents) (defun yas/get-snippet-tables (&optional mode-symbol dont-search-parents)
@ -1284,7 +1284,7 @@ Here's a list of currently recognized variables:
(when (string= "name" (match-string-no-properties 1)) (when (string= "name" (match-string-no-properties 1))
(setq name (match-string-no-properties 2))) (setq name (match-string-no-properties 2)))
(when (string= "condition" (match-string-no-properties 1)) (when (string= "condition" (match-string-no-properties 1))
(setq condition (match-string-no-properties 2))) (setq condition (yas/read-lisp (match-string-no-properties 2))))
(when (string= "group" (match-string-no-properties 1)) (when (string= "group" (match-string-no-properties 1))
(setq group (match-string-no-properties 2))) (setq group (match-string-no-properties 2)))
(when (string= "expand-env" (match-string-no-properties 1)) (when (string= "expand-env" (match-string-no-properties 1))
@ -1556,7 +1556,7 @@ content of the file is the template."
(call-interactively 'yas/load-directory)) (call-interactively 'yas/load-directory))
;; Reload the direct keybindings ;; Reload the direct keybindings
;; ;;
(yas/snippet-keymaps-reload) (yas/direct-keymaps-reload)
;; Restore the mode configuration ;; Restore the mode configuration
;; ;;
(when restore-minor-mode (when restore-minor-mode
@ -1669,7 +1669,12 @@ Here's the default value for all the parameters:
(insert "\n\n")))) (insert "\n\n"))))
(dolist (dir dirs) (dolist (dir dirs)
(dolist (subdir (yas/subdirs dir)) (dolist (subdir (yas/subdirs dir))
(yas/load-directory-1 subdir nil 'no-hierarchy-parents)))) (yas/load-directory-1 subdir nil 'no-hierarchy-parents)
(let ((file (concat subdir "/.yas-setup.el")))
(when (file-readable-p file)
(insert ";; Supporting elisp for subdir " (file-name-nondirectory subdir) "\n\n")
(goto-char (+ (point)
(second (insert-file-contents file)))))))))
(insert (pp-to-string `(yas/global-mode 1))) (insert (pp-to-string `(yas/global-mode 1)))
(insert ")\n\n" code "\n") (insert ")\n\n" code "\n")
@ -1930,7 +1935,7 @@ object satisfying `yas/field-p' to restrict the expansion to."
(yas/fallback 'trigger-key)))) (yas/fallback 'trigger-key))))
(defun yas/expand-from-keymap () (defun yas/expand-from-keymap ()
"Directly expand some snippets, searching `yas/snippet-keymaps'. "Directly expand some snippets, searching `yas/direct-keymaps'.
If expansion fails, execute the previous binding for this key" If expansion fails, execute the previous binding for this key"
(interactive) (interactive)
@ -1968,7 +1973,7 @@ Common gateway for `yas/expand-from-trigger-key' and
nil) nil)
((eq yas/fallback-behavior 'call-other-command) ((eq yas/fallback-behavior 'call-other-command)
(let* ((yas/minor-mode nil) (let* ((yas/minor-mode nil)
(yas/snippet-keymaps nil) (yas/direct-keymaps nil)
(keys-1 (this-command-keys-vector)) (keys-1 (this-command-keys-vector))
(keys-2 (and yas/trigger-key (keys-2 (and yas/trigger-key
from-trigger-key-p from-trigger-key-p
@ -2172,7 +2177,7 @@ lurking."
# -*- mode: snippet -*- # -*- mode: snippet -*-
# name: %s # name: %s
# key: $1${2: # key: $1${2:
# binding: \"${3:keybinding}\"}${4: # binding: \"${3:direct-keybinding}\"}${4:
# expand-env: ((${5:some-var} ${6:some-value}))} # expand-env: ((${5:some-var} ${6:some-value}))}
# -- # --
$0" name)))) $0" name))))
@ -2373,6 +2378,12 @@ Otherwise throw exception."
(when field (when field
(yas/field-text-for-display field)))) (yas/field-text-for-display field))))
(defun yas/get-field-once (number &optional transform-fn)
(unless yas/modified-p
(if transform-fn
(funcall transform-fn yas/field-value number)
(yas/field-value number))))
(defun yas/default-from-field (number) (defun yas/default-from-field (number)
(unless yas/modified-p (unless yas/modified-p
(yas/field-value number))) (yas/field-value number)))
@ -3451,7 +3462,7 @@ When multiple expressions are found, only the last one counts."
(let ((lisp-expression-string (buffer-substring-no-properties (match-beginning 1) (let ((lisp-expression-string (buffer-substring-no-properties (match-beginning 1)
real-match-end-1))) real-match-end-1)))
(setf (yas/field-transform parent-field) (setf (yas/field-transform parent-field)
(yas/restore-escapes (yas/read-lisp lisp-expression-string)))) (yas/read-lisp (yas/restore-escapes lisp-expression-string))))
(push (cons (match-beginning 0) real-match-end-1) (push (cons (match-beginning 0) real-match-end-1)
yas/dollar-regions))))))) yas/dollar-regions)))))))
@ -3623,7 +3634,7 @@ object satisfying `yas/field-p' to restrict the expansion to.")))
(templates (mapcan #'(lambda (table) (templates (mapcan #'(lambda (table)
(yas/fetch table vec)) (yas/fetch table vec))
(yas/get-snippet-tables))) (yas/get-snippet-tables)))
(yas/snippet-keymaps nil) (yas/direct-keymaps nil)
(fallback (key-binding vec))) (fallback (key-binding vec)))
(concat "In this particular case\nmy guess is it would " (concat "In this particular case\nmy guess is it would "
(when templates (when templates