diff --git a/fnl/macros.fnl b/fnl/macros.fnl index f634bb1..9d644d7 100644 --- a/fnl/macros.fnl +++ b/fnl/macros.fnl @@ -32,29 +32,54 @@ { :clear true }) :pattern ,pattern_table :callback ,callback }))) + +;; Utility functions for use! +(lambda create-list-entries [...] + (let [output { :active-entry nil + :entries {} }] + (lambda output.process [self entry] + (var result false) + (when self.active-entry + (if (and (. self :entries self.active-entry :is-first) + (not (list? entry))) + (do (tset self :entries self.active-entry :data entry) + (set self.active-entry nil) + (set result true)) + (= (type entry) :string) + (set self.active-entry nil) + (do (table.insert (. self :entries self.active-entry :data) entry) + (tset self :entries self.active-entry :is-first false) + (set result true)))) + (when (and (= (type entry) :string) (. self :entries entry)) + (assert-compile (not (. self :entries entry :present)) + (.. "':" entry "' cannot appear more than once in `use'")) + (set self.active-entry entry) + (tset self :entries entry :present true) + (set result true)) + result) + (lambda output.splice-into [self other] + (each [name entry (pairs self.entries)] + (when entry.present + (tset other name entry.data)))) + (each [_ val (ipairs [...])] + (tset output :entries val { :present false :is-first true :data `(lambda [])})) + output)) + ;; Nicer macro for use ;; :config acts like use-package's :init and :config options, ;; taking in the following lisp expressions as its arguments (lambda use! [repo ...] (local output [ repo ]) (var last_key nil) - (var config_mode false) - (var has_config false) - (var config_entries (list `lambda [])) + (var list_entries (create-list-entries :config :setup + :run)) (each [_ val (ipairs [...])] - (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)) + (if last_key + (do (tset output last_key val) + (set last_key nil)) + (not (list_entries:process val)) (set last_key val))) - (if has_config - (tset output :config config_entries)) + (list_entries:splice-into output) `(use ,output)) ;; Call a plugin's `setup function' diff --git a/fnl/plugin.fnl b/fnl/plugin.fnl index 8133d9e..d167ed8 100644 --- a/fnl/plugin.fnl +++ b/fnl/plugin.fnl @@ -59,33 +59,59 @@ ;; fzf (a fuzzy finder) (use! :ibhagwan/fzf-lua + :cmd :FzfLua + :setup + (bind! :n :fq "FzfLua quickfix") + (bind! :n :fr "FzfLua registers") + (bind! :n :fj "FzfLua jumps") + (bind! :n :fa "FzfLua marks") + (bind! :n :fh "FzfLua help_tags") + (bind! :n :g "FzfLua live_grep") + (bind! :n :fg "FzfLua live_grep") + (bind! :n :G "FzfLua grep") + (bind! :n :fG "FzfLua grep") + (bind! :n :b "FzfLua buffers") + (bind! :n :gb "FzfLua buffers") + (bind! :n :fu "FzfLua git_status") + (bind! :n :fm "FzfLua man_pages") + (bind! :n :fe "FzfLua diagnostics_document") + (bind! :n :fE "FzfLua diagnostics_workspace") + (bind! :n :d "FzfLua loclist") + (bind! :n :fp "FzfLua spell_suggest") + (bind! :n :i "FzfLua files") + (bind! :n :z= "FzfLua spell_suggest") + (bind! :n :ff (fn [] + (let [code (os.execute "git rev-parse --is-inside-work-tree >/dev/null 2>&1")] + (if (= code 0) + (vim.cmd "FzfLua git_files") + (vim.cmd "FzfLua files"))))) :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))))) + ;; (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) @@ -101,7 +127,8 @@ (vim.cmd.terminal) (= term_count 1) (vim.cmd.buffer last_id) - (fzf.buffers { :query "term://" }))) + (vim.cmd "FzfLua buffers query=term://"))) + ;;(fzf.buffers { :query "term://" }))) (bind! :n :t jump-or-open-terminal))) ;; Nvim surround @@ -170,6 +197,7 @@ ;; vlime (lisp environment) (use! :vlime/vlime + :ft :lisp :config (set vim.g.vlime_cl_impl :my_sbcl) (set vim.g.vlime_address [ "127.0.0.1" 52842 ]) @@ -199,13 +227,16 @@ :config (module-call! :plugin.cmp :configure)) + ;; does what the name says, lets you pick icons (use! :ziontee113/icon-picker.nvim - :after :fzf-lua - :config - (setup! :icon-picker - :disable_legacy_commands true) + :cmd [ :IconPickerNormal :IconPickerYank ] + :setup (bind! :n :ci "IconPickerNormal") - (bind! :n :cy "IconPickerYank")) + (bind! :n :cy "IconPickerYank") + :config + (vim.cmd "PackerLoad fzf-lua") + (setup! :icon-picker + :disable_legacy_commands true)) ;; guess style from buffer (use! :NMAC427/guess-indent.nvim @@ -214,8 +245,7 @@ ;; lspconfig (use! :neovim/nvim-lspconfig - :after [ :cmp-nvim-lsp - :fzf-lua ] + :after :cmp-nvim-lsp :config (module-call! :plugin.lsp :configure)) diff --git a/fnl/plugin/lsp.fnl b/fnl/plugin/lsp.fnl index 235c50e..92352a0 100644 --- a/fnl/plugin/lsp.fnl +++ b/fnl/plugin/lsp.fnl @@ -23,15 +23,22 @@ ; (bind! :n :gr vim.lsp.buf.references buf) (bind! :n :o #(vim.lsp.buf.format { :async true }) buf) - ;; Some telescope commands - (let [fzf (require :fzf-lua)] - (bind! :n :gr fzf.lsp_references buf) - (bind! :n :s fzf.lsp_live_workspace_symbols buf) - (bind! :n :fs fzf.lsp_live_workspace_symbols buf) - (bind! :n :fS fzf.lsp_workspace_symbols buf) - (bind! :n :d fzf.lsp_document_symbols buf) - (bind! :n :fd fzf.lsp_document_symbols buf) - (bind! :n :cn fzf.lsp_code_actions buf))) + ;; Some fzf commands + (bind! :n :gr "FzfLua lsp_references" buf) + (bind! :n :s "FzfLua lsp_live_workspace_symbols" buf) + (bind! :n :fs "FzfLua lsp_live_workspace_symbols" buf) + (bind! :n :fS "FzfLua lsp_workspace_symbols" buf) + (bind! :n :d "FzfLua lsp_document_symbols" buf) + (bind! :n :fd "FzfLua lsp_document_symbols" buf) + (bind! :n :cn "FzfLua lsp_code_actions" buf)) + ;; (let [fzf (require :fzf-lua)] + ;; (bind! :n :gr fzf.lsp_references buf) + ;; (bind! :n :s fzf.lsp_live_workspace_symbols buf) + ;; (bind! :n :fs fzf.lsp_live_workspace_symbols buf) + ;; (bind! :n :fS fzf.lsp_workspace_symbols buf) + ;; (bind! :n :d fzf.lsp_document_symbols buf) + ;; (bind! :n :fd fzf.lsp_document_symbols buf) + ;; (bind! :n :cn fzf.lsp_code_actions buf))) (fn get-data-dir [server root] (let [resolved_path (vim.fn.resolve root)