From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "T.V. Raman" Newsgroups: gmane.emacs.devel Subject: eww.el: Patch to cache the parse tree Date: Wed, 27 Nov 2013 09:09:05 -0800 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: ger.gmane.org 1385572149 20327 80.91.229.3 (27 Nov 2013 17:09:09 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 27 Nov 2013 17:09:09 +0000 (UTC) Cc: tv.raman.tv@gmail.com To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Nov 27 18:09:16 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Vlic0-0001vt-8N for ged-emacs-devel@m.gmane.org; Wed, 27 Nov 2013 18:09:16 +0100 Original-Received: from localhost ([::1]:36948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vlibz-0006AV-Mv for ged-emacs-devel@m.gmane.org; Wed, 27 Nov 2013 12:09:15 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55729) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vlibv-00067c-9S for emacs-devel@gnu.org; Wed, 27 Nov 2013 12:09:12 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vlibq-0000oR-9N for emacs-devel@gnu.org; Wed, 27 Nov 2013 12:09:11 -0500 Original-Received: from mail-oa0-x231.google.com ([2607:f8b0:4003:c02::231]:48534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vlibq-0000ns-37 for emacs-devel@gnu.org; Wed, 27 Nov 2013 12:09:06 -0500 Original-Received: by mail-oa0-f49.google.com with SMTP id i4so7883545oah.22 for ; Wed, 27 Nov 2013 09:09:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:cc:content-type; bh=vC02aF54BY18wRpS3uatYgaPRuHGsqkLJO+0qSp0pco=; b=oCRMqNF2ndBi5qmaMmYlS3kf/lDtY7ljh8cZ0aLplTOPnysmLizG7aQss/AovOI3Ct ctcWTd+eFmnUQXWHZRRQhNLpPi1cL69yh66f/GEdADNQrDf2rI0kIaWX5hUkMKD2zQbD w2Q8mo2Ic4LrSxx15q9XgQ47Q1YcN8fnMSQwOUK3RcgX9/jrgV4hw+rSvrot32s1S1Q7 CTZ+j+cIpCF7U74c2tCltHb2cmRezWqkXFVgkSOWS32x31TcQIih/M7VEK4Wzb9+JYhN SAIp4EWpgvqvo30/AA6ZQf7aPpHwrs0iNeGqoVqwcWfX1Dzvjvs1We+XwpSb6V1TTxVv d6kg== X-Received: by 10.182.213.97 with SMTP id nr1mr11463100obc.48.1385572145212; Wed, 27 Nov 2013 09:09:05 -0800 (PST) Original-Received: by 10.182.112.42 with HTTP; Wed, 27 Nov 2013 09:09:05 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c02::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:165804 Archived-At: Hi, I'd like to add some code to eww.el so that the parsed document is cached ( -- this will enable functionality such as document filtering etc (see http://emacspeak.googlecode.com/svn/trunk/lisp/shr-url.el) for similar functionality that I originally built using bare shr. Here is a patch against Master: git diff master diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 86e0977..a446a01 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -89,6 +89,9 @@ :group 'eww) (defvar eww-current-url nil) +(defvar eww-current-dom nil) +(make-variable-buffer-local 'eww-current-dom) + (defvar eww-current-title "" "Title of current page.") (defvar eww-history nil) @@ -208,6 +211,7 @@ word(s) will be searched for via `eww-search-prefix'." (start end &optional base-url)) (defun eww-display-html (charset url) + (declare (special eww-current-dom)) (or (fboundp 'libxml-parse-html-region) (error "This function requires Emacs to be compiled with libxml2")) (unless (eq charset 'utf8) @@ -219,6 +223,7 @@ word(s) will be searched for via `eww-search-prefix'." 'base (list (cons 'href url)) (libxml-parse-html-region (point) (point-max))))) (eww-setup-buffer) + (setq eww-current-dom document) (let ((inhibit-read-only t) (after-change-functions nil) (shr-width nil) @@ -387,9 +392,11 @@ word(s) will be searched for via `eww-search-prefix'." ) (defun eww-save-history () + (declare (special ew-current-dom)) (push (list :url eww-current-url :title eww-current-title :point (point) + :dom eww-current-dom :text (buffer-string)) eww-history)) @@ -427,6 +434,7 @@ word(s) will be searched for via `eww-search-prefix'." (let ((inhibit-read-only t)) (erase-buffer) (insert (plist-get elem :text)) + (setq eww-current-dom (plist-get elem :dom)) (goto-char (plist-get elem :point)) (setq eww-current-url (plist-get elem :url) eww-current-title (plist-get elem :title)))) 09:05:43 raman-glaptop net $ -- --