From 8b8d198b891282ebed8f7baa62f9793a047c8eaf Mon Sep 17 00:00:00 2001 From: Lee Dohm Date: Fri, 7 Mar 2014 21:51:21 -0800 Subject: [PATCH] Initial commit --- .gitignore | 3 +++ LICENSE.md | 20 ++++++++++++++++++++ README.md | 7 +++++++ lib/tabs-to-spaces.coffee | 29 +++++++++++++++++++++++++++++ menus/tabs-to-spaces.cson | 15 +++++++++++++++ package.json | 14 ++++++++++++++ spec/tabs-to-spaces-spec.coffee | 5 +++++ 7 files changed, 93 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 lib/tabs-to-spaces.coffee create mode 100644 menus/tabs-to-spaces.cson create mode 100644 package.json create mode 100644 spec/tabs-to-spaces-spec.coffee diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ade14b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +npm-debug.log +node_modules diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..c70b99a --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,20 @@ +Copyright © 2014 Lee Dohm, Lifted Studios + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..66a30cb --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Tabs to Spaces + +Converts tabs to spaces. + +## Copyright + +Copyright © 2014 by Lee Dohm, Lifted Studios. See [LICENSE](https://github.com/lee-dohm/tabs-to-spaces/LICENSE.md) for details. diff --git a/lib/tabs-to-spaces.coffee b/lib/tabs-to-spaces.coffee new file mode 100644 index 0000000..352ad8a --- /dev/null +++ b/lib/tabs-to-spaces.coffee @@ -0,0 +1,29 @@ +# +# Copyright (c) 2014 by Lifted Studios. All Rights Reserved. +# + +class TabsToSpaces + spaces = null + + activate: -> + atom.workspaceView.command 'tabs-to-spaces:convert', => @convert() + + convert: -> + editor = atom.workspace.getActiveEditor() + return unless editor? + + spaces = Array(atom.config.get('editor.tabLength') + 1).join(' ') + editor.transact => + editor.selectAll() + editor.splitSelectionsIntoLines() + @replaceTabsWithSpaces(selection) for selection in editor.getSelections() + editor.setCursorBufferPosition([0, 0]) + + replaceTabsWithSpaces: (selection) -> + text = selection.getText() + newText = text.replace /^\t+/, '' + indentation = Array(text.length - newText.length + 1).join(spaces) + selection.insertText(indentation + newText) + selection.clear() + +module.exports = new TabsToSpaces diff --git a/menus/tabs-to-spaces.cson b/menus/tabs-to-spaces.cson new file mode 100644 index 0000000..af27c31 --- /dev/null +++ b/menus/tabs-to-spaces.cson @@ -0,0 +1,15 @@ +'context-menu': + '.overlayer': + 'Convert Tabs to Spaces': 'tabs-to-spaces:convert' + +'menu': [ + { + 'label': 'Packages' + 'submenu': [ + 'label': 'Tabs to Spaces' + 'submenu': [ + { 'label': 'Convert', 'command': 'tabs-to-spaces:convert' } + ] + ] + } +] diff --git a/package.json b/package.json new file mode 100644 index 0000000..15908b5 --- /dev/null +++ b/package.json @@ -0,0 +1,14 @@ +{ + "name": "tabs-to-spaces", + "main": "./lib/tabs-to-spaces", + "version": "0.0.0", + "description": "Provides the ability to convert all tabs to spaces in a document", + "activationEvents": ["tabs-to-spaces:convert"], + "repository": "https://github.com/lee-dohm/tabs-to-spaces", + "license": "MIT", + "engines": { + "atom": ">0.50.0" + }, + "dependencies": { + } +} diff --git a/spec/tabs-to-spaces-spec.coffee b/spec/tabs-to-spaces-spec.coffee new file mode 100644 index 0000000..82b799a --- /dev/null +++ b/spec/tabs-to-spaces-spec.coffee @@ -0,0 +1,5 @@ +# +# Copyright (c) 2014 by Lifted Studios. All Rights Reserved. +# + +describe 'TabsToSpaces', ->