tminor / jsonnet-mode

Emacs major mode for editing Jsonnet files.
GNU General Public License v3.0
46 stars 17 forks source link

Align close paren with opening paren #24

Closed yuezhu closed 3 years ago

yuezhu commented 3 years ago

Description

This fixes smie indentation by aligning close paren with opening paren.

Motivation and Context

The close paren should be aligned with its opening one. eg:

  foo: [
    "bar"
  ]

However, current indentation behavior would make it

  foo: [
    "bar"
    ]
tminor commented 3 years ago

Thanks for the PR! I've tested this particular case with emacs -q and the latest version of jsonnet-mode and don't have this issue; the closing bracket isn't indented after I initially type it, but with electric-indent-mode enabled, pressing RET indents it properly (the same is true if I press TAB).

I'm not opposed to merging this PR, but I'm unsure whether it would unexpectedly change the behavior of other SMIE rules. I'd like to merge #25 before merging this just to be extra sure! In a more general sense, if this change doesn't break other SMIE rules, I'm guessing some of the current SMIE rules would become superfluous/redundant (I honestly didn't know about smie-indent-close :smile:).

yuezhu commented 3 years ago

Yeah, I have electric-indent-mode enabled and the close paren is indented for an extra level while it should align with the corresponding opening paren. After I added smie-indent-close, the opening and close parens are aligned.

I actually have little knowledge on SMIE indentation engine so I am not sure if smie-indent-close comes with any side effects, though it apparently fixes the paren alignment. I completely agree that #25 would be helpful.