Fixes #894. Default options are extracted from Atom Editor options

This is for indent_size, indent_char, indent_with_tabs, and wrap_attributes_indent_size.
This commit is contained in:
Glavin Wiechert 2017-04-15 19:09:27 -03:00
parent 7990806008
commit 147f97d4c7
18 changed files with 351 additions and 365 deletions

View File

@ -82,12 +82,6 @@ Handlebars.registerHelper('example-config', (key, option, options) ->
Handlebars.registerHelper('language-beautifiers-support', (languageOptions, options) -> Handlebars.registerHelper('language-beautifiers-support', (languageOptions, options) ->
###
| Language | Supported Beautifiers |
| --- | ---- |
| JavaScript | Js-Beautify, Pretty Diff |
###
rows = _.map(languageOptions, (val, k) -> rows = _.map(languageOptions, (val, k) ->
name = val.title name = val.title
defaultBeautifier = _.get(val, "properties.default_beautifier.default") defaultBeautifier = _.get(val, "properties.default_beautifier.default")

File diff suppressed because it is too large Load Diff

View File

@ -185,6 +185,7 @@ buildOptionsForBeautifiers = function(beautifiers, allLanguages) {
type: 'object', type: 'object',
description: "Options for language " + lang.name, description: "Options for language " + lang.name,
collapsed: true, collapsed: true,
scope: lang.scope,
beautifiers: [], beautifiers: [],
grammars: lang.grammars, grammars: lang.grammars,
extensions: lang.extensions, extensions: lang.extensions,

View File

@ -110,11 +110,32 @@ module.exports = class Beautifiers extends EventEmitter
new Beautifier() new Beautifier()
) )
@options = @loadOptions()
loadOptions : ->
try try
@options = require('../options.json') options = require('../options.json')
catch options = _.mapValues(options, (lang) ->
console.warn('Beautifier options not found.') scope = lang.scope
@options = {} tabLength = atom?.config.get('editor.tabLength', scope: scope)
softTabs = atom?.config.get('editor.softTabs', scope: scope)
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
if _.has(lang, "properties.indent_size")
_.set(lang, "properties.indent_size.default", defaultIndentSize)
if _.has(lang, "properties.indent_char")
_.set(lang, "properties.indent_char.default", defaultIndentChar)
if _.has(lang, "properties.indent_with_tabs")
_.set(lang, "properties.indent_with_tabs.default", defaultIndentWithTabs)
if _.has(lang, "properties.wrap_attributes_indent_size")
_.set(lang, "properties.wrap_attributes_indent_size.default", defaultIndentSize)
return lang
)
catch error
console.error("Error loading options", error)
options = {}
return options
### ###
From https://github.com/atom/notifications/blob/01779ade79e7196f1603b8c1fa31716aa4a33911/lib/notification-issue.coffee#L130 From https://github.com/atom/notifications/blob/01779ade79e7196f1603b8c1fa31716aa4a33911/lib/notification-issue.coffee#L130

View File

@ -1,12 +1,8 @@
scope = ['source.sh', 'source.bash']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 2
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
module.exports = { module.exports = {
name: "Bash" name: "Bash"
namespace: "bash" namespace: "bash"
scope: ['source.sh', 'source.bash']
### ###
Supported Grammars Supported Grammars
@ -28,7 +24,7 @@ module.exports = {
options: options:
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"

View File

@ -1,15 +1,9 @@
scope = ['text.html']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "Coldfusion" name: "Coldfusion"
description: "Coldfusion Markup; cfscript is also handled via the prettydiff javascript parser" description: "Coldfusion Markup; cfscript is also handled via the prettydiff javascript parser"
namespace: "cfml" namespace: "cfml"
scope: ['text.html']
### ###
Supported Grammars Supported Grammars
@ -30,12 +24,12 @@ module.exports = {
options: options:
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
minimum: 0 minimum: 0
description: "Indentation character" description: "Indentation character"
wrap_line_length: wrap_line_length:

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['source.css']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "CSS" name: "CSS"
namespace: "css" namespace: "css"
scope: ['source.css']
### ###
Supported Grammars Supported Grammars
@ -31,12 +24,12 @@ module.exports = {
# CSS # CSS
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
minimum: 0 minimum: 0
description: "Indentation character" description: "Indentation character"
selector_separator_newline: selector_separator_newline:

View File

@ -1,14 +1,8 @@
# Get Atom defaults
tabLength = atom?.config.get('editor.tabLength') ? 4
softTabs = atom?.config.get('editor.softTabs') ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "gherkin" name: "gherkin"
namespace: "gherkin" namespace: "gherkin"
scope: []
grammars: [ grammars: [
"Gherkin" "Gherkin"
@ -21,12 +15,12 @@ module.exports = {
options: options:
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
minimum: 0 minimum: 0
description: "Indentation character" description: "Indentation character"
} }

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['text.html']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "HTML" name: "HTML"
namespace: "html" namespace: "html"
scope: ['text.html']
### ###
Supported Grammars Supported Grammars
@ -32,12 +25,12 @@ module.exports = {
description: "Indent <head> and <body> sections." description: "Indent <head> and <body> sections."
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
description: "Indentation character" description: "Indentation character"
brace_style: brace_style:
type: 'string' type: 'string'
@ -60,7 +53,7 @@ module.exports = {
description: "Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline]" description: "Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline]"
wrap_attributes_indent_size: wrap_attributes_indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indent wrapped attributes to after N characters" description: "Indent wrapped attributes to after N characters"
preserve_newlines: preserve_newlines:

View File

@ -1,16 +1,9 @@
# Get Atom defaults
scope = ['text.jade']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "Jade" name: "Jade"
namespace: "jade" namespace: "jade"
fallback: ['html'] fallback: ['html']
scope: ['text.jade']
### ###
Supported Grammars Supported Grammars
@ -29,12 +22,12 @@ module.exports = {
options: [ options: [
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
description: "Indentation character" description: "Indentation character"
omit_div: omit_div:
type: 'boolean' type: 'boolean'

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['source.js']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "JavaScript" name: "JavaScript"
namespace: "js" namespace: "js"
scope: ['source.js']
### ###
Supported Grammars Supported Grammars
@ -46,7 +39,7 @@ module.exports = {
description: "Initial indentation level" description: "Initial indentation level"
indent_with_tabs: indent_with_tabs:
type: 'boolean' type: 'boolean'
default: defaultIndentWithTabs default: null
description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`" description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`"
preserve_newlines: preserve_newlines:
type: 'boolean' type: 'boolean'

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['source.js']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "LaTeX" name: "LaTeX"
namespace: "latex" namespace: "latex"
scope: ['source.tex']
### ###
Supported Grammars Supported Grammars
@ -33,11 +26,11 @@ module.exports = {
options: options:
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
description: "Indentation character" description: "Indentation character"
indent_with_tabs: indent_with_tabs:
type: 'boolean' type: 'boolean'
default: true default: null
description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`" description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`"
indent_preamble: indent_preamble:
type: 'boolean' type: 'boolean'

View File

@ -1,16 +1,9 @@
# Get Atom defaults
scope = ['text.marko']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 4)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "Marko" name: "Marko"
namespace: "marko" namespace: "marko"
fallback: ['html'] fallback: ['html']
scope: ['text.marko']
### ###
Supported Grammars Supported Grammars
@ -29,12 +22,12 @@ module.exports = {
options: options:
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
description: "Indentation character" description: "Indentation character"
syntax: syntax:
type: 'string' type: 'string'

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['source.conf']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "Nginx" name: "Nginx"
namespace: "nginx" namespace: "nginx"
scope: ['source.conf']
### ###
Supported Grammars Supported Grammars
@ -30,16 +23,16 @@ module.exports = {
options: options:
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char: indent_char:
type: 'string' type: 'string'
default: defaultIndentChar default: null
description: "Indentation character" description: "Indentation character"
indent_with_tabs: indent_with_tabs:
type: 'boolean' type: 'boolean'
default: defaultIndentWithTabs default: null
description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`" description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`"
dontJoinCurlyBracet: dontJoinCurlyBracet:
title: "Don't join curly brackets" title: "Don't join curly brackets"

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['source.python']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "Python" name: "Python"
namespace: "python" namespace: "python"
scope: ['source.python']
### ###
Supported Grammars Supported Grammars
@ -32,7 +25,7 @@ module.exports = {
description: "set maximum allowed line length" description: "set maximum allowed line length"
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
ignore: ignore:

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['text.html']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "R" name: "R"
namespace: "r" namespace: "r"
scope: ['text.r']
### ###
Supported Grammars Supported Grammars
@ -29,7 +22,7 @@ module.exports = {
options: options:
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
description: "Indentation size/length" description: "Indentation size/length"
} }

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['source.ruby']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "Ruby" name: "Ruby"
namespace: "ruby" namespace: "ruby"
scope: ['source.ruby']
### ###
Supported Grammars Supported Grammars
@ -29,19 +22,18 @@ module.exports = {
options: options:
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
indent_char:
type: 'string'
default: null
description: "Indentation character"
enum: [" ", "\t"]
rubocop_path: rubocop_path:
title: "Rubocop Path" title: "Rubocop Path"
type: 'string' type: 'string'
default: "" default: ""
description: "Path to the `rubocop` CLI executable" description: "Path to the `rubocop` CLI executable"
indent_char:
type: 'string'
default: defaultIndentChar
description: "Indentation character"
enum: [" ", "\t"]
} }

View File

@ -1,15 +1,8 @@
# Get Atom defaults
scope = ['source.sql']
tabLength = atom?.config.get('editor.tabLength', scope: scope) ? 4
softTabs = atom?.config.get('editor.softTabs', scope: scope) ? true
defaultIndentSize = (if softTabs then tabLength else 1)
defaultIndentChar = (if softTabs then " " else "\t")
defaultIndentWithTabs = not softTabs
module.exports = { module.exports = {
name: "SQL" name: "SQL"
namespace: "sql" namespace: "sql"
scope: ['source.sql']
### ###
Supported Grammars Supported Grammars
@ -30,7 +23,7 @@ module.exports = {
# SQL # SQL
indent_size: indent_size:
type: 'integer' type: 'integer'
default: defaultIndentSize default: null
minimum: 0 minimum: 0
description: "Indentation size/length" description: "Indentation size/length"
keywords: keywords: