aboutsummaryrefslogtreecommitdiff
path: root/sx-question-mode.el
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-11-25 23:25:45 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-11-25 23:25:45 +0000
commit3a13169bb9b02a4f5935d992e603f53115ddf3dd (patch)
treeb9ea7e43db0fcea03eb0116287ec68300c124c8f /sx-question-mode.el
parent4368b7693a0fa8e9118655014685f7aed299a75f (diff)
Question/answer score is displayed in the question buffer
Diffstat (limited to 'sx-question-mode.el')
-rw-r--r--sx-question-mode.el64
1 files changed, 49 insertions, 15 deletions
diff --git a/sx-question-mode.el b/sx-question-mode.el
index e762bab..f1a8cc0 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -54,13 +54,17 @@
If WINDOW is nil, use selected one.
Returns the question buffer."
+ (with-current-buffer
+ (sx-question-mode--display-buffer window)
+ (sx-question-mode--erase-and-print-question data)))
+
+(defun sx-question-mode--erase-and-print-question (data)
+ "Erase contents of buffer and print question given by DATA."
(let ((inhibit-read-only t))
- (with-current-buffer
- (sx-question-mode--display-buffer window)
- (erase-buffer)
- (sx-question-mode)
- (sx-question-mode--print-question data)
- (current-buffer))))
+ (erase-buffer)
+ (sx-question-mode)
+ (sx-question-mode--print-question data)
+ (current-buffer)))
(defun sx-question-mode--display-buffer (window)
"Display and return the buffer used for displaying a question.
@@ -134,11 +138,32 @@ If WINDOW is given, use that to display the buffer."
"Face used for author names in the question buffer."
:group 'sx-question-mode-faces)
+(defface sx-question-mode-score
+ '((t))
+ "Face used for the score in the question buffer."
+ :group 'sx-question-mode-faces)
+
+(defface sx-question-mode-score-downvoted
+ '((t :inherit (font-lock-warning-face sx-question-mode-score)))
+ "Face used for downvoted score in the question buffer."
+ :group 'sx-question-mode-faces)
+
+(defface sx-question-mode-score-upvoted
+ '((t :weight bold
+ :inherit (font-lock-function-name-face sx-question-mode-score)))
+ "Face used for downvoted score in the question buffer."
+ :group 'sx-question-mode-faces)
+
(defcustom sx-question-mode-header-tags "\nTags: "
"String used before the question tags at the header."
:type 'string
:group 'sx-question-mode)
+(defcustom sx-question-mode-header-score "\nScore: "
+ "String used before the question score at the header."
+ :type 'string
+ :group 'sx-question-mode)
+
(defface sx-question-mode-content-face
'((((background dark)) :background "#090909")
(((background light)) :background "#f4f4f4"))
@@ -195,10 +220,9 @@ QUESTION must be a data structure returned by `json-read'."
;; Print everything
(sx-question-mode--print-section question)
(sx-assoc-let question
- (mapc #'sx-question-mode--print-section .answers))
+ (mapc #'sx-question-mode--print-section .answers))
(goto-char (point-min))
- (with-selected-window sx-question-mode--window
- (sx-question-mode-next-section)))
+ (sx-question-mode-next-section))
(defvar sx-question-mode--section-help-echo
(format
@@ -249,6 +273,13 @@ DATA can represent a question or an answer."
(sx-time-since .last_edit_date)
(sx-question-mode--propertize-display-name .last_editor))))
'sx-question-mode-date)
+ (sx-question-mode--insert-header
+ sx-question-mode-header-score
+ (format "%s" .score)
+ (cond
+ ((eq .upvoted t) 'sx-question-mode-score-upvoted)
+ ((eq .downvoted t) 'sx-question-mode-score-downvoted)
+ (t 'sx-question-mode-score)))
(when .title
;; Tags
(sx-question-mode--insert-header
@@ -562,12 +593,15 @@ With non-nil prefix argument NO-UPDATE, just redisplay, don't
query the api."
(interactive "P")
(sx-question-mode--ensure-mode)
- (sx-question-mode--display
- (if no-update
- sx-question-mode--data
- (sx-assoc-let sx-question-mode--data
- (sx-question-get-question .site .question_id)))
- (selected-window)))
+ (let ((point (point)))
+ (sx-question-mode--erase-and-print-question
+ (if no-update
+ sx-question-mode--data
+ (sx-assoc-let sx-question-mode--data
+ (sx-question-get-question .site .question_id))))
+ (goto-char point)
+ (when (get-buffer-window (current-buffer))
+ (recenter))))
(defun sx-question-mode--ensure-mode ()
"Ensures we are in question mode, erroring otherwise."