karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.06k stars 116 forks source link

unexpected behavior when `(org-entry-get (point-min) "GPTEL_BOUNDS")` returns `nil` #98

Closed Elilif closed 11 months ago

Elilif commented 11 months ago

In gptel--restore-state, read will use the value of standard-input if (org-entry-get (point-min) "GPTEL_BOUNDS") returns nil. That will interrupt your workflow when you restore a lot of gptel buffers. Therefore, should we make adjustments to the code? For example:

(when-let ((bounds
                           (org-entry-get (point-min) "GPTEL_BOUNDS")))
                 (mapc (pcase-lambda (`(,beg . ,end))
                         (put-text-property beg end 'gptel 'response))
                       (read bounds))
                 (message "gptel chat restored."))

The same as in gptel--save-state

karthink commented 11 months ago

Thank you for spotting this bug -- I ran into it for the first time a couple of hours after your message!

Fixed in c0ffce08.

Elilif commented 11 months ago

@karthink Thank you for quick response.

The same problem also exists in gptel--save-state, beacuse (gptel--get-bounds) would return nil.

karthink commented 11 months ago

The same problem also exists in gptel--save-state, beacuse (gptel--get-bounds) would return nil.

I'm not sure I understand. It's fine for gptel--get-bounds to return nil, and desirable for that to be written into the Org file:

:PROPERTIES: :GPTEL_MODEL: gpt-3.5-turbo :GPTEL_BOUNDS: nil :END:

^ Do you foresee a problem with this?

Elilif commented 11 months ago

@karthink Sorry for my ambiguous comment. Here are steps to reproduce in emacs -Q:

  1. input the following code
    (add-to-list 'load-path "path-to/gptel/")
    (require 'gptel)
    (setq gptel-default-mode 'org-mode)
  2. M-x gptel RET
  3. M-: (gptel--save-state) RET

Then you will get (wrong-type-argument number-or-marker-p nil) error.

I guess the error is caused by (= (marker-position offset-marker) offset) when (gptel--get-bounds) returns nil.