summaryrefslogtreecommitdiff
path: root/lisp/org/org-protocol.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/org/org-protocol.el')
-rw-r--r--lisp/org/org-protocol.el95
1 files changed, 47 insertions, 48 deletions
diff --git a/lisp/org/org-protocol.el b/lisp/org/org-protocol.el
index 016105ef53b..44c6abbd959 100644
--- a/lisp/org/org-protocol.el
+++ b/lisp/org/org-protocol.el
@@ -116,12 +116,14 @@
;;; Code:
(require 'org)
+(require 'ol)
(declare-function org-publish-get-project-from-filename "ox-publish"
(filename &optional up))
(declare-function server-edit "server" (&optional arg))
(defvar org-capture-link-is-already-stored)
+(defvar org-capture-templates)
(defgroup org-protocol nil
"Intercept calls from emacsclient to trigger custom actions.
@@ -297,11 +299,9 @@ SEPARATOR is specified or SEPARATOR is nil, assume \"/+\". The
results of that splitting are returned as a list."
(let* ((sep (or separator "/+\\|\\?"))
(split-parts (split-string data sep)))
- (if unhexify
- (if (fboundp unhexify)
- (mapcar unhexify split-parts)
- (mapcar 'org-link-unescape split-parts))
- split-parts)))
+ (cond ((not unhexify) split-parts)
+ ((fboundp unhexify) (mapcar unhexify split-parts))
+ (t (mapcar #'org-link-decode split-parts)))))
(defun org-protocol-flatten-greedy (param-list &optional strip-path replacement)
"Transform PARAM-LIST into a flat list for greedy handlers.
@@ -381,11 +381,8 @@ If INFO is already a property list, return it unchanged."
result)
(while data
(setq result
- (append
- result
- (list
- (pop data)
- (org-link-unescape (pop data))))))
+ (append result
+ (list (pop data) (org-link-decode (pop data))))))
result)
(let ((data (org-protocol-split-data info t org-protocol-data-separator)))
(if default-order
@@ -444,9 +441,9 @@ form URL/TITLE can also be used."
(when (boundp 'org-stored-links)
(push (list uri title) org-stored-links))
(kill-new uri)
- (message "`%s' to insert new org-link, `%s' to insert `%s'"
- (substitute-command-keys "`\\[org-insert-link]'")
- (substitute-command-keys "`\\[yank]'")
+ (message "`%s' to insert new Org link, `%s' to insert %S"
+ (substitute-command-keys "\\[org-insert-link]")
+ (substitute-command-keys "\\[yank]")
uri))
nil)
@@ -471,51 +468,53 @@ You may specify the template with a template= query parameter, like this:
javascript:location.href = \\='org-protocol://capture?template=b\\='+ ...
Now template ?b will be used."
- (if (and (boundp 'org-stored-links)
- (org-protocol-do-capture info))
- (message "Item captured."))
- nil)
-
-(defun org-protocol-convert-query-to-plist (query)
- "Convert QUERY key=value pairs in the URL to a 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)
- "Perform the actual capture based on INFO."
- (let* ((temp-parts (org-protocol-parse-parameters info))
- (parts
- (cond
- ((and (listp info) (symbolp (car info))) info)
- ((= (length (car temp-parts)) 1) ;; First parameter is exactly one character long
- (org-protocol-assign-parameters temp-parts '(:template :url :title :body)))
- (t
- (org-protocol-assign-parameters temp-parts '(:url :title :body)))))
+ (let* ((parts
+ (pcase (org-protocol-parse-parameters info)
+ ;; New style links are parsed as a plist.
+ ((let `(,(pred keywordp) . ,_) info) info)
+ ;; Old style links, with or without template key, are
+ ;; parsed as a list of strings.
+ (p
+ (let ((k (if (= 1 (length (car p)))
+ '(:template :url :title :body)
+ '(:url :title :body))))
+ (org-protocol-assign-parameters p k)))))
(template (or (plist-get parts :template)
org-protocol-default-template-key))
- (url (and (plist-get parts :url) (org-protocol-sanitize-uri (plist-get parts :url))))
- (type (and url (if (string-match "^\\([a-z]+\\):" url)
- (match-string 1 url))))
+ (url (and (plist-get parts :url)
+ (org-protocol-sanitize-uri (plist-get parts :url))))
+ (type (and url
+ (string-match "^\\([a-z]+\\):" url)
+ (match-string 1 url)))
(title (or (plist-get parts :title) ""))
(region (or (plist-get parts :body) ""))
- (orglink (if url
- (org-make-link-string
- url (if (string-match "[^[:space:]]" title) title url))
- title))
- (org-capture-link-is-already-stored t)) ;; avoid call to org-store-link
- (setq org-stored-links
- (cons (list url title) org-stored-links))
- (org-store-link-props :type type
+ (orglink
+ (if (null url) title
+ (org-link-make-string url (or (org-string-nw-p title) url))))
+ ;; Avoid call to `org-store-link'.
+ (org-capture-link-is-already-stored t))
+ ;; Only store link if there's a URL to insert later on.
+ (when url (push (list url title) org-stored-links))
+ (org-link-store-props :type type
:link url
:description title
:annotation orglink
:initial region
:query parts)
(raise-frame)
- (funcall 'org-capture nil template)))
+ (org-capture nil template)
+ (message "Item captured.")
+ ;; Make sure we do not return a string, as `server-visit-files',
+ ;; through `server-edit', would interpret it as a file name.
+ nil))
+
+(defun org-protocol-convert-query-to-plist (query)
+ "Convert QUERY key=value pairs in the URL to a property list."
+ (when query
+ (apply 'append (mapcar (lambda (x)
+ (let ((c (split-string x "=")))
+ (list (intern (concat ":" (car c))) (cadr c))))
+ (split-string query "&")))))
(defun org-protocol-open-source (fname)
"Process an org-protocol://open-source?url= style URL with FNAME.