branch: elpa/gptel commit 4b505e72e9ad0cdbf800457996a4b85c6cb68519 Author: Kayomarz <kayom...@gmail.com> Commit: GitHub <nore...@github.com>
gptel: Set process coding to utf-8-unix explicitly (#754) gptel-curl.el (gptel-curl-get-response): Explicitly set the process coding system to `utf-8-unix' when reading output from subprocesses. This ensures correct handling of Unicode text and prevents encoding-related display issues. `utf-8-unix' was previously set explicitly only for Windows platforms. Now do it for non-windows platforms too. gptel.el (gptel--url-get-response): Same change, but using `set-buffer-file-coding-system'. This has to be set in the callback to `url-retrieve' and not immediately, as `url-retrieve' runs `zlib-decompress-region', which requires the buffer to be unibyte. --- gptel-curl.el | 8 ++++---- gptel.el | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gptel-curl.el b/gptel-curl.el index f8cfd0f05f..09a61324f1 100644 --- a/gptel-curl.el +++ b/gptel-curl.el @@ -135,10 +135,10 @@ the response is inserted into the current buffer after point." (stream (plist-get info :stream)) (process (apply #'start-process "gptel-curl" (gptel--temp-buffer " *gptel-curl*") "curl" args))) - (when (memq system-type '(windows-nt ms-dos)) - ;; Don't try to convert cr-lf to cr on Windows so that curl's "header size - ;; in bytes" stays correct - (set-process-coding-system process 'utf-8-unix 'utf-8-unix)) + ;; Don't try to convert cr-lf to cr on Windows so that curl's "header size + ;; in bytes" stays correct. Explicitly set utf-8 for non-win systems too, + ;; for cases when buffer coding system is not set to utf-8. + (set-process-coding-system process 'utf-8-unix 'utf-8-unix) (when (eq gptel-log-level 'debug) (gptel--log (mapconcat #'shell-quote-argument (cons "curl" args) " \\\n") "request Curl command" 'no-json)) diff --git a/gptel.el b/gptel.el index 1d1b47fbd9..1280fcaf91 100644 --- a/gptel.el +++ b/gptel.el @@ -2763,6 +2763,8 @@ the response is inserted into the current buffer after point." (if (functionp backend-url) (funcall backend-url) backend-url)) (lambda (_) + (set-buffer-multibyte t) + (set-buffer-file-coding-system 'utf-8-unix) (pcase-let ((`(,response ,http-status ,http-msg ,error) (gptel--url-parse-response backend info)) (buf (current-buffer)))