Last active
December 14, 2015 18:29
-
-
Save dkandalov/5129543 to your computer and use it in GitHub Desktop.
Wrap-selection micro plugin for IntelliJ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static liveplugin.PluginUtil.* | |
// This is micro-plugin for IntelliJ to wrap long lines with separator. | |
// E.g. list literal like this [1, 2, 3, 4, ..., 200000] can be split into somewhat more readable | |
// [1, 2, 3, 4, | |
// 5, 6, 7, 8 | |
// ..., 200000] | |
// (Note that this code can only be executed within this plugin https://github.com/dkandalov/live-plugin) | |
if (isIdeStartup) return | |
def separator = "," | |
def newLine = "\n" | |
def blockSize = 5 | |
transformSelectedText(project) { text -> | |
text.split(separator).toList().with { | |
def blocks = [] | |
for (int i = 0; i < it.size(); i += blockSize) { | |
def from = i | |
def to = (i + blockSize < it.size() ? i + blockSize : it.size()) | |
blocks << it.subList(from, to).join(separator) | |
} | |
blocks.join(separator + newLine) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment