bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#21328: 25.0.50; css-mode: Indenting brackets in presence of pseudo-s


From: Stefan Monnier
Subject: bug#21328: 25.0.50; css-mode: Indenting brackets in presence of pseudo-selectors
Date: Tue, 25 Aug 2015 09:06:18 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

>    main:first
>             {
>                 background: green;
>             }
> }
[...]
> (`(:before . "{")
>   (when (smie-rule-hanging-p)
>     (smie-backward-sexp ";")
>     (smie-indent-virtual)))

The (smie-rule-hanging-p) test checks if the "{" is at the end of the
line (and with text before it on the same line).  I guess you could use
something like

   (when (or (smie-rule-hanging-p) (smie-rule-bolp))

tho for the bolp case, maybe some people like

   main:first
     {
       background: green;
     }

since that's the "standard GNU style" in C/C++ (so for the bolp case, we
might like to add the indentation step to the return value of
smie-indent-virtual).
The current behavior is "almost" like this standard, except that it
indents relatively to the "first" instead of doing it relatively to the
"main", because it misparses the above as

   main : (first {...})

i.s.o

   (main : first) {...}

[ Where I added parentheses just to clarify the grouping.  ]

> However I haven't been able to fully understand how SMIE works yet, so
> I'm not sure what that check was meant for in the first place, or
> whether it breaks some other cases (though I haven't been able to find
> such a case).

You could also remove the (smie-rule-hanging-p) test
altogether, indeed.  This could lead to mis-indentations in some cases,
tho I can't think of any right now that would show up in CSS.  E.g. things
where we'd want

   main:first {toto}
              (tutu)

because the "(tutu)" is like a "second argument" to "main:first", and
we'd instead get

   main:first {toto}
   (tutu)

because the `(:before . "{") case also triggers here when we compute the
(virtual) indentation of {toto}.


        Stefan





reply via email to

[Prev in Thread] Current Thread [Next in Thread]