summary refs log tree commit diff stats
path: root/lisp/+eww.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/+eww.el')
-rw-r--r--lisp/+eww.el71
1 files changed, 71 insertions, 0 deletions
diff --git a/lisp/+eww.el b/lisp/+eww.el new file mode 100644 index 0000000..aad602f --- /dev/null +++ b/lisp/+eww.el
@@ -0,0 +1,71 @@
1;;; +eww.el -*- lexical-binding: t; -*-
2
3;;; Code:
4
5(require 'bookmark)
6(require 'eww)
7
8;; Track whether the current page is readable
9
10(defvar-local +eww-readable-p nil
11 "Whether `eww-readable' has been toggled on the current buffer.")
12
13(defun +eww-mark-readable (&rest _)
14 "ADVICE to mark current eww buffer \"readable.\""
15 (setq-local +eww-readable-p t))
16
17(defun +eww-mark-unreadable (&rest _)
18 "ADVICE to mark current eww buffer \"unreadable.\""
19 (setq-local +eww-readable-p nil))
20
21(defvar +eww-readable-unreadable-after-functions '(eww-render
22 eww-reload
23 eww-back-url)
24 "Functions after which the page is rendered \"unreadable\".")
25
26;;;###autoload
27(define-minor-mode +eww-track-readable-mode
28 "Track whether the current webpage has been rendered readable."
29 :lighter ""
30 (if +eww-track-readable-mode
31 (progn
32 (advice-add 'eww-readable :after #'+eww-mark-readable)
33 (dolist (func +eww-readable-unreadable-after-functions)
34 (advice-add func :after #'+eww-mark-unreadable)))
35 (dolist (func +eww-readable-unreadable-after-functions)
36 (advice-remove func #'+eww-mark-unreadable))
37 (advice-remove 'eww-readable #'+eww-mark-readable)))
38
39;; Integrate bookmarks in eww
40
41(defun +eww-bookmark--make ()
42 "Make eww bookmark record."
43 `((filename . ,(plist-get eww-data :url))
44 (title . ,(plist-get eww-data :title))
45 (time . ,(current-time-string))
46 (handler . ,#'+eww-bookmark-handler)
47 (defaults . (,(concat
48 ;; url without the https and path
49 (replace-regexp-in-string
50 "/.*" ""
51 (replace-regexp-in-string
52 "\\`https?://" ""
53 (plist-get eww-data :url)))
54 " - "
55 ;; page title
56 (replace-regexp-in-string
57 "\\` +\\| +\\'" ""
58 (replace-regexp-in-string
59 "[\n\t\r ]+" " "
60 (plist-get eww-data :title))))))))
61
62(defun +eww-bookmark-handler (bm)
63 "Handler for eww bookmarks."
64 (eww-browse-url (alist-get 'filename bm)))
65
66(defun +eww-bookmark-setup ()
67 "Setup eww bookmark integration."
68 (setq-local bookmark-make-record-function #'eww-bookmark--make))
69
70(provide '+eww)
71;;; +eww.el ends here