nvim - replace aniseed.util fn-bridge with vim.api call

This commit is contained in:
2025-04-29 10:08:21 -05:00
parent 8186744af8
commit 07eb5d3b94
6 changed files with 267 additions and 274 deletions

View File

@@ -1,8 +1,8 @@
(module dotfiles.core {autoload {a aniseed.core} (module dotfiles.core
require {anenv aniseed.env {autoload {a aniseed.core}
nvim aniseed.nvim require {anenv aniseed.env nvim aniseed.nvim}})
nu aniseed.nvim.util
u dotfiles.util}}) (local u (require :dotfiles.util))
(nvim.ex.set :shortmess+=c) (nvim.ex.set :shortmess+=c)
@@ -10,7 +10,8 @@
(nvim.ex.set :path+=**) (nvim.ex.set :path+=**)
(nvim.ex.set "wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*") (nvim.ex.set "wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*")
(defn- safe-source [filename] (defn- safe-source
[filename]
(let [glob (nvim.fn.glob filename)] (let [glob (nvim.fn.glob filename)]
(if (not (a.empty? glob)) (if (not (a.empty? glob))
(nvim.ex.source filename)))) (nvim.ex.source filename))))
@@ -20,7 +21,8 @@
(def- backup-dir (.. (nvim.fn.glob :$HOME) :/.vim/backup)) (def- backup-dir (.. (nvim.fn.glob :$HOME) :/.vim/backup))
(def- undo-dir (.. (nvim.fn.glob :$HOME) :/.vim/backup)) (def- undo-dir (.. (nvim.fn.glob :$HOME) :/.vim/backup))
(def- on-opts [:autoindent (def- on-opts
[:autoindent
:autoread :autoread
:expandtab :expandtab
:exrc :exrc
@@ -44,7 +46,8 @@
:undofile :undofile
:wildmenu]) :wildmenu])
(def- val-based-opts {; :t_Co 256 (def- val-based-opts
{; :t_Co 256
:laststatus 2 :laststatus 2
:encoding :utf-8 :encoding :utf-8
:history 500 :history 500
@@ -87,7 +90,8 @@
(defn- set-opt [[opt val]] (tset vim.opt (a.str opt) val)) (defn- set-opt [[opt val]] (tset vim.opt (a.str opt) val))
(defn- set-opt+ [[opt val]] (defn- set-opt+
[[opt val]]
(let [existing-opt-val (a.get nvim.o opt)] (let [existing-opt-val (a.get nvim.o opt)]
(tset vim.opt (a.str opt) (a.str existing-opt-val "," val)))) (tset vim.opt (a.str opt) (a.str existing-opt-val "," val))))
@@ -109,15 +113,14 @@
; ;
; (nvim.fn.glob "~/.vimrc.local") ; (nvim.fn.glob "~/.vimrc.local")
(defn make-fennel-scratch [] (fn make-fennel-scratch []
(nvim.command "new | setlocal bt=nofile bh=wipe nobl noswapfile nu filetype=fennel")) (vim.cmd "new | setlocal bt=nofile bh=wipe nobl noswapfile nu filetype=fennel"))
(nu.fn-bridge :FennelScratchBuffer :dotfiles.core :make-fennel-scratch (vim.api.nvim_create_user_command :FennelScratchBuffer make-fennel-scratch {})
{:return false})
(u.nnoremap :<leader>fsb ":call FennelScratchBuffer ()<CR>") (u.nnoremap :<leader>fsb ":call FennelScratchBuffer ()<CR>")
(defn compile-fnl [] (print :recompiling) (fn compile-fnl [] (print :recompiling)
(anenv.init {:force true :init :dotfiles.init})) (anenv.init {:force true :init :dotfiles.init}))
(nu.fn-bridge :AniseedCompile :dotfiles.core :compile-fnl {:return false}) (vim.api.nvim_create_user_command :AniseedCompile compile-fnl {})

View File

@@ -4,7 +4,6 @@
nvim aniseed.nvim nvim aniseed.nvim
lsp vim.lsp lsp vim.lsp
lspconfig lspconfig lspconfig lspconfig
nu aniseed.nvim.util
mason dotfiles.plugin.mason mason dotfiles.plugin.mason
cmp_nvim_lsp cmp_nvim_lsp}}) cmp_nvim_lsp cmp_nvim_lsp}})
@@ -14,13 +13,13 @@
(defn xbufmap [from to] (bufmap :x from to)) (defn xbufmap [from to] (bufmap :x from to))
(vim.diagnostic.config (vim.diagnostic.config {:signs {:text {vim.diagnostic.severity.ERROR "☢️"
{:signs {:text {vim.diagnostic.severity.ERROR "☢️"
vim.diagnostic.severity.WARN "⚠️" vim.diagnostic.severity.WARN "⚠️"
vim.diagnostic.severity.INFO "" vim.diagnostic.severity.INFO ""
vim.diagnostic.severity.HINT "🔎"} vim.diagnostic.severity.HINT "🔎"}
:linehl {vim.diagnostic.severity.ERROR :ErrorMsg} ;; :linehl {vim.diagnostic.severity.ERROR :ErrorMsg}
:numhl {vim.diagnostic.severity.WARN :WarningMsg}}}) ;; :numhl {vim.diagnostic.severity.WARN :WarningMsg}
}})
(def core-nmappings (def core-nmappings
{:gd "lua vim.lsp.buf.definition()" {:gd "lua vim.lsp.buf.definition()"
@@ -48,8 +47,7 @@
:<leader>m2l "call LspExecuteCommand('move-to-let', input('Binding name: '))"}}) :<leader>m2l "call LspExecuteCommand('move-to-let', input('Binding name: '))"}})
(def client-command-lnmappings (def client-command-lnmappings
{:clojure_lsp {:ai [:add-import-to-namespace {:clojure_lsp {:ai [:add-import-to-namespace ["input('Namespace name: ')"]]
["input('Namespace name: ')"]]
:am [:add-missing-libspec []] :am [:add-missing-libspec []]
:as [:add-require-suggestion :as [:add-require-suggestion
["input('Namespace name: ')" ["input('Namespace name: ')"
@@ -84,7 +82,8 @@
(def server-specific-opts {}) (def server-specific-opts {})
(defn bind-client-mappings [client] (defn bind-client-mappings
[client]
(let [client-name (a.get client :name) (let [client-name (a.get client :name)
mappings (a.get client-nmappings client-name) mappings (a.get client-nmappings client-name)
command-lnmappings (a.get client-command-lnmappings client-name)] command-lnmappings (a.get client-command-lnmappings client-name)]
@@ -100,11 +99,11 @@
cmd (.. "call LspExecuteCommand('" lsp-cmd "'" opts-str ")")] cmd (.. "call LspExecuteCommand('" lsp-cmd "'" opts-str ")")]
(nbufmap mapping cmd)))))) (nbufmap mapping cmd))))))
(defn on_attach [client bufnr] (defn on_attach
[client bufnr]
(each [mapping cmd (pairs core-nmappings)] (each [mapping cmd (pairs core-nmappings)]
(nbufmap mapping cmd)) ; x mode mappings (nbufmap mapping cmd)) ; x mode mappings
(xbufmap :<leader>fa "lua vim.lsp.buf.format()") (xbufmap :<leader>fa "lua vim.lsp.buf.format()") ; -- buf_set_keymap('n', 'gs', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
; -- buf_set_keymap('n', 'gs', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
; -- buf_set_keymap('n', 'gS', '<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts) ; -- buf_set_keymap('n', 'gS', '<Cmd>lua vim.lsp.buf.workspace_symbol()<CR>', opts)
; -- buf_set_keymap('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) ; -- buf_set_keymap('n', 'gt', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
; -- buf_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) ; -- buf_set_keymap('n', '<leader>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
@@ -116,23 +115,23 @@
(nvim.buf_set_option 0 :omnifunc "v:lua.vim.lsp.omnifunc") (nvim.buf_set_option 0 :omnifunc "v:lua.vim.lsp.omnifunc")
(bind-client-mappings client) (bind-client-mappings client)
(if client.server_capabilities.documentFormattingProvider (if client.server_capabilities.documentFormattingProvider
(nvim.ex.autocmd :BufWritePre :<buffer> ":lua vim.lsp.buf.format()")) (nvim.ex.autocmd :BufWritePre :<buffer> ":lua vim.lsp.buf.format()")) ; (nvim.ex.autocmd "BufEnter,CursorHold,InsertLeave" :<buffer> :lua "vim.lsp.codelens.refresh()")
; (nvim.ex.autocmd "BufEnter,CursorHold,InsertLeave" :<buffer> :lua "vim.lsp.codelens.refresh()") ; client autocmds ; -- vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf_request_sync(vim.api.nvim_get_current_buf(), 'workspace/executeCommand', {command = 'clean-ns', arguments = {vim.uri_from_bufnr(1), vim.api.nvim_win_get_cursor(0)[1], vim.api.nvim_win_get_cursor(0)[2]}, title = 'Clean Namespace'})]]
; client autocmds
; -- vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf_request_sync(vim.api.nvim_get_current_buf(), 'workspace/executeCommand', {command = 'clean-ns', arguments = {vim.uri_from_bufnr(1), vim.api.nvim_win_get_cursor(0)[1], vim.api.nvim_win_get_cursor(0)[2]}, title = 'Clean Namespace'})]]
(print "LSP Client Attached.")) (print "LSP Client Attached."))
(def base-server-opts (def base-server-opts
(let [capabilities (cmp_nvim_lsp.default_capabilities (lsp.protocol.make_client_capabilities))] (let [capabilities (cmp_nvim_lsp.default_capabilities (lsp.protocol.make_client_capabilities))]
{: on_attach : capabilities :flags {:debounce_text_changes 150}})) {: on_attach : capabilities :flags {:debounce_text_changes 150}}))
(defn default-server-handler [server-name] (defn default-server-handler
[server-name]
(let [specific-opts (a.get server-specific-opts server-name {}) (let [specific-opts (a.get server-specific-opts server-name {})
server (a.get lspconfig server-name) server (a.get lspconfig server-name)
server-opts (a.merge base-server-opts server-opts)] server-opts (a.merge base-server-opts server-opts)]
(server.setup server-opts))) (server.setup server-opts)))
(defn lsp-execute-command [cmd ...] (defn lsp-execute-command
[cmd ...]
(let [buf-uri (vim.uri_from_bufnr 0) (let [buf-uri (vim.uri_from_bufnr 0)
cursor (vim.api.nvim_win_get_cursor 0) cursor (vim.api.nvim_win_get_cursor 0)
r (- (a.first cursor) 1) r (- (a.first cursor) 1)
@@ -143,10 +142,9 @@
(mason.setup) (mason.setup)
(when-let [mason-lspconfig (require :mason-lspconfig)] (when-let [mason-lspconfig (require :mason-lspconfig)] (mason-lspconfig.setup)
(mason-lspconfig.setup)
(mason-lspconfig.setup_handlers {1 default-server-handler})) (mason-lspconfig.setup_handlers {1 default-server-handler}))
(u.nnoremap :<leader>li :LspInfo) (u.nnoremap :<leader>li :LspInfo)
(nu.fn-bridge :LspExecuteCommand :dotfiles.plugin.lspconfig
:lsp-execute-command {:return false}) (vim.api.nvim_create_user_command :LspExecuteCommand lsp-execute-command {})

View File

@@ -1,30 +1,27 @@
(module dotfiles.toggleterm (local toggleterm (require :toggleterm))
{autoload {a aniseed.core}
require {nvim aniseed.nvim
nu aniseed.nvim.util
toggleterm toggleterm}})
(toggleterm.setup { (toggleterm.setup {:open_mapping "<c-\\>"
:open_mapping :<c-\>
:start_in_insert true :start_in_insert true
:insert_mappings true ;; whether or not the open mapping applies in insert mode :insert_mappings true
:terminal_mappings true ;; whether or not the open mapping applies in the opened terminals ;; whether or not the open mapping applies in insert mode
:terminal_mappings true
;; whether or not the open mapping applies in the opened terminals
:persist_size true :persist_size true
:persist_mode true ;; if set to true (default) the previous terminal mode will be remembered :persist_mode true
:autochdir true ;; if set to true (default) the previous terminal mode will be remembered
}) :autochdir true})
(fn set-terminal-keymaps []
(defn set_terminal_keymaps [] (vim.keymap.set :t :<esc> "<C-\\><C-n>")
(vim.keymap.set :t :<esc> :<C-\><C-n>) (vim.keymap.set :t :jk "<C-\\><C-n>")
(vim.keymap.set :t :jk :<C-\><C-n>)
(vim.keymap.set :t :<C-h> "<Cmd>wincmd h<CR>") (vim.keymap.set :t :<C-h> "<Cmd>wincmd h<CR>")
(vim.keymap.set :t :<C-j> "<Cmd>wincmd j<CR>") (vim.keymap.set :t :<C-j> "<Cmd>wincmd j<CR>")
(vim.keymap.set :t :<C-k> "<Cmd>wincmd k<CR>") (vim.keymap.set :t :<C-k> "<Cmd>wincmd k<CR>")
(vim.keymap.set :t :<C-l> "<Cmd>wincmd l<CR>") (vim.keymap.set :t :<C-l> "<Cmd>wincmd l<CR>")
(vim.keymap.set :t :<C-w> :<C-\><C-n><C-w>)) (vim.keymap.set :t :<C-w> "<C-\\><C-n><C-w>"))
(vim.api.nvim_create_user_command :SetTerminalKeymaps set-terminal-keymaps {})
(nu.fn-bridge :SetTerminalKeymaps :dotfiles.toggleterm :set_terminal_keymaps {:return false}) (vim.api.nvim_create_autocmd [:TermOpen]
{:pattern "term://*"
(nvim.ex.autocmd :TermOpen "term://*" :call "SetTerminalKeymaps()") :callback set-terminal-keymaps})

View File

@@ -1,29 +1,31 @@
(module dotfiles.plugin.treesitter (local treesitter-configs (require :nvim-treesitter.configs))
{autoload {treesitter nvim-treesitter
ts_utils nvim-treesitter.ts_utils
treesitter-configs nvim-treesitter.configs}})
(treesitter-configs.setup (treesitter-configs.setup {:highlight {:enable true
{:highlight {:enable true
;; :additional_vim_regex_highlighting false ;; :additional_vim_regex_highlighting false
:additional_vim_regex_highlighting [:org] :additional_vim_regex_highlighting [:org]}
} :ensure_installed :all
; [:org]
:ensure_installed :all ; [:org]
:rainbow {:enable true :rainbow {:enable true
:extended_mode true ; Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean :extended_mode true
:max_file_lines 10000 ; Do not enable for files with more than 1000 lines, int ; Also highlight non-bracket delimiters like html tags, boolean or table: lang -> boolean
:colors [ :max_file_lines 10000
:#dc322f ; red ; Do not enable for files with more than 1000 lines, int
:#b58900 ; yellow :colors ["#dc322f"
:#d33682 ; magenta ; red
:#859900 ; green "#b58900"
:#2aa198 ; cyan ; yellow
:#268bd2 ; blue "#d33682"
:#6c71c4 ; violet / brmagenta ; magenta
] ; table of hex strings "#859900"
} ; green
}) "#2aa198"
; cyan
"#268bd2"
; blue
"#6c71c4"
; violet / brmagenta
]
; table of hex strings
}})
; lua print(require('nvim-treesitter.parsers').get_parser():language_for_range({ require('nvim-treesitter.ts_utils').get_node_at_cursor():range() }):lang()) ; lua print(require('nvim-treesitter.parsers').get_parser():language_for_range({ require('nvim-treesitter.ts_utils').get_node_at_cursor():range() }):lang())

View File

@@ -1,18 +1,14 @@
(module dotfiles.terraform-helpers (module dotfiles.terraform-helpers
{autoload {a aniseed.core} {autoload {a aniseed.core}
require {anenv aniseed.env require {anenv aniseed.env nvim aniseed.nvim u dotfiles.util}})
nvim aniseed.nvim
nu aniseed.nvim.util
u dotfiles.util}})
(defn append-to-buf [bufno lines] (fn append-to-buf [bufno lines]
(when lines (when lines
(nvim.buf_set_lines buffno -1 -1 false lines))) (nvim.buf_set_lines buffno -1 -1 false lines)))
(var tf-log-bufno nil) (var tf-log-bufno nil)
(defn tf-log-buffer [])
(defn terraform-import [] (fn terraform-import []
(vim.fn.jobstart [:terraform :import :-no-color address id] (vim.fn.jobstart [:terraform :import :-no-color address id]
{:stdout_buffered true {:stdout_buffered true
:on_stdout (fn [_ data] :on_stdout (fn [_ data]

View File

@@ -1,21 +1,18 @@
(module dotfiles.zoom-toggle (local u (require :dotfiles.util))
{autoload {a aniseed.core}
require {anenv aniseed.env
nvim aniseed.nvim
nu aniseed.nvim.util
u dotfiles.util}})
(var unzoom! nil) (var unzoom! nil)
(defn zoom-toggle [] (if unzoom! (fn zoom-toggle []
(if unzoom!
(do (do
(nvim.command unzoom!) (vim.cmd unzoom!)
(set unzoom! nil)) (set unzoom! nil))
(do (do
(set unzoom! (nvim.fn.winrestcmd)) (set unzoom! (vim.fn.winrestcmd))
(nvim.ex.resize) (vim.fn.resize)
(nvim.ex.vertical :resize)))) (vim.fn.vertical :resize))))
(vim.api.nvim_create_user_command :ZoomToggle zoom-toggle {})
(nu.fn-bridge :ZoomToggle :dotfiles.zoom-toggle :zoom-toggle {:return false})
(u.nnoremap :<M-z> ":call ZoomToggle()<CR>") (u.nnoremap :<M-z> ":call ZoomToggle()<CR>")
(u.tnoremap :<M-z> "<c-\\><c-n>:call ZoomToggle()<CR>") (u.tnoremap :<M-z> "<c-\\><c-n>:call ZoomToggle()<CR>")