diff options
author | Case Duckworth | 2021-12-26 22:49:25 -0600 |
---|---|---|
committer | Case Duckworth | 2021-12-26 22:49:41 -0600 |
commit | d7a6880805833d8b07caf4daa2b65b8abfe9f67b (patch) | |
tree | 7bdc84d39a44f452401d4aed513b9de93f6a52ac /lisp | |
parent | Add keybinding for `visible-mode' (diff) | |
download | emacs-d7a6880805833d8b07caf4daa2b65b8abfe9f67b.tar.gz emacs-d7a6880805833d8b07caf4daa2b65b8abfe9f67b.zip |
Add +eww and further customize eww
Diffstat (limited to 'lisp')
-rw-r--r-- | lisp/+eww.el | 71 | ||||
-rw-r--r-- | lisp/+modeline.el | 31 |
2 files changed, 87 insertions, 15 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 | ||
diff --git a/lisp/+modeline.el b/lisp/+modeline.el index 855ff50..5354e5b 100644 --- a/lisp/+modeline.el +++ b/lisp/+modeline.el | |||
@@ -115,21 +115,22 @@ The order of elements matters: whichever one matches first is applied." | |||
115 | "Display an indication that the buffer is in `reading-mode'." | 115 | "Display an indication that the buffer is in `reading-mode'." |
116 | (when reading-mode | 116 | (when reading-mode |
117 | (concat " " | 117 | (concat " " |
118 | (propertize "R" | 118 | (propertize |
119 | 'help-echo (format "%s\n%s" | 119 | (concat "R" (when (bound-and-true-p +eww-readable-p) "w")) |
120 | "Buffer is in reading-mode." | 120 | 'help-echo (format "%s\n%s" |
121 | "mouse-2: disable reading-mode.") | 121 | "Buffer is in reading-mode." |
122 | 'local-map (purecopy | 122 | "mouse-2: disable reading-mode.") |
123 | (simple-modeline-make-mouse-map | 123 | 'local-map (purecopy |
124 | 'mouse-2 (lambda (ev) | 124 | (simple-modeline-make-mouse-map |
125 | (interactive "e") | 125 | 'mouse-2 (lambda (ev) |
126 | (with-selected-window | 126 | (interactive "e") |
127 | (posn-window | 127 | (with-selected-window |
128 | (event-start ev)) | 128 | (posn-window |
129 | (reading-mode -1) | 129 | (event-start ev)) |
130 | (force-mode-line-update))))) | 130 | (reading-mode -1) |
131 | 'face 'font-lock-doc-face | 131 | (force-mode-line-update))))) |
132 | 'mouse-face 'mode-line-highlight)))) | 132 | 'face 'font-lock-doc-face |
133 | 'mouse-face 'mode-line-highlight)))) | ||
133 | 134 | ||
134 | (define-minor-mode file-percentage-mode | 135 | (define-minor-mode file-percentage-mode |
135 | "Toggle the percentage display in the mode line (File Percentage Mode)." | 136 | "Toggle the percentage display in the mode line (File Percentage Mode)." |