bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#18010: eww: desktop support


From: Ivan Shmakov
Subject: bug#18010: eww: desktop support
Date: Sun, 13 Jul 2014 12:17:47 +0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

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’d
        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
        ‘reduce’ or ‘remove-if’ for property lists.  Alas, I didn’t find
        any existing function for that, so I coded it the explicit way.

-- 
FSF associate member #7257      http://boycottsystemd.org/
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

reply via email to

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