diff options
author | smihica <smihica@gmail.com> | 2014-06-14 15:06:22 +0900 |
---|---|---|
committer | smihica <smihica@gmail.com> | 2014-06-14 15:06:22 +0900 |
commit | 6a0f56dd41ab92dcc08f41ef66eca06d7d37336d (patch) | |
tree | 5fefd5920caf1afa3a4323849a6c0ceb4692f608 | |
parent | bf76d717c60f33d223cdac35513105e9f9244885 (diff) | |
download | emmet-mode-6a0f56dd41ab92dcc08f41ef66eca06d7d37336d.tar.lz emmet-mode-6a0f56dd41ab92dcc08f41ef66eca06d7d37336d.tar.xz emmet-mode-6a0f56dd41ab92dcc08f41ef66eca06d7d37336d.zip |
Fixed issue-11 : Respect indent-tabs-mode.
-rw-r--r-- | emmet-mode.el | 14 | ||||
-rw-r--r-- | src/mode-def.el | 14 | ||||
-rw-r--r-- | src/test.el | 91 |
3 files changed, 78 insertions, 41 deletions
diff --git a/emmet-mode.el b/emmet-mode.el index 4052c82..2380aea 100644 --- a/emmet-mode.el +++ b/emmet-mode.el @@ -3481,11 +3481,15 @@ tbl)) :group 'emmet) (defun emmet-prettify (markup indent) - (let ((first-col (format (format "%%%ds" indent) "")) - (tab (format (format "%%%ds" emmet-indentation) ""))) - (concat first-col - (replace-regexp-in-string "\n" (concat "\n" first-col) - (replace-regexp-in-string " " tab markup))))) + (destructuring-bind (first-col tab) + (if indent-tabs-mode + (list (apply #'concat (loop for i from 1 to (/ indent tab-width) collect "\t")) "\t") + (list (format (format "%%%ds" indent) "") + (format (format "%%%ds" emmet-indentation) ""))) + (let ((internal-indent-1 " ")) + (concat first-col + (replace-regexp-in-string "\n" (concat "\n" first-col) + (replace-regexp-in-string internal-indent-1 tab markup)))))) (defvar emmet-use-css-transform nil "When true, transform Emmet snippets into CSS, instead of the usual HTML.") diff --git a/src/mode-def.el b/src/mode-def.el index 5ff77ff..fa01727 100644 --- a/src/mode-def.el +++ b/src/mode-def.el @@ -21,11 +21,15 @@ :group 'emmet) (defun emmet-prettify (markup indent) - (let ((first-col (format (format "%%%ds" indent) "")) - (tab (format (format "%%%ds" emmet-indentation) ""))) - (concat first-col - (replace-regexp-in-string "\n" (concat "\n" first-col) - (replace-regexp-in-string " " tab markup))))) + (destructuring-bind (first-col tab) + (if indent-tabs-mode + (list (apply #'concat (loop for i from 1 to (/ indent tab-width) collect "\t")) "\t") + (list (format (format "%%%ds" indent) "") + (format (format "%%%ds" emmet-indentation) ""))) + (let ((internal-indent-1 " ")) + (concat first-col + (replace-regexp-in-string "\n" (concat "\n" first-col) + (replace-regexp-in-string internal-indent-1 tab markup)))))) (defvar emmet-use-css-transform nil "When true, transform Emmet snippets into CSS, instead of the usual HTML.") diff --git a/src/test.el b/src/test.el index 3477192..ef2c90f 100644 --- a/src/test.el +++ b/src/test.el @@ -5,39 +5,38 @@ (emmet-defparameter *emmet-test-cases* nil) +(defun emmet-run-test-case (name fn cases) + (let ((res (loop for c in cases + for i to (1- (length cases)) do + (let ((expected (cdr c)) + (actual (funcall fn (car c)))) + (when (not (equal expected actual)) + (princ + (concat "*** [FAIL] | \"" name "\" " (number-to-string i) "\n\n" + (format "%s" (car c)) "\t=>\n\n" + "Expected\n" (format "%s" expected) "\n\nActual\n" (format "%s" actual) "\n\n")) + (return 'fail)))))) + (if (not (eql res 'fail)) + (princ (concat " [PASS] | \"" name "\" " + (number-to-string (length cases)) " tests.\n"))))) + (defun emmet-test-cases (&rest args) (let ((cmd (car args))) - (flet - ((run-cases - (fn cases) - (loop for c in cases - for i to (1- (length cases)) do - (let ((expected (cdr c)) - (actual (funcall fn (car c)))) - (when (not (equal expected actual)) - (princ - (concat "*** [FAIL] | \"" name "\" " (number-to-string i) "\n\n" - (format "%s" (car c)) "\t=>\n\n" - "Expected\n" (format "%s" expected) "\n\nActual\n" (format "%s" actual) "\n\n")) - (return 'fail)))))) - (cond ((eql cmd 'assign) - (let ((name (cadr args)) - (fn (caddr args)) - (defs (cadddr args))) - (let ((place (assoc name *emmet-test-cases*))) - (if place - (setf (cdr place) (cons fn defs)) - (setq *emmet-test-cases* - (cons (cons name (cons fn defs)) *emmet-test-cases*)))))) - (t - (loop for test in (reverse *emmet-test-cases*) do - (let ((name (symbol-name (car test))) - (fn (cadr test)) - (cases (cddr test))) - (let ((res (run-cases fn cases))) - (if (not (eql res 'fail)) - (princ (concat " [PASS] | \"" name "\" " - (number-to-string (length cases)) " tests.\n"))))))))))) + (cond ((eql cmd 'assign) + (let ((name (cadr args)) + (fn (caddr args)) + (defs (cadddr args))) + (let ((place (assoc name *emmet-test-cases*))) + (if place + (setf (cdr place) (cons fn defs)) + (setq *emmet-test-cases* + (cons (cons name (cons fn defs)) *emmet-test-cases*)))))) + (t + (loop for test in (reverse *emmet-test-cases*) do + (let ((name (symbol-name (car test))) + (fn (cadr test)) + (cases (cddr test))) + (emmet-run-test-case name fn cases))))))) (defmacro define-emmet-transform-test-case (name fn &rest tests) `(emmet-test-cases 'assign ',name @@ -575,5 +574,35 @@ (concat "*** [FAIL] | \"" name "\".\n") (concat " [PASS] | \"" name "\" 5 tests.\n")))) + +(defun emmet-prettify-test (lis) + (emmet-prettify (car lis) (cadr lis))) + +;; indent +(setq-default indent-tabs-mode nil) +(emmet-run-test-case "Indent-1" + #'emmet-prettify-test + '((("<html>" 0) . "<html>") + (("<html>" 1) . " <html>") + (("<html>" 4) . " <html>") + (("<html>" 8) . " <html>") + (("<html>\n <body></body>\n</html>" 1) . " <html>\n <body></body>\n </html>"))) +(setq-default emmet-indentation 8) +(emmet-run-test-case "Indent-2" + #'emmet-prettify-test + '((("<html>\n <body></body>\n</html>" 0) . "<html>\n <body></body>\n</html>") + (("<html>\n <body></body>\n</html>" 4) . " <html>\n <body></body>\n </html>"))) +(setq-default indent-tabs-mode t) +(setq-default tab-width 2) +(emmet-run-test-case "Indent-3" + #'emmet-prettify-test + '((("<html>\n <body></body>\n</html>" 0) . "<html>\n\t<body></body>\n</html>") + (("<html>\n <body></body>\n</html>" 4) . "\t\t<html>\n\t\t\t<body></body>\n\t\t</html>"))) +(setq-default tab-width 1) +(emmet-run-test-case "Indent-4" + #'emmet-prettify-test + '((("<html>\n <body></body>\n</html>" 0) . "<html>\n\t<body></body>\n</html>") + (("<html>\n <body></body>\n</html>" 4) . "\t\t\t\t<html>\n\t\t\t\t\t<body></body>\n\t\t\t\t</html>"))) + ;; start (emmet-test-cases) |