Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
t9md committed Jun 9, 2015
1 parent 862614a commit f08db01
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
@@ -0,0 +1,3 @@
.DS_Store
npm-debug.log
node_modules
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -0,0 +1 @@
## 0.1.0 - First Release
20 changes: 20 additions & 0 deletions LICENSE.md
@@ -0,0 +1,20 @@
Copyright (c) 2015 t9md

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.
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -2,6 +2,8 @@

Toggle word at cursor

![gif](https://raw.githubusercontent.com/t9md/t9md/846644d6d84621ec8d2b2405d1b0059c9a357714/img/atom-toggle.gif)

# Development state

Alpha
Expand Down Expand Up @@ -36,4 +38,4 @@ e.g.

# TODO
* [ ] Support language specific keyword handling
* [ ] Customize toggle function by user's function.
* [ ] Customizable toggle behavior by user function.
64 changes: 64 additions & 0 deletions lib/main.coffee
@@ -0,0 +1,64 @@
{CompositeDisposable} = require 'atom'
_ = require 'underscore-plus'

Config =
wordGroup:
type: 'array'
default: [
['yes' , 'no']
['up' , 'down']
['right' , 'left']
['true' , 'false']
['high' , 'low']
['column', 'row']
['and' , 'or']
['not' , '']
['on' , 'off']
['in' , 'out']
['this' , '@']
['is' , 'isnt']
['one' , 'two' , 'three']
]

module.exports =
disposables: null
config: Config

activate: (state) ->
@disposables = new CompositeDisposable

@disposables.add atom.commands.add 'atom-workspace',
'toggle:toggle': => @toggle()

deactivate: ->
@disposables.dispose()

serialize: ->

getWord: (word) ->
wordGroup = atom.config.get('toggle.wordGroup')
words = _.detect(wordGroup, (words) -> word in words)
return null unless words
index = words.indexOf(word)

nextIndex = index + 1
if nextIndex is words.length
nextIndex = 0

words[nextIndex]

toggleWord: (cursor) ->
range = cursor.getCurrentWordBufferRange()
word = cursor.editor.getTextInBufferRange range
newWord = @getWord word
if newWord?
cursor.editor.setTextInBufferRange(range, newWord)

toggle: ->
console.log 'called'
return unless editor = atom.workspace.getActiveTextEditor()
editor.transact =>
for cursor in editor.getCursors()
position = cursor.getBufferPosition()
@toggleWord(cursor)
cursor.setBufferPosition(position)
17 changes: 17 additions & 0 deletions package.json
@@ -0,0 +1,17 @@
{
"name": "toggle",
"main": "./lib/main",
"version": "0.0.0",
"description": "Toggle word at cursor",
"repository": "https://github.com/t9md/atom-toggle",
"activationCommands": {
"atom-workspace": "toggle:toggle"
},
"license": "MIT",
"engines": {
"atom": ">=0.174.0 <2.0.0"
},
"dependencies": {
"underscore-plus": "^1.6.6"
}
}

0 comments on commit f08db01

Please sign in to comment.