From a4ff384dbfe2e998ea8abca1029c14d656240ba6 Mon Sep 17 00:00:00 2001 From: Focus Date: Wed, 2 Mar 2016 16:45:56 +0000 Subject: [PATCH] Implements #384 --- src/beautifiers/latex-beautify.coffee | 27 ++++++ src/languages/latex.coffee | 115 ++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 src/beautifiers/latex-beautify.coffee create mode 100644 src/languages/latex.coffee diff --git a/src/beautifiers/latex-beautify.coffee b/src/beautifiers/latex-beautify.coffee new file mode 100644 index 0000000..f019ee7 --- /dev/null +++ b/src/beautifiers/latex-beautify.coffee @@ -0,0 +1,27 @@ +"use strict" +Beautifier = require('./beautifier') +path = require('path') + +module.exports = class LatexBeautify extends Beautifier + name: "Latex Beautify" + + options: { + LaTeX: true + } + + beautify: (text, language, options) -> + @tempFile("indent", "", "log") + .then( (logFile)=> + logDir = path.dirname logFile + @tempTex = @tempFile("latex", text) + run = @run "latexindent", [ + "-o" + "-s" + "-c=" + logDir + @tempTex + @tempTex + ] + ) + .then( => + @readFile(@tempTex) + ) diff --git a/src/languages/latex.coffee b/src/languages/latex.coffee new file mode 100644 index 0000000..1e9fc4a --- /dev/null +++ b/src/languages/latex.coffee @@ -0,0 +1,115 @@ +# 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" + + ### + Supported Grammars + ### + grammars: [ + "LaTeX" + ] + + ### + Supported extensions + ### + extensions: [ + "tex" + ] + + defaultBeautifier: "Latex Beautify" + + ### + + ### + options: + # JavaScript + indent_size: + type: 'integer' + default: defaultIndentSize + minimum: 0 + description: "Indentation size/length" + indent_char: + type: 'string' + default: defaultIndentChar + description: "Indentation character" + indent_level: + type: 'integer' + default: 0 + description: "Initial indentation level" + indent_with_tabs: + type: 'boolean' + default: defaultIndentWithTabs + description: "Indentation uses tabs, overrides `Indent Size` and `Indent Char`" + preserve_newlines: + type: 'boolean' + default: true + description: "Preserve line-breaks" + max_preserve_newlines: + type: 'integer' + default: 10 + description: "Number of line-breaks to be preserved in one chunk" + space_in_paren: + type: 'boolean' + default: false + description: "Add padding spaces within paren, ie. f( a, b )" + jslint_happy: + type: 'boolean' + default: false + description: "Enable jslint-stricter mode" + space_after_anon_function: + type: 'boolean' + default: false + description: "Add a space before an anonymous function's parens, ie. function ()" + brace_style: + type: 'string' + default: "collapse" + enum: ["collapse", "collapse-preserve-inline", "expand", "end-expand", "none"] + description: "[collapse|collapse-preserve-inline|expand|end-expand|none]" + break_chained_methods: + type: 'boolean' + default: false + description: "Break chained method calls across subsequent lines" + keep_array_indentation: + type: 'boolean' + default: false + description: "Preserve array indentation" + keep_function_indentation: + type: 'boolean' + default: false + description: "" + space_before_conditional: + type: 'boolean' + default: true + description: "" + eval_code: + type: 'boolean' + default: false + description: "" + unescape_strings: + type: 'boolean' + default: false + description: "Decode printable characters encoded in xNN notation" + wrap_line_length: + type: 'integer' + default: 0 + description: "Wrap lines at next opportunity after N characters" + end_with_newline: + type: 'boolean' + default: false + description: "End output with newline" + end_with_comma: + type: 'boolean' + default: false + description: "If a terminating comma should be inserted into \ + arrays, object literals, and destructured objects." + +}