From 79fcdd9111fffc883305cb1b00b2f23806192952 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Sun, 28 Sep 2014 16:22:29 -0300 Subject: [PATCH] Closes #105. Add options to mute errors. New options: - muteUnsupportedLanguageErrors - muteAllErrors --- README.md | 17 +++++++++++++++-- lib/beautify.coffee | 19 ++++++++++++------- lib/language-options.coffee | 7 +++++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 93cb368..25b56b8 100644 --- a/README.md +++ b/README.md @@ -85,10 +85,23 @@ For example: ### Package Options -- `beautifyOnSave` +- `beautifyOnSave` (Default *false*) You can also choose to beautify on every file save. -- `analytics` +- `beautifyEntireFileOnSave` (Default *true*) +Beautification will normally only beautify your selected text. +However, when beautification occurs on save then it will +be forced to beautify the entire file's contents, +not just selected text. + +- `muteUnsupportedLanguageErrors` (Default *false*) +Mute only *unsupported language* errors. + +- `muteAllErrors` (Default *false*) +Do not show the *Atom Beautify Error Messages* panel +for any of the errors occurring while beautifying. + +- `analytics` (Default *true*) There is [Segment.io](https://segment.io/), which forwards the data to [Google Analytics](http://www.google.com/analytics/), to track what languages diff --git a/lib/beautify.coffee b/lib/beautify.coffee index cbbff91..8173903 100644 --- a/lib/beautify.coffee +++ b/lib/beautify.coffee @@ -136,13 +136,14 @@ beautify = -> forceEntireFile = atom.config.get("atom-beautify.beautifyEntireFileOnSave") # Show error showError = (e) => - # console.log(e) @loadingView.hide() - @messagePanel.attach() - @messagePanel.add(new PlainMessageView({ - message: e.message, - className: 'text-error' - })) + if not atom.config.get("atom-beautify.muteAllErrors") + # console.log(e) + @messagePanel.attach() + @messagePanel.add(new PlainMessageView({ + message: e.message, + className: 'text-error' + })) # Look for .jsbeautifierrc in file and home path, check env variables getConfig = (startPath, upwards=true) -> # Verify that startPath is a string @@ -185,7 +186,9 @@ beautify = -> # Asynchronously and callback-style beautifyCompleted = (text) => # console.log 'beautifyCompleted' - if text instanceof Error + if not text? + # Do nothing, is undefined + else if text instanceof Error showError(text) else if oldText isnt text # console.log "Replacing current editor's text with new text" @@ -313,6 +316,8 @@ plugin.configDefaults = _.merge( analytics: true beautifyOnSave: false beautifyEntireFileOnSave: true + muteUnsupportedLanguageErrors: false + muteAllErrors: false , defaultLanguageOptions) plugin.activate = -> handleSaveEvent() diff --git a/lib/language-options.coffee b/lib/language-options.coffee index 9061802..7d796b2 100644 --- a/lib/language-options.coffee +++ b/lib/language-options.coffee @@ -88,7 +88,7 @@ module.exports = sql_keywords: "upper" sql_identifiers: "lower" sql_sqlformat_path: "" - + # Markdown markdown_pandoc_path: "" @@ -252,7 +252,10 @@ module.exports = category: version # if unsupportedGrammar - throw new Error("Unsupported language for grammar '#{grammar}'.") + if atom.config.get("atom-beautify.muteUnsupportedLanguageErrors") + return beautifyCompleted(null) + else + throw new Error("Unsupported language for grammar '#{grammar}'.") return getOptions: (selection, allOptions) ->