aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam David Mayo ("Dave") <pobocks@gmail.com>2014-08-10 18:21:37 -0400
committerWilliam David Mayo ("Dave") <pobocks@gmail.com>2014-08-10 18:21:37 -0400
commitf085c9e3c248358cb5bd06b1d8495fa8b0f35638 (patch)
treedf0d458fb0c47f3549d5c6bcb60d1d65e6a75e66
parent4ab83795aa00b0f8ff6ad97ca0d63e91ebe09628 (diff)
parente47b30a56de5fee21a029c5e9d168be744949d92 (diff)
downloademmet-mode-f085c9e3c248358cb5bd06b1d8495fa8b0f35638.tar.lz
emmet-mode-f085c9e3c248358cb5bd06b1d8495fa8b0f35638.tar.xz
emmet-mode-f085c9e3c248358cb5bd06b1d8495fa8b0f35638.zip
Merge pull request #30 from pobocks/issue_28
Issue 28 - This seems to work better and fail on less cases than the current code, anyway. I've seen some pausing when expanding hiccup inside Clojure code, but the existing code fails entirely in the same spot, so it's an improvement.
-rw-r--r--README.md52
-rw-r--r--emmet-mode.el68
-rw-r--r--src/html-abbrev.el12
-rw-r--r--src/mode-def.el56
-rw-r--r--src/test.el52
5 files changed, 124 insertions, 116 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 5ff158a..46c6c0d 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,28 @@ 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-char) (setq char (char-before)))
+ (t
+ (setq char nil))))
+ (point)))))
+
(defcustom emmet-indentation 4
"Number of spaces used for indentation."
:type '(number :tag "Spaces")
@@ -3531,17 +3541,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)
@@ -3559,7 +3563,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)
@@ -3666,7 +3670,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))
@@ -3759,7 +3763,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)
@@ -3846,7 +3850,7 @@ accept it or skip it."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun emmet-go-to-edit-point (count)
- (let
+ (let
((buf (buffer-string))
(point (point))
(edit-point "\\(\\(><\\)\\|\\(^[[:blank:]]+$\\)\\|\\(=\\(\"\\|'\\)\\{2\\}\\)\\)"))
@@ -3864,8 +3868,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/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=&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