From 59327f6f9c6ba419543c47670a62af0aa41271ca Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 4 Jan 2015 11:41:30 -0500 Subject: Tree-style specification for filter-from-nil Instead of saying (field-a field-b object-a.subfield field-c object-b.subfield-a object-b.subfield-b) you can rather say (field-a field-b (object-a subfield) field-c (object-b subfield-a subfield-b)) To avoid a dependency loop, sx-browse-filter has been moved to sx-filter.el. --- sx.el | 61 ++++++++++++++++++++----------------------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) (limited to 'sx.el') diff --git a/sx.el b/sx.el index 3aa87e7..f77b313 100644 --- a/sx.el +++ b/sx.el @@ -136,6 +136,26 @@ with a `link' property)." result)) result)) +(defun sx--tree-paths (tree) + "Return a list of all paths in TREE. +Adapted from http://stackoverflow.com/q/3019250." + (if (atom tree) + (list (list tree)) + (apply #'append + (mapcar (lambda (node) + (mapcar (lambda (path) + (cons (car tree) path)) + (sx--tree-paths node))) + (cdr tree))))) + +(defun sx--tree-expand (path-func tree) + "Apply PATH-FUNC to every path in TREE. +Return the result. See `sx--tree-paths'." + (mapcar path-func + (apply #'append + (mapcar #'sx--tree-paths + tree)))) + (defmacro sx-assoc-let (alist &rest body) "Use ALIST with `let-alist' to execute BODY. `.site_par' has a special meaning, thanks to `sx--ensure-site'. @@ -148,47 +168,6 @@ If ALIST doesn't have a `site' property, one is created using the ,(macroexpand `(let-alist ,alist ,@body)))) - -;;; Browsing filter -(defvar sx-browse-filter - ;; @TODO: Use `sx-filter-from-nil' - '((question.body_markdown - question.comments - question.answers - question.last_editor - question.last_activity_date - question.accepted_answer_id - question.link - question.upvoted - question.downvoted - question.question_id - question.share_link - user.display_name - comment.owner - comment.body_markdown - comment.body - comment.link - comment.edited - comment.creation_date - comment.upvoted - comment.score - comment.post_type - comment.post_id - comment.comment_id - answer.answer_id - answer.last_editor - answer.last_activity_date - answer.link - answer.share_link - answer.owner - answer.body_markdown - answer.upvoted - answer.downvoted - answer.comments) - (user.profile_image shallow_user.profile_image)) - "The filter applied when retrieving question data. -See `sx-question-get-questions' and `sx-question-get-question'.") - ;;; Utility Functions (defun sx-completing-read (&rest args) -- cgit v1.2.3