diff options
Diffstat (limited to 'sx-question.el')
-rw-r--r-- | sx-question.el | 76 |
1 files changed, 27 insertions, 49 deletions
diff --git a/sx-question.el b/sx-question.el index 20a71cc..d15cc80 100644 --- a/sx-question.el +++ b/sx-question.el @@ -30,7 +30,19 @@ (require 'sx-method) (defvar sx-question-browse-filter - '(nil (user.profile_image shallow_user.profile_image))) + '((question.body_markdown + question.comments + question.answers + question.last_editor + user.display_name + comment.owner + comment.body_markdown + comment.body + answer.last_editor + answer.owner + answer.body_markdown + answer.comments) + (user.profile_image shallow_user.profile_image))) (defun sx-question-get-questions (site &optional page) "Get the page PAGE of questions from SITE." @@ -40,6 +52,16 @@ (page . ,page)) sx-question-browse-filter)) +(defun sx-question-get-question (site id) + "Get the question ID from SITE." + (let ((res (sx-method-call + (format "questions/%s" id) + `((site . ,site)) + sx-question-browse-filter))) + (if (vectorp res) + (elt res 0) + (error "Couldn't find question %S in %S" id site)))) + ;;; Question Properties (defun sx-question--read-p (question) @@ -62,54 +84,10 @@ With optional argument predicate, use it instead of `<'." (funcall (or pred #'<) (cdr (assoc property x)) (cdr (assoc property y)))) - -;;; Displaying a question -(defvar sx-question--window nil - "Window where the content of questions is displayed.") - -(defvar sx-question--buffer nil - "Buffer being used to display questions.") - -(defcustom sx-question-use-html t - "If nil, markdown is used for the body." - :type 'boolean - :group 'sx-question) - -(defun sx-question--display (data &optional window) - "Display question given by DATA on WINDOW. -If WINDOW is nil, use selected one." - (let ((sx-lto--body-src-block - (if sx-question-use-html nil - sx-lto--body-src-block)) - (inhibit-read-only t)) - (with-current-buffer - (sx-question--display-buffer window) - (erase-buffer) - (insert - (org-element-interpret-data - (sx-lto--question data))) - (org-mode) - (show-all) - (view-mode) - (current-buffer)))) - -(defun sx-question--display-buffer (window) - "Display and return the buffer used for displaying a question. -Create the buffer if necessary. -If WINDOW is given, use that to display the buffer." - ;; Create the buffer if necessary. - (unless (buffer-live-p sx-question--buffer) - (setq sx-question--buffer - (generate-new-buffer "*sx-question*"))) - (cond - ;; Window was given, use it. - ((window-live-p window) - (set-window-buffer window sx-question--buffer)) - ;; No window, but the buffer is already being displayed somewhere. - ((get-buffer-window sx-question--buffer 'visible)) - ;; Neither, so we create the window. - (t (switch-to-buffer sx-question--buffer))) - sx-question--buffer) + +(defun sx-question--tag-format (tag) + "Formats TAG for display" + (concat "[" tag "]")) (provide 'sx-question) ;;; sx-question.el ends here |