Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: emit AiderTerminalOpen event when terminal is created #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

colout
Copy link

@colout colout commented Nov 27, 2024

Hi,

I was looking for a way to add shortcuts that are only applied to this specific buffer. I wanted to use escape to close in normal mode, and <c-s> in all modes, but only in the aider terminal buffer.

Rather than fussing around with checking buffer names in an autocmd, I found it easier to just emit a User event in the plugin on my branch and use the following code in my LazyVim:

  {
   "GeorgesAlkhouri/nvim-aider",
   init = function()
     vim.api.nvim_create_autocmd("User", {
       pattern = "AiderTerminalOpen",
       callback = function(args)
         local buf = args.data.buf
         vim.keymap.set("n", "<Esc>", function()
           require("nvim_aider.terminal").toggle()
         end, { buffer = buf, silent = true })

         vim.keymap.set({"t", "n", "i", "v"}, "<c-s>", function()
           require("nvim_aider.terminal").toggle()
         end, { buffer = buf, silent = true })
       end,
     })
   end,

Not sure if you find this at all helpful, but if you do feel free to merge this (or supply any feedback and I'll happily make the change).

This has been my favorite nvim aider plugin for its simplicity, and I'm happy to contribute more if you're supporting it.

This PR was written 100% by aider / claude sonnet, including the readme. Keeping with the plugin theme, no code was written by a human, though this pr description is 100% me.

@GeorgesAlkhouri
Copy link
Owner

Thanks for your PR! I really appreciate you taking the time to contribute. I'll make sure to review this over the weekend. Really cool to hear that you're finding the plugin useful.

Copy link
Owner

@GeorgesAlkhouri GeorgesAlkhouri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again for your contribution! The idea of emitting user events brings flexibility to the plugin architecture, I really like it! Would you be interested in extending this approach by adding a closing event to provide a more generalized solution? Also, the README could replace its keymap section with an events section that includes keymaps as examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants