branch: elpa/gptel commit 4a4f253686373810d09cf9ead59ff8f772e23eba Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-rewrite: Add context indicator * gptel-transient.el (gptel--refactor-or-rewrite): Turn into defsubst * gptel-rewrite.el: Require gptel-transient for the context buffer suffix. TODO: Find some way around having to require gptel-transient. (gptel--refactor-or-rewrite): Turn into defsubst. (gptel-rewrite-menu): Add context indicator and context buffer suffix (gptel--suffix-rewrite): Always include context (when available) with the system message. --- gptel-rewrite.el | 14 ++++++++++---- gptel-transient.el | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/gptel-rewrite.el b/gptel-rewrite.el index 516b2fe287..7f98c17623 100644 --- a/gptel-rewrite.el +++ b/gptel-rewrite.el @@ -23,8 +23,7 @@ ;; ;;; Code: -(require 'gptel) -(require 'transient) +(require 'gptel-transient) (require 'cl-lib) (defvar eldoc-documentation-functions) @@ -81,7 +80,7 @@ for a particular major-mode." (cl-delete-if-not #'overlay-buffer gptel--rewrite-overlays))) -(defun gptel--refactor-or-rewrite () +(defsubst gptel--refactor-or-rewrite () "Rewrite should be refactored into refactor. Or is it the other way around?" @@ -258,6 +257,11 @@ the changed regions. BUF is the (current) buffer." gptel--rewrite-message (max (- (window-width) 14) 20) nil nil t))) (gptel--infix-rewrite-prompt)] + ;; FIXME: We are requiring `gptel-transient' because of this suffix, perhaps + ;; we can get find some way around that? + [:description (lambda () (concat "Context for " (gptel--refactor-or-rewrite))) + :if use-region-p + (gptel--suffix-context-buffer :key "C")] [[:description "Diff Options" :if (lambda () gptel--rewrite-overlays) ("-b" "Ignore whitespace changes" ("-b" "--ignore-space-change")) @@ -321,7 +325,9 @@ the changed regions. BUF is the (current) buffer." (interactive (list gptel--rewrite-message)) (let* ((prompt (buffer-substring-no-properties (region-beginning) (region-end))) - (gptel--system-message (or rewrite-message gptel--rewrite-message))) + (gptel--system-message (or rewrite-message gptel--rewrite-message)) + ;; always send context with system message + (gptel-use-context (and gptel-use-context 'system))) (deactivate-mark) (gptel-request prompt :context diff --git a/gptel-transient.el b/gptel-transient.el index 019ac1ae7d..5c79c891eb 100644 --- a/gptel-transient.el +++ b/gptel-transient.el @@ -97,7 +97,7 @@ documention." (ignore-errors (read-from-minibuffer prompt initial-input read-expression-map t history))) -(defun gptel--refactor-or-rewrite () +(defsubst gptel--refactor-or-rewrite () "Rewrite should be refactored into refactor. Or is it the other way around?"