diff options
| author | Ivan Shmakov | 2014-11-19 18:21:58 +0100 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2014-11-19 18:21:58 +0100 |
| commit | 7d77dc18c7a3040fc565680bc1e2785f6db2c09f (patch) | |
| tree | b1eff7cb8b5cde76055ed9787a319fa66d2f299d | |
| parent | e9917c08dce94e0ff92b0b202c9f5a4dd3231d22 (diff) | |
| download | emacs-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/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/net/eww.el | 121 |
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 @@ | |||
| 1 | 2014-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 | |||
| 1 | 2014-11-19 Eli Zaretskii <eliz@gnu.org> | 10 | 2014-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. | ||
| 70 | If non-nil, repetitive EWW history entries (comprising of the URI, the | ||
| 71 | title, and the point position) will not be saved as part of the Emacs | ||
| 72 | desktop. 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'. | ||
| 79 | If t or 'auto, the buffers will be reloaded automatically. | ||
| 80 | If nil, buffers will require manual reload, and will contain the text | ||
| 81 | specified in `eww-restore-reload-prompt' instead of the actual Web | ||
| 82 | page 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'. | ||
| 91 | This prompt will be used if `eww-restore-desktop' is nil. | ||
| 92 | |||
| 93 | The 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. | ||
| 1561 | Also 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. | ||
| 1588 | This list will contain, as :history, the list, whose first element is | ||
| 1589 | the value of `eww-data', and the tail is `eww-history'. | ||
| 1590 | |||
| 1591 | If `eww-desktop-remove-duplicates' is non-nil, duplicate | ||
| 1592 | entries (if any) will be removed from the list. | ||
| 1593 | |||
| 1594 | Only the properties listed in `eww-desktop-data-save' are included. | ||
| 1595 | Generally, 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. | ||
| 1606 | If `eww-restore-desktop' is t or 'auto, this function will also | ||
| 1607 | initiate the retrieval of the respective URI in the background. | ||
| 1608 | Otherwise, 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 |