From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sebastian Rose Subject: Re: org-protocol and encoding Date: Thu, 16 Apr 2009 00:22:44 +0200 Message-ID: <873ac9a763.fsf@kassiopeya.MSHEIMNETZ> References: <87y6ue3sms.fsf@kassiopeya.MSHEIMNETZ> <8763hgbth5.fsf@kassiopeya.MSHEIMNETZ> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LuDS3-0003FP-00 for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 18:19:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LuDRx-0003DQ-Ki for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 18:19:25 -0400 Received: from [199.232.76.173] (port=39254 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LuDRx-0003DN-DX for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 18:19:21 -0400 Received: from mail.gmx.net ([213.165.64.20]:33570) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1LuDRw-0006h4-Ow for emacs-orgmode@gnu.org; Wed, 15 Apr 2009 18:19:21 -0400 In-Reply-To: <8763hgbth5.fsf@kassiopeya.MSHEIMNETZ> (Sebastian Rose's message of "Tue, 07 Apr 2009 13:20:38 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Ulf Stegemann Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: base64 SGkgVWxmIGFuZCBDYXJzdGVuLA0KDQoNCmhlcmUgYXBwZW5kZWQgaXMgYSBwYXRjaCwgdGhhdCBk b2VzIHR3byB0aGluZ3MuDQoNCg0KMS4gRGVjb2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ENCiDlhazluo/oia/kv5fjgavlj43j gZfjgarjgYTnr4Tlm7Ljgafoh6rnlLHjgavjganjgYbjgZ7jgIIgDQoNCiA8PSAtLS04PC0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tODwtLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLTg8 LS0tDQogIA0KDQoNCiAgDQoyLiBBbGxvdyBhIGZ1bmN0aW9uIGFzIHNlY29uZCBhcmd1bWVudCB0 byBvcmctcHJvdG9jb2wtc3BsaXQtZGF0YQ0KPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0NCg0KVGhlIGRlZmF1bHQgZGVjb2Rp bmcgZnVuY3Rpb24gaXMgbm93IGBvcmctcHJvdG9jb2wtdW5oZXgtc3RyaW5nJywgaWYgdGhlDQpz ZWNvbmQgcGFyYW1ldGVyIHRvIGBvcmctcHJvdG9jb2wtc3BsaXQtZGF0YScgaXMgbm9uLW5pbC4g SWYgdGhhdA0KcGFyYW1ldGVyIGlzIGEgZnVuY3Rpb24sIHRoYXQgZnVuY3Rpb24gaXMgdXNlZCB0 byBkZWNvZGUgdGhlIHNwbGl0DQpwYXJ0cy4gDQogIA0KDQoNCg0KDQpUaGUgcGF0Y2ggc3RpbGwg Y29udGFpbmVzIHNvbWUgbGluZXMgd2l0aCBkZWJ1Z2dpbmcgY29kZSwgdGhhdA0KbWF5IGJlIHVu Y29tbWVudGVkIHRvIHNlZSB3aGF0J3MgZ29pbmcgb24uIA0KDQoNCg== --=-=-= Content-Type: application/emacs-lisp Content-Disposition: attachment; filename=patch-org-protocol.el Content-Transfer-Encoding: quoted-printable diff --git a/lisp/org-protocol.el b/lisp/org-protocol.el index cc99235..31373e0 100644 --- a/lisp/org-protocol.el +++ b/lisp/org-protocol.el @@ -271,14 +271,75 @@ Slashes are sanitized to double slashes here." data is that one argument. Data is splitted at each occurrence of separator (regexp). If no separator is specified or separator is nil, assume \"/+\". The results of that splitting are return as a list. If unhexify is non-nil, -hex-decode each split part." +hex-decode each split part. If unhexify is a function, use that function to +decode each split part." (let* ((sep (or separator "/+")) (split-parts (split-string data sep))) (if unhexify - (mapcar 'url-unhex-string split-parts) + (if (fboundp unhexify) + (mapcar unhexify split-parts) + (mapcar 'org-protocol-unhex-string split-parts)) split-parts))) =20 =20 +(defun org-protocol-unhex-string(str) + "Unhex hexified unicode strings as returned from the JavaScript function +encodeURIComponent. E.g. `%C3%B6' is the german Umlaut `=C3=BC'." + (setq str (or str "")) + (let ((tmp "") + (case-fold-search t)) + (while (string-match "\\(%[0-9a-f][0-9a-f]\\)+" str) + (let* ((start (match-beginning 0)) + (end (match-end 0)) + (hex (match-string 0 str)) + (replacement (org-protocol-unhex-compound hex))) + (setq tmp (concat tmp (substring str 0 start) replacement)) + (setq str (substring str end)))) + (setq tmp (concat tmp str)) + tmp)) + + +(defun org-protocol-unhex-compound (hex) + "Unhexify unicode hex-chars. E.g. `%C3%B6' is the german Umlaut `=C3=BC'= ." + ;; (message "HEX: %S" hex) + (let* ((bytes (remove "" (split-string hex "%"))) + (ret "") + (eat 0) + (sum 0)) + (while bytes + (let* ((b (pop bytes)) + (c1 (url-unhex (elt b 0))) + (c2 (url-unhex (elt b 1))) + (val (+ (lsh c1 4) c2)) + (shift + (if (=3D 0 eat) ;; new byte + (if (>=3D val 252) 6 + (if (>=3D val 248) 5 + (if (>=3D val 240) 4 + (if (>=3D val 224) 3 + (if (>=3D val 192) 2 0))))) + 6)) + (xor + (if (=3D 0 eat) ;; new byte + (if (>=3D val 252) 252 + (if (>=3D val 248) 248 + (if (>=3D val 240) 240 + (if (>=3D val 224) 224 + (if (>=3D val 192) 192 0))))) + 128))) + (if (>=3D val 192) (setq eat shift)) + ;; (message "\n =3D 1 =3D ")(message "val: %s" val)(message "shift= : %s" shift)(message "eat: %s" eat)(message "xor: %s" xor) ;; debug + (setq val (logxor val xor)) + (setq sum (+ (lsh sum shift) val)) + ;; (message " =3D ") (message "val: %s" val) (message "sum: %s" sum) ;; d= ebug + (if (> eat 0) (setq eat (- eat 1))) + (when (=3D 0 eat) + (setq ret (concat ret (char-to-string sum))) + (setq sum 0)) + )) ;; end (while bytes + ret )) + + (defun org-protocol-flatten-greedy (param-list &optional strip-path replac= ement) "Greedy handlers might recieve a list like this from emacsclient: '( (\"/dir/org-protocol:/greedy:/~/path1\" (23 . 12)) (\"/dir/param\") @@ -426,7 +487,7 @@ The location for a browser's bookmark should look like = this: ;; As we enter this function for a match on our protocol, the return val= ue ;; defaults to nil. (let ((result nil) - (f (url-unhex-string fname))) + (f (org-protocol-unhex-string fname))) (catch 'result (dolist (prolist org-protocol-project-alist) (let* ((base-url (plist-get (cdr prolist) :base-url)) --=-=-= Best Sebastian --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-orgmode mailing list Remember: use `Reply All' to send replies to the list. Emacs-orgmode@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-orgmode --=-=-=--