unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#18010: eww: desktop support
@ 2014-07-13 12:17 Ivan Shmakov
  2014-11-04 16:36 ` Ted Zlatanov
  2014-11-10 21:24 ` Lars Magne Ingebrigtsen
  0 siblings, 2 replies; 22+ messages in thread
From: Ivan Shmakov @ 2014-07-13 12:17 UTC (permalink / raw)
  To: 18010

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

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/

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-diff, Size: 3233 bytes --]

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

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2015-02-16 19:12 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-13 12:17 bug#18010: eww: desktop support Ivan Shmakov
2014-11-04 16:36 ` Ted Zlatanov
2014-11-10 21:24 ` Lars Magne Ingebrigtsen
2014-11-10 21:32   ` Glenn Morris
2014-11-10 21:36     ` Lars Magne Ingebrigtsen
2014-11-19 10:24       ` Ivan Shmakov
2014-11-19 17:23         ` Lars Magne Ingebrigtsen
2014-11-19 20:17           ` Ivan Shmakov
2014-11-23 15:10           ` Ivan Shmakov
2014-11-23 15:44             ` Lars Magne Ingebrigtsen
2014-11-30 11:04           ` bug#19226: eww.el desktop support fixes: autoload eww-mode, use inhibit-read-only Ivan Shmakov
2014-11-30 19:57             ` Glenn Morris
2014-11-30 20:15               ` Ivan Shmakov
2014-12-01  2:22                 ` Glenn Morris
2014-12-01  5:59                   ` Ivan Shmakov
2014-12-01 13:52                     ` Stefan Monnier
2014-12-07 18:56                       ` Ivan Shmakov
2014-12-08  2:54                         ` Stefan Monnier
2014-12-09 19:45                           ` Ivan Shmakov
2014-12-10  0:35                             ` Stefan Monnier
2015-02-14 20:50             ` Ivan Shmakov
2015-02-16 19:12               ` Ivan Shmakov

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).