From 141cc78aa4552e99bf14c13d9e64357ccafe171b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Tue, 15 Aug 2017 12:39:42 +0200 Subject: [PATCH] Support indentation of detached Less CSS rulesets * lisp/textmodes/css-mode.el (css-smie-rules): Provide better support for indentation of detached rulesets passed to Less mixins. * test/manual/indent/less-css-mode.less: New file. --- lisp/textmodes/css-mode.el | 9 ++++++--- test/manual/indent/less-css-mode.less | 29 +++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 test/manual/indent/less-css-mode.less diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el index 19cb7b4fea8..1e49ca81fcc 100644 --- a/lisp/textmodes/css-mode.el +++ b/lisp/textmodes/css-mode.el @@ -1205,9 +1205,12 @@ for determining whether point is within a selector." (`(:before . "{") (when (or (smie-rule-hanging-p) (smie-rule-bolp)) (smie-backward-sexp ";") - (smie-indent-virtual))) - (`(:before . ,(or "{" "(")) - (if (smie-rule-hanging-p) (smie-rule-parent 0))) + (unless (eq (char-after) ?\{) + (smie-indent-virtual)))) + (`(:before . "(") + (cond + ((smie-rule-hanging-p) (smie-rule-parent 0)) + ((not (smie-rule-bolp)) 0))) (`(:after . ":-property") (when (smie-rule-hanging-p) css-indent-offset)))) diff --git a/test/manual/indent/less-css-mode.less b/test/manual/indent/less-css-mode.less new file mode 100644 index 00000000000..36c037450cc --- /dev/null +++ b/test/manual/indent/less-css-mode.less @@ -0,0 +1,29 @@ +.desktop-and-old-ie(@rules) { + @media screen and (min-width: 1200) { @rules(); } + html.lt-ie9 & { @rules(); } +} + +header { + background-color: blue; + + .desktop-and-old-ie({ + background-color: red; + }); +} + +.e(@name, @rules) { + &__@{name} { @rules(); } +} + +.m(@name, @rules) { + &--@{name} { @rules(); } +} + +.btn { + .e(span, { // .btn__span + display: inline-block; + }); + .m(primary, { // .btn--primary + background: blue; + }); +}