use cooper theme -- end of git, I am trying livemesh
[srid.dotfiles.git] / emacs / external / smooth-scrolling.el
blob232d6cf0c5a5a9b21ceeb8adb02c54f96cd3f3eb
1 ;; See http://www.emacswiki.org/cgi-bin/wiki/SmoothScrolling
2 ;; for more information on this.
4 (setq scroll-margin 0)
6 (defvar smooth-scroll-margin 10
7 "Number of lines of visible margin at the top and bottom of a window.
8 If the point is within these margins, then scrolling will occur
9 smoothly for `previous-line' at the top of the window, and for
10 `next-line' at the bottom.
12 This is very similar in its goal to `scroll-margin'. However, it
13 is implemented by activating `smooth-scroll-down' and
14 `smooth-scroll-up' advise via `defadvice' for `previous-line' and
15 `next-line' respectively. As a result it avoids problems
16 afflicting `scroll-margin', such as a sudden jump and unexpected
17 highlighting of a region when the mouse is clicked in the margin.
19 Scrolling only occurs when the point is closer to the window
20 boundary it is heading for (top or bottom) than the middle of the
21 window. This is to intelligently handle the case where the
22 margins cover the whole buffer (e.g. if `smooth-scroll-margin'
23 was 5 and `window-height' returned 10 or less).
25 See also `smooth-scroll-strict-margins'.")
27 (defvar smooth-scroll-strict-margins t
28 "If true, the advice code supporting `smooth-scroll-margin'
29 will use `count-screen-lines' to determine the number of
30 *visible* lines between the point and the window top/bottom,
31 rather than `count-lines' which obtains the number of actual
32 newlines. This is because there might be extra newlines hidden
33 by a mode such as folding-mode, outline-mode, org-mode etc., or
34 fewer due to very long lines being displayed wrapped when
35 `truncate-lines' is nil.
37 However, using `count-screen-lines' can supposedly cause
38 performance issues in buffers with extremely long lines. Setting
39 `cache-long-line-scans' may be able to address this;
40 alternatively you can set this variable to nil so that the advice
41 code uses `count-lines', and put up with the fact that sometimes
42 the point will be allowed to stray into the margin.")
44 (defadvice previous-line (after smooth-scroll-down
45 (&optional arg try-vscroll)
46 activate)
47 "Scroll down smoothly if cursor is within `smooth-scroll-margin'
48 lines of the top of the window."
49 (and (> (window-start) (buffer-end -1))
50 (let ((lines-from-window-start
51 (apply (if smooth-scroll-strict-margins
52 'count-screen-lines
53 'count-lines)
54 (list (window-start) (point)))))
55 (and (< lines-from-window-start smooth-scroll-margin)
56 (< lines-from-window-start (/ (window-height) 2))))
57 (save-excursion (scroll-down 1))))
59 (defadvice next-line (after smooth-scroll-up
60 (&optional arg try-vscroll)
61 activate)
62 "Scroll up smoothly if cursor is within `smooth-scroll-margin'
63 lines of the bottom of the window."
64 (interactive)
65 (and (< (window-end) (buffer-end 1))
66 (let ((lines-from-window-bottom
67 (apply (if smooth-scroll-strict-margins
68 'count-screen-lines
69 'count-lines)
70 (list (point) (window-end)))))
71 (and (< lines-from-window-bottom smooth-scroll-margin)
72 (< lines-from-window-bottom (/ (window-height) 2))))
73 (save-excursion (scroll-up 1))))
75 (provide 'smooth-scrolling)