aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2015-01-02 09:00:27 -0500
committerSean Allred <code@seanallred.com>2015-01-02 09:00:27 -0500
commitb87903a14b5b6da5b847ed64de34df00971cbb4a (patch)
treed75e0564b947655e996b3fe8387704557c3c5c4a
parent80541f53ab81695f5878055ac4404ee212766b11 (diff)
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
-rw-r--r--sx-interaction.el12
-rw-r--r--sx-search.el2
2 files changed, 13 insertions, 1 deletions
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"))