diff options
| author | Kenjiro Nakayama | 2014-11-23 16:30:40 +0100 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2014-11-23 16:30:40 +0100 |
| commit | 7f223a582e586f69e034981925db9ad70d9d6965 (patch) | |
| tree | d4934e0d1b845aba45fe7399b5116d596f6d9232 | |
| parent | b10d90066338c88a371fef1b59e2f455a37a3ba2 (diff) | |
| download | emacs-7f223a582e586f69e034981925db9ad70d9d6965.tar.gz emacs-7f223a582e586f69e034981925db9ad70d9d6965.zip | |
Allow setting the charset in eww
Fixes: debbugs:16225
* net/eww.el (eww-set-character-encoding): New command and keystroke.
(eww-display-raw): Use it.
| -rw-r--r-- | lisp/ChangeLog | 5 | ||||
| -rw-r--r-- | lisp/net/eww.el | 41 |
2 files changed, 34 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index b4e5b7954e3..79375078ae4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2014-11-23 Kenjiro Nakayama <nakayamakenjiro@gmail.com> | ||
| 2 | |||
| 3 | * net/eww.el (eww-set-character-encoding): New command and keystroke. | ||
| 4 | (eww-display-raw): Use it (bug#16225). | ||
| 5 | |||
| 1 | 2014-11-23 Lars Magne Ingebrigtsen <larsi@gnus.org> | 6 | 2014-11-23 Lars Magne Ingebrigtsen <larsi@gnus.org> |
| 2 | 7 | ||
| 3 | * net/nsm.el (network-security-level): Rename from | 8 | * net/nsm.el (network-security-level): Rename from |
diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 67466686aae..3c1621c0468 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el | |||
| @@ -241,7 +241,7 @@ See the `eww-search-prefix' variable for the search engine used." | |||
| 241 | (interactive "r") | 241 | (interactive "r") |
| 242 | (eww (buffer-substring beg end))) | 242 | (eww (buffer-substring beg end))) |
| 243 | 243 | ||
| 244 | (defun eww-render (status url &optional point buffer) | 244 | (defun eww-render (status url &optional point buffer encode) |
| 245 | (let ((redirect (plist-get status :redirect))) | 245 | (let ((redirect (plist-get status :redirect))) |
| 246 | (when redirect | 246 | (when redirect |
| 247 | (setq url redirect))) | 247 | (setq url redirect))) |
| @@ -255,7 +255,7 @@ See the `eww-search-prefix' variable for the search engine used." | |||
| 255 | (or (cdr (assq 'charset (cdr content-type))) | 255 | (or (cdr (assq 'charset (cdr content-type))) |
| 256 | (eww-detect-charset (equal (car content-type) | 256 | (eww-detect-charset (equal (car content-type) |
| 257 | "text/html")) | 257 | "text/html")) |
| 258 | "utf8")))) | 258 | "utf-8")))) |
| 259 | (data-buffer (current-buffer))) | 259 | (data-buffer (current-buffer))) |
| 260 | (unwind-protect | 260 | (unwind-protect |
| 261 | (progn | 261 | (progn |
| @@ -265,14 +265,14 @@ See the `eww-search-prefix' variable for the search engine used." | |||
| 265 | (car content-type))) | 265 | (car content-type))) |
| 266 | (eww-browse-with-external-browser url)) | 266 | (eww-browse-with-external-browser url)) |
| 267 | ((equal (car content-type) "text/html") | 267 | ((equal (car content-type) "text/html") |
| 268 | (eww-display-html charset url nil point buffer)) | 268 | (eww-display-html charset url nil point buffer encode)) |
| 269 | ((equal (car content-type) "application/pdf") | 269 | ((equal (car content-type) "application/pdf") |
| 270 | (eww-display-pdf)) | 270 | (eww-display-pdf)) |
| 271 | ((string-match-p "\\`image/" (car content-type)) | 271 | ((string-match-p "\\`image/" (car content-type)) |
| 272 | (eww-display-image buffer) | 272 | (eww-display-image buffer) |
| 273 | (eww-update-header-line-format)) | 273 | (eww-update-header-line-format)) |
| 274 | (t | 274 | (t |
| 275 | (eww-display-raw buffer) | 275 | (eww-display-raw buffer encode) |
| 276 | (eww-update-header-line-format))) | 276 | (eww-update-header-line-format))) |
| 277 | (plist-put eww-data :url url) | 277 | (plist-put eww-data :url url) |
| 278 | (setq eww-history-position 0) | 278 | (setq eww-history-position 0) |
| @@ -308,7 +308,7 @@ See the `eww-search-prefix' variable for the search engine used." | |||
| 308 | (declare-function libxml-parse-html-region "xml.c" | 308 | (declare-function libxml-parse-html-region "xml.c" |
| 309 | (start end &optional base-url)) | 309 | (start end &optional base-url)) |
| 310 | 310 | ||
| 311 | (defun eww-display-html (charset url &optional document point buffer) | 311 | (defun eww-display-html (charset url &optional document point buffer encode) |
| 312 | (or (fboundp 'libxml-parse-html-region) | 312 | (or (fboundp 'libxml-parse-html-region) |
| 313 | (error "This function requires Emacs to be compiled with libxml2")) | 313 | (error "This function requires Emacs to be compiled with libxml2")) |
| 314 | ;; There should be a better way to abort loading images | 314 | ;; There should be a better way to abort loading images |
| @@ -319,9 +319,9 @@ See the `eww-search-prefix' variable for the search engine used." | |||
| 319 | (list | 319 | (list |
| 320 | 'base (list (cons 'href url)) | 320 | 'base (list (cons 'href url)) |
| 321 | (progn | 321 | (progn |
| 322 | (unless (eq charset 'utf-8) | 322 | (unless (eq charset encode) |
| 323 | (condition-case nil | 323 | (condition-case nil |
| 324 | (decode-coding-region (point) (point-max) charset) | 324 | (decode-coding-region (point) (point-max) encode) |
| 325 | (coding-system-error nil))) | 325 | (coding-system-error nil))) |
| 326 | (libxml-parse-html-region (point) (point-max)))))) | 326 | (libxml-parse-html-region (point) (point-max)))))) |
| 327 | (source (and (null document) | 327 | (source (and (null document) |
| @@ -429,11 +429,16 @@ See the `eww-search-prefix' variable for the search engine used." | |||
| 429 | (shr-generic cont) | 429 | (shr-generic cont) |
| 430 | (shr-colorize-region start (point) fgcolor bgcolor))) | 430 | (shr-colorize-region start (point) fgcolor bgcolor))) |
| 431 | 431 | ||
| 432 | (defun eww-display-raw (&optional buffer) | 432 | (defun eww-display-raw (&optional buffer encode) |
| 433 | (let ((data (buffer-substring (point) (point-max)))) | 433 | (let ((data (buffer-substring (point) (point-max)))) |
| 434 | (eww-setup-buffer buffer) | 434 | (eww-setup-buffer buffer) |
| 435 | (let ((inhibit-read-only t)) | 435 | (let ((inhibit-read-only t)) |
| 436 | (insert data)) | 436 | (insert data) |
| 437 | (unless (eq encode 'utf-8) | ||
| 438 | (encode-coding-region (point-min) (1+ (length data)) 'utf-8) | ||
| 439 | (condition-case nil | ||
| 440 | (decode-coding-region (point-min) (1+ (length data)) encode) | ||
| 441 | (coding-system-error nil)))) | ||
| 437 | (goto-char (point-min)))) | 442 | (goto-char (point-min)))) |
| 438 | 443 | ||
| 439 | (defun eww-display-image (&optional buffer) | 444 | (defun eww-display-image (&optional buffer) |
| @@ -567,6 +572,7 @@ the like." | |||
| 567 | (define-key map "v" 'eww-view-source) | 572 | (define-key map "v" 'eww-view-source) |
| 568 | (define-key map "R" 'eww-readable) | 573 | (define-key map "R" 'eww-readable) |
| 569 | (define-key map "H" 'eww-list-histories) | 574 | (define-key map "H" 'eww-list-histories) |
| 575 | (define-key map "E" 'eww-set-character-encoding) | ||
| 570 | 576 | ||
| 571 | (define-key map "b" 'eww-add-bookmark) | 577 | (define-key map "b" 'eww-add-bookmark) |
| 572 | (define-key map "B" 'eww-list-bookmarks) | 578 | (define-key map "B" 'eww-list-bookmarks) |
| @@ -589,7 +595,8 @@ the like." | |||
| 589 | ["List histories" eww-list-histories t] | 595 | ["List histories" eww-list-histories t] |
| 590 | ["Add bookmark" eww-add-bookmark t] | 596 | ["Add bookmark" eww-add-bookmark t] |
| 591 | ["List bookmarks" eww-list-bookmarks t] | 597 | ["List bookmarks" eww-list-bookmarks t] |
| 592 | ["List cookies" url-cookie-list t])) | 598 | ["List cookies" url-cookie-list t] |
| 599 | ["Character Encoding" eww-set-character-encoding])) | ||
| 593 | map)) | 600 | map)) |
| 594 | 601 | ||
| 595 | (defvar eww-tool-bar-map | 602 | (defvar eww-tool-bar-map |
| @@ -700,12 +707,12 @@ appears in a <link> or <a> tag." | |||
| 700 | (eww-browse-url (shr-expand-url best-url (plist-get eww-data :url))) | 707 | (eww-browse-url (shr-expand-url best-url (plist-get eww-data :url))) |
| 701 | (user-error "No `top' for this page")))) | 708 | (user-error "No `top' for this page")))) |
| 702 | 709 | ||
| 703 | (defun eww-reload () | 710 | (defun eww-reload (&optional encode) |
| 704 | "Reload the current page." | 711 | "Reload the current page." |
| 705 | (interactive) | 712 | (interactive) |
| 706 | (let ((url (plist-get eww-data :url))) | 713 | (let ((url (plist-get eww-data :url))) |
| 707 | (url-retrieve url 'eww-render | 714 | (url-retrieve url 'eww-render |
| 708 | (list url (point) (current-buffer))))) | 715 | (list url (point) (current-buffer) encode)))) |
| 709 | 716 | ||
| 710 | ;; Form support. | 717 | ;; Form support. |
| 711 | 718 | ||
| @@ -1307,6 +1314,16 @@ Differences in #targets are ignored." | |||
| 1307 | (setq count (1+ count))) | 1314 | (setq count (1+ count))) |
| 1308 | (expand-file-name file directory))) | 1315 | (expand-file-name file directory))) |
| 1309 | 1316 | ||
| 1317 | (defun eww-set-character-encoding (encode) | ||
| 1318 | "Set character encoding." | ||
| 1319 | (interactive "sSet Character Encoding (default utf-8): ") | ||
| 1320 | (cond ((zerop (length encode)) | ||
| 1321 | (eww-reload 'utf-8)) | ||
| 1322 | (t | ||
| 1323 | (if (not (coding-system-p (intern encode))) | ||
| 1324 | (user-error "Invalid encodeing type.") | ||
| 1325 | (eww-reload (intern encode)))))) | ||
| 1326 | |||
| 1310 | ;;; Bookmarks code | 1327 | ;;; Bookmarks code |
| 1311 | 1328 | ||
| 1312 | (defvar eww-bookmarks nil) | 1329 | (defvar eww-bookmarks nil) |