Closes #308. Beautify On Save is opt-in for each language

Deprecate old global beautifyOnSave option
This commit is contained in:
Glavin Wiechert 2015-05-06 12:35:34 -03:00
parent d1b0e6d66d
commit a94721e1b5
2 changed files with 42 additions and 5 deletions

View File

@ -213,6 +213,13 @@ module.exports = class Beautifiers
description: "Default Beautifier to be used for #{name}"
enum: _.uniq(beautifiers)
}
flatOptions["#{optionName}_beautify_on_save"] = {
title: "Language Config - #{name} - Beautify On Save"
type: 'boolean'
default: false
description: "Automatically beautify #{name} files on save"
}
# logger.verbose('flatOptions', flatOptions)
return flatOptions
@ -236,7 +243,7 @@ module.exports = class Beautifiers
###
###
beautify: (text, allOptions, grammar, filePath) ->
beautify: (text, allOptions, grammar, filePath, {onSave}={}) ->
return new Promise((resolve, reject) =>
logger.info('beautify', text, allOptions, grammar, filePath)
@ -247,13 +254,19 @@ module.exports = class Beautifiers
# Check if unsupported language
if languages.length < 1
unsupportedGrammar = true
# Check if on save
if onSave
# Ignore this, as it was just a general file save, and
# not intended to be beautified
return resolve(null)
else
# TODO: select appropriate language
language = languages[0]
# Get language config
langDisabled = atom.config.get("atom-beautify.language_#{language.namespace}_disabled")
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
# Beautify!
unsupportedGrammar = false
@ -261,6 +274,16 @@ module.exports = class Beautifiers
if langDisabled
return resolve(null)
# Get more language config
preferredBeautifierName = atom.config.get("atom-beautify.language_#{language.namespace}_default_beautifier")
beautifyOnSave = atom.config.get("atom-beautify.language_#{language.namespace}_beautify_on_save")
legacyBeautifyOnSave = atom.config.get("atom-beautify.beautifyOnSave")
# Verify if beautifying on save
if onSave and not (beautifyOnSave or legacyBeautifyOnSave)
# Saving, and beautify on save is disabled
return resolve(null)
# Options for Language
options = @getOptions(language.namespace, allOptions) || {}
# Support fallback for options

View File

@ -43,8 +43,21 @@ setCursors = (editor, posArray) ->
return
beautify = ({onSave}) ->
# Verify if beautify on save
return if onSave and atom.config.get("atom-beautify.beautifyOnSave") is false
# 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")
LoadingView ?= require "./views/loading-view"
@ -133,7 +146,7 @@ beautify = ({onSave}) ->
grammarName = editor.getGrammar().name
# Finally, beautify!
try
beautifier.beautify(text, allOptions, grammarName, editedFilePath)
beautifier.beautify(text, allOptions, grammarName, editedFilePath, onSave:onSave)
.then(beautifyCompleted)
.catch(beautifyCompleted)
catch e
@ -350,6 +363,7 @@ plugin.config = _.merge(
description: 'Set the level for the logger'
enum: ['verbose','debug','info','warn','error']
beautifyOnSave:
title: "DEPRECATED: Beautfy On Save"
type: 'boolean'
default: false
description: "Beautify active editor on save"