diff options
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | doc/conform.txt | 2 | ||||
-rw-r--r-- | lua/conform/init.lua | 1 | ||||
-rw-r--r-- | lua/conform/runner.lua | 7 | ||||
-rw-r--r-- | scripts/options_doc.lua | 2 |
5 files changed, 13 insertions, 1 deletions
@@ -464,6 +464,8 @@ require("conform").setup({ cwd = require("conform.util").root_file({ ".editorconfig", "package.json" }), -- When cwd is not found, don't run the formatter (default false) require_cwd = true, + -- When stdin=false, use this template to generate the temporary file that gets formatted + tmpfile_format = ".conform.$RANDOM.$FILENAME", -- When returns false, the formatter will not be used condition = function(ctx) return vim.fs.basename(ctx.filename) ~= "README.md" diff --git a/doc/conform.txt b/doc/conform.txt index b28ac3f..bcf6e31 100644 --- a/doc/conform.txt +++ b/doc/conform.txt @@ -72,6 +72,8 @@ OPTIONS *conform-option cwd = require("conform.util").root_file({ ".editorconfig", "package.json" }), -- When cwd is not found, don't run the formatter (default false) require_cwd = true, + -- When stdin=false, use this template to generate the temporary file that gets formatted + tmpfile_format = ".conform.$RANDOM.$FILENAME", -- When returns false, the formatter will not be used condition = function(ctx) return vim.fs.basename(ctx.filename) ~= "README.md" diff --git a/lua/conform/init.lua b/lua/conform/init.lua index e1f3544..2412445 100644 --- a/lua/conform/init.lua +++ b/lua/conform/init.lua @@ -14,6 +14,7 @@ local M = {} ---@field cwd? fun(self: conform.JobFormatterConfig, ctx: conform.Context): nil|string ---@field require_cwd? boolean When cwd is not found, don't run the formatter (default false) ---@field stdin? boolean Send buffer contents to stdin (default true) +---@field tmpfile_format? string When stdin=false, use this format for temporary files (default ".conform.$RANDOM.$FILENAME") ---@field condition? fun(self: conform.JobFormatterConfig, ctx: conform.Context): boolean ---@field exit_codes? integer[] Exit codes that indicate success (default {0}) ---@field env? table<string, any>|fun(self: conform.JobFormatterConfig, ctx: conform.Context): table<string, any> diff --git a/lua/conform/runner.lua b/lua/conform/runner.lua index 2810948..ff58570 100644 --- a/lua/conform/runner.lua +++ b/lua/conform/runner.lua @@ -442,8 +442,13 @@ M.build_context = function(bufnr, config, range) end if not config.stdin then + local template = config.tmpfile_format + if not template then + template = ".conform.$RANDOM.$FILENAME" + end local basename = vim.fs.basename(filename) - local tmpname = string.format(".conform.%d.%s", math.random(1000000, 9999999), basename) + local tmpname = + template:gsub("$FILENAME", basename):gsub("$RANDOM", tostring(math.random(1000000, 9999999))) local parent = vim.fs.dirname(filename) filename = fs.join(parent, tmpname) end diff --git a/scripts/options_doc.lua b/scripts/options_doc.lua index 4b1687e..96c0f2b 100644 --- a/scripts/options_doc.lua +++ b/scripts/options_doc.lua @@ -59,6 +59,8 @@ require("conform").setup({ cwd = require("conform.util").root_file({ ".editorconfig", "package.json" }), -- When cwd is not found, don't run the formatter (default false) require_cwd = true, + -- When stdin=false, use this template to generate the temporary file that gets formatted + tmpfile_format = ".conform.$RANDOM.$FILENAME", -- When returns false, the formatter will not be used condition = function(ctx) return vim.fs.basename(ctx.filename) ~= "README.md" |