Autodetection of character encoding.
authorTim Vaughan <tgvaughan@gmail.com>
Thu, 20 Jun 2019 12:43:59 +0000 (14:43 +0200)
committerTim Vaughan <tgvaughan@gmail.com>
Thu, 20 Jun 2019 12:43:59 +0000 (14:43 +0200)
Can't detect koi8-r, but sadly there's not chardet
for emacs...

elpher.el

index 33804cf..e016e45 100644 (file)
--- 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)