[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

eww: display page source (was: eww.el: Patch to cache the parse tree)

From: Ted Zlatanov
Subject: eww: display page source (was: eww.el: Patch to cache the parse tree)
Date: Wed, 04 Dec 2013 11:46:54 -0500
User-agent: Gnus/5.130008 (Ma Gnus v0.8) Emacs/24.3.50 (gnu/linux)

Lars, since you're in a generous mood ;)

Here's a patch to display the current page's HTML source.  Can you see
if it's acceptable?  I used the `eww-current-dom' code as a guide to
where to put the stateful data.


=== modified file 'lisp/net/eww.el'
--- lisp/net/eww.el     2013-12-03 04:54:17 +0000
+++ lisp/net/eww.el     2013-12-04 16:43:02 +0000
@@ -117,6 +117,7 @@
 (defvar eww-current-url nil)
 (defvar eww-current-dom nil)
+(defvar eww-current-source nil)
 (defvar eww-current-title ""
   "Title of current page.")
 (defvar eww-history nil)
@@ -247,6 +248,7 @@
              'base (list (cons 'href url))
              (libxml-parse-html-region (point) (point-max))))))
+    (setq eww-current-source (buffer-substring (point) (point-max)))
     (setq eww-current-dom document)
     (let ((inhibit-read-only t)
@@ -375,6 +377,14 @@
   (unless (eq major-mode 'eww-mode)
+(defun eww-view-source ()
+  (let ((buf (get-buffer-create "*eww-source*"))
+        (source eww-current-source))
+    (with-current-buffer buf
+      (delete-region (point-min) (point-max))
+      (insert (or eww-current-source "no source")))
+    (view-buffer buf)))
 (defvar eww-mode-map
   (let ((map (make-sparse-keymap)))
     (suppress-keymap map)
@@ -395,6 +405,7 @@
     (define-key map "d" 'eww-download)
     (define-key map "w" 'eww-copy-page-url)
     (define-key map "C" 'url-cookie-list)
+    (define-key map "v" 'eww-view-source)
     (define-key map "b" 'eww-add-bookmark)
     (define-key map "B" 'eww-list-bookmarks)
@@ -411,6 +422,7 @@
         :active (not (zerop eww-history-position))]
        ["Browse with external browser" eww-browse-with-external-browser t]
        ["Download" eww-download t]
+       ["View page source" eww-view-source]
        ["Copy page URL" eww-copy-page-url t]
        ["Add bookmark" eww-add-bookmark t]
        ["List bookmarks" eww-copy-page-url t]
@@ -424,6 +436,7 @@
   ;; FIXME?  This seems a strange default.
   (set (make-local-variable 'eww-current-url) 'author)
   (set (make-local-variable 'eww-current-dom) nil)
+  (set (make-local-variable 'eww-current-source) nil)
   (set (make-local-variable 'browse-url-browser-function) 'eww-browse-url)
   (set (make-local-variable 'after-change-functions) 'eww-process-text-input)
   (set (make-local-variable 'eww-history) nil)
@@ -437,6 +450,7 @@
              :title eww-current-title
              :point (point)
               :dom eww-current-dom
+              :source eww-current-source
              :text (buffer-string))
@@ -468,6 +482,7 @@
   (let ((inhibit-read-only t))
     (insert (plist-get elem :text))
+    (setq eww-current-source (plist-get elem :source))
     (setq eww-current-dom (plist-get elem :dom))
     (goto-char (plist-get elem :point))
     (setq eww-current-url (plist-get elem :url)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]