diff --git a/docs/options.md b/docs/options.md index 2187766..450f95d 100644 --- a/docs/options.md +++ b/docs/options.md @@ -137,6 +137,27 @@ Supported options for each language. Configure executables used by beautifiers. +##### [Rscript](#rscript) + +**Namespace**: `` + +**Key**: `Rscript` + +**Type**: `object` + +**Supported Beautifiers**: [`formatR`](#formatr) + +**Description**: + +Options for Rscript executable. + +**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 "*Rscript*" and change it to your desired configuration. + ##### [PHP](#php) **Namespace**: `` @@ -20123,6 +20144,27 @@ Indentation size/length (Supported by formatR) } ``` +##### [Rscript](#rscript) + +**Namespace**: `` + +**Key**: `Rscript` + +**Type**: `object` + +**Supported Beautifiers**: [`formatR`](#formatr) + +**Description**: + +Options for Rscript executable. + +**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 "*Rscript*" and change it to your desired configuration. + ### pybeautifier diff --git a/src/beautifiers/formatR/index.coffee b/src/beautifiers/formatR/index.coffee index bf0e8f5..fd463bd 100644 --- a/src/beautifiers/formatR/index.coffee +++ b/src/beautifiers/formatR/index.coffee @@ -9,18 +9,35 @@ Beautifier = require('../beautifier') module.exports = class R extends Beautifier name: "formatR" link: "https://github.com/yihui/formatR" - isPreInstalled: false + executables: [ + { + name: "Rscript" + cmd: "Rscript" + homepage: "https://github.com/yihui/formatR" + installation: "https://github.com/yihui/formatR" + version: { + parse: (text) -> + r = /version (\d\.\d\.\d) / + console.log("parse version", text, r, text.match(r)) + text.match(r)[1] + runOptions: { + returnStderr: true + } + } + } + ] options: { R: true } beautify: (text, language, options) -> + rScript = @exe("Rscript") r_beautifier = path.resolve(__dirname, "formatR.r") - @run("Rscript", [ + rScript.run([ r_beautifier, options.indent_size, @tempFile("input", text), '>', @tempFile("input", text) - ]) + ]) diff --git a/src/options.json b/src/options.json index 9e667a7..6675736 100644 --- a/src/options.json +++ b/src/options.json @@ -9186,6 +9186,25 @@ "description": "Absolute path to the \"phpcbf\" executable." } } + }, + "Rscript": { + "key": "Rscript", + "title": "Rscript", + "type": "object", + "collapsed": true, + "description": "Options for Rscript executable.", + "beautifiers": [ + "formatR" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"Rscript\" executable." + } + } } } }