aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2015-02-26 19:42:38 -0300
committerArtur Malabarba <bruce.connor.am@gmail.com>2015-02-26 19:42:38 -0300
commitcd72f5f03dcc3490318920ef95fc09b07ae900da (patch)
treecc2bcb61f4350dce6a5b5ecba12218f25645275f
parentf4ba0e2a11581477e412c276080a049d19351361 (diff)
parent7df79a35edcb79e7caca4a0d50fcec54d5f68fef (diff)
Merge pull request #265 from vermiculus/question-mode-line
Question mode line
-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 def490b..32bc140 100644
--- a/sx-question-list.el
+++ b/sx-question-list.el
@@ -397,9 +397,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 846ad7f..820c5b4 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)
@@ -183,13 +185,47 @@ property."
": Quit")
"Header-line used on the question list.")
+(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 501f1e0..e5e9c3e 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)