Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Dohm committed Mar 8, 2014
0 parents commit 8b8d198
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
20 changes: 20 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright &copy 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.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
29 changes: 29 additions & 0 deletions lib/tabs-to-spaces.coffee
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions menus/tabs-to-spaces.cson
Original file line number Diff line number Diff line change
@@ -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' }
]
]
}
]
14 changes: 14 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
}
}
5 changes: 5 additions & 0 deletions spec/tabs-to-spaces-spec.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#
# Copyright (c) 2014 by Lifted Studios. All Rights Reserved.
#

describe 'TabsToSpaces', ->

0 comments on commit 8b8d198

Please sign in to comment.