Skip to content

[Feature (not a request)] Consult chatgpt-buffer #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
gggion opened this issue Mar 25, 2025 · 2 comments
Open

[Feature (not a request)] Consult chatgpt-buffer #335

gggion opened this issue Mar 25, 2025 · 2 comments

Comments

@gggion
Copy link

gggion commented Mar 25, 2025

Just figured I would put here this consult function for chatgpt-shell buffers I've been using,
it uses the process name to fetch all the chatgpt-shell buffers so no need to pattern match buffer names in case they're renamed (previously used llm to fetch them).

Im using doom emacs so no idea if it'll work for everyone.

(require 'consult)

(defgroup consult-chatgpt-shell-buffers nil
  "Navigate between LLM conversation buffers."
  :group 'convenience
  :prefix "consult-chatgpt-shell-buffers-")


;;;###autoload
(defun consult-chatgpt-shell-buffers ()
  "Choose an LLM conversation buffer from a Consult menu.
Lists buffers that have a process with 'chatgpt' in the name."
  (interactive)
  (let* ((llm-buffers
          (cl-loop for proc in (process-list)
                   ;; Check if process name contains "chatgpt"
                   when (and (string-match-p "chatgpt" (process-name proc))
                             (process-buffer proc)
                             (buffer-live-p (process-buffer proc)))
                   collect (process-buffer proc)))
         (selected-buffer
          (consult--read
           (mapcar #'buffer-name llm-buffers)
           :prompt "Select an LLM buffer: "
           :category 'buffer
           :sort nil
           :require-match t
           :state (consult--buffer-state))))
    (when selected-buffer
      (switch-to-buffer selected-buffer))))

Image

@xenodium
Copy link
Owner

Neat! I have a more rudimentary approach of invoking my usual function to swap buffers and type "llm" to filter chat buffes. Thanks for sharing it. Have you considered using completing-read? It would enable folks using any completion framework.

@gggion
Copy link
Author

gggion commented Mar 25, 2025

Nice hadn't thought of that, yeah its was pretty straightforward

(defun chatgpt-shell-switch-buffer ()
  "Switch to a ChatGPT shell buffer using completion."
  (interactive)
  (let* ((buffers (seq-filter
                   (lambda (buf)
                     (when-let ((proc (get-buffer-process buf)))
                       (string-match-p "chatgpt" (process-name proc))))
                   (buffer-list)))
         (names (mapcar #'buffer-name buffers))
         (selected (and names (completing-read "ChatGPT buffer: " names nil t))))
    (if selected
        (switch-to-buffer selected)
      (message "No active ChatGPT shell buffers"))))

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants