]> git.eshelyaron.com Git - emacs.git/commitdiff
Make eww display PDFs inline
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 3 Nov 2014 19:39:08 +0000 (20:39 +0100)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Mon, 3 Nov 2014 19:39:08 +0000 (20:39 +0100)
* net/eww.el (eww-display-html): Clear `url-queue'.
(eww-display-pdf): New function.
(eww-render): Display PDFs with `doc-view'.

lisp/ChangeLog
lisp/net/eww.el

index ffea1b323ad88bf59f9ada13e7d554c639d1e611..4de1fe0fded14d74767b7d6550c6f26d1c0e7b1c 100644 (file)
@@ -1,3 +1,9 @@
+2014-11-03  Lars Magne Ingebrigtsen  <larsi@gnus.org>
+
+       * net/eww.el (eww-display-html): Clear `url-queue'.
+       (eww-display-pdf): New function.
+       (eww-render): Display PDFs with `doc-view'.
+
 2014-11-03  Yoni Rabkin <yrk@gnu.org>
 
        * net/eww.el (eww-list-bookmarks): Autoload.
index f319d68e1fb5c47cb522e11d2c97d1900249361d..9a97f02747fb818416dc1079b840d224c9f26e25 100644 (file)
@@ -214,6 +214,8 @@ word(s) will be searched for via `eww-search-prefix'."
             (eww-browse-with-external-browser url))
           ((equal (car content-type) "text/html")
            (eww-display-html charset url nil point))
+          ((equal (car content-type) "application/pdf")
+           (eww-display-pdf))
           ((string-match-p "\\`image/" (car content-type))
            (eww-display-image)
            (eww-update-header-line-format))
@@ -256,6 +258,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"))
+  ;; There should be a better way to abort loading images
+  ;; asynchronously.
+  (setq url-queue nil)
   (let ((document
         (or document
             (list
@@ -393,6 +398,16 @@ word(s) will be searched for via `eww-search-prefix'."
       (shr-put-image data nil))
     (goto-char (point-min))))
 
+(defun eww-display-pdf ()
+  (let ((data (buffer-substring (point) (point-max))))
+    (switch-to-buffer (get-buffer-create "*eww pdf*"))
+    (let ((coding-system-for-write 'raw-text)
+         (inhibit-read-only t))
+      (erase-buffer)
+      (insert data)
+      (doc-view-mode)))
+  (goto-char (point-min)))
+
 (defun eww-setup-buffer ()
   (switch-to-buffer (get-buffer-create "*eww*"))
   (let ((inhibit-read-only t))