aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Mayo <dave_mayo@harvard.edu>2016-09-05 23:53:01 -0400
committerDave Mayo <dave_mayo@harvard.edu>2016-09-06 00:07:43 -0400
commit1a64b7dfece4357df0b0d96929225057951fe781 (patch)
treeaf07641cd1b9d669521c80ee5b3a641cd3789dd0
parent3c2d5c3e86c317601cbf8d976c5611b8c73ac178 (diff)
downloademmet-mode-1a64b7dfece4357df0b0d96929225057951fe781.tar.lz
emmet-mode-1a64b7dfece4357df0b0d96929225057951fe781.tar.xz
emmet-mode-1a64b7dfece4357df0b0d96929225057951fe781.zip
Added multi-line * wrap functionality as per #81
This is a proof-of-concept - it needs to do the token-replacement jazz the original version did, because right now this will fail if the content of the txt/lines includes unmatched braces in various configurations. I think the overall plan is sound: split expression into leading and terminal components, render the text as a list (either a one-element list of all text or a multiline list, depending on trailing *), and create a terminal phrase consisting of "terminal-element{TOKEN}" joined on "+" To do: render list into a-list of '((hash-of-txt . txt), ...), mapconcat the hash replacement instead of the text, then run replace over result. Write tests. Also, tests appear to be broken on master, at least on my machine.
-rw-r--r--emmet-mode.el23
-rw-r--r--src/mode-def.el23
2 files changed, 30 insertions, 16 deletions
diff --git a/emmet-mode.el b/emmet-mode.el
index 5c2bdee..2e03c94 100644
--- a/emmet-mode.el
+++ b/emmet-mode.el
@@ -172,7 +172,7 @@ and leaving the point in place."
"Find the left bound of an emmet expr"
(save-excursion (save-match-data
(let ((char (char-before))
- (in-style-attr (looking-back "style=[\"'][^\"']*"))
+ (in-style-attr (looking-back "style=[\"'][^\"']*" nil))
(syn-tab (make-syntax-table)))
(modify-syntax-entry ?\\ "\\")
(while char
@@ -627,12 +627,20 @@ accept it or skip it."
(defun emmet-wrap-with-markup (wrap-with)
"Wrap region with markup."
(interactive "sExpression to wrap with: ")
- (let* ((to-wrap (buffer-substring-no-properties (region-beginning) (region-end)))
- (expr (concat wrap-with ">{!EMMET-TO-WRAP-REPLACEMENT!}"))
- (markup (replace-regexp-in-string
- "!EMMET-TO-WRAP-REPLACEMENT!" to-wrap
- (emmet-transform expr)
- t t)))
+ (let* ((multi (string-match "\\*$" wrap-with))
+ (txt (buffer-substring-no-properties (region-beginning) (region-end)))
+ (to-wrap (if multi
+ (split-string txt "\n")
+ (list txt)))
+ (initial-elements (replace-regexp-in-string "\\(.*>\\)?[^>*]+\\*?$" "\\1" wrap-with))
+ (terminal-element (replace-regexp-in-string "\\(.*>\\)?\\([^>*]+\\)\\*?$" "\\2" wrap-with))
+ (expr (concat
+ initial-elements
+ (mapconcat (lambda (el) (concat terminal-element "{" el "}")) to-wrap "+")))
+
+ (markup (emmet-transform expr))
+ (debug-shit (message "initial-elements: %s\nterminal-element: %s\n expr: %s\n markup: %s" initial-elements terminal-element expr markup))
+ )
(when markup
(delete-region (region-beginning) (region-end))
(insert markup)
@@ -656,7 +664,6 @@ accept it or skip it."
(error "First edit point reached.")))
(provide 'emmet-mode)
-
;; src/snippets.el
;; This file is generated from conf/snippets.json
;; Don't edit.
diff --git a/src/mode-def.el b/src/mode-def.el
index 104ace2..1b4358e 100644
--- a/src/mode-def.el
+++ b/src/mode-def.el
@@ -19,7 +19,7 @@
"Find the left bound of an emmet expr"
(save-excursion (save-match-data
(let ((char (char-before))
- (in-style-attr (looking-back "style=[\"'][^\"']*"))
+ (in-style-attr (looking-back "style=[\"'][^\"']*" nil))
(syn-tab (make-syntax-table)))
(modify-syntax-entry ?\\ "\\")
(while char
@@ -474,12 +474,20 @@ accept it or skip it."
(defun emmet-wrap-with-markup (wrap-with)
"Wrap region with markup."
(interactive "sExpression to wrap with: ")
- (let* ((to-wrap (buffer-substring-no-properties (region-beginning) (region-end)))
- (expr (concat wrap-with ">{!EMMET-TO-WRAP-REPLACEMENT!}"))
- (markup (replace-regexp-in-string
- "!EMMET-TO-WRAP-REPLACEMENT!" to-wrap
- (emmet-transform expr)
- t t)))
+ (let* ((multi (string-match "\\*$" wrap-with))
+ (txt (buffer-substring-no-properties (region-beginning) (region-end)))
+ (to-wrap (if multi
+ (split-string txt "\n")
+ (list txt)))
+ (initial-elements (replace-regexp-in-string "\\(.*>\\)?[^>*]+\\*?$" "\\1" wrap-with))
+ (terminal-element (replace-regexp-in-string "\\(.*>\\)?\\([^>*]+\\)\\*?$" "\\2" wrap-with))
+ (expr (concat
+ initial-elements
+ (mapconcat (lambda (el) (concat terminal-element "{" el "}")) to-wrap "+")))
+
+ (markup (emmet-transform expr))
+ (debug-shit (message "initial-elements: %s\nterminal-element: %s\n expr: %s\n markup: %s" initial-elements terminal-element expr markup))
+ )
(when markup
(delete-region (region-beginning) (region-end))
(insert markup)
@@ -503,4 +511,3 @@ accept it or skip it."
(error "First edit point reached.")))
(provide 'emmet-mode)
-