unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#16225: 24.3.50; [PATCH] eww: machinery to set character encoding.
@ 2013-12-23 15:38 Kenjiro NAKAYAMA
  2013-12-24  7:52 ` Lars Ingebrigtsen
  2014-11-22 17:36 ` bug#16225: [PATCH]eww: " Kenjiro Nakayama
  0 siblings, 2 replies; 10+ messages in thread
From: Kenjiro NAKAYAMA @ 2013-12-23 15:38 UTC (permalink / raw)
  To: 16225

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@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





^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2014-11-24 15:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-23 15:38 bug#16225: 24.3.50; [PATCH] eww: machinery to set character encoding Kenjiro NAKAYAMA
2013-12-24  7:52 ` Lars Ingebrigtsen
2013-12-25  7:32   ` Kenjiro NAKAYAMA
2013-12-25  8:58     ` Lars Ingebrigtsen
2014-11-10 21:39       ` Lars Magne Ingebrigtsen
2014-11-22 17:25         ` Nakayama Kenjiro
2014-11-22 17:36 ` bug#16225: [PATCH]eww: " Kenjiro Nakayama
2014-11-23 15:31   ` Lars Magne Ingebrigtsen
2014-11-23 18:24   ` bug#16225: eww: " Ivan Shmakov
2014-11-24 15:59     ` Lars Magne Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).