-
-
Notifications
You must be signed in to change notification settings - Fork 146
Add reindent utility. #159
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
Conversation
There already is a |
Do you have a plan to implement the usage of this utility in the dlang.org makefiles as well? |
|
It's messy to unite it with detab, because this code uses ranges whereas detab uses a manual char array loop. |
Then maybe reimplement detab on top of this code? :P detab is probably D1-era. |
Isn't detab just a simple matter of running |
Not if you have non-leading tabs (or mixed tabs and spaces). Then you need to track columns. |
.copy(stdout.lockingTextWriter()); | ||
} | ||
|
||
// vim:ai sw=4 ts=4 et: |
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.
We should probably avoid editor metadata in D source files. We use .editorconfig
, but there isn't one in the tools repo.
Oh, right. Darn. :-D Well, it would have no code in common with |
OK, let's leave detab alone then. |
import std.regex; | ||
|
||
auto reSplitInitialSpace = regex(`^( +)(.*)`, "s"); | ||
auto reReindent = regex(" ".replicate(inputIndent)); |
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 is probably a little overkill, just looking at m.captures[1].length
would suffice.
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.
Probably, but I was too lazy to figure out the exact formula for it. :-P
Well, I was planning to take a look to see how nasty it would get. "Planning to implement" sounds a bit too strong. :-P |
import std.array; | ||
import std.regex; | ||
|
||
auto reSplitInitialSpace = regex(`^( +)(.*)`, "s"); |
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.
If you replace the +
with *
, you can drop the if
in the map
predicate.
OK. I think it might get very messy, especially in the case of win32.mak. |
That is an awful lot of code for a "simple" replacement:
Why no go the whole mile and have a reindent that knows D source, looks for braces and such? Maybe dfmt is the proper place? Still, I like the small script for educational purposes. |
Hmm... |
You mean |
Err, yes. |
But this only correctly performs reindentation of 2n spaces to n spaces, whereas the current code is more flexible, e.g., reindenting 4-space indentation to 3-space. |
Well, yes, but do we need N-to-N reindent? |
I think the harder problem is integrating this tool with the makefiles. |
Yes. :-) |
Are we going ahead with this, or should I just close this and forget about it? It's been a looong time. |
Can't you do that with CSS? |
Code is usually rendered in blocks with a fixed-width font, so I don't see how CSS would help solve this problem. |
But if there's not that much interest in this, maybe this PR should just be closed. It is just a trivial utility after all. |
The intention is to use this tool in dlang.org to generate docs with narrower indentation when targeting narrow-screen media like Kindle.