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: Mon, 04 Mar 2013 09:13:34 +0900 Message-ID: <87obf0hvip.fsf@gmail.com> References: <1356917036-31179-1-git-send-email-ryo.takaishi.0@gmail.com> <87bodao7jx.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([208.118.235.92]:39330) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCJ2C-0002sM-7L for emacs-orgmode@gnu.org; Sun, 03 Mar 2013 19:13:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UCJ2A-0002Kp-Uv for emacs-orgmode@gnu.org; Sun, 03 Mar 2013 19:13:40 -0500 Received: from mail-da0-f47.google.com ([209.85.210.47]:54170) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UCJ2A-0002Kk-Od for emacs-orgmode@gnu.org; Sun, 03 Mar 2013 19:13:38 -0500 Received: by mail-da0-f47.google.com with SMTP id s35so2246097dak.34 for ; Sun, 03 Mar 2013 16:13:37 -0800 (PST) In-Reply-To: <87bodao7jx.fsf@bzg.ath.cx> (Bastien's message of "Mon, 31 Dec 2012 11:11:14 +0100") 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 * 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). --- Hello, Bastien I fixed and resend a patch. Thanks, Ryo lisp/org-protocol.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el index 2a804ad..d676c39 100644 --- a/lisp/org-protocol.el +++ b/lisp/org-protocol.el @@ -267,10 +267,12 @@ 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 + :version "24.4" + :package-version '(Org . "8.0") :type 'string) ;;; 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. 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 +413,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 +433,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 +442,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)