Clojure specific Which-key menu
Whilst looking for a Neovim way to have language specific configuration, I discovered the after/ftplugin
approach. This allows a configuration to be loaded when a buffer is switched to a specific language.
Having used Spacemacs (Emacs) for many years I was used to having language mode specific menus, e.g. Clojure has many cider which-key bindings available which are defined in the Clojure major mode.
I was curious how I could also do this with Neovim.
Whist autocmd
definitions can be used for filetype specific actions, there is also a seemingly simpler approach using configuration in after/ftplugin/
directory, i.e. after/ftplugin/clojure.lua
for the Clojure filetypes.
The after/ftplugin
approach is used to add meaningful names to the Conjure menus that display when pressing the local leader ,
to help with discoverability of commands.
-- Loaded after clojure filetype set in buffer
local whichkey = require "which-key"
return {
{
"folke/which-key.nvim",
-- Load Conjure Groups only for Clojure filetypes
whichkey.add {
-- Conjure sub-menus
{ "<LocalLeader>c", group = "Connect" },
{ "<LocalLeader>e", group = "Evaluate" },
{ "<LocalLeader>ec", group = "Comment" },
{ "<LocalLeader>g", group = "Go" },
{ "<LocalLeader>l", group = "Log" },
{ "<LocalLeader>r", group = "Refresh" },
{ "<LocalLeader>s", group = "Session" },
{ "<LocalLeader>t", group = "Test" },
{ "<LocalLeader>v", group = "Values" },
},
},
}
This should only show the menu when using the localleader
when the current buffer is clojure
filetype. It seems to work so far...
Thank you.