aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-question-list.el1
-rw-r--r--sx-question.el6
-rw-r--r--sx-tab.el97
3 files changed, 98 insertions, 6 deletions
diff --git a/sx-question-list.el b/sx-question-list.el
index 18f8ba0..e2eb2b6 100644
--- a/sx-question-list.el
+++ b/sx-question-list.el
@@ -296,6 +296,7 @@ into consideration.
("K" sx-question-list-previous-far)
("g" sx-question-list-refresh)
(":" sx-question-list-switch-site)
+ ("t" sx-question-list-switch-tab)
("v" sx-visit)
("u" sx-toggle-upvote)
("d" sx-toggle-downvote)
diff --git a/sx-question.el b/sx-question.el
index 24fd97f..c4b2445 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))
diff --git a/sx-tab.el b/sx-tab.el
index 0ec9551..4978ba8 100644
--- a/sx-tab.el
+++ b/sx-tab.el
@@ -33,6 +33,18 @@
:type 'string
:group 'sx)
+(defvar sx-tab--list nil
+ "List of the names of all defined tabs.")
+
+(defun sx-tab-switch (tab)
+ "Switch to another question-list tab."
+ (interactive
+ (list (funcall (if ido-mode #'ido-completing-read #'completing-read)
+ "Switch to tab: " sx-tab--list
+ (lambda (tab) (not (equal tab sx-question-list--current-tab)))
+ t)))
+ (funcall (intern (format "sx-tab-%s" (downcase tab)))))
+
(defmacro sx-tab--define (tab pager &optional printer refresher
&rest body)
"Define a StackExchange tab called TAB.
@@ -56,7 +68,7 @@ variables, but before refreshing the display."
`(progn
(defvar ,buffer-variable nil
,(format "Buffer where the %s questions are displayed."
- tab))
+ tab))
(defun
,(intern (concat "sx-tab-" name))
(&optional no-update site)
@@ -64,7 +76,7 @@ variables, but before refreshing the display."
NO-UPDATE (the prefix arg) is passed to `sx-question-list-refresh'.
If SITE is nil, use `sx-tab-default-site'."
- tab)
+ tab)
(interactive
(list current-prefix-arg
(funcall (if ido-mode #'ido-completing-read #'completing-read)
@@ -90,14 +102,17 @@ If SITE is nil, use `sx-tab-default-site'."
(setq sx-question-list--current-tab ,tab)
,@body
(sx-question-list-refresh 'redisplay no-update))
- (switch-to-buffer ,buffer-variable)))))
+ (switch-to-buffer ,buffer-variable))
+ ;; Add this tab to the list of existing tabs. So we can prompt
+ ;; the user with completion and stuff.
+ (add-to-list 'sx-tab--list ,tab))))
;;; FrontPage
(sx-tab--define "FrontPage"
(lambda (page)
(sx-question-get-questions
- sx-question-list--site page)))
+ sx-question-list--site page '((sort . activity)))))
;;;###autoload
(autoload 'sx-tab-frontpage
(expand-file-name
@@ -106,5 +121,79 @@ If SITE is nil, use `sx-tab-default-site'."
(file-name-directory load-file-name)))
nil t)
+
+;;; Newest
+(sx-tab--define "Newest"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page '((sort . creation)))))
+;;;###autoload
+(autoload 'sx-tab-newest
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+
+;;; TopVoted
+(sx-tab--define "TopVoted"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page '((sort . votes)))))
+;;;###autoload
+(autoload 'sx-tab-topvoted
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+
+;;; Hot
+(sx-tab--define "Hot"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page '((sort . hot)))))
+;;;###autoload
+(autoload 'sx-tab-hot
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+
+;;; Week
+(sx-tab--define "Week"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page '((sort . week)))))
+;;;###autoload
+(autoload 'sx-tab-week
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+
+;;; Month
+(sx-tab--define "Month"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page '((sort . month)))))
+;;;###autoload
+(autoload 'sx-tab-month
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
(provide 'sx-tab)
;;; sx-tab.el ends here