add basic "set" command, with "ft" and "tw" options

This commit is contained in:
Rom Grk 2015-05-27 22:15:05 -04:00
parent 86101ef8ac
commit 5fe2f87c24

View file

@ -165,6 +165,28 @@ class Ex
else
pane.splitUp(copyActiveItem: true)
set: (args...) ->
editor = ->
atom.workspace.getActiveTextEditor()
arg = args[1]
regex = /\s*(\w+)(?:\s*=\s*([\d\w]+)\s*|(!))/
matches = arg.match regex
return unless matches?
[whole, option, value, bang] = matches
switch option
when 'tw'
editor().setTabLength(parseInt(value))
when 'ft'
regex = new RegExp "(source|text)\.#{value}$"
lowerCaseName = value.toLowerCase()
for name, grammar of atom.grammars.grammarsByScopeName
grammarName = grammar.name.toLowerCase()
if name.match(regex) or lowerCaseName is grammarName
editor().setGrammar(grammar)
sp: (args...) => @split(args...)
substitute: (range, args) ->