]> code.delx.au - gnu-emacs/blobdiff - lisp/net/eww.el
; Remove obsolete comment in tramp.el
[gnu-emacs] / lisp / net / eww.el
index b7ee0650d7080b120daf1fb0464b4a889336d46b..bda4e0cfec28455c9878e3ffce455400cec982fc 100644 (file)
@@ -49,7 +49,7 @@
   :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)
@@ -254,7 +254,7 @@ word(s) will be searched for via `eww-search-prefix'."
   (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.
@@ -263,7 +263,7 @@ word(s) will be searched for via `eww-search-prefix'."
                 ;; 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
@@ -292,7 +292,7 @@ word(s) will be searched for via `eww-search-prefix'."
 
 ;;;###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))
@@ -301,11 +301,17 @@ word(s) will be searched for via `eww-search-prefix'."
 
 ;;;###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
@@ -318,8 +324,7 @@ See the `eww-search-prefix' variable for the search engine used."
         (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.
@@ -332,7 +337,7 @@ See the `eww-search-prefix' variable for the search engine used."
                  (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))
@@ -374,7 +379,7 @@ See the `eww-search-prefix' variable for the search engine used."
             (match-string 1)))))
 
 (declare-function libxml-parse-html-region "xml.c"
-                 (start end &optional base-url))
+                 (start end &optional base-url discard-comments))
 
 (defun eww-display-html (charset url &optional document point buffer encode)
   (unless (fboundp 'libxml-parse-html-region)
@@ -622,7 +627,6 @@ the like."
 
 (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)
@@ -1363,7 +1367,7 @@ If EXTERNAL is double prefix, browse in new buffer."
       (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)))
@@ -1413,7 +1417,8 @@ Differences in #targets are ignored."
       (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)
@@ -1577,8 +1582,6 @@ Differences in #targets are ignored."
 
 (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)
@@ -1595,13 +1598,12 @@ Differences in #targets are ignored."
          :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
 
@@ -1664,8 +1666,6 @@ Differences in #targets are ignored."
 
 (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)
@@ -1678,13 +1678,12 @@ Differences in #targets are ignored."
          :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
 
@@ -1789,8 +1788,6 @@ Differences in #targets are ignored."
 
 (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)
@@ -1806,13 +1803,12 @@ Differences in #targets are ignored."
          :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