NixOS / nix-mode

An Emacs major mode for editing Nix expressions.
GNU Lesser General Public License v2.1
293 stars 74 forks source link

Use `nix-indent-line` as the default indentation function #198

Open slotThe opened 6 months ago

slotThe commented 6 months ago

Somewhat closes https://github.com/NixOS/nix-mode/issues/57

Basically, this change unifies nix-indent-line with SMIE, in that it uses the latter most of the time, only falling back to hand-baked indentation functions when SMIE would return something surprising. I've been using this for a few months, and haven't noticed any problems so far.

The changes so far are somewhat backwards incompatible, and should be seen as an extreme version of what they could be. I'm happy to e.g. completely revert https://github.com/NixOS/nix-mode/commit/0f480d2d5bb4ec270329d7cb9f7151b5a091c619 in case people think keeping these functions around is worthwhile.

Commit summary

nix-smie-rules: Fix indentation of ","

This seems deceptively simple, but there are actually quite a few situations that can occur; e.g.,

f = { a,    f = {    f = { a      f =       f =
      b       a,         , b        { a       {
    }         b          }          , b         a
            }                       }           , b
                                              }

Thankfully, smie already sanely handles all of these for us, so rely on that instead.

nix-indent-line: Use smie-indent-line in most cases

SMIE does not know how to handle multiline strings, but other than that it's quite a solid foundation—use it.

Make old indentation functions obsolete

SMIE is necessary now, and nix-indent-line is the one and only indent function to use.

[EXPERIMENTAL] Remove old nix-indent-line code