aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflyingleafe <flyingleafe@gmail.com>2014-08-25 03:11:34 +0600
committerDave Mayo <pobocks@gmail.com>2014-08-24 19:00:12 -0400
commit8a6a20a28d0805d37676fc548bef32891cbb5431 (patch)
tree89a09ee2746d5716e6d5c98cb97d9be0500c3b44
parentec4d63f31c41941af3e85f9493ebc5cfed8be90e (diff)
downloademmet-mode-8a6a20a28d0805d37676fc548bef32891cbb5431.tar.lz
emmet-mode-8a6a20a28d0805d37676fc548bef32891cbb5431.tar.xz
emmet-mode-8a6a20a28d0805d37676fc548bef32891cbb5431.zip
Added support of CSS snippets expanding inside style tags and attrs
Conflicts: emmet-mode.el src/mode-def.el
-rw-r--r--emmet-mode.el27
-rw-r--r--src/mode-def.el27
2 files changed, 40 insertions, 14 deletions
diff --git a/emmet-mode.el b/emmet-mode.el
index 8263b16..991c68e 100644
--- a/emmet-mode.el
+++ b/emmet-mode.el
@@ -3499,18 +3499,21 @@ tbl))
for the current line."
(let* ((end (point))
(start (emmet-find-left-bound))
- (line (buffer-substring-no-properties start end)))
- (let ((expr (emmet-regex "\\([ \t]*\\)\\([^\n]+\\)" line 2)))
- (if (first expr)
- (list (first expr) start end)))))
+ (line (buffer-substring-no-properties start end))
+ (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))
- (last-gt (point)))
+ (last-gt (point))
+ (in-style-attr (looking-back "style=\"[^\"]*")))
(while char
- (cond ((member char '(?\} ?\] ?\)))
+ (cond ((and in-style-attr (eq char ?\"))
+ (setq char nil))
+ ((member char '(?\} ?\] ?\)))
(with-syntax-table (standard-syntax-table)
(backward-sexp) (setq char (char-before))))
((eq char ?\>)
@@ -3551,7 +3554,7 @@ e. g. without semicolons")
"Major modes that use emmet for CSS, rather than HTML.")
(defun emmet-transform (input)
- (if emmet-use-css-transform
+ (if (or (emmet-detect-style-tag-and-attr) emmet-use-css-transform)
(emmet-css-transform input)
(emmet-html-transform input)))
@@ -3566,6 +3569,16 @@ e. g. without semicolons")
(+ (- p (length output-markup))
new-pos))))))
+(defun emmet-detect-style-tag-and-attr ()
+ (let* ((qt "\"")
+ (not-qt (format "[^%s]" qt))
+ (everything "\\(.\\|\n\\)*"))
+ (or
+ (and (looking-at (format "%s*%s" not-qt qt))
+ (looking-back (format "style=%s%s*" qt not-qt))) ; style attr
+ (and (looking-at (format "%s</style>" everything))
+ (looking-back (format "<style>%s" everything)))))) ; style tag
+
;;;###autoload
(defun emmet-expand-line (arg)
"Replace the current line's emmet expression with the corresponding expansion.
diff --git a/src/mode-def.el b/src/mode-def.el
index 6a7f5aa..78c9fa4 100644
--- a/src/mode-def.el
+++ b/src/mode-def.el
@@ -10,18 +10,21 @@
for the current line."
(let* ((end (point))
(start (emmet-find-left-bound))
- (line (buffer-substring-no-properties start end)))
- (let ((expr (emmet-regex "\\([ \t]*\\)\\([^\n]+\\)" line 2)))
- (if (first expr)
- (list (first expr) start end)))))
+ (line (buffer-substring-no-properties start end))
+ (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))
- (last-gt (point)))
+ (last-gt (point))
+ (in-style-attr (looking-back "style=\"[^\"]*")))
(while char
- (cond ((member char '(?\} ?\] ?\)))
+ (cond ((and in-style-attr (eq char ?\"))
+ (setq char nil))
+ ((member char '(?\} ?\] ?\)))
(with-syntax-table (standard-syntax-table)
(backward-sexp) (setq char (char-before))))
((eq char ?\>)
@@ -62,7 +65,7 @@ e. g. without semicolons")
"Major modes that use emmet for CSS, rather than HTML.")
(defun emmet-transform (input)
- (if emmet-use-css-transform
+ (if (or (emmet-detect-style-tag-and-attr) emmet-use-css-transform)
(emmet-css-transform input)
(emmet-html-transform input)))
@@ -77,6 +80,16 @@ e. g. without semicolons")
(+ (- p (length output-markup))
new-pos))))))
+(defun emmet-detect-style-tag-and-attr ()
+ (let* ((qt "\"")
+ (not-qt (format "[^%s]" qt))
+ (everything "\\(.\\|\n\\)*"))
+ (or
+ (and (looking-at (format "%s*%s" not-qt qt))
+ (looking-back (format "style=%s%s*" qt not-qt))) ; style attr
+ (and (looking-at (format "%s</style>" everything))
+ (looking-back (format "<style>%s" everything)))))) ; style tag
+
;;;###autoload
(defun emmet-expand-line (arg)
"Replace the current line's emmet expression with the corresponding expansion.