diff options
author | sefidel <contact@sefidel.net> | 2024-05-22 14:56:47 +0900 |
---|---|---|
committer | sefidel <contact@sefidel.net> | 2024-05-22 14:56:47 +0900 |
commit | 811b5ae91117efc586fd7f80c31b236df708768f (patch) | |
tree | b331d70ee11c9889e248c2a7a7249555c1c046f4 /fnl/nvrc/packs | |
parent | c1086f1f88b5335bfd0106264d2b4e5541956620 (diff) | |
download | nvimrc-811b5ae91117efc586fd7f80c31b236df708768f.tar.gz nvimrc-811b5ae91117efc586fd7f80c31b236df708768f.zip |
feat(packs): add conform
* Replaces LSP-based formatter. No action is needed as the formatter would always fall back to LSP when it's available.
Diffstat (limited to 'fnl/nvrc/packs')
-rw-r--r-- | fnl/nvrc/packs/conform.fnl | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/fnl/nvrc/packs/conform.fnl b/fnl/nvrc/packs/conform.fnl new file mode 100644 index 0000000..b9e3737 --- /dev/null +++ b/fnl/nvrc/packs/conform.fnl @@ -0,0 +1,25 @@ +(import-macros {: set!} :nvrc.macro.set) +(local {: setup :conform-formatexpr formatexpr} (require :conform)) + +(setup {:formatters_by_ft {:nix [:nixpkgs_fmt]}}) + +(set! formatexpr "v:lua.require'conform'.formatexpr({ lsp_fallback = 'always' })") + +(vim.api.nvim_create_user_command :ConformFormat +(fn [args] + (var range nil) + (when (not= args.count (- 1)) + (local end-line + (. (vim.api.nvim_buf_get_lines 0 + (- args.line2 + 1) + args.line2 + true) + 1)) + (set range + {:end [args.line2 (end-line:len)] + :start [args.line1 0]})) + ((. (require :conform) :format) {:async true + :lsp_fallback :always + : range})) +{:range true}) |