From ff330530123a9e3f6fbb2d0fe52564e4e3d78369 Mon Sep 17 00:00:00 2001 From: Simen Heggestøyl Date: Fri, 13 Oct 2017 21:48:12 +0200 Subject: Fix indentation bug in multi-line CSS selectors * lisp/textmodes/css-mode.el (css--colon-inside-selector-p): Fix indentation of multi-line CSS selectors that include both a pseudo-class and parenthesis. * test/manual/indent/css-mode.css: Add test for the above change. --- test/manual/indent/css-mode.css | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/manual/indent/css-mode.css') diff --git a/test/manual/indent/css-mode.css b/test/manual/indent/css-mode.css index bf612b53a14..640418b022d 100644 --- a/test/manual/indent/css-mode.css +++ b/test/manual/indent/css-mode.css @@ -66,6 +66,16 @@ div::before { ); } +/* Multi-line selector including both a pseudo-class and + parenthesis. */ +.form-group:not(.required) label, +.birth-date .row > * { + &::after { + display: inline; + font-weight: normal; + } +} + @font-face { src: url("Sans-Regular.eot") format("eot"), url("Sans-Regular.woff") format("woff"), -- cgit v1.2.3 From 26ee371d6dc7bd650db003a3bb62c11474373036 Mon Sep 17 00:00:00 2001 From: Simen Heggestøyl Date: Sat, 27 Jan 2018 18:03:49 +0100 Subject: Fix indentation bug with multi-line CSS values * lisp/textmodes/css-mode.el (css-smie-rules): Fix indentation of multi-line CSS values that are separated by spaces. * test/manual/indent/css-mode.css: Add a test case for the fix. --- lisp/textmodes/css-mode.el | 3 ++- test/manual/indent/css-mode.css | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'test/manual/indent/css-mode.css') diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 7e997ac2c0f..6bd08f59190 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1215,7 +1215,8 @@ for determining whether point is within a selector." (pcase (cons kind token) (`(:elem . basic) css-indent-offset) (`(:elem . arg) 0) - (`(:list-intro . ,(or `";" `"")) t) ;"" stands for BOB (bug#15467). + ;; "" stands for BOB (bug#15467). + (`(:list-intro . ,(or `";" `"" `":-property")) t) (`(:before . "{") (when (or (smie-rule-hanging-p) (smie-rule-bolp)) (smie-backward-sexp ";") diff --git a/test/manual/indent/css-mode.css b/test/manual/indent/css-mode.css index 640418b022d..ecf6c3c0ca5 100644 --- a/test/manual/indent/css-mode.css +++ b/test/manual/indent/css-mode.css @@ -56,6 +56,8 @@ div::before { sans-serif; font: 15px "Helvetica Neue", Helvetica, Arial, "Nimbus Sans L", sans-serif; + background: no-repeat right + 5px center; transform: matrix(1.0, 2.0, 3.0, 4.0, 5.0, 6.0); -- cgit v1.2.3 From 1efaa1d66b9bc51284c7cac4477f45c9bde4fcfb Mon Sep 17 00:00:00 2001 From: Simen Heggestøyl Date: Sun, 10 May 2020 14:44:26 +0200 Subject: Allow underscores in CSS variable names * lisp/textmodes/css-mode.el (css-nmchar-re): Allow underscores in variable names (and in identifiers in general). * test/manual/indent/css-mode.css: Add some examples of variable names with underscores in them. * test/manual/indent/less-css-mode.less: Add some examples of variable names with underscores in them. * test/manual/indent/scss-mode.scss: Add some examples of variable names with underscores in them. --- lisp/textmodes/css-mode.el | 2 +- test/manual/indent/css-mode.css | 4 ++++ test/manual/indent/less-css-mode.less | 10 ++++++++++ test/manual/indent/scss-mode.scss | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) (limited to 'test/manual/indent/css-mode.css') diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index ab9e2dc35ec..0035c5e7b05 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -886,7 +886,7 @@ cannot be completed sensibly: `custom-ident', (defconst css-escapes-re "\\\\\\(?:[^\000-\037\177]\\|[[:xdigit:]]+[ \n\t\r\f]?\\)") -(defconst css-nmchar-re (concat "\\(?:[-[:alnum:]]\\|" css-escapes-re "\\)")) +(defconst css-nmchar-re (concat "\\(?:[-_[:alnum:]]\\|" css-escapes-re "\\)")) (defconst css-nmstart-re (concat "\\(?:[[:alpha:]]\\|" css-escapes-re "\\)")) (defconst css-ident-re ;; (concat css-nmstart-re css-nmchar-re "*") ;; Apparently, "at rules" names can start with a dash, e.g. @-moz-keyframes. diff --git a/test/manual/indent/css-mode.css b/test/manual/indent/css-mode.css index ecf6c3c0ca5..041aeec1b15 100644 --- a/test/manual/indent/css-mode.css +++ b/test/manual/indent/css-mode.css @@ -92,5 +92,9 @@ div::before { .foo-bar--baz { --foo-variable: 5px; + --_variable_with_underscores: #fff; + --_variable-starting-with-underscore: none; margin: var(--foo-variable); + color: var(--_variable_with_underscores); + display: var(--_variable-starting-with-underscore); } diff --git a/test/manual/indent/less-css-mode.less b/test/manual/indent/less-css-mode.less index 36c037450cc..b40a2362e28 100644 --- a/test/manual/indent/less-css-mode.less +++ b/test/manual/indent/less-css-mode.less @@ -1,3 +1,13 @@ +@var-with-dashes: #428bca; +@var_with_underscores: 10px; +@_var-starting-with-underscore: none; + +body { + background: @var-with-dashes; + padding: @var_with_underscores; + display: @_var-starting-with-underscore; +} + .desktop-and-old-ie(@rules) { @media screen and (min-width: 1200) { @rules(); } html.lt-ie9 & { @rules(); } diff --git a/test/manual/indent/scss-mode.scss b/test/manual/indent/scss-mode.scss index a3dd41eeb47..189ec4e22ac 100644 --- a/test/manual/indent/scss-mode.scss +++ b/test/manual/indent/scss-mode.scss @@ -41,9 +41,13 @@ p.#{$name} var article[role="main"] { $toto: 500 !global; $var-with-default: 300 !default; + $var_with_underscores: #fff; + $_var-starting-with-underscore: none; float: left !important; width: 600px / 888px * 100%; height: 100px / 888px * 100%; + color: $var_with_underscores; + display: $_var-starting-with-underscore; } %placeholder { -- cgit v1.2.3 From 4ba71eee8d8991c95028df40cb784cb9cb2e964d Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Thu, 10 Sep 2020 20:40:34 +0200 Subject: Convert indent test for css-mode into automatic test * test/lisp/textmodes/css-mode-tests.el (css-mode-test-indent): New test. (css-mode-tests-data-dir): New variable. * test/manual/indent/css-mode.css: Move from here... * test/lisp/textmodes/css-mode-resources/test-indent.css: ...to here. --- .../textmodes/css-mode-resources/test-indent.css | 100 +++++++++++++++++++++ test/lisp/textmodes/css-mode-tests.el | 14 +++ test/manual/indent/css-mode.css | 100 --------------------- 3 files changed, 114 insertions(+), 100 deletions(-) create mode 100644 test/lisp/textmodes/css-mode-resources/test-indent.css delete mode 100644 test/manual/indent/css-mode.css (limited to 'test/manual/indent/css-mode.css') diff --git a/test/lisp/textmodes/css-mode-resources/test-indent.css b/test/lisp/textmodes/css-mode-resources/test-indent.css new file mode 100644 index 00000000000..041aeec1b15 --- /dev/null +++ b/test/lisp/textmodes/css-mode-resources/test-indent.css @@ -0,0 +1,100 @@ +/* asdfasdf */ + +.xxx +{ +} + +article[role="main"] { + width: 60%; +} + +a, b:hover, c { + color: black !important; +} + +a, b:hover { /* bug:20282 */ + c { + color: black; + } + color: black; +} + +a.b:c,d.e:f,g[h]:i,j[k]:l,.m.n:o,.p.q:r,.s[t]:u,.v[w]:x { /* bug:20282 */ + background-color: white; +} + +/* asdfasdf */ +@foo x2 { + bla:toto; +} +.x2 +{ + /* foo: bar; */ foo2: bar2; + bar1: url("http://toto/titi"); + bar2: url('http://toto/titi'); + bar3: url(http://toto/titi); +} + +div.x3 +{ +} + +article:hover +{ + color: black; +} + +/* bug:13425 */ +div:first-child, +div:last-child, +div[disabled], +div::before { + font: 15px "Helvetica Neue", + Helvetica, + Arial, + "Nimbus Sans L", + sans-serif; + font: 15px "Helvetica Neue", Helvetica, Arial, + "Nimbus Sans L", sans-serif; + background: no-repeat right + 5px center; + transform: matrix(1.0, 2.0, + 3.0, 4.0, + 5.0, 6.0); + transform: matrix( + 1.0, 2.0, + 3.0, 4.0, + 5.0, 6.0 + ); +} + +/* Multi-line selector including both a pseudo-class and + parenthesis. */ +.form-group:not(.required) label, +.birth-date .row > * { + &::after { + display: inline; + font-weight: normal; + } +} + +@font-face { + src: url("Sans-Regular.eot") format("eot"), + url("Sans-Regular.woff") format("woff"), + url("Sans-Regular.ttf") format("truetype"); +} + +@font-face { + src: + url("Sans-Regular.eot") format("eot"), + url("Sans-Regular.woff") format("woff"); +} + +.foo-bar--baz { + --foo-variable: 5px; + --_variable_with_underscores: #fff; + --_variable-starting-with-underscore: none; + margin: var(--foo-variable); + color: var(--_variable_with_underscores); + display: var(--_variable-starting-with-underscore); +} diff --git a/test/lisp/textmodes/css-mode-tests.el b/test/lisp/textmodes/css-mode-tests.el index 38cb73b3557..f627d1c02c9 100644 --- a/test/lisp/textmodes/css-mode-tests.el +++ b/test/lisp/textmodes/css-mode-tests.el @@ -30,6 +30,12 @@ (require 'ert) (require 'seq) +(defvar css-mode-tests-data-dir + (file-truename + (expand-file-name "css-mode-resources/" + (file-name-directory (or load-file-name + buffer-file-name))))) + (ert-deftest css-test-property-values () ;; The `float' property has a flat value list. (should @@ -411,5 +417,13 @@ (point)) "black"))))) +(ert-deftest css-mode-test-indent () + (with-current-buffer + (find-file-noselect (expand-file-name "test-indent.css" + css-mode-tests-data-dir)) + (let ((orig (buffer-string))) + (indent-region (point-min) (point-max)) + (should (equal (buffer-string) orig))))) + (provide 'css-mode-tests) ;;; css-mode-tests.el ends here diff --git a/test/manual/indent/css-mode.css b/test/manual/indent/css-mode.css deleted file mode 100644 index 041aeec1b15..00000000000 --- a/test/manual/indent/css-mode.css +++ /dev/null @@ -1,100 +0,0 @@ -/* asdfasdf */ - -.xxx -{ -} - -article[role="main"] { - width: 60%; -} - -a, b:hover, c { - color: black !important; -} - -a, b:hover { /* bug:20282 */ - c { - color: black; - } - color: black; -} - -a.b:c,d.e:f,g[h]:i,j[k]:l,.m.n:o,.p.q:r,.s[t]:u,.v[w]:x { /* bug:20282 */ - background-color: white; -} - -/* asdfasdf */ -@foo x2 { - bla:toto; -} -.x2 -{ - /* foo: bar; */ foo2: bar2; - bar1: url("http://toto/titi"); - bar2: url('http://toto/titi'); - bar3: url(http://toto/titi); -} - -div.x3 -{ -} - -article:hover -{ - color: black; -} - -/* bug:13425 */ -div:first-child, -div:last-child, -div[disabled], -div::before { - font: 15px "Helvetica Neue", - Helvetica, - Arial, - "Nimbus Sans L", - sans-serif; - font: 15px "Helvetica Neue", Helvetica, Arial, - "Nimbus Sans L", sans-serif; - background: no-repeat right - 5px center; - transform: matrix(1.0, 2.0, - 3.0, 4.0, - 5.0, 6.0); - transform: matrix( - 1.0, 2.0, - 3.0, 4.0, - 5.0, 6.0 - ); -} - -/* Multi-line selector including both a pseudo-class and - parenthesis. */ -.form-group:not(.required) label, -.birth-date .row > * { - &::after { - display: inline; - font-weight: normal; - } -} - -@font-face { - src: url("Sans-Regular.eot") format("eot"), - url("Sans-Regular.woff") format("woff"), - url("Sans-Regular.ttf") format("truetype"); -} - -@font-face { - src: - url("Sans-Regular.eot") format("eot"), - url("Sans-Regular.woff") format("woff"); -} - -.foo-bar--baz { - --foo-variable: 5px; - --_variable_with_underscores: #fff; - --_variable-starting-with-underscore: none; - margin: var(--foo-variable); - color: var(--_variable_with_underscores); - display: var(--_variable-starting-with-underscore); -} -- cgit v1.2.3