GNU bug report logs -
#16225
24.3.50; [PATCH] eww: machinery to set character encoding.
Previous Next
Reported by: Kenjiro NAKAYAMA <nakayamakenjiro <at> gmail.com>
Date: Mon, 23 Dec 2013 15:39:03 UTC
Severity: normal
Tags: fixed, patch
Found in version 24.3.50
Fixed in version 25.1
Done: Lars Magne Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
This report includes a patch to the bug. Please, review and install it
to the official tree if appreciated.
The user can't change encoding type. This patch is to fix it.
Signed-off-by: Kenjiro NAKAYAMA <nakayamakenjiro <at> gmail.com>
* net/eww.el (eww-character-encoding): Default value of encoding type.
(eww-display-html,eww-display-raw): Change to enable to set
encoding type.
(eww-mode-map): New key map and easy-menu to set encoding type.
(eww-set-character-encoding): New funtion to set encoding type.
---
lisp/net/eww.el | 33 +++++++++++++++++++++++++++------
1 file changed, 27 insertions(+), 6 deletions(-)
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index 89a7eb9..9353b6e 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -129,6 +129,7 @@ See also `eww-form-checkbox-selected-symbol'."
(defvar eww-home-url nil)
(defvar eww-start-url nil)
(defvar eww-contents-url nil)
+(defvar eww-character-encoding 'utf-8)
(defvar eww-local-regex "localhost"
"When this regex is found in the URL, it's not a keyword but an address.")
@@ -189,7 +190,7 @@ word(s) will be searched for via `eww-search-prefix'."
(or (cdr (assq 'charset (cdr content-type)))
(eww-detect-charset (equal (car content-type)
"text/html"))
- "utf8"))))
+ "utf-8"))))
(data-buffer (current-buffer)))
(unwind-protect
(progn
@@ -243,9 +244,9 @@ word(s) will be searched for via `eww-search-prefix'."
(defun eww-display-html (charset url &optional document point)
(or (fboundp 'libxml-parse-html-region)
(error "This function requires Emacs to be compiled with libxml2"))
- (unless (eq charset 'utf8)
+ (unless (eq charset eww-character-encoding)
(condition-case nil
- (decode-coding-region (point) (point-max) charset)
+ (decode-coding-region (point) (point-max) eww-character-encoding)
(coding-system-error nil)))
(let ((document
(or document
@@ -364,7 +365,12 @@ word(s) will be searched for via `eww-search-prefix'."
(let ((data (buffer-substring (point) (point-max))))
(eww-setup-buffer)
(let ((inhibit-read-only t))
- (insert data))
+ (insert data)
+ (unless (eq eww-character-encoding 'utf-8)
+ (encode-coding-region (point-min) (1+ (length data)) 'utf-8)
+ (condition-case nil
+ (decode-coding-region (point-min) (1+ (length data)) eww-character-encoding)
+ (coding-system-error nil))))
(goto-char (point-min))))
(defun eww-display-image ()
@@ -417,6 +423,7 @@ word(s) will be searched for via `eww-search-prefix'."
(define-key map "C" 'url-cookie-list)
(define-key map "v" 'eww-view-source)
(define-key map "H" 'eww-list-histories)
+ (define-key map "E" 'eww-set-character-encoding)
(define-key map "b" 'eww-add-bookmark)
(define-key map "B" 'eww-list-bookmarks)
@@ -439,7 +446,8 @@ word(s) will be searched for via `eww-search-prefix'."
["List histories" eww-list-histories t]
["Add bookmark" eww-add-bookmark t]
["List bookmarks" eww-list-bookmarks t]
- ["List cookies" url-cookie-list t]))
+ ["List cookies" url-cookie-list t]
+ ["Character Encoding" eww-set-character-encoding]))
map))
(defvar eww-tool-bar-map
@@ -1029,7 +1037,7 @@ If EXTERNAL, browse the URL using `shr-external-browser'."
((and (url-target (url-generic-parse-url url))
(eww-same-page-p url eww-current-url))
(eww-save-history)
- (eww-display-html 'utf8 url eww-current-dom))
+ (eww-display-html eww-character-encoding url eww-current-dom))
(t
(eww-browse-url url)))))
@@ -1080,6 +1088,19 @@ Differences in #targets are ignored."
(setq count (1+ count)))
(expand-file-name file directory)))
+(defun eww-set-character-encoding (encode)
+ "Set character encoding."
+ (interactive "sSet Character Encoding (default utf-8): ")
+ (cond ((zerop (length encode))
+ (setq eww-character-encoding 'utf-8)
+ (message "The change will take effect next load."))
+ (t
+ (if (not (coding-system-p (car (read-from-string encode))))
+ (user-error "Invalid encodeing type.")
+ (setq eww-character-encoding (car (read-from-string encode)))
+ (message "The change will take effect next load.")
+ ))))
+
;;; Bookmarks code
(defvar eww-bookmarks nil)
--
1.8.3.1
This bug report was last modified 10 years and 240 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.