Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions shell-maker.el
Original file line number Diff line number Diff line change
Expand Up @@ -571,14 +571,21 @@ Error if invoked from non-shell buffer."
"Search forward for a real prompt matching PROMPT-REGEXP before BOUND.

Skips matches in response content by verifying that the matched
text has `comint-highlight-prompt' face."
(let (found)
text has `comint-highlight-prompt' face.

Like `re-search-forward', leave point unchanged when no prompt is
found. Without this, skipped lookalikes strand point on the last
one searched."
(let ((start (point))
found)
(while (and (not found)
(re-search-forward prompt-regexp bound t))
(when (memq 'comint-highlight-prompt
(ensure-list
(get-text-property (match-beginning 0) 'font-lock-face)))
(setq found t)))
(unless found
(goto-char start))
found))

(defun shell-maker-narrow-to-prompt ()
Expand Down
14 changes: 14 additions & 0 deletions tests/shell-maker-history-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,20 @@
(should (equal (cdr (car result))
"Here is the code:\n<shell-maker-end-of-prompt>\nMore text after")))))

(ert-deftest shell-maker-history-test-search-prompt-leaves-point-when-not-found ()
"Searching past prompt lookalikes should not move point when none is real."
(with-temp-buffer
(insert (shell-maker-history-test--prompt "Agent> ") "explain\n"
(shell-maker-history-test--marker "<shell-maker-end-of-prompt>")
"Here is a transcript excerpt:\n"
"Agent> hello\n"
"and the rest of the answer\n")
(goto-char (point-min))
(should (shell-maker--re-search-forward-prompt "^Agent> "))
(let ((pos (point)))
(should-not (shell-maker--re-search-forward-prompt "^Agent> "))
(should (= (point) pos)))))

(provide 'shell-maker-history-tests)

;;; shell-maker-history-tests.el ends here