branch: elpa/gptel
commit 79387687688214bc1416977470d6c7b65aee038b
Author: Karthik Chikmagalur <karthikchikmaga...@gmail.com>
Commit: Karthik Chikmagalur <karthikchikmaga...@gmail.com>

    gptel-rewrite: Don't turn on major-mode in rewrite buffer
    
    * gptel-rewrite.el (gptel--rewrite-callback): Don't turn on the
    major-mode in the rewrite buffer, as this can have too many
    unexpected side effects to manage (#722, #730).  Instead just set
    the major-mode symbol so post-rewrite-functions that use
    org-element (say) will work.  This will also cause issues, but
    these issues will be limited to `gptel-post-rewrite-functions'
    instead of stopping the whole rewrite process when an error
    occurs.
    
    Also demote errors in functions in `gptel-post-rewrite-functions'
    to make the rewrite process more robust.
---
 gptel-rewrite.el | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/gptel-rewrite.el b/gptel-rewrite.el
index f0affe66af..29a94a8dfe 100644
--- a/gptel-rewrite.el
+++ b/gptel-rewrite.el
@@ -396,9 +396,7 @@ INFO is the async communication channel for the rewrite 
request."
             (insert-buffer-substring buf (overlay-start ov) (overlay-end ov))
             (when (eq (char-before (point-max)) ?\n)
               (plist-put info :newline t))
-            (delay-mode-hooks (funcall (buffer-local-value 'major-mode buf)))
-           ;; message.el and possily others set these when entering the major 
mode. (#730)
-           (setq buffer-file-name nil buffer-auto-save-file-name nil)
+            (setq major-mode (buffer-local-value 'major-mode buf)) ;Don't turn 
on major-mode (#730, #722)
             (add-text-properties (point-min) (point-max) '(face shadow 
font-lock-face shadow))
             (goto-char (point-min)))
           (insert response)
@@ -421,7 +419,8 @@ INFO is the async communication channel for the rewrite 
request."
             (let ((inhibit-read-only t))
               (delete-region (point) (point-max))
               ;; Run post-rewrite-functions on rewritten text in its buffer
-              (run-hook-with-args 'gptel-post-rewrite-functions (point-min) 
(point-max))
+              (with-demoted-errors
+                  (run-hook-with-args 'gptel-post-rewrite-functions 
(point-min) (point-max)))
               (when (and (plist-get info :newline)
                          (not (eq (char-before (point-max)) ?\n)))
                 (insert "\n"))

Reply via email to