forked from mirrors/org-mode
org-protocol: Pass optional value using query in url to capture from protocol.
* lisp/org-protocol.el: (org-protocol-convert-query-to-plist): New function. (org-protocol-do-capture): Use new function. (org-protocol-data-separator): Change default separator. When org-protocol's url has query, org-capture get query using plist-get from store-link. For example: Url is "org-protocol:/capture:/URL/TITLE/BODY?key=value" org-capture can get (:key value) with (plist-get org-store-link-plist :query). TINYCHANGE
This commit is contained in:
parent
8b637b54a9
commit
c956672bb9
|
@ -267,10 +267,12 @@ string with two characters."
|
||||||
:group 'org-protocol
|
:group 'org-protocol
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
(defcustom org-protocol-data-separator "/+"
|
(defcustom org-protocol-data-separator "/+\\|\\?"
|
||||||
"The default data separator to use.
|
"The default data separator to use.
|
||||||
This should be a single regexp string."
|
This should be a single regexp string."
|
||||||
:group 'org-protocol
|
:group 'org-protocol
|
||||||
|
:version "24.4"
|
||||||
|
:package-version '(Org . "8.0")
|
||||||
:type 'string)
|
:type 'string)
|
||||||
|
|
||||||
;;; Helper functions:
|
;;; Helper functions:
|
||||||
|
@ -291,7 +293,7 @@ nil, assume \"/+\". The results of that splitting are returned
|
||||||
as a list. If UNHEXIFY is non-nil, hex-decode each split part.
|
as a list. If UNHEXIFY is non-nil, hex-decode each split part.
|
||||||
If UNHEXIFY is a function, use that function to decode each split
|
If UNHEXIFY is a function, use that function to decode each split
|
||||||
part."
|
part."
|
||||||
(let* ((sep (or separator "/+"))
|
(let* ((sep (or separator "/+\\|\\?"))
|
||||||
(split-parts (split-string data sep)))
|
(split-parts (split-string data sep)))
|
||||||
(if unhexify
|
(if unhexify
|
||||||
(if (fboundp unhexify)
|
(if (fboundp unhexify)
|
||||||
|
@ -411,6 +413,14 @@ Now template ?b will be used."
|
||||||
(message "Item captured."))
|
(message "Item captured."))
|
||||||
nil)
|
nil)
|
||||||
|
|
||||||
|
(defun org-protocol-convert-query-to-plist (query)
|
||||||
|
"Convert query string that is part of url to property list."
|
||||||
|
(if query
|
||||||
|
(apply 'append (mapcar (lambda (x)
|
||||||
|
(let ((c (split-string x "=")))
|
||||||
|
(list (intern (concat ":" (car c))) (cadr c))))
|
||||||
|
(split-string query "&")))))
|
||||||
|
|
||||||
(defun org-protocol-do-capture (info)
|
(defun org-protocol-do-capture (info)
|
||||||
"Support `org-capture'."
|
"Support `org-capture'."
|
||||||
(let* ((parts (org-protocol-split-data info t org-protocol-data-separator))
|
(let* ((parts (org-protocol-split-data info t org-protocol-data-separator))
|
||||||
|
@ -423,6 +433,7 @@ Now template ?b will be used."
|
||||||
(region (or (caddr parts) ""))
|
(region (or (caddr parts) ""))
|
||||||
(orglink (org-make-link-string
|
(orglink (org-make-link-string
|
||||||
url (if (string-match "[^[:space:]]" title) title url)))
|
url (if (string-match "[^[:space:]]" title) title url)))
|
||||||
|
(query (or (org-protocol-convert-query-to-plist (cadddr parts)) ""))
|
||||||
(org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
|
(org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
|
||||||
(setq org-stored-links
|
(setq org-stored-links
|
||||||
(cons (list url title) org-stored-links))
|
(cons (list url title) org-stored-links))
|
||||||
|
@ -431,7 +442,8 @@ Now template ?b will be used."
|
||||||
:link url
|
:link url
|
||||||
:description title
|
:description title
|
||||||
:annotation orglink
|
:annotation orglink
|
||||||
:initial region)
|
:initial region
|
||||||
|
:query query)
|
||||||
(raise-frame)
|
(raise-frame)
|
||||||
(funcall 'org-capture nil template)))
|
(funcall 'org-capture nil template)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue