[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/gptel 56f9fc5e72 04/20: gptel-transient: Make gptel-lisp-v
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/gptel 56f9fc5e72 04/20: gptel-transient: Make gptel-lisp-variable more flexible |
Date: |
Sun, 23 Jun 2024 00:59:52 -0400 (EDT) |
branch: elpa/gptel
commit 56f9fc5e720dcfdb5e10184bddf2e5d399478d5f
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: karthink <karthikchikmagalur@gmail.com>
gptel-transient: Make gptel-lisp-variable more flexible
gptel-transient.el (gptel-lisp-variable): Provide more flexible
display options for transient class `gptel-lisp-variable`.
Specifically, add an optional alist of mappings from possible
values to display strings. This mapping is used by
`transient-format-value` when creating the transient menu.
This avoids creating singleton transient suffix classes for
variables whose values are symbols with special semantics, for
instance.
* gptel-transient.el (gptel-context-destination-variable,
gptel--infix-context-destination): Use the `gptel-lisp-variable`
class instead of defining a singleton class just for value
formatting.
---
gptel-transient.el | 63 ++++++++++++++++++++++--------------------------------
1 file changed, 26 insertions(+), 37 deletions(-)
diff --git a/gptel-transient.el b/gptel-transient.el
index 333631ecfe..d082fd0b78 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -166,14 +166,19 @@ which see."
;; * Transient classes and methods for gptel
(defclass gptel-lisp-variable (transient-lisp-variable)
- ((display-nil :initarg :display-nil))
+ ((display-nil :initarg :display-nil) ;String to display if value if nil
+ (display-map :initarg :display-map :initform nil)) ;Display string from
alist display-map
"Lisp variables that show :display-nil instead of nil.")
-(cl-defmethod transient-format-value
- ((obj gptel-lisp-variable))
- (propertize (prin1-to-string (or (oref obj value)
- (oref obj display-nil)))
- 'face 'transient-value))
+(cl-defmethod transient-format-value ((obj gptel-lisp-variable))
+ (let ((display-value
+ (with-slots (value display-nil display-map) obj
+ (cond ((null value) display-nil)
+ (display-map (cdr (assoc value display-map)))
+ (t value)))))
+ (propertize
+ (if (stringp display-value) display-value (prin1-to-string display-value))
+ 'face 'transient-value)))
(cl-defmethod transient-infix-set ((obj gptel-lisp-variable) value)
(funcall (oref obj set-value)
@@ -236,32 +241,6 @@ This is used only for setting this variable via
`gptel-menu'.")
(oset obj model-value model-value)
gptel--set-buffer-locally)))
-(defclass gptel-context-destination-variable (transient-lisp-variable)
- ((display-value :initarg :display-value
- :initform (lambda (value)
- (pcase value
- (:nowhere "Nowhere")
- (:before-system-message "Before system
message")
- (:after-system-message "After system message")
- (:before-user-prompt "Before user prompt")
- (:after-user-prompt "After user prompt"))))))
-
-(cl-defmethod transient-format-value ((obj gptel-context-destination-variable))
- (propertize (funcall (oref obj display-value)
- (buffer-local-value (oref obj variable)
transient--original-buffer))
- 'face 'transient-value))
-
-(cl-defmethod transient-infix-set ((obj gptel-context-destination-variable)
value)
- (funcall (oref obj set-value)
- (oref obj variable)
- (pcase value
- ("Nowhere" :nowhere)
- ("Before system message" :before-system-message)
- ("After system message" :after-system-message)
- ("Before user prompt" :before-user-prompt)
- ("After user prompt" :after-user-prompt))
- gptel--set-buffer-locally))
-
(defclass gptel-option-overlaid (transient-option)
((display-nil :initarg :display-nil)
(overlay :initarg :overlay))
@@ -502,15 +481,25 @@ Customize `gptel-directives' for task-specific prompts."
(transient-define-infix gptel--infix-context-destination ()
"Describe target destination for context injection."
- :description "Context destination"
- :class 'gptel-context-destination-variable
+ :description "Include context"
+ :class 'gptel-lisp-variable
:variable 'gptel-context-injection-destination
:set-value #'gptel--set-with-scope
+ :display-nil "No"
+ :display-map '((:nowhere . "No")
+ (:before-system-message . "before system message")
+ (:after-system-message . "after system message")
+ (:before-user-prompt . "before user prompt")
+ (:after-user-prompt . "after user prompt"))
:key "-xd"
:reader (lambda (prompt &rest _)
- (completing-read prompt '("Nowhere" "Before system message" "After
system message"
- "Before user prompt" "After user prompt")
- nil t)))
+ (let* ((choices '(("No" . :nowhere)
+ ("before system message" .
:before-system-message)
+ ("after system message" . :after-system-message)
+ ("before user prompt" . :before-user-prompt)
+ ("after user prompt" . :after-user-prompt)))
+ (destination (completing-read prompt choices nil t)))
+ (cdr (assoc destination choices)))))
(transient-define-infix gptel--infix-use-context-in-chat ()
"Determine if context should be passed to the LLM during the chat."
- [nongnu] elpa/gptel b10cd98e07 02/20: gptel-context: Implement DWIM features, (continued)
- [nongnu] elpa/gptel b10cd98e07 02/20: gptel-context: Implement DWIM features, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 382b409176 03/20: gptel-transient: Simplify context buffer, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel f6306b5b15 08/20: gptel-transient: Update menu for context actions, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 5d093f2135 10/20: gptel-context: Support for files as context, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 0787592609 12/20: gptel-context: Fix context deletion overlay bug, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 0abaefed38 13/20: gptel-context: Fix narrowing bug when inserting context, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel c81284479f 18/20: gptel-transient: Move context items around, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 883b5e608a 17/20: gptel-context: Extra newlines before separator-line, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel df0b424ea1 20/20: gptel-ollama: Add num_ctx option, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel ef44164614 19/20: README: Update for context features, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 56f9fc5e72 04/20: gptel-transient: Make gptel-lisp-variable more flexible,
ELPA Syncer <=
- [nongnu] elpa/gptel cbb49f92d3 05/20: gptel-context: Add gptel-context--wrap, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 2b1dbf77b1 09/20: gptel-context: Make overlays front/rear-advance, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 70e3053c42 14/20: gptel-context: Clean up context buffer setup, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 8838f88950 06/20: gptel: Add gptel--strip-mode-suffix, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 31aa385a9d 07/20: gptel-context: Invert dependency, rename contexter and lint, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 3e7a4eb83c 11/20: gptel-context: Better context buffer navigation, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel 121d73b99d 15/20: gptel-context: wrap-function instead of string-function, ELPA Syncer, 2024/06/23
- [nongnu] elpa/gptel aa5f0737f2 16/20: gptel-context: whitespace at end of context string, ELPA Syncer, 2024/06/23