gptel: Set window when doing auto-scrolling

* gptel.el (gptel-auto-scroll):  After calling `gptel-send`, the
window focus could have changed as the response is received.  Set
the window correctly when running `gptel-auto-scroll` to ensure
the correct buffer is scrolled.
This commit is contained in:
Karthik Chikmagalur 2023-12-25 14:02:06 -08:00
parent c3ca4fd0a0
commit 9126bed43f

View file

@ -462,14 +462,18 @@ and \"apikey\" as USER."
"Scroll window if LLM response continues below viewport. "Scroll window if LLM response continues below viewport.
Note: This will move the cursor." Note: This will move the cursor."
(when (and (window-live-p (get-buffer-window (current-buffer))) (when-let* ((win (get-buffer-window (current-buffer) 'visible))
(not (pos-visible-in-window-p))) ((not (pos-visible-in-window-p (point) win)))
(scroll-up-command))) (scroll-error-top-bottom t))
(condition-case nil
(with-selected-window win
(scroll-up-command))
(error nil))))
(defun gptel-end-of-response (&optional arg) (defun gptel-end-of-response (&optional arg)
"Move point to the end of the LLM response ARG times." "Move point to the end of the LLM response ARG times."
(interactive "p") (interactive "p")
(dotimes (if arg (abs arg) 1) (dotimes (_ (if arg (abs arg) 1))
(text-property-search-forward 'gptel 'response t) (text-property-search-forward 'gptel 'response t)
(when (looking-at (concat "\n\\{1,2\\}" (when (looking-at (concat "\n\\{1,2\\}"
(regexp-quote (regexp-quote