branch: externals/minuet commit 49e36de4b50054ce5b4afba4cc9553dd4416d308 Author: Milan Glacier <d...@milanglacier.com> Commit: Milan Glacier <d...@milanglacier.com>
feat: add minuet-active-mode for better keybinding management --- README.md | 17 ++++++++++++----- minuet.el | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 09867c8e4a..f3b4b014c4 100644 --- a/README.md +++ b/README.md @@ -68,11 +68,7 @@ Currently you need to install from github via `package-vc` or ;; use completion-in-region for completion "M-y" #'minuet-completion-region ;; use overlay for completion - "M-p" #'minuet-previous-suggestion ;; invoke completion or cycle to next completion - "M-n" #'minuet-next-suggestion ;; invoke completion or cycle to previous completion - "M-A" #'minuet-accept-suggestion ;; accept whole completion - "M-a" #'minuet-accept-suggestion-line ;; accept current line completion - "M-e" #'minuet-dismiss-suggestion) + "M-i" #'minuet-show-suggestion) ;; if you want to enable auto suggestion. ;; Note that you can manually invoke completions without enable minuet-auto-suggestion-mode @@ -81,6 +77,17 @@ Currently you need to install from github via `package-vc` or :config (setq minuet-provider 'openai-fim-compatible) + ;; if you are using evil, this is required. + (add-hook 'minuet-active-mode-hook #'evil-normalize-keymaps) + + (general-define-key + :keymaps 'minuet-active-mode-map + "M-p" #'minuet-previous-suggestion ;; invoke completion or cycle to next completion + "M-n" #'minuet-next-suggestion ;; invoke completion or cycle to previous completion + "M-A" #'minuet-accept-suggestion ;; accept whole completion + "M-a" #'minuet-accept-suggestion-line ;; accept current line completion + "M-e" #'minuet-dismiss-suggestion) + (minuet-set-optional-options minuet-openai-fim-compatible-options :max_tokens 256)) ``` diff --git a/minuet.el b/minuet.el index 660adeefbd..179819f89d 100644 --- a/minuet.el +++ b/minuet.el @@ -322,7 +322,8 @@ symbol, return its value. Else return itself." (minuet--cancel-requests)) (when minuet--current-overlay (delete-overlay minuet--current-overlay) - (setq minuet--current-overlay nil)) + (setq minuet--current-overlay nil) + (minuet-active-mode -1)) (remove-hook 'post-command-hook #'minuet--on-cursor-moved t) (setq minuet--last-point nil)) @@ -359,7 +360,8 @@ symbol, return its value. Else return itself." total) 'face 'minuet-suggestion-face)) (overlay-put ov 'minuet t) - (setq minuet--current-overlay ov))) + (setq minuet--current-overlay ov) + (minuet-active-mode 1))) ;;;###autoload (defun minuet-next-suggestion () @@ -1030,5 +1032,14 @@ When enabled, Minuet will automatically show suggestions while you type." (minuet--setup-auto-suggestion) (minuet--cleanup-auto-suggestion))) +(defvar minuet-active-mode-map + (let ((map (make-sparse-keymap))) map) + "Keymap used when minuet-active-mode is enabled.") + +(define-minor-mode minuet-active-mode + "When there is an active suggestion in minuet." + :init-value nil + :keymap minuet-active-mode-map) + (provide 'minuet) ;;; minuet.el ends here