karthink / gptel

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

gptel: Use save-excursion when major-mode is org-mode #112

Closed codeasone closed 8 months ago

codeasone commented 8 months ago

I was using gptel-mode when editing org-roam files and noticed point was moving to the top of the buffer on save, not returning to where I was last editing the file as expected

karthink commented 8 months ago

Hmm, I can't reproduce this. I already manage the excursion and restriction with org-with-wide-buffer when saving the buffer. This macro is included with Org:

(defmacro org-with-wide-buffer (&rest body)
  "Execute body while temporarily widening the buffer."
  (declare (debug (body)))
  `(save-excursion
     (save-restriction
       (widen)
       ,@body)))

But it looks like it's not working for you. Does adding an additional save-excursion on top fix it?

codeasone commented 8 months ago

I didn't realise org-with-wide-buffer was doing a save-excursion. That should be sufficient. I'll check I can repro the issue I was having without the details of my personal config muddying things, and get back to you shortly.

codeasone commented 8 months ago

@karthink I re-evaluated with a minimal dotemacs and couldn't reproduce the problem either, meaning it's an own goal related to the peculiarities of my broader configuration.

Apologies for not assessing that before raising the PR. Thank you for developing gptel it's fitting into my workflow really well!