Add support for :set [option]
This commit is contained in:
parent
13c5c84688
commit
0f38fd195a
2 changed files with 47 additions and 0 deletions
|
|
@ -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()
|
||||||
|
|
@ -232,4 +233,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
23
lib/vim-option.coffee
Normal 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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue