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
Improve indentation robustness #48
Conversation
Wanted to say thanks to you. You fixed very important thing to many Nix* people. Yes, "track function definitions/calls" in Nix is obscure and can be hard even for a human. |
nix-mode.el
Outdated
"Return regexp for matching string quotes." | ||
(nix-mode-make-regexp nix-mode-quotes)) | ||
|
||
(defun nix-mode-combined-regexp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should have a parens.
(when (/= counter 0) (goto-char (point-min))) t)) | ||
(defun nix-mode-make-regexp (parts) | ||
"Combine the regexps into a single or-delimited regexp." | ||
(declare (indent defun)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this one do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nix-mode-make-regexp
takes a list of regexps and makes a larger regex out of them separated by \\|
so that any of the constituents match.
Thanks so much for doing this! I think this is definitely an improvement and we are getting closer to having things working properly. A few notes trying this on some nix expressions:
|
That is just how it is going to be unless someone wants to hack in some heuristics. Consider what the header is. An open I'll take a look at the "with" handling as that should be handled properly ( |
OK the
The |
I've started using this and have found the following strange behavior: { nodes, pkgs, ... }:
{
services.prometheus = {
scrapeConfigs = [
{
job_name = "node";
static_configs = [
{ targets = builtins.map
(nodename: "${nodename}:9100")
(builtins.attrNames nodes);
}
];
}
];
};
} |
Can we not leverage something like rnix to help improve indentation? |
As for trying this...
|
@mkaito rnix looks interesting, check out It's been on my mind for a while now to use it as an aggressive Nix pretty-printer (like |
@mkaito said:
Sorry that should be fixed now. @grahamc said:
Sorry, I can't replicate. Copying your paste into a buffer and formatting I get: { nodes, pkgs, ... }:
{
services.prometheus = {
scrapeConfigs = [
{
job_name = "node";
static_configs = [
{ targets = builtins.map
(nodename: "${nodename}:9100")
(builtins.attrNames nodes);
}
];
}
];
};
} |
nix-mode.el
Outdated
(cond | ||
((looking-at (nix-mode-quotes-regexp)) | ||
;; skip over strings entirely | ||
(re-search-backward nix-mode-quotes-regexp nil t)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(re-search-backward (nix-mode-quotes-regexp) nil t))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dang it, lol
Improves indentation by covering more cases more often. It isn't perfect, but I've shopped it around and people seem to approve.
I defer to the code, which is heavily commented, for a deeper explanation of the technique. But in summary, the algorithm looks something like:
caps
andends
which we will count to track expression balance.** Quirks
=
sign in assignments must be couched by spaces