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: Wed, 19 Nov 2014 10:24:26 +0000 Message-ID: <87d28j7ajp.fsf@violet.siamics.net> References: <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 1416392731 14221 80.91.229.3 (19 Nov 2014 10:25:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 19 Nov 2014 10:25:31 +0000 (UTC) To: 18010@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Nov 19 11:25:25 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 1Xr2Ru-0002XV-4p for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Nov 2014 11:25:22 +0100 Original-Received: from localhost ([::1]:57414 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr2Rt-0006yU-Ft for geb-bug-gnu-emacs@m.gmane.org; Wed, 19 Nov 2014 05:25:21 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr2Rg-0006ne-DL for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 05:25:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xr2Rb-00067s-Ci for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 05:25:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xr2Rb-000674-36 for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 05:25:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Xr2Ra-00061G-Hq for bug-gnu-emacs@gnu.org; Wed, 19 Nov 2014 05:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ivan Shmakov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 19 Nov 2014 10:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18010 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 18010-submit@debbugs.gnu.org id=B18010.141639268423108 (code B ref 18010); Wed, 19 Nov 2014 10:25:02 +0000 Original-Received: (at 18010) by debbugs.gnu.org; 19 Nov 2014 10:24:44 +0000 Original-Received: from localhost ([127.0.0.1]:37852 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xr2RE-00060a-MD for submit@debbugs.gnu.org; Wed, 19 Nov 2014 05:24:44 -0500 Original-Received: from fely.am-1.org ([78.47.74.50]:41364) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Xr2R9-00060N-1Z for 18010@debbugs.gnu.org; Wed, 19 Nov 2014 05:24:39 -0500 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:In-Reply-To:Date:Sender:References:Subject:To:From; bh=OvmiPaIFcd2QXWr34DvNLDAx9I0H5whdkSjseZ5NWXU=; b=edxhhHaeZmH9LKppTiFhUuyIsQkQc2dUXuU6wwiFZ0A5gpAQ0Bo6pQ4nd+js3O8L/TWwo0RX4oQmf+nPLezLKKZNDamE+Jk4s9XuHfMRdAvxIr4Z08kQ1xH/yAEYDWF64q8DzMXDvZLh14SL1zieiR5pvbqT1Pz4xv9E1hyvlhY=; Original-Received: from [2a02:2560:6d4:26ca::1:1d] (helo=violet.siamics.net) by fely.am-1.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Xr2R7-0002uY-Tv for 18010@debbugs.gnu.org; Wed, 19 Nov 2014 10:24:34 +0000 Original-Received: from localhost ([::1] helo=violet.siamics.net) by violet.siamics.net with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1Xr2R0-0005i9-V6 for 18010@debbugs.gnu.org; Wed, 19 Nov 2014 17:24:27 +0700 In-Reply-To: (Lars Magne Ingebrigtsen's message of "Mon, 10 Nov 2014 22:36:24 +0100") 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:96226 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable >>>>> Lars Magne Ingebrigtsen writes: > Ivan, if you could respin this patch to apply to eww now, I'll apply > it. Please consider the patch MIMEd. Albeit I=E2=80=99ve tested it only somewhat superficially, it does seem to work as intended. Beware of the line numbers being slightly offset, for I also have other patches applied to eww.el locally. --=20 FSF associate member #7257 http://boycottsystemd.org/ =E2=80=A6 3013 B6A0= 230E 334A --=-=-= Content-Type: text/plain Content-Disposition: inline --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -65,6 +65,36 @@ :group 'eww :type 'string) +(defcustom eww-desktop-remove-duplicates t + "Whether to remove duplicates from the history when saving desktop data. +If non-nil, repetitive EWW history entries (comprising of the URI, the +title, and the point position) will not be saved as part of the Emacs +desktop. Otherwise, such entries will be retained." + :version "24.4" + :group 'eww + :type 'boolean) + +(defcustom eww-restore-desktop nil + "How to restore EWW buffers on `desktop-restore'. +If t or 'auto, the buffers will be reloaded automatically. +If nil, buffers will require manual reload, and will contain the text +specified in `eww-restore-reload-prompt' instead of the actual Web +page contents." + :version "24.4" + :group 'eww + :type '(choice (const :tag "Restore all automatically" t) + (const :tag "Require manual reload" nil))) + +(defcustom eww-restore-reload-prompt + "\n\n *** Use \\[eww-reload] to reload this buffer. ***\n" + "The string to put in the buffers not reloaded on `desktop-restore'. +This prompt will be used if `eww-restore-desktop' is nil. + +The string will be passed through `substitute-command-keys'." + :version "24.4" + :group 'eww + :type 'string) + (defcustom eww-use-external-browser-for-content-type "\\`\\(video/\\|audio/\\|application/ogg\\)" "Always use external browser for specified content-type." @@ -583,6 +633,8 @@ define-derived-mode eww-mode nil "eww" (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)) @@ -611,12 +660,15 @@ (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)) - (goto-char (plist-get elem :point)) + (let ((inhibit-read-only t) + (text (plist-get elem :text))) (setq eww-data elem) - (eww-update-header-line-format))) + (if (null text) + (eww-reload) ; FIXME: restore :point? + (erase-buffer) + (insert text) + (goto-char (plist-get elem :point)) + (eww-update-header-line-format)))) (defun eww-next-url () "Go to the page marked `next'. @@ -1518,6 +1585,82 @@ (setq buffer-read-only t truncate-lines t)) +;;; Desktop support + +(defvar eww-desktop-data-save + '(:url :title :point) + "List of `eww-data' properties to preserve in the desktop file. +Also used when saving `eww-history'.") + +(defun eww-desktop-data-1 (alist) + (let ((acc nil) + (tail alist)) + (while tail + (let ((k (car tail)) + (v (cadr tail))) + (when (memq k eww-desktop-data-save) + (setq acc (cons k (cons v acc))))) + (setq tail (cddr tail))) + acc)) + +(defun eww-desktop-history-duplicate (a b) + (let ((tail a) (r t)) + (while tail + (if (or (memq (car tail) '(:point)) ; ignore :point + (equal (cadr tail) + (plist-get b (car tail)))) + (setq tail (cddr tail)) + (setq tail nil + r nil))) + ;; . + r)) + +(defun eww-desktop-misc-data (directory) + "Return a property list with data used to restore eww buffers. +This list will contain, as :history, the list, whose first element is +the value of `eww-data', and the tail is `eww-history'. + +If `eww-desktop-remove-duplicates' is non-nil, duplicate +entries (if any) will be removed from the list. + +Only the properties listed in `eww-desktop-data-save' are included. +Generally, the list should not include the (usually overly large) +:dom, :source and :text properties." + (let ((history (mapcar 'eww-desktop-data-1 + (cons eww-data eww-history)))) + (list :history (if eww-desktop-remove-duplicates + (remove-duplicates + history :test 'eww-desktop-history-duplicate) + history)))) + +(defun eww-restore-desktop (file-name buffer-name misc-data) + "Restore an eww buffer from its desktop file record. +If `eww-restore-desktop' is t or 'auto, this function will also +initiate the retrieval of the respective URI in the background. +Otherwise, the restored buffer will contain a prompt to do so by using +\\[eww-reload]." + (with-current-buffer (get-buffer-create buffer-name) + (eww-mode) + ;; NB: eww-history, eww-data are buffer-local per (eww-mode) + (setq eww-history (cdr (plist-get misc-data :history)) + eww-data (or (car (plist-get misc-data :history)) + ;; backwards compatibility + (list :url (plist-get misc-data :uri)))) + (unless file-name + (when (plist-get eww-data :url) + (case eww-restore-desktop + ((t auto) (eww (plist-get eww-data :url))) + ((zerop (buffer-size)) + (insert (substitute-command-keys + eww-restore-reload-prompt)))))) + ;; . + (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 --=-=-=--