make arguments for latexindent configurable

This commit is contained in:
project-pp 2018-03-10 22:11:53 +09:00
parent 3697780997
commit 16c062afea
2 changed files with 18 additions and 2 deletions

View File

@ -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."
}
}
},

View File

@ -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<string>('path') || 'latexindent'
this.formatterArgs = configuration.get<string>('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.')