diff options
author | Dave Mayo <dave_mayo@harvard.edu> | 2014-08-08 17:38:20 -0400 |
---|---|---|
committer | Dave Mayo <pobocks@gmail.com> | 2014-08-10 15:58:08 -0400 |
commit | bee781f7e31c2f6591239fbb0271c4a96b48ecd6 (patch) | |
tree | a204fbb599e512711778a764255cdd3c280ba14c /src | |
parent | 09c2f6381bb6313d0472cbc77724964e2b554c24 (diff) | |
download | emmet-mode-bee781f7e31c2f6591239fbb0271c4a96b48ecd6.tar.lz emmet-mode-bee781f7e31c2f6591239fbb0271c4a96b48ecd6.tar.xz emmet-mode-bee781f7e31c2f6591239fbb0271c4a96b48ecd6.zip |
Changes to come closer to Emmet support, to allow for better consistency of behavior.
Major changes include:
* Parser is changed to use Emmet's bracket syntax for properties
* now uses point as the right bound of the expression
* searches for left bound from right bound. This is poorly executed as of now
Diffstat (limited to 'src')
-rw-r--r-- | src/html-abbrev.el | 12 | ||||
-rw-r--r-- | src/mode-def.el | 39 | ||||
-rw-r--r-- | src/test.el | 52 |
3 files changed, 52 insertions, 51 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 e8060a6..cef6151 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -8,24 +8,25 @@ (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-word) (setq char (char-before))) + (t (setq char nil)))) + (point))))) + (defcustom emmet-indentation 4 "Number of spaces used for indentation." :type '(number :tag "Spaces") @@ -66,16 +67,10 @@ 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)) + (emmet-find-left-bound) (when (use-region-p) (region-beginning)))) (end (if preview - (progn - (end-of-line) - (skip-chars-backward " \t") - (point)) + here (when (use-region-p) (region-end))))) (if (and preview beg) (progn @@ -201,7 +196,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)) 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 |