See #713. Properly extract configuration from package settings
This commit is contained in:
parent
43a3647e31
commit
caabb95ed7
|
@ -122,7 +122,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
beautifiers = @getBeautifiers(language.name)
|
||||
logger.verbose('beautifiers', _.map(beautifiers, 'name'))
|
||||
# Select beautifier from language config preferences
|
||||
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
|
||||
preferredBeautifierName = atom.config.get("atom-beautify.#{language.namespace}.default_beautifier")
|
||||
beautifier = _.find(beautifiers, (beautifier) ->
|
||||
beautifier.name is preferredBeautifierName
|
||||
) or beautifiers[0]
|
||||
|
@ -229,7 +229,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
logger.verbose("Language #{language.name} supported")
|
||||
|
||||
# Get language config
|
||||
langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled")
|
||||
langDisabled = atom.config.get("atom-beautify.#{language.namespace}.disabled")
|
||||
|
||||
|
||||
# Beautify!
|
||||
|
@ -242,11 +242,10 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
return resolve( null )
|
||||
|
||||
# Get more language config
|
||||
beautifyOnSave = atom.config.get("atom-beautify.language_#{language.namespace}_beautify_on_save")
|
||||
legacyBeautifyOnSave = atom.config.get("atom-beautify.beautifyOnSave")
|
||||
beautifyOnSave = atom.config.get("atom-beautify.#{language.namespace}.beautify_on_save")
|
||||
|
||||
# Verify if beautifying on save
|
||||
if onSave and not (beautifyOnSave or legacyBeautifyOnSave)
|
||||
if onSave and not beautifyOnSave
|
||||
logger.verbose("Beautify on save is disabled for language #{language.name}")
|
||||
# Saving, and beautify on save is disabled
|
||||
return resolve( null )
|
||||
|
@ -410,32 +409,7 @@ module.exports = class Beautifiers extends EventEmitter
|
|||
null
|
||||
getConfigOptionsFromSettings : (langs) ->
|
||||
config = atom.config.get('atom-beautify')
|
||||
options = {}
|
||||
|
||||
|
||||
# logger.verbose(langs, config);
|
||||
# Iterate over keys of the settings
|
||||
_.every _.keys(config), (k) ->
|
||||
|
||||
# Check if keys start with a language
|
||||
p = k.split("_")[0]
|
||||
idx = _.indexOf(langs, p)
|
||||
|
||||
|
||||
# logger.verbose(k, p, idx);
|
||||
if idx >= 0
|
||||
|
||||
# Remove the language prefix and nest in options
|
||||
lang = langs[idx]
|
||||
opt = k.replace( new RegExp("^" + lang + "_"), "")
|
||||
options[lang] = options[lang] or {}
|
||||
options[lang][opt] = config[k]
|
||||
|
||||
# logger.verbose(lang, opt)
|
||||
true
|
||||
|
||||
# logger.verbose(options)
|
||||
options
|
||||
options = _.pick(config, langs)
|
||||
|
||||
# Look for .jsbeautifierrc in file and home path, check env variables
|
||||
getConfig : (startPath, upwards = true) ->
|
||||
|
|
|
@ -66,21 +66,6 @@ showError = (error) ->
|
|||
stack, detail, dismissable : true})
|
||||
|
||||
beautify = ({onSave}) ->
|
||||
# Deprecation warning for beautify on save
|
||||
if atom.config.get("atom-beautify.beautifyOnSave") is true
|
||||
detail = """See issue https://github.com/Glavin001/atom-beautify/issues/308
|
||||
|
||||
To stop seeing this message:
|
||||
- Uncheck (disable) the deprecated \"Beautify On Save\" option
|
||||
|
||||
To enable Beautify on Save for a particular language:
|
||||
- Go to Atom Beautify's package settings
|
||||
- Find option for \"Language Config - <Your Language> - Beautify On Save\"
|
||||
- Check (enable) Beautify On Save option for that particular language
|
||||
|
||||
"""
|
||||
|
||||
atom?.notifications.addWarning("The option \"atom-beautify.beautifyOnSave\" has been deprecated", {detail, dismissable : true})
|
||||
|
||||
# Continue beautifying
|
||||
path ?= require("path")
|
||||
|
@ -490,7 +475,7 @@ handleSaveEvent = ->
|
|||
# TODO: select appropriate language
|
||||
language = languages[0]
|
||||
# Get language config
|
||||
key = "atom-beautify.language_#{language.namespace}_beautify_on_save"
|
||||
key = "atom-beautify.#{language.namespace}.beautify_on_save"
|
||||
beautifyOnSave = atom.config.get(key)
|
||||
logger.verbose('save editor positions', key, beautifyOnSave)
|
||||
if beautifyOnSave
|
||||
|
@ -516,7 +501,6 @@ plugin.config = _.merge(require('./config.coffee'), defaultLanguageOptions)
|
|||
plugin.activate = ->
|
||||
@subscriptions = new CompositeDisposable
|
||||
@subscriptions.add handleSaveEvent()
|
||||
@subscriptions.add atom.config.observe("atom-beautify.beautifyOnSave", handleSaveEvent)
|
||||
@subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:beautify-editor", beautify
|
||||
@subscriptions.add atom.commands.add "atom-workspace", "atom-beautify:help-debug-editor", debug
|
||||
@subscriptions.add atom.commands.add ".tree-view .file .name", "atom-beautify:beautify-file", beautifyFile
|
||||
|
|
Loading…
Reference in New Issue