Merge pull request #1598 from Glavin001/issue894

Fixes #894. Default options are extracted from Atom Editor options
This commit is contained in:
Glavin Wiechert 2017-04-15 19:55:39 -03:00 committed by GitHub
commit c881bdf656
19 changed files with 78 additions and 161 deletions

View File

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

View File

@ -414,7 +414,7 @@ Automatically beautify Bash files on save
**Key**: `indent_size`
**Default**: `2`
**Default**: `4`
**Type**: `integer`
@ -429,7 +429,7 @@ Indentation size/length (Supported by beautysh)
```json
{
"bash": {
"indent_size": 2
"indent_size": 4
}
}
```
@ -7216,8 +7216,6 @@ Indent the preable (Supported by Latex Beautify)
**Key**: `indent_with_tabs`
**Default**: `true`
**Type**: `boolean`
**Supported Beautifiers**: [`Latex Beautify`](#latex-beautify)
@ -7231,7 +7229,7 @@ Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by L
```json
{
"latex": {
"indent_with_tabs": true
"indent_with_tabs": false
}
}
```
@ -16446,8 +16444,6 @@ Indentation character (Supported by Latex Beautify)
**Key**: `indent_with_tabs`
**Default**: `true`
**Type**: `boolean`
**Supported Beautifiers**: [`Latex Beautify`](#latex-beautify)
@ -16461,7 +16457,7 @@ Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by L
```json
{
"latex": {
"indent_with_tabs": true
"indent_with_tabs": false
}
}
```
@ -19380,7 +19376,7 @@ defines how from imports wrap (requires isort installed) (Supported by autopep8,
**Key**: `indent_size`
**Default**: `2`
**Default**: `4`
**Type**: `integer`
@ -19395,7 +19391,7 @@ Indentation size/length (Supported by beautysh)
```json
{
"bash": {
"indent_size": 2
"indent_size": 4
}
}
```

View File

@ -327,7 +327,6 @@
},
"scripts": {
"build-options": "node script/build-options.js",
"postinstall": "npm run build-options",
"docs": "npm run build-options && coffee docs/",
"prepublish": "npm run docs",
"lint": "coffeelint src/ spec/",

View File

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

View File

@ -110,11 +110,32 @@ module.exports = class Beautifiers extends EventEmitter
new Beautifier()
)
@options = @loadOptions()
loadOptions : ->
try
@options = require('../options.json')
catch
console.warn('Beautifier options not found.')
@options = {}
options = require('../options.json')
options = _.mapValues(options, (lang) ->
scope = lang.scope
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
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

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 = {
name: "Bash"
namespace: "bash"
scope: ['source.sh', 'source.bash']
###
Supported Grammars
@ -28,7 +24,7 @@ module.exports = {
options:
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
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 = {
name: "Coldfusion"
description: "Coldfusion Markup; cfscript is also handled via the prettydiff javascript parser"
namespace: "cfml"
scope: ['text.html']
###
Supported Grammars
@ -30,12 +24,12 @@ module.exports = {
options:
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
minimum: 0
description: "Indentation character"
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 = {
name: "CSS"
namespace: "css"
scope: ['source.css']
###
Supported Grammars
@ -31,12 +24,12 @@ module.exports = {
# CSS
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
minimum: 0
description: "Indentation character"
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 = {
name: "gherkin"
namespace: "gherkin"
scope: []
grammars: [
"Gherkin"
@ -21,12 +15,12 @@ module.exports = {
options:
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
minimum: 0
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 = {
name: "HTML"
namespace: "html"
scope: ['text.html']
###
Supported Grammars
@ -32,12 +25,12 @@ module.exports = {
description: "Indent <head> and <body> sections."
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
description: "Indentation character"
brace_style:
type: 'string'
@ -60,7 +53,7 @@ module.exports = {
description: "Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline]"
wrap_attributes_indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indent wrapped attributes to after N characters"
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 = {
name: "Jade"
namespace: "jade"
fallback: ['html']
scope: ['text.jade']
###
Supported Grammars
@ -29,12 +22,12 @@ module.exports = {
options: [
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
description: "Indentation character"
omit_div:
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 = {
name: "JavaScript"
namespace: "js"
scope: ['source.js']
###
Supported Grammars
@ -33,12 +26,12 @@ module.exports = {
# JavaScript
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
description: "Indentation character"
indent_level:
type: 'integer'
@ -46,7 +39,7 @@ module.exports = {
description: "Initial indentation level"
indent_with_tabs:
type: 'boolean'
default: defaultIndentWithTabs
default: null
description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`"
preserve_newlines:
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 = {
name: "LaTeX"
namespace: "latex"
scope: ['source.tex']
###
Supported Grammars
@ -33,11 +26,11 @@ module.exports = {
options:
indent_char:
type: 'string'
default: defaultIndentChar
default: null
description: "Indentation character"
indent_with_tabs:
type: 'boolean'
default: true
default: null
description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`"
indent_preamble:
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 = {
name: "Marko"
namespace: "marko"
fallback: ['html']
scope: ['text.marko']
###
Supported Grammars
@ -29,12 +22,12 @@ module.exports = {
options:
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
description: "Indentation character"
syntax:
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 = {
name: "Nginx"
namespace: "nginx"
scope: ['source.conf']
###
Supported Grammars
@ -30,16 +23,16 @@ module.exports = {
options:
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: defaultIndentChar
default: null
description: "Indentation character"
indent_with_tabs:
type: 'boolean'
default: defaultIndentWithTabs
default: null
description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`"
dontJoinCurlyBracet:
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 = {
name: "Python"
namespace: "python"
scope: ['source.python']
###
Supported Grammars
@ -32,7 +25,7 @@ module.exports = {
description: "set maximum allowed line length"
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
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 = {
name: "R"
namespace: "r"
scope: ['text.r']
###
Supported Grammars
@ -29,7 +22,7 @@ module.exports = {
options:
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
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 = {
name: "Ruby"
namespace: "ruby"
scope: ['source.ruby']
###
Supported Grammars
@ -29,19 +22,18 @@ module.exports = {
options:
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
indent_char:
type: 'string'
default: null
description: "Indentation character"
enum: [" ", "\t"]
rubocop_path:
title: "Rubocop Path"
type: 'string'
default: ""
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 = {
name: "SQL"
namespace: "sql"
scope: ['source.sql']
###
Supported Grammars
@ -30,7 +23,7 @@ module.exports = {
# SQL
indent_size:
type: 'integer'
default: defaultIndentSize
default: null
minimum: 0
description: "Indentation size/length"
keywords: