add fallback for user prompt start
This commit is contained in:
17
codex.el
17
codex.el
@@ -180,9 +180,20 @@
|
|||||||
|
|
||||||
(defun codex--get-current-user-prompt ()
|
(defun codex--get-current-user-prompt ()
|
||||||
(with-codex-buffer
|
(with-codex-buffer
|
||||||
(unless codex--prompt-start
|
(let ((prompt-start (and codex--prompt-start
|
||||||
(error "No current prompt start"))
|
(marker-buffer codex--prompt-start)
|
||||||
(buffer-substring-no-properties codex--prompt-start (point-max))))
|
(marker-position codex--prompt-start))))
|
||||||
|
;; fallback in case we somehow lost where our user prompt starts
|
||||||
|
(unless prompt-start
|
||||||
|
(let* ((haystack (buffer-string))
|
||||||
|
(needle "---\nUser:\n")
|
||||||
|
(index (cl-search needle haystack :from-end t)))
|
||||||
|
(when index
|
||||||
|
(setq prompt-start (+ (length needle) index))
|
||||||
|
(setq codex--prompt-start (copy-marker prompt-start)))))
|
||||||
|
(unless prompt-start
|
||||||
|
(error "No current prompt start"))
|
||||||
|
(buffer-substring-no-properties prompt-start (point-max)))))
|
||||||
|
|
||||||
(defun codex-send ()
|
(defun codex-send ()
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|||||||
Reference in New Issue
Block a user