Skip to content

Conversation

quickfur
Copy link
Member

The intention is to use this tool in dlang.org to generate docs with narrower indentation when targeting narrow-screen media like Kindle.

@CyberShadow
Copy link
Member

There already is a detab utility, maybe there's some value in uniting them?

@CyberShadow
Copy link
Member

when targeting narrow-screen media like Kindle

Do you have a plan to implement the usage of this utility in the dlang.org makefiles as well?

@CyberShadow
Copy link
Member

  • win32.mak too please.

@quickfur
Copy link
Member Author

It's messy to unite it with detab, because this code uses ranges whereas detab uses a manual char array loop.

@CyberShadow
Copy link
Member

Then maybe reimplement detab on top of this code? :P detab is probably D1-era.

@quickfur
Copy link
Member Author

Isn't detab just a simple matter of running std.regex.replaceAll("\t", " "); on every line?

@CyberShadow
Copy link
Member

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:
Copy link
Member

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.

@quickfur
Copy link
Member Author

Oh, right. Darn. :-D

Well, it would have no code in common with reindent then. Although I can see some benefit in having a single program with subcommands that you can select, e.g., reformat reindent abc.d, reformat detab abc.d, etc.. On Linux, you could even symlink reindent, detab, etc., to the executable, and use argv[0] to switch on what action to run.

@CyberShadow
Copy link
Member

OK, let's leave detab alone then.

import std.regex;

auto reSplitInitialSpace = regex(`^( +)(.*)`, "s");
auto reReindent = regex(" ".replicate(inputIndent));
Copy link
Member

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.

Copy link
Member Author

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

@quickfur
Copy link
Member Author

Do you have a plan to implement the usage of this utility in the dlang.org makefiles as well?

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");
Copy link
Member

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.

@CyberShadow
Copy link
Member

Well, I was planning to take a look to see how nasty it would get.

OK. I think it might get very messy, especially in the case of win32.mak.

@kuettler
Copy link
Contributor

That is an awful lot of code for a "simple" replacement:

perl -p -e 's/^(  )+/$& =~ s,  ,    ,gr/e' filename.d

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.

@CyberShadow
Copy link
Member

Hmm... ^s/( )+\1/\1/g

@quickfur
Copy link
Member Author

You mean s/^( +)\1/\1/g?

@CyberShadow
Copy link
Member

Err, yes.

@quickfur
Copy link
Member Author

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.

@CyberShadow
Copy link
Member

Well, yes, but do we need N-to-N reindent?

@CyberShadow
Copy link
Member

I think the harder problem is integrating this tool with the makefiles.

@quickfur
Copy link
Member Author

Yes. :-)

@quickfur
Copy link
Member Author

Are we going ahead with this, or should I just close this and forget about it? It's been a looong time.

@MartinNowak
Copy link
Member

The intention is to use this tool in dlang.org to generate docs with narrower indentation when targeting narrow-screen media like Kindle.

Can't you do that with CSS?

@quickfur
Copy link
Member Author

Code is usually rendered in blocks with a fixed-width font, so I don't see how CSS would help solve this problem.

@quickfur
Copy link
Member Author

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.

@quickfur quickfur deleted the reindent branch August 20, 2015 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants