void (String textToFoldRegexp, final String placeholder) { final Matcher matcher = Pattern.compile(textToFoldRegexp).matcher(getEditor().getDocument().getCharsSequence()); getEditor().getFoldingModel().runBatchFoldingOperation(() -> { while (matcher.find()) { FoldRegion foldRegion = getEditor().getFoldingModel().addFoldRegion(matcher.start(), matcher.end(), placeholder); assertNotNull(foldRegion); foldRegion.setExpanded(false); } }); }