aboutsummaryrefslogtreecommitdiff
path: root/sx-question.el
diff options
context:
space:
mode:
authorSean Allred <code@seanallred.com>2014-11-14 09:34:14 -0500
committerSean Allred <code@seanallred.com>2014-11-14 09:34:14 -0500
commit77e519de7b1219767a25399b727c2aece6189e6c (patch)
tree5c99eb09549561a549e93c19aaa788cd81a16073 /sx-question.el
parent525a304f9aca38e1101a1d02ade26ec3b8e91b23 (diff)
parent8d14a6b425d27b7b942f3922d583877ec8b00690 (diff)
Merge pull request #46 from vermiculus/sx-question-mode
Question Mode
Diffstat (limited to 'sx-question.el')
-rw-r--r--sx-question.el76
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