aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Shmakov2014-11-19 18:21:58 +0100
committerLars Magne Ingebrigtsen2014-11-19 18:21:58 +0100
commit7d77dc18c7a3040fc565680bc1e2785f6db2c09f (patch)
treeb1eff7cb8b5cde76055ed9787a319fa66d2f299d
parente9917c08dce94e0ff92b0b202c9f5a4dd3231d22 (diff)
downloademacs-7d77dc18c7a3040fc565680bc1e2785f6db2c09f.tar.gz
emacs-7d77dc18c7a3040fc565680bc1e2785f6db2c09f.zip
Add desktop support to eww
* net/eww.el (eww-desktop-remove-duplicates) (eww-restore-desktop, eww-restore-reload-prompt): New variables. (eww-mode): Set up desktop mode. (eww-desktop-data-save, eww-desktop-data-1) (eww-desktop-history-duplicate, eww-desktop-misc-data) (eww-restore-desktop): New functions.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/net/eww.el121
2 files changed, 125 insertions, 5 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 0d1e9860ae1..b18dc417a89 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12014-11-19 Ivan Shmakov <ivan@siamics.net>
2
3 * net/eww.el (eww-desktop-remove-duplicates)
4 (eww-restore-desktop, eww-restore-reload-prompt): New variables.
5 (eww-mode): Set up desktop mode.
6 (eww-desktop-data-save, eww-desktop-data-1)
7 (eww-desktop-history-duplicate, eww-desktop-misc-data)
8 (eww-restore-desktop): New functions.
9
12014-11-19 Eli Zaretskii <eliz@gnu.org> 102014-11-19 Eli Zaretskii <eliz@gnu.org>
2 11
3 * vc/vc.el (vc-log-internal-common): Turn on log-view-mode in the 12 * vc/vc.el (vc-log-internal-common): Turn on log-view-mode in the
diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index fbac428b76f..dd449ff5e47 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -65,6 +65,36 @@
65 :group 'eww 65 :group 'eww
66 :type 'string) 66 :type 'string)
67 67
68(defcustom eww-desktop-remove-duplicates t
69 "Whether to remove duplicates from the history when saving desktop data.
70If non-nil, repetitive EWW history entries (comprising of the URI, the
71title, and the point position) will not be saved as part of the Emacs
72desktop. Otherwise, such entries will be retained."
73 :version "25.1"
74 :group 'eww
75 :type 'boolean)
76
77(defcustom eww-restore-desktop nil
78 "How to restore EWW buffers on `desktop-restore'.
79If t or 'auto, the buffers will be reloaded automatically.
80If nil, buffers will require manual reload, and will contain the text
81specified in `eww-restore-reload-prompt' instead of the actual Web
82page contents."
83 :version "25.1"
84 :group 'eww
85 :type '(choice (const :tag "Restore all automatically" t)
86 (const :tag "Require manual reload" nil)))
87
88(defcustom eww-restore-reload-prompt
89 "\n\n *** Use \\[eww-reload] to reload this buffer. ***\n"
90 "The string to put in the buffers not reloaded on `desktop-restore'.
91This prompt will be used if `eww-restore-desktop' is nil.
92
93The string will be passed through `substitute-command-keys'."
94 :version "25.1"
95 :group 'eww
96 :type 'string)
97
68(defcustom eww-use-external-browser-for-content-type 98(defcustom eww-use-external-browser-for-content-type
69 "\\`\\(video/\\|audio/\\|application/ogg\\)" 99 "\\`\\(video/\\|audio/\\|application/ogg\\)"
70 "Always use external browser for specified content-type." 100 "Always use external browser for specified content-type."
@@ -583,6 +613,8 @@ the like."
583 (setq-local eww-history-position 0) 613 (setq-local eww-history-position 0)
584 (when (boundp 'tool-bar-map) 614 (when (boundp 'tool-bar-map)
585 (setq-local tool-bar-map eww-tool-bar-map)) 615 (setq-local tool-bar-map eww-tool-bar-map))
616 ;; desktop support
617 (setq-local desktop-save-buffer 'eww-desktop-misc-data)
586 (buffer-disable-undo) 618 (buffer-disable-undo)
587 (setq buffer-read-only t)) 619 (setq buffer-read-only t))
588 620
@@ -611,12 +643,15 @@ the like."
611 (eww-restore-history (elt eww-history (1- eww-history-position)))) 643 (eww-restore-history (elt eww-history (1- eww-history-position))))
612 644
613(defun eww-restore-history (elem) 645(defun eww-restore-history (elem)
614 (let ((inhibit-read-only t)) 646 (let ((inhibit-read-only t)
615 (erase-buffer) 647 (text (plist-get elem :text)))
616 (insert (plist-get elem :text))
617 (goto-char (plist-get elem :point))
618 (setq eww-data elem) 648 (setq eww-data elem)
619 (eww-update-header-line-format))) 649 (if (null text)
650 (eww-reload) ; FIXME: restore :point?
651 (erase-buffer)
652 (insert text)
653 (goto-char (plist-get elem :point))
654 (eww-update-header-line-format))))
620 655
621(defun eww-next-url () 656(defun eww-next-url ()
622 "Go to the page marked `next'. 657 "Go to the page marked `next'.
@@ -1518,6 +1553,82 @@ Differences in #targets are ignored."
1518 (setq buffer-read-only t 1553 (setq buffer-read-only t
1519 truncate-lines t)) 1554 truncate-lines t))
1520 1555
1556;;; Desktop support
1557
1558(defvar eww-desktop-data-save
1559 '(:url :title :point)
1560 "List of `eww-data' properties to preserve in the desktop file.
1561Also used when saving `eww-history'.")
1562
1563(defun eww-desktop-data-1 (alist)
1564 (let ((acc nil)
1565 (tail alist))
1566 (while tail
1567 (let ((k (car tail))
1568 (v (cadr tail)))
1569 (when (memq k eww-desktop-data-save)
1570 (setq acc (cons k (cons v acc)))))
1571 (setq tail (cddr tail)))
1572 acc))
1573
1574(defun eww-desktop-history-duplicate (a b)
1575 (let ((tail a) (r t))
1576 (while tail
1577 (if (or (memq (car tail) '(:point)) ; ignore :point
1578 (equal (cadr tail)
1579 (plist-get b (car tail))))
1580 (setq tail (cddr tail))
1581 (setq tail nil
1582 r nil)))
1583 ;; .
1584 r))
1585
1586(defun eww-desktop-misc-data (directory)
1587 "Return a property list with data used to restore eww buffers.
1588This list will contain, as :history, the list, whose first element is
1589the value of `eww-data', and the tail is `eww-history'.
1590
1591If `eww-desktop-remove-duplicates' is non-nil, duplicate
1592entries (if any) will be removed from the list.
1593
1594Only the properties listed in `eww-desktop-data-save' are included.
1595Generally, the list should not include the (usually overly large)
1596:dom, :source and :text properties."
1597 (let ((history (mapcar 'eww-desktop-data-1
1598 (cons eww-data eww-history))))
1599 (list :history (if eww-desktop-remove-duplicates
1600 (remove-duplicates
1601 history :test 'eww-desktop-history-duplicate)
1602 history))))
1603
1604(defun eww-restore-desktop (file-name buffer-name misc-data)
1605 "Restore an eww buffer from its desktop file record.
1606If `eww-restore-desktop' is t or 'auto, this function will also
1607initiate the retrieval of the respective URI in the background.
1608Otherwise, the restored buffer will contain a prompt to do so by using
1609\\[eww-reload]."
1610 (with-current-buffer (get-buffer-create buffer-name)
1611 (eww-mode)
1612 ;; NB: eww-history, eww-data are buffer-local per (eww-mode)
1613 (setq eww-history (cdr (plist-get misc-data :history))
1614 eww-data (or (car (plist-get misc-data :history))
1615 ;; backwards compatibility
1616 (list :url (plist-get misc-data :uri))))
1617 (unless file-name
1618 (when (plist-get eww-data :url)
1619 (case eww-restore-desktop
1620 ((t auto) (eww (plist-get eww-data :url)))
1621 ((zerop (buffer-size))
1622 (insert (substitute-command-keys
1623 eww-restore-reload-prompt))))))
1624 ;; .
1625 (current-buffer)))
1626
1627(add-to-list 'desktop-locals-to-save
1628 'eww-history-position)
1629(add-to-list 'desktop-buffer-mode-handlers
1630 '(eww-mode . eww-restore-desktop))
1631
1521(provide 'eww) 1632(provide 'eww)
1522 1633
1523;;; eww.el ends here 1634;;; eww.el ends here