about summary refs log tree commit diff
path: root/fnl/nvrc/packs
diff options
context:
space:
mode:
Diffstat (limited to 'fnl/nvrc/packs')
-rw-r--r--fnl/nvrc/packs/conform.fnl25
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})