From d7a6880805833d8b07caf4daa2b65b8abfe9f67b Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sun, 26 Dec 2021 22:49:25 -0600 Subject: Add +eww and further customize eww --- init.el | 11 ++++++++- lisp/+eww.el | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lisp/+modeline.el | 31 ++++++++++++------------ 3 files changed, 97 insertions(+), 16 deletions(-) create mode 100644 lisp/+eww.el diff --git a/init.el b/init.el index ab08e10..ddb755c 100644 --- a/init.el +++ b/init.el @@ -236,7 +236,16 @@ (setenv "PAGER" "cat"))) (setup eww - (:hook 'reading-mode)) + (:also-load +eww) + (:option eww-search-prefix "https://duckduckgo.com/html?q=" + url-privacy-level '(email agent cookies lastloc)) + (add-hook 'eww-after-render-hook 'reading-mode) + (:hook '+eww-bookmark-setup + '+eww-track-readable-mode) + (:bind "b" 'bookmark-set + "B" 'bookmark-jump + "M-n" nil + "M-p" nil)) (setup ibuffer (:also-load ibuf-ext) 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 @@ +;;; +eww.el -*- lexical-binding: t; -*- + +;;; Code: + +(require 'bookmark) +(require 'eww) + +;; Track whether the current page is readable + +(defvar-local +eww-readable-p nil + "Whether `eww-readable' has been toggled on the current buffer.") + +(defun +eww-mark-readable (&rest _) + "ADVICE to mark current eww buffer \"readable.\"" + (setq-local +eww-readable-p t)) + +(defun +eww-mark-unreadable (&rest _) + "ADVICE to mark current eww buffer \"unreadable.\"" + (setq-local +eww-readable-p nil)) + +(defvar +eww-readable-unreadable-after-functions '(eww-render + eww-reload + eww-back-url) + "Functions after which the page is rendered \"unreadable\".") + +;;;###autoload +(define-minor-mode +eww-track-readable-mode + "Track whether the current webpage has been rendered readable." + :lighter "" + (if +eww-track-readable-mode + (progn + (advice-add 'eww-readable :after #'+eww-mark-readable) + (dolist (func +eww-readable-unreadable-after-functions) + (advice-add func :after #'+eww-mark-unreadable))) + (dolist (func +eww-readable-unreadable-after-functions) + (advice-remove func #'+eww-mark-unreadable)) + (advice-remove 'eww-readable #'+eww-mark-readable))) + +;; Integrate bookmarks in eww + +(defun +eww-bookmark--make () + "Make eww bookmark record." + `((filename . ,(plist-get eww-data :url)) + (title . ,(plist-get eww-data :title)) + (time . ,(current-time-string)) + (handler . ,#'+eww-bookmark-handler) + (defaults . (,(concat + ;; url without the https and path + (replace-regexp-in-string + "/.*" "" + (replace-regexp-in-string + "\\`https?://" "" + (plist-get eww-data :url))) + " - " + ;; page title + (replace-regexp-in-string + "\\` +\\| +\\'" "" + (replace-regexp-in-string + "[\n\t\r ]+" " " + (plist-get eww-data :title)))))))) + +(defun +eww-bookmark-handler (bm) + "Handler for eww bookmarks." + (eww-browse-url (alist-get 'filename bm))) + +(defun +eww-bookmark-setup () + "Setup eww bookmark integration." + (setq-local bookmark-make-record-function #'eww-bookmark--make)) + +(provide '+eww) +;;; +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." "Display an indication that the buffer is in `reading-mode'." (when reading-mode (concat " " - (propertize "R" - 'help-echo (format "%s\n%s" - "Buffer is in reading-mode." - "mouse-2: disable reading-mode.") - 'local-map (purecopy - (simple-modeline-make-mouse-map - 'mouse-2 (lambda (ev) - (interactive "e") - (with-selected-window - (posn-window - (event-start ev)) - (reading-mode -1) - (force-mode-line-update))))) - 'face 'font-lock-doc-face - 'mouse-face 'mode-line-highlight)))) + (propertize + (concat "R" (when (bound-and-true-p +eww-readable-p) "w")) + 'help-echo (format "%s\n%s" + "Buffer is in reading-mode." + "mouse-2: disable reading-mode.") + 'local-map (purecopy + (simple-modeline-make-mouse-map + 'mouse-2 (lambda (ev) + (interactive "e") + (with-selected-window + (posn-window + (event-start ev)) + (reading-mode -1) + (force-mode-line-update))))) + 'face 'font-lock-doc-face + 'mouse-face 'mode-line-highlight)))) (define-minor-mode file-percentage-mode "Toggle the percentage display in the mode line (File Percentage Mode)." -- cgit 1.4.1-21-gabe81