From f6699988fd521703c1d44489e3d89c6f71d418df Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 11 Nov 2014 12:12:30 -0500 Subject: Move question sorting function to sx.el It is not specific to questions -- it is generally applicable to any alist. --- sx-question.el | 6 ------ 1 file changed, 6 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index 20a71cc..601875f 100644 --- a/sx-question.el +++ b/sx-question.el @@ -56,12 +56,6 @@ "Mark QUESTION as being read, until it is updated again." nil) -(defun sx-question--< (property x y &optional pred) - "Non-nil if PROPERTY attribute of question X is less than that of Y. -With optional argument predicate, use it instead of `<'." - (funcall (or pred #'<) - (cdr (assoc property x)) - (cdr (assoc property y)))) ;;; Displaying a question (defvar sx-question--window nil -- cgit v1.2.3 From 6a2252c6e6aec21cb9c9336b706947343f9e4fa6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 15 Nov 2014 01:52:27 +0000 Subject: Highlighting accepted answers actually works now. --- sx-question-list.el | 10 +++------- sx-question.el | 8 +++++--- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question-list.el b/sx-question-list.el index c6eb58e..82f0017 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -51,11 +51,7 @@ :group 'sx-question-list-faces) (defface sx-question-list-answers-accepted - '((((background light)) :background "YellowGreen" - :inherit sx-question-list-answers) - (((background dark)) :background "DarkOliveGreen" - :inherit sx-question-list-answers) - (t :inherit sx-question-list-answers)) + '((t :underline t :overline t :inherit sx-question-list-answers)) "" :group 'sx-question-list-faces) @@ -228,13 +224,13 @@ Used in the questions list to indicate a question was updated \"4d ago\"." 'face (if .upvoted 'sx-question-list-score-upvoted 'sx-question-list-score)) (list (int-to-string .answer_count) - 'face (if (sx-question--accepted-answer .data) + 'face (if (sx-question--accepted-answer data) 'sx-question-list-answers-accepted 'sx-question-list-answers)) (concat (propertize .title - 'face (if (sx-question--read-p .data) + 'face (if (sx-question--read-p data) 'sx-question-list-read-question ;; Increment `sx-question-list--unread-count' for the mode-line. (cl-incf sx-question-list--unread-count) diff --git a/sx-question.el b/sx-question.el index d15cc80..19251ab 100644 --- a/sx-question.el +++ b/sx-question.el @@ -34,6 +34,7 @@ question.comments question.answers question.last_editor + question.accepted_answer_id user.display_name comment.owner comment.body_markdown @@ -69,10 +70,11 @@ ;; @TODO: (cl-evenp (random))) -(defun sx-question--accepted-answer (question) +(defun sx-question--accepted-answer-id (question) "Return accepted answer in QUESTION, or nil if none." - ;; @TODO: - (cl-evenp (random))) + (sx-assoc-let question + (and (integerp .accepted_answer_id) + .accepted_answer_id))) (defun sx-question--mark-read (question) "Mark QUESTION as being read, until it is updated again." -- cgit v1.2.3 From c0c46f3bed3479f14065d1d28cad63217f9473bc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 15 Nov 2014 02:05:56 +0000 Subject: Add site date to questions --- sx-question.el | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index 19251ab..607b3f6 100644 --- a/sx-question.el +++ b/sx-question.el @@ -47,11 +47,13 @@ (defun sx-question-get-questions (site &optional page) "Get the page PAGE of questions from SITE." - (sx-method-call - "questions" - `((site . ,site) - (page . ,page)) - sx-question-browse-filter)) + (mapcar + (lambda (question) (cons (cons 'site site) question)) + (sx-method-call + "questions" + `((site . ,site) + (page . ,page)) + sx-question-browse-filter))) (defun sx-question-get-question (site id) "Get the question ID from SITE." -- cgit v1.2.3 From ef241cbf39b57a24f8464d35a8616df7833101cc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 15 Nov 2014 02:28:12 +0000 Subject: sx-question-read-p and mark-read actually work --- sx-question.el | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index 607b3f6..76f9a67 100644 --- a/sx-question.el +++ b/sx-question.el @@ -67,10 +67,18 @@ ;;; Question Properties +(defvar sx-question--user-read-list nil + "Alist of questions read by the user. +Each element has the form (SITE . QUESTION-LIST). +And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE).") + (defun sx-question--read-p (question) "Non-nil if QUESTION has been read since last updated." - ;; @TODO: - (cl-evenp (random))) + (sx-assoc-let question + (let ((ql (cdr (assoc .site sx-question--user-read-list)))) + (and ql + (>= (or (cdr (assoc .question_id ql)) 0) + .last_activity_date))))) (defun sx-question--accepted-answer-id (question) "Return accepted answer in QUESTION, or nil if none." @@ -80,7 +88,22 @@ (defun sx-question--mark-read (question) "Mark QUESTION as being read, until it is updated again." - nil) + (sx-assoc-let question + (let ((site-cell (assoc .site sx-question--user-read-list)) + (q-cell (cons .question_id .last_activity_date)) + cell) + (cond + ;; First question from this site. + ((null site-cell) + (push (list .site q-cell) sx-question--user-read-list)) + ;; Question already has an older time. + ((setq cell (assoc .question_id site-cell)) + (setcdr cell .last_activity_date)) + ;; Question wasn't present. + (t + (setcdr site-cell (cons q-cell (cdr site-cell))))))) + ;; Save the results. + (sx-cache-set 'read-questions sx-question--user-read-list)) (defun sx-question--< (property x y &optional pred) "Non-nil if PROPERTY attribute of question X is less than that of Y. -- cgit v1.2.3 From 884363ac75fe0c5f8e082c31cfeb8632ad85f19e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 15 Nov 2014 02:38:22 +0000 Subject: Ensure we don't overwrite the cache --- sx-question.el | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index 76f9a67..7debf4f 100644 --- a/sx-question.el +++ b/sx-question.el @@ -72,22 +72,24 @@ Each element has the form (SITE . QUESTION-LIST). And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE).") +(defun sx-question--ensure-read-list () + "Ensure the `sx-question--user-read-list' has been read from cache." + (unless sx-question--user-read-list + (setq sx-question--user-read-list + (sx-cache-get 'read-questions)))) + (defun sx-question--read-p (question) "Non-nil if QUESTION has been read since last updated." + (sx-question--ensure-read-list) (sx-assoc-let question (let ((ql (cdr (assoc .site sx-question--user-read-list)))) (and ql (>= (or (cdr (assoc .question_id ql)) 0) .last_activity_date))))) -(defun sx-question--accepted-answer-id (question) - "Return accepted answer in QUESTION, or nil if none." - (sx-assoc-let question - (and (integerp .accepted_answer_id) - .accepted_answer_id))) - (defun sx-question--mark-read (question) "Mark QUESTION as being read, until it is updated again." + (sx-question--ensure-read-list) (sx-assoc-let question (let ((site-cell (assoc .site sx-question--user-read-list)) (q-cell (cons .question_id .last_activity_date)) @@ -105,6 +107,12 @@ And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE). ;; Save the results. (sx-cache-set 'read-questions sx-question--user-read-list)) +(defun sx-question--accepted-answer-id (question) + "Return accepted answer in QUESTION, or nil if none." + (sx-assoc-let question + (and (integerp .accepted_answer_id) + .accepted_answer_id))) + (defun sx-question--< (property x y &optional pred) "Non-nil if PROPERTY attribute of question X is less than that of Y. With optional argument predicate, use it instead of `<'." -- cgit v1.2.3 From fe57abe554146382b60289523d5122d76e20781c Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 15 Nov 2014 02:49:53 +0000 Subject: Finish merge --- sx-question-list.el | 2 +- sx-question.el | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question-list.el b/sx-question-list.el index 773ce0d..b220097 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -226,7 +226,7 @@ Used in the questions list to indicate a question was updated \"4d ago\"." 'face (if .upvoted 'sx-question-list-score-upvoted 'sx-question-list-score)) (list (int-to-string .answer_count) - 'face (if (sx-question--accepted-answer data) + 'face (if (sx-question--accepted-answer-id data) 'sx-question-list-answers-accepted 'sx-question-list-answers)) (concat diff --git a/sx-question.el b/sx-question.el index 768e5db..fc44bd8 100644 --- a/sx-question.el +++ b/sx-question.el @@ -71,16 +71,17 @@ Each element has the form (SITE . QUESTION-LIST). And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE).") -(defun sx-question--ensure-read-list () - "Ensure the `sx-question--user-read-list' has been read from cache." +(defun sx-question--ensure-read-list (site) + "Ensure the `sx-question--user-read-list' has been read from cache. +If no cache exists for it, initialize one with SITE." (unless sx-question--user-read-list (setq sx-question--user-read-list - (sx-cache-get 'read-questions)))) + (sx-cache-get 'read-questions `(list ,site))))) (defun sx-question--read-p (question) "Non-nil if QUESTION has been read since last updated." - (sx-question--ensure-read-list) (sx-assoc-let question + (sx-question--ensure-read-list .site) (let ((ql (cdr (assoc .site sx-question--user-read-list)))) (and ql (>= (or (cdr (assoc .question_id ql)) 0) @@ -88,8 +89,8 @@ And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE). (defun sx-question--mark-read (question) "Mark QUESTION as being read, until it is updated again." - (sx-question--ensure-read-list) (sx-assoc-let question + (sx-question--ensure-read-list .site) (let ((site-cell (assoc .site sx-question--user-read-list)) (q-cell (cons .question_id .last_activity_date)) cell) @@ -103,6 +104,8 @@ And each element in QUESTION-LIST has the form (QUESTION_ID . LAST-VIEWED-DATE). ;; Question wasn't present. (t (setcdr site-cell (cons q-cell (cdr site-cell))))))) + ;; This causes a small lag on `j' and `k' as the list gets large. + ;; Should we do this on a timer? ;; Save the results. (sx-cache-set 'read-questions sx-question--user-read-list)) -- cgit v1.2.3