aboutsummaryrefslogtreecommitdiff
path: root/sx-question-mode.el
diff options
context:
space:
mode:
Diffstat (limited to 'sx-question-mode.el')
-rw-r--r--sx-question-mode.el60
1 files changed, 46 insertions, 14 deletions
diff --git a/sx-question-mode.el b/sx-question-mode.el
index 9be02ce..f702822 100644
--- a/sx-question-mode.el
+++ b/sx-question-mode.el
@@ -1,4 +1,4 @@
-;;; sx-question-mode.el --- major-mode for displaying questions -*- lexical-binding: t -*-
+;;; sx-question-mode.el --- major-mode for displaying questions -*- lexical-binding: t; -*-
;; Copyright (C) 2014 Artur Malabarba
@@ -33,11 +33,13 @@
;;; Displaying a question
-(defcustom sx-question-mode-display-buffer-function #'switch-to-buffer
+(defcustom sx-question-mode-display-buffer-function #'pop-to-buffer
"Function used to display the question buffer.
Called, for instance, when hitting \\<sx-question-list-mode-map>`\\[sx-question-list-display-question]' on an entry in the
question list.
-This is not used when navigating the question list with `\\[sx-question-list-view-next]."
+This is not used when navigating the question list with `\\[sx-question-list-view-next].
+
+Common values for this variable are `pop-to-buffer' and `switch-to-buffer'."
:type 'function
:group 'sx-question-mode)
@@ -65,7 +67,9 @@ Returns the question buffer."
(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."
+ "Erase contents of buffer and print question given by DATA.
+Also marks the question as read with `sx-question--mark-read'."
+ (sx-question--mark-read data)
(let ((inhibit-read-only t))
(erase-buffer)
(sx-question-mode)
@@ -121,13 +125,11 @@ Prefix argument N moves N sections down or up."
;; If all we did was move out the current one, then move again
;; and we're guaranteed to reach the next section.
(sx-question-mode--goto-property-change 'section n))
- (let ((ov (car-safe (sx-question-mode--section-overlays-at (point)))))
- (unless (and (overlayp ov)
- (overlay-get ov 'invisible))
- (cl-decf count)))))
+ (unless (get-char-property (point) 'invisible)
+ (cl-decf count))))
(when (equal (selected-window) (get-buffer-window))
(when sx-question-mode-recenter-line
- (let ((ov (car-safe (sx-question-mode--section-overlays-at (line-end-position)))))
+ (let ((ov (sx-question-mode--section-overlays-at (line-end-position))))
(when (and (overlayp ov) (> (overlay-end ov) (window-end)))
(recenter sx-question-mode-recenter-line))))
(sx-message-help-echo)))
@@ -176,12 +178,34 @@ property."
;;; Major-mode
+(defvar sx-question-mode--header-line
+ '(" "
+ (:propertize "n p TAB" face mode-line-buffer-id)
+ ": Navigate"
+ " "
+ (:propertize "u d" face mode-line-buffer-id)
+ ": Up/Down Vote"
+ " "
+ (:propertize "c" face mode-line-buffer-id)
+ ": Comment"
+ " "
+ (:propertize "a" face mode-line-buffer-id)
+ ": Answer"
+ " "
+ (:propertize "e" face mode-line-buffer-id)
+ ": Edit"
+ " "
+ (:propertize "q" face mode-line-buffer-id)
+ ": Quit")
+ "Header-line used on the question list.")
+
(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.
\\<sx-question-mode>
\\{sx-question-mode}"
+ (setq header-line-format sx-question-mode--header-line)
;; Determine how to close this window.
(unless (window-parameter nil 'quit-restore)
(set-window-parameter
@@ -196,15 +220,23 @@ Letters do not insert themselves; instead, they are commands.
(mapc
(lambda (x) (define-key sx-question-mode-map
(car x) (cadr x)))
- `(("n" sx-question-mode-next-section)
+ `(
+ ([down] sx-question-mode-next-section)
+ ([up] sx-question-mode-previous-section)
+ ("n" sx-question-mode-next-section)
("p" sx-question-mode-previous-section)
("g" sx-question-mode-refresh)
("c" sx-comment)
- ("v" sx-visit)
- ("u" sx-toggle-upvote)
- ("d" sx-toggle-downvote)
+ ("v" sx-visit-externally)
+ ("u" sx-upvote)
+ ("d" sx-downvote)
("q" quit-window)
(" " scroll-up-command)
+ ("a" sx-answer)
+ ("e" sx-edit)
+ ("S" sx-search)
+ ("s" sx-switchto-map)
+ ("*" sx-favorite)
(,(kbd "S-SPC") scroll-down-command)
([backspace] scroll-down-command)
([tab] forward-button)
@@ -228,7 +260,7 @@ query the api."
(if no-update
sx-question-mode--data
(sx-assoc-let sx-question-mode--data
- (sx-question-get-question .site .question_id))))
+ (sx-question-get-question .site_par .question_id))))
(goto-char point)
(when (equal (selected-window)
(get-buffer-window (current-buffer)))