emacs/lisp/acdw-eww.el

39 lines
1.2 KiB
EmacsLisp

;;; 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