all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ted Zlatanov <tzz@lifelogs.com>
To: emacs-devel@gnu.org
Subject: eww: display page source (was: eww.el: Patch to cache the parse tree)
Date: Wed, 04 Dec 2013 11:46:54 -0500	[thread overview]
Message-ID: <87siu81s3l.fsf_-_@flea.lifelogs.com> (raw)
In-Reply-To: m31u1w7m1a.fsf@stories.gnus.org

[-- Attachment #1: Type: text/plain, Size: 227 bytes --]

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.

Thanks
Ted


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: eww-display-source.patch --]
[-- Type: text/x-diff, Size: 2605 bytes --]

=== 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 @@
 	     (list
 	      'base (list (cons 'href url))
 	      (libxml-parse-html-region (point) (point-max))))))
+    (setq eww-current-source (buffer-substring (point) (point-max)))
     (eww-setup-buffer)
     (setq eww-current-dom document)
     (let ((inhibit-read-only t)
@@ -375,6 +377,14 @@
   (unless (eq major-mode 'eww-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))
 	eww-history))
 
@@ -468,6 +482,7 @@
   (let ((inhibit-read-only t))
     (erase-buffer)
     (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)


  parent reply	other threads:[~2013-12-04 16:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-27 17:09 eww.el: Patch to cache the parse tree T.V. Raman
2013-11-30  1:08 ` T.V. Raman
2013-12-01 13:12 ` Lars Magne Ingebrigtsen
2013-12-03  3:09   ` T.V. Raman
2013-12-03  3:34   ` T.V. Raman
2013-12-14 16:27     ` Lars Magne Ingebrigtsen
2013-12-16  0:22       ` T.V. Raman
2013-12-16  0:24       ` T.V. Raman
2013-12-24 20:36         ` Lars Ingebrigtsen
2013-12-04 16:46   ` Ted Zlatanov [this message]
2013-12-05  1:37     ` eww: display page source Lars Magne Ingebrigtsen
2013-12-05 16:06       ` Ted Zlatanov
2013-12-14 16:26         ` Lars Magne Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87siu81s3l.fsf_-_@flea.lifelogs.com \
    --to=tzz@lifelogs.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.