From f26a55ce664d1840efef36079ab3634394006c5b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 29 Nov 2014 00:00:28 +0000 Subject: Fix byte-compile warnings Fixes #115 --- sx-question.el | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index 01ba030..f80a9bd 100644 --- a/sx-question.el +++ b/sx-question.el @@ -134,20 +134,21 @@ If no cache exists for it, initialize one with SITE." (defun sx-question--mark-hidden (question) "Mark QUESTION as being hidden." - (let ((site-cell (assoc .site sx-question--user-hidden-list)) - cell) - ;; If question already hidden, do nothing. - (unless (memq .question_id site-cell) - ;; First question from this site. - (push (list .site .question_id) sx-question--user-hidden-list) - ;; Question wasn't present. - ;; Add it in, but make sure it's sorted (just in case we need - ;; it later). - (sx-sorted-insert-skip-first .question_id 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 'hidden-questions sx-question--user-hidden-list)))) + (sx-assoc-let question + (let ((site-cell (assoc .site sx-question--user-hidden-list)) + cell) + ;; If question already hidden, do nothing. + (unless (memq .question_id site-cell) + ;; First question from this site. + (push (list .site .question_id) sx-question--user-hidden-list) + ;; Question wasn't present. + ;; Add it in, but make sure it's sorted (just in case we need + ;; it later). + (sx-sorted-insert-skip-first .question_id 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 'hidden-questions sx-question--user-hidden-list))))) ;;;; Other data -- cgit v1.2.3 From f0d788a34a6d3e9ea564299703c35eee26f64374 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 01:29:44 +0000 Subject: sx-question--mark-read returns nil if nothing changed --- sx-question-list.el | 3 +-- sx-question.el | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 22 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question-list.el b/sx-question-list.el index 01cdc61..9185531 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -491,8 +491,7 @@ relevant window." (interactive '(nil t)) (unless data (setq data (tabulated-list-get-id))) (unless data (error "No question here!")) - (unless (sx-question--read-p data) - (sx-question--mark-read data) + (when (sx-question--mark-read data) (sx-question-list-refresh 'redisplay 'no-update)) (unless (and (window-live-p sx-question-mode--window) (null (equal sx-question-mode--window (selected-window)))) diff --git a/sx-question.el b/sx-question.el index f80a9bd..24fd97f 100644 --- a/sx-question.el +++ b/sx-question.el @@ -86,27 +86,32 @@ See `sx-question--user-read-list'." (defun sx-question--mark-read (question) "Mark QUESTION as being read until it is updated again. +Returns nil if question (in its current state) was already marked +read, i.e., if it was `sx-question--read-p'. See `sx-question--user-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) - (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 - (sx-sorted-insert-skip-first - q-cell site-cell (lambda (x y) (> (car x) (car y)))))))) - ;; Save the results. - ;; @TODO This causes a small lag on `j' and `k' as the list gets - ;; large. Should we do this on a timer? - (sx-cache-set 'read-questions sx-question--user-read-list)) + (prog1 + (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) + (cond + ;; First question from this site. + ((null site-cell) + (push (list .site q-cell) sx-question--user-read-list)) + ;; Question already present. + ((setq cell (assoc .question_id site-cell)) + ;; Current version is newer than cached version. + (when (> .last_activity_date (cdr cell)) + (setcdr cell .last_activity_date))) + ;; Question wasn't present. + (t + (sx-sorted-insert-skip-first + q-cell site-cell (lambda (x y) (> (car x) (car y)))))))) + ;; Save the results. + ;; @TODO This causes a small lag on `j' and `k' as the list gets + ;; large. Should we do this on a timer? + (sx-cache-set 'read-questions sx-question--user-read-list))) ;;;; Hidden -- cgit v1.2.3 From 039ef045855fa4e2c039e228dda998d2173eca01 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 02:50:10 +0000 Subject: sx-question-get-questions takes arbitrary keywords. --- sx-question.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'sx-question.el') diff --git a/sx-question.el b/sx-question.el index f80a9bd..00b5f7f 100644 --- a/sx-question.el +++ b/sx-question.el @@ -26,15 +26,17 @@ (require 'sx-filter) (require 'sx-method) -(defun sx-question-get-questions (site &optional page) +(defun sx-question-get-questions (site &optional page keywords) "Get SITE questions. Return page PAGE (the first if nil). Return a list of question. Each question is an alist of properties returned by the API with an added (site SITE) property. +KEYWORDS are added to the method call along with PAGE. + `sx-method-call' is used with `sx-browse-filter'." (sx-method-call 'questions - :keywords `((page . ,page)) + :keywords `((page . ,page) ,@keywords) :site site :auth t :filter sx-browse-filter)) -- cgit v1.2.3