(feat): Allow ORP to capture the webpage's selection (#1239)

* (feat): Temporarily store link when capturing with ORP

* org-roam-protocol.el (org-roam-protocol-open-ref): Replicate default
`org-protocol' behaviour temporarily for storing links
* org-roam-capture.el (org-roam-capture--capture): Prevent stored link from
being reset

When capturing a web-page with org-roam-protocol, a link is now temporarily
stored in `org-store-link-plist' via `org-link-store-props'.  This is to allow
the forwarding of properties to `org-capture', one of them being `:initial'
which contains the content of the selected text in the browser.

* (feat): Add toggle for storing link when capturing with ORP

* org-roam-protocol.el (org-roam-protocol-store-links): Add new toggle
(org-roam-protocol-open-ref): Conditionally store link for later used

Building up on b2ee5f2c68, the user can now
decide whether to store links when capturing with org-roam-protocol (default
nil).

* Update changelog
This commit is contained in:
Leo Vivier
2020-11-08 13:30:16 +01:00
committed by GitHub
parent c6797cbd75
commit 7602b8c48d
3 changed files with 23 additions and 2 deletions

View File

@ -7,6 +7,7 @@
- [#1183](https://github.com/org-roam/org-roam/pull/1183) add interactive functions for managing aliases and tags in Org-roam file, namely `org-roam-alias-add`, `org-roam-alias-delete`, `org-roam-tag-add`, and `org-roam-tag-delete`.
- [#1215](https://github.com/org-roam/org-roam/pull/1215) Multiple `ROAM_KEY` keywords can now be specified in one file. This allows bibliographical entries to share the same note file.
- [#1238](https://github.com/org-roam/org-roam/pull/1238) add `org-roam-prefer-id-links` variable to select linking method
- [#1239](https://github.com/org-roam/org-roam/pull/1239) Allow `org-roam-protocol` to capture the webpage's selection, and add a toggle for storing the links to the pages
### Bugfixes

View File

@ -512,7 +512,8 @@ GOTO and KEYS argument have the same functionality as
`org-capture'."
(let* ((org-capture-templates (mapcar #'org-roam-capture--convert-template org-roam-capture-templates))
(one-template-p (= (length org-capture-templates) 1))
org-capture-templates-contexts)
org-capture-templates-contexts
(org-capture-link-is-already-stored t))
(when one-template-p
(setq keys (caar org-capture-templates)))
(if (or one-template-p

View File

@ -39,6 +39,11 @@
(require 'org-roam)
(require 'ol) ;; for org-link-decode
(defcustom org-roam-protocol-store-links nil
"Whether to store links when capturing websites with `org-roam-protocol'."
:type 'boolean
:group 'org-roam)
;;;; Functions
(defun org-roam-protocol-open-ref (info)
"Process an org-protocol://roam-ref?ref= style url with INFO.
@ -46,7 +51,7 @@
It opens or creates a note with the given ref.
javascript:location.href = \\='org-protocol://roam-ref?template=r&ref=\\='+ \\
encodeURIComponent(location.href) + \\='&title=\\=' \\
encodeURIComponent(location.href) + \\='&title=\\=' + \\
encodeURIComponent(document.title) + \\='&body=\\=' + \\
encodeURIComponent(window.getSelection())"
(when-let* ((alist (org-roam--plist-to-alist info))
@ -58,6 +63,20 @@ It opens or creates a note with the given ref.
(error "No ref key provided"))
(when-let ((title (cdr (assoc 'title decoded-alist))))
(push (cons 'slug (funcall org-roam-title-to-slug-function title)) decoded-alist))
(let-alist decoded-alist
(let* ((ref (org-protocol-sanitize-uri .ref))
(type (and (string-match "^\\([a-z]+\\):" ref)
(match-string 1 ref)))
(title (or .title ""))
(body (or .body ""))
(orglink
(org-link-make-string ref (or (org-string-nw-p title) ref))))
(when org-roam-protocol-store-links
(push (list ref title) org-stored-links))
(org-link-store-props :type type
:link ref
:annotation orglink
:initial body)))
(let* ((org-roam-capture-templates org-roam-capture-ref-templates)
(org-roam-capture--context 'ref)
(org-roam-capture--info decoded-alist)