aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-13 14:37:05 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-13 14:37:38 +0000
commit70469eb3e31223606fa141dd4deb7684d8a09977 (patch)
tree64836f20a78b32aeabea22c319ae5901ba98a49a
parent5f6640e6af708097379ba419d8735713dbecff6e (diff)
Also print answers
-rw-r--r--sx-question-mode.el49
-rw-r--r--sx-question.el7
2 files changed, 44 insertions, 12 deletions
diff --git a/sx-question-mode.el b/sx-question-mode.el
index 812340f..1c8d19a 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -153,6 +153,11 @@ editor's name."
:type 'string
:group 'sx-question-mode)
+(defcustom sx-question-mode-answer-title " Answer"
+ "Title used at the start of \"Answer\" sections."
+ :type 'string
+ :group 'sx-question-mode)
+
;;; Printing a question's content
;;;; Functions
@@ -162,15 +167,30 @@ editor's name."
"Print a buffer describing QUESTION.
QUESTION must be a data structure returned by `json-read'."
;; Clear the overlays
- (mapc #'delete-overlay sx-question-mode--overlays)
+ (mapc #'delete-overlayj sx-question-mode--overlays)
(setq sx-question-mode--overlays nil)
;; Print everything
+ (sx-question-mode--print-section question)
(sx-assoc-let question
+ (mapc #'sx-question-mode--print-section .answers)))
+
+(defun sx-question-mode--print-section (data)
+ "Print a section corresponding to DATA.
+DATA can represent a question or an answer."
+ (sx-assoc-let data
(insert sx-question-mode-header-title
- (propertize (sx-encoding-clean-content .title)
- 'font-lock-face 'sx-question-mode-title
- 'sx-question-mode--section 1))
- ;; Sections are hidden with overlays
+ (if .title
+ ;; Questions have title
+ (propertize
+ (sx-encoding-clean-content .title)
+ 'font-lock-face 'sx-question-mode-title
+ 'sx-question-mode--section 1)
+ ;; Answers don't
+ (propertize
+ sx-question-mode-answer-title
+ 'font-lock-face 'sx-question-mode-title
+ 'sx-question-mode--section 2)))
+ ;; Sections can be hidden with overlays
(sx-question-mode--wrap-in-overlay
'(sx-question-mode--section-content t)
(sx-question-mode--insert-header
@@ -187,18 +207,25 @@ QUESTION must be a data structure returned by `json-read'."
(sx-time-since .last_edit_date)
(cdr (assoc 'display_name .last_editor)))))
'sx-question-mode-date)
- ;; Tags
- (insert sx-question-mode-header-tags)
- (sx-question-mode--wrap-in-overlay
- '(face sx-question-mode-tags)
- (insert (mapconcat #'sx-question--tag-format .tags " ")))
+ (when .title
+ ;; Tags
+ (insert sx-question-mode-header-tags)
+ (sx-question-mode--wrap-in-overlay
+ '(face sx-question-mode-tags)
+ (insert (mapconcat #'sx-question--tag-format .tags " "))))
;; Body
(insert sx-question-mode-separator)
(sx-question-mode--wrap-in-overlay
'(face sx-question-mode-content-face)
(insert
(sx-encoding-clean-content .body_markdown)
- "\n")))))
+ "\n")))
+ ;; Answers
+ (mapc #'sx-question-mode--print-comment .comments)))
+
+(defun sx-question-mode--print-comment (data)
+ "Print the comment described by alist DATA."
+ )
(defmacro sx-question-mode--wrap-in-overlay (properties &rest body)
"Execute BODY and wrap any inserted text in an overlay.
diff --git a/sx-question.el b/sx-question.el
index e04598b..59d5ded 100644
--- a/sx-question.el
+++ b/sx-question.el
@@ -30,7 +30,12 @@
(require 'sx-method)
(defvar sx-question-browse-filter
- '((question.body_markdown question.comments question.answers answer.body_markdown answer.comments) (user.profile_image shallow_user.profile_image)))
+ '((question.body_markdown
+ question.comments
+ question.answers
+ 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."