comparison lisp/simple.el @ 6743:77349221ca81

(hscroll-window-column): New function. (hscroll-point-visible): Do the right thing in the hard cases.
author Karl Heuer <kwzh@gnu.org>
date Fri, 08 Apr 1994 03:23:08 +0000
parents 097fa44199ab
children e7d9adf0b7d7
comparison
equal deleted inserted replaced
6742:ef62a96ce830 6743:77349221ca81
1588 "*The number of columns to try scrolling a window by when point moves out. 1588 "*The number of columns to try scrolling a window by when point moves out.
1589 If that fails to bring point back on frame, point is centered instead. 1589 If that fails to bring point back on frame, point is centered instead.
1590 If this is zero, point is always centered after it moves off frame.") 1590 If this is zero, point is always centered after it moves off frame.")
1591 1591
1592 (defun hscroll-point-visible () 1592 (defun hscroll-point-visible ()
1593 "Scrolls the window horizontally to make point visible." 1593 "Scrolls the selected window horizontally to make point visible."
1594 (let* ((here (current-column)) 1594 (save-excursion
1595 (left (window-hscroll)) 1595 (set-buffer (window-buffer))
1596 (right (- (+ left (window-width)) 3))) 1596 (if (not (or truncate-lines
1597 (cond 1597 (> (window-hscroll) 0)
1598 ;; Should we recenter? 1598 (and truncate-partial-width-windows
1599 ((or (< here (- left hscroll-step)) 1599 (< (window-width) (frame-width)))))
1600 (> here (+ right hscroll-step))) 1600 ;; Point is always visible when lines are wrapped.
1601 (set-window-hscroll 1601 ()
1602 (selected-window) 1602 ;; If point is on the invisible part of the line before window-start,
1603 ;; Recenter, but don't show too much white space off the end of 1603 ;; then hscrolling can't bring it back, so reset window-start first.
1604 ;; the line. 1604 (and (< (point) (window-start))
1605 (max 0 1605 (let ((ws-bol (save-excursion
1606 (min (- (save-excursion (end-of-line) (current-column)) 1606 (goto-char (window-start))
1607 (window-width) 1607 (beginning-of-line)
1608 -5) 1608 (point))))
1609 (- here (/ (window-width) 2)))))) 1609 (and (>= (point) ws-bol)
1610 ;; Should we scroll left? 1610 (set-window-start nil ws-bol))))
1611 ((> here right) 1611 (let* ((here (hscroll-window-column))
1612 (scroll-left hscroll-step)) 1612 (left (min (window-hscroll) 1))
1613 ;; Or right? 1613 (right (1- (window-width))))
1614 ((< here left) 1614 ;; Allow for the truncation glyph, if we're not exactly at eol.
1615 (scroll-right hscroll-step))))) 1615 (if (not (and (= here right)
1616 (= (following-char) ?\n)))
1617 (setq right (1- right)))
1618 (cond
1619 ;; If too far away, just recenter. But don't show too much
1620 ;; white space off the end of the line.
1621 ((or (< here (- left hscroll-step))
1622 (> here (+ right hscroll-step)))
1623 (let ((eol (save-excursion (end-of-line) (hscroll-window-column))))
1624 (scroll-left (min (- here (/ (window-width) 2))
1625 (- eol (window-width) -5)))))
1626 ;; Within range. Scroll by one step (or maybe not at all).
1627 ((< here left)
1628 (scroll-right hscroll-step))
1629 ((> here right)
1630 (scroll-left hscroll-step)))))))
1631
1632 ;; This function returns the window's idea of the display column of point,
1633 ;; assuming that the window is already known to be truncated rather than
1634 ;; wrapped, and that we've already handled the case where point is on the
1635 ;; part of the line before window-start. We ignore window-width; if point
1636 ;; is beyond the right margin, we want to know how far. The return value
1637 ;; includes the effects of window-hscroll, window-start, and the prompt
1638 ;; string in the minibuffer. It may be negative due to hscroll.
1639 (defun hscroll-window-column ()
1640 (let* ((hscroll (window-hscroll))
1641 (startpos (save-excursion
1642 (beginning-of-line)
1643 (if (= (point) (save-excursion
1644 (goto-char (window-start))
1645 (beginning-of-line)
1646 (point)))
1647 (goto-char (window-start)))
1648 (point)))
1649 (hpos (+ (if (and (eq (selected-window) (minibuffer-window))
1650 (= 1 (window-start))
1651 (= startpos (point-min)))
1652 (minibuffer-prompt-width)
1653 0)
1654 (min 0 (- 1 hscroll))))
1655 val)
1656 (car (cdr (compute-motion startpos (cons hpos 0)
1657 (point) (cons 0 1)
1658 1000000 (cons hscroll 0) nil)))))
1659
1616 1660
1617 ;; rms: (1) The definitions of arrow keys should not simply restate 1661 ;; rms: (1) The definitions of arrow keys should not simply restate
1618 ;; what keys they are. The arrow keys should run the ordinary commands. 1662 ;; what keys they are. The arrow keys should run the ordinary commands.
1619 ;; (2) The arrow keys are just one of many common ways of moving point 1663 ;; (2) The arrow keys are just one of many common ways of moving point
1620 ;; within a line. Real horizontal autoscrolling would be a good feature, 1664 ;; within a line. Real horizontal autoscrolling would be a good feature,