diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-02 01:33:59 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-12-02 01:33:59 +0000 |
commit | 1174858c8f7e87546e671c7322850e2c9e22de4d (patch) | |
tree | 5e4ac7e200642ae8150b8f0b962350f40bca252e | |
parent | f939c9d9fd7a2e7aabe23b2a8084652d12ca5751 (diff) |
Implement a command for asking.
-rw-r--r-- | sx-interaction.el | 17 | ||||
-rw-r--r-- | sx-question-list.el | 1 | ||||
-rw-r--r-- | sx-tab.el | 22 |
3 files changed, 33 insertions, 7 deletions
diff --git a/sx-interaction.el b/sx-interaction.el index df871dd..ce00889 100644 --- a/sx-interaction.el +++ b/sx-interaction.el @@ -26,6 +26,8 @@ (require 'sx-question) (require 'sx-question-mode) (require 'sx-question-list) +(require 'sx-compose) +(require 'sx-tab) ;;; Using data in buffer @@ -222,6 +224,21 @@ from context at point." (sx--maybe-update-display buffer)))))))) +;;; Asking +(defun sx-ask (site) + "Start composing a question for SITE. +SITE is a string, indicating where the question will be posted." + ;; Answering doesn't really make sense from anywhere other than + ;; inside a question. So we don't need `sx--data-here' here. + (interactive (list (sx-tab--interactive-site-prompt))) + (let ((buffer (current-buffer))) + (pop-to-buffer + (sx-compose--create + site nil nil + ;; After send functions + (list (lambda (_ res) (sx--maybe-update-display buffer))))))) + + ;;; Answering (defun sx-answer (data) "Start composing an answer for question given by DATA. diff --git a/sx-question-list.el b/sx-question-list.el index 9709b99..2bfcce0 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -299,6 +299,7 @@ into consideration. ("K" sx-question-list-previous-far) ("g" sx-question-list-refresh) (":" sx-question-list-switch-site) + ("a" sx-ask) ("v" sx-visit) ("u" sx-toggle-upvote) ("d" sx-toggle-downvote) @@ -26,13 +26,24 @@ (require 'sx) (require 'sx-question-list) -(require 'sx-interaction) (defcustom sx-tab-default-site "emacs" "Name of the site to use by default when listing questions." :type 'string :group 'sx) +(defun sx-tab--interactive-site-prompt () + "Query the user for a site." + (let ((default (or sx-question-list--site + (sx-assoc-let sx-question-mode--data + .site) + sx-tab-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))) + +;;; The main macro (defmacro sx-tab--define (tab pager &optional printer refresher &rest body) "Define a StackExchange tab called TAB. @@ -56,7 +67,7 @@ variables, but before refreshing the display." `(progn (defvar ,buffer-variable nil ,(format "Buffer where the %s questions are displayed." - tab)) + tab)) (defun ,(intern (concat "sx-tab-" name)) (&optional no-update site) @@ -64,13 +75,10 @@ variables, but before refreshing the display." NO-UPDATE (the prefix arg) is passed to `sx-question-list-refresh'. If SITE is nil, use `sx-tab-default-site'." - tab) + tab) (interactive (list current-prefix-arg - (funcall (if ido-mode #'ido-completing-read #'completing-read) - (format "Site (%s): " sx-tab-default-site) - (sx-site-get-api-tokens) nil t nil nil - sx-tab-default-site))) + (sx-tab--interactive-site-prompt))) (sx-initialize) (unless site (setq site sx-tab-default-site)) ;; Create the buffer |