Skip to content

Commit

Permalink
1.1.0 added tempfile_dir option
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-reineke committed Oct 28, 2020
1 parent 1bbab09 commit 25b9d6d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion doc/format.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


Author: Lukas Reineke <lukas.reineke@protonmail.com>
Version: 1.0.0
Version: 1.1.0

==============================================================================
CONTENTS *format*
Expand Down Expand Up @@ -82,6 +82,9 @@ One format table can have following keys
tempfile_postfix: ~
String to append to the temporary file
Defaults to ""
tempfile_dir: ~
Directory to which the temprorary file is written to
Defaults to the same directory as the real file
target: ~
Either "all" or "current"
When "current", the plugin only formats embedded syntax blocks when the
Expand Down Expand Up @@ -192,6 +195,9 @@ FormatWrite *FormatWrite*
==============================================================================
5. CHANGELOG *format-changelog*

1.1.0
* Added `tempfile_dir` option

1.0.0
* First release

Expand Down
5 changes: 3 additions & 2 deletions lua/format/format.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function M.format(cmd, options, callback)
local split_bufname = vim.split(bufname, "/")
local tempfile_prefix = options.tempfile_prefix or "~formatting"
local tempfile_postfix = options.tempfile_postfix or ""
split_bufname[#split_bufname] =
local filename =
string.format(
"%s_%d-%d_%d_%s%s",
tempfile_prefix,
Expand All @@ -27,7 +27,8 @@ function M.format(cmd, options, callback)
split_bufname[#split_bufname],
tempfile_postfix
)
local tempfile_name = table.concat(split_bufname, "/")
split_bufname[#split_bufname] = nil
local tempfile_name = (options.tempfile_dir or table.concat(split_bufname, "/")) .. "/" .. filename

local tempfile = io.open(tempfile_name, "w+")
for _, line in pairs(lines) do
Expand Down
1 change: 1 addition & 0 deletions lua/format/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function M.format(bang, write, startline, endline)
endline = endline,
tempfile_postfix = current.tempfile_postfix,
tempfile_prefix = current.tempfile_prefix,
tempfile_dir = current.tempfile_dir,
undojoin = undojoin
}

Expand Down
7 changes: 6 additions & 1 deletion lua/format/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function M.merge_config(input_config)
local base_cmd = {}
local base_tempfile_postfix
local base_tempfile_prefix
local base_tempfile_dir
local config = {}

for _, c in pairs(input_config) do
Expand All @@ -33,6 +34,9 @@ function M.merge_config(input_config)
if v.tempfile_prefix ~= nil then
base_tempfile_prefix = v.tempfile_prefix
end
if v.tempfile_dir ~= nil then
base_tempfile_dir = v.tempfile_dir
end
end

::continue::
Expand All @@ -46,7 +50,8 @@ function M.merge_config(input_config)
{
cmd = base_cmd,
tempfile_prefix = base_tempfile_prefix,
tempfile_postfix = base_tempfile_postfix
tempfile_postfix = base_tempfile_postfix,
tempfile_dir = base_tempfile_dir
}
)
end
Expand Down

0 comments on commit 25b9d6d

Please sign in to comment.