Merge pull request #1625 from hxsf/master
Fixed #1613 and #1588. Add EOL, scientific notiation, and adjust whitespace support
This commit is contained in:
commit
800066963c
|
@ -7633,6 +7633,7 @@ Maximum amount of characters per line (0 = disable) (Supported by Pretty Diff)
|
|||
| `disabled` | :white_check_mark: |
|
||||
| `default_beautifier` | :white_check_mark: |
|
||||
| `beautify_on_save` | :white_check_mark: |
|
||||
| `end_of_line` | :white_check_mark: |
|
||||
|
||||
**Description**:
|
||||
|
||||
|
@ -7693,6 +7694,34 @@ Automatically beautify Lua files on save
|
|||
2. Go into *Packages* and search for "*Atom Beautify*" package.
|
||||
3. Find the option "*Beautify On Save*" and change it to your desired configuration.
|
||||
|
||||
##### [End of line](#end-of-line)
|
||||
|
||||
**Namespace**: `lua`
|
||||
|
||||
**Key**: `end_of_line`
|
||||
|
||||
**Default**: `System Default`
|
||||
|
||||
**Type**: `string`
|
||||
|
||||
**Enum**: `CRLF` `LF` `System Default`
|
||||
|
||||
**Supported Beautifiers**: [`Lua beautifier`](#lua-beautifier)
|
||||
|
||||
**Description**:
|
||||
|
||||
Override EOL from line-ending-selector (Supported by Lua beautifier)
|
||||
|
||||
**Example `.jsbeautifyrc` Configuration**
|
||||
|
||||
```json
|
||||
{
|
||||
"lua": {
|
||||
"end_of_line": "System Default"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### [Markdown](#markdown)
|
||||
|
||||
**Supported Beautifiers**: [`Remark`](#remark) [`Tidy Markdown`](#tidy-markdown)
|
||||
|
@ -16831,6 +16860,37 @@ Remove trailing whitespace (Supported by Latex Beautify)
|
|||
```
|
||||
|
||||
|
||||
### Lua beautifier
|
||||
|
||||
##### [End of line](#end-of-line)
|
||||
|
||||
**Namespace**: `lua`
|
||||
|
||||
**Key**: `end_of_line`
|
||||
|
||||
**Default**: `System Default`
|
||||
|
||||
**Type**: `string`
|
||||
|
||||
**Enum**: `CRLF` `LF` `System Default`
|
||||
|
||||
**Supported Beautifiers**: [`Lua beautifier`](#lua-beautifier)
|
||||
|
||||
**Description**:
|
||||
|
||||
Override EOL from line-ending-selector (Supported by Lua beautifier)
|
||||
|
||||
**Example `.jsbeautifyrc` Configuration**
|
||||
|
||||
```json
|
||||
{
|
||||
"lua": {
|
||||
"end_of_line": "System Default"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### Marko Beautifier
|
||||
|
||||
##### [Indent size](#indent-size)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
-- and return a closure which can be used for continuing the sort.
|
||||
local a = 'a b c'
|
||||
local b = '12345678'
|
||||
local x = 1.99e-07
|
||||
local c = 'a b c' + 'a b c'
|
||||
local t = {
|
||||
a = 1,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
-- and return a closure which can be used for continuing the sort.
|
||||
local a= 'a b c'
|
||||
local b ='12345678'
|
||||
local x = 1.99e-07
|
||||
local c = 'a b c' +'a b c'
|
||||
local t = {
|
||||
a = 1,
|
||||
|
|
|
@ -8,7 +8,8 @@ adjust_space = (line) ->
|
|||
# replace all whitespaces inside the string with one space, WARNING: the whitespaces in string will be replace too!
|
||||
line = line.replace /\s?(==|>=|<=|~=|[=><\+\*\/])\s?/g, ' $1 '
|
||||
# add whitespace around the operator
|
||||
line = line.replace /([^=|\-|(|\s])\s?\-\s?([^\-|\[])/g, '$1 - $2'
|
||||
line = line.replace /([^=e\-\(\s])\s?\-\s?([^\-\[])/g, '$1 - $2'
|
||||
line = line.replace /([^\d])e\s?\-\s?([^\-\[])/g, '$1e - $2'
|
||||
# just format minus, not for -- or negative number or commentary.
|
||||
line = line.replace /,([^\s])/g, ', $1'
|
||||
# adjust ','
|
||||
|
@ -25,7 +26,8 @@ adjust_space = (line) ->
|
|||
DEFAULT_WARN_FN = (msg) ->
|
||||
console.log('WARNING:', msg)
|
||||
|
||||
module.exports = (str, indent, warn_fn) ->
|
||||
module.exports = (str, indent, warn_fn, opts = {}) ->
|
||||
eol = opts?.eol or '\n'
|
||||
indent = indent or DEFAULT_INDENT
|
||||
warn_fn = if typeof warn_fn == 'function' then warn_fn else DEFAULT_WARN_FN
|
||||
indent = ' '.repeat(indent) if Number.isInteger(indent)
|
||||
|
@ -100,4 +102,4 @@ module.exports = (str, indent, warn_fn) ->
|
|||
new_line or undefined
|
||||
|
||||
warn_fn 'positive indentation at the end' if $currIndent > 0
|
||||
new_code.join '\n'
|
||||
new_code.join eol
|
||||
|
|
|
@ -16,8 +16,9 @@ module.exports = class Lua extends Beautifier
|
|||
}
|
||||
|
||||
beautify: (text, language, options) ->
|
||||
options.eol = @getDefaultLineEnding('\r\n','\n',options.end_of_line)
|
||||
new @Promise (resolve, reject) ->
|
||||
try
|
||||
resolve format text, options.indent_char.repeat options.indent_size
|
||||
resolve format text, options.indent_char.repeat(options.indent_size), @warn, options
|
||||
catch error
|
||||
reject error
|
||||
|
|
|
@ -19,4 +19,10 @@ module.exports = {
|
|||
|
||||
defaultBeautifier: "Lua beautifier"
|
||||
|
||||
options:
|
||||
end_of_line:
|
||||
type: 'string'
|
||||
default: "System Default"
|
||||
enum: ["CRLF","LF","System Default"]
|
||||
description: "Override EOL from line-ending-selector"
|
||||
}
|
||||
|
|
|
@ -4576,6 +4576,25 @@
|
|||
"lua"
|
||||
],
|
||||
"properties": {
|
||||
"end_of_line": {
|
||||
"type": "string",
|
||||
"default": "System Default",
|
||||
"enum": [
|
||||
"CRLF",
|
||||
"LF",
|
||||
"System Default"
|
||||
],
|
||||
"description": "Override EOL from line-ending-selector (Supported by Lua beautifier)",
|
||||
"title": "End of line",
|
||||
"beautifiers": [
|
||||
"Lua beautifier"
|
||||
],
|
||||
"key": "end_of_line",
|
||||
"language": {
|
||||
"name": "Lua",
|
||||
"namespace": "lua"
|
||||
}
|
||||
},
|
||||
"disabled": {
|
||||
"title": "Disable Beautifying Language",
|
||||
"order": -3,
|
||||
|
|
Loading…
Reference in New Issue