diff options
author | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-26 12:22:34 +0000 |
---|---|---|
committer | Artur Malabarba <bruce.connor.am@gmail.com> | 2014-11-26 12:22:34 +0000 |
commit | 244aca25de91f6b6e5e9d59775ab05f0669df80c (patch) | |
tree | 14bf81c230f64ad630588d99377d1af7716a7fbc | |
parent | e9f03bfb583d514ff9c930c551f8e0760f29a598 (diff) |
Preserve visual position when refreshing
Both for question list and question mode.
-rw-r--r-- | sx-question-list.el | 20 | ||||
-rw-r--r-- | sx-question-mode.el | 9 |
2 files changed, 17 insertions, 12 deletions
diff --git a/sx-question-list.el b/sx-question-list.el index 2965ede..bb49b54 100644 --- a/sx-question-list.el +++ b/sx-question-list.el @@ -371,19 +371,21 @@ a new list before redisplaying." (setq sx-question-list--unread-count 0) (unless no-update (setq sx-question-list--pages-so-far 1)) - (let ((question-list - (or (and no-update sx-question-list--dataset) - (and (functionp sx-question-list--refresh-function) - (funcall sx-question-list--refresh-function)) - (and (functionp sx-question-list--next-page-function) - (funcall sx-question-list--next-page-function 1)) - sx-question-list--dataset))) + (cl-letf ((question-list + (or (and no-update sx-question-list--dataset) + (and (functionp sx-question-list--refresh-function) + (funcall sx-question-list--refresh-function)) + (and (functionp sx-question-list--next-page-function) + (funcall sx-question-list--next-page-function 1)) + sx-question-list--dataset)) + ;; Preserve window positioning. + ((window-start))) (setq sx-question-list--dataset question-list) ;; Print the result. (setq tabulated-list-entries (mapcar sx-question-list--print-function - (cl-remove-if #'sx-question--hidden-p question-list)))) - (when redisplay (tabulated-list-print 'remember))) + (cl-remove-if #'sx-question--hidden-p question-list))) + (when redisplay (tabulated-list-print 'remember)))) (defcustom sx-question-list-ago-string " ago" "String appended to descriptions of the time since something happened. diff --git a/sx-question-mode.el b/sx-question-mode.el index 70b8866..c90e3e1 100644 --- a/sx-question-mode.el +++ b/sx-question-mode.el @@ -595,15 +595,18 @@ With non-nil prefix argument NO-UPDATE, just redisplay, don't query the api." (interactive "P") (sx-question-mode--ensure-mode) - (let ((point (point))) + (let ((point (point)) + (line (count-screen-lines + (window-start) (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)))) + (when (equal (selected-window) + (get-buffer-window (current-buffer))) + (recenter line)))) (defun sx-question-mode--ensure-mode () "Ensures we are in question mode, erroring otherwise." |