[NeoVim] Slight syntax improvements

This commit is contained in:
2022-08-25 21:36:31 +02:00
parent cebfc517fe
commit 370a677344
11 changed files with 253 additions and 214 deletions

View File

@@ -1,16 +1,16 @@
(import-macros {: map!} :hibiscus.vim) (import-macros {: map!} :hibiscus.vim)
(import-macros {: setup} :macros) (import-macros {: setup} :macros)
(setup :aerial { (setup :aerial
:close_behavior "global" {:close_behavior "global"
:open_automatic true :open_automatic true
:placement_editor_edge true :placement_editor_edge true
:width 30 :width 30
:on_attach (fn [bufnr] :on_attach (fn [bufnr]
(map! [n :buffer] :t (fn [] (map! [n :buffer] :t (fn []
(vim.tbl_map (fn [buf] (vim.tbl_map (fn [buf]
(if (= (vim.api.nvim_buf_get_option buf "filetype") "aerial") (if (= (vim.api.nvim_buf_get_option buf "filetype") "aerial")
(vim.tbl_map (fn [win] (vim.tbl_map (fn [win]
(vim.api.nvim_set_current_win win)) (vim.api.nvim_set_current_win win))
(vim.fn.win_findbuf buf)))) (vim.fn.win_findbuf buf))))
(vim.api.nvim_list_bufs)))))}) (vim.api.nvim_list_bufs)))))})

View File

@@ -3,16 +3,16 @@
(local colors (require :solarized.colors)) (local colors (require :solarized.colors))
(setup :bufferline { (setup :bufferline
:options {:close_command "Bdelete %d" {:options {:close_command "Bdelete %d"
:right_mouse_command "Bdelete %d" :right_mouse_command "Bdelete %d"
:offsets [{:filetype "neo-tree" :text "File Explorer" :padding 1} :offsets [{:filetype "neo-tree" :text "File Explorer" :padding 1}
{:filetype "aerial" :text "Outline" :padding 1}] {:filetype "aerial" :text "Outline" :padding 1}]
:enforce_regular_tabs true :enforce_regular_tabs true
:separator_style "slant"} :separator_style "slant"}
:highlights {:separator {:fg colors.bg_alt} :highlights {:separator {:fg colors.bg_alt}
:separator_visible {:fg colors.bg_alt} :separator_visible {:fg colors.bg_alt}
:separator_selected {:fg colors.bg_alt}}}) :separator_selected {:fg colors.bg_alt}}})
(map! [n] :<S-Right> ":bnext<CR>") (map! [n] :<S-Right> ":bnext<CR>")
(map! [n] :<S-Left> ":bprevious<CR>") (map! [n] :<S-Left> ":bprevious<CR>")

View File

@@ -1,10 +1,10 @@
(import-macros {: map!} :hibiscus.vim) (import-macros {: map!} :hibiscus.vim)
(import-macros {: setup} :macros) (import-macros {: setup} :macros)
(setup :diffview { (setup :diffview
:keymaps {:view {:q ":tabc<CR>"} {:keymaps {:view {:q ":tabc<CR>"}
:file_panel {:q ":tabc<CR>"} :file_panel {:q ":tabc<CR>"}
:file_history_panel {:q ":tabc<CR>"}}}) :file_history_panel {:q ":tabc<CR>"}}})
(map! [n] :r ":DiffviewOpen<CR>") (map! [n] :r ":DiffviewOpen<CR>")
(map! [n] :R ":DiffviewFileHistory %<CR>") (map! [n] :R ":DiffviewFileHistory %<CR>")

View File

@@ -2,30 +2,31 @@
(local colors (require :solarized.colors)) (local colors (require :solarized.colors))
(local theme {:fg colors.fg (local theme
:bg colors.bg_alt {:fg colors.fg
:black colors.black :bg colors.bg_alt
:skyblue colors.paleblue :black colors.black
:cyan colors.cyan :skyblue colors.paleblue
:green colors.green :cyan colors.cyan
:oceanblue colors.blue :green colors.green
:magenta colors.magenta :oceanblue colors.blue
:orange colors.orange :magenta colors.magenta
:red colors.red :orange colors.orange
:violet colors.purple :red colors.red
:white colors.white :violet colors.purple
:yellow colors.yellow}) :white colors.white
:yellow colors.yellow})
(setup :feline { (setup :feline
:theme theme {:theme theme
:force_inactive {:filetypes ["^neo\\-tree$" :force_inactive {:filetypes ["^neo\\-tree$"
"^aerial$" "^aerial$"
"^packer$" "^packer$"
"^startify$" "^startify$"
"^fugitive$" "^fugitive$"
"^fugitiveblame$" "^fugitiveblame$"
"^qf$" "^qf$"
"^help$" "^help$"
"^DiffviewFileHistory"] "^DiffviewFileHistory"]
:buftypes ["^terminal$"] :buftypes ["^terminal$"]
:bufnames ["neo\\-.*"]}}) :bufnames ["neo\\-.*"]}})

View File

@@ -2,74 +2,86 @@
(local M {}) (local M {})
(local files {:dictionary (.. (vim.fn.stdpath "config") "/spell/en.utf-8.add") (local files
:disabledRules (.. (vim.fn.stdpath "config") "/spell/disable.txt") {:dictionary (.. (vim.fn.stdpath "config") "/spell/en.utf-8.add")
:hiddenFalsePositives (.. (vim.fn.stdpath "config") "/spell/false.txt")}) :disabledRules (.. (vim.fn.stdpath "config") "/spell/disable.txt")
:hiddenFalsePositives (.. (vim.fn.stdpath "config") "/spell/false.txt")})
(fn file_exists [file] (let [f (io.open file "rb")] (fn file_exists [file]
(match f nil false (let [f (io.open file "rb")]
_ (do (f.close f) true)))) (if f
(do (f:close) true)
false)))
(fn lines_from [file] (match (file_exists file) false [] (fn lines_from [file]
true (let [lines []] (if (file_exists file)
(do (each [line (io.lines file)] (icollect [line (io.lines file)] line)
(table.insert lines line)) []))
lines))))
(fn get_client_by_name [name] (let [buf_clients (vim.lsp.buf_get_clients)] (fn get_client_by_name [name]
(each [_ client (ipairs buf_clients)] (let [buf_clients (vim.lsp.buf_get_clients)]
(match client.name name (lua "return client"))))) (var found_client nil)
(each [_ client (ipairs buf_clients) :until found_client]
(match client.name name (set found_client client)))
found_client))
(fn update_config [lang configtype] (let [client (get_client_by_name "ltex")] (fn update_config [lang configtype]
(if client (let [client (get_client_by_name "ltex")]
(if (. client.config.settings.ltex configtype) (if (and client (. client.config.settings.ltex configtype))
(do (tset client.config.settings.ltex configtype {lang (lines_from (. files configtype))}) (do (tset client.config.settings.ltex configtype {lang (lines_from (. files configtype))})
(client.notify "workspace/didChangeConfiguration" client.config.settings)) (client.notify "workspace/didChangeConfiguration" client.config.settings))
(vim.notify "Error when reading dictionary config, check it"))))) (vim.notify "Error when reading dictionary config, check it"))))
(fn add_to_file [configtype lang file value] (let [dict (lines_from file)] (fn add_to_file [configtype lang file value]
(do (each [_ v (ipairs dict)] (let [dict (lines_from file)]
(if (= v value) (lua "return nil"))) (var found_existing false)
(let [file (io.open file "a+")] (each [_ v (ipairs dict) :until found_existing]
(if file (if (= v value) (set found_existing true)))
(do (file.write file (.. value "\n")) (if (not found_existing)
(file.close file) (let [file (io.open file "a+")]
(update_config lang configtype)) (if file
(vim.notify (string.format "Failed insert %s" value))))))) (do (file:write (.. value "\n"))
(file:close)
(update_config lang configtype))
(vim.notify (string.format "Failed insert %s" value)))))))
(fn do_command [arg configtype] (each [lang words (pairs arg)] (fn do_command [arg configtype]
(each [_ word (ipairs words)] (each [lang words (pairs arg)]
(add_to_file configtype lang (. files configtype) word)))) (each [_ word (ipairs words)]
(add_to_file configtype lang (. files configtype) word))))
(tset vim.lsp.commands "_ltex.addToDictionary" (tset vim.lsp.commands "_ltex.addToDictionary"
(fn [command _] (do_command (. (. command.arguments 1) :words) "dictionary"))) (fn [command _] (do_command (. command.arguments 1 :words) :dictionary)))
(tset vim.lsp.commands "_ltex.disableRules" (tset vim.lsp.commands "_ltex.disableRules"
(fn [command _] (do_command (. (. command.arguments 1) :ruleIds) "disabledRules"))) (fn [command _] (do_command (. command.arguments 1 :ruleIds) :disabledRules)))
(tset vim.lsp.commands "_ltex.hideFalsePositives" (tset vim.lsp.commands "_ltex.hideFalsePositives"
(fn [command _] (do_command (. (. command.arguments 1) :falsePositives) "hiddenFalsePositives"))) (fn [command _] (do_command (. command.arguments 1 :falsePositives) :hiddenFalsePositives)))
(fn post_attach [] (do (exec [[:setlocal "spell"] [:setlocal "nospell"]]) (fn post_attach []
(update_config "en-US" "dictionary") (exec [[:setlocal "spell"] [:setlocal "nospell"]])
(update_config "en-US" "disabledRules") (update_config "en-US" "dictionary")
(update_config "en-US" "hiddenFalsePositives") (update_config "en-US" "disabledRules")
(map! [n :buffer :verbose] :zug (fn [] (do (exec [[:normal! "zug"]]) (update_config "en-US" "hiddenFalsePositives")
(update_config "en-US" "dictionary") (map! [n :buffer :verbose] :zug (fn [] (exec [[:normal! "zug"]])
nil)) (update_config "en-US" "dictionary")
"Remove word from spellfile and update ltex") nil)
(map! [n :buffer :verbose] :zg (fn [] (do (exec [[:normal! "zg"]]) "Remove word from spellfile and update ltex")
(update_config "en-US" "dictionary") (map! [n :buffer :verbose] :zg (fn [] (exec [[:normal! "zg"]])
nil)) (update_config "en-US" "dictionary")
"Add word to spellfile and update ltex") nil)
nil)) "Add word to spellfile and update ltex")
nil)
(set M.setup (fn [opts] (fn M.setup [opts]
((. (. (require "lspconfig") "ltex") :setup) {:on_attach (fn [client] ((. (require :lspconfig) :ltex :setup)
(do (opts.on_attach client) (post_attach) nil)) {:on_attach (fn [client] (opts.on_attach client)
:capabilities opts.capabilities (post_attach)
:flags opts.flags nil)
:settings {:ltex {:dictionary [] :capabilities opts.capabilities
:disabledRules [] :flags opts.flags
:hiddenFalsePositives []} :settings {:ltex {:dictionary []
:additionalRules {:enablePickyRules true}}}))) :disabledRules []
:hiddenFalsePositives []}
:additionalRules {:enablePickyRules true}}}))
M M

View File

@@ -1,7 +1,12 @@
(import-macros {: map!} :hibiscus.vim) (import-macros {: map!} :hibiscus.vim)
(import-macros {: setup} :macros) (import-macros {: setup} :macros)
(local servers [:pyright :sumneko_lua :eslint :tsserver :ltex]) (local servers
[:eslint
:ltex
:pyright
:sumneko_lua
:tsserver])
; Mappings. ; Mappings.
(map! [n :noremap] "<space>e" vim.diagnostic.open_float) (map! [n :noremap] "<space>e" vim.diagnostic.open_float)
@@ -10,33 +15,35 @@
(map! [n :noremap] "<space>q" vim.diagnostic.setloclist) (map! [n :noremap] "<space>q" vim.diagnostic.setloclist)
(fn on_attach [_ bufnr] (fn on_attach [_ bufnr]
(do (map! [n :noremap :buffer] :gD vim.lsp.buf.declaration) (map! [n :noremap :buffer] :gD vim.lsp.buf.declaration)
(map! [n :noremap :buffer] :gd vim.lsp.buf.definition) (map! [n :noremap :buffer] :gd vim.lsp.buf.definition)
(map! [n :noremap :buffer] :K vim.lsp.buf.hover) (map! [n :noremap :buffer] :K vim.lsp.buf.hover)
(map! [n :noremap :buffer] :gi vim.lsp.buf.implementation) (map! [n :noremap :buffer] :gi vim.lsp.buf.implementation)
(map! [n :noremap :buffer] :<C-k> vim.lsp.buf.signature_help) (map! [n :noremap :buffer] :<C-k> vim.lsp.buf.signature_help)
(map! [n :noremap :buffer] :<space>wa vim.lsp.buf.add_workspace_folder) (map! [n :noremap :buffer] :<space>wa vim.lsp.buf.add_workspace_folder)
(map! [n :noremap :buffer] :<space>wr vim.lsp.buf.remove_workspace_folder) (map! [n :noremap :buffer] :<space>wr vim.lsp.buf.remove_workspace_folder)
(map! [n :noremap :buffer] :<space>wl (fn [] (print (vim.inspect (vim.lsp.buf.list_workspace_folders))))) (map! [n :noremap :buffer] :<space>wl (fn [] (print (vim.inspect (vim.lsp.buf.list_workspace_folders)))))
(map! [n :noremap :buffer] :<space>D vim.lsp.buf.type_definition) (map! [n :noremap :buffer] :<space>D vim.lsp.buf.type_definition)
(map! [n :noremap :buffer] :<space>rn vim.lsp.buf.rename) (map! [n :noremap :buffer] :<space>rn vim.lsp.buf.rename)
(map! [n :noremap :buffer] :<space>ca vim.lsp.buf.code_action) (map! [n :noremap :buffer] :<space>ca vim.lsp.buf.code_action)
(map! [n :noremap :buffer] :gr vim.lsp.buf.references) (map! [n :noremap :buffer] :gr vim.lsp.buf.references)
(map! [n :noremap :buffer] :<space>f vim.lsp.buf.formatting))) (map! [n :noremap :buffer] :<space>f vim.lsp.buf.formatting))
(local capabilities ((. (require :cmp_nvim_lsp) :update_capabilities) (vim.lsp.protocol.make_client_capabilities))) (local capabilities ((. (require :cmp_nvim_lsp) :update_capabilities) (vim.lsp.protocol.make_client_capabilities)))
(setup :mason) (setup :mason)
(setup :mason-lspconfig {:ensure_installed servers}) (setup :mason-lspconfig
{:ensure_installed servers})
(each [_ lsp (pairs servers)] (each [_ lsp (pairs servers)]
(do (local lsp_opts {:on_attach on_attach (local lsp_opts
:capabilities capabilities {:on_attach on_attach
:flags {:debounce_text_changes 150}}) :capabilities capabilities
(local (status config) (pcall require (.. "settings.lsp." lsp))) :flags {:debounce_text_changes 150}})
(if status (local (status config) (pcall require (.. "settings.lsp." lsp)))
(config.setup lsp_opts) (if status
((. (. (require :lspconfig) lsp) :setup) lsp_opts)))) (config.setup lsp_opts)
((. (require :lspconfig) lsp :setup) lsp_opts)))
; LuaSnip setup ; LuaSnip setup
(local luasnip (require :luasnip)) (local luasnip (require :luasnip))
@@ -45,27 +52,29 @@
; nvim-cmp setup ; nvim-cmp setup
(local lspkind (require :lspkind)) (local lspkind (require :lspkind))
(local cmp (require :cmp)) (local cmp (require :cmp))
(cmp.setup {:snippet {:expand (fn [args] (luasnip.lsp_expand args.body))} (cmp.setup
:mapping (cmp.mapping.preset.insert {:<C-d> (cmp.mapping.scroll_docs -4) {:snippet {:expand (fn [args] (luasnip.lsp_expand args.body))}
:<C-f> (cmp.mapping.scroll_docs 4) :mapping (cmp.mapping.preset.insert
:<C-Space> (cmp.mapping.complete) {:<C-d> (cmp.mapping.scroll_docs -4)
:<CR> (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Replace :<C-f> (cmp.mapping.scroll_docs 4)
:select true}) :<C-Space> (cmp.mapping.complete)
:<Tab> (cmp.mapping (fn [fallback] :<CR> (cmp.mapping.confirm {:behavior cmp.ConfirmBehavior.Replace
(if (cmp.visible) :select true})
(cmp.select_next_item) :<Tab> (cmp.mapping
(if (luasnip.expand_or_jumpable) (fn [fallback] (if (cmp.visible)
(luasnip.expand_or_jump) (cmp.select_next_item)
(fallback)))) (luasnip.expand_or_jumpable)
[:i :s]) (luasnip.expand_or_jump)
:<S-Tab> (cmp.mapping (fn [fallback] (fallback)))
(if (cmp.visible) [:i :s])
(cmp.select_prev_item) :<S-Tab> (cmp.mapping
(if (luasnip.jumpable -1) (fn [fallback] (if (cmp.visible)
(luasnip.jump -1) (cmp.select_prev_item)
(fallback)))) (luasnip.jumpable -1)
[:i :s])}) (luasnip.jump -1)
:sources [{:name "luasnip"} (fallback)))
{:name "nvim_lsp"} [:i :s])})
{:name "omni"}] :sources [{:name "luasnip"}
:formatting {:format (lspkind.cmp_format {:mode "symbol_text"})}}) {:name "nvim_lsp"}
{:name "omni"}]
:formatting {:format (lspkind.cmp_format {:mode "symbol_text"})}})

View File

@@ -3,42 +3,42 @@
(g! :neo_tree_remove_legacy_commands 1) (g! :neo_tree_remove_legacy_commands 1)
(setup :neo-tree { (setup :neo-tree
:close_if_last_window true {:close_if_last_window true
:window {:width 30 :window {:width 30
:mappings {:<cr> "open_with_window_picker" :mappings {:<cr> "open_with_window_picker"
:S "split_with_window_picker" :S "split_with_window_picker"
:s "vsplit_with_window_picker"}} :s "vsplit_with_window_picker"}}
:filesystem {:filtered_items {:visible true} :filesystem {:filtered_items {:visible true}
:follow_current_file true :follow_current_file true
:window {:mappings {:/ "noop" :window {:mappings {:/ "noop"
:g/ "fuzzy_finder" :g/ "fuzzy_finder"
:f "noop" :f "noop"
:ff (fn [] (exec [[:Telescope "find_files"]])) :ff (fn [] (exec [[:Telescope "find_files"]]))
:fg (fn [] (exec [[:Telescope "live_grep"]])) :fg (fn [] (exec [[:Telescope "live_grep"]]))
:<CR> "custom_open" :<CR> "custom_open"
:<S-Right> (fn []) :<S-Right> (fn [])
:<S-Left> (fn [])}} :<S-Left> (fn [])}}
:commands {:custom_open (fn [state] :commands {:custom_open (fn [state]
(let [node (state.tree.get_node state.tree) (let [node (state.tree:get_node)
quoted_path (.. "'" (.. (node.get_id node) "'"))] quoted_path (.. "'" (.. (node:get_id) "'"))]
(do (exec [[:silent "!file -bL --mime" quoted_path "| grep -qv '^text\\|^inode' && xdg-open" quoted_path "&"]]) (exec [[:silent "!file -bL --mime" quoted_path "| grep -qv '^text\\|^inode' && xdg-open" quoted_path "&"]])
(if (= vim.v.shell_error 1) (if (= vim.v.shell_error 1)
((. (require :neo-tree.sources.filesystem.commands) :open) state)))))}} ((. (require :neo-tree.sources.filesystem.commands) :open) state))))}}
:renderers {:directory [[:indent] :renderers {:directory [[:indent]
[:icon] [:icon]
[:current_filter] [:current_filter]
[:name] [:name]
[:clipboard] [:clipboard]
{1 "diagnostics" :errors_only true}] {1 :diagnostics :errors_only true}]
:file [[:indent] :file [[:indent]
[:icon] [:icon]
{1 "name" :use_git_status_colors true :zindex 10} {1 :name :use_git_status_colors true :zindex 10}
[:clipboard] [:clipboard]
[:bufnr] [:bufnr]
[:modified] [:modified]
[:diagnostics] [:diagnostics]
[:git_status]]}}) [:git_status]]}})
(map! [n] :f ":Neotree focus<CR>") (map! [n] :f ":Neotree focus<CR>")
(map! [n] :F (fn [] (exec [[:Neotree "toggle"] [:Neotree "toggle" "action=show"]]))) (map! [n] :F (fn [] (exec [[:Neotree "toggle"] [:Neotree "toggle" "action=show"]])))
@@ -47,5 +47,5 @@
; Startup ; Startup
(if (or (= (vim.fn.expand "%") "") (not= (vim.fn.isdirectory (vim.fn.expand "%")) 0)) (if (or (= (vim.fn.expand "%") "") (not= (vim.fn.isdirectory (vim.fn.expand "%")) 0))
((. (require :neo-tree.command) :_command) (vim.fn.getcwd)) ((. (require :neo-tree.command) :_command) (vim.fn.getcwd))
((. (require :neo-tree.command) :_command) "show" (vim.fn.getcwd))) ((. (require :neo-tree.command) :_command) :show (vim.fn.getcwd)))

View File

@@ -1,4 +1,4 @@
(import-macros {: setup} :macros) (import-macros {: setup} :macros)
(setup :null-ls { (setup :null-ls
:sources [(. (. (. (require :null-ls) :builtins) :diagnostics) :flake8)]}) {:sources [(. (require :null-ls) :builtins :diagnostics :flake8)]})

View File

@@ -2,9 +2,18 @@
(local actions (require :telescope.actions)) (local actions (require :telescope.actions))
(setup :telescope { (setup :telescope
:defaults {:mappings {:n {:S actions.file_split {:defaults {:mappings {:n {:S actions.file_split
:s actions.file_vsplit}} :s actions.file_vsplit}}
:get_selection_window (. (require :window-picker) :pick_window)} :get_selection_window (. (require :window-picker) :pick_window)}
:pickers {:find_files {:find_command [:fd "--type" "f" "--strip-cwd-prefix" "--hidden"]} :pickers {:find_files {:find_command [:fd "--type" "f"
:live_grep {:vimgrep_arguments ["rg" "--color=never" "--no-heading" "--with-filename" "--line-number" "--column" "--smart-case" "--hidden"]}}}) "--strip-cwd-prefix"
"--hidden"]}
:live_grep {:vimgrep_arguments ["rg"
"--color=never"
"--no-heading"
"--with-filename"
"--line-number"
"--column"
"--smart-case"
"--hidden"]}}})

View File

@@ -1,9 +1,17 @@
(import-macros {: setup} :macros) (import-macros {: setup} :macros)
(setup :nvim-treesitter.configs { (setup :nvim-treesitter.configs
:ensure_installed [:c :lua :rust :java :python :javascript :typescript :fennel] {:ensure_installed
:sync_install false [:c
:ignore_install [] :fennel
:highlight {:enable true :java
:disable [] :javascript
:additional_vim_regex_highlighting false}}) :lua
:python
:rust
:typescript]
:sync_install false
:ignore_install []
:highlight {:enable true
:disable []
:additional_vim_regex_highlighting false}})

View File

@@ -1,7 +1,7 @@
(import-macros {: setup} :macros) (import-macros {: setup} :macros)
(setup :window-picker { (setup :window-picker
:autoselect_one true {:autoselect_one true
:selection_chars "ABCDEFGHIJKLMNOP" :selection_chars "ABCDEFGHIJKLMNOP"
:filter_rules {:bo {:filetype [:NvimTree :neo-tree :notify :aerial] :filter_rules {:bo {:filetype [:NvimTree :neo-tree :notify :aerial]
:buftype [:terminal]}}}) :buftype [:terminal]}}})