From 910e982e3796faefd9cc248e2477596d01fb499a Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Mon, 27 Sep 2021 18:18:54 -0500 Subject: Add bookmarks to eww Like, regular ones. --- init.el | 37 ++++++++++++++++++++++--------------- lisp/acdw-eww.el | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 lisp/acdw-eww.el diff --git a/init.el b/init.el index 35172e3..0ace8a4 100644 --- a/init.el +++ b/init.el @@ -483,6 +483,7 @@ In short, DO NOT USE THIS FUNCTION!!!" (load (expand-file-name "eshell" user-emacs-directory)))))) (setup eww + (:also-load acdw-eww) (defvar-local eww-readable-p nil "Whether current buffer is in readable-mode.") (:option eww-search-prefix "https://duckduckgo.com/html?q=" @@ -497,23 +498,29 @@ In short, DO NOT USE THIS FUNCTION!!!" (advice-add 'eww-render :after #'eww@is-not-readable) (advice-add 'eww-back-url :after #'eww@is-not-readable) - (:hook #'reading-mode)) + (:hook #'reading-mode + (defun bookmark-eww--setup () + "Setup eww bookmark integration." + (setq-local bookmark-make-record-function #'bookmark-eww--make))) -(setup files - (:option - auto-save-file-name-transforms `((".*" ,(acdw/dir "auto-save/" t) t)) - auto-save-list-file-prefix (acdw/dir "auto-save-list/.saves-" t) - auto-save-interval 60 - auto-save-timeout 60 - auto-save-visited-interval auto-save-timeout - backup-by-copying t - backup-directory-alist `((".*" . ,(acdw/dir "backup/" t))) - delete-old-versions t - mode-require-final-newline 'visit-save - tramp-backup-directory-alist backup-directory-alist - vc-make-backup-files t - version-control t) + (:bind "b" #'bookmark-set + "B" #'bookmark-jump + "M-n" nil + "M-p" nil)) +(setup files + (:option auto-save-file-name-transforms `((".*" ,(acdw/dir "auto-save/" t) t)) + auto-save-list-file-prefix (acdw/dir "auto-save-list/.saves-" t) + auto-save-interval 60 + auto-save-timeout 60 + auto-save-visited-interval auto-save-timeout + backup-by-copying t + backup-directory-alist `((".*" . ,(acdw/dir "backup/" t))) + delete-old-versions t + mode-require-final-newline 'visit-save + tramp-backup-directory-alist backup-directory-alist + vc-make-backup-files t + version-control t) (auto-save-visited-mode +1)) (setup find-func diff --git a/lisp/acdw-eww.el b/lisp/acdw-eww.el new file mode 100644 index 0000000..8e7f42d --- /dev/null +++ b/lisp/acdw-eww.el @@ -0,0 +1,38 @@ +;;; acdw-eww.el --- EWW customizations -*- lexical-binding: t -*- + +(require 'bookmark) +(require 'eww) + +(defun bookmark-eww--make () + "Make eww bookmark record." + `((filename . ,(plist-get eww-data :url)) + (title . ,(plist-get eww-data :title)) + (time . ,(current-time-string)) + (handler . ,#'bookmark-eww-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 bookmark-eww-handler (bm) + "Handler for eww bookmarks." + (eww-browse-url (alist-get 'filename bm))) + +(defun bookmark-eww--setup () + "Setup eww bookmark integration." + (setq-local bookmark-make-record-function #'bookmark-eww--make)) + +(provide 'acdw-eww) +;;; acdw-eww.el ends here -- cgit 1.4.1-21-gabe81