1

I'm writing indentation rules for a custom mode using SMIE.

I want to use smie-rule-parent-p to have different behavior for indenting an empty line depending on context, so inside my indentation rules function, I have a case like this:

(`(:elem . empty-line-token)
     (if (smie-rule-parent-p ",") "," "---"))

(The "---" is a token that's always indented at column 0.)

The source language has definitions that look like this:

type Network = DC { reference_id    : ReferenceId
                  , inventory_class : InventoryClass
                  , children        : [Network]
                  }

when I start a new line in the middle of the { .. } block, I want it indented in line with the commas:

type Network = DC { reference_id    : ReferenceId
                  , inventory_class : InventoryClass
                  , children        : [Network]
                  ^ -- I want the cursor here after indenting.
                  }

The rule using smie-rule-parent-p "," accomplishes this, but it also fires in other parts of the code. In fact, it even triggers when there isn't a single comma in the whole buffer.

How does SMIE determine what the parent of a token is? Can I use that to indent empty lines differently depending on context like I'm trying here?

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.