From 8e9983d1c9edab01335e3923bb5b50ad5a91ed1f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:09:31 -0500 Subject: Abstract sorting function --- sx-question-print.el | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'sx-question-print.el') 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 -- cgit v1.2.3 From fe912f7a4871f7beedeafe5f29feb57ca65ecc47 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 15 Jan 2015 00:22:33 -0500 Subject: Abstract sorting function into customizable option --- sx-question-print.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'sx-question-print.el') diff --git a/sx-question-print.el b/sx-question-print.el index 210f99a..c19b0c3 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -166,6 +166,15 @@ replaced with the comment." :type 'boolean :group 'sx-question-mode) +(defcustom sx-question-mode-answer-sort-function + #'sx-answer-higher-score-p + "Function used to sort answers in the question buffer." + :type '(choice + (const :tag "Higher-scoring first" sx-answer-higher-score-p) + (const :tag "Older first" sx-answer-older-p) + (const :tag "More active first" sx-answer-more-active-p)) + :group 'sx-question-mode) + ;;; Functions ;;;; Printing the general structure @@ -180,7 +189,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 #'sx-answer-higher-score-p))) + (cl-sort .answers sx-question-list--sort-answer-function))) (insert "\n\n ") (insert-text-button "Write an Answer" :type 'sx-button-answer) ;; Go up -- cgit v1.2.3 From 7470438d4455e38e4f7b749579470d4af2b66751 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 16 Jan 2015 00:43:21 -0500 Subject: Change older-p to newer-p Older functions generally have more votes anyway -- new answers need initial the attention. --- sx-question-print.el | 2 +- sx-question.el | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'sx-question-print.el') diff --git a/sx-question-print.el b/sx-question-print.el index c19b0c3..031e06b 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -171,7 +171,7 @@ replaced with the comment." "Function used to sort answers in the question buffer." :type '(choice (const :tag "Higher-scoring first" sx-answer-higher-score-p) - (const :tag "Older first" sx-answer-older-p) + (const :tag "Newer first" sx-answer-newer-p) (const :tag "More active first" sx-answer-more-active-p)) :group 'sx-question-mode) diff --git a/sx-question.el b/sx-question.el index e199966..e39634b 100644 --- a/sx-question.el +++ b/sx-question.el @@ -194,9 +194,9 @@ If no cache exists for it, initialize one with SITE." "Return t if answer A has a higher score than answer B." #'> (lambda (x) (cdr (assq 'score x)))) -(sx--create-comparator sx-answer-older-p +(sx--create-comparator sx-answer-newer-p "Return t if answer A was posted later than answer B." - #'< (lambda (x) (cdr (assq 'creation_date x)))) + #'> (lambda (x) (cdr (assq 'creation_date x)))) (sx--create-comparator sx-answer-more-active-p "Return t if answer A was updated after answer B." -- cgit v1.2.3 From 389e433953bba4003b102748dbbf5f8a9b421a51 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 16 Jan 2015 08:54:13 -0500 Subject: Hotfix: wrong variable name Fix #234 --- sx-question-print.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sx-question-print.el') diff --git a/sx-question-print.el b/sx-question-print.el index a25ff52..f9ecfab 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -176,7 +176,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 sx-question-list--sort-answer-function))) + (cl-sort .answers sx-question-mode-answer-sort-function))) (insert "\n\n ") (insert-text-button "Write an Answer" :type 'sx-button-answer) ;; Go up -- cgit v1.2.3