From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ryo TAKAISHI Subject: [PATCH] org-protocol: Pass optional value using query in url to capture from protocol. Date: Mon, 31 Dec 2012 10:23:56 +0900 Message-ID: <1356917036-31179-1-git-send-email-ryo.takaishi.0@gmail.com> Return-path: Received: from eggs.gnu.org ([208.118.235.92]:57193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpU6l-0007Sn-1o for emacs-orgmode@gnu.org; Sun, 30 Dec 2012 20:24:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TpU6k-00008G-30 for emacs-orgmode@gnu.org; Sun, 30 Dec 2012 20:24:02 -0500 Received: from mail-da0-f50.google.com ([209.85.210.50]:36634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TpU6j-00008A-S3 for emacs-orgmode@gnu.org; Sun, 30 Dec 2012 20:24:02 -0500 Received: by mail-da0-f50.google.com with SMTP id h15so5540299dan.37 for ; Sun, 30 Dec 2012 17:24:00 -0800 (PST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Ryo TAKAISHI * lisp/org-protocol.el: (org-protocol-convert-query-to-plist): New function. (org-protocol-do-capture): Use new function. 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). --- lisp/org-protocol.el | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el index 31f6fb2..2fa7c76 100644 --- a/lisp/org-protocol.el +++ b/lisp/org-protocol.el @@ -273,7 +273,7 @@ string with two characters." :group 'org-protocol :type 'string) -(defcustom org-protocol-data-separator "/+" +(defcustom org-protocol-data-separator "/+\\|\\?" "The default data separator to use. This should be a single regexp string." :group 'org-protocol @@ -297,7 +297,7 @@ nil, assume \"/+\". The results of that splitting are returned 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 part." - (let* ((sep (or separator "/+")) + (let* ((sep (or separator "/+\\|\\?")) (split-parts (split-string data sep))) (if unhexify (if (fboundp unhexify) @@ -436,6 +436,14 @@ Now template ?b will be used." (message "Item captured.")) 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 capture-func) "Support `org-capture' and `org-remember' alike. CAPTURE-FUNC is either the symbol `org-remember' or `org-capture'." @@ -449,6 +457,7 @@ CAPTURE-FUNC is either the symbol `org-remember' or `org-capture'." (region (or (caddr parts) "")) (orglink (org-make-link-string 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 remember-annotation-functions) (setq org-stored-links @@ -458,7 +467,8 @@ CAPTURE-FUNC is either the symbol `org-remember' or `org-capture'." :link url :description title :annotation orglink - :initial region) + :initial region + :query query) (raise-frame) (funcall capture-func nil template))) -- 1.7.9.6 (Apple Git-31.1)