aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Mayo <dave_mayo@harvard.edu>2014-08-08 17:38:20 -0400
committerDave Mayo <pobocks@gmail.com>2014-08-10 15:58:08 -0400
commitbee781f7e31c2f6591239fbb0271c4a96b48ecd6 (patch)
treea204fbb599e512711778a764255cdd3c280ba14c
parent09c2f6381bb6313d0472cbc77724964e2b554c24 (diff)
downloademmet-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
-rw-r--r--README.md52
-rw-r--r--emmet-mode.el51
-rw-r--r--src/html-abbrev.el12
-rw-r--r--src/mode-def.el39
-rw-r--r--src/test.el52
5 files changed, 104 insertions, 102 deletions
diff --git a/README.md b/README.md
index 69211b3..dea9958 100644
--- a/README.md
+++ b/README.md
@@ -93,7 +93,7 @@ you'll transform your snippet into the appropriate tag structure.
#### Self-closing tags
- input type=text <input type="text" name="" value=""/>
+ input[type=text] <input type="text" name="" value=""/>
img <img src="" alt=""/>
img>metadata/*2 <img src="" alt="">
<metadata/>
@@ -137,7 +137,7 @@ you'll transform your snippet into the appropriate tag structure.
<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>
@@ -267,27 +267,27 @@ you'll transform your snippet into the appropriate tag structure.
#### Properties
- b x <b x=""></b>
- b x= <b x=""></b>
- b x="" <b x=""></b>
- b x=y <b x="y"></b>
- b x="y" <b x="y"></b>
- b x="()" <b x="()"></b>
- b x m <b x="" m=""></b>
- b x= m="" <b x="" m=""></b>
- b x=y m=l <b x="y" m="l"></b>
- b/ x=y m=l <b x="y" m="l"/>
- b#foo x=y m=l <b id="foo" x="y" m="l"></b>
- b.foo x=y m=l <b class="foo" x="y" m="l"></b>
- b#foo.bar.mu x=y m=l <b id="foo" class="bar mu" x="y" m="l"></b>
- b/#foo.bar.mu x=y m=l <b id="foo" class="bar mu" x="y" m="l"/>
- b x=y+b <b x="y"></b>
+ b[x] <b x=""></b>
+ b[x=] <b x=""></b>
+ b[x=""] <b x=""></b>
+ b[x=y] <b x="y"></b>
+ b[x="y"] <b x="y"></b>
+ b[x="()"] <b x="()"></b>
+ b[x m] <b x="" m=""></b>
+ b[x= m=""] <b x="" m=""></b>
+ b[x=y m=l] <b x="y" m="l"></b>
+ b/[x=y m=l] <b x="y" m="l"/>
+ b#foo[x=y m=l] <b id="foo" x="y" m="l"></b>
+ b.foo[x=y m=l] <b class="foo" x="y" m="l"></b>
+ b#foo.bar.mu[x=y m=l] <b id="foo" class="bar mu" x="y" m="l"></b>
+ b/#foo.bar.mu[x=y m=l] <b id="foo" class="bar mu" x="y" m="l"/>
+ b[x=y]+b <b x="y"></b>
<b></b>
- b x=y+b x=y <b x="y"></b>
+ b[x=y]+b[x=y] <b x="y"></b>
<b x="y"></b>
- b x=y>b <b x="y"><b></b></b>
- b x=y>b x=y <b x="y"><b x="y"></b></b>
- b x=y>b x=y+c x=y <b x="y">
+ b[x=y]>b <b x="y"><b></b></b>
+ b[x=y]>b[x=y] <b x="y"><b x="y"></b></b>
+ b[x=y]>b[x=y]+c[x=y] <b x="y">
<b x="y"></b>
<c x="y"></c>
</b>
@@ -387,11 +387,11 @@ you'll transform your snippet into the appropriate tag structure.
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>{txt}+a href=#+br|haml %p
+ p>{txt}+a[href=#]+br|haml %p
txt
%a{:href => "#"}
%br
@@ -400,9 +400,9 @@ you'll transform your snippet into the appropriate tag structure.
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]]
#q>(a*2>b{x})+p>b|hic [:div#q
@@ -413,7 +413,7 @@ you'll transform your snippet into the appropriate tag structure.
#### Filter: escape
- script src=&quot;|e &lt;script src="&amp;quot;"&gt;
+ script[src=&quot;]|e &lt;script src="&amp;quot;"&gt;
&lt;/script&gt;
#### Aliases
diff --git a/emmet-mode.el b/emmet-mode.el
index 462adf2..c1f5d80 100644
--- a/emmet-mode.el
+++ b/emmet-mode.el
@@ -2538,7 +2538,7 @@ tbl))
`(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))
@@ -2617,7 +2617,7 @@ tbl))
(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))))
@@ -2631,7 +2631,7 @@ tbl))
(defun emmet-prop (input)
(emmet-parse
- " " 1 "space"
+ " *" 1 "space"
(emmet-run
emmet-name
(let ((name (cdr expr)))
@@ -2675,6 +2675,12 @@ tbl))
(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 "("
@@ -3473,24 +3479,25 @@ tbl))
(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")
@@ -3531,16 +3538,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
@@ -3666,7 +3667,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/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=&quot;|e" ("&lt;script src=\"&amp;quot;\"&gt;&lt;/script&gt;"))
+ "script[src=&quot;]|e" ("&lt;script src=\"&amp;quot;\"&gt;&lt;/script&gt;"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CSS-abbrev tests