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}
require {anenv aniseed.env
nvim aniseed.nvim
nu aniseed.nvim.util
u dotfiles.util}})
(module dotfiles.core
{autoload {a aniseed.core}
require {anenv aniseed.env nvim aniseed.nvim}})
(local u (require :dotfiles.util))
(nvim.ex.set :shortmess+=c)
@@ -10,7 +10,8 @@
(nvim.ex.set :path+=**)
(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)]
(if (not (a.empty? glob))
(nvim.ex.source filename))))
@@ -20,7 +21,8 @@
(def- backup-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
:expandtab
:exrc
@@ -44,7 +46,8 @@
:undofile
:wildmenu])
(def- val-based-opts {; :t_Co 256
(def- val-based-opts
{; :t_Co 256
:laststatus 2
:encoding :utf-8
:history 500
@@ -87,7 +90,8 @@
(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)]
(tset vim.opt (a.str opt) (a.str existing-opt-val "," val))))
@@ -109,15 +113,14 @@
;
; (nvim.fn.glob "~/.vimrc.local")
(defn make-fennel-scratch []
(nvim.command "new | setlocal bt=nofile bh=wipe nobl noswapfile nu filetype=fennel"))
(fn make-fennel-scratch []
(vim.cmd "new | setlocal bt=nofile bh=wipe nobl noswapfile nu filetype=fennel"))
(nu.fn-bridge :FennelScratchBuffer :dotfiles.core :make-fennel-scratch
{:return false})
(vim.api.nvim_create_user_command :FennelScratchBuffer make-fennel-scratch {})
(u.nnoremap :<leader>fsb ":call FennelScratchBuffer ()<CR>")
(defn compile-fnl [] (print :recompiling)
(fn compile-fnl [] (print :recompiling)
(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
lsp vim.lsp
lspconfig lspconfig
nu aniseed.nvim.util
mason dotfiles.plugin.mason
cmp_nvim_lsp cmp_nvim_lsp}})
@@ -14,13 +13,13 @@
(defn xbufmap [from to] (bufmap :x from to))
(vim.diagnostic.config
{:signs {:text {vim.diagnostic.severity.ERROR "☢️"
(vim.diagnostic.config {:signs {:text {vim.diagnostic.severity.ERROR "☢️"
vim.diagnostic.severity.WARN "⚠️"
vim.diagnostic.severity.INFO ""
vim.diagnostic.severity.HINT "🔎"}
:linehl {vim.diagnostic.severity.ERROR :ErrorMsg}
:numhl {vim.diagnostic.severity.WARN :WarningMsg}}})
;; :linehl {vim.diagnostic.severity.ERROR :ErrorMsg}
;; :numhl {vim.diagnostic.severity.WARN :WarningMsg}
}})
(def core-nmappings
{:gd "lua vim.lsp.buf.definition()"
@@ -48,8 +47,7 @@
:<leader>m2l "call LspExecuteCommand('move-to-let', input('Binding name: '))"}})
(def client-command-lnmappings
{:clojure_lsp {:ai [:add-import-to-namespace
["input('Namespace name: ')"]]
{:clojure_lsp {:ai [:add-import-to-namespace ["input('Namespace name: ')"]]
:am [:add-missing-libspec []]
:as [:add-require-suggestion
["input('Namespace name: ')"
@@ -84,7 +82,8 @@
(def server-specific-opts {})
(defn bind-client-mappings [client]
(defn bind-client-mappings
[client]
(let [client-name (a.get client :name)
mappings (a.get client-nmappings client-name)
command-lnmappings (a.get client-command-lnmappings client-name)]
@@ -100,11 +99,11 @@
cmd (.. "call LspExecuteCommand('" lsp-cmd "'" opts-str ")")]
(nbufmap mapping cmd))))))
(defn on_attach [client bufnr]
(defn on_attach
[client bufnr]
(each [mapping cmd (pairs core-nmappings)]
(nbufmap mapping cmd)) ; x mode mappings
(xbufmap :<leader>fa "lua vim.lsp.buf.format()")
; -- buf_set_keymap('n', 'gs', '<Cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
(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.workspace_symbol()<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)
@@ -116,23 +115,23 @@
(nvim.buf_set_option 0 :omnifunc "v:lua.vim.lsp.omnifunc")
(bind-client-mappings client)
(if client.server_capabilities.documentFormattingProvider
(nvim.ex.autocmd :BufWritePre :<buffer> ":lua vim.lsp.buf.format()"))
; (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'})]]
(nvim.ex.autocmd :BufWritePre :<buffer> ":lua vim.lsp.buf.format()")) ; (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'})]]
(print "LSP Client Attached."))
(def base-server-opts
(let [capabilities (cmp_nvim_lsp.default_capabilities (lsp.protocol.make_client_capabilities))]
{: 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 {})
server (a.get lspconfig server-name)
server-opts (a.merge base-server-opts server-opts)]
(server.setup server-opts)))
(defn lsp-execute-command [cmd ...]
(defn lsp-execute-command
[cmd ...]
(let [buf-uri (vim.uri_from_bufnr 0)
cursor (vim.api.nvim_win_get_cursor 0)
r (- (a.first cursor) 1)
@@ -143,10 +142,9 @@
(mason.setup)
(when-let [mason-lspconfig (require :mason-lspconfig)]
(mason-lspconfig.setup)
(when-let [mason-lspconfig (require :mason-lspconfig)] (mason-lspconfig.setup)
(mason-lspconfig.setup_handlers {1 default-server-handler}))
(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
{autoload {a aniseed.core}
require {nvim aniseed.nvim
nu aniseed.nvim.util
toggleterm toggleterm}})
(local toggleterm (require :toggleterm))
(toggleterm.setup {
:open_mapping :<c-\>
(toggleterm.setup {:open_mapping "<c-\\>"
:start_in_insert true
:insert_mappings true ;; whether or not the open mapping applies in insert mode
:terminal_mappings true ;; whether or not the open mapping applies in the opened terminals
:insert_mappings true
;; 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_mode true ;; if set to true (default) the previous terminal mode will be remembered
:autochdir true
})
:persist_mode true
;; if set to true (default) the previous terminal mode will be remembered
:autochdir true})
(defn set_terminal_keymaps []
(vim.keymap.set :t :<esc> :<C-\><C-n>)
(vim.keymap.set :t :jk :<C-\><C-n>)
(fn set-terminal-keymaps []
(vim.keymap.set :t :<esc> "<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-j> "<Cmd>wincmd j<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-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})
(nvim.ex.autocmd :TermOpen "term://*" :call "SetTerminalKeymaps()")
(vim.api.nvim_create_autocmd [:TermOpen]
{:pattern "term://*"
:callback set-terminal-keymaps})

View File

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

View File

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

View File

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