Add org-protocol bookmark handler
This commit is contained in:
parent
0819cc0e55
commit
7d3ebeae7f
@ -107,6 +107,7 @@ Load org-mode early to [[https://github.com/raxod502/straight.el#the-wrong-versi
|
||||
;; Annoying that this is necessary...
|
||||
(require 'org)
|
||||
(require 'org-refile)
|
||||
(require 'org-protocol)
|
||||
#+END_SRC
|
||||
|
||||
* Doom themes
|
||||
@ -1917,6 +1918,9 @@ Intelligently inserts an org-mode link from the clipboard.
|
||||
:defer t
|
||||
:after org
|
||||
:init
|
||||
|
||||
;; Org-capture setup
|
||||
|
||||
(defvar org-capture-bookmark-last-url nil)
|
||||
(defvar org-capture-bookmark-last-title nil)
|
||||
|
||||
@ -1931,13 +1935,16 @@ Intelligently inserts an org-mode link from the clipboard.
|
||||
(or (org-cliplink-retrieve-title-synchronously url)
|
||||
(read-string "Bookmark title: ")))
|
||||
|
||||
(defun bookmark-file (title)
|
||||
(concat (get-dropbox-directory)
|
||||
(format "/org/%s.org" (org-roam--get-new-id title))))
|
||||
|
||||
(defun org-capture-bookmark-file ()
|
||||
(let* ((url (org-capture-bookmark-get-url))
|
||||
(title (org-capture-bookmark-get-title url)))
|
||||
(setq org-capture-bookmark-last-url url)
|
||||
(setq org-capture-bookmark-last-title title)
|
||||
(concat (get-dropbox-directory)
|
||||
(format "/org/%s.org" (org-roam--get-new-id title)))))
|
||||
(bookmark-file title)))
|
||||
|
||||
(defun org-capture-bookmark-link ()
|
||||
(format "[[%s][%s]]"
|
||||
@ -1947,6 +1954,19 @@ Intelligently inserts an org-mode link from the clipboard.
|
||||
(defun org-capture-bookmark-title ()
|
||||
org-capture-bookmark-last-title)
|
||||
|
||||
(defun save-bookmark (url)
|
||||
(save-excursion
|
||||
(goto-char (point-min))
|
||||
(when (search-forward "* Bookmark" nil t)
|
||||
(org-board-new url)
|
||||
(wallabag-add-entry url
|
||||
(cl-function
|
||||
(lambda (&key data &allow-other-keys)
|
||||
(let ((entry-url (format "%s/view/%s"
|
||||
wallabag-base-url
|
||||
(alist-get 'id data))))
|
||||
(message "Added bookmark to Wallabag: %s" entry-url))))))))
|
||||
|
||||
(defun org-capture-bookmark-after-finalize ()
|
||||
"Runs `org-board-new' on the captured entry.
|
||||
Also saves to Wallabag."
|
||||
@ -1957,16 +1977,7 @@ Intelligently inserts an org-mode link from the clipboard.
|
||||
(equal key "b")
|
||||
(equal desc "Bookmark")
|
||||
org-capture-bookmark-last-url)
|
||||
(goto-char (point-min))
|
||||
(search-forward "* Bookmark")
|
||||
(org-board-new org-capture-bookmark-last-url)
|
||||
(wallabag-add-entry org-capture-bookmark-last-url
|
||||
(cl-function
|
||||
(lambda (&key data &allow-other-keys)
|
||||
(let ((entry-url (format "%s/view/%s"
|
||||
wallabag-base-url
|
||||
(alist-get 'id data))))
|
||||
(message "Added bookmark to Wallabag: %s" entry-url)))))
|
||||
(save-bookmark org-capture-bookmark-last-url)
|
||||
(setq org-capture-bookmark-last-url nil)
|
||||
(setq org-capture-bookmark-last-title nil))))
|
||||
|
||||
@ -1977,6 +1988,29 @@ Intelligently inserts an org-mode link from the clipboard.
|
||||
'("b" "Bookmark" plain
|
||||
(file org-capture-bookmark-file)
|
||||
"#+TITLE: %(org-capture-bookmark-title)\n\n- tags :: [[file:deft/bookmarks.org][Bookmarks]]\n- source :: %(org-capture-bookmark-link)\n%?\n* Bookmark"))
|
||||
|
||||
;; Org-protocol setup
|
||||
(defun make-org-protocol-bookmark (url title)
|
||||
(with-temp-buffer
|
||||
(let ((filename (bookmark-file title)))
|
||||
(save-excursion
|
||||
(insert (concat (format "#+TITLE: %s\n\n" title)
|
||||
"- tags :: [[file:deft/bookmarks.org][Bookmarks]]\n"
|
||||
(format "- source :: [[%s][%s]]\n\n" url title)
|
||||
"* Bookmark"))
|
||||
(write-file filename)
|
||||
(save-bookmark url)
|
||||
(save-buffer)))))
|
||||
|
||||
(defun bookmark-via-org-protocol (url)
|
||||
(org-cliplink-retrieve-title (url-unhex-string url) #'make-org-protocol-bookmark))
|
||||
|
||||
(add-to-list 'org-protocol-protocol-alist
|
||||
'("Bookmark"
|
||||
:protocol "bookmark"
|
||||
:function bookmark-via-org-protocol
|
||||
:kill-client t))
|
||||
|
||||
:config
|
||||
(add-to-list 'org-board-wget-switches "--recursive")
|
||||
(add-to-list 'org-board-wget-switches "--level=1")
|
||||
|
Loading…
Reference in New Issue
Block a user