comparison lisp/gnus/gnus-sum.el @ 106741:c0641205dcbb

Fix gnus-summary-recenter to properly handle invisible lines * gnus-sum.el (gnus-forward-line-ignore-invisible): New function. (gnus-summary-recenter): Use it instead of forward-line. (Bug#5257)
author Andreas Schwab <schwab@suse.de>
date Tue, 05 Jan 2010 21:37:43 +0100
parents c5e66d596cbf
children f973aced61a2
comparison
equal deleted inserted replaced
106740:4d2fbb46854b 106741:c0641205dcbb
6725 (recenter-top-bottom n) 6725 (recenter-top-bottom n)
6726 (recenter n))) 6726 (recenter n)))
6727 6727
6728 (put 'gnus-recenter 'isearch-scroll t) 6728 (put 'gnus-recenter 'isearch-scroll t)
6729 6729
6730 (defun gnus-forward-line-ignore-invisible (n)
6731 "Move N lines forward (backward if N is negative).
6732 Like forward-line, but skip over (and don't count) invisible lines."
6733 (let (done)
6734 (while (and (> n 0) (not done))
6735 ;; If the following character is currently invisible,
6736 ;; skip all characters with that same `invisible' property value.
6737 (while (invisible-p (point))
6738 (goto-char (next-char-property-change (point))))
6739 (forward-line 1)
6740 (if (eobp)
6741 (setq done t)
6742 (setq n (1- n))))
6743 (while (and (< n 0) (not done))
6744 (forward-line -1)
6745 (if (bobp) (setq done t)
6746 (setq n (1+ n))
6747 (while (and (not (bobp)) (invisible-p (1- (point))))
6748 (goto-char (previous-char-property-change (point))))))))
6749
6730 (defun gnus-summary-recenter () 6750 (defun gnus-summary-recenter ()
6731 "Center point in the summary window. 6751 "Center point in the summary window.
6732 If `gnus-auto-center-summary' is nil, or the article buffer isn't 6752 If `gnus-auto-center-summary' is nil, or the article buffer isn't
6733 displayed, no centering will be performed." 6753 displayed, no centering will be performed."
6734 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle). 6754 ;; Suggested by earle@mahendo.JPL.NASA.GOV (Greg Earle).
6740 ((< (window-height) 7) 1) 6760 ((< (window-height) 7) 1)
6741 (t (if (numberp gnus-auto-center-summary) 6761 (t (if (numberp gnus-auto-center-summary)
6742 gnus-auto-center-summary 6762 gnus-auto-center-summary
6743 (/ (1- (window-height)) 2))))) 6763 (/ (1- (window-height)) 2)))))
6744 (height (1- (window-height))) 6764 (height (1- (window-height)))
6745 (bottom (save-excursion (goto-char (point-max)) 6765 (bottom (save-excursion
6746 (forward-line (- height)) 6766 (goto-char (point-max))
6747 (point))) 6767 (gnus-forward-line-ignore-invisible (- height))
6768 (point)))
6748 (window (get-buffer-window (current-buffer)))) 6769 (window (get-buffer-window (current-buffer))))
6749 (when (get-buffer-window gnus-article-buffer) 6770 (when (get-buffer-window gnus-article-buffer)
6750 ;; Only do recentering when the article buffer is displayed, 6771 ;; Only do recentering when the article buffer is displayed,
6751 ;; Set the window start to either `bottom', which is the biggest 6772 ;; Set the window start to either `bottom', which is the biggest
6752 ;; possible valid number, or the second line from the top, 6773 ;; possible valid number, or the second line from the top,
6753 ;; whichever is the least. 6774 ;; whichever is the least.
6754 (let ((top-pos (save-excursion (forward-line (- top)) (point)))) 6775 (let ((top-pos (save-excursion
6776 (gnus-forward-line-ignore-invisible (- top))
6777 (point))))
6755 (if (> bottom top-pos) 6778 (if (> bottom top-pos)
6756 ;; Keep the second line from the top visible 6779 ;; Keep the second line from the top visible
6757 (set-window-start window top-pos) 6780 (set-window-start window top-pos)
6758 ;; Try to keep the bottom line visible; if it's partially 6781 ;; Try to keep the bottom line visible; if it's partially
6759 ;; obscured, either scroll one more line to make it fully 6782 ;; obscured, either scroll one more line to make it fully
6760 ;; visible, or revert to using TOP-POS. 6783 ;; visible, or revert to using TOP-POS.
6761 (save-excursion 6784 (save-excursion
6762 (goto-char (point-max)) 6785 (goto-char (point-max))
6763 (forward-line -1) 6786 (gnus-forward-line-ignore-invisible -1)
6764 (let ((last-line-start (point))) 6787 (let ((last-line-start (point)))
6765 (goto-char bottom) 6788 (goto-char bottom)
6766 (set-window-start window (point) t) 6789 (set-window-start window (point) t)
6767 (when (not (pos-visible-in-window-p last-line-start window)) 6790 (when (not (pos-visible-in-window-p last-line-start window))
6768 (forward-line 1) 6791 (gnus-forward-line-ignore-invisible 1)
6769 (set-window-start window (min (point) top-pos) t))))))) 6792 (set-window-start window (min (point) top-pos) t)))))))
6770 ;; Do horizontal recentering while we're at it. 6793 ;; Do horizontal recentering while we're at it.
6771 (when (and (get-buffer-window (current-buffer) t) 6794 (when (and (get-buffer-window (current-buffer) t)
6772 (not (eq gnus-auto-center-summary 'vertical))) 6795 (not (eq gnus-auto-center-summary 'vertical)))
6773 (let ((selected (selected-window))) 6796 (let ((selected (selected-window)))