Skip to content

Commit

Permalink
Closes #308. Beautify On Save is opt-in for each language
Browse files Browse the repository at this point in the history
Deprecate old global beautifyOnSave option
  • Loading branch information
Glavin001 committed May 6, 2015
1 parent d1b0e6d commit a94721e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
27 changes: 25 additions & 2 deletions src/beautifiers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -247,20 +254,36 @@ 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
# Check if Language is disabled
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
Expand Down
20 changes: 17 additions & 3 deletions src/beautify.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit a94721e

Please sign in to comment.