aboutsummaryrefslogtreecommitdiff
path: root/sx-tab.el
diff options
context:
space:
mode:
Diffstat (limited to 'sx-tab.el')
-rw-r--r--sx-tab.el117
1 files changed, 96 insertions, 21 deletions
diff --git a/sx-tab.el b/sx-tab.el
index 86aaf3c..2b3f20a 100644
--- a/sx-tab.el
+++ b/sx-tab.el
@@ -1,4 +1,4 @@
-;;; sx-tab.el --- functions for viewing different tabs -*- lexical-binding: t -*-
+;;; sx-tab.el --- functions for viewing different tabs -*- lexical-binding: t; -*-
;; Copyright (C) 2014 Artur Malabarba
@@ -24,32 +24,35 @@
;;; Tabs:
-;; - frontpage :: the frontpage of a single site
-
-
-;;; Code:
+;; - FrontPage :: The standard front page
+;; - Newest :: Newest questions
+;; - TopVoted :: Top-voted questions
+;; - Hot :: Hot questions recently
+;; - Week :: Hot questions for the week
+;; - Month :: Hot questions for the month
+;; - Unanswered :: Unanswered questions
+;; - Unanswered My-tags :: Unanswered questions (subscribed tags)
+;; - Featured :: Featured questions
+;; - Starred :: Favorite questions
(require 'sx)
(require 'sx-question-list)
(require 'sx-interaction)
-(defcustom sx-tab-default-site "emacs"
- "Name of the site to use by default when listing questions."
- :type 'string
- :group 'sx)
-
-(defvar sx-tab--list nil
+(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)))
+ (list (sx-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)))))
+
+;;; The main macro
(defmacro sx-tab--define (tab pager &optional printer refresher
&rest body)
"Define a StackExchange tab called TAB.
@@ -80,16 +83,13 @@ variables, but before refreshing the display."
,(format "Display a list of %s questions for SITE.
NO-UPDATE (the prefix arg) is passed to `sx-question-list-refresh'.
-If SITE is nil, use `sx-tab-default-site'."
+If SITE is nil, use `sx-default-site'."
tab)
(interactive
(list current-prefix-arg
- (funcall (if ido-mode #'ido-completing-read #'completing-read)
- (format "Site (%s): " sx-tab-default-site)
- (sx-site-get-api-tokens) nil t nil nil
- sx-tab-default-site)))
+ (sx--interactive-site-prompt)))
(sx-initialize)
- (unless site (setq site sx-tab-default-site))
+ (unless site (setq site sx-default-site))
;; Create the buffer
(unless (buffer-live-p ,buffer-variable)
(setq ,buffer-variable
@@ -200,6 +200,81 @@ If SITE is nil, use `sx-tab-default-site'."
(file-name-directory load-file-name)))
nil t)
+
+;;; Unanswered
+(sx-tab--define "Unanswered"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page nil 'unanswered)))
+;;;###autoload
+(autoload 'sx-tab-unanswered
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+;;; Unanswered My-tags
+(sx-tab--define "Unanswered-my-tags"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page nil 'unanswered/my-tags)))
+;;;###autoload
+(autoload 'sx-tab-unanswered
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+;;; Featured
+(sx-tab--define "Featured"
+ (lambda (page)
+ (sx-question-get-questions
+ sx-question-list--site page nil 'featured)))
+;;;###autoload
+(autoload 'sx-tab-featured
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+;;; Starred
+(sx-tab--define "Starred"
+ (lambda (page)
+ (sx-method-call 'me
+ :page page
+ :site sx-question-list--site
+ :auth t
+ :submethod 'favorites
+ :filter sx-browse-filter)))
+;;;###autoload
+(autoload 'sx-tab-featured
+ (expand-file-name
+ "sx-tab"
+ (when load-file-name
+ (file-name-directory load-file-name)))
+ nil t)
+
+
+;;; Inter-modes navigation
+(defun sx-tab-meta-or-main ()
+ "Switch to the meta version of a main site, or vice-versa.
+Inside a question, go to the frontpage of the site this question
+belongs to."
+ (interactive)
+ (if (and (derived-mode-p 'sx-question-list-mode)
+ sx-question-list--site)
+ (sx-question-list-switch-site
+ (if (string-match "\\`meta\\." sx-question-list--site)
+ (replace-match "" :fixedcase nil sx-question-list--site)
+ (concat "meta." sx-question-list--site)))
+ (sx-tab-frontpage nil (sx--site (sx--data-here 'question)))))
+
(provide 'sx-tab)
;;; sx-tab.el ends here