Index: sbbs.el ================================================================== --- sbbs.el +++ sbbs.el @@ -337,21 +337,47 @@ (delete-overlay o))) (setq sbbs--last-spoiler nil)))) ;; URL.EL CALLBACKS +(defun sbbs--fix-encoding () + "Convert the raw response after point to utf-8." + (save-excursion + ;; see http://textboard.org/prog/39/263 + (set-buffer-multibyte nil) + (while (search-forward-regexp + ;; rx generates a multibyte string, that confuses + ;; search-forward-regexp, therefore the regexp literal + ;; here + "[\x80-\xff]\\(\\(?:\\\\[0-7]\\{3\\}\\)+\\)" + nil t) + (let (new) + (goto-char (match-beginning 1)) + (while (< (point) (match-end 1)) + (push (string-to-number (buffer-substring + (+ (point) 1) + (+ (point) 4)) + 8) + new) + (forward-char 4)) + (replace-match (apply #'string (nreverse new)) + nil t nil 1)))) + (set-buffer-multibyte t) + (decode-coding-region (point) (point-max) + 'utf-8)) + (defun sbbs--board-loader (status buf) "Callback function for `url-retrieve' when loading board. Load results into buffer BUF. STATUS is used to check for errors." (when (buffer-live-p buf) (when (plist-get status :error) (error "Error while loading: %s" (cdr (plist-get status :error)))) - (decode-coding-region (point-min) (point-max) 'utf-8) (forward-paragraph) + (sbbs--fix-encoding) (let ((list (read (current-buffer)))) (kill-buffer) (with-current-buffer buf (let (ent) (dolist (thread list) @@ -377,11 +403,11 @@ (when (plist-get status :error) (error "Error while loading: %s" (cdr (plist-get status :error)))) (prog-mode) (forward-paragraph) - (decode-coding-region (point) (point-max) 'utf-8) + (sbbs--fix-encoding) (save-excursion (save-match-data (while (search-forward "#f" nil t) (unless (cadddr (syntax-ppss)) (replace-match "nil")))))