diff options
Diffstat (limited to 'sx-question-list.el')
-rw-r--r-- | sx-question-list.el | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/sx-question-list.el b/sx-question-list.el index a164706..c6d298a 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -25,7 +25,9 @@ (require 'sx) (require 'sx-time) +(require 'sx-site) (require 'sx-question) +(require 'sx-question-mode) ;;; Customization @@ -69,7 +71,7 @@ :group 'sx-question-list-faces) (defface sx-question-list-tags - '((t :inherit font-lock-function-name-face)) + '((t :inherit sx-question-mode-tags)) "" :group 'sx-question-list-faces) @@ -132,6 +134,8 @@ Letters do not insert themselves; instead, they are commands. ("j" sx-question-list-view-next) ("k" sx-question-list-view-previous) ("g" sx-question-list-refresh) + (":" sx-question-list-switch-site) + ("v" sx-question-list-visit) ([?\r] sx-question-list-display-question))) (defvar sx-question-list--current-page "Latest" @@ -178,6 +182,9 @@ Letters do not insert themselves; instead, they are commands. (defvar sx-question-list--current-site "emacs" "Site being displayed in the *question-list* buffer.") +(defvar sx-question-list--current-dataset nil + "") + (defun sx-question-list-refresh (&optional redisplay no-update) "Update the list of questions. If REDISPLAY is non-nil, also call `tabulated-list-print'. @@ -186,13 +193,25 @@ a new list before redisplaying." (interactive "pP") ;; Reset the mode-line unread count (we rebuild it here). (setq sx-question-list--unread-count 0) - (let ((question-list (sx-question-get-questions - sx-question-list--current-site))) + (let ((question-list + (if (and no-update sx-question-list--current-dataset) + sx-question-list--current-dataset + (sx-question-get-questions + sx-question-list--current-site)))) + (setq sx-question-list--current-dataset question-list) ;; Print the result. (setq tabulated-list-entries (mapcar #'sx-question-list--print-info question-list))) (when redisplay (tabulated-list-print 'remember))) +(defun sx-question-list-visit (&optional data) + "Visits question under point (or from DATA) using `browse-url'." + (interactive) + (unless data (setq data (tabulated-list-get-id))) + (unless data (error "No question here!")) + (sx-assoc-let data + (browse-url .link))) + (defcustom sx-question-list-ago-string " ago" "String appended to descriptions of the time since something happened. Used in the questions list to indicate a question was updated \"4d ago\"." @@ -205,26 +224,27 @@ Used in the questions list to indicate a question was updated \"4d ago\"." (list data (vector - (list (int-to-string score) - 'face (if upvoted 'sx-question-list-score-upvoted + (list (int-to-string .score) + '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) + (list (int-to-string .answer_count) + '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) + .title + '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) 'sx-question-list-unread-question)) (propertize " " 'display "\n ") - (propertize (concat (sx-time-since last_activity_date) + (propertize (concat (sx-time-since .last_activity_date) sx-question-list-ago-string) 'face 'sx-question-list-date) - (propertize (concat " [" (mapconcat #'identity tags "] [") "]") + " " + (propertize (mapconcat #'sx-question--tag-format .tags " ") 'face 'sx-question-list-tags) (propertize " " 'display "\n")))))) @@ -261,8 +281,9 @@ focus the relevant window." (when (sx-question--read-p data) (cl-decf sx-question-list--unread-count) (sx-question--mark-read data)) - (unless (window-live-p sx-question--window) - (setq sx-question--window + (unless (and (window-live-p sx-question-mode--window) + (null (equal sx-question-mode--window (selected-window)))) + (setq sx-question-mode--window (condition-case er (split-window-below sx-question-list-height) (error @@ -272,11 +293,22 @@ focus the relevant window." (car (cdr-safe er))) nil (error (cdr er))))))) - (sx-question--display data sx-question--window) + (sx-question-mode--display data sx-question-mode--window) (when focus - (if sx-question--window - (select-window sx-question--window) - (switch-to-buffer sx-question--buffer)))) + (if sx-question-mode--window + (select-window sx-question-mode--window) + (switch-to-buffer sx-question-mode--buffer)))) + +(defun sx-question-list-switch-site (site) + "Switch the current site to SITE and display its questions" + (interactive + (list (funcall (if ido-mode #'ido-completing-read #'completing-read) + "Switch to site: " (sx-site-get-api-tokens) + (lambda (site) + (not (equal site sx-question-list--current-site))) + t))) + (setq sx-question-list--current-site site) + (sx-question-list-refresh 'redisplay)) (defvar sx-question-list--buffer nil "Buffer where the list of questions is displayed.") |