xenodium / chatgpt-shell

ChatGPT and DALL-E Emacs shells + Org babel 🦄 + a shell maker for other providers
https://xenodium.com
GNU General Public License v3.0
825 stars 74 forks source link

Pop chatgpt shell into its own frame when not exists (with code and demo) #67

Closed tuhdo closed 1 year ago

tuhdo commented 1 year ago

Popping the shell onto another window disrupts the current workflow. It would be nice if there is an option to pop the shell to another frame instead: a frame named chatgpt is created if not exists, otherwise reuse that frame. I roughly implemented the feature:

(defun find-or-make-frame (fname)
    (condition-case
        nil
        (select-frame-by-name fname)
      (error (make-frame `((name . ,fname))))))
(defun display-chatgpt-shell-frame (bname)
    (let ((cur-f (selected-frame))
          (f (find-or-make-frame "chatgpt")))
      (select-frame-by-name "chatgpt")
      (pop-to-buffer-same-window bname)
      (set-frame-position f (/ (display-pixel-width) 2) 0)
      (set-frame-height f (frame-height cur-f))
      (set-frame-width f  (frame-width cur-f) 1)
      ))
   (setq shell-maker-display-function 'display-chatgpt-shell-frame)

It would be nice if this is refined and integrated into the package.

This is a really nice package.

Demo:

https://imgur.com/4GjJHnk

xenodium commented 1 year ago

Nice idea! Have you looked at setting chatgpt-shell-display-function? By default, it uses pop-to-buffer-same-window but could be something else?

tuhdo commented 1 year ago

Nice idea! Have you looked at setting chatgpt-shell-display-function? By default, it uses pop-to-buffer-same-window but could be something else?

I did code up a function to switch the shell in another frame, by default in the right half of your monitor:

(defun find-or-make-frame (fname)
    (condition-case
        nil
        (select-frame-by-name fname)
      (error (make-frame `((name . ,fname))))))
(defun display-chatgpt-shell-frame (bname)
    (let ((cur-f (selected-frame))
          (f (find-or-make-frame "chatgpt")))
      (select-frame-by-name "chatgpt")
      (pop-to-buffer-same-window bname)
      (set-frame-position f (/ (display-pixel-width) 2) 0)
      (set-frame-height f (frame-height cur-f))
      (set-frame-width f  (frame-width cur-f) 1)
      ))
   (setq shell-maker-display-function 'display-chatgpt-shell-frame)
xenodium commented 1 year ago

Ah sorry! I totally missed you using shell-maker-display-function. I blame reading from mobile ;-)

I'm thinking we can add the proposed function to the documentation as an example. I originally added the variable as someone had a different preference. The configuration option should be enough to cater for everyone's choice.

tuhdo commented 1 year ago

But it would be nice if users can simply set a variable, not pasting a whole function and bloat their config files.

xenodium commented 1 year ago

Hear ya. The sweet spot isn't always clear. The challenge is that we are a diverse bunch of emacsers, so if we add all proposed functions to the package, the bloat will take place in the package itself. The compromise here is to add customization points and emacsers can choose to customize based on their preference. Hope that makes sense.

xenodium commented 1 year ago

Added sample to README.

ps. Hey, you wrote that amazing helm guide! I'm on ivy these days, but was on helm for quite some time thanks to that guide.