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