1
0
Fork 0
dotfiles/home/config/nvim/plugins/formatter.fnl

36 lines
1.8 KiB
Text
Raw Normal View History

(let [formatter (require :formatter)
formatter-utils (require :formatter.util)
treefmt-exists (vim.fn.executable :treefmt)
2023-07-13 17:57:12 +00:00
treefmt-formatter #{:exe :treefmt :stdin false :tempfile_prefix :treefmt}]
(fn builtin-formatter [ft formatter]
(let [file (.. :formatter.filetypes. ft)]
(. (require file) formatter)))
2023-07-13 17:57:12 +00:00
(fn other-formatter [ft-or-fn formatter]
(if (= (type ft-or-fn) :function) (ft-or-fn)
((builtin-formatter ft-or-fn formatter))))
(fn prefer-treefmt [ft-or-fn formatter]
(if (= treefmt-exists 1)
(treefmt-formatter)
2023-07-13 17:57:12 +00:00
(other-formatter ft-or-fn formatter)))
(formatter.setup {:logging true
:log_level vim.log.levels.WARN
2023-07-13 10:02:14 +00:00
:filetype {:css [(prefer-treefmt :css :prettier)]
:fennel [#{:exe :fnlfmt :args ["-"] :stdin true}]
:fish [(builtin-formatter :fish :fishindent)]
2023-07-13 10:02:14 +00:00
:html [(prefer-treefmt :html :prettier)]
:javascript [(prefer-treefmt :javascript
:prettier)]
:json [(prefer-treefmt :json :prettier)]
:nix [(prefer-treefmt :nix :nixpkgs_fmt)]
:sh [(prefer-treefmt :sh :shfmt)]
2023-07-13 10:02:14 +00:00
:toml [(prefer-treefmt :toml :taplo)]
:typescript [(prefer-treefmt :typescript
2023-07-13 17:57:12 +00:00
:prettier)]
:yaml [(prefer-treefmt #{:exe :yamlfmt
:args [:-in]
:stdin true})]}}))