From ef1d321a157e300d29c48e461257897fca1c9aa4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 20 Dec 2014 02:01:52 -0500 Subject: Expand `let-alist' upon `sx-assoc-let' expansion --- sx.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 6f4e7c7..97a6d61 100644 --- a/sx.el +++ b/sx.el @@ -313,10 +313,11 @@ with a `link' property)." If ALIST doesn't have a `site' property, one is created using the `link' property." (declare (indent 1) (debug t)) + (require 'let-alist) `(progn - (require 'let-alist) (sx--ensure-site ,alist) - (let-alist ,alist ,@body))) + ,(macroexpand + `(let-alist ,alist ,@body)))) (defcustom sx-init-hook nil "Hook run when SX initializes. -- cgit v1.2.3 From 7d2cccd82cf6c658e330767d0e20e48e42ff1ac6 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 20 Dec 2014 02:22:37 -0500 Subject: Fix `sx-assoc-let' tests `require' form is no longer needed -- macro expansion is done with the expansion of `sx-assoc-let'. --- test/tests.el | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/test/tests.el b/test/tests.el index 66d8d88..cc58105 100644 --- a/test/tests.el +++ b/test/tests.el @@ -121,14 +121,16 @@ (ert-deftest macro-test--sx-assoc-let () "Tests macro expansion for `sx-assoc-let'" (should - (equal '(progn (require 'let-alist) - (sx--ensure-site data) - (let-alist data .test)) - (macroexpand '(sx-assoc-let data .test)))) + (equal `(progn (sx--ensure-site data) + ,(macroexpand + '(let-alist data .test))) + (macroexpand + '(sx-assoc-let data .test)))) (should - (equal '(progn (require 'let-alist) - (sx--ensure-site data) - (let-alist data (cons .test-one .test-two))) + (equal `(progn (sx--ensure-site data) + ,(macroexpand + '(let-alist data + (cons .test-one .test-two)))) (macroexpand '(sx-assoc-let data (cons .test-one .test-two)))))) -- cgit v1.2.3 From 6eb53ee0f12dd9f7d444e6749f6cc55c6db62078 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 23 Dec 2014 23:54:14 -0200 Subject: Define assoc let first --- sx.el | 68 +++++++++++++++++++++++++++++++++---------------------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/sx.el b/sx.el index 6f4e7c7..a31c0a0 100644 --- a/sx.el +++ b/sx.el @@ -50,6 +50,40 @@ (interactive) (browse-url "https://github.com/vermiculus/sx.el/issues/new")) + +;;; Site +(defun sx--site (data) + "Get the site in which DATA belongs. +DATA can be a question, answer, comment, or user (or any object +with a `link' property). +DATA can also be the link itself." + (let ((link (if (stringp data) data + (cdr (assoc 'link data))))) + (when (stringp link) + (replace-regexp-in-string + "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$" + "\\1\\2" link)))) + +(defun sx--ensure-site (data) + "Add a `site' property to DATA if it doesn't have one. Return DATA. +DATA can be a question, answer, comment, or user (or any object +with a `link' property)." + (when data + (unless (assq 'site data) + (setcdr data (cons (cons 'site (sx--site data)) + (cdr data)))) + data)) + +(defmacro sx-assoc-let (alist &rest body) + "Identical to `let-alist', except `.site' has a special meaning. +If ALIST doesn't have a `site' property, one is created using the +`link' property." + (declare (indent 1) (debug t)) + `(progn + (require 'let-alist) + (sx--ensure-site ,alist) + (let-alist ,alist ,@body))) + ;;; Browsing filter (defvar sx-browse-filter @@ -284,40 +318,6 @@ removed from the display name before it is returned." (format "[%s]" (car kar)) (cdr kar) string))) string)) - -;;; Site -(defun sx--site (data) - "Get the site in which DATA belongs. -DATA can be a question, answer, comment, or user (or any object -with a `link' property). -DATA can also be the link itself." - (let ((link (if (stringp data) data - (cdr (assoc 'link data))))) - (when (stringp link) - (replace-regexp-in-string - "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$" - "\\1\\2" link)))) - -(defun sx--ensure-site (data) - "Add a `site' property to DATA if it doesn't have one. Return DATA. -DATA can be a question, answer, comment, or user (or any object -with a `link' property)." - (when data - (unless (assq 'site data) - (setcdr data (cons (cons 'site (sx--site data)) - (cdr data)))) - data)) - -(defmacro sx-assoc-let (alist &rest body) - "Identical to `let-alist', except `.site' has a special meaning. -If ALIST doesn't have a `site' property, one is created using the -`link' property." - (declare (indent 1) (debug t)) - `(progn - (require 'let-alist) - (sx--ensure-site ,alist) - (let-alist ,alist ,@body))) - (defcustom sx-init-hook nil "Hook run when SX initializes. Run after `sx-init--internal-hook'." -- cgit v1.2.3 From 3f71435f4266ab770b296e07df650a8a3bcd3a79 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 25 Dec 2014 12:44:04 -0200 Subject: Slight face modifications --- sx-inbox.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sx-inbox.el b/sx-inbox.el index 07453d4..d0be379 100644 --- a/sx-inbox.el +++ b/sx-inbox.el @@ -170,14 +170,13 @@ is an alist containing the elements: (list (propertize " " 'display - (concat "\n " .title "\n" + (concat "\n " (propertize .title 'face 'sx-question-list-date) "\n" (let ((col fill-column)) (with-temp-buffer (setq fill-column col) (insert " " .body) (fill-region (point-min) (point-max)) - (propertize (buffer-string) - 'face 'font-lock-function-name-face)))) + (buffer-string)))) 'face 'default)))))) -- cgit v1.2.3 From 5225bd4ae6e26177a4daf62ddc5e807784e7c46e Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 25 Dec 2014 12:47:28 -0200 Subject: Fix merge --- sx.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sx.el b/sx.el index a31c0a0..79d51f7 100644 --- a/sx.el +++ b/sx.el @@ -69,9 +69,12 @@ DATA can also be the link itself." DATA can be a question, answer, comment, or user (or any object with a `link' property)." (when data - (unless (assq 'site data) - (setcdr data (cons (cons 'site (sx--site data)) - (cdr data)))) + (let-alist data + (unless .site_par + (setcdr data (cons (cons 'site_par + (or .site.api_site_parameter + (sx--site data))) + (cdr data))))) data)) (defmacro sx-assoc-let (alist &rest body) -- cgit v1.2.3 From 93573c854da4c502ccca676c1dd70bf680ab1036 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 16:32:03 -0500 Subject: Bump let-alist required version to 1.0.3 Syntax introduced in commits: * d51791fb6ae69e3b426f7d598920b4349858908f * 5225bd4ae6e26177a4daf62ddc5e807784e7c46e --- sx.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx.el b/sx.el index 79d51f7..9a5a6a0 100644 --- a/sx.el +++ b/sx.el @@ -6,7 +6,7 @@ ;; URL: https://github.com/vermiculus/sx.el/ ;; Version: 0.1 ;; Keywords: help, hypermedia, tools -;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (json "1.3") (markdown-mode "2.0") (let-alist "1.0.1")) +;; Package-Requires: ((emacs "24.1") (cl-lib "0.5") (json "1.3") (markdown-mode "2.0") (let-alist "1.0.3")) ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by -- cgit v1.2.3 From 31a3e357261641228186692ab3a9ac0a053d197b Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 16:40:30 -0500 Subject: Simpler syntax for quoted cons cells --- sx.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 7d67835..8913024 100644 --- a/sx.el +++ b/sx.el @@ -324,11 +324,11 @@ If ALIST doesn't have a `site' property, one is created using the ;; Answer (and (or (string-match "/a/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) (string-match "/questions/[0-9]+/[^/]+/\\([0-9]\\)/?\\(#.*\\|\\)\\'" link)) - (push (cons 'type 'answer) result)) + (push '(type . answer) result)) ;; Question (and (or (string-match "/q/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) (string-match "/questions/\\([0-9]+\\)/" link)) - (push (cons 'type 'question) result))) + (push '(type . question) result))) (push (cons 'id (string-to-number (match-string-no-properties 1 link))) result)) result)) -- cgit v1.2.3 From 0e54ca6ad3e4cf11b5512fadef39066e955e6281 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 16:55:32 -0500 Subject: Use `rx' macro for some regular expressions --- sx.el | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/sx.el b/sx.el index 8913024..091526f 100644 --- a/sx.el +++ b/sx.el @@ -322,12 +322,29 @@ If ALIST doesn't have a `site' property, one is created using the (let ((result (list (cons 'site (sx--site link))))) (when (or ;; Answer - (and (or (string-match "/a/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) - (string-match "/questions/[0-9]+/[^/]+/\\([0-9]\\)/?\\(#.*\\|\\)\\'" link)) + (and (or (string-match + (rx "/a/" (group (1+ digit)) "/" + (1+ digit) + (group (or (sequence "#" (0+ any)) "")) + string-end) link) + (string-match + (rx "/questions/" (1+ digit) "/" + (1+ (not (any "/"))) "/" + (group digit) + (optional "/") + (group (or (sequence "#" (0+ any)) "")) + string-end) link)) (push '(type . answer) result)) ;; Question - (and (or (string-match "/q/\\([0-9]+\\)/[0-9]+\\(#.*\\|\\)\\'" link) - (string-match "/questions/\\([0-9]+\\)/" link)) + (and (or (string-match + (rx "/q/" + (group (1+ digit)) "/" + (1+ digit) + (group (or (sequence "#" (0+ any)) "")) + string-end) link) + (string-match + (rx "/questions/" + (group (1+ digit)) "/") link)) (push '(type . question) result))) (push (cons 'id (string-to-number (match-string-no-properties 1 link))) result)) -- cgit v1.2.3 From 60e483c5f6bfa5ea897f3bc6f85f402b09f63d9e Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 17:21:26 -0500 Subject: Groups on their own lines Ideally, these groups would have explanations of what they capture. For now, the official stance is 'eh'. --- sx.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 091526f..7f6b901 100644 --- a/sx.el +++ b/sx.el @@ -323,7 +323,10 @@ If ALIST doesn't have a `site' property, one is created using the (when (or ;; Answer (and (or (string-match - (rx "/a/" (group (1+ digit)) "/" + (rx "/a/" + ;; Answer ID + (group (1+ digit)) + "/" (1+ digit) (group (or (sequence "#" (0+ any)) "")) string-end) link) @@ -344,7 +347,8 @@ If ALIST doesn't have a `site' property, one is created using the string-end) link) (string-match (rx "/questions/" - (group (1+ digit)) "/") link)) + (group (1+ digit)) + "/") link)) (push '(type . question) result))) (push (cons 'id (string-to-number (match-string-no-properties 1 link))) result)) -- cgit v1.2.3 From d732176007abdcc3395f7188dc918981d9ff2801 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 17:22:03 -0500 Subject: `rx'-ify regular expression --- sx.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sx.el b/sx.el index 7f6b901..19c5f12 100644 --- a/sx.el +++ b/sx.el @@ -294,7 +294,15 @@ DATA can also be the link itself." (cdr (assoc 'link data))))) (when (stringp link) (replace-regexp-in-string - "^https?://\\(?:\\(?1:[^/]+\\)\\.stackexchange\\|\\(?2:[^/]+\\)\\)\\.[^.]+/.*$" + (rx line-start "http" (optional "s") "://" + (or + (sequence + (group-n 1 (+ (not (any "/")))) + ".stackexchange") + (group-n 2 (+ (not (any "/"))))) + "." (+ (not (any "."))) + "/" (* any) + line-end) "\\1\\2" link)))) (defun sx--ensure-site (data) -- cgit v1.2.3 From 970acd6f7e5920ed6492a4a74e65eae9e29838b6 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 17:34:37 -0500 Subject: Add some explanatory comments --- sx.el | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/sx.el b/sx.el index 19c5f12..c460f62 100644 --- a/sx.el +++ b/sx.el @@ -328,19 +328,24 @@ If ALIST doesn't have a `site' property, one is created using the (defun sx--link-to-data (link) "Convert string LINK into data that can be displayed." (let ((result (list (cons 'site (sx--site link))))) + ;; Try to strip a question or answer ID (when (or ;; Answer (and (or (string-match + ;; From 'Share' button (rx "/a/" - ;; Answer ID + ;; Question ID (group (1+ digit)) - "/" - (1+ digit) + ;; User ID + "/" (1+ digit) + ;; Answer ID (group (or (sequence "#" (0+ any)) "")) string-end) link) (string-match + ;; From URL (rx "/questions/" (1+ digit) "/" (1+ (not (any "/"))) "/" + ;; User ID (group digit) (optional "/") (group (or (sequence "#" (0+ any)) "")) @@ -348,13 +353,19 @@ If ALIST doesn't have a `site' property, one is created using the (push '(type . answer) result)) ;; Question (and (or (string-match + ;; From 'Share' button (rx "/q/" - (group (1+ digit)) "/" - (1+ digit) + ;; Question ID + (group (1+ digit)) + ;; User ID + "/" (1+ digit) + ;; Answer or Comment ID (group (or (sequence "#" (0+ any)) "")) string-end) link) (string-match + ;; From URL (rx "/questions/" + ;; Question ID (group (1+ digit)) "/") link)) (push '(type . question) result))) -- cgit v1.2.3 From b87861b6187ef4395e77e34882401f7fb28dfa26 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 17:35:25 -0500 Subject: Make user IDs optional when parsing from link --- sx.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index c460f62..4ef6caf 100644 --- a/sx.el +++ b/sx.el @@ -346,7 +346,7 @@ If ALIST doesn't have a `site' property, one is created using the (rx "/questions/" (1+ digit) "/" (1+ (not (any "/"))) "/" ;; User ID - (group digit) + (optional (group digit)) (optional "/") (group (or (sequence "#" (0+ any)) "")) string-end) link)) @@ -358,7 +358,7 @@ If ALIST doesn't have a `site' property, one is created using the ;; Question ID (group (1+ digit)) ;; User ID - "/" (1+ digit) + (optional "/" (1+ digit)) ;; Answer or Comment ID (group (or (sequence "#" (0+ any)) "")) string-end) link) -- cgit v1.2.3 From a935ee7e5aa887f345b50aa4e922732e31157628 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 17:35:51 -0500 Subject: User IDs are very often more than one digit --- sx.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx.el b/sx.el index 4ef6caf..d1c7633 100644 --- a/sx.el +++ b/sx.el @@ -346,7 +346,7 @@ If ALIST doesn't have a `site' property, one is created using the (rx "/questions/" (1+ digit) "/" (1+ (not (any "/"))) "/" ;; User ID - (optional (group digit)) + (optional (group (+ digit))) (optional "/") (group (or (sequence "#" (0+ any)) "")) string-end) link)) -- cgit v1.2.3 From 0354bf2c974b13967558187936918db4af125571 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 26 Dec 2014 17:37:17 -0500 Subject: Modify rx forms to be `rx-greedy-flag'-independent See `rx' documentation for details. --- sx.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sx.el b/sx.el index d1c7633..c9b5d76 100644 --- a/sx.el +++ b/sx.el @@ -335,20 +335,20 @@ If ALIST doesn't have a `site' property, one is created using the ;; From 'Share' button (rx "/a/" ;; Question ID - (group (1+ digit)) + (group (+ digit)) ;; User ID - "/" (1+ digit) + "/" (+ digit) ;; Answer ID - (group (or (sequence "#" (0+ any)) "")) + (group (or (sequence "#" (* any)) "")) string-end) link) (string-match ;; From URL - (rx "/questions/" (1+ digit) "/" - (1+ (not (any "/"))) "/" + (rx "/questions/" (+ digit) "/" + (+ (not (any "/"))) "/" ;; User ID (optional (group (+ digit))) (optional "/") - (group (or (sequence "#" (0+ any)) "")) + (group (or (sequence "#" (* any)) "")) string-end) link)) (push '(type . answer) result)) ;; Question @@ -356,17 +356,17 @@ If ALIST doesn't have a `site' property, one is created using the ;; From 'Share' button (rx "/q/" ;; Question ID - (group (1+ digit)) + (group (+ digit)) ;; User ID - (optional "/" (1+ digit)) + (optional "/" (+ digit)) ;; Answer or Comment ID - (group (or (sequence "#" (0+ any)) "")) + (group (or (sequence "#" (* any)) "")) string-end) link) (string-match ;; From URL (rx "/questions/" ;; Question ID - (group (1+ digit)) + (group (+ digit)) "/") link)) (push '(type . question) result))) (push (cons 'id (string-to-number (match-string-no-properties 1 link))) -- cgit v1.2.3 From 57976619d5bf17b6b822a4e0159dee4aab673b33 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 27 Dec 2014 00:01:34 -0500 Subject: Use string-start/-end instead of line-start/-end --- sx.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index c9fbf75..508de46 100644 --- a/sx.el +++ b/sx.el @@ -61,7 +61,8 @@ DATA can also be the link itself." (cdr (assoc 'link data))))) (when (stringp link) (replace-regexp-in-string - (rx line-start "http" (optional "s") "://" + (rx string-start + "http" (optional "s") "://" (or (sequence (group-n 1 (+ (not (any "/")))) @@ -69,7 +70,7 @@ DATA can also be the link itself." (group-n 2 (+ (not (any "/"))))) "." (+ (not (any "."))) "/" (* any) - line-end) + string-end) "\\1\\2" link)))) (defun sx--ensure-site (data) -- cgit v1.2.3 From 2fd7f5e04662b435b66009064257355b742b187d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 11:58:36 -0200 Subject: Hotfix Empty question buffer. --- sx-compose.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sx-compose.el b/sx-compose.el index 5201435..ab4a58d 100644 --- a/sx-compose.el +++ b/sx-compose.el @@ -149,7 +149,8 @@ respectively added locally to `sx-compose-before-send-hook' and (error "Invalid PARENT")) (let ((is-question (and (listp parent) - (cdr (assoc 'title parent))))) + (or (null parent) + (cdr (assoc 'title parent)))))) (with-current-buffer (sx-compose--get-buffer-create site parent) (sx-compose-mode) (setq sx-compose--send-function -- cgit v1.2.3 From 60bed65f15505261dd297fcf4ad2c71a7c76dbeb Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 27 Dec 2014 09:56:03 -0500 Subject: Add autoload cookie to `sx-ask' --- sx-interaction.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-interaction.el b/sx-interaction.el index c6f2639..baf8c13 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -327,6 +327,7 @@ from context at point." (sx-site-get-api-tokens) nil t nil nil default))) +;;;###autoload (defun sx-ask (site) "Start composing a question for SITE. SITE is a string, indicating where the question will be posted." -- cgit v1.2.3 From 6c20202ad50aeba70290de860bd1f5feb944c955 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 15:31:22 -0200 Subject: Don't rely on the new feature. This is to avoid a bug in package.el which only gets fixed in Emacs 25 Unfortunately, there's no safe way to use a new feature offered by a previously defined macro, because files were not reloaded on upgrade. After a couple of weeks, once we can expect most of our users to have restarted Emacs at least once since the last upgrade, we can start relying on this new feature. --- sx.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx.el b/sx.el index 9a5a6a0..be37766 100644 --- a/sx.el +++ b/sx.el @@ -72,7 +72,7 @@ with a `link' property)." (let-alist data (unless .site_par (setcdr data (cons (cons 'site_par - (or .site.api_site_parameter + (or (cdr (assq 'api_site_parameter .site)) (sx--site data))) (cdr data))))) data)) -- cgit v1.2.3 From 531d3d911990a5f9eed6646af24b2f55ae128aa3 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 16:11:57 -0200 Subject: Hotfix Mark hidden sends point to (bob) --- sx-question-list.el | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sx-question-list.el b/sx-question-list.el index 62ce032..4bd6478 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -333,6 +333,11 @@ Non-interactively, DATA is a question alist." (tabulated-list-get-id) (sx-user-error "Not in `sx-question-list-mode'")))) (sx-question--mark-hidden data) + ;; The current entry will not be present after the list is + ;; redisplayed. To avoid `tabulated-list-mode' getting lost (and + ;; sending us to the top) we move to the next entry before + ;; redisplaying. + (forward-line 1) (when (called-interactively-p 'any) (sx-question-list-refresh 'redisplay 'noupdate))) -- cgit v1.2.3 From 1ab0df0975e67a626c95d89120ae0c0e2fdcf9ff Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 19:33:26 -0200 Subject: Fix `sx-question--mark-hidden', which was just plain wrong. --- sx-question.el | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/sx-question.el b/sx-question.el index 801384a..03ebb4b 100644 --- a/sx-question.el +++ b/sx-question.el @@ -159,14 +159,13 @@ If no cache exists for it, initialize one with SITE." (let ((site-cell (assoc .site sx-question--user-hidden-list))) ;; If question already hidden, do nothing. (unless (memq .question_id site-cell) - ;; First question from this site. - (push (list .site .question_id) sx-question--user-hidden-list) - ;; Question wasn't present. - ;; Add it in, but make sure it's sorted (just in case we need - ;; it later). - (sx-sorted-insert-skip-first .question_id site-cell >) - ;; This causes a small lag on `j' and `k' as the list gets large. - ;; Should we do this on a timer? + (if (null site-cell) + ;; First question from this site. + (push (list .site .question_id) sx-question--user-hidden-list) + ;; Not first question and question wasn't present. + ;; Add it in, but make sure it's sorted (just in case we + ;; decide to rely on it later). + (sx-sorted-insert-skip-first .question_id site-cell >)) ;; Save the results. (sx-cache-set 'hidden-questions sx-question--user-hidden-list))))) -- cgit v1.2.3 From 2012346d11a04f7cd9871fced0df2417b5503336 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 22:54:42 -0200 Subject: Explicitly request last_activity_date --- sx.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sx.el b/sx.el index 508de46..a63c155 100644 --- a/sx.el +++ b/sx.el @@ -148,6 +148,7 @@ If ALIST doesn't have a `site' property, one is created using the question.comments question.answers question.last_editor + question.last_activity_date question.accepted_answer_id question.link question.upvoted @@ -168,6 +169,7 @@ If ALIST doesn't have a `site' property, one is created using the comment.comment_id answer.answer_id answer.last_editor + answer.last_activity_date answer.link answer.share_link answer.owner -- cgit v1.2.3 From c37022ffbc52b900d81eee05f3c2c3d5fe6fee01 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 23:06:00 -0200 Subject: Initial implementation of sx-completing-read --- sx-interaction.el | 8 ++++---- sx-question-list.el | 3 +-- sx-tab.el | 8 ++++---- sx.el | 5 +++++ 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/sx-interaction.el b/sx-interaction.el index 372a5b1..9ced1ab 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -340,10 +340,10 @@ from context at point." (let ((default (or sx-question-list--site (sx-assoc-let sx-question-mode--data .site) sx-default-site))) - (funcall (if ido-mode #'ido-completing-read #'completing-read) - (format "Site (%s): " default) - (sx-site-get-api-tokens) nil t nil nil - default))) + (sx-completing-read + (format "Site (%s): " default) + (sx-site-get-api-tokens) nil t nil nil + default))) ;;;###autoload (defun sx-ask (site) diff --git a/sx-question-list.el b/sx-question-list.el index 4bd6478..d84d1ea 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -559,12 +559,11 @@ This does not update `sx-question-mode--window'." (defun sx-question-list-switch-site (site) "Switch the current site to SITE and display its questions. -Use `ido-completing-read' if variable `ido-mode' is active. Retrieve completions from `sx-site-get-api-tokens'. Sets `sx-question-list--site' and then call `sx-question-list-refresh' with `redisplay'." (interactive - (list (funcall (if ido-mode #'ido-completing-read #'completing-read) + (list (sx-completing-read "Switch to site: " (sx-site-get-api-tokens) (lambda (site) (not (equal site sx-question-list--site))) t))) diff --git a/sx-tab.el b/sx-tab.el index 6c5e21e..32a7784 100644 --- a/sx-tab.el +++ b/sx-tab.el @@ -34,10 +34,10 @@ (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))))) diff --git a/sx.el b/sx.el index a63c155..c2d1164 100644 --- a/sx.el +++ b/sx.el @@ -183,6 +183,11 @@ See `sx-question-get-questions' and `sx-question-get-question'.") ;;; Utility Functions +(defun sx-completing-read (&rest args) + "Like `completing-read', but possibly use ido. +All ARGS are passed to `completing-read' or `ido-completing-read'." + (apply (if ido-mode #'ido-completing-read #'completing-read) + args)) (defmacro sx-sorted-insert-skip-first (newelt list &optional predicate) "Inserted NEWELT into LIST sorted by PREDICATE. -- cgit v1.2.3 From 8c2b378b439d24ec7d3f4417c602a1b22e693709 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sat, 27 Dec 2014 23:37:55 -0200 Subject: Implement sx--multiple-read for reading multiple strings --- sx.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sx.el b/sx.el index c2d1164..2824b4d 100644 --- a/sx.el +++ b/sx.el @@ -189,6 +189,25 @@ All ARGS are passed to `completing-read' or `ido-completing-read'." (apply (if ido-mode #'ido-completing-read #'completing-read) args)) +(defun sx--multiple-read (prompt hist-var) + "Interactively query gthe user for a list of strings. +Call `read-string' multiple times, until the input is empty. + +PROMPT is a string displayed to the user. and should not +end with a space nor a colon. +HIST-VAR is a quoted symbol, indicating a list in which to store +input history." + (let (list input) + (while (not (string= + "" + (setq input (read-string + (concat prompt " [" + (mapconcat #'identity list ",") + "]: ") + "" hist-var)))) + (push input list)) + list)) + (defmacro sx-sorted-insert-skip-first (newelt list &optional predicate) "Inserted NEWELT into LIST sorted by PREDICATE. This is designed for the (site id id ...) lists. So the first car -- cgit v1.2.3 From c92ed1bbc3df248943834b466bbdd74180649e72 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 28 Dec 2014 00:07:10 -0200 Subject: Implement searching with sx-search Fix #16 Fix #20 --- sx-search.el | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 sx-search.el diff --git a/sx-search.el b/sx-search.el new file mode 100644 index 0000000..928db5d --- /dev/null +++ b/sx-search.el @@ -0,0 +1,112 @@ +;;; sx-search.el --- Searching for questions. -*- lexical-binding: t; -*- + +;; Copyright (C) 2014 Artur Malabarba + +;; Author: Artur Malabarba + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; Implements sarch functionality. The basic function is +;; `sx-search-get-questions', which returns an array of questions +;; according to a search term. +;; +;; This also defines a user-level command, `sx-search', which is an +;; interactive wrapper around `sx-search-get-questions' and +;; `sx-question-list-mode'. + + +;;; Code: + +(require 'sx) +(require 'sx-question-list) + +(defvar sx-search--query-history nil + "Query history for interactive prompts.") + +(defvar sx-search--tag-history nil + "Tags history for interactive prompts.") + + +;;; Basic function +(defun sx-search-get-questions (site page query &optional tags excluded-tags keywords) + "Like `sx-question-get-questions', but restrict results by a search. + +Perform search on SITE. PAGE is an integer indicating which page +of results to return. QUERY, TAGS, and EXCLUDED-TAGS restrict the +possible returned questions as per `sx-search'. + +Either QUERY or TAGS must be non-nil, or the search will +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) + ,@keywords) + :site site + :auth t + :filter sx-browse-filter)) + + +;;; User command +(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 +match. When EXCLUDED-TAGS is given, it is a list of tags, none +of which is allowed to match. + +Interactively, the user is asked for SITE and QUERY. With a +prefix argument, the user is asked for everything." + (interactive + (let ((site (sx--interactive-site-prompt)) + (query (read-string + (format "Query (%s): " + (if current-prefix-arg "optional" "mandatory")) + "" + 'sx-search--query-history)) + tags excluded-tags) + (when (string= query "") + (setq query nil)) + (when current-prefix-arg + (setq tags (sx--multiple-read + (format "Tags (%s)" + (if query "optional" "mandatory")) + 'sx-search--tag-history)) + (when (and (not query) (string= "" tags)) + (sx-user-error "Must supply either QUERY or TAGS")) + (setq excluded-tags + (sx--multiple-read + "Excluded tags (optional)" 'sx-search--tag-history))) + (list site query tags excluded-tags))) + + ;; Here starts the actual function + (sx-initialize) + (with-current-buffer (get-buffer-create "*sx-search-result*") + (sx-question-list-mode) + (setq sx-question-list--next-page-function + (lambda (page) + (sx-search-get-questions + sx-question-list--site page + query tags excluded-tags))) + (setq sx-question-list--site site) + (sx-question-list-refresh 'redisplay) + (switch-to-buffer (current-buffer)))) + +(provide 'sx-search) +;;; sx-search.el ends here -- cgit v1.2.3 From 39116611ea99b3b0ba33545d38c2983a17db487d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Sun, 28 Dec 2014 00:11:02 -0200 Subject: Bind sx-search to s --- sx-question-list.el | 1 + sx-question-mode.el | 1 + 2 files changed, 2 insertions(+) diff --git a/sx-question-list.el b/sx-question-list.el index d84d1ea..0856e2a 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -317,6 +317,7 @@ into consideration. (":" sx-question-list-switch-site) ("t" sx-tab-switch) ("a" sx-ask) + ("s" sx-search) ("v" sx-visit-externally) ("u" sx-toggle-upvote) ("d" sx-toggle-downvote) diff --git a/sx-question-mode.el b/sx-question-mode.el index a60cf3a..05b8984 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -231,6 +231,7 @@ Letters do not insert themselves; instead, they are commands. (" " scroll-up-command) ("a" sx-answer) ("e" sx-edit) + ("s" sx-search) (,(kbd "S-SPC") scroll-down-command) ([backspace] scroll-down-command) ([tab] forward-button) -- cgit v1.2.3 From 35b0883d3e551c5cbc4f416082957e977d6e03eb Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 30 Dec 2014 18:10:39 -0500 Subject: Reapply ef1d321a157e300d29c48e461257897fca1c9aa4 It was somehow lost in the merging. --- sx.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 508de46..8fe31ac 100644 --- a/sx.el +++ b/sx.el @@ -136,10 +136,11 @@ with a `link' property)." If ALIST doesn't have a `site' property, one is created using the `link' property." (declare (indent 1) (debug t)) + (require 'let-alist) `(progn - (require 'let-alist) (sx--ensure-site ,alist) - (let-alist ,alist ,@body))) + ,(macroexpand + `(let-alist ,alist ,@body)))) ;;; Browsing filter -- cgit v1.2.3 From 06f7059bffa517d63c72a0815ff0779cfe5e5ce2 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 30 Dec 2014 23:07:36 -0500 Subject: Test sx-assoc-let according to functionality See http://emacs.stackexchange.com/q/5915/2264 and #151 for more information. This patch tests for functional equivalence rather than symbolic equivalence. Symbolic equivalence would be far preferable, but it does not appear to be happening anytime soon -- perhaps when things settle down a bit for the authors :) --- test/tests.el | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/test/tests.el b/test/tests.el index cc58105..3c275fd 100644 --- a/test/tests.el +++ b/test/tests.el @@ -120,19 +120,21 @@ (ert-deftest macro-test--sx-assoc-let () "Tests macro expansion for `sx-assoc-let'" - (should - (equal `(progn (sx--ensure-site data) - ,(macroexpand - '(let-alist data .test))) - (macroexpand - '(sx-assoc-let data .test)))) - (should - (equal `(progn (sx--ensure-site data) - ,(macroexpand - '(let-alist data - (cons .test-one .test-two)))) - (macroexpand - '(sx-assoc-let data (cons .test-one .test-two)))))) + (let ((prototype '((test . nil) (test-one . 1) (test-two . 2) + (link . "http://meta.emacs.stackexchange.com/")))) + (let ((data (copy-tree prototype))) + (should + (null (let-alist data .site)))) + + (let ((data (copy-tree prototype))) + (should + (equal (sx-assoc-let data .site) + "meta.emacs"))) + + (let ((data (copy-tree prototype))) + (should + (equal (sx-assoc-let data (cons .test-one .test-two)) + '(1 . 2)))))) (ert-deftest sx--user-@name () "Tests macro expansion for `sx-assoc-let'" -- cgit v1.2.3 From b8eb3d978109c1d5bf18be8cc1e1678afb6c017a Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Tue, 30 Dec 2014 23:10:01 -0500 Subject: Fix typo --- sx-request.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sx-request.el b/sx-request.el index 1031ea7..bc34f9c 100644 --- a/sx-request.el +++ b/sx-request.el @@ -162,7 +162,7 @@ the main content of the response is returned." .method .error_id .error_name .error_message)) (when (< (setq sx-request-remaining-api-requests .quota_remaining) sx-request-remaining-api-requests-message-threshold) - (sx-message "%d API requests reamining" + (sx-message "%d API requests remaining" sx-request-remaining-api-requests)) (sx-encoding-clean-content-deep .items))))))) -- cgit v1.2.3 From 7217c37a3619c72bce6ac5be97b969a0bb2f03cc Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 12:05:04 -0500 Subject: Split tests into separate files --- test/test-api.el | 13 ++++ test/test-macros.el | 18 +++++ test/test-printing.el | 45 +++++++++++++ test/test-util.el | 66 +++++++++++++++++++ test/tests.el | 179 ++++++++------------------------------------------ 5 files changed, 169 insertions(+), 152 deletions(-) create mode 100644 test/test-api.el create mode 100644 test/test-macros.el create mode 100644 test/test-printing.el create mode 100644 test/test-util.el diff --git a/test/test-api.el b/test/test-api.el new file mode 100644 index 0000000..ca775ff --- /dev/null +++ b/test/test-api.el @@ -0,0 +1,13 @@ +(ert-deftest test-basic-request () + "Test basic request functionality" + (should (sx-request-make "sites"))) + +(ert-deftest test-question-retrieve () + "Test the ability to receive a list of questions." + (should (sx-question-get-questions 'emacs))) + +(ert-deftest test-bad-request () + "Test a method given a bad set of keywords" + (should-error + (sx-request-make "questions" '(())))) + diff --git a/test/test-macros.el b/test/test-macros.el new file mode 100644 index 0000000..6a1910c --- /dev/null +++ b/test/test-macros.el @@ -0,0 +1,18 @@ +(ert-deftest macro-test--sx-assoc-let () + "Tests macro expansion for `sx-assoc-let'" + (let ((prototype '((test . nil) (test-one . 1) (test-two . 2) + (link . "http://meta.emacs.stackexchange.com/")))) + (let ((data (copy-tree prototype))) + (should + (null (let-alist data .site)))) + + (let ((data (copy-tree prototype))) + (should + (equal (sx-assoc-let data .site) + "meta.emacs"))) + + (let ((data (copy-tree prototype))) + (should + (equal (sx-assoc-let data (cons .test-one .test-two)) + '(1 . 2)))))) + diff --git a/test/test-printing.el b/test/test-printing.el new file mode 100644 index 0000000..4fe31db --- /dev/null +++ b/test/test-printing.el @@ -0,0 +1,45 @@ + +;;; Setup +(require 'cl-lib) + +(defmacro line-should-match (regexp) + "" + `(let ((line (buffer-substring-no-properties + (line-beginning-position) + (line-end-position)))) + (message "Line here is: %S" line) + (should (string-match ,regexp line)))) + + +;;; Tests +(ert-deftest question-list-display () + (cl-letf (((symbol-function #'sx-request-make) + (lambda (&rest _) sx-test-data-questions))) + (sx-tab-frontpage nil "emacs") + (switch-to-buffer "*question-list*") + (goto-char (point-min)) + (should (equal (buffer-name) "*question-list*")) + (line-should-match + "^\\s-+1\\s-+0\\s-+Focus-hook: attenuate colours when losing focus [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[frames\\] \\[hooks\\] \\[focus\\]") + (sx-question-list-next 5) + (line-should-match + "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[org-mode\\]") + ;; ;; Use this when we have a real sx-question buffer. + ;; (call-interactively 'sx-question-list-display-question) + ;; (should (equal (buffer-name) "*sx-question*")) + (switch-to-buffer "*question-list*") + (sx-question-list-previous 4) + (line-should-match + "^\\s-+2\\s-+1\\s-+"Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[autocomplete\\]"))) + +(ert-deftest sx--user-@name () + "Tests macro expansion for `sx-assoc-let'" + (should + (string= + (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) + "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) + (should + (string= + (sx--user-@name '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) + "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) + diff --git a/test/test-util.el b/test/test-util.el new file mode 100644 index 0000000..53dc200 --- /dev/null +++ b/test/test-util.el @@ -0,0 +1,66 @@ +(ert-deftest test-tree-filter () + "`sx-core-filter-data'" + ;; flat + (should + (equal + '((1 . t) (2 . [1 2]) (3)) + (sx--filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2]) + ("5" . bop) (3) (p . 4)) + '(1 2 3)))) + ;; complex + (should + (equal + '((1 . [a b c]) + (2 . [((a . 1) (c . 3)) + ((a . 4) (c . 6))]) + (3 . peach)) + (sx--filter-data '((1 . [a b c]) + (2 . [((a . 1) (b . 2) (c . 3)) + ((a . 4) (b . 5) (c . 6))]) + (3 . peach) + (4 . banana)) + '(1 (2 a c) 3)))) + + ;; vector + (should + (equal + [((1 . 2) (2 . 3) (3 . 4)) + ((1 . a) (2 . b) (3 . c)) + nil ((1 . alpha) (2 . beta))] + (sx--filter-data [((1 . 2) (2 . 3) (3 . 4)) + ((1 . a) (2 . b) (3 . c) (5 . seven)) + ((should-not-go)) + ((1 . alpha) (2 . beta))] + '(1 2 3))))) + +(ert-deftest thing-as-string () + "Tests `sx--thing-as-string'" + (should + (string= (sx--thing-as-string + '(hello world (this is a test)) + '(";" "+")) + "hello;world;this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test) '(";" "+")) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + '(this is a test) "+") + "this+is+a+test")) + (should + (string= (sx--thing-as-string + '(this is a test)) + "this;is;a;test")) + (should + (string= (sx--thing-as-string + 'test) + "test")) + (should + (string= (sx--thing-as-string + 'test&) + "test&")) + (should + (string= (sx--thing-as-string + 'test& nil t) + "test%26"))) diff --git a/test/tests.el b/test/tests.el index 3c275fd..daaa8b5 100644 --- a/test/tests.el +++ b/test/tests.el @@ -1,3 +1,5 @@ + +;;; SX Settings (defun -sx--nuke () (interactive) (mapatoms @@ -5,11 +7,17 @@ (if (string-prefix-p "sx-" (symbol-name symbol)) (unintern symbol))))) -;;; Tests +(setq + sx-initialized t + sx-request-remaining-api-requests-message-threshold 50000 + debug-on-error t + user-emacs-directory "." + sx-test-base-dir (file-name-directory (or load-file-name "./"))) + + +;;; Test Data (defvar sx-test-data-dir - (expand-file-name - "data-samples/" - (file-name-directory (or load-file-name "./")))) + (expand-file-name "data-samples/" sx-test-base-dir)) (defun sx-test-sample-data (method &optional directory) (let ((file (concat (when directory (concat directory "/")) @@ -20,161 +28,28 @@ (insert-file-contents file) (read (buffer-string)))))) -(defmacro line-should-match (regexp) - "" - `(let ((line (buffer-substring-no-properties - (line-beginning-position) - (line-end-position)))) - (message "Line here is: %S" line) - (should (string-match ,regexp line)))) - (setq - sx-initialized t - sx-request-remaining-api-requests-message-threshold 50000 - debug-on-error t - user-emacs-directory "." - sx-test-data-questions (sx-test-sample-data "questions") sx-test-data-sites (sx-test-sample-data "sites")) -(setq package-user-dir - (expand-file-name (format "../../.cask/%s/elpa" emacs-version) - sx-test-data-dir)) -(package-initialize) - -(require 'cl-lib) -(require 'sx) -(require 'sx-question) -(require 'sx-question-list) -(require 'sx-tab) - -(ert-deftest test-basic-request () - "Test basic request functionality" - (should (sx-request-make "sites"))) - -(ert-deftest test-question-retrieve () - "Test the ability to receive a list of questions." - (should (sx-question-get-questions 'emacs))) - -(ert-deftest test-bad-request () - "Test a method given a bad set of keywords" - (should-error - (sx-request-make "questions" '(())))) - -(ert-deftest test-tree-filter () - "`sx-core-filter-data'" - ;; flat - (should - (equal - '((1 . t) (2 . [1 2]) (3)) - (sx--filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2]) - ("5" . bop) (3) (p . 4)) - '(1 2 3)))) - ;; complex - (should - (equal - '((1 . [a b c]) - (2 . [((a . 1) (c . 3)) - ((a . 4) (c . 6))]) - (3 . peach)) - (sx--filter-data '((1 . [a b c]) - (2 . [((a . 1) (b . 2) (c . 3)) - ((a . 4) (b . 5) (c . 6))]) - (3 . peach) - (4 . banana)) - '(1 (2 a c) 3)))) - - ;; vector - (should - (equal - [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c)) - nil ((1 . alpha) (2 . beta))] - (sx--filter-data [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c) (5 . seven)) - ((should-not-go)) - ((1 . alpha) (2 . beta))] - '(1 2 3))))) - -(ert-deftest question-list-display () - (cl-letf (((symbol-function #'sx-request-make) - (lambda (&rest _) sx-test-data-questions))) - (sx-tab-frontpage nil "emacs") - (switch-to-buffer "*question-list*") - (goto-char (point-min)) - (should (equal (buffer-name) "*question-list*")) - (line-should-match - "^\\s-+1\\s-+0\\s-+Focus-hook: attenuate colours when losing focus [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[frames\\] \\[hooks\\] \\[focus\\]") - (sx-question-list-next 5) - (line-should-match - "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[org-mode\\]") - ;; ;; Use this when we have a real sx-question buffer. - ;; (call-interactively 'sx-question-list-display-question) - ;; (should (equal (buffer-name) "*sx-question*")) - (switch-to-buffer "*question-list*") - (sx-question-list-previous 4) - (line-should-match - "^\\s-+2\\s-+1\\s-+"Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[autocomplete\\]"))) - -(ert-deftest macro-test--sx-assoc-let () - "Tests macro expansion for `sx-assoc-let'" - (let ((prototype '((test . nil) (test-one . 1) (test-two . 2) - (link . "http://meta.emacs.stackexchange.com/")))) - (let ((data (copy-tree prototype))) - (should - (null (let-alist data .site)))) + +;;; General Settings +(setq + package-user-dir (expand-file-name + (format "../../.cask/%s/elpa" emacs-version) + sx-test-data-dir)) - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data .site) - "meta.emacs"))) +(package-initialize) - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data (cons .test-one .test-two)) - '(1 . 2)))))) +(require 'sx-load) -(ert-deftest sx--user-@name () - "Tests macro expansion for `sx-assoc-let'" - (should - (string= - (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) - "@hTHssdlrggyynnsssszzzccccuuuuuuooooooooiiiiieeeeeaaaaaaaaj")) - (should - (string= - (sx--user-@name '((display_name . "ĤÞßĐŁŘĞĜÝŸÑŃŚŞŠŜŻŹŽÇĆČĈÙÚÛÜŬŮÒÓÔÕÖØŐÐÌÍÎÏıÈÉÊËĘÀÅÁÂÄÃÅĄĴ"))) - "@HTHssDLRGGYYNNSSSSZZZCCCCUUUUUUOOOOOOOOIIIIiEEEEEAAAAAAAAJ"))) +(defun sx-load-test (test) + (load-file + (format "%s/test-%s.el" + sx-test-base-dir + (symbol-name test)))) -(ert-deftest thing-as-string () - "Tests `sx--thing-as-string'" - (should - (string= (sx--thing-as-string - '(hello world (this is a test)) - '(";" "+")) - "hello;world;this+is+a+test")) - (should - (string= (sx--thing-as-string - '(this is a test) '(";" "+")) - "this;is;a;test")) - (should - (string= (sx--thing-as-string - '(this is a test) "+") - "this+is+a+test")) - (should - (string= (sx--thing-as-string - '(this is a test)) - "this;is;a;test")) - (should - (string= (sx--thing-as-string - 'test) - "test")) - (should - (string= (sx--thing-as-string - 'test&) - "test&")) - (should - (string= (sx--thing-as-string - 'test& nil t) - "test%26"))) +(mapc #'sx-load-test + '(api macros printing util)) -- cgit v1.2.3 From 9469287080501f3e3c7ce0002d837664a1b9b91e Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 13:15:20 -0500 Subject: Use test fixture for sample data See (info "(ert) Fixtures and Test Suites"). --- test/test-macros.el | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/test/test-macros.el b/test/test-macros.el index 6a1910c..8bdd527 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -1,18 +1,21 @@ +(defmacro sx-test-with-json-data (cell &rest body) + (declare (indent 1)) + `(let ((,cell '((test . nil) (test-one . 1) (test-two . 2) + (link . "http://meta.emacs.stackexchange.com/")))) + ,@body)) + (ert-deftest macro-test--sx-assoc-let () "Tests macro expansion for `sx-assoc-let'" - (let ((prototype '((test . nil) (test-one . 1) (test-two . 2) - (link . "http://meta.emacs.stackexchange.com/")))) - (let ((data (copy-tree prototype))) - (should - (null (let-alist data .site)))) - - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data .site) - "meta.emacs"))) + (sx-test-with-json-data data + (should + (null (let-alist data .site)))) - (let ((data (copy-tree prototype))) - (should - (equal (sx-assoc-let data (cons .test-one .test-two)) - '(1 . 2)))))) + (sx-test-with-json-data data + (should + (equal (sx-assoc-let data .site) + "meta.emacs"))) + (sx-test-with-json-data data + (should + (equal (sx-assoc-let data (cons .test-one .test-two)) + '(1 . 2))))) -- cgit v1.2.3 From eed71f7024169c2d400ef5d0a84595d186c81bb0 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 13:51:22 -0500 Subject: Simplify question list display tests Use a macro (using `rx') to create the regular expression for the question list display test. --- test/test-printing.el | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/test/test-printing.el b/test/test-printing.el index 4fe31db..0ea5b03 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -10,6 +10,18 @@ (message "Line here is: %S" line) (should (string-match ,regexp line)))) +(defmacro question-list-regex (title votes answers &rest tags) + `(rx line-start + (+ whitespace) ,(number-to-string votes) + (+ whitespace) ,(number-to-string answers) + (+ whitespace) + ,title + (+ (any whitespace digit)) + (or "y" "d" "h" "m" "mo" "s") " ago" + (+ whitespace) + (eval (mapconcat #'sx-question--tag-format + (list ,@tags) " ")))) + ;;; Tests (ert-deftest question-list-display () @@ -20,17 +32,23 @@ (goto-char (point-min)) (should (equal (buffer-name) "*question-list*")) (line-should-match - "^\\s-+1\\s-+0\\s-+Focus-hook: attenuate colours when losing focus [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[frames\\] \\[hooks\\] \\[focus\\]") + (question-list-regex + "Focus-hook: attenuate colours when losing focus" + 1 0 "frames" "hooks" "focus")) (sx-question-list-next 5) (line-should-match - "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[org-mode\\]") + (question-list-regex + "Babel doesn't wrap results in verbatim" + 0 1 "org-mode" "org-export" "org-babel")) ;; ;; Use this when we have a real sx-question buffer. ;; (call-interactively 'sx-question-list-display-question) ;; (should (equal (buffer-name) "*sx-question*")) (switch-to-buffer "*question-list*") (sx-question-list-previous 4) (line-should-match - "^\\s-+2\\s-+1\\s-+"Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+\\(y\\|d\\|h\\|mo?\\|s\\) ago\\s-+\\[autocomplete\\]"))) + (question-list-regex + ""Making tag completion table" Freezes/Blocks -- how to disable" + 2 1 "autocomplete" "performance" "ctags")))) (ert-deftest sx--user-@name () "Tests macro expansion for `sx-assoc-let'" -- cgit v1.2.3 From 6376a70f9d70f711723e144ea787cd0a79f7cd7b Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 14:09:02 -0500 Subject: Docstrings for tests --- test/test-macros.el | 11 ++++++----- test/test-printing.el | 7 +++++-- test/test-util.el | 4 ++-- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/test/test-macros.el b/test/test-macros.el index 8bdd527..2169088 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -1,11 +1,12 @@ (defmacro sx-test-with-json-data (cell &rest body) - (declare (indent 1)) - `(let ((,cell '((test . nil) (test-one . 1) (test-two . 2) - (link . "http://meta.emacs.stackexchange.com/")))) - ,@body)) + "Run BODY with sample data let-bound to CELL" + (declare (indent 1)) + `(let ((,cell '((test . nil) (test-one . 1) (test-two . 2) + (link . "http://meta.emacs.stackexchange.com/")))) + ,@body)) (ert-deftest macro-test--sx-assoc-let () - "Tests macro expansion for `sx-assoc-let'" + "Test `sx-assoc-let'" (sx-test-with-json-data data (should (null (let-alist data .site)))) diff --git a/test/test-printing.el b/test/test-printing.el index 0ea5b03..2260a00 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -3,7 +3,7 @@ (require 'cl-lib) (defmacro line-should-match (regexp) - "" + "Test if the line at point matches REGEXP" `(let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) @@ -11,6 +11,9 @@ (should (string-match ,regexp line)))) (defmacro question-list-regex (title votes answers &rest tags) + "Construct a matching regexp for TITLE, VOTES, and ANSWERS. +Each element of TAGS is appended at the end of the expression +after being run through `sx-question--tag-format'." `(rx line-start (+ whitespace) ,(number-to-string votes) (+ whitespace) ,(number-to-string answers) @@ -51,7 +54,7 @@ 2 1 "autocomplete" "performance" "ctags")))) (ert-deftest sx--user-@name () - "Tests macro expansion for `sx-assoc-let'" + "Test macro expansion for `sx-assoc-let'" (should (string= (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) diff --git a/test/test-util.el b/test/test-util.el index 53dc200..49df274 100644 --- a/test/test-util.el +++ b/test/test-util.el @@ -1,5 +1,5 @@ (ert-deftest test-tree-filter () - "`sx-core-filter-data'" + "Test `sx-core-filter-data'" ;; flat (should (equal @@ -34,7 +34,7 @@ '(1 2 3))))) (ert-deftest thing-as-string () - "Tests `sx--thing-as-string'" + "Test `sx--thing-as-string'" (should (string= (sx--thing-as-string '(hello world (this is a test)) -- cgit v1.2.3 From 1518cee93ef2d33af9ddf214ae1c181d02c7b94f Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 14:14:05 -0500 Subject: Add toggle for detailed test messages --- test/test-printing.el | 9 ++++++++- test/tests.el | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/test/test-printing.el b/test/test-printing.el index 2260a00..6225bf6 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -7,7 +7,7 @@ `(let ((line (buffer-substring-no-properties (line-beginning-position) (line-end-position)))) - (message "Line here is: %S" line) + (sx-test-message "Line here is: %S" line) (should (string-match ,regexp line)))) (defmacro question-list-regex (title votes answers &rest tags) @@ -27,6 +27,13 @@ after being run through `sx-question--tag-format'." ;;; Tests +(ert-deftest question-list-tag () + "Test `sx-question--tag-format'." + (should + (string= + (sx-question--tag-format "tag") + "[tag]"))) + (ert-deftest question-list-display () (cl-letf (((symbol-function #'sx-request-make) (lambda (&rest _) sx-test-data-questions))) diff --git a/test/tests.el b/test/tests.el index daaa8b5..d709600 100644 --- a/test/tests.el +++ b/test/tests.el @@ -51,5 +51,11 @@ sx-test-base-dir (symbol-name test)))) +(setq sx-test-enable-messages nil) + +(defun sx-test-message (message &rest args) + (when sx-test-enable-messages + (apply #'message (cons message args)))) + (mapc #'sx-load-test '(api macros printing util)) -- cgit v1.2.3 From 7d73bc8b9da4a093b0a3b477da81252d5b805ca5 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 14:19:58 -0500 Subject: Prune sx--filter-data --- sx.el | 44 -------------------------------------------- test/test-util.el | 35 ----------------------------------- 2 files changed, 79 deletions(-) diff --git a/sx.el b/sx.el index 8fe31ac..73d1a40 100644 --- a/sx.el +++ b/sx.el @@ -239,50 +239,6 @@ and sequences of strings." (funcall first-f sequence-sep) ";")))))) -(defun sx--filter-data (data desired-tree) - "Filter DATA and return the DESIRED-TREE. - -For example: - - (sx--filter-data - '((prop1 . value1) - (prop2 . value2) - (prop3 - (test1 . 1) - (test2 . 2)) - (prop4 . t)) - '(prop1 (prop3 test2))) - -would yield - - ((prop1 . value1) - (prop3 - (test2 . 2)))" - (if (vectorp data) - (apply #'vector - (mapcar (lambda (entry) - (sx--filter-data - entry desired-tree)) - data)) - (delq - nil - (mapcar (lambda (cons-cell) - ;; @TODO the resolution of `f' is O(2n) in the worst - ;; case. It may be faster to implement the same - ;; functionality as a `while' loop to stop looking the - ;; list once it has found a match. Do speed tests. - ;; See edfab4443ec3d376c31a38bef12d305838d3fa2e. - (let ((f (or (memq (car cons-cell) desired-tree) - (assoc (car cons-cell) desired-tree)))) - (when f - (if (and (sequencep (cdr cons-cell)) - (sequencep (elt (cdr cons-cell) 0))) - (cons (car cons-cell) - (sx--filter-data - (cdr cons-cell) (cdr f))) - cons-cell)))) - data)))) - (defun sx--shorten-url (url) "Shorten URL hiding anything other than the domain. Paths after the domain are replaced with \"...\". diff --git a/test/test-util.el b/test/test-util.el index 49df274..5db1691 100644 --- a/test/test-util.el +++ b/test/test-util.el @@ -1,38 +1,3 @@ -(ert-deftest test-tree-filter () - "Test `sx-core-filter-data'" - ;; flat - (should - (equal - '((1 . t) (2 . [1 2]) (3)) - (sx--filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2]) - ("5" . bop) (3) (p . 4)) - '(1 2 3)))) - ;; complex - (should - (equal - '((1 . [a b c]) - (2 . [((a . 1) (c . 3)) - ((a . 4) (c . 6))]) - (3 . peach)) - (sx--filter-data '((1 . [a b c]) - (2 . [((a . 1) (b . 2) (c . 3)) - ((a . 4) (b . 5) (c . 6))]) - (3 . peach) - (4 . banana)) - '(1 (2 a c) 3)))) - - ;; vector - (should - (equal - [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c)) - nil ((1 . alpha) (2 . beta))] - (sx--filter-data [((1 . 2) (2 . 3) (3 . 4)) - ((1 . a) (2 . b) (3 . c) (5 . seven)) - ((should-not-go)) - ((1 . alpha) (2 . beta))] - '(1 2 3))))) - (ert-deftest thing-as-string () "Test `sx--thing-as-string'" (should -- cgit v1.2.3 From b4ac5e67f55147db98e17f9e2df8d7e044b6bcdf Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 17:07:38 -0500 Subject: Remove redundant consing --- test/tests.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests.el b/test/tests.el index d709600..53e053f 100644 --- a/test/tests.el +++ b/test/tests.el @@ -55,7 +55,7 @@ (defun sx-test-message (message &rest args) (when sx-test-enable-messages - (apply #'message (cons message args)))) + (apply #'message message args))) (mapc #'sx-load-test '(api macros printing util)) -- cgit v1.2.3 From bf4f193a76100917764f249023f4844a2ca15b2c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 19:01:36 -0500 Subject: Fix docstring --- test/test-printing.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test-printing.el b/test/test-printing.el index 6225bf6..2857cb7 100644 --- a/test/test-printing.el +++ b/test/test-printing.el @@ -61,7 +61,7 @@ after being run through `sx-question--tag-format'." 2 1 "autocomplete" "performance" "ctags")))) (ert-deftest sx--user-@name () - "Test macro expansion for `sx-assoc-let'" + "Test `sx--user-@name' character substitution" (should (string= (sx--user-@name '((display_name . "ĥÞßđłřğĝýÿñńśşšŝżźžçćčĉùúûüŭůòóôõöøőðìíîïıèéêëęàåáâäãåąĵ★"))) -- cgit v1.2.3 From cad44329de7679158dee78e25aeb068c0724770b Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 1 Jan 2015 22:26:22 -0200 Subject: Add TODO reminder --- sx.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sx.el b/sx.el index 151255e..e2ea914 100644 --- a/sx.el +++ b/sx.el @@ -80,6 +80,8 @@ with a `link' property)." (when data (let-alist data (unless .site_par + ;; @TODO: Change this to .site.api_site_parameter sometime + ;; after February. (setcdr data (cons (cons 'site_par (or (cdr (assq 'api_site_parameter .site)) (sx--site data))) -- cgit v1.2.3 From 5ac68096b4a1d97667f181daad4d0c43ead910d4 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 23:03:07 -0500 Subject: Add sx-search to sx-load --- sx-load.el | 1 + 1 file changed, 1 insertion(+) diff --git a/sx-load.el b/sx-load.el index d71b8ed..465d504 100644 --- a/sx-load.el +++ b/sx-load.el @@ -39,6 +39,7 @@ sx-question-mode sx-question-print sx-request + sx-search sx-site sx-tab )) -- cgit v1.2.3 From 8b5e430d385db04b21b917bb62935e8266819e38 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 23:13:17 -0500 Subject: Add tests for search functionality --- test/test-search.el | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/tests.el | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/test-search.el diff --git a/test/test-search.el b/test/test-search.el new file mode 100644 index 0000000..72dbcdc --- /dev/null +++ b/test/test-search.el @@ -0,0 +1,53 @@ +(defmacro test-with-bogus-string (cell &rest body) + "Let-bind a bogus string to CELL and execute BODY." + (declare (indent 1)) + `(let ((,cell "E7631BCF-A94B-4507-8F0C-02CFB3207F55")) + ,@body)) + + +(ert-deftest test-search-basic () + "Test basic search functionality" + (should + (sx-search-get-questions + "emacs" 1 "emacs"))) + +(ert-deftest test-search-empty () + "Test bogus search returns empty vector" + (test-with-bogus-string query + (should + (equal + [] + (sx-search-get-questions "emacs" 1 query))))) + +(ert-deftest test-search-invalid () + "Test invalid search" + (should-error + ;; @todo: test the interactive call + (sx-search + "emacs" nil nil ["emacs"]))) + +(ert-deftest test-search-full-page () + "Test retrieval of the full search page" + (should + (= 30 (length (sx-search-get-questions + "stackoverflow" 1 "jquery"))))) + +(ert-deftest test-search-exclude-tags () + "Test excluding tags from a search" + (should + (cl-every + (lambda (p) + (sx-assoc-let p + (not (member "org-export" .tags)))) + (sx-search-get-questions + "emacs" 1 nil "org-mode" "org-export"))) + (should + (cl-every + (lambda (p) + (sx-assoc-let p + (not (or (member "org-export" .tags) + (member "org-agenda" .tags))))) + (sx-search-get-questions + "emacs" 1 nil "org-mode" + ["org-export" "org-agenda"])))) + diff --git a/test/tests.el b/test/tests.el index 53e053f..d06c0ff 100644 --- a/test/tests.el +++ b/test/tests.el @@ -58,4 +58,4 @@ (apply #'message message args))) (mapc #'sx-load-test - '(api macros printing util)) + '(api macros printing util search)) -- cgit v1.2.3 From 80541f53ab81695f5878055ac4404ee212766b11 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 1 Jan 2015 23:20:34 -0500 Subject: Checkdoc --- sx.el | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/sx.el b/sx.el index b31b22f..e6215b4 100644 --- a/sx.el +++ b/sx.el @@ -74,7 +74,7 @@ DATA can also be the link itself." "\\1\\2" link)))) (defun sx--ensure-site (data) - "Add a `site' property to DATA if it doesn't have one. Return DATA. + "Add a `site' property to DATA if it doesn't have one. Return DATA. DATA can be a question, answer, comment, or user (or any object with a `link' property)." (when data @@ -132,8 +132,9 @@ with a `link' property)." result)) (defmacro sx-assoc-let (alist &rest body) - "Identical to `let-alist', except `.site' has a special meaning. -If ALIST doesn't have a `site' property, one is created using the + "Use ALIST with `let-alist' to execute BODY. +`.site' has a special meaning, thanks to `sx--ensure-site'. If +ALIST doesn't have a `site' property, one is created using the `link' property." (declare (indent 1) (debug t)) (require 'let-alist) @@ -191,13 +192,12 @@ All ARGS are passed to `completing-read' or `ido-completing-read'." args)) (defun sx--multiple-read (prompt hist-var) - "Interactively query gthe user for a list of strings. + "Interactively query the user for a list of strings. Call `read-string' multiple times, until the input is empty. -PROMPT is a string displayed to the user. and should not -end with a space nor a colon. -HIST-VAR is a quoted symbol, indicating a list in which to store -input history." +PROMPT is a string displayed to the user and should not end with +a space nor a colon. HIST-VAR is a quoted symbol, indicating a +list in which to store input history." (let (list input) (while (not (string= "" @@ -336,7 +336,7 @@ Return the result of BODY." ("ĥ" . "h") ("ĵ" . "j") ("^[:ascii:]" . "")) - "List of replacements to use for non-ascii characters + "List of replacements to use for non-ascii characters. Used to convert user names into @mentions.") (defun sx--user-@name (user) -- cgit v1.2.3 From b87903a14b5b6da5b847ed64de34df00971cbb4a Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 2 Jan 2015 09:00:27 -0500 Subject: Introduce convencience function for site prompting Arose from comment discussion at [1]. This function allows for simplified syntax when the use case wants to retrieve a site token in an interactive context. See docstring for details. [1]: https://github.com/vermiculus/sx.el/pull/183/files#r22403919 --- sx-interaction.el | 12 ++++++++++++ sx-search.el | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/sx-interaction.el b/sx-interaction.el index 9ced1ab..d814485 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -345,6 +345,18 @@ from context at point." (sx-site-get-api-tokens) nil t nil nil default))) +(defun sx--maybe-site-prompt (arg) + "Get a site token conditionally in an interactive context. +If PREFIX-ARG is non-nil, use `sx--interactive-site-prompt'. +Otherwise, use `sx-question-list--site' if non-nil. If nil, +use `sx--interactive-site-prompt' anyway." + ;; This could eventually be generalized into (sx--maybe-prompt + ;; prefix-arg value-if-non-nil #'prompt-function). + (if arg + (sx--interactive-site-prompt) + (or sx-question-list--site + (sx--interactive-site-prompt)))) + ;;;###autoload (defun sx-ask (site) "Start composing a question for SITE. diff --git a/sx-search.el b/sx-search.el index 928db5d..2633da9 100644 --- a/sx-search.el +++ b/sx-search.el @@ -74,7 +74,7 @@ of which is allowed to match. Interactively, the user is asked for SITE and QUERY. With a prefix argument, the user is asked for everything." (interactive - (let ((site (sx--interactive-site-prompt)) + (let ((site (sx--maybe-site-prompt current-prefix-arg)) (query (read-string (format "Query (%s): " (if current-prefix-arg "optional" "mandatory")) -- cgit v1.2.3 From 57a784d6810ab19771db46d9339b73ab27240b87 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 2 Jan 2015 10:54:26 -0500 Subject: Fix bad docstring Branch: search --- sx-interaction.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sx-interaction.el b/sx-interaction.el index d814485..be9d664 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -347,9 +347,9 @@ from context at point." (defun sx--maybe-site-prompt (arg) "Get a site token conditionally in an interactive context. -If PREFIX-ARG is non-nil, use `sx--interactive-site-prompt'. -Otherwise, use `sx-question-list--site' if non-nil. If nil, -use `sx--interactive-site-prompt' anyway." +If ARG is non-nil, use `sx--interactive-site-prompt'. +Otherwise, use `sx-question-list--site' if non-nil. +If nil, use `sx--interactive-site-prompt' anyway." ;; This could eventually be generalized into (sx--maybe-prompt ;; prefix-arg value-if-non-nil #'prompt-function). (if arg -- cgit v1.2.3 From a11be51a7aa5ea26e3d55383d328a0624b924125 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 2 Jan 2015 12:02:27 -0500 Subject: Use .site_par in tests In accordance with d51791fb6ae69e3b426f7d598920b4349858908f --- test/test-macros.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test-macros.el b/test/test-macros.el index 2169088..b6bf20b 100644 --- a/test/test-macros.el +++ b/test/test-macros.el @@ -9,11 +9,11 @@ "Test `sx-assoc-let'" (sx-test-with-json-data data (should - (null (let-alist data .site)))) + (null (let-alist data .site_par)))) (sx-test-with-json-data data (should - (equal (sx-assoc-let data .site) + (equal (sx-assoc-let data .site_par) "meta.emacs"))) (sx-test-with-json-data data -- cgit v1.2.3 From 0325369632523a81e4246533e4067ebd57f7a0e7 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Fri, 2 Jan 2015 12:09:06 -0500 Subject: Fix docstring Branch: search --- sx.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sx.el b/sx.el index 2605f27..62484b7 100644 --- a/sx.el +++ b/sx.el @@ -138,8 +138,8 @@ with a `link' property)." (defmacro sx-assoc-let (alist &rest body) "Use ALIST with `let-alist' to execute BODY. -`.site' has a special meaning, thanks to `sx--ensure-site'. If -ALIST doesn't have a `site' property, one is created using the +`.site_par' has a special meaning, thanks to `sx--ensure-site'. +If ALIST doesn't have a `site' property, one is created using the `link' property." (declare (indent 1) (debug t)) (require 'let-alist) -- cgit v1.2.3