From 53a905dafc99fc1a3732655a2123657c145343a2 Mon Sep 17 00:00:00 2001 From: Karthik Chikmagalur Date: Tue, 2 Apr 2024 19:33:39 -0700 Subject: [PATCH] gptel: Show chosen system message in header-line * gptel.el (gptel): Show chosen system message in header-line (#274). Remove the context indicator `[Send: ...]`, as this needs to be reworked for the upcoming context-inclusion features anyway. * gptel-transient.el (gptel-system-prompt): Autoload `gptel-system-prompt`, this is required for the gptel header-line. --- gptel-transient.el | 1 + gptel.el | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/gptel-transient.el b/gptel-transient.el index d7971fc..ee7f381 100644 --- a/gptel-transient.el +++ b/gptel-transient.el @@ -404,6 +404,7 @@ Also format its value in the Transient menu." ;; instead of returning to the system prompt menu. :transient 'transient--do-exit)))))) +;;;###autoload (autoload 'gptel-system-prompt "gptel-transient" nil t) (transient-define-prefix gptel-system-prompt () "Set the LLM system message for LLM interactions in this buffer. diff --git a/gptel.el b/gptel.el index e3ec652..4dcb2f7 100644 --- a/gptel.el +++ b/gptel.el @@ -108,6 +108,7 @@ (declare-function markdown-mode "markdown-mode") (declare-function gptel-curl-get-response "gptel-curl") (declare-function gptel-menu "gptel-transient") +(declare-function gptel-system-prompt "gptel-transient") (declare-function pulse-momentary-highlight-region "pulse") ;; Functions used for saving/restoring gptel state in Org buffers @@ -773,21 +774,20 @@ file." (format "%s" (gptel-backend-name gptel-backend)))) (propertize " Ready" 'face 'success) '(:eval - (let* ((l1 (length gptel-model)) - (num-exchanges - (if gptel--num-messages-to-send - (format "[Send: %s exchanges]" gptel--num-messages-to-send) - "[Send: buffer]")) - (l2 (length num-exchanges))) + (let ((system + (format "[Prompt: %s]" + (or (car-safe (rassoc gptel--system-message gptel-directives)) + (truncate-string-to-width gptel--system-message 15 nil nil t))))) (concat (propertize - " " 'display `(space :align-to ,(max 1 (- (window-width) (+ 2 l1 l2))))) + " " 'display + `(space :align-to (- right ,(+ 2 (length gptel-model) (length system))))) (propertize - (buttonize num-exchanges - (lambda (&rest _) (gptel-menu))) + (buttonize system + (lambda (&rest _) (gptel-system-prompt))) 'mouse-face 'highlight 'help-echo - "Number of past exchanges to include with each request") + "System message for buffer") " " (propertize (buttonize (concat "[" gptel-model "]")