practicalli

practicalli-johnny 2024-08-18T14:55:39.886459Z

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. I can use this after/ftplugin approach to add meaningful names to the Conjure menus that display when pressing the local leader, . to help with discoverability of commands.

-- Configure loaded after clojure filetype set

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>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...

🆒 3