From 73b380e1407bfc688204812bbf58f9872e57f8c5 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 25 Nov 2014 02:45:48 +0000 Subject: sx can also updates question-mode buffer. --- sx-question-mode.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 59313d1..416a4eb 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -552,16 +552,21 @@ Letters do not insert themselves; instead, they are commands. (,(kbd "") backward-button) ([return] push-button))) -(defun sx-question-mode-refresh () +(defun sx-question-mode-refresh (&optional no-update) "Refresh currently displayed question. Queries the API for any changes to the question or its answers or -comments, and redisplays it." - (interactive) +comments, and redisplays it. + +With non-nil prefix argument NO-UPDATE, just redisplay, don't +query the api." + (interactive "P") (sx-question-mode--ensure-mode) - (sx-assoc-let sx-question-mode--data - (sx-question-mode--display - (sx-question-get-question .site .question_id) - (selected-window)))) + (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))) (defun sx-question-mode--ensure-mode () "Ensures we are in question mode, erroring otherwise." -- cgit v1.2.3 From ddd4c4ed0387acd66d80004154835586f540dcd1 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 25 Nov 2014 02:56:29 +0000 Subject: Binds for voting. --- sx-question-list.el | 2 ++ sx-question-mode.el | 2 ++ 2 files changed, 4 insertions(+) (limited to 'sx-question-mode.el') diff --git a/sx-question-list.el b/sx-question-list.el index ddc04c7..36a3c51 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -288,6 +288,8 @@ into consideration. ("g" sx-question-list-refresh) (":" sx-question-list-switch-site) ("v" sx-visit) + ("u" sx-toggle-upvote) + ("d" sx-toggle-downvote) ("h" sx-question-list-hide) ("m" sx-question-list-mark-read) ([?\r] sx-question-list-display-question))) diff --git a/sx-question-mode.el b/sx-question-mode.el index 416a4eb..8ccc576 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -542,6 +542,8 @@ Letters do not insert themselves; instead, they are commands. ("p" sx-question-mode-previous-section) ("g" sx-question-mode-refresh) ("v" sx-visit) + ("u" sx-toggle-upvote) + ("d" sx-toggle-downvote) ("q" quit-window) (" " scroll-up-command) (,(kbd "S-SPC") scroll-down-command) -- cgit v1.2.3 From 4368b7693a0fa8e9118655014685f7aed299a75f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 25 Nov 2014 22:51:04 +0000 Subject: Cleanup old obsolete line. --- sx-question-mode.el | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sx-question-mode.el') diff --git a/sx-question-mode.el b/sx-question-mode.el index 8ccc576..e762bab 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -332,7 +332,6 @@ where `value' is given `face' as its face. (defun sx-question-mode--fill-and-fontify (text) "Return TEXT filled according to `markdown-mode'." (with-temp-buffer - (erase-buffer) (insert text) (markdown-mode) (font-lock-mode -1) @@ -344,8 +343,8 @@ where `value' is given `face' as its face. (font-lock-add-keywords ;; Highlight usernames. nil `((,(rx (or blank line-start) - (group-n 1 (and "@" (1+ (or (syntax word) (syntax symbol))))) - symbol-end) + (group-n 1 (and "@" (1+ (or (syntax word) (syntax symbol))))) + symbol-end) 1 font-lock-builtin-face))) ;; Everything. (font-lock-fontify-region (point-min) (point-max)) -- cgit v1.2.3 From 3a13169bb9b02a4f5935d992e603f53115ddf3dd Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Tue, 25 Nov 2014 23:25:45 +0000 Subject: Question/answer score is displayed in the question buffer --- sx-question-mode.el | 64 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 49 insertions(+), 15 deletions(-) (limited to 'sx-question-mode.el') 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." -- cgit v1.2.3