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