Skip to content

Instantly share code, notes, and snippets.

@dkandalov
Last active December 14, 2015 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dkandalov/5129543 to your computer and use it in GitHub Desktop.
Save dkandalov/5129543 to your computer and use it in GitHub Desktop.
Wrap-selection micro plugin for IntelliJ
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