Mercurial > emacs
comparison lisp/follow.el @ 100779:a0ff5fd45390
(follow-select-if-visible): Improve the check for the
last line of the window.
(follow-post-command-hook): Perform redisplay in more circumstances,
to avoid getting point stuck on partially visible lines.
author | Chong Yidong <cyd@stupidchicken.com> |
---|---|
date | Tue, 30 Dec 2008 16:21:20 +0000 |
parents | 3d5ce6a8b477 |
children | a9dc0e7c3f2b |
comparison
equal
deleted
inserted
replaced
100778:77846ef20f35 | 100779:a0ff5fd45390 |
---|---|
1031 ;; We don't select a window if it just has been moved. | 1031 ;; We don't select a window if it just has been moved. |
1032 | 1032 |
1033 (defun follow-select-if-visible (dest win-start-end) | 1033 (defun follow-select-if-visible (dest win-start-end) |
1034 "Select and return a window, if DEST is visible in it. | 1034 "Select and return a window, if DEST is visible in it. |
1035 Return the selected window." | 1035 Return the selected window." |
1036 (let (win) | 1036 (let (win win-end) |
1037 (while (and (not win) win-start-end) | 1037 (while (and (not win) win-start-end) |
1038 ;; Don't select a window that was just moved. This makes it | 1038 ;; Don't select a window that was just moved. This makes it |
1039 ;; possible to later select the last window after a `end-of-buffer' | 1039 ;; possible to later select the last window after a `end-of-buffer' |
1040 ;; command. | 1040 ;; command. |
1041 (when (follow-pos-visible dest (caar win-start-end) win-start-end) | 1041 (when (follow-pos-visible dest (caar win-start-end) win-start-end) |
1042 (setq win (caar win-start-end)) | 1042 (setq win (caar win-start-end) |
1043 win-end (car (cddr (car win-start-end)))) | |
1043 (select-window win)) | 1044 (select-window win)) |
1044 (setq win-start-end (cdr win-start-end))) | 1045 (setq win-start-end (cdr win-start-end))) |
1045 ;; The last line of the window may be partially visible; if so, | 1046 ;; The last line of the window may be partially visible; if so, |
1046 ;; and if point is visible in the next window, select the next | 1047 ;; and if point is visible in the next window, select the next |
1047 ;; window instead. | 1048 ;; window instead. |
1048 (and (/= dest (point-max)) | 1049 (and win |
1050 (/= dest (point-max)) | |
1049 win-start-end | 1051 win-start-end |
1050 (follow-pos-visible dest (caar win-start-end) win-start-end) | 1052 (follow-pos-visible dest (caar win-start-end) win-start-end) |
1053 (save-excursion | |
1054 (goto-char dest) | |
1055 (vertical-motion 1 win) | |
1056 (>= (point) win-end)) | |
1051 (setq win (caar win-start-end)) | 1057 (setq win (caar win-start-end)) |
1052 (select-window win)) | 1058 (select-window win)) |
1053 win)) | 1059 win)) |
1054 | 1060 |
1055 | 1061 |
1371 ;; This is the normal case! | 1377 ;; This is the normal case! |
1372 ;; It should be optimized for speed. | 1378 ;; It should be optimized for speed. |
1373 ((and visible aligned) | 1379 ((and visible aligned) |
1374 (follow-debug-message "same")) | 1380 (follow-debug-message "same")) |
1375 ;; Pick a position in any window. If the display is | 1381 ;; Pick a position in any window. If the display is |
1376 ;; ok, this will pick the `correct' window. If the | 1382 ;; ok, this will pick the `correct' window. |
1377 ;; display is wierd (e.g., after a delete at the | |
1378 ;; beginning of the window) do this anyway. | |
1379 ((follow-select-if-visible dest win-start-end) | 1383 ((follow-select-if-visible dest win-start-end) |
1380 (follow-debug-message "visible") | 1384 (follow-debug-message "visible") |
1381 (setq visible t) | 1385 (goto-char dest) |
1382 (goto-char dest)) | 1386 ;; We have to perform redisplay, since scrolling is |
1387 ;; needed in case the line is partially visible. | |
1388 (setq visible nil)) | |
1383 ;; Not visible anywhere else, lets pick this one. | 1389 ;; Not visible anywhere else, lets pick this one. |
1384 ;; (Is this case used?) | 1390 ;; (Is this case used?) |
1385 (visible | 1391 (visible |
1386 (follow-debug-message "visible in selected.")) | 1392 (follow-debug-message "visible in selected.")) |
1387 ;; Far out! | 1393 ;; Far out! |
1409 ;; window. | 1415 ;; window. |
1410 (unless (eq win (selected-window)) | 1416 (unless (eq win (selected-window)) |
1411 (let ((p (window-point win))) | 1417 (let ((p (window-point win))) |
1412 (set-window-start win (window-start win) nil) | 1418 (set-window-start win (window-start win) nil) |
1413 (set-window-point win p)))) | 1419 (set-window-point win p)))) |
1414 (unless (or visible | 1420 (unless visible |
1415 ;; Use the UPDATE argument of window-end | 1421 ;; If point may not be visible in the selected window, |
1416 ;; instead of calling follow-pos-visible | 1422 ;; perform a redisplay; this ensures scrolling. |
1417 ;; (which may be inaccurate for partially | 1423 (redisplay) |
1418 ;; visible lines). | |
1419 (and (>= dest (window-start)) | |
1420 (< dest (window-end nil t)))) | |
1421 ;; If point is not visible in the selected window, | |
1422 ;; perform a redisplay; this causes scrolling. | |
1423 (sit-for 0) | |
1424 (setq selected-window-up-to-date t) | 1424 (setq selected-window-up-to-date t) |
1425 (follow-avoid-tail-recenter) | 1425 (follow-avoid-tail-recenter) |
1426 (setq win-start-end (follow-windows-start-end windows)) | 1426 (setq win-start-end (follow-windows-start-end windows)) |
1427 (follow-invalidate-cache) | 1427 (follow-invalidate-cache) |
1428 (setq aligned nil)) | 1428 (setq aligned nil)) |