[emacs-w3m:13695] Re: stealing a code snippet

Katsumi Yamaoka <[email protected]> Mon, 09 Nov 2020 08:29:18 +0900
Newsgroups gmane.emacs.w3m
Organization Emacsen advocacy group
Message-ID <[email protected]>
In [emacs-w3m:13694]
On Fri, 06 Nov 2020 02:59:12 -0500, Boruch Baum wrote:
> (defun diredc--decode-hexlated-string (str)
[...]
>       (decode-coding-string
>         (buffer-string)
>         (with-coding-priority nil
>                (car (detect-coding-region (point-min) (point-max))))))))

`detect-coding-region' does it by analogy, so the result will
not necessarily be correct (especially if there are not many
characteristic bytes).  For example, it behaves as follows in
the Japanese locale on the Cygwin platform:

(with-temp-buffer
  (set-buffer-multibyte nil)
  (insert (encode-coding-string "あいうえお" 'euc-jp))
  (with-coding-priority nil
    (car (detect-coding-region (point-min) (point-max)))))
 => japanese-shift-jis

(decode-coding-string
 (encode-coding-string "あいうえお" 'euc-jp)
 'japanese-shift-jis)
 => "、「、、、ヲ、ィ、ェ"

Therefore, as for `url-unhex-string', the coding system used to
decode the result has to be given by the one that creates the
encoded bytes (web site?).  eww does so, and so emacs-w3m does.