From 2b55cf7bd93f5038f59ecdb1909d3d4f20e339f8 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Wed, 13 Jul 2022 18:48:55 +0100 Subject: [PATCH] feat(completion/copilot): add new and improve existing keybindings --- modules/completion/siren-copilot.el | 46 ++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/modules/completion/siren-copilot.el b/modules/completion/siren-copilot.el index df78242..39d5bb1 100644 --- a/modules/completion/siren-copilot.el +++ b/modules/completion/siren-copilot.el @@ -13,21 +13,45 @@ (prog-mode . copilot-mode) :general - ("C-" 'copilot-accept-completion) - ("" 'copilot-accept-completion) - (:keymaps 'company-active-map - "C-" 'copilot-accept-completion - "C-TAB" 'copilot-accept-completion - "" 'copilot-accept-completion) + ("C-" 'siren-copilot-accept-completion-dwim) + ("" 'siren-copilot-accept-completion-dwim) + ("M-F" 'siren-copilot-accept-completion-by-word-dwim) + ("M-E" 'siren-copilot-accept-completion-by-line-dwim) + (:keymaps 'copilot-completion-map + "M-N" 'copilot-next-completion + "M-P" 'copilot-previous-completion) + + :preface + (defun siren-copilot-accept-completion-dwim () + "Accept the current completion or trigger copilot-compilot." + (interactive) + (siren-copilot-complete-or-call 'copilot-accept-completion)) + + (defun siren-copilot-accept-completion-by-word-dwim () + "Accept the current completion by word, or trigger copilot-compilot." + (interactive) + (siren-copilot-complete-or-call 'copilot-accept-completion-by-word 1)) + + (defun siren-copilot-accept-completion-by-line-dwim () + "Accept the current completion by word, or trigger copilot-compilot." + (interactive) + (siren-copilot-complete-or-call 'copilot-accept-completion-by-line 1)) + + (defun siren-copilot-complete-or-call (f &rest args) + "Trigger copilot-complete or call F." + (if (copilot-current-completion) + (apply f args) + (copilot-complete))) :config (with-eval-after-load 'company ;; Use company popup even when there's only one result - (delq 'company-preview-if-just-one-frontend company-frontends) - (setf (nth (position 'company-pseudo-tooltip-unless-just-one-frontend - company-frontends) - company-frontends) - 'company-pseudo-tooltip-frontend))) + (when (member 'company-preview-if-just-one-frontend company-frontends) + (delq 'company-preview-if-just-one-frontend company-frontends) + (setf (nth (position 'company-pseudo-tooltip-unless-just-one-frontend + company-frontends) + company-frontends) + 'company-pseudo-tooltip-frontend)))) (provide 'siren-copilot) ;;; siren-copilot.el ends here