aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-12-20 16:10:01 -0200
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-12-20 16:10:01 -0200
commita56f77ba8d990e0bf0333b5b93b9cdd1bf55b33f (patch)
tree144199c14618255873f6ef5228e927ac72c195b3
parent0c380f42cf56e64d3b4446b6168fa8028760d8c5 (diff)
Handle utf-8 encoding the right way.
-rw-r--r--sx-question-print.el3
-rw-r--r--sx-request.el19
2 files changed, 12 insertions, 10 deletions
diff --git a/sx-question-print.el b/sx-question-print.el
index 2f07132..b58a84a 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -182,9 +182,6 @@ QUESTION must be a data structure returned by `json-read'."
(mapc #'sx-question-mode--print-section .answers))
(insert "\n\n ")
(insert-text-button "Write an Answer" :type 'sx-button-answer)
- ;; Display weird chars correctly
- (set-buffer-multibyte nil)
- (set-buffer-multibyte t)
;; Go up
(goto-char (point-min))
(sx-question-mode-next-section))
diff --git a/sx-request.el b/sx-request.el
index 9f2ecdb..1031ea7 100644
--- a/sx-request.el
+++ b/sx-request.el
@@ -136,13 +136,18 @@ the main content of the response is returned."
(delete-region (point-min) (point))
(buffer-string))))
(response-zipped-p (sx-encoding-gzipped-p data))
- (data (if (not response-zipped-p) data
- (if (fboundp 'zlib-decompress-region)
- (zlib-decompress-region (point-min) (point-max))
- (shell-command-on-region
- (point-min) (point-max)
- sx-request-unzip-program nil t))
- (buffer-string)))
+ (data
+ ;; Turn string of bytes into string of characters. See
+ ;; http://emacs.stackexchange.com/q/4100/50
+ (decode-coding-string
+ (if (not response-zipped-p) data
+ (if (fboundp 'zlib-decompress-region)
+ (zlib-decompress-region (point-min) (point-max))
+ (shell-command-on-region
+ (point-min) (point-max)
+ sx-request-unzip-program nil t))
+ (buffer-string))
+ 'utf-8 'nocopy))
;; @TODO should use `condition-case' here -- set
;; RESPONSE to 'corrupt or something
(response (with-demoted-errors "`json' error: %S"