From 285204874ce284bd4e2815c21097b678c4cd8cd6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:01:16 +0000 Subject: Define sx-question-list--order --- sx-question-list.el | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index 92b4c07..d10309f 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -420,6 +420,10 @@ Non-interactively, DATA is a question alist." "Site being displayed in the *question-list* buffer.") (make-variable-buffer-local 'sx-question-list--site) +(defvar sx-question-list--order nil + "Order being displayed in the *question-list* buffer.") +(make-variable-buffer-local 'sx-question-list--order) + (defun sx-question-list-refresh (&optional redisplay no-update) "Update the list of questions. If REDISPLAY is non-nil (or if interactive), also call `tabulated-list-print'. -- cgit v1.2.3 From 96ae2ad5cb8d8827a1062c66806a60fdae79d3b2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:06:08 +0000 Subject: Document sx-question-list--order --- sx-question-list.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index d10309f..04004b3 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -259,6 +259,10 @@ The full list of variables which can be set is: 5. `sx-question-list--dataset' This is only used if both 3 and 4 are nil. It can be used to display a static list. + 6. `sx-question-list--order' + Set this to the `sort' method that should be used when + requesting the list, if that makes sense. If it doesn't + leave it as nil. \\ If none of these is configured, the behaviour is that of a \"Frontpage\", for the site given by @@ -282,7 +286,7 @@ Adding further questions to the bottom of the list is done by: display; otherwise, decrement `sx-question-list--pages-so-far'. If `sx-question-list--site' is given, items 3 and 4 should take it -into consideration. +into consideration. The same holds for `sx-question-list--order'. \\{sx-question-list-mode-map}" (hl-line-mode 1) -- cgit v1.2.3 From db202249de34136cf43b9f9926d41f0964a184c6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:30:03 +0000 Subject: Define sx-question-list--interactive-order-prompt --- sx-question-list.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index 04004b3..d2745db 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -230,6 +230,22 @@ This is ignored if `sx-question-list--refresh-function' is set.") ": Quit") "Header-line used on the question list.") +(defconst sx-question-list--order-methods + '(("Recent Activity" . activity) + ("Creation Date" . creation) + ("Most Voted" . votes) + ("Hot" . hot)) + "Alist of possible values to be passed to the `sort' keyword.") + +(defun sx-question-list--interactive-order-prompt (&optional prompt) + "Interactively prompt for a sorting order. +PROMPT is displayed to the user. If it is omitted, a default one +is used." + (let ((order (sx-completing-read + (or prompt "Order questions by: ") + (mapcar #'car sx-question-list--order-methods)))) + (cdr-safe (assoc-string order sx-question-list--order-methods)))) + ;;; Mode Definition (define-derived-mode sx-question-list-mode -- cgit v1.2.3 From 3293b8a2f75aa92c348cfa82e60b6e5a1e39f088 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:30:23 +0000 Subject: Define sx-question-list-order-by Command for switching the ordering method. --- sx-question-list.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index d2745db..907ff39 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -616,6 +616,19 @@ Sets `sx-question-list--site' and then call (setq sx-question-list--site site) (sx-question-list-refresh 'redisplay))) +(defun sx-question-list-order-by (sort) + "Order questions in the current list by the method SORT. +Sets `sx-question-list--order' and then calls +`sx-question-list-refresh' with `redisplay'." + (interactive + (list (when sx-question-list--order + (sx-question-list--interactive-order-prompt)))) + (unless sx-question-list--order + (sx-user-error "This list can't be reordered")) + (when (and sort (symbolp sort)) + (setq sx-question-list--order sort) + (sx-question-list-refresh 'redisplay))) + (provide 'sx-question-list) ;;; sx-question-list.el ends here -- cgit v1.2.3 From 0f6749ea36669ed0d8be4f284244813ea30ff4cd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:41:08 +0000 Subject: Improve order-methods --- sx-question-list.el | 2 ++ 1 file changed, 2 insertions(+) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index 907ff39..7757503 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -234,8 +234,10 @@ This is ignored if `sx-question-list--refresh-function' is set.") '(("Recent Activity" . activity) ("Creation Date" . creation) ("Most Voted" . votes) + ("Score" . votes) ("Hot" . hot)) "Alist of possible values to be passed to the `sort' keyword.") +(make-variable-buffer-local 'sx-question-list--order-methods) (defun sx-question-list--interactive-order-prompt (&optional prompt) "Interactively prompt for a sorting order. -- cgit v1.2.3