eww: Add `url' and `title' optional arguments to eww-add-bookmark

master
Pierre Neidhardt 2018-07-28 12:20:00 +02:00
parent c541fa0ab4
commit dbae48e80d
1 changed files with 7 additions and 6 deletions

View File

@ -170,8 +170,10 @@ word(s) will be searched for via `eww-search-prefix'."
;; TODO: Merge qutebrowser quickmarks.
;; TODO: Add bookmark editing functions such as edit title, tags, quickmark,
;; search-engine. Use eww-buffers and Helm.
(defun ambrevar/eww-add-bookmark ()
(defun ambrevar/eww-add-bookmark (&optional url title)
"Bookmark the current page."
(setq url (or url (plist-get eww-data :url)))
(setq title (or title (plist-get eww-data :title)))
(interactive)
(eww-read-bookmarks)
(let (tag-list)
@ -179,22 +181,21 @@ word(s) will be searched for via `eww-search-prefix'."
(when (equal
;; PATCH: Ignore protocol when sorting.
;; TODO: Include "sort-bookmarks": Warn for unique tags, warn for same URL up to paragraph. Make this customizable.
(replace-regexp-in-string "^https?" "" (plist-get eww-data :url))
(replace-regexp-in-string "^https?" "" url)
(replace-regexp-in-string "^https?" "" (plist-get bookmark :url)))
(user-error "Already bookmarked"))
(setq tag-list (append tag-list (plist-get bookmark :tags))))
(cl-delete-duplicates tag-list)
(let ((tags (completing-read-multiple "Tags for bookmark (comma separated): " tag-list))
(title (replace-regexp-in-string "[\n\t\r]" " "
(plist-get eww-data :title))))
(title (replace-regexp-in-string "[\n\t\r]" " " title)))
(setq title (replace-regexp-in-string "\\` +\\| +\\'" "" title))
(push `(:url ,(plist-get eww-data :url)
(push `(:url ,url
:title ,title
:time ,(current-time-string)
,@(if tags (list :tags tags)))
eww-bookmarks)
(eww-write-bookmarks)
(message "Bookmarked %s (%s)" (plist-get eww-data :url)
(message "Bookmarked %s (%s)" url
(plist-get eww-data :title)))))
(advice-add 'eww-add-bookmark :override 'ambrevar/eww-add-bookmark)