From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ivan Shmakov Newsgroups: gmane.emacs.bugs Subject: bug#18010: eww: desktop support Date: Sun, 13 Jul 2014 12:17:47 +0000 Message-ID: <87bnst4fmc.fsf@violet.siamics.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1405254026 15769 80.91.229.3 (13 Jul 2014 12:20:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 13 Jul 2014 12:20:26 +0000 (UTC) To: 18010@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jul 13 14:20:20 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1X6IlO-0000Rb-4v for geb-bug-gnu-emacs@m.gmane.org; Sun, 13 Jul 2014 14:20:18 +0200 Original-Received: from localhost ([::1]:52113 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6IlN-0002GI-Mg for geb-bug-gnu-emacs@m.gmane.org; Sun, 13 Jul 2014 08:20:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6IlF-0002Fz-5I for bug-gnu-emacs@gnu.org; Sun, 13 Jul 2014 08:20:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X6Il9-00029C-4p for bug-gnu-emacs@gnu.org; Sun, 13 Jul 2014 08:20:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58286) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X6Il8-00027L-Nx for bug-gnu-emacs@gnu.org; Sun, 13 Jul 2014 08:20:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1X6Il8-0007fY-8I for bug-gnu-emacs@gnu.org; Sun, 13 Jul 2014 08:20:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 13 Jul 2014 12:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 18010 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: submit@debbugs.gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.140525395829414 (code B ref -1); Sun, 13 Jul 2014 12:20:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 13 Jul 2014 12:19:18 +0000 Original-Received: from localhost ([127.0.0.1]:53552 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X6IkP-0007eJ-BN for submit@debbugs.gnu.org; Sun, 13 Jul 2014 08:19:17 -0400 Original-Received: from fely.am-1.org ([78.47.74.50]:46944) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1X6IkM-0007eB-Ag for submit@debbugs.gnu.org; Sun, 13 Jul 2014 08:19:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=siamics.net; s=a2013295; h=Content-Type:MIME-Version:Message-ID:Date:Sender:Subject:To:From; bh=X+iRDD/ZTYVik1zoiTeO8f8ol+kkliDVVQReLNOJ+/E=; b=gh84CEh5hLR5ARUmU9cyiGxRO2H5yeUZJZGIwdXhvF8sKjb4mE1v9l+lKTeRCbgAisan5Sux6nhMIGbOUw294Hf/Rtdu52/3Nal6ATmLH42nGw69df6+ozogJidY6LpquOtb3RhPozPWS2qXdODa86vFS8W+Gd4NLGLlvgEfNfA=; Original-Received: from host-46-241-38-202.bbcustomer.zsttk.net ([46.241.38.202] helo=waterlily.siamics.net) by fely.am-1.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1X6IkK-0003v8-S2 for submit@debbugs.gnu.org; Sun, 13 Jul 2014 12:19:13 +0000 Original-Received: from [2a02:2560:6d4:26ca::1:1d] (helo=violet.siamics.net) by waterlily.siamics.net with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1X6Ik8-0002lQ-LH for submit@debbugs.gnu.org; Sun, 13 Jul 2014 19:19:00 +0700 Original-Received: from localhost ([::1] helo=violet.siamics.net) by violet.siamics.net with esmtp (Exim 4.80) (envelope-from ) id 1X6Iiy-0007Fd-9w for submit@debbugs.gnu.org; Sun, 13 Jul 2014 19:17:48 +0700 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:91502 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Package: emacs Severity: wishlist Tags: patch Control: block -1 by 16211 Control: tags 16211 + patch Assuming that #16211 is resolved, adding desktop support to EWW seems pretty natural. (Why, Info already has one.) One thing to save is, obviously, eww-current-url. The other is eww-history, but that has to be filtered for the overly bulky :text, :dom, and :source properties. The last part poses a problem, as eww-restore-history does /not/ currently handle the case where :text is missing. A possible solution is to use (eww-reload) if :text is nil. As a side effect, eww-current-source and eww-current-dom will also be set. Also, AIUI, for the EWW history facility to work properly, eww-history-position is also to be saved, which is possible via desktop-locals-to-save. For anyone eager to try, the patch I suggest is MIMEd. This change looks quite substantial to be copyrightable, so I=E2=80=99d like to explicitly disclaim copyright on it, as per CC0 Public Domain Dedication [0]. For the most part, eww-desktop-history-1 function is a kind of =E2=80=98reduce=E2=80=99 or =E2=80=98remove-if=E2=80=99 for property lists= . Alas, I didn=E2=80=99t find any existing function for that, so I coded it the explicit way. --=20 FSF associate member #7257 http://boycottsystemd.org/ --=-=-= Content-Type: text/x-diff Content-Disposition: inline diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 02fc575..f6ee185 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -479,6 +495,8 @@ word(s) will be searched for via `eww-search-prefix'." (setq-local eww-history-position 0) (when (boundp 'tool-bar-map) (setq-local tool-bar-map eww-tool-bar-map)) + ;; desktop support + (setq-local desktop-save-buffer 'eww-desktop-misc-data) (buffer-disable-undo) ;;(setq buffer-read-only t) ) @@ -514,15 +533,22 @@ word(s) will be searched for via `eww-search-prefix'." (eww-restore-history (elt eww-history (1- eww-history-position)))) (defun eww-restore-history (elem) - (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) - eww-current-title (plist-get elem :title)) - (eww-update-header-line-format))) + (let ((inhibit-read-only t) + (text (plist-get elem :text)) + (pos (plist-get elem :point))) + (setq eww-current-source (plist-get elem :source) + eww-current-dom (plist-get elem :dom) + eww-current-url (plist-get elem :url)) + (if (null text) + (eww-reload) + (erase-buffer) + (insert text) + (setq eww-current-title + (plist-get elem :title)) + (eww-update-header-line-format)) + ;; FIXME: pos may no longer match the contents if the page gets reloaded + (when pos + (goto-char pos)))) (defun eww-next-url () "Go to the page marked `next'. @@ -1343,6 +1371,48 @@ Differences in #targets are ignored." (setq buffer-read-only t truncate-lines t)) +;;; Desktop support + +(defvar eww-desktop-history-save + '(:url :title :point) + "List of `eww-history' values to preserve in the desktop file.") + +(defun eww-desktop-history-1 (alist) + (let ((acc nil) + (tail alist)) + (while tail + (let ((k (car tail)) + (v (cadr tail))) + (when (memq k eww-desktop-history-save) + (setq acc (cons k (cons v acc))))) + (setq tail (cddr tail))) + acc)) + +(defun eww-desktop-misc-data (directory) + "Return a property list with data used to restore eww buffers. +This list will contain the URI to browse as the :uri property, and, as +:history, a copy of eww-history with the (usually overly large) :dom, +:source and :text properties removed." + (list :history (mapcar 'eww-desktop-history-1 eww-history) + :uri eww-current-url)) + +(defun eww-restore-desktop (file-name buffer-name misc-data) + "Restore an eww buffer from its desktop file record." + (with-current-buffer (get-buffer-create buffer-name) + (eww-mode) + ;; NB: eww-history is buffer-local per (eww-mode) + (setq eww-history (plist-get :history misc-data)) + (unless file-name + (let ((uri (plist-get :uri misc-data))) + (when uri + (eww uri)))) + (current-buffer))) + +(add-to-list 'desktop-locals-to-save + 'eww-history-position) +(add-to-list 'desktop-buffer-mode-handlers + '(eww-mode . eww-restore-desktop)) + (provide 'eww) ;;; eww.el ends here --=-=-=--