From 16c062afeac47c38fccff57b203c3c9e7ddf7dfa Mon Sep 17 00:00:00 2001 From: project-pp Date: Sat, 10 Mar 2018 22:11:53 +0900 Subject: [PATCH] make arguments for latexindent configurable --- package.json | 5 +++++ src/providers/latexformatter.ts | 15 +++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index c72b7318d..ab941c218 100644 --- a/package.json +++ b/package.json @@ -437,6 +437,11 @@ "type": "string", "default": "latexindent", "description": "Define the location of the latexindent executable file." + }, + "latex-workshop.latexindent.args": { + "type": "string", + "default": "-c \"%DIR%\" \"%TMPFILE%\" -y=\"defaultIndent: '%INDENT%'\"", + "description": "Define the command line arguments for latexindent." } } }, diff --git a/src/providers/latexformatter.ts b/src/providers/latexformatter.ts index 217a4b4e7..b92393ced 100644 --- a/src/providers/latexformatter.ts +++ b/src/providers/latexformatter.ts @@ -29,6 +29,7 @@ export class LaTexFormatter { private machineOs: string private currentOs: OperatingSystem private formatter: string + private formatterArgs: string constructor(extension: Extension) { this.extension = extension @@ -47,6 +48,7 @@ export class LaTexFormatter { const configuration = vscode.workspace.getConfiguration('latex-workshop.latexindent') this.formatter = configuration.get('path') || 'latexindent' + this.formatterArgs = configuration.get('args') || "-c \"%DIR%\" \"%TMPFILE%\" -y=\"defaultIndent: '%INDENT%'\"" const pathMeta = configuration.inspect('path') if (pathMeta && pathMeta.defaultValue && pathMeta.defaultValue !== this.formatter) { @@ -112,8 +114,17 @@ export class LaTexFormatter { const temporaryFile = documentDirectory + path.sep + '__latexindent_temp.tex' fs.writeFileSync(temporaryFile, textToFormat) - cp.exec(this.formatter + ' -c "' + documentDirectory + '" "' + temporaryFile + '"' - + ' -y="defaultIndent: \'' + indent + '\'"', (err, stdout, _stderr) => { + // generate command line + const args = this.formatterArgs + // taken from ../components/builder.ts + .replace('%DOC%', document.fileName.replace(/\.tex$/, '').split(path.sep).join('/')) + .replace('%DOCFILE%', path.basename(document.fileName, '.tex').split(path.sep).join('/')) + .replace('%DIR%', path.dirname(document.fileName).split(path.sep).join('/')) + // latexformatter.ts specific tokens + .replace('%TMPFILE%', temporaryFile) + .replace('%INDENT%', indent) + + cp.exec(`${this.formatter} ${args}`, (err, stdout, _stderr) => { if (err) { this.extension.logger.addLogMessage(`Formatting failed: ${err.message}`) vscode.window.showErrorMessage('Formatting failed. Please refer to LaTeX Workshop Output for details.')