Skip to content

Commit

Permalink
nvim: autoformat setup.cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
seanbreckenridge committed Sep 25, 2023
1 parent 65b44ce commit 3b80a2b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .config/nvim/lua/plugins/format.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
local wk = require("which-key")
wk.register({':Format<CR>', 'format'}, {prefix = '<leader>t'})

local cfg_format = function()
local util = require('formatter.util')
if util.get_current_buffer_file_name() == "setup.cfg" then
return {
exe = "setup-cfg-fmt-tempfile",
stdin = true,
args = {"--include-version-classifiers"}
}
else
print("Not a setup.cfg file")
return nil
end
end

return {
'mhartington/formatter.nvim',
-- hmm: using <leader>t as lazy load doesn't seem to work
Expand Down Expand Up @@ -28,6 +42,7 @@ return {
html = prettier,
json = fixjson,
typescript = prettier,
cfg = cfg_format,
javascript = prettier,
typescriptreact = prettier,
javascriptreact = prettier,
Expand Down
11 changes: 11 additions & 0 deletions .config/shortcuts.toml
Original file line number Diff line number Diff line change
Expand Up @@ -858,3 +858,14 @@ spell-list || true
spell-interactive "$@"
'''
shebang = "#!/usr/bin/env bash"

[setup-cfg-fmt-tempfile]
command = '''
set -e
tfile="$(mktemp -t setup.cfg.XXXXXX)"
cat >"$tfile"
setup-cfg-fmt "$@" "$tfile" >&2 || true
cat "$tfile"
command rm -f "$tfile"
'''
shebang = "#!/usr/bin/env bash"
7 changes: 7 additions & 0 deletions .local/share/shortcuts/setup-cfg-fmt-tempfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -e
tfile="$(mktemp -t setup.cfg.XXXXXX)"
cat >"$tfile"
setup-cfg-fmt "$@" "$tfile" >&2 || true
cat "$tfile"
command rm -f "$tfile"

0 comments on commit 3b80a2b

Please sign in to comment.