aboutsummaryrefslogtreecommitdiffstats
path: root/src/html-abbrev.el
diff options
context:
space:
mode:
Diffstat (limited to 'src/html-abbrev.el')
-rw-r--r--src/html-abbrev.el344
1 files changed, 172 insertions, 172 deletions
diff --git a/src/html-abbrev.el b/src/html-abbrev.el
index e66b459..1bc3e45 100644
--- a/src/html-abbrev.el
+++ b/src/html-abbrev.el
@@ -8,46 +8,46 @@
(defun emmet-expr (input)
"Parse a zen coding expression with optional filters."
(emmet-pif (emmet-parse "\\(.*?\\)|" 2 "expr|filter" it)
- (let ((input (elt it 1))
- (filters (elt it 2)))
- (emmet-pif (emmet-extract-filters filters)
- (emmet-filter input it)
- it))
- (emmet-filter input (emmet-default-filter))))
+ (let ((input (elt it 1))
+ (filters (elt it 2)))
+ (emmet-pif (emmet-extract-filters filters)
+ (emmet-filter input it)
+ it))
+ (emmet-filter input (emmet-default-filter))))
(defun emmet-subexpr (input)
"Parse a zen coding expression with no filter. This pretty much defines precedence."
(emmet-run emmet-siblings
- it
- (emmet-run emmet-parent-child
- it
- (emmet-run emmet-multiplier
- it
- (emmet-run emmet-pexpr
- it
- (emmet-run emmet-text
- it
- (emmet-run emmet-tag
- it
- '(error "no match, expecting ( or a-zA-Z0-9"))))))))
+ it
+ (emmet-run emmet-parent-child
+ it
+ (emmet-run emmet-multiplier
+ it
+ (emmet-run emmet-pexpr
+ it
+ (emmet-run emmet-text
+ it
+ (emmet-run emmet-tag
+ it
+ '(error "no match, expecting ( or a-zA-Z0-9"))))))))
(defun emmet-extract-filters (input)
"Extract filters from expression."
(emmet-pif (emmet-parse "\\([^\\|]+?\\)|" 2 "" it)
- (let ((filter-name (elt it 1))
- (more-filters (elt it 2)))
- (emmet-pif (emmet-extract-filters more-filters)
- (cons filter-name it)
- it))
- (emmet-parse "\\([^\\|]+\\)" 1 "filter name" `(,(elt it 1)))))
+ (let ((filter-name (elt it 1))
+ (more-filters (elt it 2)))
+ (emmet-pif (emmet-extract-filters more-filters)
+ (cons filter-name it)
+ it))
+ (emmet-parse "\\([^\\|]+\\)" 1 "filter name" `(,(elt it 1)))))
(defun emmet-filter (input filters)
"Construct AST with specified filters."
(emmet-pif (emmet-subexpr input)
- (let ((result (car it))
- (rest (cdr it)))
- `((filter ,filters ,result) . ,rest))
- it))
+ (let ((result (car it))
+ (rest (cdr it)))
+ `((filter ,filters ,result) . ,rest))
+ it))
(defun emmet-default-filter ()
"Default filter(s) to be used if none is specified."
@@ -69,27 +69,27 @@
"\\(\\$+\\)" 2 "numbering, $"
(let ((doller (elt it 1)))
(emmet-pif (emmet-parse
- "@\\([0-9-][0-9]*\\)" 2 "numbering args"
- (let* ((args (read (elt it 1)))
- (direction (not (or (eq '- args) (minusp args))))
- (base (if (eq '- args) 1 (abs args))))
- `((n ,(length doller) ,direction ,base) . ,input)))
- it
- `((n ,(length doller) t 1) . ,input)))))
+ "@\\([0-9-][0-9]*\\)" 2 "numbering args"
+ (let* ((args (read (elt it 1)))
+ (direction (not (or (eq '- args) (minusp args))))
+ (base (if (eq '- args) 1 (abs args))))
+ `((n ,(length doller) ,direction ,base) . ,input)))
+ it
+ `((n ,(length doller) t 1) . ,input)))))
(defun emmet-split-numbering-expressions (input)
(cl-labels
((iter (input)
(emmet-aif (emmet-regex "\\([^$]*\\)\\(\\$.*\\)" input '(1 2))
- (let ((prefix (car it))
- (input (cadr it)))
- (if (and (< 0 (length prefix)) ; check if ..\\$... or ...$...
- (string-equal (substring prefix -1) "\\"))
- `(,(store-substring prefix (- (length prefix) 1) ?$)
- ,@(iter (substring input 1)))
- (let ((res (emmet-numbering input)))
- `(,prefix ,(car res) ,@(iter (cdr res))))))
- (list input))))
+ (let ((prefix (car it))
+ (input (cadr it)))
+ (if (and (< 0 (length prefix)) ; check if ..\\$... or ...$...
+ (string-equal (substring prefix -1) "\\"))
+ `(,(store-substring prefix (- (length prefix) 1) ?$)
+ ,@(iter (substring input 1)))
+ (let ((res (emmet-numbering input)))
+ `(,prefix ,(car res) ,@(iter (cdr res))))))
+ (list input))))
(let ((res (iter input)))
(if (every #'stringp res)
(apply #'concat res)
@@ -97,29 +97,29 @@
(defun emmet-instantiate-numbering-expression (i lim exp)
(cl-labels ((instantiate
- (i lim exps)
- (apply #'concat
- (mapcar
- (lambda (exp)
- (if (listp exp)
- (let ((digits (second exp))
- (direction (third exp))
- (base (fourth exp)))
- (let ((num (if direction (+ base i)
- (- (+ lim (- base 1)) i))))
- (format (concat "%0" (format "%d" digits) "d") num)))
- exp)) exps)))
- (search
- (i lim exp)
- (if (listp exp)
- (if (eql (car exp) 'numberings)
- (instantiate i lim (cdr exp))
- ;; Should do like this for real searching.
- ;; But stack overflow occurs.
- ;; (cons (search-numberings i lim (car exp))
- ;; (search-numberings i lim (cdr exp)))
- (mapcar (lambda (exp) (search i lim exp)) exp))
- exp)))
+ (i lim exps)
+ (apply #'concat
+ (mapcar
+ (lambda (exp)
+ (if (listp exp)
+ (let ((digits (second exp))
+ (direction (third exp))
+ (base (fourth exp)))
+ (let ((num (if direction (+ base i)
+ (- (+ lim (- base 1)) i))))
+ (format (concat "%0" (format "%d" digits) "d") num)))
+ exp)) exps)))
+ (search
+ (i lim exp)
+ (if (listp exp)
+ (if (eql (car exp) 'numberings)
+ (instantiate i lim (cdr exp))
+ ;; Should do like this for real searching.
+ ;; But stack overflow occurs.
+ ;; (cons (search-numberings i lim (car exp))
+ ;; (search-numberings i lim (cdr exp)))
+ (mapcar (lambda (exp) (search i lim exp)) exp))
+ exp)))
(search i lim exp)))
(defun emmet-multiply-expression (multiplicand exp)
@@ -128,19 +128,19 @@
(defun emmet-multiplier (input)
(emmet-pif (emmet-run emmet-pexpr
- it
- (emmet-run emmet-tag
- it
- (emmet-run emmet-text
- it
- '(error "expected *n multiplier"))))
- (let* ((expr (car it)) (input (cdr it))
- (multiplier expr))
- (emmet-parse "\\*\\([0-9]+\\)" 2 "*n where n is a number"
- (let ((multiplicand (read (elt it 1))))
- `((list ,(emmet-multiply-expression
- multiplicand
- multiplier)) . ,input))))))
+ it
+ (emmet-run emmet-tag
+ it
+ (emmet-run emmet-text
+ it
+ '(error "expected *n multiplier"))))
+ (let* ((expr (car it)) (input (cdr it))
+ (multiplier expr))
+ (emmet-parse "\\*\\([0-9]+\\)" 2 "*n where n is a number"
+ (let ((multiplicand (read (elt it 1))))
+ `((list ,(emmet-multiply-expression
+ multiplicand
+ multiplier)) . ,input))))))
(defun emmet-tag (input)
"Parse a tag."
@@ -150,22 +150,22 @@
(has-body? (cddr expr)))
(emmet-pif
(emmet-run emmet-identifier
- (emmet-tag-classes
- `(tag (,tagname ,has-body? ,(cddr expr))) input)
- (emmet-tag-classes
- `(tag (,tagname ,has-body? nil)) input))
+ (emmet-tag-classes
+ `(tag (,tagname ,has-body? ,(cddr expr))) input)
+ (emmet-tag-classes
+ `(tag (,tagname ,has-body? nil)) input))
(let ((tag-data (cadar it)) (input (cdr it)))
(emmet-pif (emmet-run
- emmet-properties
- (let ((props (cdr expr)))
- `((tag ,(append tag-data (list props))) . ,input))
- `((tag ,(append tag-data '(nil))) . ,input))
- (let ((expr (car it)) (input (cdr it)))
- (destructuring-bind (expr . input)
- (emmet-tag-text expr input)
- (or
- (emmet-expand-lorem expr input)
- (emmet-expand-tag-alias expr input))))))))
+ emmet-properties
+ (let ((props (cdr expr)))
+ `((tag ,(append tag-data (list props))) . ,input))
+ `((tag ,(append tag-data '(nil))) . ,input))
+ (let ((expr (car it)) (input (cdr it)))
+ (destructuring-bind (expr . input)
+ (emmet-tag-text expr input)
+ (or
+ (emmet-expand-lorem expr input)
+ (emmet-expand-tag-alias expr input))))))))
(emmet-default-tag input)))
(defun emmet-get-first-tag (expr)
@@ -224,28 +224,28 @@
(defun emmet-default-tag (input)
"Parse a #id or .class"
(emmet-parse "\\([#|\\.]\\)" 1 "tagname"
- (emmet-tag (concat "div" (elt it 0)))))
+ (emmet-tag (concat "div" (elt it 0)))))
(defun emmet-tag-text (tag input)
(let ((tag-data (cadr tag)))
(emmet-run emmet-text
- (let ((txt (cadr expr)))
- `((tag ,(append tag-data (list txt))) . ,input))
- `((tag ,(append tag-data '(nil))) . ,input))))
+ (let ((txt (cadr expr)))
+ `((tag ,(append tag-data (list txt))) . ,input))
+ `((tag ,(append tag-data '(nil))) . ,input))))
(defun emmet-tag-props (tag input)
(let ((tag-data (cadr tag)))
(emmet-run emmet-properties
- (let ((props (cdr expr)))
- `((tag ,(append tag-data (list props))) . ,input))
- `((tag ,(append tag-data '(nil))) . ,input))))
+ (let ((props (cdr expr)))
+ `((tag ,(append tag-data (list props))) . ,input))
+ `((tag ,(append tag-data '(nil))) . ,input))))
(defun emmet-props (input)
"Parse many props."
- (emmet-run emmet-prop
- (emmet-pif (emmet-props input)
- `((props . ,(cons expr (cdar it))) . ,(cdr it))
- `((props . ,(list expr)) . ,input))))
+ (emmet-run emmet-prop
+ (emmet-pif (emmet-props input)
+ `((props . ,(cons expr (cdar it))) . ,(cdr it))
+ `((props . ,(list expr)) . ,input))))
(defun emmet-prop (input)
(emmet-parse
@@ -276,19 +276,19 @@
(defun emmet-tag-classes (tag input)
(let ((tag-data (cadr tag)))
(emmet-run emmet-classes
- (let ((classes (mapcar (lambda (cls) (cdadr cls))
- (cdr expr))))
- `((tag ,(append tag-data (list classes))) . ,input))
- `((tag ,(append tag-data '(nil))) . ,input))))
+ (let ((classes (mapcar (lambda (cls) (cdadr cls))
+ (cdr expr))))
+ `((tag ,(append tag-data (list classes))) . ,input))
+ `((tag ,(append tag-data '(nil))) . ,input))))
(defun emmet-tagname (input)
"Parse a tagname a-zA-Z0-9 tagname (e.g. html/head/xsl:if/br)."
(emmet-parse "\\([a-zA-Z!][a-zA-Z0-9:!$@-]*\/?\\)" 2 "tagname, a-zA-Z0-9"
- (let* ((tag-spec (elt it 1))
- (empty-tag (emmet-regex "\\([^\/]*\\)\/" tag-spec 1))
- (tag (emmet-split-numbering-expressions
- (if empty-tag (car empty-tag) tag-spec))))
- `((tagname . (,tag . ,(not empty-tag))) . ,input))))
+ (let* ((tag-spec (elt it 1))
+ (empty-tag (emmet-regex "\\([^\/]*\\)\/" tag-spec 1))
+ (tag (emmet-split-numbering-expressions
+ (if empty-tag (car empty-tag) tag-spec))))
+ `((tagname . (,tag . ,(not empty-tag))) . ,input))))
(defun emmet-text (input)
"A zen coding expression innertext."
@@ -302,29 +302,29 @@
(defun emmet-properties (input)
"A bracketed emmet property expression."
(emmet-parse "\\[\\(.*?\\)\\]" 2 "properties"
- `(,(car (emmet-props (elt it 1))) . ,input)))
+ `(,(car (emmet-props (elt it 1))) . ,input)))
(defun emmet-pexpr (input)
"A zen coding expression with parentheses around it."
(emmet-parse "(" 1 "("
- (emmet-run emmet-subexpr
- (emmet-aif (emmet-regex ")" input '(0 1))
- `(,expr . ,(elt it 1))
- '(error "expecting `)'")))))
+ (emmet-run emmet-subexpr
+ (emmet-aif (emmet-regex ")" input '(0 1))
+ `(,expr . ,(elt it 1))
+ '(error "expecting `)'")))))
(defun emmet-parent-child (input)
"Parse an tag>e expression, where `n' is an tag and `e' is any
expression."
(cl-labels
- ((listing (parents child input)
- (let ((len (length parents)))
- `((list ,(map 'list
- (lambda (parent i)
- `(parent-child ,parent
- ,(emmet-instantiate-numbering-expression i len child)))
- parents
- (loop for i to (- len 1) collect i))) . ,input))))
+ ((listing (parents child input)
+ (let ((len (length parents)))
+ `((list ,(map 'list
+ (lambda (parent i)
+ `(parent-child ,parent
+ ,(emmet-instantiate-numbering-expression i len child)))
+ parents
+ (loop for i to (- len 1) collect i))) . ,input))))
(emmet-run
emmet-multiplier
(let* ((items (cadr expr))
@@ -347,80 +347,80 @@
(defun emmet-child-sans (parent input)
(emmet-parse ">" 1 ">"
- (emmet-run emmet-subexpr
- it
- '(error "expected child"))))
+ (emmet-run emmet-subexpr
+ it
+ '(error "expected child"))))
(defun emmet-child (parent input)
(emmet-parse ">" 1 ">"
- (emmet-run emmet-subexpr
- (let ((child expr))
- (emmet-aif (emmet-regex "^" input '(0 1))
- (let ((input (elt it 1)))
- (emmet-run emmet-subexpr
- `((sibling (parent-child ,parent ,child) ,expr) . ,input)
- `((parent-child ,parent ,child) . ,input)))
- `((parent-child ,parent ,child) . ,input)))
- '(error "expected child"))))
+ (emmet-run emmet-subexpr
+ (let ((child expr))
+ (emmet-aif (emmet-regex "^" input '(0 1))
+ (let ((input (elt it 1)))
+ (emmet-run emmet-subexpr
+ `((sibling (parent-child ,parent ,child) ,expr) . ,input)
+ `((parent-child ,parent ,child) . ,input)))
+ `((parent-child ,parent ,child) . ,input)))
+ '(error "expected child"))))
(defun emmet-sibling (input)
(emmet-por emmet-pexpr emmet-multiplier
- it
- (emmet-run emmet-tag
- it
- (emmet-run emmet-text
- it
- '(error "expected sibling")))))
+ it
+ (emmet-run emmet-tag
+ it
+ (emmet-run emmet-text
+ it
+ '(error "expected sibling")))))
(defun emmet-siblings (input)
"Parse an e+e expression, where e is an tag or a pexpr."
(emmet-run emmet-sibling
- (let ((parent expr))
- (emmet-parse
- "\\+" 1 "+"
- (emmet-run
- emmet-subexpr
- (let ((child expr))
- `((sibling ,parent ,child) . ,input))
- (emmet-expand parent input))))
- '(error "expected first sibling")))
+ (let ((parent expr))
+ (emmet-parse
+ "\\+" 1 "+"
+ (emmet-run
+ emmet-subexpr
+ (let ((child expr))
+ `((sibling ,parent ,child) . ,input))
+ (emmet-expand parent input))))
+ '(error "expected first sibling")))
(defun emmet-expand (parent input)
"Parse an e+ expression, where e is an expandable tag"
(let* ((parent-tag (car (cadr parent))))
(setf (caadr parent) (concat parent-tag "+"))
(destructuring-bind (parent . input)
- (emmet-expand-tag-alias parent input)
- (emmet-pif (emmet-parse "+\\(.*\\)" 1 "+expr"
- (emmet-subexpr (elt it 1)))
- `((sibling ,parent ,@it))
- `(,parent . ,input)))))
+ (emmet-expand-tag-alias parent input)
+ (emmet-pif (emmet-parse "+\\(.*\\)" 1 "+expr"
+ (emmet-subexpr (elt it 1)))
+ `((sibling ,parent ,@it))
+ `(,parent . ,input)))))
(defun emmet-name (input)
"Parse a class or identifier name, e.g. news, footer, mainimage"
(emmet-parse "\\([a-zA-Z$@][a-zA-Z0-9$@_:-]*\\)" 2 "class or identifer name"
- `((name . ,(emmet-split-numbering-expressions
- (elt it 1))) . ,input)))
+ `((name . ,(emmet-split-numbering-expressions
+ (elt it 1))) . ,input)))
(defun emmet-class (input)
"Parse a classname expression, e.g. .foo"
(emmet-parse "\\." 1 "."
- (emmet-run emmet-name
- `((class ,expr) . ,input)
- '(error "expected class name"))))
+ (emmet-run emmet-name
+ `((class ,expr) . ,input)
+ '(error "expected class name"))))
(defun emmet-identifier (input)
"Parse an identifier expression, e.g. #foo"
(emmet-parse "#" 1 "#"
- (emmet-run emmet-name
- `((identifier . ,expr) . ,input))))
+ (emmet-run emmet-name
+ `((identifier . ,expr) . ,input))))
(defun emmet-classes (input)
"Parse many classes."
(emmet-run emmet-class
- (emmet-pif (emmet-classes input)
- `((classes . ,(cons expr (cdar it))) . ,(cdr it))
- `((classes . ,(list expr)) . ,input))
- '(error "expected class")))
+ (emmet-pif (emmet-classes input)
+ `((classes . ,(cons expr (cdar it))) . ,(cdr it))
+ `((classes . ,(list expr)) . ,input))
+ '(error "expected class")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Zen coding transformer from AST to string
@@ -695,8 +695,8 @@
(cond
((eq type 'list)
(mapconcat (lexical-let ((make-tag-fun tag-maker))
- #'(lambda (sub-ast)
- (emmet-transform-ast sub-ast make-tag-fun)))
+ #'(lambda (sub-ast)
+ (emmet-transform-ast sub-ast make-tag-fun)))
(cadr ast)
"\n"))
((eq type 'tag)