diff options
author | Jesús <heckyel@hyperbola.info> | 2020-01-10 13:58:14 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2020-01-10 13:58:14 -0500 |
commit | dc471a600b7c9219e46c95900919ec0ac88106d0 (patch) | |
tree | 5a73ca7bfdd335baf8972ceeafa1fc2723e56b59 | |
parent | d7424d40aa963e47d3224b81ccf41c4f8669617d (diff) | |
download | emmet-mode-dc471a600b7c9219e46c95900919ec0ac88106d0.tar.lz emmet-mode-dc471a600b7c9219e46c95900919ec0ac88106d0.tar.xz emmet-mode-dc471a600b7c9219e46c95900919ec0ac88106d0.zip |
improve syntax
-rw-r--r-- | src/css-abbrev.el | 162 | ||||
-rw-r--r-- | src/html-abbrev.el | 344 | ||||
-rw-r--r-- | src/init.el | 30 | ||||
-rw-r--r-- | src/mode-def.el | 86 | ||||
-rw-r--r-- | src/test.el | 118 |
5 files changed, 370 insertions, 370 deletions
diff --git a/src/css-abbrev.el b/src/css-abbrev.el index 37fb091..8b7b907 100644 --- a/src/css-abbrev.el +++ b/src/css-abbrev.el @@ -33,7 +33,7 @@ 4 "css color argument" (let ((color (let* ((n (elt it 1)) - (l (length n))) + (l (length n))) (substring (cond ((= l 1) (concat (make-list 6 (string-to-char n)))) ((= l 2) (concat n n n)) @@ -73,11 +73,11 @@ (defun emmet-css-parse-arg (input) (emmet-run emmet-css-arg-number it - (emmet-run emmet-css-arg-color it - (emmet-run emmet-css-arg-something it - (if (equal input "") - it - (cons input "")))))) + (emmet-run emmet-css-arg-color it + (emmet-run emmet-css-arg-something it + (if (equal input "") + it + (cons input "")))))) (defun emmet-css-important-p (input) (let ((len (length input))) @@ -113,12 +113,12 @@ (defun emmet-css-subexpr (exp) (let* ((importantp (emmet-css-important-p exp))) (destructuring-bind (exp vp) - (emmet-css-split-vendor-prefixes exp) - (destructuring-bind (key args) - (emmet-css-split-args (if importantp (subseq exp 0 -1) exp)) - `(,key ,vp - ,importantp - ,@(emmet-css-parse-args args)))))) + (emmet-css-split-vendor-prefixes exp) + (destructuring-bind (key args) + (emmet-css-split-args (if importantp (subseq exp 0 -1) exp)) + `(,key ,vp + ,importantp + ,@(emmet-css-parse-args args)))))) (defun emmet-css-toknize (str) (let* ((i (split-string str "+")) @@ -161,41 +161,41 @@ (defun emmet-css-instantiate-lambda (str) (cl-flet ((insert-space-between-name-and-body - (str) - (if (string-match "^\\([a-z-]+:\\)\\(.+\\)$" str) - (emmet-join-string - (mapcar (lambda (ref) (match-string ref str)) '(1 2)) " ") - str)) - (split-string-to-body - (str args-sym) - (let ((rt '(concat)) (idx-max 0)) - (loop for i from 0 to 255 do - (emmet-aif - (string-match "\\(?:|\\|${\\(?:\\([0-9]\\)\\|\\)\\(?::\\(.+?\\)\\|\\)}\\)" str) - (destructuring-bind (mat idx def) - (mapcar (lambda (ref) (match-string ref str)) '(0 1 2)) - (setf rt - `((or - (nth ,(let ((cur-idx (if idx (1- (string-to-number idx)) i))) - (setf idx-max (max cur-idx idx-max))) - ,args-sym) - ,(or def "")) - ,(substring str 0 it) ;; ordered to reverse - ,@rt)) - (setf str (substring str (+ it (length mat))))) - ;; don't use nreverse. cause bug in emacs-lisp. - (return (cons idx-max (reverse (cons str rt))))))))) + (str) + (if (string-match "^\\([a-z-]+:\\)\\(.+\\)$" str) + (emmet-join-string + (mapcar (lambda (ref) (match-string ref str)) '(1 2)) " ") + str)) + (split-string-to-body + (str args-sym) + (let ((rt '(concat)) (idx-max 0)) + (loop for i from 0 to 255 do + (emmet-aif + (string-match "\\(?:|\\|${\\(?:\\([0-9]\\)\\|\\)\\(?::\\(.+?\\)\\|\\)}\\)" str) + (destructuring-bind (mat idx def) + (mapcar (lambda (ref) (match-string ref str)) '(0 1 2)) + (setf rt + `((or + (nth ,(let ((cur-idx (if idx (1- (string-to-number idx)) i))) + (setf idx-max (max cur-idx idx-max))) + ,args-sym) + ,(or def "")) + ,(substring str 0 it) ;; ordered to reverse + ,@rt)) + (setf str (substring str (+ it (length mat))))) + ;; don't use nreverse. cause bug in emacs-lisp. + (return (cons idx-max (reverse (cons str rt))))))))) (let ((args (gensym)) (str (insert-space-between-name-and-body str))) (destructuring-bind (idx-max . body) (split-string-to-body str args) - (eval - `(lambda (&rest ,args) - (progn - (when (nthcdr ,idx-max ,args) - (setf (nthcdr ,idx-max ,args) - (list (emmet-join-string - (nthcdr ,idx-max ,args) " ")))) - ,body))))))) + (eval + `(lambda (&rest ,args) + (progn + (when (nthcdr ,idx-max ,args) + (setf (nthcdr ,idx-max ,args) + (list (emmet-join-string + (nthcdr ,idx-max ,args) " ")))) + ,body))))))) (emmet-defparameter emmet-vendor-prefixes-properties @@ -225,47 +225,47 @@ (mapcar #'(lambda (expr) (let* - ((hash-map (if emmet-use-sass-syntax emmet-sass-snippets emmet-css-snippets)) - (basement - (emmet-aif - (or (gethash (car expr) hash-map) (gethash (car expr) emmet-css-snippets)) - (let ((set it) (fn nil) (unitlessp nil)) - (if (stringp set) - (progn - ;; new pattern - ;; creating print function - (setf fn (emmet-css-instantiate-lambda set)) - ;; get unitless or no - (setf unitlessp - (not (null (string-match - emmet-css-unitless-properties-regex set)))) - ;; caching - (puthash (car expr) (cons fn unitlessp) hash-map)) - (progn - ;; cache hit. - (setf fn (car set)) - (setf unitlessp (cdr set)))) - (apply fn - (mapcar - #'(lambda (arg) - (if (listp arg) - (if unitlessp (car arg) - (apply #'concat arg)) - arg)) - (cdddr expr)))) - (concat (car expr) ": " - (emmet-join-string - (mapcar #'(lambda (arg) - (if (listp arg) (apply #'concat arg) arg)) - (cdddr expr)) " ") - ";")))) + ((hash-map (if emmet-use-sass-syntax emmet-sass-snippets emmet-css-snippets)) + (basement + (emmet-aif + (or (gethash (car expr) hash-map) (gethash (car expr) emmet-css-snippets)) + (let ((set it) (fn nil) (unitlessp nil)) + (if (stringp set) + (progn + ;; new pattern + ;; creating print function + (setf fn (emmet-css-instantiate-lambda set)) + ;; get unitless or no + (setf unitlessp + (not (null (string-match + emmet-css-unitless-properties-regex set)))) + ;; caching + (puthash (car expr) (cons fn unitlessp) hash-map)) + (progn + ;; cache hit. + (setf fn (car set)) + (setf unitlessp (cdr set)))) + (apply fn + (mapcar + #'(lambda (arg) + (if (listp arg) + (if unitlessp (car arg) + (apply #'concat arg)) + arg)) + (cdddr expr)))) + (concat (car expr) ": " + (emmet-join-string + (mapcar #'(lambda (arg) + (if (listp arg) (apply #'concat arg) arg)) + (cdddr expr)) " ") + ";")))) (let ((line (if (caddr expr) (concat (subseq basement 0 -1) " !important;") basement))) - ;; remove trailing semicolon while editing Sass files - (if (and emmet-use-sass-syntax (equal ";" (subseq line -1))) - (setq line (subseq line 0 -1))) + ;; remove trailing semicolon while editing Sass files + (if (and emmet-use-sass-syntax (equal ";" (subseq line -1))) + (setq line (subseq line 0 -1))) (emmet-aif (cadr expr) (emmet-css-transform-vendor-prefixes line it) 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) diff --git a/src/init.el b/src/init.el index ca412eb..31f7c61 100644 --- a/src/init.el +++ b/src/init.el @@ -47,30 +47,30 @@ (defmacro emmet-parse (regex nums label &rest body) "Parse according to a regex and update the `input' variable." `(emmet-aif (emmet-regex ,regex input ',(number-sequence 0 nums)) - (let ((input (elt it ,nums))) - ,@body) - `,`(error ,(concat "expected " ,label)))) + (let ((input (elt it ,nums))) + ,@body) + `,`(error ,(concat "expected " ,label)))) (defmacro emmet-run (parser then-form &rest else-forms) "Run a parser and update the input properly, extract the parsed expression." `(emmet-pif (,parser input) - (let ((input (cdr it)) - (expr (car it))) - ,then-form) - ,@(or else-forms '(it)))) + (let ((input (cdr it)) + (expr (car it))) + ,then-form) + ,@(or else-forms '(it)))) (defmacro emmet-por (parser1 parser2 then-form &rest else-forms) "OR two parsers. Try one parser, if it fails try the next." `(emmet-pif (,parser1 input) - (let ((input (cdr it)) - (expr (car it))) - ,then-form) - (emmet-pif (,parser2 input) - (let ((input (cdr it)) - (expr (car it))) - ,then-form) - ,@else-forms))) + (let ((input (cdr it)) + (expr (car it))) + ,then-form) + (emmet-pif (,parser2 input) + (let ((input (cdr it)) + (expr (car it))) + ,then-form) + ,@else-forms))) (defmacro emmet-find (direction regexp &optional limit-of-search repeat-count) "Regexp-search in given direction, returning the position (or nil) diff --git a/src/mode-def.el b/src/mode-def.el index f8d481f..db064a9 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -18,25 +18,25 @@ (defun emmet-find-left-bound () "Find the left bound of an emmet expr" (save-excursion (save-match-data - (let ((char (char-before)) - (in-style-attr (looking-back "style=[\"'][^\"']*" nil)) - (syn-tab (make-syntax-table))) - (modify-syntax-entry ?\\ "\\") - (while char - (cond ((and in-style-attr (member char '(?\" ?\'))) - (setq char nil)) - ((member char '(?\} ?\] ?\))) - (with-syntax-table syn-tab - (backward-sexp) (setq char (char-before)))) - ((eq char ?\>) - (if (looking-back "<[^>]+>" (line-beginning-position)) - (setq char nil) - (progn (backward-char) (setq char (char-before))))) - ((not (string-match-p "[[:space:]\n;]" (string char))) - (backward-char) (setq char (char-before))) - (t - (setq char nil)))) - (point))))) + (let ((char (char-before)) + (in-style-attr (looking-back "style=[\"'][^\"']*" nil)) + (syn-tab (make-syntax-table))) + (modify-syntax-entry ?\\ "\\") + (while char + (cond ((and in-style-attr (member char '(?\" ?\'))) + (setq char nil)) + ((member char '(?\} ?\] ?\))) + (with-syntax-table syn-tab + (backward-sexp) (setq char (char-before)))) + ((eq char ?\>) + (if (looking-back "<[^>]+>" (line-beginning-position)) + (setq char nil) + (progn (backward-char) (setq char (char-before))))) + ((not (string-match-p "[[:space:]\n;]" (string char))) + (backward-char) (setq char (char-before))) + (t + (setq char nil)))) + (point))))) (defcustom emmet-indentation 4 "Number of spaces used for indentation." @@ -447,8 +447,8 @@ See `emmet-preview-online'." (defun emmet-preview-transformed (indent) (let* ((string (buffer-substring-no-properties - (overlay-start emmet-preview-input) - (overlay-end emmet-preview-input)))) + (overlay-start emmet-preview-input) + (overlay-end emmet-preview-input)))) (let ((output (emmet-transform string))) (when output output)))) @@ -480,30 +480,30 @@ See `emmet-preview-online'." "\\|")) (edit-point (format "\\(%s\\)" whole-regex))) (if (> count 0) - (progn - (forward-char) - (let - ((search-result (re-search-forward edit-point nil t count))) - (if search-result - (progn - (cond - ((match-string 2) (goto-char (- (match-end 2) 1))) - ((match-string 3) (end-of-line)) + (progn + (forward-char) + (let + ((search-result (re-search-forward edit-point nil t count))) + (if search-result + (progn + (cond + ((match-string 2) (goto-char (- (match-end 2) 1))) + ((match-string 3) (end-of-line)) ((match-string 4) (backward-char))) - (point)) - (backward-char)))) + (point)) + (backward-char)))) (progn - (backward-char) - (let - ((search-result (re-search-backward edit-point nil t (- count)))) - (if search-result - (progn - (cond - ((match-string 2) (goto-char (- (match-end 2) 1))) - ((match-string 3) (end-of-line)) - ((match-string 4) (forward-char 2))) - (point)) - (forward-char))))))) + (backward-char) + (let + ((search-result (re-search-backward edit-point nil t (- count)))) + (if search-result + (progn + (cond + ((match-string 2) (goto-char (- (match-end 2) 1))) + ((match-string 3) (end-of-line)) + ((match-string 4) (forward-char 2))) + (point)) + (forward-char))))))) (defcustom emmet-postwrap-goto-edit-point nil "Goto first edit point after wrapping markup?" diff --git a/src/test.el b/src/test.el index ddc7e40..b5140b9 100644 --- a/src/test.el +++ b/src/test.el @@ -7,15 +7,15 @@ (defun emmet-run-test-case (name fn cases) (let ((res (loop for c in cases - for i to (1- (length cases)) do - (let ((expected (cdr c)) - (actual (funcall fn (car c)))) - (when (not (equal expected actual)) - (princ - (concat "*** [FAIL] | \"" name "\" " (number-to-string i) "\n\n" - (format "%s" (car c)) "\t=>\n\n" - "Expected\n" (format "%s" expected) "\n\nActual\n" (format "%s" actual) "\n\n")) - (return 'fail)))))) + for i to (1- (length cases)) do + (let ((expected (cdr c)) + (actual (funcall fn (car c)))) + (when (not (equal expected actual)) + (princ + (concat "*** [FAIL] | \"" name "\" " (number-to-string i) "\n\n" + (format "%s" (car c)) "\t=>\n\n" + "Expected\n" (format "%s" expected) "\n\nActual\n" (format "%s" actual) "\n\n")) + (return 'fail)))))) (if (not (eql res 'fail)) (princ (concat " [PASS] | \"" name "\" " (number-to-string (length cases)) " tests.\n"))))) @@ -40,11 +40,11 @@ (defmacro define-emmet-transform-test-case (name fn &rest tests) `(emmet-test-cases 'assign ',name - ,fn - ',(loop for x on tests by #'cddr collect - (cons (car x) - (emmet-join-string (cadr x) - "\n"))))) + ,fn + ',(loop for x on tests by #'cddr collect + (cons (car x) + (emmet-join-string (cadr x) + "\n"))))) (defmacro define-emmet-transform-html-test-case (name &rest tests) `(define-emmet-transform-test-case ,name @@ -53,9 +53,9 @@ (defmacro define-emmet-unit-test-case (name fn &rest tests) `(emmet-test-cases 'assign ',name - ,fn - ',(loop for x on tests by #'cddr collect - (cons (car x) (cadr x))))) + ,fn + ',(loop for x on tests by #'cddr collect + (cons (car x) (cadr x))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; XML-abbrev tests @@ -119,8 +119,8 @@ " <li></li>" "</ol>") "ul#q.x.y[m=l]+" ("<ul id=\"q\" class=\"x y\" m=\"l\">" - " <li></li>" - "</ul>")) + " <li></li>" + "</ul>")) (define-emmet-transform-html-test-case Parent-child "a>b" ("<a href=\"\"><b></b></a>") @@ -296,15 +296,15 @@ "a#foo.bar.mu[x=y m=l]" ("<a id=\"foo\" class=\"bar mu\" href=\"\" x=\"y\" m=\"l\"></a>") "a/#foo.bar.mu[x=y m=l]" ("<a id=\"foo\" class=\"bar mu\" href=\"\" x=\"y\" m=\"l\"/>") "a[x=y]+b" ("<a href=\"\" x=\"y\"></a>" - "<b></b>") + "<b></b>") "a[x=y]+b[x=y]" ("<a href=\"\" x=\"y\"></a>" - "<b x=\"y\"></b>") + "<b x=\"y\"></b>") "a[x=y]>b" ("<a href=\"\" x=\"y\"><b></b></a>") "a[x=y]>b[x=y]" ("<a href=\"\" x=\"y\"><b x=\"y\"></b></a>") "a[x=y]>b[x=y]+c[x=y]" ("<a href=\"\" x=\"y\">" - " <b x=\"y\"></b>" - " <c x=\"y\"></c>" - "</a>")) + " <b x=\"y\"></b>" + " <c x=\"y\"></c>" + "</a>")) (define-emmet-transform-html-test-case Parentheses "(a)" ("<a href=\"\"></a>") @@ -432,8 +432,8 @@ "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]]") + " [:a {:href \"#\"}]" + " [:br]]") "#q>(a*2>b{x})+p>{m}+b|hic" ("[:div#q" @@ -552,9 +552,9 @@ "fs" ("font-style: italic;") "xxxxxx 0 auto 0e auto!" ("xxxxxx: 0px auto 0em auto !important;") "p auto+m auto+bg+#F00 x.jpg 10 10 repeat-x" - ("padding: auto;" - "margin: auto;" - "background: #F00 url(x.jpg) 10px 10px repeat-x;") + ("padding: auto;" + "margin: auto;" + "background: #F00 url(x.jpg) 10px 10px repeat-x;") "-bdrs" ("-webkit-border-radius: ;" "-moz-border-radius: ;" "border-radius: ;") @@ -570,7 +570,7 @@ " 1px" "}") "@i http://github.com/smihica/index.css" - ("@import url(http://github.com/smihica/index.css);") + ("@import url(http://github.com/smihica/index.css);") ) ;; lorem generator test @@ -599,8 +599,8 @@ (buffer-string)))) (emmet-run-test-case "Inline Expansion" - #'emmet-inline-expansion-test - '((("span#test") . "<div><span id=\"test\"></span></div>"))) + #'emmet-inline-expansion-test + '((("span#test") . "<div><span id=\"test\"></span></div>"))) ;; indent ;; NOTE: Indent uses indent-region by default, @@ -621,14 +621,14 @@ (let ((emmet-indent-after-insert t)) (emmet-run-test-case "Indentation via indent-region" - #'emmet-indent-test - '((("div>ul>li*3") . "<div>\n <ul>\n <li></li>\n <li></li>\n <li></li>\n </ul>\n</div>")))) + #'emmet-indent-test + '((("div>ul>li*3") . "<div>\n <ul>\n <li></li>\n <li></li>\n <li></li>\n </ul>\n</div>")))) (let ((emmet-indent-after-insert nil) (emmet-indentation 2)) (emmet-run-test-case "Indentation via emmet-indentation" - #'emmet-indent-test - '((("div>ul>li*3") . "<div>\n <ul>\n <li></li>\n <li></li>\n <li></li>\n </ul>\n</div>")))) + #'emmet-indent-test + '((("div>ul>li*3") . "<div>\n <ul>\n <li></li>\n <li></li>\n <li></li>\n </ul>\n</div>")))) ;; Old tests for previous indent behavior last seen: ;; commit: f56174e5905a40583b47f9737abee3af8da3faeb @@ -648,21 +648,21 @@ (buffer-string)))) (emmet-run-test-case "Wrap with markup on text with brackets and markup" - #'emmet-wrap-with-markup-test - '((("div>ul>li") . "<div>\n <ul>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n </ul>\n</div>"))) + #'emmet-wrap-with-markup-test + '((("div>ul>li") . "<div>\n <ul>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n </ul>\n</div>"))) (emmet-run-test-case "Wrap with markup multiplier" - #'emmet-wrap-with-markup-test - '((("div>ul>li*3") . "<div>\n <ul>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n </ul>\n</div>"))) + #'emmet-wrap-with-markup-test + '((("div>ul>li*3") . "<div>\n <ul>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n </ul>\n</div>"))) (emmet-run-test-case "Wrap with multiline content" - #'emmet-wrap-with-markup-test - '((("div>ul>li" "I am some\nmultiline\n text") . "<div>\n <ul>\n <li>I am some\n multiline\n text</li>\n </ul>\n</div>"))) + #'emmet-wrap-with-markup-test + '((("div>ul>li" "I am some\nmultiline\n text") . "<div>\n <ul>\n <li>I am some\n multiline\n text</li>\n </ul>\n</div>"))) (emmet-run-test-case "Wrap with per-line markup (trailing *)" #'emmet-wrap-with-markup-test '((("div>ul>li*" "I am some\nmultiline\n text") . - "<div>\n <ul>\n <li>I am some</li>\n <li>multiline</li>\n <li> text</li>\n </ul>\n</div>"))) + "<div>\n <ul>\n <li>I am some</li>\n <li>multiline</li>\n <li>text</li>\n </ul>\n</div>"))) ;; Regression test for #54 (broken emmet-find-left-bound behavior ;; after tag with attributes) @@ -679,12 +679,12 @@ (buffer-string)))) (emmet-run-test-case "Regression 54 with span" - #'emmet-regression-54-test - '((("span") . "<div class=\"broken\"><span></span>"))) + #'emmet-regression-54-test + '((("span") . "<div class=\"broken\"><span></span>"))) (emmet-run-test-case "Regression 54 with complex span" - #'emmet-regression-54-test - '((("span.whut[thing=\"stuff\"]{Huh?}") . "<div class=\"broken\"><span class=\"whut\" thing=\"stuff\">Huh?</span>"))) + #'emmet-regression-54-test + '((("span.whut[thing=\"stuff\"]{Huh?}") . "<div class=\"broken\"><span class=\"whut\" thing=\"stuff\">Huh?</span>"))) (define-emmet-transform-html-test-case regression-61-bracket-escapes "div{\\}\\}\\}}" ("<div>}}}</div>")) @@ -703,12 +703,12 @@ (buffer-string)))) (emmet-run-test-case "JSX's className 1" - #'emmet-expand-jsx-className?-test - '(((".jsx") . "<div className=\"jsx\"></div>"))) + #'emmet-expand-jsx-className?-test + '(((".jsx") . "<div className=\"jsx\"></div>"))) (emmet-run-test-case "JSX's className 2" - #'emmet-expand-jsx-className?-test - '(((".jsx>ul.lis>li.itm{x}*2") . "<div className=\"jsx\">\n <ul className=\"lis\">\n <li className=\"itm\">x</li>\n <li className=\"itm\">x</li>\n </ul>\n</div>"))) + #'emmet-expand-jsx-className?-test + '(((".jsx>ul.lis>li.itm{x}*2") . "<div className=\"jsx\">\n <ul className=\"lis\">\n <li className=\"itm\">x</li>\n <li className=\"itm\">x</li>\n </ul>\n</div>"))) (defun emmet-self-closing-tag-style-test (lis) (let ((es (car lis)) @@ -721,23 +721,23 @@ ;; By default, `emmet-self-closing-tag-style' must not break any test code. (emmet-run-test-case "Self closing tag style 1" - #'emmet-self-closing-tag-style-test - '((("meta") . "<meta/>"))) + #'emmet-self-closing-tag-style-test + '((("meta") . "<meta/>"))) (let ((emmet-self-closing-tag-style "/")) (emmet-run-test-case "Self closing tag style 2" - #'emmet-self-closing-tag-style-test - '((("meta") . "<meta/>")))) + #'emmet-self-closing-tag-style-test + '((("meta") . "<meta/>")))) (let ((emmet-self-closing-tag-style " /")) (emmet-run-test-case "Self closing tag style 3" - #'emmet-self-closing-tag-style-test - '((("meta") . "<meta />")))) + #'emmet-self-closing-tag-style-test + '((("meta") . "<meta />")))) (let ((emmet-self-closing-tag-style "")) (emmet-run-test-case "Self closing tag style 4" - #'emmet-self-closing-tag-style-test - '((("meta") . "<meta>")))) + #'emmet-self-closing-tag-style-test + '((("meta") . "<meta>")))) ;; start (emmet-test-cases) |