Mercurial > emacs
comparison lisp/window.el @ 106316:f4a3f47777f7
Add defcustom to define the cycling order of `recenter-top-bottom'. (Bug#4981)
* window.el (recenter-last-op): Doc fix.
(recenter-positions): New defcustom.
(recenter-top-bottom): Rewrite to use `recenter-positions'.
(move-to-window-line-top-bottom): Rewrite to use `recenter-positions'.
author | Juri Linkov <juri@jurta.org> |
---|---|
date | Sun, 29 Nov 2009 23:34:05 +0000 |
parents | 8cb41d65f821 |
children | 073d80030060 |
comparison
equal
deleted
inserted
replaced
106315:19cd8aecf8bd | 106316:f4a3f47777f7 |
---|---|
1616 (kill-buffer buffer) | 1616 (kill-buffer buffer) |
1617 (bury-buffer buffer)))) | 1617 (bury-buffer buffer)))) |
1618 | 1618 |
1619 (defvar recenter-last-op nil | 1619 (defvar recenter-last-op nil |
1620 "Indicates the last recenter operation performed. | 1620 "Indicates the last recenter operation performed. |
1621 Possible values: `top', `middle', `bottom'.") | 1621 Possible values: `top', `middle', `bottom', integer or float numbers.") |
1622 | |
1623 (defcustom recenter-positions '(middle top bottom) | |
1624 "Cycling order for `recenter-top-bottom'. | |
1625 A list of elements with possible values `top', `middle', `bottom', | |
1626 integer or float numbers that define the cycling order for | |
1627 the command `recenter-top-bottom'. | |
1628 | |
1629 Top and bottom destinations are `scroll-margin' lines the from true | |
1630 window top and bottom. Middle redraws the frame and centers point | |
1631 vertically within the window. Integer number moves current line to | |
1632 the specified absolute window-line. Float number between 0.0 and 1.0 | |
1633 means the percentage of the screen space from the top. The default | |
1634 cycling order is middle -> top -> bottom." | |
1635 :type '(repeat (choice | |
1636 (const :tag "Top" top) | |
1637 (const :tag "Middle" middle) | |
1638 (const :tag "Bottom" bottom) | |
1639 (integer :tag "Line number") | |
1640 (float :tag "Percentage"))) | |
1641 :version "23.2" | |
1642 :group 'windows) | |
1622 | 1643 |
1623 (defun recenter-top-bottom (&optional arg) | 1644 (defun recenter-top-bottom (&optional arg) |
1624 "Move current line to window center, top, and bottom, successively. | 1645 "Move current buffer line to the specified window line. |
1625 With no prefix argument, the first call redraws the frame and | 1646 With no prefix argument, successive calls place point according |
1626 centers point vertically within the window. Successive calls | 1647 to the cycling order defined by `recenter-positions'. |
1627 scroll the window, placing point on the top, bottom, and middle | |
1628 consecutively. The cycling order is middle -> top -> bottom. | |
1629 | 1648 |
1630 A prefix argument is handled like `recenter': | 1649 A prefix argument is handled like `recenter': |
1631 With numeric prefix ARG, move current line to window-line ARG. | 1650 With numeric prefix ARG, move current line to window-line ARG. |
1632 With plain `C-u', move current line to window center. | 1651 With plain `C-u', move current line to window center." |
1633 | |
1634 Top and bottom destinations are actually `scroll-margin' lines | |
1635 the from true window top and bottom." | |
1636 (interactive "P") | 1652 (interactive "P") |
1637 (cond | 1653 (cond |
1638 (arg (recenter arg)) ; Always respect ARG. | 1654 (arg (recenter arg)) ; Always respect ARG. |
1639 ((or (not (eq this-command last-command)) | |
1640 (eq recenter-last-op 'bottom)) | |
1641 (setq recenter-last-op 'middle) | |
1642 (recenter)) | |
1643 (t | 1655 (t |
1656 (setq recenter-last-op | |
1657 (if (eq this-command last-command) | |
1658 (car (or (cdr (member recenter-last-op recenter-positions)) | |
1659 recenter-positions)) | |
1660 (car recenter-positions))) | |
1644 (let ((this-scroll-margin | 1661 (let ((this-scroll-margin |
1645 (min (max 0 scroll-margin) | 1662 (min (max 0 scroll-margin) |
1646 (truncate (/ (window-body-height) 4.0))))) | 1663 (truncate (/ (window-body-height) 4.0))))) |
1647 (cond ((eq recenter-last-op 'middle) | 1664 (cond ((eq recenter-last-op 'middle) |
1648 (setq recenter-last-op 'top) | 1665 (recenter)) |
1666 ((eq recenter-last-op 'top) | |
1649 (recenter this-scroll-margin)) | 1667 (recenter this-scroll-margin)) |
1650 ((eq recenter-last-op 'top) | 1668 ((eq recenter-last-op 'bottom) |
1651 (setq recenter-last-op 'bottom) | 1669 (recenter (- -1 this-scroll-margin))) |
1652 (recenter (- -1 this-scroll-margin)))))))) | 1670 ((integerp recenter-last-op) |
1671 (recenter recenter-last-op)) | |
1672 ((floatp recenter-last-op) | |
1673 (recenter (round (* recenter-last-op (window-height)))))))))) | |
1653 | 1674 |
1654 (define-key global-map [?\C-l] 'recenter-top-bottom) | 1675 (define-key global-map [?\C-l] 'recenter-top-bottom) |
1655 | 1676 |
1656 (defun move-to-window-line-top-bottom (&optional arg) | 1677 (defun move-to-window-line-top-bottom (&optional arg) |
1657 "Position point relative to window. | 1678 "Position point relative to window. |
1658 | 1679 |
1659 With a prefix argument ARG, acts like `move-to-window-line'. | 1680 With a prefix argument ARG, acts like `move-to-window-line'. |
1660 | 1681 |
1661 With no argument, positions point at center of window. | 1682 With no argument, positions point at center of window. |
1662 Successive calls position point at the top, the bottom and again | 1683 Successive calls position point at positions defined |
1663 at the center of the window." | 1684 by `recenter-positions'." |
1664 (interactive "P") | 1685 (interactive "P") |
1665 (cond | 1686 (cond |
1666 (arg (move-to-window-line arg)) ; Always respect ARG. | 1687 (arg (move-to-window-line arg)) ; Always respect ARG. |
1667 ((or (not (eq this-command last-command)) | |
1668 (eq recenter-last-op 'bottom)) | |
1669 (setq recenter-last-op 'middle) | |
1670 (call-interactively 'move-to-window-line)) | |
1671 (t | 1688 (t |
1689 (setq recenter-last-op | |
1690 (if (eq this-command last-command) | |
1691 (car (or (cdr (member recenter-last-op recenter-positions)) | |
1692 recenter-positions)) | |
1693 (car recenter-positions))) | |
1672 (let ((this-scroll-margin | 1694 (let ((this-scroll-margin |
1673 (min (max 0 scroll-margin) | 1695 (min (max 0 scroll-margin) |
1674 (truncate (/ (window-body-height) 4.0))))) | 1696 (truncate (/ (window-body-height) 4.0))))) |
1675 (cond ((eq recenter-last-op 'middle) | 1697 (cond ((eq recenter-last-op 'middle) |
1676 (setq recenter-last-op 'top) | 1698 (call-interactively 'move-to-window-line)) |
1699 ((eq recenter-last-op 'top) | |
1677 (move-to-window-line this-scroll-margin)) | 1700 (move-to-window-line this-scroll-margin)) |
1678 ((eq recenter-last-op 'top) | 1701 ((eq recenter-last-op 'bottom) |
1679 (setq recenter-last-op 'bottom) | 1702 (move-to-window-line (- -1 this-scroll-margin))) |
1680 (move-to-window-line (- -1 this-scroll-margin)))))))) | 1703 ((integerp recenter-last-op) |
1704 (move-to-window-line recenter-last-op)) | |
1705 ((floatp recenter-last-op) | |
1706 (move-to-window-line (round (* recenter-last-op (window-height)))))))))) | |
1681 | 1707 |
1682 (define-key global-map [?\M-r] 'move-to-window-line-top-bottom) | 1708 (define-key global-map [?\M-r] 'move-to-window-line-top-bottom) |
1683 | 1709 |
1684 | 1710 |
1685 (defvar mouse-autoselect-window-timer nil | 1711 (defvar mouse-autoselect-window-timer nil |