karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.63k stars 151 forks source link

change keybindings for refactor of highlighted buffer #463

Open kyle-okami opened 2 weeks ago

kyle-okami commented 2 weeks ago

When I highlight a section of code in a buffer and press C-u gptel-send, then "r" twice, the refactoring process begins. After refactoring, the modified code is highlighted, displaying the label REFACTOR_READY. To accept or clear this refactored code, the keybindings are C-c C-a and C-c C-k, respectively.

How can I rebind these actions so that when my cursor is in the highlighted region, I can press "a" to accept or "q" to clear instead?

karthink commented 2 weeks ago

These keybindings are in the gptel-rewrite-actions-map keymap, so you can set them like:

(keymap-set gptel-rewrite-actions-map "a" 'gptel--rewrite-apply)

See M-x describe-keymap gptel-rewrite-actions-map for the bindings and commands.


As an aside, here's how you could discover this yourself: when the refactoring is ready, instead of running C-c C-a (say), run M-x describe-key C-c C-a. This pops up a help window with the following text:

C-c C-a runs the command gptel--rewrite-apply (found in
gptel-rewrite-actions-map), which is an interactive Lisp closure in
‘gptel-rewrite.el’.

It is bound to C-c C-a.

(gptel--rewrite-apply &optional OVS)

Apply pending LLM responses in OVS or at point.

[back]

As you can see, it shows you the command and the keymap where it is found.


Please close this issue if the answer is satisfactory.