0

If I use the default SML mode parser, or other SMIE parsers, and have a rule for if-then-else as an expression form, I get reasonable indentation of

   x + if p 
       then
         q
       else
         r

just as I would with parentheses:

   x + (y * 
        z)

However, if I make the opening token (if or () sit on its own, I get indentation of the next token that ignores the position of the opener:

   x + (
     y * 
     z)

I can check for hanging-ness in the rule for (:elem . basic) and indent with respect to the position of the x, but how do I indent with respect to the left-delimiter (if or ()?

I tried

    (`(:elem  . basic) (if (smie-rule-parent-p '("if"))
                           (smie-rule-parent 2)))

but got errors telling me smie--parent wasn't defined.

I also tried to use (smie-rule-parent 2) in a rule for (after . "if") but this didn't help either.

I would like

  x + if 
        p
      then
        q
      else
        r

but don't see how to get it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.