Merge pull request #1128 from Sebastian-D/master

add R language
This commit is contained in:
Glavin Wiechert 2016-09-03 09:37:25 -03:00 committed by GitHub
commit f8fdd3d790
11 changed files with 240 additions and 2 deletions

View File

@ -98,6 +98,9 @@ before_install:
- pip install --upgrade sqlparse
# Java, C, C++, C#, Objective-C, D, Pawn, Vala
- brew install uncrustify
# R
- brew tap homebrew/science
- brew install r
# PHP
- brew tap homebrew/homebrew-php
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then

View File

@ -94,6 +94,7 @@ See [all supported options in the documentation at `docs/options.md`](https://g
| PHP | `PHP` |`.php`, `.module`, `.inc` | [`PHP-CS-Fixer`](http://php.net/manual/en/install.php) (Default), [`PHPCBF`](http://php.net/manual/en/install.php) |
| Puppet | `Puppet` |`.pp` | [`puppet-lint`](http://puppet-lint.com/) (Default) |
| Python | `Python` |`.py` | [`autopep8`](https://github.com/hhatto/autopep8) (Default), [`yapf`](https://github.com/google/yapf) |
| R | `R` |`.r`, `.R` | [`formatR`](https://github.com/yihui/formatR) (Default) |
| Riot.js | `Riot.js`, `HTML (Riot Tag)` |`.tag` | [`Pretty Diff`](https://github.com/prettydiff/prettydiff) (Default) |
| Ruby | `Ruby`, `Ruby on Rails` |`.rb` | [`Rubocop`](https://github.com/bbatsov/rubocop) (Default), [`Ruby Beautify`](https://github.com/erniebrodeur/ruby-beautify) |
| Rust | `Rust` |`.rs`, `.rlib` | [`rustfmt`](https://github.com/nrc/rustfmt) (Default) |

View File

@ -8242,6 +8242,102 @@ sort imports (requires isort installed) (Supported by autopep8)
}
```
#### [R](#r)
**Supported Beautifiers**: [`formatR`](#formatr)
| Option | formatR |
| --- | --- |
| `disabled` | :white_check_mark: |
| `default_beautifier` | :white_check_mark: |
| `beautify_on_save` | :white_check_mark: |
| `indent_size` | :white_check_mark: |
**Description**:
Options for language R
##### [Disable Beautifying Language](#disable-beautifying-language)
**Important**: This option is only configurable from within Atom Beautify's setting panel.
**Type**: `boolean`
**Description**:
Disable R Beautification
**How to Configure**
1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Disable Beautifying Language*" and change it to your desired configuration.
##### [Default Beautifier](#default-beautifier)
**Important**: This option is only configurable from within Atom Beautify's setting panel.
**Default**: `formatR`
**Type**: `string`
**Enum**: `formatR`
**Description**:
Default Beautifier to be used for R
**How to Configure**
1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Default Beautifier*" and change it to your desired configuration.
##### [Beautify On Save](#beautify-on-save)
**Important**: This option is only configurable from within Atom Beautify's setting panel.
**Type**: `boolean`
**Description**:
Automatically beautify R files on save
**How to Configure**
1. You can open the [Settings View](https://github.com/atom/settings-view) by navigating to
*Edit > Preferences (Linux)*, *Atom > Preferences (OS X)*, or *File > Preferences (Windows)*.
2. Go into *Packages* and search for "*Atom Beautify*" package.
3. Find the option "*Beautify On Save*" and change it to your desired configuration.
##### [Indent size](#indent-size)
**Namespace**: `r`
**Key**: `indent_size`
**Default**: `4`
**Type**: `integer`
**Supported Beautifiers**: [`formatR`](#formatr)
**Description**:
Indentation size/length (Supported by formatR)
**Example `.jsbeautifyrc` Configuration**
```json
{
"r": {
"indent_size": 4
}
}
```
#### [Riot.js](#riot.js)
**Supported Beautifiers**: [`Pretty Diff`](#pretty-diff)
@ -16338,6 +16434,35 @@ Indentation uses tabs, overrides `Indent Size` and `Indent Char` (Supported by C
```
### formatR
##### [Indent size](#indent-size)
**Namespace**: `r`
**Key**: `indent_size`
**Default**: `4`
**Type**: `integer`
**Supported Beautifiers**: [`formatR`](#formatr)
**Description**:
Indentation size/length (Supported by formatR)
**Example `.jsbeautifyrc` Configuration**
```json
{
"r": {
"indent_size": 4
}
}
```
### rustfmt
##### [Rustfmt path](#rustfmt-path)

View File

@ -0,0 +1,20 @@
# a single line of comments is preserved
1 + 1
if (TRUE) {
x = 1 # inline comments
} else {
x = 2
print("Oh no... ask the right bracket to go away!")
}
1 * 3 # one space before this comment will become two!
2 + 2 + 2 # 'short comments'
# only 'single quotes' are allowed in comments
df = data.frame(y = rnorm(100), x1 = rnorm(100), x2 = rnorm(100))
lm(y ~ x1 + x2, data = df)
1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 +
1 + 1 ## comments after a long line
## here is a long long long long long long long long long long long long long long
## long long long long long long comment

View File

@ -0,0 +1,16 @@
# a single line of comments is preserved
1+1
if(TRUE){
x=1 # inline comments
}else{
x=2;print('Oh no... ask the right bracket to go away!')}
1*3 # one space before this comment will become two!
2+2+2 # 'short comments'
# only 'single quotes' are allowed in comments
df=data.frame(y=rnorm(100),x1=rnorm(100),x2=rnorm(100))
lm(y~x1+x2, data=df)
1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1 ## comments after a long line
## here is a long long long long long long long long long long long long long long long long long long long long comment

View File

@ -95,6 +95,10 @@
"name": "Arman Yessenamanov",
"url": "https://github.com/yesenarman"
},
{
"name": "Sebastian DiLorenzo",
"url": "https://github.com/Sebastian-D"
},
{
"name": "Émile Bergeron",
"url": "https://github.com/emileber"
@ -251,6 +255,7 @@
"pretty diff",
"pug beautify",
"puppet-lint",
"r",
"remark",
"rubocop",
"ruby beautify",
@ -264,7 +269,8 @@
"marko beautifier",
"vue",
"vue beautifier",
"sassconvert"
"sassconvert",
"formatr"
],
"devDependencies": {
"coffeelint": "^1.10.1",

View File

@ -0,0 +1,5 @@
if(!("formatR" %in% installed.packages()[,"Package"])) install.packages("formatR",repos='http://cran.us.r-project.org')
library(formatR)
indent_size <- commandArgs(trailingOnly = TRUE)[1]
file <- commandArgs(trailingOnly = TRUE)[2]
tidy_source(text = readLines(file), indent = indent_size)

View File

@ -0,0 +1,25 @@
###
Requires [formatR](https://github.com/yihui/formatR)
###
path = require("path")
"use strict"
Beautifier = require('../beautifier')
module.exports = class R extends Beautifier
name: "formatR"
link: "https://github.com/yihui/formatR"
options: {
R: true
}
beautify: (text, language, options) ->
r_beautifier = path.resolve(__dirname, "formatR.r")
@run("Rscript", [
r_beautifier,
options.indent_size,
@tempFile("input", text),
'>',
@tempFile("input", text)
])

View File

@ -71,6 +71,7 @@ module.exports = class Beautifiers extends EventEmitter
'yapf'
'erl_tidy'
'marko-beautifier'
'formatR'
]
###

View File

@ -51,6 +51,7 @@ module.exports = class Languages
"php"
"puppet"
"python"
"r"
"riotjs"
"ruby"
"rust"

35
src/languages/r.coffee Normal file
View File

@ -0,0 +1,35 @@
# 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"
###
Supported Grammars
###
grammars: [
"R"
]
###
Supported extensions
###
extensions: [
"r"
"R"
]
options:
indent_size:
type: 'integer'
default: defaultIndentSize
description: "Indentation size/length"
}