aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mode-def.el29
-rw-r--r--src/test.el26
2 files changed, 52 insertions, 3 deletions
diff --git a/src/mode-def.el b/src/mode-def.el
index 7cac58d..e0a22b9 100644
--- a/src/mode-def.el
+++ b/src/mode-def.el
@@ -127,6 +127,7 @@ For more information see `emmet-mode'."
(define-key map (kbd "<C-return>") 'emmet-expand-line)
(define-key map (kbd "<C-M-right>") 'emmet-next-edit-point)
(define-key map (kbd "<C-M-left>") 'emmet-prev-edit-point)
+ (define-key map (kbd "C-c w") 'emmet-wrap-with-markup)
map)
"Keymap for emmet minor mode.")
@@ -392,9 +393,14 @@ accept it or skip it."
((between-tags
(if only-before-closed-tag "\\(><\\)/" "\\(><\\)"))
(indented-line "\\(^[[:blank:]]+$\\)")
- (between-quotes "\\(=\\(\"\\|'\\)\\{2\\}\\)")
- (edit-point (format "\\(%s\\|%s\\|%s\\)"
- between-tags indented-line between-quotes)))
+ (between-quotes
+ (if emmet-move-cursor-between-quotes "\\(=\\(\"\\|'\\)\\{2\\}\\)" nil))
+ (whole-regex
+ (mapconcat 'identity
+ (delq nil
+ (list between-tags indented-line between-quotes))
+ "\\|"))
+ (edit-point (format "\\(%s\\)" whole-regex)))
(if (> count 0)
(progn
(forward-char)
@@ -422,6 +428,23 @@ accept it or skip it."
(forward-char)))))))
;;;###autoload
+(defun emmet-wrap-with-markup (wrap-with)
+ "Wrap region with markup."
+ (interactive "sExpression to wrap with: ")
+ (let* ((emmet-move-cursor-between-quotes nil)
+ (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)))
+ (when markup
+ (delete-region (region-beginning) (region-end))
+ (insert markup)
+ (indent-region (region-beginning) (region-end))
+ )))
+
+;;;###autoload
(defun emmet-next-edit-point (count)
(interactive "^p")
(unless (or emmet-use-css-transform (emmet-go-to-edit-point count))
diff --git a/src/test.el b/src/test.el
index 69c5a3c..28b7db4 100644
--- a/src/test.el
+++ b/src/test.el
@@ -622,5 +622,31 @@
;; Old tests for previous indent behavior last seen:
;; commit: f56174e5905a40583b47f9737abee3af8da3faeb
+(defun emmet-wrap-with-markup-test (lis)
+ (let ((es (car lis))
+ (ins (or (elt lis 1) "This is gnarly text with $$$s and <span>markup</span> and end brackets}}s"))
+ (indent-tabs-mode nil)
+ (tab-width 2)
+ (standard-indent 2))
+ (with-temp-buffer
+ (emmet-mode 1)
+ (sgml-mode)
+ (set-mark (point))
+ (insert ins)
+ (emmet-wrap-with-markup es)
+ (buffer-string))))
+
+(emmet-run-test-case "Wrap with markup on text with brackets and markup"
+ #'emmet-wrap-with-markup-test
+ '((("div>ul>li") . "<div>\n <ul>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n </ul>\n</div>")))
+
+(emmet-run-test-case "Wrap with markup multiplier"
+ #'emmet-wrap-with-markup-test
+ '((("div>ul>li*3") . "<div>\n <ul>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n <li>This is gnarly text with $$$s and <span>markup</span> and end brackets}}s</li>\n </ul>\n</div>")))
+
+(emmet-run-test-case "Wrap with multiline content"
+ #'emmet-wrap-with-markup-test
+ '((("div>ul>li" "I am some\nmultiline\n text") . "<div>\n <ul>\n <li>I am some\n multiline\n text</li>\n </ul>\n</div>")))
+
;; start
(emmet-test-cases)