summaryrefslogtreecommitdiff
path: root/fnl
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2023-09-23 22:05:37 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2023-09-23 22:05:37 +0200
commitd474c779523c512e3bc91bc5ce7bc87cafc6372b (patch)
tree3c50cc5bf8fb55167150c76171f54590babf7118 /fnl
parent6dcd88cde5825573a3732e8b18f7d663ca47495b (diff)
Move user and auto cmds to plugins
Diffstat (limited to 'fnl')
-rw-r--r--fnl/plugins/editor/comment.fnl16
-rw-r--r--fnl/plugins/editor/harpoon.fnl31
-rw-r--r--fnl/plugins/editor/neogit.fnl12
-rw-r--r--fnl/plugins/editor/orgmode.fnl32
-rw-r--r--fnl/plugins/editor/persistence.fnl21
-rw-r--r--fnl/plugins/editor/spectre.fnl28
-rw-r--r--fnl/plugins/editor/telescope.fnl22
-rw-r--r--fnl/plugins/editor/toggleterm.fnl20
-rw-r--r--fnl/settings/autocmds.fnl38
-rw-r--r--fnl/settings/init.fnl3
-rw-r--r--fnl/settings/usercmds.fnl87
-rw-r--r--fnl/util/cmds.fnl12
12 files changed, 189 insertions, 133 deletions
diff --git a/fnl/plugins/editor/comment.fnl b/fnl/plugins/editor/comment.fnl
index 63401a0..f15e61f 100644
--- a/fnl/plugins/editor/comment.fnl
+++ b/fnl/plugins/editor/comment.fnl
@@ -1,7 +1,23 @@
;; Language aware commenting.
+(local user-cmds [[:CommentNormal
+ (lambda []
+ (let [comment-api (require :Comment.api)]
+ (comment-api.toggle.linewise.current)))
+ {:nargs 0}]
+ [:CommentVisual
+ (lambda []
+ (let [comment-api (require :Comment.api)]
+ (comment-api.toggle.linewise (vim.fn.visualmode))))
+ {:nargs 0}]])
+
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-user-cmds user-cmds)))
+
{1 :numToStr/Comment.nvim
:event :BufReadPost
+ : inti
:opts {:toggler {;; Line-comment toggle keymap
:line :mcc
;; Block-comment toggle keymap
diff --git a/fnl/plugins/editor/harpoon.fnl b/fnl/plugins/editor/harpoon.fnl
index 167cf3b..8a9818f 100644
--- a/fnl/plugins/editor/harpoon.fnl
+++ b/fnl/plugins/editor/harpoon.fnl
@@ -1,12 +1,37 @@
;; Harpoon files for navigation.
+(local user-cmds [[:HarpoonAdd
+ (lambda []
+ (let [harpoon (require :harpoon.mark)]
+ (harpoon.add_file)))
+ {:nargs 0}]
+ [:HarpoonNext
+ (lambda []
+ (let [harpoon (require :harpoon.ui)]
+ (harpoon.nav_next)))
+ {:nargs 0}]
+ [:HarpoonPrev
+ (lambda []
+ (let [harpoon (require :harpoon.ui)]
+ (harpoon.nav_prev)))
+ {:nargs 0}]
+ [:HarpoonUI
+ (lambda []
+ (let [harpoon (require :harpoon.ui)]
+ (harpoon.toggle_quick_menu)))
+ {:nargs 0}]])
+
(fn telescope-ext [ext fun opts]
(let [telescope (require :telescope)
themes (require :telescope.themes)
theme (. opts :theme)]
((. (. (. telescope :extensions) ext) fun) ((. themes theme) opts))))
-(fn setup []
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-user-cmds user-cmds)))
+
+(fn config []
(vim.keymap.set :n :<tab>
(fn []
(telescope-ext :harpoon :marks
@@ -22,9 +47,9 @@
{1 :ThePrimeagen/harpoon
:event :BufReadPost
+ : init
:keys [{1 :ma 2 :<cmd>HarpoonAdd<cr> :desc :Harpoon}
{1 :mr 2 :<cmd>HarpoonUI<cr> :desc "Harpoon UI"}
{1 :ms 2 :<cmd>HarpoonPrev<cr> :desc "Harpoon Prev"}
{1 :mt 2 :<cmd>HarpoonNext<cr> :desc "Harpoon Next"}]
- :config (fn []
- (setup))}
+ : config}
diff --git a/fnl/plugins/editor/neogit.fnl b/fnl/plugins/editor/neogit.fnl
index af3a738..5a3c5e3 100644
--- a/fnl/plugins/editor/neogit.fnl
+++ b/fnl/plugins/editor/neogit.fnl
@@ -1,9 +1,21 @@
;; Git ui.
+(local auto-cmds [[:FileType
+ {:pattern [:NeogitStatus
+ :NeogitCommitMessage
+ :NeogitNotification
+ :NeogitCommitView]
+ :command "setlocal spell!"}]])
+
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-auto-cmds auto-cmds)))
+
(local opts {:integrations {:diffview true :telescope true}})
{1 :TimUntersberger/neogit
:cmd :Neogit
: opts
+ : init
:dependencies [:nvim-lua/plenary.nvim]
:keys [{1 :<leader>gm 2 :<cmd>Neogit<cr> :desc :Neogit}]}
diff --git a/fnl/plugins/editor/orgmode.fnl b/fnl/plugins/editor/orgmode.fnl
index bb67b88..5324b8d 100644
--- a/fnl/plugins/editor/orgmode.fnl
+++ b/fnl/plugins/editor/orgmode.fnl
@@ -1,5 +1,28 @@
;; Orgmode for nvim.
+(local user-cmds [[:OrgAgendaPrompt
+ (lambda []
+ (let [orgmode (require :orgmode)]
+ (orgmode.action :agenda.prompt)))
+ {:nargs 0}]
+ [:OrgCapturePrompt
+ (lambda []
+ (let [orgmode (require :orgmode)]
+ (orgmode.action :capture.prompt)))
+ {:nargs 0}]])
+
+(local auto-cmds
+ [[:FileType
+ {:pattern :org
+ :callback (fn []
+ (tset vim.opt_local :conceallevel 2)
+ (tset vim.opt_local :concealcursor :nc))}]])
+
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-user-cmds user-cmds)
+ (cmds.create-auto-cmds auto-cmds)))
+
(local templates
{:t {:description :Task :template "* TODO %?\n %u\n DEADLINE: %T\n"}
:m {:description :Meeting :template "* Meeting %?"}
@@ -11,14 +34,15 @@
:org_default_notes_file "~/.local/share/org/refile.org"
:org_agenda_templates templates})
-(fn setup []
- (let [orgmode (require :orgmode)]
+(fn config []
+ (let [orgmode (require :orgmode)
+ cmds (require :util.cmds)]
(orgmode.setup_ts_grammar)
(orgmode.setup opts)))
{1 :nvim-orgmode/orgmode
- :config (fn []
- (setup))
+ : config
+ : init
:event :BufReadPost
:keys [{1 :ga 2 :<cmd>OrgAgendaPrompt<cr> :desc "Open agenda prompt"}
{1 :gc 2 :<cmd>OrgCapturePrompt<cr> :desc "Open capture prompt"}
diff --git a/fnl/plugins/editor/persistence.fnl b/fnl/plugins/editor/persistence.fnl
index 0b4e7a8..492ef0d 100644
--- a/fnl/plugins/editor/persistence.fnl
+++ b/fnl/plugins/editor/persistence.fnl
@@ -1,7 +1,28 @@
;; Session manager.
+(local user-cmds [[:RestoreSession
+ (lambda []
+ (let [persistence (require :persistence)]
+ (persistence.load)))
+ {:nargs 0}]
+ [:RestoreLastSession
+ (lambda []
+ (let [persistence (require :persistence)]
+ (persistence.load {:last true})))
+ {:nargs 0}]
+ [:IgnoreSession
+ (lambda []
+ (let [persistence (require :persistence)]
+ (persistence.stop)))
+ {:nargs 0}]])
+
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-user-cmds user-cmds)))
+
{1 :folke/persistence.nvim
:event :VeryLazy
+ : init
:keys [{1 :<leader>sn 2 :<cmd>RestoreSession<cr> :desc "Restore session"}
{1 :<leader>se
2 :<cmd>RestoreLastSession<cr>
diff --git a/fnl/plugins/editor/spectre.fnl b/fnl/plugins/editor/spectre.fnl
index 526b196..81cc77c 100644
--- a/fnl/plugins/editor/spectre.fnl
+++ b/fnl/plugins/editor/spectre.fnl
@@ -1,5 +1,32 @@
;; Find and replace.
+(local user-cmds [[:Replace
+ (lambda []
+ (let [spectre (require :spectre)]
+ (spectre.open)))
+ {:nargs 0}]
+ [:ReplaceWord
+ (lambda []
+ (let [spectre (require :spectre)]
+ (spectre.open_visual {:select_word true})))
+ {:nargs 0}]
+ [:ReplaceInBuf
+ (lambda []
+ (let [spectre (require :spectre)]
+ (spectre.open_file_search)))
+ {:nargs 0}]])
+
+(local auto-cmds
+ [[:FileType
+ {:pattern [:spectre_panel]
+ :command "nnoremap <silent> <buffer> q :close<CR>"}]
+ [:FileType {:pattern [:spectre_panel] :command "setlocal spell!"}]])
+
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-user-cmds user-cmds)
+ (cmds.create-auto-cmds auto-cmds)))
+
(local opts {:color_devicons true
:highlight {:ui :String :search :DiffChange :replace :DiffDelete}
:mapping {:toggle_line {:map :t
@@ -53,6 +80,7 @@
{1 :windwp/nvim-spectre
:event :BufReadPost
+ : init
:keys [{1 :<leader>rn 2 :<cmd>ReplaceInBuf<cr> :desc "Replace in Buffer"}
{1 :<leader>re 2 :<cmd>Replace<cr> :desc :Replace}
{1 :<leader>ri 2 :<cmd>ReplaceWord<cr> :desc "Replace Word"}]
diff --git a/fnl/plugins/editor/telescope.fnl b/fnl/plugins/editor/telescope.fnl
index 8f2bff3..83cb4a1 100644
--- a/fnl/plugins/editor/telescope.fnl
+++ b/fnl/plugins/editor/telescope.fnl
@@ -6,6 +6,22 @@
(each [_ extension (ipairs extensions)]
(telescope.load_extension extension)))
+(fn telescope-builtin [builtin opts]
+ (let [telescope (require :telescope.builtin)
+ themes (require :telescope.themes)
+ theme (. opts :theme)]
+ ((. telescope builtin) ((. themes theme) opts))))
+
+(local user-cmds [[:FindFiles
+ (lambda []
+ (telescope-builtin :find_files
+ {:theme :get_dropdown :previewer false}))
+ {:nargs 0}]])
+
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-user-cmds user-cmds)))
+
(local keys [{1 :mf 2 :<cmd>FindFiles<cr> :desc "Find Files"}
{1 :mg
2 "<cmd>Telescope live_grep theme=dropdown<cr>"
@@ -60,7 +76,7 @@
2 "<cmd>Telescope lsp_document_symbols theme=dropdown<cr>"
:desc "Document Symbols"}])
-(fn setup []
+(fn config []
(let [telescope (require :telescope)
actions (require :telescope.actions)
icons (require :plugins.icons)]
@@ -140,8 +156,8 @@
{1 :nvim-telescope/telescope.nvim
:cmd :Telescope
- :config (fn []
- (setup))
+ : init
+ : config
:dependencies [:nvim-lua/popup.nvim
:nvim-telescope/telescope-frecency.nvim
{1 :nvim-telescope/telescope-fzf-native.nvim :build :make}
diff --git a/fnl/plugins/editor/toggleterm.fnl b/fnl/plugins/editor/toggleterm.fnl
index 89d203d..9c2c5dc 100644
--- a/fnl/plugins/editor/toggleterm.fnl
+++ b/fnl/plugins/editor/toggleterm.fnl
@@ -1,6 +1,26 @@
;; Terminal inside nvim.
+(local auto-cmds [[:TermOpen
+ {:pattern "term://*toggleterm#*"
+ :callback (fn []
+ (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>"
+ {}))}]
+ [:TermOpen
+ {:pattern ["term://*toggleterm#*"]
+ :command "setlocal spell!"}]])
+
+(fn init []
+ (let [cmds (require :util.cmds)]
+ (cmds.create-auto-cmds auto-cmds)))
+
{1 :akinsho/toggleterm.nvim
:cmd :ToggleTerm
+ : init
:keys [{1 :<leader>t 2 :<cmd>ToggleTerm<cr> :desc :Terminal}]
:opts {:size 24 :shade_terminals false}}
diff --git a/fnl/settings/autocmds.fnl b/fnl/settings/autocmds.fnl
index a646130..5a2a145 100644
--- a/fnl/settings/autocmds.fnl
+++ b/fnl/settings/autocmds.fnl
@@ -2,48 +2,18 @@
(local cursorline (require :util.cursorline))
-(local autocmds
- [[:FileType
- {:pattern [:qf :help :man :lspinfo :spectre_panel]
- :command "nnoremap <silent> <buffer> q :close<CR>"}]
- [:TextYankPost
+(local auto-cmds
+ [[:TextYankPost
{:callback (lambda []
(vim.highlight.on_yank {:higroup :Visual :timeout 200}))}]
- [:FileType
- {:pattern :lir
- :callback (fn []
- (tset vim.opt_local :number false)
- (tset vim.opt_local :relativenumber false))}]
[:BufWinEnter {:command "setlocal formatoptions-=cro"}]
- [:FileType
- {:pattern :org
- :callback (fn []
- (tset vim.opt_local :conceallevel 2)
- (tset vim.opt_local :concealcursor :nc))}]
[:FileType {:pattern :qf :command "set nobuflisted"}]
[:FileType {:pattern [:gitcommit :markdown] :command "setlocal wrap"}]
- [:FileType
- {:pattern [:NeogitStatus
- :NeogitCommitMessage
- :NeogitNotification
- :NeogitCommitView
- :spectre_panel]
- :command "setlocal spell!"}]
- [:TermOpen
- {:pattern ["term://*toggleterm#*"] :command "setlocal spell!"}]
[:VimResized {:command "tabdo wincmd ="}]
[[:FocusGained :BufEnter :CursorHold :CursorHoldI]
{:command :checktime}]
- [:TermOpen
- {:pattern "term://*toggleterm#*"
- :callback (fn []
- (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>" {}))}]
[[:InsertLeave :WinEnter] {:callback cursorline.show}]
[[:InsertEnter :WinLeave] {:callback cursorline.hide}]])
-(each [_ autocmd (ipairs autocmds)]
- (match autocmd
- [event opts] (vim.api.nvim_create_autocmd event opts)))
+(let [cmds (require :util.cmds)]
+ (cmds.create-auto-cmds auto-cmds))
diff --git a/fnl/settings/init.fnl b/fnl/settings/init.fnl
index 3caa86b..dd392a8 100644
--- a/fnl/settings/init.fnl
+++ b/fnl/settings/init.fnl
@@ -8,5 +8,4 @@
:pattern :VeryLazy
:callback (lambda []
(require :settings.autocmds)
- (require :settings.keymaps)
- (require :settings.usercmds))})
+ (require :settings.keymaps))})
diff --git a/fnl/settings/usercmds.fnl b/fnl/settings/usercmds.fnl
deleted file mode 100644
index 002e1b2..0000000
--- a/fnl/settings/usercmds.fnl
+++ /dev/null
@@ -1,87 +0,0 @@
-;; Commands for plugins.
-
-(fn telescope-builtin [builtin opts]
- (let [telescope (require :telescope.builtin)
- themes (require :telescope.themes)
- theme (. opts :theme)]
- ((. telescope builtin) ((. themes theme) opts))))
-
-(local usercmds [[:OrgAgendaPrompt
- (lambda []
- (let [orgmode (require :orgmode)]
- (orgmode.action :agenda.prompt)))
- {:nargs 0}]
- [:OrgCapturePrompt
- (lambda []
- (let [orgmode (require :orgmode)]
- (orgmode.action :capture.prompt)))
- {:nargs 0}]
- [:CommentNormal
- (lambda []
- (let [comment-api (require :Comment.api)]
- (comment-api.toggle.linewise.current)))
- {:nargs 0}]
- [:CommentVisual
- (lambda []
- (let [comment-api (require :Comment.api)]
- (comment-api.toggle.linewise (vim.fn.visualmode))))
- {:nargs 0}]
- [:HarpoonAdd
- (lambda []
- (let [harpoon (require :harpoon.mark)]
- (harpoon.add_file)))
- {:nargs 0}]
- [:HarpoonNext
- (lambda []
- (let [harpoon (require :harpoon.ui)]
- (harpoon.nav_next)))
- {:nargs 0}]
- [:HarpoonPrev
- (lambda []
- (let [harpoon (require :harpoon.ui)]
- (harpoon.nav_prev)))
- {:nargs 0}]
- [:HarpoonUI
- (lambda []
- (let [harpoon (require :harpoon.ui)]
- (harpoon.toggle_quick_menu)))
- {:nargs 0}]
- [:Replace
- (lambda []
- (let [spectre (require :spectre)]
- (spectre.open)))
- {:nargs 0}]
- [:ReplaceWord
- (lambda []
- (let [spectre (require :spectre)]
- (spectre.open_visual {:select_word true})))
- {:nargs 0}]
- [:ReplaceInBuf
- (lambda []
- (let [spectre (require :spectre)]
- (spectre.open_file_search)))
- {:nargs 0}]
- [:RestoreSession
- (lambda []
- (let [persistence (require :persistence)]
- (persistence.load)))
- {:nargs 0}]
- [:RestoreLastSession
- (lambda []
- (let [persistence (require :persistence)]
- (persistence.load {:last true})))
- {:nargs 0}]
- [:IgnoreSession
- (lambda []
- (let [persistence (require :persistence)]
- (persistence.stop)))
- {:nargs 0}]
- [:FindFiles
- (lambda []
- (telescope-builtin :find_files
- {:theme :get_dropdown :previewer false}))
- {:nargs 0}]])
-
-(each [_ usercmd (ipairs usercmds)]
- (match usercmd
- [event cmd opts] (vim.api.nvim_create_user_command event cmd opts)))
diff --git a/fnl/util/cmds.fnl b/fnl/util/cmds.fnl
new file mode 100644
index 0000000..6ff95a1
--- /dev/null
+++ b/fnl/util/cmds.fnl
@@ -0,0 +1,12 @@
+(fn create-user-cmds [user-cmds]
+ (each [_ user-cmd (ipairs user-cmds)]
+ (match user-cmd
+ [event cmd opts] (vim.api.nvim_create_user_command event cmd opts))))
+
+(fn create-auto-cmds [auto-cmds]
+ (each [_ auto-cmd (ipairs auto-cmds)]
+ ; (print (vim.inspect auto-cmd))
+ (match auto-cmd
+ [event opts] (vim.api.nvim_create_autocmd event opts))))
+
+{: create-user-cmds : create-auto-cmds}