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