diff options
author | --- <deactivated@gmail.com> | 2009-11-08 17:12:04 +0800 |
---|---|---|
committer | Chris Done <chrisdone@gmail.com> | 2009-11-11 15:43:35 +0800 |
commit | 6416739410e243669f7bdfa8313c6198eaf9f2f5 (patch) | |
tree | 75bc7de5559f4bbc1526ef7b1371f922001239e1 /zencoding-mode.el | |
parent | 9f8ae5e285a35a26e4b17cd39f57b4d7c9c19582 (diff) | |
download | emmet-mode-6416739410e243669f7bdfa8313c6198eaf9f2f5.tar.lz emmet-mode-6416739410e243669f7bdfa8313c6198eaf9f2f5.tar.xz emmet-mode-6416739410e243669f7bdfa8313c6198eaf9f2f5.zip |
Add experimental yasnippet integration
Diffstat (limited to 'zencoding-mode.el')
-rw-r--r-- | zencoding-mode.el | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/zencoding-mode.el b/zencoding-mode.el index 7e05c5e..25987a2 100644 --- a/zencoding-mode.el +++ b/zencoding-mode.el @@ -266,6 +266,10 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Zen coding transformer from AST to HTML +(defvar zencoding-leaf-function nil + "Function to execute when expanding a leaf node in the + Zencoding AST.") + (defun zencoding-make-tag (tag &optional content) (let ((name (car tag)) (props (apply 'concat (mapcar @@ -274,7 +278,8 @@ "=\"" (cadr prop) "\"")) (cadr tag))))) (concat "<" name props ">" - (if content content "") + (if content content + (if zencoding-leaf-function (funcall zencoding-leaf-function))) "</" name ">"))) (defun zencoding-transform (ast) @@ -399,6 +404,31 @@ :lighter " Zen" :keymap zencoding-mode-keymap) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Zencoding yasnippet integration + +(defun zencoding-transform-yas (ast) + (let* ((leaf-count 0) + (zencoding-leaf-function + (lambda () + (format "$%d" (incf leaf-count))))) + (zencoding-transform ast))) + +(defun zencoding-expand-yas () + (interactive) + (let ((expr (zencoding-expr-at-point))) + (if expr + (let* ((markup (zencoding-transform-yas (car (zencoding-expr (first expr))))) + (filled (replace-regexp-in-string "><" ">\n<" markup))) + (delete-region (second expr) (third expr)) + (insert filled) + (indent-region (second expr) (point)) + (yas/expand-snippet + (buffer-substring (second expr) (point)) + (second expr) (point)))))) + + ;;; Real-time preview ;; |