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
827 stars 74 forks source link

Make display-buffer-alist configuration customizable #188

Closed DivineDominion closed 4 months ago

DivineDominion commented 10 months ago

Currently, the built-in display-buffer-alist settings are applied on the fly and thus put in front of the list -- so they always win:

https://github.com/xenodium/chatgpt-shell/blob/39dd8e7415ebe6d836a1d721337019cfea89f5ad/chatgpt-shell.el#L1182-L1188

This makes customization of e.g. the direction in which to display the buffer impossible.

WDYT about making the value a defcustom with a default of

             (cons (regexp-quote (buffer-name buffer))
                   '((display-buffer-reuse-window display-buffer-in-direction)
                     (dedicated . t)
                     (reusable-frames . visible)
                     (direction . left)
                     (window-width . 0.35)))

so users can use customize-variable for tweaks, and also nil to disable auto-setting this?

xenodium commented 10 months ago

WDYT about making the value a defcustom with a default of

We may have to make the defcustom accept a function, since it'd have to resolve "(regexp-quote (buffer-name buffer))" to the current buffer name. The challenge being that these buffers can change in name, specially if either chatgpt-shell-swap-model-version or chatgpt-shell-swap-system-prompt are invoked on the shell.

settings are applied on the fly and thus put in front of the list

What if we uniquely append instead? Would the user customization win?

DivineDominion commented 10 months ago

WDYT about making the value a defcustom with a default of

We may have to make the defcustom accept a function, since it'd have to resolve "(regexp-quote (buffer-name buffer))" to the current buffer name. The challenge being that these buffers can change in name, specially if either chatgpt-shell-swap-model-version or chatgpt-shell-swap-system-prompt are invoked on the shell.

Makes sense!

For what it's worth, I believe a regexp based matcher for ^*chatgpt* prefix and compose$ suffix would be enough for the built-in setting (it applies the same settings for all model versions anyway). And if users want to customize where 3.5-turbo is displayed, adding an alist item is simple enough (plus maybe disabling the default one)

What if we uniquely append instead? Would the user customization win?

To be honest, I believe that relying on the list position is a quick fix that works in the user configuration, but should not be the default behavior of a library (if we can help it) because it's so brittle! User customizations can change the list in many ways and then we have the same problem but for different reasons

xenodium commented 9 months ago

To be honest, I believe that relying on the list position is a quick fix that works in the user configuration

Sounds good. Let's go for something more explicit...

For what it's worth, I believe a regexp based matcher for ^chatgpt prefix and compose$ suffix would be enough for the built-in setting (it applies the same settings for all model versions anyway). And if users want to customize where 3.5->turbo is displayed, adding an alist item is simple enough (plus maybe disabling the default one)

Eventually, I'd like to make it much easier to support other llm backends by virtue of moving logic to shell-maker. If at all possible, I'd trying to stay away from adding chatgpt-specific logic if possible.

Lemme see if I can add the function-based option to shell-maker.

DivineDominion commented 9 months ago

This sounds like a sensible decision! Ping me if I can help in any way.

xenodium commented 9 months ago

Sorry for the delay.

It'll be quite some time until I rework the compose feature and move it to shell-maker, so better to remove the automatic entry in display-buffer-alist for the time being (e2073d9).

I think this should unblock ya?

DivineDominion commented 9 months ago

Thanks! Don't worry, I'm fine in my own setup

xenodium commented 4 months ago

While I haven't moved the compose functionality to shell-maker, the compose buffers do use their own major mode now, which simplifies display-buffer-alist usage. For example:

(add-to-list 'display-buffer-alist
             (cons '(major-mode . chatgpt-shell-prompt-compose-mode)
                   '((display-buffer-reuse-window
                      display-buffer-in-direction
                      display-buffer-select)
                     (reusable-frames . visible)
                     (direction . left)
                     (window-width . 0.35))))

I think this should hopefully address the original request to Make display-buffer-alist configuration customizable. Gonna close this issue, but please reopen if ya reckon there's something missing.

DivineDominion commented 4 months ago

Thank you! I'll play around with this.