aboutsummaryrefslogtreecommitdiff
path: root/sx.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-12-02 00:04:44 -0500
committerSean Allred <code@seanallred.com>2014-12-02 00:04:44 -0500
commitfd0eb04a72eae2d85a2a023e44cf641e450fa2f1 (patch)
tree8d001c7e85a2ccb50e0049286f34ac02c1c96e4b /sx.el
parentd72f3128b1c4615c2d9c38550c0f244d4096d9df (diff)
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.
Diffstat (limited to 'sx.el')
-rw-r--r--sx.el31
1 files 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.