diff --git a/package.json b/package.json index 3635b8725..8e9d0d832 100644 --- a/package.json +++ b/package.json @@ -68,6 +68,7 @@ "xml-tmbundle": "1.0.0", "yaml-tmbundle": "1.0.0", "archive-view": "0.1.0", + "autoflow": "0.1.0", "spell-check": "0.1.0", "terminal": "0.3.0" }, diff --git a/src/packages/autoflow/keymaps/autoflow.cson b/src/packages/autoflow/keymaps/autoflow.cson deleted file mode 100644 index 6ef31cf06..000000000 --- a/src/packages/autoflow/keymaps/autoflow.cson +++ /dev/null @@ -1,2 +0,0 @@ -'.editor': - 'alt-meta-q': 'autoflow:reflow-paragraph' diff --git a/src/packages/autoflow/lib/autoflow.coffee b/src/packages/autoflow/lib/autoflow.coffee deleted file mode 100644 index 0fa969309..000000000 --- a/src/packages/autoflow/lib/autoflow.coffee +++ /dev/null @@ -1,50 +0,0 @@ -module.exports = - activate: -> - rootView.eachEditor (editor) => - return unless editor.attached and editor.getPane()? - editor.command 'autoflow:reflow-paragraph', (e) => - @reflowParagraph(e.currentTargetView()) - - reflowParagraph: (editor) -> - if range = editor.getCurrentParagraphBufferRange() - wrapColumn = config.getPositiveInt('editor.preferredLineLength', 80) - editor.getBuffer().change(range, @reflow(editor.getTextInRange(range), {wrapColumn})) - - reflow: (text, {wrapColumn}) -> - paragraphs = [] - paragraphBlocks = text.split(/\n\s*\n/g) - - for block in paragraphBlocks - - # TODO: this could be more language specific. Use the actual comment char. - linePrefix = block.match(/^\s*[\/#*-]*\s*/g)[0] - blockLines = block.split('\n') - blockLines = (blockLine.replace(new RegExp('^' + linePrefix.replace('*', '\\*')), '') for blockLine in blockLines) if linePrefix - - lines = [] - currentLine = [] - currentLineLength = linePrefix.length - - for segment in @segmentText(blockLines.join(' ')) - if @wrapSegment(segment, currentLineLength, wrapColumn) - lines.push(linePrefix + currentLine.join('')) - currentLine = [] - currentLineLength = linePrefix.length - currentLine.push(segment) - currentLineLength += segment.length - lines.push(linePrefix + currentLine.join('')) - - paragraphs.push(lines.join('\n').replace(/\s+\n/g, '\n')) - - paragraphs.join('\n\n') - - wrapSegment: (segment, currentLineLength, wrapColumn) -> - /\w/.test(segment) and - (currentLineLength + segment.length > wrapColumn) and - (currentLineLength > 0 or segment.length < wrapColumn) - - segmentText: (text) -> - segments = [] - re = /[\s]+|[^\s]+/g - segments.push(match[0]) while match = re.exec(text) - segments diff --git a/src/packages/autoflow/package.cson b/src/packages/autoflow/package.cson deleted file mode 100644 index 07b0fea4d..000000000 --- a/src/packages/autoflow/package.cson +++ /dev/null @@ -1,4 +0,0 @@ -'main': './lib/autoflow' -'description': 'Format the current paragraph to have lines no longer than 80 characters.\n\nThis packages uses the config value of `editor.preferredLineLength` when set.' -'activationEvents': - 'autoflow:reflow-paragraph': '.editor' diff --git a/src/packages/autoflow/spec/autoflow-spec.coffee b/src/packages/autoflow/spec/autoflow-spec.coffee deleted file mode 100644 index dca8ca29e..000000000 --- a/src/packages/autoflow/spec/autoflow-spec.coffee +++ /dev/null @@ -1,166 +0,0 @@ -RootView = require 'root-view' - -describe "Autoflow package", -> - editor = null - autoflow = null - - describe "autoflow:reflow-paragraph", -> - beforeEach -> - window.rootView = new RootView - rootView.open() - atom.activatePackage('autoflow') - rootView.attachToDom() - editor = rootView.getActiveView() - - config.set('editor.preferredLineLength', 30) - - it "rearranges line breaks in the current paragraph to ensure lines are shorter than config.editor.preferredLineLength", -> - editor.setText """ - This is a preceding paragraph, which shouldn't be modified by a reflow of the following paragraph. - - The quick brown fox jumps over the lazy - dog. The preceding sentence contains every letter - in the entire English alphabet, which has absolutely no relevance - to this test. - - This is a following paragraph, which shouldn't be modified by a reflow of the preciding paragraph. - - """ - - editor.setCursorBufferPosition([3, 5]) - editor.trigger 'autoflow:reflow-paragraph' - - expect(editor.getText()).toBe """ - This is a preceding paragraph, which shouldn't be modified by a reflow of the following paragraph. - - The quick brown fox jumps over - the lazy dog. The preceding - sentence contains every letter - in the entire English - alphabet, which has absolutely - no relevance to this test. - - This is a following paragraph, which shouldn't be modified by a reflow of the preciding paragraph. - - """ - - it "allows for single words that exceed the preferred wrap column length", -> - editor.setText("this-is-a-super-long-word-that-shouldn't-break-autoflow and these are some smaller words") - - editor.setCursorBufferPosition([0, 4]) - editor.trigger 'autoflow:reflow-paragraph' - - expect(editor.getText()).toBe """ - this-is-a-super-long-word-that-shouldn't-break-autoflow - and these are some smaller - words - """ - - describe "reflowing text", -> - beforeEach -> - window.rootView = new RootView - autoflow = atom.activatePackage('autoflow', immediate: true).mainModule - - it 'respects current paragraphs', -> - text = ''' - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh id magna ullamcorper sagittis. Maecenas - et enim eu orci tincidunt adipiscing - aliquam ligula. - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Phasellus gravida - nibh id magna ullamcorper - tincidunt adipiscing lacinia a dui. Etiam quis erat dolor. - rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum. - ''' - - res = ''' - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh - id magna ullamcorper sagittis. Maecenas et enim eu orci tincidunt adipiscing - aliquam ligula. - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh - id magna ullamcorper tincidunt adipiscing lacinia a dui. Etiam quis erat dolor. - rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum. - ''' - expect(autoflow.reflow(text, wrapColumn: 80)).toEqual res - - it 'respects indentation', -> - text = ''' - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh id magna ullamcorper sagittis. Maecenas - et enim eu orci tincidunt adipiscing - aliquam ligula. - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Phasellus gravida - nibh id magna ullamcorper - tincidunt adipiscing lacinia a dui. Etiam quis erat dolor. - rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum - ''' - - res = ''' - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh - id magna ullamcorper sagittis. Maecenas et enim eu orci tincidunt adipiscing - aliquam ligula. - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida - nibh id magna ullamcorper tincidunt adipiscing lacinia a dui. Etiam quis - erat dolor. rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis - fermentum - ''' - expect(autoflow.reflow(text, wrapColumn: 80)).toEqual res - - it 'respects prefixed text (comments!)', -> - text = ''' - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh id magna ullamcorper sagittis. Maecenas - et enim eu orci tincidunt adipiscing - aliquam ligula. - - # Lorem ipsum dolor sit amet, consectetur adipiscing elit. - # Phasellus gravida - # nibh id magna ullamcorper - # tincidunt adipiscing lacinia a dui. Etiam quis erat dolor. - # rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis fermentum - ''' - - res = ''' - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida nibh - id magna ullamcorper sagittis. Maecenas et enim eu orci tincidunt adipiscing - aliquam ligula. - - # Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida - # nibh id magna ullamcorper tincidunt adipiscing lacinia a dui. Etiam quis - # erat dolor. rutrum nisl fermentum rhoncus. Duis blandit ligula facilisis - # fermentum - ''' - expect(autoflow.reflow(text, wrapColumn: 80)).toEqual res - - it 'respects multiple prefixes (js/c comments)', -> - text = ''' - // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida - et enim eu orci tincidunt adipiscing - aliquam ligula. - ''' - - res = ''' - // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida et - // enim eu orci tincidunt adipiscing aliquam ligula. - ''' - expect(autoflow.reflow(text, wrapColumn: 80)).toEqual res - - it 'properly handles * prefix', -> - text = ''' - * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida - et enim eu orci tincidunt adipiscing - aliquam ligula. - - * soidjfiojsoidj foi - ''' - - res = ''' - * Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus gravida et - * enim eu orci tincidunt adipiscing aliquam ligula. - - * soidjfiojsoidj foi - ''' - expect(autoflow.reflow(text, wrapColumn: 80)).toEqual res