start using markers for tracking where the user’s prompt is
This commit is contained in:
17
codex.el
17
codex.el
@@ -61,6 +61,8 @@
|
|||||||
(setq-local truncate-lines t)
|
(setq-local truncate-lines t)
|
||||||
(setq-local codex--busy nil))
|
(setq-local codex--busy nil))
|
||||||
|
|
||||||
|
(defvar-local codex--prompt-start nil)
|
||||||
|
|
||||||
(defun list->hash-set (list &optional test)
|
(defun list->hash-set (list &optional test)
|
||||||
"Return a hash table whose keys are the elements of LIST."
|
"Return a hash table whose keys are the elements of LIST."
|
||||||
(let ((ht (make-hash-table :test (or test #'equal))))
|
(let ((ht (make-hash-table :test (or test #'equal))))
|
||||||
@@ -79,7 +81,8 @@
|
|||||||
(defun user-prompt ()
|
(defun user-prompt ()
|
||||||
(prompt-delimiter)
|
(prompt-delimiter)
|
||||||
(insert "User:")
|
(insert "User:")
|
||||||
(newline))
|
(newline)
|
||||||
|
(setq codex--prompt-start (point-marker)))
|
||||||
|
|
||||||
(defun codex--write-to-chat (msg)
|
(defun codex--write-to-chat (msg)
|
||||||
(with-codex-buffer
|
(with-codex-buffer
|
||||||
@@ -153,12 +156,10 @@
|
|||||||
(kill-buffer)))))))
|
(kill-buffer)))))))
|
||||||
|
|
||||||
(defun codex--get-current-user-prompt ()
|
(defun codex--get-current-user-prompt ()
|
||||||
(with-current-buffer codex-buffer-name
|
(with-codex-buffer
|
||||||
(let* ((haystack (buffer-string))
|
(unless codex--prompt-start
|
||||||
(needle "---\nUser:\n")
|
(error "No current prompt start"))
|
||||||
(index
|
(buffer-substring-no-properties codex--prompt-start (point-max))))
|
||||||
(cl-search needle haystack :from-end t)))
|
|
||||||
(substring haystack (+ (length needle) index)))))
|
|
||||||
|
|
||||||
(defun codex-send ()
|
(defun codex-send ()
|
||||||
(interactive)
|
(interactive)
|
||||||
@@ -181,7 +182,7 @@
|
|||||||
(pop-to-buffer buf)
|
(pop-to-buffer buf)
|
||||||
(unless (derived-mode-p 'codex-mode)
|
(unless (derived-mode-p 'codex-mode)
|
||||||
(codex-mode))
|
(codex-mode))
|
||||||
(insert "---\nUser:\n")
|
(user-prompt)
|
||||||
(goto-char (point-max)))))
|
(goto-char (point-max)))))
|
||||||
|
|
||||||
(defun codex--read-sessions-file ()
|
(defun codex--read-sessions-file ()
|
||||||
|
|||||||
Reference in New Issue
Block a user