From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ryo Takaishi Subject: Re: [PATCH] org-protocol: Pass optional value using query in url to capture from protocol. Date: Sun, 3 Mar 2013 10:06:15 +0900 Message-ID: References: <1356917036-31179-1-git-send-email-ryo.takaishi.0@gmail.com> <87bodao7jx.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=e89a8ff2424fe0c3c904d6fad8fe Return-path: Received: from eggs.gnu.org ([208.118.235.92]:40681) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBxNa-0006HW-HJ for emacs-orgmode@gnu.org; Sat, 02 Mar 2013 20:06:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UBxNY-0004vc-GR for emacs-orgmode@gnu.org; Sat, 02 Mar 2013 20:06:18 -0500 Received: from mail-oa0-f46.google.com ([209.85.219.46]:44461) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UBxNY-0004vW-9j for emacs-orgmode@gnu.org; Sat, 02 Mar 2013 20:06:16 -0500 Received: by mail-oa0-f46.google.com with SMTP id k1so7615862oag.33 for ; Sat, 02 Mar 2013 17:06:15 -0800 (PST) In-Reply-To: <87bodao7jx.fsf@bzg.ath.cx> 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: Bastien Cc: emacs-orgmode@gnu.org --e89a8ff2424fe0c3c904d6fad8fe Content-Type: text/plain; charset=ISO-8859-1 Hello, Bastien I resend a patch for HEAD of master branch. Thanks, Ryo. --- * 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 2a804ad..1f76e85 100644 --- a/lisp/org-protocol.el +++ b/lisp/org-protocol.el @@ -267,7 +267,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 @@ -291,7 +291,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) @@ -411,6 +411,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) "Support `org-capture'." (let* ((parts (org-protocol-split-data info t org-protocol-data-separator)) @@ -423,6 +431,7 @@ Now template ?b will be used." (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 (setq org-stored-links (cons (list url title) org-stored-links)) @@ -431,7 +440,8 @@ Now template ?b will be used." :link url :description title :annotation orglink - :initial region) + :initial region + :query query) (raise-frame) (funcall 'org-capture nil template))) -- 1.7.9.6 (Apple Git-31.1) 2012/12/31 Bastien > Hi Ryo, > > I'm willing to apply this patch but since you already submitted "tiny > changes" we would need to have you sign the FSF copyright assignment. > > See > http://orgmode.org/cgit.cgi/org-mode.git/plain/request-assign-future.txt > > Let me know if you are willing to assign your copyright to the FSF. > > Thanks! > > -- > Bastien > -- Ryo Takaishi --e89a8ff2424fe0c3c904d6fad8fe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hello,
Bastien

I resend a patch for HEAD of mast= er branch.

Thanks,
Ryo.
---

* lisp/org-protocol.el: (or= g-protocol-convert-query-to-plist): New function.
(org-protocol-do-captu= re): Use new function.

When org-protocol's url has query, org-capture get query using plis= t-get from store-link.
For example:
Url is "org-protocol:/captur= e:/URL/TITLE/BODY?key=3Dvalue"
org-capture can get (:key value) wit= h (plist-get org-store-link-plist :query).
---
=A0lisp/org-protocol.el |=A0=A0 16 +++++++++++++---
=A01 file cha= nged, 13 insertions(+), 3 deletions(-)

diff --git a/lisp/org-protoco= l.el b/lisp/org-protocol.el
index 2a804ad..1f76e85 100644
--- a/lisp/= org-protocol.el
+++ b/lisp/org-protocol.el
@@ -267,7 +267,7 @@ string with two character= s."
=A0=A0 :group 'org-protocol
=A0=A0 :type 'string)=A0
-(defcustom org-protocol-data-separator "/+"
+(defcust= om org-protocol-data-separator "/+\\|\\?"
=A0=A0 "The default data separator to use.
=A0=A0=A0 This should be= a single regexp string."
=A0=A0 :group 'org-protocol
@@ -29= 1,7 +291,7 @@ nil, assume \"/+\".=A0 The results of that splittin= g are returned
=A0as a list.=A0 If UNHEXIFY is non-nil, hex-decode each split part.
=A0= If UNHEXIFY is a function, use that function to decode each split
=A0par= t."
-=A0 (let* ((sep (or separator "/+"))
+=A0 (let* (= (sep (or separator "/+\\|\\?"))
=A0=A0=A0=A0=A0=A0=A0=A0=A0 (split-parts (split-string data sep)))
=A0= =A0=A0=A0 (if unhexify
=A0=A0=A0=A0 (if (fboundp unhexify)
@@ -411,6 = +411,14 @@ Now template ?b will be used."
=A0=A0=A0=A0=A0=A0 (messa= ge "Item captured."))
=A0=A0 nil)
=A0
+(defun org-protocol-convert-query-to-plist (query)
+=A0 "Co= nvert query string that is part of url to property list."
+=A0 (if = query
+=A0=A0=A0=A0=A0 (apply 'append (mapcar (lambda (x)
+=A0=A0= =A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0=A0=A0 (let ((c (split-string x "= =3D")))
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0(list (intern (concat ":&q= uot; (car c))) (cadr c))))
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=A0 (= split-string query "&")))))
+
=A0(defun org-protocol-do= -capture (info)
=A0=A0 "Support `org-capture'."
=A0=A0 (let* ((parts (org-protocol-split-data info t org-protocol-data-sepa= rator))
@@ -423,6 +431,7 @@ Now template ?b will be used."
=A0= =A0=A0=A0 =A0(region (or (caddr parts) ""))
=A0=A0=A0=A0 =A0(o= rglink (org-make-link-string
=A0=A0=A0=A0 =A0=A0=A0 =A0=A0 url (if (string-match "[^[:space:]]"= ; title) title url)))
+=A0=A0=A0 =A0(query (or (org-protocol-convert-que= ry-to-plist (cadddr parts)) ""))
=A0=A0=A0=A0 =A0(org-capture-= link-is-already-stored t)) ;; avoid call to org-store-link
=A0=A0=A0=A0 (setq org-stored-links
=A0=A0=A0=A0 =A0 (cons (list url tit= le) org-stored-links))
@@ -431,7 +440,8 @@ Now template ?b will be used.= "
=A0=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 :link url
=A0=A0=A0=A0 = =A0=A0=A0 =A0=A0=A0 =A0 :description title
=A0=A0=A0=A0 =A0=A0=A0 =A0=A0= =A0 =A0 :annotation orglink
-=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 :initial region)
+=A0=A0=A0 =A0=A0=A0= =A0=A0=A0 =A0 :initial region
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0 :query= query)
=A0=A0=A0=A0 (raise-frame)
=A0=A0=A0=A0 (funcall 'org-cap= ture nil template)))
=A0
--
1.7.9.6 (Apple Git-31.1)




2012/12= /31 Bastien <bzg@altern.org>
Hi Ryo,

I'm willing to apply this patch but since you already submitted "t= iny
changes" we would need to have you sign the FSF copyright assignment.<= br>
See http://orgmode.org/cgit.cgi/org-mode.git/pl= ain/request-assign-future.txt

Let me know if you are willing to assign your copyright to the FSF.

Thanks!

--
=A0Bastien



--
Ryo Takai= shi
--e89a8ff2424fe0c3c904d6fad8fe--