From 6c111d0eb2e6a15c02a925458d64b870c96ac74c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:04:01 -0500 Subject: Prune unused parameter --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index a98af5a..7ed8792 100644 --- a/sx-request.el +++ b/sx-request.el @@ -170,7 +170,7 @@ Currently returns nil." ;;; Support Functions (defun sx-request--build-keyword-arguments (alist &optional - kv-sep need-auth) + kv-sep) "Format ALIST as a key-value list joined with KV-SEP. If authentication is needed, include it also or error if it is not available. -- cgit v1.2.3 From d72f3128b1c4615c2d9c38550c0f244d4096d9df Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:04:16 -0500 Subject: Add missing dot-operator --- sx-interaction.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-interaction.el b/sx-interaction.el index d0c4c47..7f851e7 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -169,7 +169,7 @@ TEXT is a string. Interactively, it is read from the minibufer." :url-method "POST" :filter sx-browse-filter :site .site - :keywords `((body ,text))))) + :keywords `((body . ,text))))) ;; The api returns the new DATA. (when (> (length result) 0) (sx--add-comment-to-object -- cgit v1.2.3 From fd0eb04a72eae2d85a2a023e44cf641e450fa2f1 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:04:44 -0500 Subject: Augment `sx--thing-as-string' to hexify as needed Also fix issue where function options would not be transferred from the original use into its recursive steps. --- sx.el | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/sx.el b/sx.el index f1d3634..411c9e2 100644 --- a/sx.el +++ b/sx.el @@ -115,19 +115,32 @@ See `format'." (let ((echo (get-text-property (point) 'help-echo))) (when echo (message "%s" echo)))) -(defun sx--thing-as-string (thing &optional sequence-sep) +(defun sx--thing-as-string (thing &optional sequence-sep url-hexify) "Return a string representation of THING. If THING is already a string, just return it. Optional argument SEQUENCE-SEP is the separator applied between -elements of a sequence." - (cond - ((stringp thing) thing) - ((symbolp thing) (symbol-name thing)) - ((numberp thing) (number-to-string thing)) - ((sequencep thing) - (mapconcat #'sx--thing-as-string - thing (if sequence-sep sequence-sep ";"))))) +elements of a sequence. If SEQUENCE-SEP is a list, use the first +element for the top level joining, the second for the next level, +etc. \";\" is used as a default. + +If optional argument URL-HEXIFY is non-nil, this function behaves +as `url-hexify-string'; this option is only effective on strings +and sequences of strings." + (let ((process (if url-hexify #'url-hexify-string #'identity)) + (first-f (if (listp sequence-sep) #'car #'identity)) + (rest-f (if (listp sequence-sep) #'cdr #'identity))) + (cond + ((stringp thing) (funcall process thing)) + ((symbolp thing) (funcall process (symbol-name thing))) + ((numberp thing) (number-to-string thing)) + ((sequencep thing) + (mapconcat (lambda (thing) + (sx--thing-as-string + thing (funcall rest-f sequence-sep) url-hexify)) + thing (if sequence-sep + (funcall first-f sequence-sep) + ";")))))) (defun sx--filter-data (data desired-tree) "Filter DATA and return the DESIRED-TREE. -- cgit v1.2.3 From 07ead3d320ebe2d14c89f47a715571f9b124187d Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:06:36 -0500 Subject: Hexify value in key-value pairs Fixes #130 --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index 7ed8792..c8c6eb6 100644 --- a/sx-request.el +++ b/sx-request.el @@ -194,7 +194,7 @@ false, use the symbol `false'. Each element is processed with (concat (sx--thing-as-string (car pair)) "=" - (sx--thing-as-string (cdr pair) kv-sep))) + (sx--thing-as-string (cdr pair) kv-sep t))) (delq nil (mapcar (lambda (pair) (when (cdr pair) pair)) -- cgit v1.2.3 From 114ca09da984738df2510bc72753a3443d16857c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 2 Dec 2014 00:07:16 -0500 Subject: Add tests for `sx--thing-as-string' --- test/tests.el | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/tests.el b/test/tests.el index 75238fe..43531b4 100644 --- a/test/tests.el +++ b/test/tests.el @@ -133,3 +133,35 @@ (macroexpand '(sx-assoc-let data (cons .test-one .test-two)))))) + +(ert-deftest thing-as-string () + "Tests `sx--thing-as-string'" + (should + (string= (sx--thing-as-string + '(hello world (this is a test)) + '(";" "+")) + "hello;world;this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test) '(";" "+")) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + '(this is a test) "+") + "this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test)) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + 'test) + "test")) + (should + (string= (sx--thing-as-string + 'test&) + "test&")) + (should + (string= (sx--thing-as-string + 'test& nil t) + "test%26"))) -- cgit v1.2.3