From bee7b2573a5cdf4fdf2c93f76533d00a13336f42 Mon Sep 17 00:00:00 2001 From: Glavin Wiechert Date: Thu, 1 Jun 2017 02:47:39 -0300 Subject: [PATCH] Switch Fortran beautifier (using Emacs) to using Executables, other minor improvements --- docs/options.md | 46 ++++++++++++++++++- script/build-options.js | 3 +- src/beautifiers/executable.coffee | 2 +- src/beautifiers/formatR/index.coffee | 5 +- .../fortran-beautifier/index.coffee | 16 ++++++- src/beautifiers/php-cs-fixer.coffee | 2 +- src/options.json | 23 +++++++++- 7 files changed, 83 insertions(+), 14 deletions(-) diff --git a/docs/options.md b/docs/options.md index 450f95d..aad2819 100644 --- a/docs/options.md +++ b/docs/options.md @@ -158,6 +158,27 @@ Options for Rscript executable. 2. Go into *Packages* and search for "*Atom Beautify*" package. 3. Find the option "*Rscript*" and change it to your desired configuration. +##### [Emacs](#emacs) + +**Namespace**: `` + +**Key**: `emacs` + +**Type**: `object` + +**Supported Beautifiers**: [`Fortran Beautifier`](#fortran-beautifier) + +**Description**: + +Options for Emacs 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 "*Emacs*" and change it to your desired configuration. + ##### [PHP](#php) **Namespace**: `` @@ -183,7 +204,7 @@ Options for PHP executable. **Namespace**: `` -**Key**: `php_cs_fixer` +**Key**: `php-cs-fixer` **Type**: `object` @@ -15873,6 +15894,27 @@ Path to the emacs script (Supported by Fortran Beautifier) } ``` +##### [Emacs](#emacs) + +**Namespace**: `` + +**Key**: `emacs` + +**Type**: `object` + +**Supported Beautifiers**: [`Fortran Beautifier`](#fortran-beautifier) + +**Description**: + +Options for Emacs 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 "*Emacs*" and change it to your desired configuration. + ### Gherkin formatter @@ -17733,7 +17775,7 @@ Options for PHP executable. **Namespace**: `` -**Key**: `php_cs_fixer` +**Key**: `php-cs-fixer` **Type**: `object` diff --git a/script/build-options.js b/script/build-options.js index 40b253b..0bd8e6e 100644 --- a/script/build-options.js +++ b/script/build-options.js @@ -185,8 +185,7 @@ buildOptionsForExecutables = function(beautifiers) { const properties = {} _.forEach(executables, (executable) => { const { name, cmd, beautifiers } = executable; - const sanitizedCmd = cmd.split('-').join('_'); - const key = sanitizedCmd; + const key = cmd; const option = { key: key, title: name, diff --git a/src/beautifiers/executable.coffee b/src/beautifiers/executable.coffee index 587a1da..15b9c27 100644 --- a/src/beautifiers/executable.coffee +++ b/src/beautifiers/executable.coffee @@ -26,7 +26,7 @@ module.exports = class Executable throw new Error("The command (i.e. cmd property) is required for an Executable.") @name = options.name @cmd = options.cmd - @key = @cmd.split('-').join('_') + @key = @cmd @homepage = options.homepage @installation = options.installation if options.version? diff --git a/src/beautifiers/formatR/index.coffee b/src/beautifiers/formatR/index.coffee index fd463bd..40e2d9f 100644 --- a/src/beautifiers/formatR/index.coffee +++ b/src/beautifiers/formatR/index.coffee @@ -16,10 +16,7 @@ module.exports = class R extends Beautifier 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] + parse: (text) -> text.match(/version (\d+\.\d+\.\d+) /)[1] runOptions: { returnStderr: true } diff --git a/src/beautifiers/fortran-beautifier/index.coffee b/src/beautifiers/fortran-beautifier/index.coffee index 8fcd759..00b7de5 100644 --- a/src/beautifiers/fortran-beautifier/index.coffee +++ b/src/beautifiers/fortran-beautifier/index.coffee @@ -9,7 +9,17 @@ path = require("path") module.exports = class FortranBeautifier extends Beautifier name: "Fortran Beautifier" link: "https://www.gnu.org/software/emacs/" - isPreInstalled: false + executables: [ + { + name: "Emacs" + cmd: "emacs" + homepage: "https://www.gnu.org/software/emacs/" + installation: "https://www.gnu.org/software/emacs/" + version: { + parse: (text) -> text.match(/Emacs (\d+\.\d+\.\d+)/)[1] + } + } + ] options: { Fortran: true @@ -17,6 +27,7 @@ module.exports = class FortranBeautifier extends Beautifier beautify: (text, language, options) -> @debug('fortran-beautifier', options) + emacs = @exe("emacs") emacs_path = options.emacs_path emacs_script_path = options.emacs_script_path @@ -36,12 +47,13 @@ module.exports = class FortranBeautifier extends Beautifier ] if emacs_path + @deprecate("The \"emacs_path\" has been deprecated. Please switch to using the config with path \"Executables - Emacs - Path\" in Atom-Beautify package settings now.") @run(emacs_path, args, {ignoreReturnCode: false}) .then(=> @readFile(tempFile) ) else - @run("emacs", args, {ignoreReturnCode: false}) + emacs.run(args, {ignoreReturnCode: false}) .then(=> @readFile(tempFile) ) diff --git a/src/beautifiers/php-cs-fixer.coffee b/src/beautifiers/php-cs-fixer.coffee index 644ce60..47539a5 100644 --- a/src/beautifiers/php-cs-fixer.coffee +++ b/src/beautifiers/php-cs-fixer.coffee @@ -78,7 +78,7 @@ module.exports = class PHPCSFixer extends Beautifier # Find php-cs-fixer.phar script if options.cs_fixer_path - @deprecate("The \"cs_fixer_path\" has been deprecated. Please change to using the config with path \"Executables - PHP - Path\" in Atom-Beautify package settings.") + @deprecate("The \"cs_fixer_path\" has been deprecated. Please switch to using the config with path \"Executables - PHP-CS-Fixer - Path\" in Atom-Beautify package settings now.") @Promise.all([ @which(options.cs_fixer_path) if options.cs_fixer_path diff --git a/src/options.json b/src/options.json index 6675736..eafcadc 100644 --- a/src/options.json +++ b/src/options.json @@ -9130,6 +9130,25 @@ "order": -1, "description": "Configure executables used by beautifiers.", "properties": { + "emacs": { + "key": "emacs", + "title": "Emacs", + "type": "object", + "collapsed": true, + "description": "Options for Emacs executable.", + "beautifiers": [ + "Fortran Beautifier" + ], + "properties": { + "path": { + "key": "path", + "title": "Executable Path", + "type": "string", + "default": "", + "description": "Absolute path to the \"emacs\" executable." + } + } + }, "php": { "key": "php", "title": "PHP", @@ -9149,8 +9168,8 @@ } } }, - "php_cs_fixer": { - "key": "php_cs_fixer", + "php-cs-fixer": { + "key": "php-cs-fixer", "title": "PHP-CS-Fixer", "type": "object", "collapsed": true,