Add support for :set [option]

This commit is contained in:
Nikita Zyuzin 2015-07-13 23:06:03 +04:00
parent 13c5c84688
commit 0f38fd195a
2 changed files with 47 additions and 0 deletions

View file

@ -1,6 +1,7 @@
path = require 'path'
CommandError = require './command-error'
fs = require 'fs'
VimOption = require './vim-option'
trySave = (func) ->
deferred = Promise.defer()
@ -232,4 +233,27 @@ class Ex
range = [[range[0], 0], [range[1] + 1, 0]]
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

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