From e7cd2b92115ee3680956097dc835faafb67fa879 Mon Sep 17 00:00:00 2001 From: Tim Vaughan Date: Thu, 20 Jun 2019 14:43:59 +0200 Subject: [PATCH] Autodetection of character encoding. Can't detect koi8-r, but sadly there's not chardet for emacs... --- elpher.el | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/elpher.el b/elpher.el index 33804cf..e016e45 100644 --- a/elpher.el +++ b/elpher.el @@ -343,11 +343,16 @@ unless PRESERVE-PARENT is non-nil." ;;; Index rendering ;; +(defun elpher-decode (string) + "Return decoded STRING." + (let ((coding (detect-coding-string string t))) + (decode-coding-string string coding))) + (defun elpher-preprocess-text-response (string) "Clear away CRs and terminating period from STRING." (replace-regexp-in-string "\n\.\n$" "\n" (replace-regexp-in-string "\r" "" - string))) + (elpher-decode string)))) (defun elpher-insert-index (string) "Insert the index corresponding to STRING into the current buffer." @@ -389,6 +394,7 @@ unless PRESERVE-PARENT is non-nil." (elpher-address-host address) (elpher-address-port address))))) + (defun elpher-insert-index-record (display-string type selector host port) "Function to insert an index record into the current buffer. The contents of the record are dictated by TYPE, DISPLAY-STRING, SELECTOR, HOST @@ -445,6 +451,8 @@ The result is stored as a string in the variable ‘elpher-selector-string’." (make-network-process :name "elpher-process" :host (elpher-address-host address) :service (elpher-address-port address) + :coding 'no-conversion + :filter-multibyte nil :filter (lambda (proc string) (setq elpher-selector-string (concat elpher-selector-string string))) @@ -575,9 +583,7 @@ calls, as is necessary if the match is performed by `string-match'." (lambda (proc event) (unless (string-prefix-p "deleted" event) (let ((image (create-image - (encode-coding-string - elpher-selector-string - 'no-conversion) + elpher-selector-string nil t))) (elpher-with-clean-buffer (insert-image image) -- 2.20.1