aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sx-question-list.el4
-rw-r--r--sx-question-mode.el36
-rw-r--r--sx.el6
3 files changed, 43 insertions, 3 deletions
diff --git a/sx-question-list.el b/sx-question-list.el
index 7d43ac9..4f298a3 100644
--- a/sx-question-list.el
+++ b/sx-question-list.el
@@ -393,9 +393,7 @@ Non-interactively, DATA is a question alist."
(defconst sx-question-list--mode-line-format
'(" "
(:propertize
- (:eval (mapconcat #'capitalize
- (split-string sx-question-list--site "\\.")
- " "))
+ (:eval (sx--pretty-site-parameter sx-question-list--site))
face mode-line-buffer-id)
" " mode-name ": "
(:propertize sx-question-list--current-tab
diff --git a/sx-question-mode.el b/sx-question-mode.el
index c91d13e..2e06de6 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -48,6 +48,7 @@ Common values for this variable are `pop-to-buffer' and `switch-to-buffer'."
(defvar sx-question-mode--data nil
"The data of the question being displayed.")
+(make-variable-buffer-local 'sx-question-mode--data)
(defun sx-question-mode--get-window ()
"Return a window displaying a question, or nil."
@@ -69,6 +70,7 @@ Returns the question buffer."
(defun sx-question-mode--erase-and-print-question (data)
"Erase contents of buffer and print question given by DATA.
Also marks the question as read with `sx-question--mark-read'."
+ (sx--ensure-site data)
(sx-question--mark-read data)
(let ((inhibit-read-only t))
(erase-buffer)
@@ -197,13 +199,47 @@ This list must follow the form described in
;;; Major-mode definition
+(defconst sx-question-mode--mode-line
+ '(" "
+ ;; `sx-question-mode--data' is guaranteed to have through
+ ;; `sx--ensure-site' already, so we use `let-alist' instead of
+ ;; `sx-assoc-let' to improve performance (since the mode-line is
+ ;; updated a lot).
+ (:propertize
+ (:eval (sx--pretty-site-parameter
+ (let-alist sx-question-mode--data .site_par)))
+ face mode-line-buffer-id)
+ " " mode-name
+ " ["
+ "Answers: "
+ (:propertize
+ (:eval (number-to-string (let-alist sx-question-mode--data .answer_count)))
+ face mode-line-buffer-id)
+ ", "
+ "Stars: "
+ (:propertize
+ (:eval (number-to-string (or (let-alist sx-question-mode--data .favorite_count) 0)))
+ face mode-line-buffer-id)
+ ", "
+ "Views: "
+ (:propertize
+ (:eval (number-to-string (let-alist sx-question-mode--data .view_count)))
+ face mode-line-buffer-id)
+ "] ")
+ "Mode-line construct to use in `sx-question-mode' buffers.")
+
(define-derived-mode sx-question-mode special-mode "Question"
"Major mode to display and navigate a question and its answers.
Letters do not insert themselves; instead, they are commands.
+Don't activate this mode directly. Instead, to print a question
+on the current buffer use
+`sx-question-mode--erase-and-print-question'.
+
\\<sx-question-mode>
\\{sx-question-mode}"
(setq header-line-format sx-question-mode--header-line)
+ (setq mode-line-format sx-question-mode--mode-line)
;; Determine how to close this window.
(unless (window-parameter nil 'quit-restore)
(set-window-parameter
diff --git a/sx.el b/sx.el
index 2e8f8db..194e32f 100644
--- a/sx.el
+++ b/sx.el
@@ -187,6 +187,12 @@ If ALIST doesn't have a `site' property, one is created using the
,(macroexpand
`(let-alist ,alist ,@body))))
+(defun sx--pretty-site-parameter (site)
+ "Returned a pretty and capitalized version of string SITE."
+ (mapconcat #'capitalize
+ (split-string site "\\.")
+ " "))
+
;;; Utility Functions
(defun sx--split-string (string &optional separators)