aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-interaction.el2
-rw-r--r--sx-request.el2
-rw-r--r--sx.el31
-rw-r--r--test/tests.el32
4 files changed, 56 insertions, 11 deletions
diff --git a/sx-interaction.el b/sx-interaction.el
index 89050c3..9b63e0a 100644
--- a/sx-interaction.el
+++ b/sx-interaction.el
@@ -230,7 +230,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
diff --git a/sx-request.el b/sx-request.el
index 6be363d..0994fbd 100644
--- a/sx-request.el
+++ b/sx-request.el
@@ -188,7 +188,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))
diff --git a/sx.el b/sx.el
index 431643c..8e3e5d3 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.
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")))