aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtur Malabarba <bruce.connor.am@gmail.com>2014-12-01 02:30:49 +0000
committerArtur Malabarba <bruce.connor.am@gmail.com>2014-12-01 02:40:33 +0000
commit30217190b487a9b0acb7e367fe4bdf226e0819e5 (patch)
treeb2dcdba1e30fcd2dab84163532aff0e4fe342590
parent5bb980d36c6e0346da629ceeb1835a020e75a9b4 (diff)
Maintain good line position while navigating the question list.
-rw-r--r--sx-question-list.el16
1 files changed, 15 insertions, 1 deletions
diff --git a/sx-question-list.el b/sx-question-list.el
index d2e1bb6..18f8ba0 100644
--- a/sx-question-list.el
+++ b/sx-question-list.el
@@ -463,7 +463,21 @@ This does not update `sx-question-mode--window'."
;; If we were trying to move forward, but we hit the end.
(when (eobp)
;; Try to get more questions.
- (sx-question-list-next-page))))
+ (sx-question-list-next-page))
+ (sx-question-list--ensure-line-good-line-position)))
+
+(defun sx-question-list--ensure-line-good-line-position ()
+ "Scroll window such that current line is a good place.
+Check if we're at least 6 lines from the bottom. Scroll up if
+we're not. Do the same for 3 lines from the top."
+ ;; At least one entry below us.
+ (let ((lines-to-bottom (count-screen-lines (point) (window-end))))
+ (unless (>= lines-to-bottom 6)
+ (recenter (- 6))))
+ ;; At least one entry above us.
+ (let ((lines-to-top (count-screen-lines (point) (window-start))))
+ (unless (>= lines-to-top 3)
+ (recenter 3))))
(defun sx-question-list-next-page ()
"Fetch and display the next page of questions."