From 8ba7c90eaf2d1255a667bf43a376b2de580ef421 Mon Sep 17 00:00:00 2001 From: Ron Panduwana Date: Mon, 21 Feb 2011 10:01:57 +0700 Subject: Added Clojure's Hiccup filter (|hic), default for .clj files. --- zencoding-mode.el | 57 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 50 insertions(+), 7 deletions(-) (limited to 'zencoding-mode.el') diff --git a/zencoding-mode.el b/zencoding-mode.el index e014dc2..123cdb3 100644 --- a/zencoding-mode.el +++ b/zencoding-mode.el @@ -162,7 +162,8 @@ (let* ((file-ext (car (zencoding-regex ".*\\(\\..*\\)"(buffer-file-name) 1))) (defaults '(".html" ("html") ".htm" ("html") - ".haml" ("haml"))) + ".haml" ("haml") + ".clj" ("hic"))) (default-else '("html")) (selected-default (member file-ext defaults))) (if selected-default @@ -390,7 +391,8 @@ (defvar zencoding-filters '("html" (zencoding-primary-filter zencoding-make-html-tag) "c" (zencoding-primary-filter zencoding-make-commented-html-tag) - "haml" (zencoding-primary-filter zencoding-make-haml-tag))) + "haml" (zencoding-primary-filter zencoding-make-haml-tag) + "hic" (zencoding-primary-filter zencoding-make-hiccup-tag))) (defun zencoding-primary-filter (input proc) "Process filter that needs to be executed first, ie. not given output from other filter." @@ -460,7 +462,7 @@ body))) (defun zencoding-make-haml-tag (tag-name tag-id tag-classes tag-props self-closing? content) - "Create HAML markup string" + "Create HAML string" (let ((name (if (and (equal tag-name "div") (or tag-id tag-classes)) "" @@ -473,6 +475,24 @@ (concat name id classes props (if content (zencoding-indent content))))) +(defun zencoding-make-hiccup-tag (tag-name tag-id tag-classes tag-props self-closing? content) + "Create Hiccup string" + (let* ((id (zencoding-concat-or-empty "#" tag-id)) + (classes (zencoding-mapconcat-or-empty "." tag-classes ".")) + (props (zencoding-mapconcat-or-empty " {" tag-props ", " "}" + (lambda (prop) + (concat ":" (symbol-name (car prop)) " \"" (cadr prop) "\"")))) + (content-multiline? (and content (string-match "\n" content))) + (block-tag? (or (member tag-name zencoding-block-tags) + (and (> (length tag-name) 1) + (not (member tag-name zencoding-inline-tags)))))) + (concat "[:" tag-name id classes props + (if content + (if (or content-multiline? block-tag?) + (zencoding-indent content) + (concat " " content))) + "]"))) + (defun zencoding-concat-or-empty (prefix body &optional suffix) "Return prefixed suffixed text or empty string." (if body @@ -684,11 +704,19 @@ "" "" "") - ;; Filters - ("#a.b|c" "" - "
" + ;; Filter: comment + ("a.b|c" "" + "" + "") + ("#a>.b|c" "" + "
" + " " + "
" + "
" + " " "
" - "") + "") + ;; Filter: HAML ("a|haml" "%a") ("a#q.x.y.z|haml" "%a#q.x.y.z") ("a#q.x x=y m=l|haml" "%a#q.x{:x => \"y\", :m => \"l\"}") @@ -698,6 +726,19 @@ ("p>a href=#+br|haml" "%p" " %a{:href => \"#\"}" " %br") + ;; Filter: Hiccup + ("a|hic" "[:a]") + ("a#q.x.y.z|hic" "[:a#q.x.y.z]") + ("a#q.x x=y m=l|hic" "[:a#q.x {:x \"y\", :m \"l\"}]") + (".footer|hic" "[:div.footer]") + ("p>a href=#+br|hic" "[:p" + " [:a {:href \"#\"}]" + " [:br]]") + ("#q>(a*2>b)+p>b|hic" "[:div#q" + " [:a [:b]]" + " [:a [:b]]" + " [:p" + " [:b]]]") ))) (mapc (lambda (input) (let ((expected (mapconcat 'identity (cdr input) "\n")) @@ -833,6 +874,8 @@ See also `zencoding-expand-line'." (buffer-substring (second expr) (point)) (second expr) (point)))))) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Real-time preview ;; -- cgit v1.2.3