diff --git a/fnl/macros.fnl b/fnl/macros.fnl index 5936d63..fdf3a2a 100644 --- a/fnl/macros.fnl +++ b/fnl/macros.fnl @@ -13,13 +13,13 @@ ;; Better autocommands (lambda hook! [hooks ?patterns callback] - (let [hook_table (if (= (type hooks) :table) - hooks + (let [hook_table (if (= (type hooks) :table) + hooks [ hooks ]) pattern_table (if (not ?patterns) [] (= (type ?patterns) :table) - ?patterns + ?patterns [ ?patterns ])] (var group "config-hook") (each [_ hook (ipairs hook_table)] @@ -27,20 +27,41 @@ (each [_ pattern (ipairs pattern_table)] (set group (.. group "-" pattern))) `(vim.api.nvim_create_autocmd ,hook_table - { :group - (vim.api.nvim_create_augroup ,group + { :group + (vim.api.nvim_create_augroup ,group { :clear true }) - :pattern ,pattern_table + :pattern ,pattern_table :callback ,callback }))) ;; Nicer macro for use +;; (lambda use! [repo ...] +;; (local output [ repo ]) +;; (var last_key nil) +;; (each [_ val (ipairs [...])] +;; (if last_key +;; (do (tset output last_key val) +;; (set last_key nil)) +;; (set last_key val))) +;; `(use ,output)) (lambda use! [repo ...] (local output [ repo ]) (var last_key nil) + (var config_mode false) + (var has_config false) + (var config_entries (list `lambda [])) (each [_ val (ipairs [...])] - (if last_key + (if config_mode + (if (= (type val) :string) + (set config_mode false) + (table.insert config_entries val)) + last_key (do (tset output last_key val) (set last_key nil)) + (= val :config) + (do (set config_mode true) + (set has_config true)) (set last_key val))) + (if has_config + (tset output :config config_entries)) `(use ,output)) ;; Can be passed to :config of `use!' @@ -62,7 +83,7 @@ (lambda module-fn! [mod func] `(. (require ,mod) ,func)) -{: bind! +{: bind! : hook! : use! : setup! diff --git a/fnl/plugin.fnl b/fnl/plugin.fnl index 8e4dee0..de94e35 100644 --- a/fnl/plugin.fnl +++ b/fnl/plugin.fnl @@ -14,18 +14,20 @@ ;; Treesitter (use! :nvim-treesitter/nvim-treesitter - :config #(setup! "nvim-treesitter.configs" - :ensure_installed :all - :sync_install false - :auto_install true - :highlight { :enable true - :additional_vim_regex_highlighting false } - :indent { :enable true })) + :config + (setup! :nvim-treesitter.configs + :ensure_installed :all + :sync_install false + :auto_install true + :highlight { :enable true + :additional_vim_regex_highlighting false } + :indent { :enable true })) ;; nightfox.nvim (colorscheme) (use! :EdenEast/nightfox.nvim :after :nvim-treesitter - :config #(vim.cmd.colorscheme :carbonfox)) + :config + (vim.cmd.colorscheme :carbonfox)) ;; Devicons (use! :kyazdani42/nvim-web-devicons) @@ -33,148 +35,157 @@ ;; lualine.nvim (use! :nvim-lualine/lualine.nvim :after [ :nightfox.nvim :nvim-web-devicons ] - :config #(setup! :lualine - :options { :section_separators "" - :component_separators "│" } - :sections { :lualine_x [ - { 1 #(.. "recording @" (vim.fn.reg_recording)) - :cond #(not= (# (vim.fn.reg_recording)) 0) } - :encoding - :fileformat - :filetype ]})) + :config + (setup! :lualine + :options { :section_separators "" + :component_separators "│" } + :sections { :lualine_x [ + { 1 #(.. "recording @" (vim.fn.reg_recording)) + :cond #(not= (# (vim.fn.reg_recording)) 0) } + :encoding + :fileformat + :filetype ]})) ;; bufferline.nvim (use! :akinsho/bufferline.nvim :after [ :nvim-web-devicons :nightfox.nvim ] - :config #(setup! :bufferline - :options { - :always_show_bufferline false - :mode :tabs - :numbers :buffer-id - :show_buffer_close_icons false - :show_close_icon false })) + :config + (setup! :bufferline + :options { + :always_show_bufferline false + :mode :tabs + :numbers :buffer-id + :show_buffer_close_icons false + :show_close_icon false })) ;; fzf (a fuzzy finder) (use! :ibhagwan/fzf-lua - :config #(let [fzf (require :fzf-lua)] - (fzf.register_ui_select) - (bind! :n :fq fzf.quickfix) - (bind! :n :fr fzf.registers) - (bind! :n :fj fzf.jumps) - (bind! :n :fa fzf.marks) - (bind! :n :fh fzf.help_tags) - (bind! :n :g fzf.live_grep) - (bind! :n :fg fzf.live_grep) - (bind! :n :G fzf.grep) - (bind! :n :fG fzf.grep) - (bind! :n :b fzf.buffers) - (bind! :n :gb fzf.buffers) - (bind! :n :fu fzf.git_status) - (bind! :n :fm fzf.man_pages) - (bind! :n :fe fzf.diagnostics_document) - (bind! :n :fE fzf.diagnostics_workspace) - (bind! :n :d fzf.loclist) - (bind! :n :fp fzf.spell_suggest) - (bind! :n :i fzf.files) - (bind! :n :z= fzf.spell_suggest) - (bind! :n :ff (fn [] - (let [code (os.execute "git rev-parse --is-inside-work-tree >/dev/null 2>&1")] - (if (= code 0) - (fzf.git_files) - (fzf.files))))) - (fn jump-or-open-terminal [] - "If no terminal buffer exists, create one. Otherwise, open new one." - (var term_count 0) - (var last_id 0) - (var terms [ ]) - (each [_ id (pairs (vim.api.nvim_list_bufs))] - (let [name (vim.api.nvim_buf_get_name id)] - (when (vim.startswith name "term://") - (table.insert terms name) - (set term_count (+ term_count 1)) - (set last_id id)))) - (if (= term_count 0) - (vim.cmd.terminal) - (= term_count 1) - (vim.cmd.buffer last_id) - (fzf.buffers { :query "term://" }))) - (bind! :n :t jump-or-open-terminal))) + :config + (let [fzf (require :fzf-lua)] + (fzf.register_ui_select) + (bind! :n :fq fzf.quickfix) + (bind! :n :fr fzf.registers) + (bind! :n :fj fzf.jumps) + (bind! :n :fa fzf.marks) + (bind! :n :fh fzf.help_tags) + (bind! :n :g fzf.live_grep) + (bind! :n :fg fzf.live_grep) + (bind! :n :G fzf.grep) + (bind! :n :fG fzf.grep) + (bind! :n :b fzf.buffers) + (bind! :n :gb fzf.buffers) + (bind! :n :fu fzf.git_status) + (bind! :n :fm fzf.man_pages) + (bind! :n :fe fzf.diagnostics_document) + (bind! :n :fE fzf.diagnostics_workspace) + (bind! :n :d fzf.loclist) + (bind! :n :fp fzf.spell_suggest) + (bind! :n :i fzf.files) + (bind! :n :z= fzf.spell_suggest) + (bind! :n :ff (fn [] + (let [code (os.execute "git rev-parse --is-inside-work-tree >/dev/null 2>&1")] + (if (= code 0) + (fzf.git_files) + (fzf.files))))) + (fn jump-or-open-terminal [] + "If no terminal buffer exists, create one. Otherwise, open new one." + (var term_count 0) + (var last_id 0) + (var terms [ ]) + (each [_ id (pairs (vim.api.nvim_list_bufs))] + (let [name (vim.api.nvim_buf_get_name id)] + (when (vim.startswith name "term://") + (table.insert terms name) + (set term_count (+ term_count 1)) + (set last_id id)))) + (if (= term_count 0) + (vim.cmd.terminal) + (= term_count 1) + (vim.cmd.buffer last_id) + (fzf.buffers { :query "term://" }))) + (bind! :n :t jump-or-open-terminal))) ;; Nvim surround (use! :kylechui/nvim-surround - :config #(setup! :nvim-surround)) + :config + (setup! :nvim-surround)) ;; Leap (use! :ggandor/leap.nvim :after :nvim-treesitter - :config (fn [] - ((. (require :leap) :add_default_mappings)) - (bind! :o :z "(leap-forward-to)") - (bind! :o :Z "(leap-backward-to)") - (vim.api.nvim_set_hl 0 :LeapBackdrop { :link :Comment }))) + :config + ((. (require :leap) :add_default_mappings)) + (bind! :o :z "(leap-forward-to)") + (bind! :o :Z "(leap-backward-to)") + (vim.api.nvim_set_hl 0 :LeapBackdrop { :link :Comment })) ;; Leap spooky (remote operations) (use! :ggandor/leap-spooky.nvim :after :leap.nvim - :config #(setup! :leap-spooky)) + :config + (setup! :leap-spooky)) ;; Flit (leap for 'till' and 'forward' motions) (use! :ggandor/flit.nvim :after :leap.nvim - :config #(setup! :flit)) + :config + (setup! :flit)) ;; Comment.nvim (use! :numToStr/Comment.nvim - :config #(setup! :Comment)) + :config + (setup! :Comment)) ;; nvim-find-other (use! "https://git.zander.im/Zander671/nvim-find-other.git" - :config (fn [] (setup! :nvim-find-other - :c [ "h" "H" ] - :h [ "c" "C" "cpp" "cxx" "c++" "cc" ] - :cpp [ "hpp" "hxx" "h++" "hh" "h" "H" ] - :hpp [ "cpp" "cxx" "c++" "cc" ]) - (let [find-other (require :nvim-find-other)] - (vim.api.nvim_create_user_command - "FindOtherFile" - find-other.find_other_current_buffer - {}) - (bind! :n :go find-other.find_other_current_buffer)))) + :config + (setup! :nvim-find-other + :c [ "h" "H" ] + :h [ "c" "C" "cpp" "cxx" "c++" "cc" ] + :cpp [ "hpp" "hxx" "h++" "hh" "h" "H" ] + :hpp [ "cpp" "cxx" "c++" "cc" ]) + (let [find-other (require :nvim-find-other)] + (vim.api.nvim_create_user_command + "FindOtherFile" + find-other.find_other_current_buffer + {}) + (bind! :n :go find-other.find_other_current_buffer))) ;; illuminate (same symbol highlight) (use! :RRethy/vim-illuminate - :config (fn [] - (module-call! :illuminate :configure) - { :providers [ - "lsp" - "treesitter" - "ragex" ] - :modes_denylist [ - :markdown - :text - :gitconfig - :gitignore ] - :delay 0 } - (hook! :FileType :lua #(vim.api.nvim_set_hl 0 - :IlluminatedWordText - {})))) + :config + (module-call! :illuminate :configure) + { :providers [ + "lsp" + "treesitter" + "ragex" ] + :modes_denylist [ + :markdown + :text + :gitconfig + :gitignore ] + :delay 0 } + (hook! :FileType :lua #(vim.api.nvim_set_hl 0 + :IlluminatedWordText + {}))) ;; vlime (lisp environment) (use! :vlime/vlime - :config (fn [] - (set vim.g.vlime_cl_impl :my_sbcl) - (set vim.g.vlime_address [ "127.0.0.1" 52842 ]) - (vim.cmd "function! VlimeBuildServerCommandFor_my_sbcl(vlime_loader, vlime_eval) - return [ \"/usr/bin/sbcl\", - \\ \"--load\", a:vlime_loader, - \\ \"--eval\", \"(vlime:main :port 52842)\" ] - endfunction"))) + :config + (set vim.g.vlime_cl_impl :my_sbcl) + (set vim.g.vlime_address [ "127.0.0.1" 52842 ]) + (vim.cmd "function! VlimeBuildServerCommandFor_my_sbcl(vlime_loader, vlime_eval) + return [ \"/usr/bin/sbcl\", + \\ \"--load\", a:vlime_loader, + \\ \"--eval\", \"(vlime:main :port 52842)\" ] + endfunction")) ;; Snippy (use! :dcampos/nvim-snippy - :config #(let [map (require :snippy.mapping)] - (bind! [ :i :s ] : ((. map :next) :)) - (bind! [ :i :s ] : (map.previous :)))) + :config + (let [map (require :snippy.mapping)] + (bind! [ :i :s ] : ((. map :next) :)) + (bind! [ :i :s ] : (map.previous :)))) ;; nvim-cmp (autocomplete) (use! :hrsh7th/nvim-cmp @@ -186,22 +197,26 @@ { 1 :ray-x/cmp-treesitter :after :nvim-cmp } :dcampos/cmp-snippy ] - :config (module-fn! :plugin.cmp :configure)) + :config + (module-call! :plugin.cmp :configure)) ;; guess style from buffer (use! :NMAC427/guess-indent.nvim - :config #(setup! :guess-indent :auto_cmd true)) + :config + (setup! :guess-indent :auto_cmd true)) ;; lspconfig (use! :neovim/nvim-lspconfig :after [ :cmp-nvim-lsp :fzf-lua ] - :config (module-fn! :plugin.lsp :configure)) + :config + (module-call! :plugin.lsp :configure)) ;; nvim-jdtls (use! :mfussenegger/nvim-jdtls :after :nvim-lspconfig - :config (module-fn! :plugin.jdtls :configure)) + :config + (module-call! :plugin.jdtls :configure)) ;; Sync all packages on first launch (if _G.first_launch