-
Notifications
You must be signed in to change notification settings - Fork 174
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
Restore gptel-mode in chat buffers #491
Comments
I do this in my personal configuration: (defun my/gptel-mode-auto ()
"Ensure that this file opens with `gptel-mode' enabled."
(save-excursion
(modify-file-local-variable-prop-line
'eval nil 'delete)
(add-file-local-variable-prop-line
'eval '(and (fboundp 'gptel-mode) (gptel-mode 1)))))
(add-hook 'gptel-save-state-hook #'my/gptel-mode-auto) I haven't had any requests from users to be able to turn on gptel-mode automatically, so I haven't bothered. EDIT: the previous version I posted wasn't robust. |
For reasons unknown gptel no longer prepends a properties drawer when a chat buffer is saved. Any idea what might have changed. The hook is also not run any more. I don't think I've changed anything? If I open a buffer that has the properties drawer, it is read and the variables are used. If I remove the hook as you've defined it. the properties drawer is again run. I'm running gptel at commit 0ce1628. |
For reasons unknown gptel no longer prepends a properties drawer when a chat buffer is saved. Any idea what might have changed. The hook is also not run any more. I don't think I've changed anything?
There have been no changes to that code in over a month. Have you customized gptel-save-state-hook in some way?
|
It appears your original version was failing if a property line did not already exist at the point of saving.
I instrumented the function as (defun my/gptel-mode-auto ()
"Ensure that this file opens with `gptel-mode' enabled."
(message "Running my/gptel-mode-auto in buffer %s" (buffer-name))
(condition-case err
(save-excursion
(modify-file-local-variable-prop-line
'eval nil 'delete)
(add-file-local-variable-prop-line
'eval '(and (fboundp 'gptel-mode) (gptel-mode 1))))
(error (message "%S" err)))) which reported:
I modified the function as: (defun my/gptel-mode-auto ()
"Ensure that this file opens with `gptel-mode' enabled."
(save-excursion
(let ((enable-local-variables t)) ; Ensure we can modify local variables
(if (and (save-excursion
(goto-char (point-min))
(looking-at ".*-\\*-"))) ; If there's a -*- line
;; First remove any existing eval, then add the new one
(modify-file-local-variable-prop-line
'eval nil 'delete))
;; Always add our eval
(add-file-local-variable-prop-line
'eval '(and (fboundp 'gptel-mode) (gptel-mode 1)))))) This appears to work. It first enables local variable modification in the off chance that it's disabled, checks if there's a property line, and removes the eval variable if it exists, and then replaces it. This leaves any other properties in the property line unchanged. This is what I need as I use the property line to give the buffers a title unrelated to the file name. Hope this helps. |
Thank you. Could you add this to the wiki? I'm not inclined to include this in gptel yet, but in the meantime the wiki is a better place for it than this thread. |
When chat buffer is saved to a file, gptel prepends a properties drawer to capture the metadata for the chat. When the chat buffer is reopened, the mode will be org mode or markdown or whatever, based on the file suffix (presuming one save it that way). However, when opening a saved chat buffer, I generally want it to automatically be opened in gptel-mode.
If a mode line does not yet exist in the buffer, why not add one just before the PROPERTIES drawer when saving the chat buffer as follows:
This would ensure that the newly reopened chat buffer would be automatically opened in gptel-mode. This has another benefit as the content of the saved chat shows the purpose of the file which would otherwise only known by way of the file suffix.
The text was updated successfully, but these errors were encountered: