config.fnl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. (import-macros {: for!} :macros)
  2. (local {: ?->table : extend : textend : compose : elem
  3. : filter} (require :utils))
  4. (local extend-unpack (compose (. (require :utils.pure) :extend) unpack))
  5. (local textend-unpack (compose textend unpack))
  6. (local NO-FT :-NO-FT-)
  7. (λ ft-opt-config-fts [config]
  8. (icollect [ft cfg (pairs config)]
  9. (if (= :number (type ft))
  10. cfg
  11. ft)))
  12. (λ ft-config-fts [config]
  13. "get fts from table with keys: string|string[]"
  14. (extend-unpack
  15. (icollect [ft _ (pairs config)]
  16. (?->table ft))))
  17. (λ ft-config-cfgs [config]
  18. "get cfgs from table with values: string|string[]"
  19. (extend-unpack
  20. (icollect [_ cfg (pairs config)]
  21. (?->table cfg))))
  22. (λ lsp-find [lsp-cfg ft]
  23. "return list of lsp servers for file type"
  24. (local unp
  25. (let [unp []]
  26. (each [fts lsp (pairs lsp-cfg)]
  27. (for! ft (?->table fts)
  28. (tset unp ft lsp)))
  29. unp))
  30. (match unp
  31. {ft lsps} (?->table lsps)))
  32. (local neogit
  33. [:NeogitCommitMessage
  34. :NeogitCommitView
  35. :NeogitGitCommandHistory
  36. :NeogitLog
  37. :NeogitLogView
  38. :NeogitNotification
  39. :NeogitPopup
  40. :NeogitStatus])
  41. (local telescope
  42. [:TelescopeResults :TelescopePrompt])
  43. (local not-code
  44. [:qf :man :help :startify :packer :Trouble :vimwiki :lspinfo])
  45. (local formaters
  46. #(textend
  47. [:sh :zsh :haskell :rust :ebuild]
  48. {:python [:autopep8 :yapf]
  49. :markdown :mdformat
  50. :haskell :brittany}))
  51. (local lsp-cfg
  52. ;; fts ;; lsps ;;
  53. {:haskell "hls"
  54. ; :nim "nimls"
  55. :zig "zls"
  56. :python "pylsp"
  57. :purescript "purescriptls"
  58. :html ["html"] ; "emmet_language_server"]
  59. [:css :scss :sass] ["cssls" "emmet_language_server"]
  60. [:typescript :javascript] "denols"
  61. [:c :cpp] "clangd"
  62. :rust "rust_analyzer"})
  63. (local linters
  64. {[:c :cpp] "clangtidy"
  65. :sh "shellcheck"})
  66. (local ts-cfg
  67. #(textend
  68. {:sh "bash"
  69. :fasm "asm"
  70. :dosini "ini"
  71. :tex "latex"
  72. :help "vimdoc"
  73. NO-FT "regex"
  74. NO-FT "markdown_inline"}
  75. [:c
  76. :cpp
  77. :lua
  78. :vim
  79. :nim
  80. :hare
  81. :bash
  82. :make
  83. :norg
  84. :dhall
  85. :purescript
  86. :html
  87. :json
  88. :rust
  89. :zig
  90. :markdown
  91. :javascript
  92. :typescript
  93. :python
  94. :java
  95. :yaml
  96. :fennel
  97. :haskell]))
  98. (macro *gen-workspaces* [prefix ...]
  99. (let [form `(doto [])
  100. {: insert} table]
  101. (each [_ i (ipairs [...])]
  102. (insert form `(tset ,i ,(.. prefix i))))
  103. form))
  104. {:ts-parsers #(ft-config-cfgs (ts-cfg))
  105. :ts-fts #(filter #(not= NO-FT $) (ft-opt-config-fts (ts-cfg)))
  106. :lsp-fts #(ft-config-fts lsp-cfg)
  107. :lsp-lsps #(ft-config-cfgs lsp-cfg)
  108. :lsp-find (partial lsp-find lsp-cfg)
  109. : lsp-cfg
  110. ; :not-code (extend not-code neogit telescope)
  111. : formaters
  112. :format-fts #(ft-opt-config-fts (formaters))
  113. :format-key "<M-f>"
  114. :lisps [:lisp :fennel :hy :lissp]
  115. :linters-fts #(ft-config-fts linters)
  116. :linters-by-ft
  117. #(let [ret []]
  118. (each [fts l (pairs linters)]
  119. (for! ft (?->table fts)
  120. (tset ret ft (?->table l))))
  121. ret)
  122. :spell "en_us,ru_ru"
  123. :neorg-workspaces
  124. (textend
  125. {:tmp (let [{: TMPDIR} (require :xdg)] (.. (TMPDIR) :/neorg))}
  126. (*gen-workspaces* "~/Documents/NORG/"
  127. :wiki
  128. :notes
  129. :lists
  130. :etsy
  131. :vds
  132. :recipes
  133. :TODO
  134. :shop
  135. :projects
  136. :work))
  137. :template
  138. {:dir
  139. #(let [{: XDG_CONFIG_HOME} (require :xdg)
  140. {: path-sep} (require :utils.vim)]
  141. (.. (XDG_CONFIG_HOME) (path-sep) :templates.nvim))
  142. :prefix "auto"
  143. :ft [:c :python :dockerfile :sh :html]}}