aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-question-print.el6
-rw-r--r--sx-question.el7
2 files changed, 8 insertions, 5 deletions
diff --git a/sx-question-print.el b/sx-question-print.el
index 737844a..210f99a 100644
--- a/sx-question-print.el
+++ b/sx-question-print.el
@@ -180,11 +180,7 @@ QUESTION must be a data structure returned by `json-read'."
(sx-question-mode--print-section question)
(sx-assoc-let question
(mapc #'sx-question-mode--print-section
- (cl-sort .answers
- ;; Highest-voted first. @TODO: custom sorting
- (lambda (a b)
- (> (cdr (assoc 'score a))
- (cdr (assoc 'score b)))))))
+ (cl-sort .answers #'sx-answer-higher-score-p)))
(insert "\n\n ")
(insert-text-button "Write an Answer" :type 'sx-button-answer)
;; Go up
diff --git a/sx-question.el b/sx-question.el
index b9fc78a..d624f45 100644
--- a/sx-question.el
+++ b/sx-question.el
@@ -187,6 +187,13 @@ If no cache exists for it, initialize one with SITE."
"Formats TAG for display."
(concat "[" tag "]"))
+
+;;; Question Mode Answer-Sorting Functions
+
+(sx--create-comparator sx-answer-higher-score-p
+ "Return t if answer A has a higher score than answer B."
+ #'> (lambda (x) (cdr (assoc 'score x))))
+
(provide 'sx-question)
;;; sx-question.el ends here