Skip to content

Commit

Permalink
gptel-transient: Fix bug when sending in existing session
Browse files Browse the repository at this point in the history
* gptel-transient.el (gptel--suffix-send, gptel-menu): When
reading input from the minibuffer and sending the output to an
existing gptel session, only use the prompt read from the
minibuffer. Reword the "Overwrite/Delete prompt" option.
  • Loading branch information
karthink committed Apr 11, 2023
1 parent 00abbf7 commit f218388
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions gptel-transient.el
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Or is it the other way around?"
(gptel--infix-model)]
["Prompt:"
("-r" "From minibuffer instead" "-r")
("-i" "Overwrite/Delete prompt" "-i")
("-i" "Replace/Delete prompt" "-i")
"Response to:"
("-m" "Minibuffer instead" "-m")
("-n" "New session" "-n"
Expand Down Expand Up @@ -339,18 +339,19 @@ will get progressively longer!"
(setq buffer (get-buffer buffer-name))
(setq output-to-other-buffer-p t)
(let ((reduced-prompt
(if (use-region-p)
(buffer-substring-no-properties (region-beginning)
(region-end))
(buffer-substring-no-properties
(save-excursion
(text-property-search-backward
'gptel 'response
(when (get-char-property (max (point-min) (1- (point)))
'gptel)
t))
(point))
(point)))))
(or prompt
(if (use-region-p)
(buffer-substring-no-properties (region-beginning)
(region-end))
(buffer-substring-no-properties
(save-excursion
(text-property-search-backward
'gptel 'response
(when (get-char-property (max (point-min) (1- (point)))
'gptel)
t))
(point))
(point))))))
(with-current-buffer buffer
(goto-char (point-max))
(insert reduced-prompt)
Expand Down

0 comments on commit f218388

Please sign in to comment.