(defcustom eww-restore-desktop nil
"How to restore EWW buffers on `desktop-restore'.
-If t or 'auto, the buffers will be reloaded automatically.
+If t or `auto', the buffers will be reloaded automatically.
If nil, buffers will require manual reload, and will contain the text
specified in `eww-restore-reload-prompt' instead of the actual Web
page contents."
;; en.wikipedia.org/wiki/Free software
(string-match "\\`[A-Za-z_]+\\.[A-Za-z._]+/" url)
(and (= (length (split-string url)) 1)
- (or (and (not (string-match-p "\\`[\"\'].*[\"\']\\'" url))
+ (or (and (not (string-match-p "\\`[\"'].*[\"']\\'" url))
(> (length (split-string url "[.:]")) 1))
(string-match eww-local-regex url))))
(progn
(or (cdr (assq 'charset (cdr content-type)))
(eww-detect-charset (eww-html-p (car content-type)))
"utf-8"))))
- (data-buffer (current-buffer)))
+ (data-buffer (current-buffer))
+ last-coding-system-used)
;; Save the https peer status.
(with-current-buffer buffer
(plist-put eww-data :peer (plist-get status :peer)))
((string-match-p "\\`image/" (car content-type))
(eww-display-image buffer))
(t
- (eww-display-raw buffer encode)))
+ (eww-display-raw buffer (or encode charset 'utf-8))))
(with-current-buffer buffer
(plist-put eww-data :url url)
(eww-update-header-line-format)
(setq eww-history-position 0)
+ (and last-coding-system-used
+ (set-buffer-file-coding-system last-coding-system-used))
(run-hooks 'eww-after-render-hook)))
(kill-buffer data-buffer))))
(list
'base (list (cons 'href url))
(progn
- (when (or (and encode
- (not (eq charset encode)))
- (not (eq charset 'utf-8)))
- (condition-case nil
- (decode-coding-region (point) (point-max)
- (or encode charset))
- (coding-system-error nil)))
+ (setq encode (or encode charset 'utf-8))
+ (condition-case nil
+ (decode-coding-region (point) (point-max) encode)
+ (coding-system-error nil))
(libxml-parse-html-region (point) (point-max))))))
(source (and (null document)
(buffer-substring (point) (point-max)))))
(let ((inhibit-read-only t))
(erase-buffer)
(insert data)
- (unless (eq encode 'utf-8)
- (encode-coding-region (point-min) (1+ (length data)) 'utf-8)
- (condition-case nil
- (decode-coding-region (point-min) (1+ (length data)) encode)
- (coding-system-error nil))))
+ (condition-case nil
+ (decode-coding-region (point-min) (1+ (length data)) encode)
+ (coding-system-error nil)))
(goto-char (point-min)))))
(defun eww-display-image (buffer)
(delete-region (point-min) (point-max))
(insert (or source "no source"))
(goto-char (point-min))
+ ;; Decode the source and set the buffer's encoding according
+ ;; to what the HTML source specifies in its 'charset' header,
+ ;; if any.
+ (let ((cs (find-auto-coding "" (point-max))))
+ (when (consp cs)
+ (setq cs (car cs))
+ (when (coding-system-p cs)
+ (decode-coding-region (point-min) (point-max) cs)
+ (setq buffer-file-coding-system last-coding-system-used))))
(when (fboundp 'html-mode)
(html-mode))))
(view-buffer buf)))
(defvar eww-mode-map
(let ((map (make-sparse-keymap)))
- (set-keymap-parent map special-mode-map)
(define-key map "g" 'eww-reload) ;FIXME: revert-buffer-function instead!
(define-key map "G" 'eww)
(define-key map [?\t] 'shr-next-link)
(unless (plist-get status :error)
(let* ((obj (url-generic-parse-url url))
(path (car (url-path-and-query obj)))
- (file (eww-make-unique-file-name (file-name-nondirectory path)
- eww-download-directory)))
+ (file (eww-make-unique-file-name
+ (eww-decode-url-file-name (file-name-nondirectory path))
+ eww-download-directory)))
(goto-char (point-min))
(re-search-forward "\r?\n\r?\n")
(write-region (point) (point-max) file)
(message "Saved %s" file))))
+(defun eww-decode-url-file-name (string)
+ (let* ((binary (url-unhex-string string))
+ (decoded
+ (decode-coding-string
+ binary
+ ;; Possibly set by `universal-coding-system-argument'.
+ (or coding-system-for-read
+ ;; RFC 3986 says that %AB stuff is utf-8.
+ (if (equal (decode-coding-string binary 'utf-8)
+ '(unicode))
+ 'utf-8
+ ;; But perhaps not.
+ (car (detect-coding-string binary))))))
+ (encodes (find-coding-systems-string decoded)))
+ (if (or (equal encodes '(undecided))
+ (memq (or file-name-coding-system
+ default-file-name-coding-system)
+ encodes))
+ decoded
+ ;; If we can't encode the decoded file name (due to language
+ ;; environment settings), then we return the original, hexified
+ ;; string.
+ string)))
+
(defun eww-make-unique-file-name (file directory)
(cond
((zerop (length file))
(setq file "!"))
((string-match "\\`[.]" file)
(setq file (concat "!" file))))
- (let ((count 1))
+ (let ((count 1)
+ (stem file)
+ (suffix ""))
+ (when (string-match "\\`\\(.*\\)\\([.][^.]+\\)" file)
+ (setq stem (match-string 1)
+ suffix (match-string 2)))
(while (file-exists-p (expand-file-name file directory))
- (setq file
- (if (string-match "\\`\\(.*\\)\\([.][^.]+\\)" file)
- (format "%s(%d)%s" (match-string 1 file)
- count (match-string 2 file))
- (format "%s(%d)" file count)))
+ (setq file (format "%s(%d)%s" stem count suffix))
(setq count (1+ count)))
(expand-file-name file directory)))
(setq start (point)
title (plist-get bookmark :title))
(when (> (length title) width)
- (setq title (substring title 0 width)))
+ (setq title (truncate-string-to-width title width)))
(insert (format format title (plist-get bookmark :url)) "\n")
(put-text-property start (1+ start) 'eww-bookmark bookmark))
(goto-char (point-min))))
(defvar eww-bookmark-mode-map
(let ((map (make-sparse-keymap)))
- (suppress-keymap map)
- (define-key map "q" 'quit-window)
(define-key map [(control k)] 'eww-bookmark-kill)
(define-key map [(control y)] 'eww-bookmark-yank)
(define-key map "\r" 'eww-bookmark-browse)
:active eww-bookmark-kill-ring]))
map))
-(define-derived-mode eww-bookmark-mode nil "eww bookmarks"
+(define-derived-mode eww-bookmark-mode special-mode "eww bookmarks"
"Mode for listing bookmarks.
\\{eww-bookmark-mode-map}"
(buffer-disable-undo)
- (setq buffer-read-only t
- truncate-lines t))
+ (setq truncate-lines t))
;;; History code
(defvar eww-history-mode-map
(let ((map (make-sparse-keymap)))
- (suppress-keymap map)
- (define-key map "q" 'quit-window)
(define-key map "\r" 'eww-history-browse)
;; (define-key map "n" 'next-error-no-select)
;; (define-key map "p" 'previous-error-no-select)
:active (get-text-property (line-beginning-position) 'eww-history)]))
map))
-(define-derived-mode eww-history-mode nil "eww history"
+(define-derived-mode eww-history-mode special-mode "eww history"
"Mode for listing eww-histories.
\\{eww-history-mode-map}"
(buffer-disable-undo)
- (setq buffer-read-only t
- truncate-lines t))
+ (setq truncate-lines t))
;;; eww buffers list
(defvar eww-buffers-mode-map
(let ((map (make-sparse-keymap)))
- (suppress-keymap map)
- (define-key map "q" 'quit-window)
(define-key map [(control k)] 'eww-buffer-kill)
(define-key map "\r" 'eww-buffer-select)
(define-key map "n" 'eww-buffer-show-next)
:active (get-text-property (line-beginning-position) 'eww-buffer)]))
map))
-(define-derived-mode eww-buffers-mode nil "eww buffers"
+(define-derived-mode eww-buffers-mode special-mode "eww buffers"
"Mode for listing buffers.
\\{eww-buffers-mode-map}"
(buffer-disable-undo)
- (setq buffer-read-only t
- truncate-lines t))
+ (setq truncate-lines t))
;;; Desktop support
(defun eww-restore-desktop (file-name buffer-name misc-data)
"Restore an eww buffer from its desktop file record.
-If `eww-restore-desktop' is t or 'auto, this function will also
+If `eww-restore-desktop' is t or `auto', this function will also
initiate the retrieval of the respective URI in the background.
Otherwise, the restored buffer will contain a prompt to do so by using
\\[eww-reload]."