From: Ivan Shmakov <ivan@siamics.net>
To: 18010@debbugs.gnu.org
Subject: bug#18010: eww: desktop support
Date: Wed, 19 Nov 2014 10:24:26 +0000 [thread overview]
Message-ID: <87d28j7ajp.fsf@violet.siamics.net> (raw)
In-Reply-To: <m3ppcug2lj.fsf@stories.gnus.org> (Lars Magne Ingebrigtsen's message of "Mon, 10 Nov 2014 22:36:24 +0100")
[-- Attachment #1: Type: text/plain, Size: 467 bytes --]
>>>>> Lars Magne Ingebrigtsen <larsi@gnus.org> writes:
> Ivan, if you could respin this patch to apply to eww now, I'll apply
> it.
Please consider the patch MIMEd. Albeit I’ve 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.
--
FSF associate member #7257 http://boycottsystemd.org/ … 3013 B6A0 230E 334A
[-- Attachment #2: Type: text/plain, Size: 5170 bytes --]
--- 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
next prev parent reply other threads:[~2014-11-19 10:24 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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=87d28j7ajp.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).