:type 'string)
(defcustom eww-search-prefix "https://duckduckgo.com/html/?q="
- "Prefix URL to search engine"
+ "Prefix URL to search engine."
:version "24.4"
:group 'eww
:type 'string)
:group 'eww
:type 'string)
+;;;###autoload
(defcustom eww-suggest-uris
'(eww-links-at-point
url-get-url-at-point
(cond ((string-match-p "\\`file:/" url))
;; Don't mangle file: URLs at all.
((string-match-p "\\`ftp://" url)
- (user-error "FTP is not supported."))
+ (user-error "FTP is not supported"))
(t
;; Anything that starts with something that vaguely looks
;; like a protocol designator is interpreted as a full URL.
;;;###autoload
(defun eww-open-file (file)
- "Render a file using EWW."
+ "Render FILE using EWW."
(interactive "fFile: ")
(eww (concat "file://"
(and (memq system-type '(windows-nt ms-dos))
;;;###autoload
(defun eww-search-words (&optional beg end)
- "Search the web for the text between the point and marker.
+ "Search the web for the text between BEG and END.
See the `eww-search-prefix' variable for the search engine used."
(interactive "r")
(eww (buffer-substring beg end)))
+(defun eww-html-p (content-type)
+ "Return non-nil if CONTENT-TYPE designates an HTML content type.
+Currently this means either text/html or application/xhtml+xml."
+ (member content-type '("text/html"
+ "application/xhtml+xml")))
+
(defun eww-render (status url &optional point buffer encode)
(let ((redirect (plist-get status :redirect)))
(when redirect
(charset (intern
(downcase
(or (cdr (assq 'charset (cdr content-type)))
- (eww-detect-charset (equal (car content-type)
- "text/html"))
+ (eww-detect-charset (eww-html-p (car content-type)))
"utf-8"))))
(data-buffer (current-buffer)))
;; Save the https peer status.
(string-match-p eww-use-external-browser-for-content-type
(car content-type)))
(eww-browse-with-external-browser url))
- ((equal (car content-type) "text/html")
+ ((eww-html-p (car content-type))
(eww-display-html charset url nil point buffer encode))
((equal (car content-type) "application/pdf")
(eww-display-pdf))
(form . eww-tag-form)
(input . eww-tag-input)
(textarea . eww-tag-textarea)
- (body . eww-tag-body)
(select . eww-tag-select)
(link . eww-tag-link)
(a . eww-tag-a))))
(replace-regexp-in-string "[ \t\r\n]+" " " (dom-text dom))))
(eww-update-header-line-format))
-(defun eww-tag-body (dom)
- (let* ((start (point))
- (fgcolor (or (dom-attr dom 'fgcolor) (dom-attr dom 'text)))
- (bgcolor (dom-attr dom 'bgcolor))
- (shr-stylesheet (list (cons 'color fgcolor)
- (cons 'background-color bgcolor))))
- (shr-generic dom)
- (shr-colorize-region start (point) fgcolor bgcolor)))
-
(defun eww-display-raw (buffer &optional encode)
(let ((data (buffer-substring (point) (point-max))))
(unless (buffer-live-p buffer)
(define-key map "H" 'eww-list-histories)
(define-key map "E" 'eww-set-character-encoding)
(define-key map "S" 'eww-list-buffers)
+ (define-key map "F" 'eww-toggle-fonts)
(define-key map "b" 'eww-add-bookmark)
(define-key map "B" 'eww-list-bookmarks)
map)
"Tool bar for `eww-mode'.")
+;; Autoload cookie needed by desktop.el.
+;;;###autoload
(define-derived-mode eww-mode special-mode "eww"
"Mode for browsing the web."
(setq-local eww-data (list :title ""))
(eww-browse-url url external)))))
(defun eww-same-page-p (url1 url2)
- "Return non-nil if both URLs represent the same page.
+ "Return non-nil if URL1 and URL2 represent the same page.
Differences in #targets are ignored."
(let ((obj1 (url-generic-parse-url url1))
(obj2 (url-generic-parse-url url2)))
(expand-file-name file directory)))
(defun eww-set-character-encoding (charset)
- "Set character encoding."
+ "Set character encoding to CHARSET.
+If CHARSET is nil then use UTF-8."
(interactive "zUse character set (default utf-8): ")
(if (null charset)
(eww-reload nil 'utf-8)
(eww-reload nil charset)))
+(defun eww-toggle-fonts ()
+ "Toggle whether to use monospaced or font-enabled layouts."
+ (interactive)
+ (message "Fonts are now %s"
+ (if (setq shr-use-fonts (not shr-use-fonts))
+ "on"
+ "off"))
+ (eww-reload))
+
;;; Bookmarks code
(defvar eww-bookmarks nil)
(defun eww-add-bookmark ()
- "Add the current page to the bookmarks."
+ "Bookmark the current page."
(interactive)
(eww-read-bookmarks)
(dolist (bookmark eww-bookmarks)
(when (equal (plist-get eww-data :url) (plist-get bookmark :url))
(user-error "Already bookmarked")))
- (if (y-or-n-p "bookmark this page? ")
- (progn
- (let ((title (replace-regexp-in-string "[\n\t\r]" " "
- (plist-get eww-data :title))))
- (setq title (replace-regexp-in-string "\\` +\\| +\\'" "" title))
- (push (list :url (plist-get eww-data :url)
- :title title
- :time (current-time-string))
- eww-bookmarks))
- (eww-write-bookmarks)
- (message "Bookmarked %s (%s)" (plist-get eww-data :url)
- (plist-get eww-data :title)))))
+ (when (y-or-n-p "Bookmark this page?")
+ (let ((title (replace-regexp-in-string "[\n\t\r]" " "
+ (plist-get eww-data :title))))
+ (setq title (replace-regexp-in-string "\\` +\\| +\\'" "" title))
+ (push (list :url (plist-get eww-data :url)
+ :title title
+ :time (current-time-string))
+ eww-bookmarks))
+ (eww-write-bookmarks)
+ (message "Bookmarked %s (%s)" (plist-get eww-data :url)
+ (plist-get eww-data :title))))
(defun eww-write-bookmarks ()
(with-temp-file (expand-file-name "eww-bookmarks" eww-bookmarks-directory)
(case eww-restore-desktop
((t auto) (eww (plist-get eww-data :url)))
((zerop (buffer-size))
- (insert (substitute-command-keys
- eww-restore-reload-prompt))))))
+ (let ((inhibit-read-only t))
+ (insert (substitute-command-keys
+ eww-restore-reload-prompt)))))))
;; .
(current-buffer)))