From 477f7c99e458f088035ab9e6a48af854d5460059 Mon Sep 17 00:00:00 2001 From: capitaomorte Date: Wed, 4 Nov 2009 15:51:43 +0000 Subject: [PATCH] * 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. --- extras/imported/html-mode/.yas-setup.el | 11 ++- ...mment Internet Explorer 5_0 only.yasnippet | 2 +- ...mment Internet Explorer 5_5 only.yasnippet | 2 +- ...al Comment Internet Explorer 5_x.yasnippet | 2 +- ...nt Internet Explorer 6 and below.yasnippet | 2 +- ...Comment Internet Explorer 6 only.yasnippet | 2 +- ...nal Comment Internet Explorer 7+.yasnippet | 2 +- ...tional Comment Internet Explorer.yasnippet | 2 +- ...al Comment NOT Internet Explorer.yasnippet | 2 +- .../XHTML   NonBreakingSpace.yasnippet | 3 +- .../html-mode/Format/Emphasize.yasnippet | 4 +- .../html-mode/Format/Strong.yasnippet | 3 +- .../Embed QT movie (movie).yasnippet | 10 +-- .../html-mode/Insert Tag/Fieldset.yasnippet | 2 +- .../Insert Tag/Input with Label.yasnippet | 4 +- .../html-mode/Insert Tag/Option.yasnippet | 2 +- .../html-mode/Insert Tag/Select Box.yasnippet | 6 +- .../html-mode/Insert Tag/XHTML base.yasnippet | 2 +- .../html-mode/Insert Tag/XHTML body.yasnippet | 4 +- .../html-mode/Insert Tag/XHTML br.yasnippet | 4 +- .../html-mode/Insert Tag/XHTML form.yasnippet | 7 +- .../html-mode/Insert Tag/XHTML h1.yasnippet | 2 +- .../html-mode/Insert Tag/XHTML head.yasnippet | 6 +- .../Insert Tag/XHTML input.yasnippet | 3 +- .../html-mode/Insert Tag/XHTML link.yasnippet | 2 +- .../html-mode/Insert Tag/XHTML meta.yasnippet | 2 +- .../Insert Tag/XHTML title.yasnippet | 4 +- ...Smart returnindent for tag pairs.yasnippet | 2 +- .../html-mode/Wrap Selection In Tag.yasnippet | 5 +- yasnippet.el | 89 +++++++++++-------- 30 files changed, 111 insertions(+), 82 deletions(-) diff --git a/extras/imported/html-mode/.yas-setup.el b/extras/imported/html-mode/.yas-setup.el index 69d49c9..37ca4ba 100644 --- a/extras/imported/html-mode/.yas-setup.el +++ b/extras/imported/html-mode/.yas-setup.el @@ -17,7 +17,7 @@ (setq word-begin (point)) (forward-word 1) (setq word-end (point))) - (when (and (> word-end word-begin) + (when (and (< word-begin orig-point) (>= word-end (point))) (setq retval (cons @@ -57,12 +57,19 @@ (defun yas/html-wrap-each-line-in-openclose-tag () (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")) yas/selected-text ""))) - (setq template (replace-regexp-in-string "\n" (concat "\n<" mirror ">") template)) + (setq template (replace-regexp-in-string "\n" (concat "\n<$1>") template)) (yas/expand-snippet template))) +(defun yas/html-wrap-selection-if-not-wrapped-already (wrapping) + (if (string-match (format "<%s>.*" wrapping wrapping) yas/selected-text) + (insert yas/selected-text) + (insert (format "<%s>%s" wrapping yas/selected-text wrapping)))) + + (defun yas/html-between-tag-pair-p () (save-excursion (backward-word) diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_0 only.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_0 only.yasnippet index 8bd737b..5536009 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_0 only.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_0 only.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: Internet Explorer 5.0 only ## condition: "text.html" # -- -$0 \ No newline at end of file +$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_5 only.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_5 only.yasnippet index a5afa6e..d740f16 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_5 only.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_5 only.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: Internet Explorer 5.5 only ## condition: "text.html" # -- -$0 \ No newline at end of file +$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_x.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_x.yasnippet index 17e31d6..272c442 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_x.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 5_x.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: Internet Explorer 5.x ## condition: "text.html" # -- -$0 \ No newline at end of file +$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 and below.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 and below.yasnippet index 23dd74e..594d847 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 and below.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 and below.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: Internet Explorer 6 and below ## condition: "text.html" # -- -$0 \ No newline at end of file +$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 only.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 only.yasnippet index b35dff4..c28d7b7 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 only.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 6 only.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: Internet Explorer 6 only ## condition: "text.html" # -- -$0 \ No newline at end of file +$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 7+.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 7+.yasnippet index 2e82875..c762c27 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 7+.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer 7+.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: Internet Explorer 7 and above ## condition: "text.html" # -- -$0 \ No newline at end of file +$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer.yasnippet index dcb89cd..00ef361 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment Internet Explorer.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: Internet Explorer ## condition: "text.html" # -- -$0 \ No newline at end of file +$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment NOT Internet Explorer.yasnippet b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment NOT Internet Explorer.yasnippet index fc12208..01de4a0 100644 --- a/extras/imported/html-mode/Conditional Comments/IE Conditional Comment NOT Internet Explorer.yasnippet +++ b/extras/imported/html-mode/Conditional Comments/IE Conditional Comment NOT Internet Explorer.yasnippet @@ -4,4 +4,4 @@ # name: IE Conditional Comment: NOT Internet Explorer ## condition: "text.html" # -- -${1:${TM_SELECTED_TEXT: IE Conditional Comment: NOT Internet Explorer }}$0 \ No newline at end of file +${1:`(or yas/selected-text " IE Conditional Comment: NOT Internet Explorer ")`}$0 \ No newline at end of file diff --git a/extras/imported/html-mode/Entities/XHTML   NonBreakingSpace.yasnippet b/extras/imported/html-mode/Entities/XHTML   NonBreakingSpace.yasnippet index d331dff..0f971dd 100644 --- a/extras/imported/html-mode/Entities/XHTML   NonBreakingSpace.yasnippet +++ b/extras/imported/html-mode/Entities/XHTML   NonBreakingSpace.yasnippet @@ -1,7 +1,8 @@ # -*- mode: snippet -*- # contributor: Translated from TextMate Snippet # name: Non-Breaking Space -## binding: "~ " +# key: nbsp +## binding: " " ## condition: "text.html" # --   \ No newline at end of file diff --git a/extras/imported/html-mode/Format/Emphasize.yasnippet b/extras/imported/html-mode/Format/Emphasize.yasnippet index a32a4b7..f52d864 100644 --- a/extras/imported/html-mode/Format/Emphasize.yasnippet +++ b/extras/imported/html-mode/Format/Emphasize.yasnippet @@ -1,7 +1,7 @@ # -*- mode: snippet -*- -# contributor: Translated from TextMate Snippet +# type: command # name: Emphasize -# binding: "A-i" +# binding: A-i ## condition: "text.html" # -- (yas/html-wrap-selection-if-not-wrapped-already "em") diff --git a/extras/imported/html-mode/Format/Strong.yasnippet b/extras/imported/html-mode/Format/Strong.yasnippet index 1811554..0fa9fdc 100644 --- a/extras/imported/html-mode/Format/Strong.yasnippet +++ b/extras/imported/html-mode/Format/Strong.yasnippet @@ -1,8 +1,7 @@ # -*- mode: snippet -*- # type: command -# contributor: Translated from TextMate Snippet # name: Strong -# binding: "A-b" +# binding: A-b ## condition: "text.html" # -- (yas/html-wrap-selection-if-not-wrapped-already "strong") diff --git a/extras/imported/html-mode/Insert Tag/Embed QT movie (movie).yasnippet b/extras/imported/html-mode/Insert Tag/Embed QT movie (movie).yasnippet index b717869..e906c01 100644 --- a/extras/imported/html-mode/Insert Tag/Embed QT movie (movie).yasnippet +++ b/extras/imported/html-mode/Insert Tag/Embed QT movie (movie).yasnippet @@ -5,13 +5,13 @@ ## condition: "text.html" # -- - - - + + + + pluginspage="http://www.apple.com/quicktime/download/"`(when (and yas/html-xhtml-attr (not (string= "" yas/html-xhtml-attr))) + (concat "\n" yas/html-xhtml-attr))`> \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/Fieldset.yasnippet b/extras/imported/html-mode/Insert Tag/Fieldset.yasnippet index fb35442..eaedcb9 100644 --- a/extras/imported/html-mode/Insert Tag/Fieldset.yasnippet +++ b/extras/imported/html-mode/Insert Tag/Fieldset.yasnippet @@ -4,7 +4,7 @@ # name: Fieldset ## condition: "text.html" # -- -
+
${1:`yas/selected-text`} $0 diff --git a/extras/imported/html-mode/Insert Tag/Input with Label.yasnippet b/extras/imported/html-mode/Insert Tag/Input with Label.yasnippet index 4bd61d7..3c53829 100644 --- a/extras/imported/html-mode/Insert Tag/Input with Label.yasnippet +++ b/extras/imported/html-mode/Insert Tag/Input with Label.yasnippet @@ -4,4 +4,6 @@ # name: Input with Label ## condition: "text.html" # -- - + \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/Option.yasnippet b/extras/imported/html-mode/Insert Tag/Option.yasnippet index 464ed53..3ad3f6d 100644 --- a/extras/imported/html-mode/Insert Tag/Option.yasnippet +++ b/extras/imported/html-mode/Insert Tag/Option.yasnippet @@ -4,4 +4,4 @@ # name: Option ## condition: "text.html" # -- -${3:$2} \ No newline at end of file +${3:option$(unless yas/modified-p (yas/field-value 2))} \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/Select Box.yasnippet b/extras/imported/html-mode/Insert Tag/Select Box.yasnippet index a68ace7..b6363d9 100644 --- a/extras/imported/html-mode/Insert Tag/Select Box.yasnippet +++ b/extras/imported/html-mode/Insert Tag/Select Box.yasnippet @@ -4,8 +4,8 @@ # name: Select Box ## condition: "text.html" # -- - + ${11:$$(yas/get-field-once 10)} + ${14:$$(yas/get-field-once 13)}$15 $0 \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML base.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML base.yasnippet index 8bc9928..9a9abba 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML base.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML base.yasnippet @@ -4,4 +4,4 @@ # name: Base ## condition: "text.html" # -- - \ No newline at end of file + \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML body.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML body.yasnippet index e538349..520e91e 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML body.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML body.yasnippet @@ -4,6 +4,8 @@ # name: Body ## condition: "text.html" # -- - + $0 \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML br.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML br.yasnippet index 017b084..b93b199 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML br.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML br.yasnippet @@ -1,7 +1,7 @@ # -*- mode: snippet -*- # contributor: Translated from TextMate Snippet # name: Br -## binding: "^ " +# binding: M-RET ## condition: "text.html" # -- - \ No newline at end of file + \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML form.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML form.yasnippet index 6e21f87..8b67b3d 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML form.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML form.yasnippet @@ -4,8 +4,11 @@ # name: Form ## condition: "text.html" # -- -
+ $0 -

+

\ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML h1.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML h1.yasnippet index 9b144da..6336e25 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML h1.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML h1.yasnippet @@ -4,4 +4,4 @@ # name: Heading ## condition: "text.html" # -- -

${1:`yas/selected-text`}

\ No newline at end of file +

${1:`yas/selected-text`}

\ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML head.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML head.yasnippet index 19c1173..fb341fa 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML head.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML head.yasnippet @@ -5,7 +5,9 @@ ## condition: "text.html - text.html source" # -- - - ${1:${TM_FILENAME/((.+)\..*)?/(?2:$2:Page Title)/}} + + ${1:`(or (and buffer-file-name + (file-name-sans-extension (file-name-nondirectory buffer-file-name))) + "Page Title")`} $0 \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML input.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML input.yasnippet index 8d62d72..097b1da 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML input.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML input.yasnippet @@ -1,7 +1,6 @@ # -*- mode: snippet -*- # key: input -# contributor: Translated from TextMate Snippet # name: Input ## condition: "text.html" # -- - \ No newline at end of file + \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML link.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML link.yasnippet index d2b7b94..6538f90 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML link.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML link.yasnippet @@ -4,4 +4,4 @@ # name: Link ## condition: "text.html" # -- - \ No newline at end of file + \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML meta.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML meta.yasnippet index 829355a..557ea0c 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML meta.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML meta.yasnippet @@ -4,4 +4,4 @@ # name: Meta ## condition: "text.html" # -- - \ No newline at end of file + \ No newline at end of file diff --git a/extras/imported/html-mode/Insert Tag/XHTML title.yasnippet b/extras/imported/html-mode/Insert Tag/XHTML title.yasnippet index 9b1c5f1..2748e5f 100644 --- a/extras/imported/html-mode/Insert Tag/XHTML title.yasnippet +++ b/extras/imported/html-mode/Insert Tag/XHTML title.yasnippet @@ -4,4 +4,6 @@ # name: Title ## condition: "text.html - text.blog" # -- -${1:${TM_FILENAME/((.+)\..*)?/(?2:$2:Page Title)/}} \ No newline at end of file +${1:`(or (and buffer-file-name + (file-name-sans-extension (file-name-nondirectory buffer-file-name))) + "Page Title")`} \ No newline at end of file diff --git a/extras/imported/html-mode/Smart returnindent for tag pairs.yasnippet b/extras/imported/html-mode/Smart returnindent for tag pairs.yasnippet index b816c2d..a8d44b4 100644 --- a/extras/imported/html-mode/Smart returnindent for tag pairs.yasnippet +++ b/extras/imported/html-mode/Smart returnindent for tag pairs.yasnippet @@ -1,7 +1,7 @@ # -*- mode: snippet -*- # contributor: Translated from TextMate Snippet # name: Special: Return Inside Empty Open/Close Tags -# binding: "C-M" +# binding: RET # condition: (yas/html-between-tag-pair-p) # -- diff --git a/extras/imported/html-mode/Wrap Selection In Tag.yasnippet b/extras/imported/html-mode/Wrap Selection In Tag.yasnippet index ee855b4..c949596 100644 --- a/extras/imported/html-mode/Wrap Selection In Tag.yasnippet +++ b/extras/imported/html-mode/Wrap Selection In Tag.yasnippet @@ -1,7 +1,8 @@ # -*- mode: snippet -*- # contributor: joaotavora, adapted from TextMate HTML bundle # name: Wrap Selection in Open/Close Tag -# binding: "C-S-w" +# binding: C-S-w # condition: mark-active +# expand-env: ((yas/html-wrap-newline (when (string-match "\n" yas/selected-text) "\n"))) # -- -<${1:p}>`yas/selected-text` \ No newline at end of file +<${1:p}>`(concat yas/html-wrap-newline yas/selected-text yas/html-wrap-newline)` \ No newline at end of file diff --git a/yasnippet.el b/yasnippet.el index 5334a30..71ffd83 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -710,7 +710,7 @@ With optional UNBIND-KEY, try to unbind that key from (defvar yas/snippet-tables (make-hash-table) "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. 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 `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) - (setq yas/snippet-keymaps nil) + (setq yas/direct-keymaps nil) (maphash #'(lambda (name table) (mapc #'(lambda (table) - (push (cons name - (yas/snippet-table-keymap table)) - yas/snippet-keymaps)) + (push (cons (intern (format "yas//direct-%s" name)) + (yas/snippet-table-direct-keymap table)) + yas/direct-keymaps)) (cons table (yas/snippet-table-get-all-parents table)))) 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 (define-minor-mode yas/minor-mode "Toggle YASnippet mode. @@ -764,26 +775,19 @@ Key bindings: ;; Install the direct keymaps in `emulation-mode-map-alists' ;; (we use `add-hook' even though it's not technically a hook, ;; 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 - ;; 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 ;; need to be set and unset buffer-locally (preferred). ;; - (add-hook 'emulation-mode-map-alists 'yas/snippet-keymaps nil 'local) - (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) - (unless (and (boundp mode) - (symbol-value mode)) - (set (make-local-variable mode) t))))) + (add-hook 'emulation-mode-map-alists 'yas/direct-keymaps) + (yas/direct-keymaps-set-vars)) (t ;; 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 () (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 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 \"namehash\", where NAME is the snippet name and TEMPLATE is a `yas/template' object. @@ -902,7 +906,7 @@ Has the following fields: A list of tables considered parents of this table: i.e. when 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 keybindings. This is kept in sync with the keyhash, i.e., all @@ -912,7 +916,7 @@ Has the following fields: name (hash (make-hash-table :test 'equal)) (parents nil) - (keymap (make-sparse-keymap))) + (direct-keymap (make-sparse-keymap))) ;; Apropos storing/updating, this is works with two steps: ;; @@ -968,7 +972,7 @@ Has the following fields: (when (= 0 (hash-table-count (cdr elem))) (remhash (car elem) (yas/snippet-table-hash table)) (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) "Store in TABLE the snippet NAME indexed by KEY and expanding TEMPLATE. @@ -987,7 +991,7 @@ keybinding)." (make-hash-table :test 'equal) (yas/snippet-table-hash table)))) (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) "Fetch snippets in TABLE by KEY. " @@ -1053,13 +1057,7 @@ conditions to filter out potential expansions." (let* ((requirement (or requirement (yas/require-template-specific-condition-p))) (result (or (null condition) - (yas/eval-condition - (condition-case err - (read condition) - (error (progn - (message (format "[yas] error reading condition: %s" - (error-message-string err)))) - nil)))))) + (yas/eval-condition condition)))) (cond ((eq requirement t) result) (t @@ -1182,7 +1180,9 @@ already have such a property." yas/snippet-tables))) (unless table (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)) (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)) (setq name (match-string-no-properties 2))) (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)) (setq group (match-string-no-properties 2))) (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)) ;; Reload the direct keybindings ;; - (yas/snippet-keymaps-reload) + (yas/direct-keymaps-reload) ;; Restore the mode configuration ;; (when restore-minor-mode @@ -1669,7 +1669,12 @@ Here's the default value for all the parameters: (insert "\n\n")))) (dolist (dir dirs) (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 ")\n\n" code "\n") @@ -1930,7 +1935,7 @@ object satisfying `yas/field-p' to restrict the expansion to." (yas/fallback 'trigger-key)))) (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" (interactive) @@ -1968,7 +1973,7 @@ Common gateway for `yas/expand-from-trigger-key' and nil) ((eq yas/fallback-behavior 'call-other-command) (let* ((yas/minor-mode nil) - (yas/snippet-keymaps nil) + (yas/direct-keymaps nil) (keys-1 (this-command-keys-vector)) (keys-2 (and yas/trigger-key from-trigger-key-p @@ -2172,7 +2177,7 @@ lurking." # -*- mode: snippet -*- # name: %s # key: $1${2: -# binding: \"${3:keybinding}\"}${4: +# binding: \"${3:direct-keybinding}\"}${4: # expand-env: ((${5:some-var} ${6:some-value}))} # -- $0" name)))) @@ -2373,6 +2378,12 @@ Otherwise throw exception." (when 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) (unless yas/modified-p (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) real-match-end-1))) (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) yas/dollar-regions))))))) @@ -3623,7 +3634,7 @@ object satisfying `yas/field-p' to restrict the expansion to."))) (templates (mapcan #'(lambda (table) (yas/fetch table vec)) (yas/get-snippet-tables))) - (yas/snippet-keymaps nil) + (yas/direct-keymaps nil) (fallback (key-binding vec))) (concat "In this particular case\nmy guess is it would " (when templates