emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/gptel 0ea3c7fb15 143/273: gptel-transient: Improve suffix


From: ELPA Syncer
Subject: [nongnu] elpa/gptel 0ea3c7fb15 143/273: gptel-transient: Improve suffix message editor
Date: Wed, 1 May 2024 10:02:16 -0400 (EDT)

branch: elpa/gptel
commit 0ea3c7fb15b0b60bcc930d7cadc5148abb1ca724
Author: Karthik Chikmagalur <karthikchikmagalur@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmagalur@gmail.com>

    gptel-transient: Improve suffix message editor
    
    * gptel-transient.el (gptel--suffix-system-message):  Improve the
    editing prompt for custom suffixes.  Unset the "C-c C-c" and "C-c
    C-k" keys from text-mode.  FIXME: This is fragile, instead add the
    keymap with these keys as a sticky text-property over the text.
---
 gptel-transient.el | 43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/gptel-transient.el b/gptel-transient.el
index 2ee95219d9..7694fedceb 100644
--- a/gptel-transient.el
+++ b/gptel-transient.el
@@ -520,24 +520,29 @@ This uses the prompts in the variable
   (let ((orig-buf (current-buffer))
         (msg-start (make-marker)))
     (with-current-buffer (get-buffer-create "*gptel-system*")
-      (erase-buffer)
-      (text-mode)
-      (insert
-       "# Insert your system message below and press "
-       (propertize "C-c C-c" 'face 'help-key-binding)
-       " when ready, or "
-       (propertize "C-c C-k" 'face 'help-key-binding)
-       " to abort.\n"
-       "# Example: You are a helpful assistant. Answer as concisely as 
possible.\n"
-       "# Example: Reply only with shell commands and no prose.\n"
-       "# Example: You are a poet. Reply only in verse.\n\n")
-      (set-marker msg-start (point))
-      (insert (buffer-local-value 'gptel--system-message orig-buf))
-      (beginning-of-line)
-      (push-mark)
-      (end-of-line)
-      (exchange-point-and-mark)
-      (activate-mark)
+      (let ((inhibit-read-only t))
+        (erase-buffer)
+        (text-mode)
+        (insert
+         "# Insert your system message below and press "
+         (propertize "C-c C-c" 'face 'help-key-binding)
+         " when ready, or "
+         (propertize "C-c C-k" 'face 'help-key-binding)
+         " to abort.\n"
+         "# Example: You are a helpful assistant. Answer as concisely as 
possible.\n"
+         "# Example: Reply only with shell commands and no prose.\n"
+         "# Example: You are a poet. Reply only in verse.\n")
+        (add-text-properties
+         (point-min) (point)
+         (list 'read-only t 'face 'font-lock-comment-face))
+        (insert "\n")
+        ;; TODO: make-separator-line requires Emacs 28.1+.
+        ;; (insert (propertize (make-separator-line) 'rear-nonsticky t))
+        (set-marker msg-start (point))
+        (insert (buffer-local-value 'gptel--system-message orig-buf))
+        (push-mark)
+        (beginning-of-line)
+        (activate-mark))
       (display-buffer (current-buffer)
                       `((display-buffer-below-selected)
                         (body-function . ,#'select-window)
@@ -545,6 +550,8 @@ This uses the prompts in the variable
       (let ((quit-to-menu
              (lambda ()
                (interactive)
+               (local-unset-key (kbd "C-c C-c"))
+               (local-unset-key (kbd "C-c C-k"))
                (quit-window)
                (display-buffer
                 orig-buf



reply via email to

[Prev in Thread] Current Thread [Next in Thread]