branch: elpa/gptel commit f9a4af702265f9855829a9a0e3266db10a569df6 Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com> Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
gptel-rewrite: Add preset picker to menu * gptel-rewrite.el (gptel-rewrite): Add preset picker to menu. * gptel-transient.el (gptel--format-preset-string): Remove text "Request Parameters" from function so it is more composable. (gptel-menu): Adjust. --- gptel-rewrite.el | 8 ++++++++ gptel-transient.el | 37 +++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/gptel-rewrite.el b/gptel-rewrite.el index 68fd8fa7a2..b5e8cfcb58 100644 --- a/gptel-rewrite.el +++ b/gptel-rewrite.el @@ -483,6 +483,14 @@ By default, gptel uses the directive associated with the `rewrite' (gptel--describe-directive gptel--rewrite-directive (max (- (window-width) 14) 20) " ")) ["" + (gptel--preset + :if (lambda () (or (get-char-property (point) 'gptel-rewrite) + (use-region-p))) + :key "@" :format "%d" + :description + (lambda () + (concat (propertize "Instructions" 'face 'transient-heading) + (gptel--format-preset-string)))) ("s" "Set full directive" gptel--rewrite-directive-menu) (gptel--infix-rewrite-extra)]] ;; FIXME: We are requiring `gptel-transient' because of this suffix, perhaps diff --git a/gptel-transient.el b/gptel-transient.el index 12b1f20225..d3cd48c3fd 100644 --- a/gptel-transient.el +++ b/gptel-transient.el @@ -422,23 +422,21 @@ which see." (defun gptel--format-preset-string () "Format the preset indicator display for `gptel-menu'." - (concat - (propertize "Request Parameters" 'face 'transient-heading) - (if (and gptel--known-presets gptel--preset) - (apply - #'format " (%s%s)" - (let ((mismatch (gptel--preset-mismatch-p gptel--preset))) - (list (propertize "@" 'face (if mismatch 'transient-key - '( :inherit transient-key - :inherit secondary-selection - :box -1 :weight bold))) - (propertize (format "%s" gptel--preset) 'face - (if mismatch - '(:inherit warning :strike-through t) - '(:inherit secondary-selection :box -1)))))) - (format " (%s%s)" - (propertize "@" 'face 'transient-key) - (propertize "preset" 'face 'transient-inactive-value))))) + (if (and gptel--known-presets gptel--preset) + (apply + #'format " (%s%s)" + (let ((mismatch (gptel--preset-mismatch-p gptel--preset))) + (list (propertize "@" 'face (if mismatch 'transient-key + '( :inherit transient-key + :inherit secondary-selection + :box -1 :weight bold))) + (propertize (format "%s" gptel--preset) 'face + (if mismatch + '(:inherit warning :strike-through t) + '(:inherit secondary-selection :box -1)))))) + (format " (%s%s)" + (propertize "@" 'face 'transient-key) + (propertize "preset" 'face 'transient-inactive-value)))) ;; * Transient classes and methods for gptel @@ -652,7 +650,10 @@ Also format its value in the Transient menu." (eq (gptel-fsm-state gptel--fsm-last) 'TOOL))))]] [[(gptel--preset :key "@" :format "%d" - :description gptel--format-preset-string) + :description + (lambda () + (concat (propertize "Request Parameters" 'face 'transient-heading) + (gptel--format-preset-string)))) (gptel--infix-variable-scope) (gptel--infix-provider) (gptel--infix-max-tokens)