From 598450c62e7ecc971b4cc5227343da10360ba978 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 15 Nov 2014 01:31:08 +0000 Subject: Close question window with q --- sx-question-list.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index a1dec7a..c6eb58e 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -285,7 +285,7 @@ focus the relevant window." (null (equal sx-question-mode--window (selected-window)))) (setq sx-question-mode--window (condition-case er - (split-window-below sx-question-list-height) + (split-window (selected-window) sx-question-list-height 'below) (error ;; If the window is too small to split, use current one. (if (string-match @@ -293,7 +293,15 @@ focus the relevant window." (car (cdr-safe er))) nil (error (cdr er))))))) + ;; Display the question. (sx-question-mode--display data sx-question-mode--window) + ;; Configure the window to be closed on `q'. + (set-window-prev-buffers sx-question-mode--window nil) + (set-window-parameter + sx-question-mode--window + 'quit-restore + ;; See https://www.gnu.org/software/emacs/manual/html_node/elisp/Window-Parameters.html#Window-Parameters + `(window window ,(selected-window) ,sx-question-mode--buffer)) (when focus (if sx-question-mode--window (select-window sx-question-mode--window) -- 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-list.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 46166a8a16f6e0c92d2cfc676ab7f302355fa2a1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 15 Nov 2014 02:28:34 +0000 Subject: Question list now makes use of read-p --- sx-question-list.el | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'sx-question-list.el') diff --git a/sx-question-list.el b/sx-question-list.el index 82f0017..e0bf300 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -183,10 +183,10 @@ Letters do not insert themselves; instead, they are commands. (defun sx-question-list-refresh (&optional redisplay no-update) "Update the list of questions. -If REDISPLAY is non-nil, also call `tabulated-list-print'. +If REDISPLAY is non-nil (or if interactive), also call `tabulated-list-print'. If the prefix argument NO-UPDATE is nil, query StackExchange for a new list before redisplaying." - (interactive "pP") + (interactive "p\nP") ;; Reset the mode-line unread count (we rebuild it here). (setq sx-question-list--unread-count 0) (let ((question-list @@ -206,7 +206,9 @@ a new list before redisplaying." (unless data (setq data (tabulated-list-get-id))) (unless data (error "No question here!")) (sx-assoc-let data - (browse-url .link))) + (browse-url .link)) + (sx-question--mark-read data) + (sx-question-list-refresh 'redisplay 'no-update)) (defcustom sx-question-list-ago-string " ago" "String appended to descriptions of the time since something happened. @@ -274,9 +276,10 @@ focus the relevant window." (interactive '(nil t)) (unless data (setq data (tabulated-list-get-id))) (unless data (error "No question here!")) - (when (sx-question--read-p data) + (unless (sx-question--read-p data) (cl-decf sx-question-list--unread-count) - (sx-question--mark-read data)) + (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)))) (setq sx-question-mode--window -- 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-list.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