From 7da9b2567c2635dfab5f9400fb76297f61b80be4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 16:57:49 -0500 Subject: Test sx-time-since --- test/test-printing.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 6225bf6..60382b2 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -27,6 +27,18 @@ after being run through `sx-question--tag-format'." ;;; Tests +(ert-deftest time-since () + (cl-letf (((symbol-function #'float-time) + (lambda () 1420148997.))) + (should + (string= + "67m" + (sx-time-since 1420145000.))) + (should + (string= + "12h" + (sx-time-since 1420105000.))))) + (ert-deftest question-list-tag () "Test `sx-question--tag-format'." (should -- cgit v1.2.3 From 54849b2564c3d9bb95bc3512b568e30aa21a3db4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 23:29:55 -0500 Subject: Update Makefile Clean compiled files before every test. This ensures that the changes made during the current session are applied when re-testing. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7b0b698..a72bea1 100644 --- a/Makefile +++ b/Makefile @@ -25,6 +25,7 @@ $(VERSIONS) :: evm use emacs-24.$@-bin emacs --version cask install + cask clean-elc emacs --batch -L . -l ert -l test/tests.el -f ert-run-tests-batch-and-exit install_cask: -- cgit v1.2.3 From 3b275a93789a568d23ece65086ffebb8de430f3a Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 23:40:20 -0500 Subject: Add test for user entry functions --- test/tests.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/tests.el b/test/tests.el index d709600..7bfc86c 100644 --- a/test/tests.el +++ b/test/tests.el @@ -59,3 +59,19 @@ (mapc #'sx-load-test '(api macros printing util)) + +(ert-deftest user-entry-functions () + "Ensures all entry functions are autoloaded." + (should + (cl-every + #'fboundp + '(sx-ask + sx-authenticate + sx-bug-report + sx-tab-frontpage + sx-tab-hot + sx-tab-month + sx-tab-newest + sx-tab-topvoted + sx-tab-week + sx-version)))) -- cgit v1.2.3 From 7a75cd61e822a4895b85bc17780b163bd6876ca7 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 4 Jan 2015 17:26:16 -0500 Subject: Add more autoloads to test --- test/tests.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/tests.el b/test/tests.el index 5eec57c..493d7dc 100644 --- a/test/tests.el +++ b/test/tests.el @@ -69,10 +69,14 @@ '(sx-ask sx-authenticate sx-bug-report + sx-switchto-map + sx-tab-featured sx-tab-frontpage sx-tab-hot sx-tab-month sx-tab-newest + sx-tab-starred sx-tab-topvoted + sx-tab-unanswered sx-tab-week sx-version)))) -- cgit v1.2.3 From 802f778bb28506d9be92618913c8db0cb4eda539 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 16 Jan 2015 12:42:53 -0200 Subject: load test-state --- test/tests.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.el b/test/tests.el index 493d7dc..be1552b 100644 --- a/test/tests.el +++ b/test/tests.el @@ -59,7 +59,7 @@ (apply #'message message args))) (mapc #'sx-load-test - '(api macros printing util search)) + '(api macros printing util search state)) (ert-deftest user-entry-functions () "Ensures all entry functions are autoloaded." -- cgit v1.2.3 From 148da420d9f464f3cc8046fed99a103af0fd7bed Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Fri, 16 Jan 2015 12:52:14 -0200 Subject: Test displaying a question --- test/test-printing.el | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 677dca3..9512a5e 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -146,6 +146,14 @@ after being run through `sx-question--tag-format'." (should (equal object '((answers . [something "answer"])))))) + +;;; question-mode +(ert-deftest sx-display-question () + (should + (sx-display-question sx-test-data-questions)) + (should-error + (sx-display-question sx-test-data-questions nil 1))) + (ert-deftest sx-question-mode--fill-and-fontify () "Check complicated questions are filled correctly." (should @@ -202,3 +210,4 @@ if you used the Stack Exchange login method, you'd... [1]: http://i.stack.imgur.com/ktFTs.png [2]: http://i.stack.imgur.com/5l2AY.png [3]: http://i.stack.imgur.com/22myl.png"))) + -- cgit v1.2.3 From 2de9020ac40daedab8ca0df194e8f4eb6ae20478 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 21 Jan 2015 22:26:57 -0200 Subject: Fix the universe and make the world right again. Amongst other things, this should put an end to whale hunting, malaria, and issues such as #238, #209 and #206. --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index 2650c55..8f672ec 100644 --- a/sx-request.el +++ b/sx-request.el @@ -160,7 +160,7 @@ the main content of the response is returned." (url-inhibit-uncompression t) (url-request-data (sx-request--build-keyword-arguments args nil)) (request-url (concat sx-request-api-root method)) - (url-request-method (and request-method (symbol-name request-method))) + (url-request-method (and request-method (upcase (symbol-name request-method)))) (url-request-extra-headers '(("Content-Type" . "application/x-www-form-urlencoded"))) (response-buffer (url-retrieve-synchronously request-url))) -- cgit v1.2.3 From a2d526c4b12ffa1cece78be7e6bfedf0b2b60576 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 24 Jan 2015 01:01:37 -0200 Subject: Less demanding final regexp for questions. --- sx.el | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/sx.el b/sx.el index e0609a7..26151b3 100644 --- a/sx.el +++ b/sx.el @@ -148,12 +148,7 @@ with a `link' property)." ;; From URL (string-match (rx "/questions/" ;; Question ID - (group-n 1 (+ digit)) "/" - ;; Optional question title - (optional (+ (not (any "/"))) "/") - ;; Garbage at the end - (optional (and (any "?#") (* any))) - string-end) + (group-n 1 (+ digit)) "/") link)) (push '(type . question) result))) (push (cons 'id (string-to-number (match-string-no-properties 1 link))) -- cgit v1.2.3 From f8710a5c08185efca16fb552a3d58893282d320e Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 28 Jan 2015 16:53:55 -0600 Subject: Ensure printing of full data structure for cache Bind `print-{depth,level}' to nil before writing to the file. This should force `prin1' to spell out the entire data structure. Should fix #244. --- sx-cache.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sx-cache.el b/sx-cache.el index 3e8e08f..b17149f 100644 --- a/sx-cache.el +++ b/sx-cache.el @@ -73,8 +73,9 @@ DATA will be written as returned by `prin1'. CACHE is resolved to a file name by `sx-cache-get-file-name'." (sx-cache--ensure-sx-cache-directory-exists) - (write-region (prin1-to-string data) nil - (sx-cache-get-file-name cache)) + (let (print-length print-level) + (write-region (prin1-to-string data) nil + (sx-cache-get-file-name cache))) data) (defun sx-cache--invalidate (cache &optional vars init-method) -- cgit v1.2.3 From ba4489691847ed1cff2f33f1bfa9aeda85af2a6b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 13:17:59 -0200 Subject: New function sx--squash-whitespace --- sx.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sx.el b/sx.el index 26151b3..14af94d 100644 --- a/sx.el +++ b/sx.el @@ -331,6 +331,10 @@ GET-FUNC and performs the actual comparison." (funcall ,get-func a) (funcall ,get-func b)))) +(defun sx--squash-whitespace (string) + "Return STRING with consecutive whitespace squashed together." + (replace-regexp-in-string "[ \r\n]+" " " string)) + ;;; Printing request data (defvar sx--overlays nil -- cgit v1.2.3 From f275e00c221c506cd4f22144649649e65179e3cc Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 13:20:56 -0200 Subject: Use sx--squash-whitespace in sx-question-mode--print-comment Fix #246 --- sx-question-print.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sx-question-print.el b/sx-question-print.el index f9ecfab..778b580 100644 --- a/sx-question-print.el +++ b/sx-question-print.el @@ -286,10 +286,10 @@ The comment is indented, filled, and then printed according to (format sx-question-mode-comments-format (sx-user--format "%d" .owner) (substring - ;; We fill with three spaces at the start, so the comment is - ;; slightly indented. (sx-question-mode--fill-and-fontify - (concat " " .body_markdown)) + ;; We fill with three spaces at the start, so the comment is + ;; slightly indented. + (concat " " (sx--squash-whitespace .body_markdown))) ;; Then we remove the spaces from the first line, since we'll ;; add the username there anyway. 3)))))) -- cgit v1.2.3 From 3116757fbbbd2a16a5809d316067338a9492e78f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 13:39:30 -0200 Subject: Fix test --- test/test-printing.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/test-printing.el b/test/test-printing.el index 9512a5e..1eea281 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -150,6 +150,8 @@ after being run through `sx-question--tag-format'." ;;; question-mode (ert-deftest sx-display-question () (should + (sx-display-question (elt sx-test-data-questions 0))) + (should-error (sx-display-question sx-test-data-questions)) (should-error (sx-display-question sx-test-data-questions nil 1))) -- cgit v1.2.3 From cf2e0f10498a4fe3f65d20454dee621062d194fd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 16:32:42 -0200 Subject: Really fix test --- test/test-printing.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 1eea281..bcc3dd9 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -149,8 +149,9 @@ after being run through `sx-question--tag-format'." ;;; question-mode (ert-deftest sx-display-question () - (should - (sx-display-question (elt sx-test-data-questions 0))) + ;; Check it doesn't error. + (sx-display-question (elt sx-test-data-questions 0)) + ;; Check it does error. (should-error (sx-display-question sx-test-data-questions)) (should-error -- cgit v1.2.3 From 4ed76728809666cee41336dc5191dcf982806f38 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 3 Feb 2015 16:55:21 -0200 Subject: Don't freak out because question_id is nil. --- sx-question.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sx-question.el b/sx-question.el index 1df4900..1fde1aa 100644 --- a/sx-question.el +++ b/sx-question.el @@ -148,7 +148,8 @@ See `sx-question--user-read-list'." ;; Question wasn't present. (t (sx-sorted-insert-skip-first - q-cell site-cell (lambda (x y) (> (car x) (car y)))))))) + q-cell site-cell + (lambda (x y) (> (or (car x) -1) (or (car y) -1)))))))) ;; Save the results. ;; @TODO This causes a small lag on `j' and `k' as the list gets ;; large. Should we do this on a timer? -- cgit v1.2.3 From 5c877938e4f3d8da9dbfb289d30159d7e0ab75ee Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 6 Feb 2015 21:01:53 -0600 Subject: Note MELPA release in README [ci skip] --- README.org | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.org b/README.org index b9888a7..a4db7e5 100644 --- a/README.org +++ b/README.org @@ -35,6 +35,9 @@ section. Add comments with =c=. As always, =C-h m= is the definitive resource for the functions of this mode. * Installation +SX is now available on MELPA! Install it via the usual method or run =M-x +package-install RET sx RET=. + To install the development version, follow the usual steps: - Clone this repository - Add this directory to your ~load-path~ -- cgit v1.2.3 From 2b4f8654f0c6329ba87eeb5f96910aa8e7badcfa Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 6 Feb 2015 21:09:55 -0600 Subject: Update README.org --- README.org | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.org b/README.org index a4db7e5..9bc8081 100644 --- a/README.org +++ b/README.org @@ -49,8 +49,6 @@ If you are going to be doing any asking / answering / commenting / upvoting / downvoting / /etc./, you must use ~sx-authenticate~ to provide SX with an authentication token to act on your behalf. -Eventually, this package will be available on MELPA. - * Contributing Please help contribute! Doing any of the following will help us immensely: - [[https://github.com/vermiculus/sx.el/issues/new][Open an issue]] -- cgit v1.2.3 From b9fbc65cd222e6666361667cf576063de4ca7c2e Mon Sep 17 00:00:00 2001 From: Steve Purcell Date: Sat, 7 Feb 2015 14:05:55 +0000 Subject: Add MELPA badges to README --- README.org | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.org b/README.org index 9bc8081..4071561 100644 --- a/README.org +++ b/README.org @@ -1,6 +1,8 @@ #+Title: SX -- Stack Exchange for Emacs [[https://travis-ci.org/vermiculus/sx.el][https://travis-ci.org/vermiculus/sx.el.svg?branch=master]] +[[http://melpa.org/#/sx][file:http://melpa.org/packages/sx-badge.svg]] +[[http://stable.melpa.org/#/sx][file:http://stable.melpa.org/packages/sx-badge.svg]] [[https://gitter.im/vermiculus/sx.el?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge][https://badges.gitter.im/Join Chat.svg]] [[https://www.waffle.io/vermiculus/sx.el][https://badge.waffle.io/vermiculus/sx.el.svg]] -- cgit v1.2.3 From dbabcbebe6773fcd17fbb18daa686d821afe0ef9 Mon Sep 17 00:00:00 2001 From: William Kunkel Date: Sat, 7 Feb 2015 19:55:36 -0500 Subject: Add new icon --- resources/sx.svg | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 resources/sx.svg diff --git a/resources/sx.svg b/resources/sx.svg new file mode 100644 index 0000000..56d0129 --- /dev/null +++ b/resources/sx.svg @@ -0,0 +1,232 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3 From ad3c2c9c05705512415afb469c8545b875c7cfe8 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 7 Feb 2015 23:31:54 -0200 Subject: Hot Fix #249. Searching without query --- sx-search.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-search.el b/sx-search.el index aefd12e..c1e1e23 100644 --- a/sx-search.el +++ b/sx-search.el @@ -84,7 +84,7 @@ prefix argument, the user is asked for everything." (when current-prefix-arg (setq tags (sx-tag-multiple-read site (concat "Tags" (when query " (optional)")))) - (when (and (not query) (string= "" tags)) + (unless (or query tags) (sx-user-error "Must supply either QUERY or TAGS")) (setq excluded-tags (sx-tag-multiple-read site "Excluded tags (optional)"))) -- cgit v1.2.3 From 208c91548a100d6a214b2161351d0a04d60adb8d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 7 Feb 2015 23:54:58 -0200 Subject: Version bump --- sx.el | 4 ++-- sx.org | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sx.el b/sx.el index 14af94d..33b36b6 100644 --- a/sx.el +++ b/sx.el @@ -4,7 +4,7 @@ ;; Author: Sean Allred ;; URL: https://github.com/vermiculus/sx.el/ -;; Version: 0.1 +;; Version: 0.2 ;; Keywords: help, hypermedia, tools ;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (json "1.3") (markdown-mode "2.0") (let-alist "1.0.3")) @@ -28,7 +28,7 @@ ;;; Code: (require 'tabulated-list) -(defconst sx-version "0.1" "Version of the `sx' package.") +(defconst sx-version "0.2" "Version of the `sx' package.") (defgroup sx nil "Customization group for the `sx' package." diff --git a/sx.org b/sx.org index e206cc2..014b0de 100644 --- a/sx.org +++ b/sx.org @@ -1,4 +1,4 @@ -#+MACRO: version 0.1 +#+MACRO: version 0.2 #+MACRO: versiondate 16 November 2014 #+MACRO: updated last updated {{{versiondate}}} -- cgit v1.2.3 From 5cd3c39fe75009f48db499bb1bff52d37b57e529 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 11 Feb 2015 07:33:36 -0600 Subject: Include bug report instructions in CONTRIBUTING Should provide some meta-help with issues like #255. This file is advertised when creating an issue, so it's the best we can do. --- CONTRIBUTING.org | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CONTRIBUTING.org b/CONTRIBUTING.org index 3fcf111..cc9f8ce 100644 --- a/CONTRIBUTING.org +++ b/CONTRIBUTING.org @@ -1,9 +1,24 @@ +** Found a Bug? +Open an issue! Please include: +- a description of what you are trying to do +- the behavior you actually see +- steps we can take to reproduce the bug +If the bug actually causes Emacs to issue an error, please +additionally include the backtrace that led up to the error. To do +this, use ~M-x toggle-debug-on-error~ to make sure that the setting is +/enabled/. Now, when the error occurs, a =*Backtrace*= window will +open with most of the information that we typically need. Copy and +paste this into your bug report. (To get out of the =*Backtrace*= +window and Emacs' subsequent 'debug mode', press =q=.) + +** Don't Know Your Way Around? If you need help, search the issue tracker to see if anyone has asked your question before. If it hasn't, a good place to ask first is our chat room on [[https://gitter.im/vermiculus/sx.el][Gitter]]. Opening an issue is welcome of course, but chat will likely be faster for you. If a code change needs to be made, an issue can be written up as necessary. +** Want to Help? Have a great idea for SX? Again, discuss it on [[https://gitter.im/vermiculus/sx.el][Gitter]] first! Don't limit ideas to mimicking the official website, either -- this is Emacs; we should take advantage of its abilities. -- cgit v1.2.3 From 384855876c6fcb0048551ceed335805babc19b1f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Wed, 11 Feb 2015 08:18:28 -0600 Subject: Hotfix sx-search autoload Should fix #255 --- sx-search.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-search.el b/sx-search.el index c1e1e23..cd2f4e7 100644 --- a/sx-search.el +++ b/sx-search.el @@ -62,7 +62,7 @@ KEYWORDS is passed to `sx-method-call'." :filter sx-browse-filter)) -;;; User command +;;;###autoload (defun sx-search (site query &optional tags excluded-tags) "Display search on SITE for question titles containing QUERY. When TAGS is given, it is a lists of tags, one of which must -- cgit v1.2.3 From 285204874ce284bd4e2815c21097b678c4cd8cd6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:01:16 +0000 Subject: Define sx-question-list--order --- sx-question-list.el | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/sx-question-list.el b/sx-question-list.el index 92b4c07..d10309f 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -420,6 +420,10 @@ Non-interactively, DATA is a question alist." "Site being displayed in the *question-list* buffer.") (make-variable-buffer-local 'sx-question-list--site) +(defvar sx-question-list--order nil + "Order being displayed in the *question-list* buffer.") +(make-variable-buffer-local 'sx-question-list--order) + (defun sx-question-list-refresh (&optional redisplay no-update) "Update the list of questions. If REDISPLAY is non-nil (or if interactive), also call `tabulated-list-print'. -- cgit v1.2.3 From 96ae2ad5cb8d8827a1062c66806a60fdae79d3b2 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:06:08 +0000 Subject: Document sx-question-list--order --- sx-question-list.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sx-question-list.el b/sx-question-list.el index d10309f..04004b3 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -259,6 +259,10 @@ The full list of variables which can be set is: 5. `sx-question-list--dataset' This is only used if both 3 and 4 are nil. It can be used to display a static list. + 6. `sx-question-list--order' + Set this to the `sort' method that should be used when + requesting the list, if that makes sense. If it doesn't + leave it as nil. \\ If none of these is configured, the behaviour is that of a \"Frontpage\", for the site given by @@ -282,7 +286,7 @@ Adding further questions to the bottom of the list is done by: display; otherwise, decrement `sx-question-list--pages-so-far'. If `sx-question-list--site' is given, items 3 and 4 should take it -into consideration. +into consideration. The same holds for `sx-question-list--order'. \\{sx-question-list-mode-map}" (hl-line-mode 1) -- cgit v1.2.3 From db202249de34136cf43b9f9926d41f0964a184c6 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:30:03 +0000 Subject: Define sx-question-list--interactive-order-prompt --- sx-question-list.el | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sx-question-list.el b/sx-question-list.el index 04004b3..d2745db 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -230,6 +230,22 @@ This is ignored if `sx-question-list--refresh-function' is set.") ": Quit") "Header-line used on the question list.") +(defconst sx-question-list--order-methods + '(("Recent Activity" . activity) + ("Creation Date" . creation) + ("Most Voted" . votes) + ("Hot" . hot)) + "Alist of possible values to be passed to the `sort' keyword.") + +(defun sx-question-list--interactive-order-prompt (&optional prompt) + "Interactively prompt for a sorting order. +PROMPT is displayed to the user. If it is omitted, a default one +is used." + (let ((order (sx-completing-read + (or prompt "Order questions by: ") + (mapcar #'car sx-question-list--order-methods)))) + (cdr-safe (assoc-string order sx-question-list--order-methods)))) + ;;; Mode Definition (define-derived-mode sx-question-list-mode -- cgit v1.2.3 From 3293b8a2f75aa92c348cfa82e60b6e5a1e39f088 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:30:23 +0000 Subject: Define sx-question-list-order-by Command for switching the ordering method. --- sx-question-list.el | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sx-question-list.el b/sx-question-list.el index d2745db..907ff39 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -616,6 +616,19 @@ Sets `sx-question-list--site' and then call (setq sx-question-list--site site) (sx-question-list-refresh 'redisplay))) +(defun sx-question-list-order-by (sort) + "Order questions in the current list by the method SORT. +Sets `sx-question-list--order' and then calls +`sx-question-list-refresh' with `redisplay'." + (interactive + (list (when sx-question-list--order + (sx-question-list--interactive-order-prompt)))) + (unless sx-question-list--order + (sx-user-error "This list can't be reordered")) + (when (and sort (symbolp sort)) + (setq sx-question-list--order sort) + (sx-question-list-refresh 'redisplay))) + (provide 'sx-question-list) ;;; sx-question-list.el ends here -- cgit v1.2.3 From 0f6749ea36669ed0d8be4f284244813ea30ff4cd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:41:08 +0000 Subject: Improve order-methods --- sx-question-list.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sx-question-list.el b/sx-question-list.el index 907ff39..7757503 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -234,8 +234,10 @@ This is ignored if `sx-question-list--refresh-function' is set.") '(("Recent Activity" . activity) ("Creation Date" . creation) ("Most Voted" . votes) + ("Score" . votes) ("Hot" . hot)) "Alist of possible values to be passed to the `sort' keyword.") +(make-variable-buffer-local 'sx-question-list--order-methods) (defun sx-question-list--interactive-order-prompt (&optional prompt) "Interactively prompt for a sorting order. -- cgit v1.2.3 From c56c78f4a285a9c48a7917eda016efbf00553b5a Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:41:16 +0000 Subject: Add ordering to question lists created by sx-search --- sx-search.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/sx-search.el b/sx-search.el index cd2f4e7..7b4e6c0 100644 --- a/sx-search.el +++ b/sx-search.el @@ -52,7 +52,6 @@ fail. EXCLUDED-TAGS is only is used if TAGS is also provided. KEYWORDS is passed to `sx-method-call'." (sx-method-call 'search :keywords `((page . ,page) - (sort . activity) (intitle . ,query) (tagged . ,tags) (nottagged . ,excluded-tags) @@ -61,6 +60,16 @@ KEYWORDS is passed to `sx-method-call'." :auth t :filter sx-browse-filter)) +(defconst sx-search--order-methods + (cons '("Relevance" . relevance) + (cl-remove-if (lambda (x) (eq (cdr x) 'hot)) + (default-value 'sx-question-list--order-methods))) + "Alist of possible values to be passed to the `sort' keyword.") + +(defvar sx-search-default-order 'activity + "Default ordering method used on new searches. +Possible values are the cdrs of `sx-search--order-methods'.") + ;;;###autoload (defun sx-search (site query &optional tags excluded-tags) @@ -98,8 +107,11 @@ prefix argument, the user is asked for everything." (lambda (page) (sx-search-get-questions sx-question-list--site page - query tags excluded-tags))) + query tags excluded-tags + `((sort . ,sx-question-list--order))))) (setq sx-question-list--site site) + (setq sx-question-list--order sx-search-default-order) + (setq sx-question-list--order-methods sx-search--order-methods) (sx-question-list-refresh 'redisplay) (switch-to-buffer (current-buffer)))) -- cgit v1.2.3 From 2c2becfa47d0b13d633f85a7c18f4d40193dc454 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Wed, 11 Feb 2015 15:52:16 +0000 Subject: sx-search-get-questions make KEYWORDS a &rest argument. --- sx-search.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sx-search.el b/sx-search.el index 7b4e6c0..55964b9 100644 --- a/sx-search.el +++ b/sx-search.el @@ -39,7 +39,9 @@ ;;; Basic function -(defun sx-search-get-questions (site page query &optional tags excluded-tags keywords) +(defun sx-search-get-questions (site page query + &optional tags excluded-tags + &rest keywords) "Like `sx-question-get-questions', but restrict results by a search. Perform search on SITE. PAGE is an integer indicating which page @@ -108,7 +110,7 @@ prefix argument, the user is asked for everything." (sx-search-get-questions sx-question-list--site page query tags excluded-tags - `((sort . ,sx-question-list--order))))) + (cons 'sort sx-question-list--order)))) (setq sx-question-list--site site) (setq sx-question-list--order sx-search-default-order) (setq sx-question-list--order-methods sx-search--order-methods) -- cgit v1.2.3