Merge pull request #69 from nzyuzin/set_options

Add support for :set [option]
This commit is contained in:
Loic Nageleisen 2015-07-28 11:30:35 +02:00
commit e679604c21
2 changed files with 47 additions and 0 deletions

View file

@ -1,6 +1,7 @@
path = require 'path' path = require 'path'
CommandError = require './command-error' CommandError = require './command-error'
fs = require 'fs' fs = require 'fs'
VimOption = require './vim-option'
trySave = (func) -> trySave = (func) ->
deferred = Promise.defer() deferred = Promise.defer()
@ -235,4 +236,27 @@ class Ex
range = [[range[0], 0], [range[1] + 1, 0]] range = [[range[0], 0], [range[1] + 1, 0]]
atom.workspace.getActiveTextEditor().buffer.setTextInRange(range, '') atom.workspace.getActiveTextEditor().buffer.setTextInRange(range, '')
set: (range, args) ->
args = args.trim()
if args == ""
throw new CommandError("No option specified")
options = args.split(' ')
for option in options
do ->
if option.includes("=")
nameValPair = option.split("=")
if (nameValPair.length != 2)
throw new CommandError("Wrong option format. [name]=[value] format is expected")
optionName = nameValPair[0]
optionValue = nameValPair[1]
optionProcessor = VimOption.singleton()[optionName]
if not optionProcessor?
throw new CommandError("No such option: #{optionName}")
optionProcessor(optionValue)
else
optionProcessor = VimOption.singleton()[option]
if not optionProcessor?
throw new CommandError("No such option: #{option}")
optionProcessor()
module.exports = Ex module.exports = Ex

23
lib/vim-option.coffee Normal file
View file

@ -0,0 +1,23 @@
class VimOption
@singleton: =>
@option ||= new VimOption
list: =>
atom.config.set("editor.showInvisibles", true)
nolist: =>
atom.config.set("editor.showInvisibles", false)
number: =>
atom.config.set("editor.showLineNumbers", true)
nu: =>
@number()
nonumber: =>
atom.config.set("editor.showLineNumbers", false)
nonu: =>
@nonumber()
module.exports = VimOption