diff --git a/lib/ex.coffee b/lib/ex.coffee index 6a887ee..f2b0b35 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -1,6 +1,7 @@ path = require 'path' CommandError = require './command-error' fs = require 'fs' +VimOption = require './vim-option' trySave = (func) -> deferred = Promise.defer() @@ -235,4 +236,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 diff --git a/lib/vim-option.coffee b/lib/vim-option.coffee new file mode 100644 index 0000000..2ee056c --- /dev/null +++ b/lib/vim-option.coffee @@ -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