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(-) 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 From 3e4386a0ec6383eb92ae5535db165c82ed7092b2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 03:07:32 +0000 Subject: Define 5 new tabs, as per http://api.stackexchange.com/docs/questions --- sx-tab.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/sx-tab.el b/sx-tab.el index 7ccbf18..1152528 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -96,7 +96,7 @@ If SITE is nil, use `sx-tab-default-site'." (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 @@ -105,5 +105,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 -- cgit v1.2.3 From 10597c39adbcf775841f908452082ed344110ce9 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 03:08:52 +0000 Subject: Define command for changing tab --- sx-tab.el | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/sx-tab.el b/sx-tab.el index 1152528..b497ce0 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -32,6 +32,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. @@ -55,7 +67,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) @@ -63,7 +75,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) @@ -89,7 +101,10 @@ 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 -- cgit v1.2.3 From 4f4b4d9f9a1000ce5f91e6d835cb71268f9525ec Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Mon, 1 Dec 2014 03:08:59 +0000 Subject: Bind sx-tab-switch to t in question list Fixes #17 --- sx-question-list.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-question-list.el b/sx-question-list.el index 9709b99..852c11a 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -299,6 +299,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) -- cgit v1.2.3