From: Ivan Shmakov <ivan@siamics.net>
To: 18010@debbugs.gnu.org
Subject: bug#18010: eww: desktop support
Date: Sun, 13 Jul 2014 12:17:47 +0000 [thread overview]
Message-ID: <87bnst4fmc.fsf@violet.siamics.net> (raw)
[-- 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
next reply other threads:[~2014-07-13 12:17 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-13 12:17 Ivan Shmakov [this message]
2014-11-04 16:36 ` bug#18010: eww: desktop support 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bnst4fmc.fsf@violet.siamics.net \
--to=ivan@siamics.net \
--cc=18010@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).