Skip to content

Commit ebea200

Browse files
author
xenodium
committed
Enable compose navigation to jump to response also
1 parent 42a4ff4 commit ebea200

File tree

1 file changed

+43
-6
lines changed

1 file changed

+43
-6
lines changed

chatgpt-shell-prompt-compose.el

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,39 +533,70 @@ Useful if sending a request failed, perhaps from failed connectivity."
533533
(set-window-configuration window-config))))))
534534

535535
(defun chatgpt-shell-prompt-compose-next-item ()
536-
"Jump to and select next item (block, link, interaction)."
536+
"Jump to and select next item (request, response, block, link, interaction)."
537537
(interactive)
538538
(unless (derived-mode-p 'chatgpt-shell-prompt-compose-mode)
539539
(user-error "Not in a shell compose buffer"))
540-
(let* ((next-block (save-excursion
540+
(let* ((request (save-excursion
541+
(when (get-text-property (point) 'ignore)
542+
(text-property-search-forward 'request t)
543+
(point))))
544+
(response (save-excursion
545+
(when (get-text-property (point) 'request)
546+
(text-property-search-forward 'request nil)
547+
(point))))
548+
(next-block (save-excursion
541549
(call-interactively #'chatgpt-shell-next-source-block)))
542550
(next-link (save-excursion
543551
(call-interactively #'chatgpt-shell-next-link)))
544552
(positions (delq nil (list next-block
545-
next-link)))
553+
next-link
554+
response
555+
request)))
546556
(next-pos (when positions
547557
(apply 'min positions))))
548558
(cond ((not next-pos)
549559
(chatgpt-shell-prompt-compose-next-interaction))
560+
((eq next-pos request)
561+
(deactivate-mark)
562+
(goto-char next-pos))
550563
((eq next-pos next-block)
551564
(deactivate-mark)
552565
(goto-char next-block)
553566
(call-interactively #'chatgpt-shell-mark-block))
567+
((eq next-pos response)
568+
(deactivate-mark)
569+
(goto-char next-pos))
554570
((eq next-pos next-link)
555571
(deactivate-mark)
556572
(goto-char next-link)))))
557573

558574
(defun chatgpt-shell-prompt-compose-previous-item ()
559-
"Jump to and select previous item (block, link, interaction)."
575+
"Jump to and select previous item (request, response, block, link, interaction)."
560576
(interactive)
561577
(unless (derived-mode-p 'chatgpt-shell-prompt-compose-mode)
562578
(user-error "Not in a shell compose buffer"))
563-
(let* ((previous-block (save-excursion
579+
(let* ((location (point))
580+
(response (save-excursion
581+
(when (and (not (get-text-property (point) 'ignore))
582+
(not (get-text-property (point) 'request)))
583+
(text-property-search-backward 'request nil)
584+
(text-property-search-forward 'request nil)
585+
(unless (eq location (point))
586+
(point)))))
587+
(request (unless response
588+
(save-excursion
589+
(goto-char (point-min))
590+
(text-property-search-forward 'prompt t)
591+
(point))))
592+
(previous-block (save-excursion
564593
(call-interactively #'chatgpt-shell-previous-source-block)))
565594
(previous-link (save-excursion
566595
(call-interactively #'chatgpt-shell-previous-link)))
567596
(positions (delq nil (list previous-block
568-
previous-link)))
597+
previous-link
598+
response
599+
request)))
569600
(previous-pos (when positions
570601
(apply 'max positions))))
571602
(cond ((eq (point) (save-excursion
@@ -574,6 +605,9 @@ Useful if sending a request failed, perhaps from failed connectivity."
574605
(point)))
575606
(deactivate-mark)
576607
(chatgpt-shell-prompt-compose-previous-interaction))
608+
((eq previous-pos request)
609+
(deactivate-mark)
610+
(goto-char request))
577611
((not previous-pos)
578612
(deactivate-mark)
579613
(goto-char (point-min))
@@ -582,6 +616,9 @@ Useful if sending a request failed, perhaps from failed connectivity."
582616
(deactivate-mark)
583617
(goto-char previous-block)
584618
(call-interactively #'chatgpt-shell-mark-block))
619+
((eq previous-pos response)
620+
(deactivate-mark)
621+
(goto-char previous-pos))
585622
((eq previous-pos previous-link)
586623
(deactivate-mark)
587624
(goto-char previous-link)))))

0 commit comments

Comments
 (0)