diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/html-abbrev.el | 12 | ||||
-rw-r--r-- | src/mode-def.el | 56 | ||||
-rw-r--r-- | src/test.el | 52 |
3 files changed, 62 insertions, 58 deletions
diff --git a/src/html-abbrev.el b/src/html-abbrev.el index 7dbf842..0c5411c 100644 --- a/src/html-abbrev.el +++ b/src/html-abbrev.el @@ -154,7 +154,7 @@ `(tag (,tagname ,has-body? nil)) input)) (let ((tag-data (cadar it)) (input (cdr it))) (emmet-pif (emmet-run - emmet-props + emmet-properties (let ((props (cdr expr))) `((tag ,(append tag-data (list props))) . ,input)) `((tag ,(append tag-data '(nil))) . ,input)) @@ -233,7 +233,7 @@ (defun emmet-tag-props (tag input) (let ((tag-data (cadr tag))) - (emmet-run emmet-props + (emmet-run emmet-properties (let ((props (cdr expr))) `((tag ,(append tag-data (list props))) . ,input)) `((tag ,(append tag-data '(nil))) . ,input)))) @@ -247,7 +247,7 @@ (defun emmet-prop (input) (emmet-parse - " " 1 "space" + " *" 1 "space" (emmet-run emmet-name (let ((name (cdr expr))) @@ -291,6 +291,12 @@ (let ((txt (emmet-split-numbering-expressions (elt it 1)))) `((text ,txt) . ,input)))) +(defun emmet-properties (input) + "A bracketed emmet property expression." + (emmet-parse "\\[\\(.*?\\)\\]" 2 "properties" + `(,(car (emmet-props (elt it 1))) . ,input))) + + (defun emmet-pexpr (input) "A zen coding expression with parentheses around it." (emmet-parse "(" 1 "(" diff --git a/src/mode-def.el b/src/mode-def.el index e84bf96..6d7aebc 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -8,24 +8,28 @@ (defun emmet-expr-on-line () "Extract a emmet expression and the corresponding bounds for the current line." - (let* ((start (line-beginning-position)) - (end (line-end-position)) + (let* ((end (point)) + (start (emmet-find-left-bound)) (line (buffer-substring-no-properties start end))) - (save-excursion - (save-match-data - (let ((bound (point))) - (goto-char start) - (if (re-search-forward "\\(\\([ \t]+\\)?<[^>]*?>\\)+" bound t) - (progn - (setq start (match-end 0)) - (setq end bound) - (setq line (buffer-substring-no-properties start end)) - ) - )))) (let ((expr (emmet-regex "\\([ \t]*\\)\\([^\n]+\\)" line 2))) (if (first expr) (list (first expr) start end))))) +(defun emmet-find-left-bound () + "Find the left bound of an emmet expr" + (save-excursion (save-match-data + (let ((char (char-before))) + (while char + (cond ((member char '(?\} ?\] ?\))) + (backward-sexp) (setq char (char-before))) + ((member char '(?\<)) + (search-forward ">") (setq char nil)) + ((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." :type '(number :tag "Spaces") @@ -66,17 +70,11 @@ For more information see `emmet-mode'." (let* ((here (point)) (preview (if emmet-preview-default (not arg) arg)) (beg (if preview - (progn - (beginning-of-line) - (skip-chars-forward " \t") - (point)) - (when mark-active (region-beginning)))) + (emmet-find-left-bound) + (when (use-region-p) (region-beginning)))) (end (if preview - (progn - (end-of-line) - (skip-chars-backward " \t") - (point)) - (when mark-active (region-end))))) + here + (when (use-region-p) (region-end))))) (if (and preview beg) (progn (goto-char here) @@ -94,7 +92,7 @@ For more information see `emmet-mode'." (+ (- p (length output-markup)) (emmet-html-next-insert-point output-markup))))))))))))) -(defvar emmet-mode-keymap +(defvar emmet-mode-keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "C-j") 'emmet-expand-line) @@ -201,7 +199,7 @@ See also `emmet-expand-line'." (let* ((indent (current-indentation)) (markup (emmet-preview-transformed indent))) (when markup - (delete-region (line-beginning-position) (overlay-end ovli)) + (delete-region (overlay-start ovli) (overlay-end ovli)) (emmet-insert-and-flash markup) (let ((output-markup (buffer-substring-no-properties (line-beginning-position) (point)))) (when (and emmet-move-cursor-after-expanding (emmet-html-text-p markup)) @@ -294,7 +292,7 @@ cursor position will be moved to after the first quote." "Expand emmet between BEG and END interactively. This will show a preview of the expanded emmet code and you can accept it or skip it." - (interactive (if mark-active + (interactive (if (use-region-p) (list (region-beginning) (region-end)) (list nil nil))) (emmet-preview-abort) @@ -381,7 +379,7 @@ accept it or skip it." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun emmet-go-to-edit-point (count) - (let + (let ((buf (buffer-string)) (point (point)) (edit-point "\\(\\(><\\)\\|\\(^[[:blank:]]+$\\)\\|\\(=\\(\"\\|'\\)\\{2\\}\\)\\)")) @@ -399,8 +397,8 @@ accept it or skip it." (backward-char)))) (progn (backward-char) - (let - ((search-result (re-search-backward edit-point nil t (- count)))) + (let + ((search-result (re-search-backward edit-point nil t (- count)))) (if search-result (progn (cond diff --git a/src/test.el b/src/test.el index 055be6c..69c5a3c 100644 --- a/src/test.el +++ b/src/test.el @@ -118,7 +118,7 @@ "<ol>" " <li></li>" "</ol>") - "ul#q.x.y m=l+" ("<ul id=\"q\" class=\"x y\" m=\"l\">" + "ul#q.x.y[m=l]+" ("<ul id=\"q\" class=\"x y\" m=\"l\">" " <li></li>" "</ul>")) @@ -270,27 +270,27 @@ "</ul>")) (define-emmet-transform-html-test-case Properties - "a x" ("<a href=\"\" x=\"\"></a>") - "a x=" ("<a href=\"\" x=\"\"></a>") - "a x=\"\"" ("<a href=\"\" x=\"\"></a>") - "a x=y" ("<a href=\"\" x=\"y\"></a>") - "a x=\"y\"" ("<a href=\"\" x=\"y\"></a>") - "a x=\"()\"" ("<a href=\"\" x=\"()\"></a>") - "a x m" ("<a href=\"\" x=\"\" m=\"\"></a>") - "a x= m=\"\"" ("<a href=\"\" x=\"\" m=\"\"></a>") - "a x=y m=l" ("<a href=\"\" x=\"y\" m=\"l\"></a>") - "a/ x=y m=l" ("<a href=\"\" x=\"y\" m=\"l\"/>") - "a#foo x=y m=l" ("<a id=\"foo\" href=\"\" x=\"y\" m=\"l\"></a>") - "a.foo x=y m=l" ("<a class=\"foo\" 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>") - "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>" + "a[x]" ("<a href=\"\" x=\"\"></a>") + "a[x=]" ("<a href=\"\" x=\"\"></a>") + "a[x=\"\"]" ("<a href=\"\" x=\"\"></a>") + "a[x=y]" ("<a href=\"\" x=\"y\"></a>") + "a[x=\"y\"]" ("<a href=\"\" x=\"y\"></a>") + "a[x=\"()\"]" ("<a href=\"\" x=\"()\"></a>") + "a[x m]" ("<a href=\"\" x=\"\" m=\"\"></a>") + "a[x= m=\"\"]" ("<a href=\"\" x=\"\" m=\"\"></a>") + "a[x=y m=l]" ("<a href=\"\" x=\"y\" m=\"l\"></a>") + "a/[x=y m=l]" ("<a href=\"\" x=\"y\" m=\"l\"/>") + "a#foo[x=y m=l]" ("<a id=\"foo\" href=\"\" x=\"y\" m=\"l\"></a>") + "a.foo[x=y m=l]" ("<a class=\"foo\" 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>") + "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>") - "a x=y+b x=y" ("<a href=\"\" x=\"y\"></a>" + "a[x=y]+b[x=y]" ("<a href=\"\" x=\"y\"></a>" "<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\">" + "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>")) @@ -346,7 +346,7 @@ "<a href=\"\">here</a>" " to continue") - "xxx#id.cls p=1{txt}" + "xxx#id.cls[p=1]{txt}" ("<xxx id=\"id\" class=\"cls\" p=\"1\">txt</xxx>")) (define-emmet-unit-test-case Lorem-ipsum @@ -403,12 +403,12 @@ (define-emmet-transform-html-test-case 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\"}") + "a#q.x[x=y m=l]|haml" ("%a#q.x{:x => \"y\", :m => \"l\"}") "div|haml" ("%div") "div.footer|haml" (".footer") ".footer|haml" (".footer") - "p>{This is haml}*2+a href=#+br|haml" + "p>{This is haml}*2+a[href=#]+br|haml" ("%p" " This is haml" " This is haml" @@ -418,9 +418,9 @@ (define-emmet-transform-html-test-case 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\"}]") + "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" + "p>a[href=#]+br|hic" ("[:p" " [:a {:href \"#\"}]" " [:br]]") @@ -433,7 +433,7 @@ " [:b]]]")) (define-emmet-transform-html-test-case Filter-escape - "script src="|e" ("<script src=\"&quot;\"></script>")) + "script[src="]|e" ("<script src=\"&quot;\"></script>")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; CSS-abbrev tests |