New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function to indent things in blocks for nix-indent-line #61

Merged
merged 1 commit into from Jan 3, 2019

Conversation

Projects
None yet
3 participants
@etu
Copy link
Collaborator

etu commented Jan 2, 2019

Add a function nix-indent-first-line-in-block that checks if the last word on the previous line is one of "let, import, [, =, (, {". Then it adds two spaces of indent to the one of the previous line.

This is a shot at improving based on the examples is #60.

It works with all examples in #60 and just by going through my configuration.nix it seems a lot better than before.

It's not perfect in all the cases like this:

let
  splitString = _sep: _s: builtins.filter
    (x: builtins.typeOf x == "string")
    (builtins.split _sep _s);
in # whatever

But it wasn't before either, in fact it behaves exactly the same as before in that case as far as I can see.

@etu etu force-pushed the etu:master branch from a0266ae to e54b368 Jan 2, 2019

@grahamc

This comment has been minimized.

Copy link
Member

grahamc commented Jan 2, 2019

What does it do in this case?

let
  splitString = _sep: _s: builtins.filter
    (x: builtins.typeOf x == "string")
    (builtins.split _sep _s);
in # whatever
@etu

This comment has been minimized.

Copy link
Collaborator Author

etu commented Jan 2, 2019

@grahamc
It becomes this:

let
  splitString = _sep: _s: builtins.filter
  (x: builtins.typeOf x == "string")
  (builtins.split _sep _s);
in # whatever

But before that would result in:

let
splitString = _sep: _s: builtins.filter
(x: builtins.typeOf x == "string")
(builtins.split _sep _s);
in # whatever

for me, so still better than before.

@etu etu force-pushed the etu:master branch from e54b368 to e6267d4 Jan 2, 2019

@grahamc

This comment has been minimized.

Copy link
Member

grahamc commented Jan 2, 2019

Confirming it fixes these cases:

{
  x86 = [
    {
      name = "t1.small.x86";
    }
  ];
}
let
  x = [
    (let y = 1; in y)
    { foo = 1; }
    [ 1 2 3 ]
    x
  ];
in x

(though I note on the first line, tabbing will indent let "forever")

let
  mozilla-overlay =
    import
  (
    builtins.fetchTarball
    https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz
  );
in mozilla-overlay

Looks like #60 can be closed with this merge!

@grahamc grahamc referenced this pull request Jan 3, 2019

Merged

Experiment/maintainer ping #293

@etu etu force-pushed the etu:master branch from e6267d4 to 2a6a45e Jan 3, 2019

@etu

This comment has been minimized.

Copy link
Collaborator Author

etu commented Jan 3, 2019

@grahamc I have now fixed the regression that it endlessly indented the first line.

I've also made some more comments to make it easier to understand and moved logic around to not have weird things (like return -2 because I add +2 at a later place to get 0, instead I return 0 in one place and return a value that is already +2 added to in the other place).

@etu

This comment has been minimized.

Copy link
Collaborator Author

etu commented Jan 3, 2019

One case it doesn't handle I realized is if there's an empty line in between like this:

let

  x = [

    (let y = 1; in y)
    { foo = 1; }
    [ 1 2 3 ]
    x
  ];
in x

EDIT: And that is now fixed.

@etu etu force-pushed the etu:master branch 2 times, most recently from f3f5fea to ab5a3a9 Jan 3, 2019

Add function to indent things in blocks for nix-indent-line
Add a function `nix-indent-first-line-in-block` that checks if the
last word on the previous line is one of "let, import, [, =, (, {".
Then it adds two spaces of indent to the one of the previous line.

And if you stand on the first line of a file, it defaults to indenting
the line to zero spaces.

@etu etu force-pushed the etu:master branch from ab5a3a9 to 98426b9 Jan 3, 2019

@etu etu referenced this pull request Jan 3, 2019

Merged

Ert indent testing #63

@matthewbauer

This comment has been minimized.

Copy link
Member

matthewbauer commented Jan 3, 2019

Awesome! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment