|
|
1.1 ! root 1: ;; Page motion commands for emacs. ! 2: ;; Copyright (C) 1985 Richard M. Stallman. ! 3: ! 4: ;; This file is part of GNU Emacs. ! 5: ! 6: ;; GNU Emacs is distributed in the hope that it will be useful, ! 7: ;; but WITHOUT ANY WARRANTY. No author or distributor ! 8: ;; accepts responsibility to anyone for the consequences of using it ! 9: ;; or for whether it serves any particular purpose or works at all, ! 10: ;; unless he says so in writing. Refer to the GNU Emacs General Public ! 11: ;; License for full details. ! 12: ! 13: ;; Everyone is granted permission to copy, modify and redistribute ! 14: ;; GNU Emacs, but only under the conditions described in the ! 15: ;; GNU Emacs General Public License. A copy of this license is ! 16: ;; supposed to have been given to you along with GNU Emacs so you ! 17: ;; can know your rights and responsibilities. It should be in a ! 18: ;; file named COPYING. Among other things, the copyright notice ! 19: ;; and this notice must be preserved on all copies. ! 20: ! 21: ! 22: (defun forward-page (&optional count) ! 23: "Move forward to page boundary. With arg, repeat, or go back if negative. ! 24: A page boundary is any line whose beginning matches the regexp page-delimiter." ! 25: (interactive "p") ! 26: (or count (setq count 1)) ! 27: (while (and (> count 0) (not (eobp))) ! 28: (if (re-search-forward page-delimiter nil t) ! 29: nil ! 30: (goto-char (point-max))) ! 31: (setq count (1- count))) ! 32: (while (and (< count 0) (not (bobp))) ! 33: (forward-char -1) ! 34: (if (re-search-backward page-delimiter nil t) ! 35: (goto-char (match-end 0)) ! 36: (goto-char (point-min))) ! 37: (setq count (1+ count)))) ! 38: ! 39: (defun backward-page (&optional count) ! 40: "Move backward to page boundary. With arg, repeat, or go fwd if negative. ! 41: A page boundary is any line whose beginning matches the regexp page-delimiter." ! 42: (interactive "p") ! 43: (or count (setq count 1)) ! 44: (forward-page (- count))) ! 45: ! 46: (defun mark-page (&optional arg) ! 47: "Put mark at end of page, point at beginning. ! 48: A numeric arg specifies to move forward or backward by that many pages, ! 49: thus marking a page other than the one point was originally in." ! 50: (interactive "P") ! 51: (setq arg (if arg (prefix-numeric-value arg) 0)) ! 52: (if (> arg 0) ! 53: (forward-page arg) ! 54: (if (< arg 0) ! 55: (forward-page (1- arg)))) ! 56: (forward-page) ! 57: (set-mark (point)) ! 58: (forward-page -1)) ! 59: ! 60: (defun narrow-to-page (&optional arg) ! 61: "Make text outside current page invisible. ! 62: A numeric arg specifies to move forward or backward by that many pages, ! 63: thus showing a page other than the one point was originally in." ! 64: (interactive "P") ! 65: (setq arg (if arg (prefix-numeric-value arg) 0)) ! 66: (save-excursion ! 67: (if (> arg 0) ! 68: (forward-page arg) ! 69: (if (< arg 0) ! 70: (forward-page (1- arg)))) ! 71: (forward-page) ! 72: (beginning-of-line) ! 73: (narrow-to-region (point) ! 74: (progn ! 75: (forward-page -1) ! 76: (point))))) ! 77: ! 78: (defun count-lines-page () ! 79: "Report number of lines on current page, and how many are before or after point." ! 80: (interactive) ! 81: (save-excursion ! 82: (let ((opoint (point)) beg end ! 83: total before after) ! 84: (forward-page) ! 85: (beginning-of-line) ! 86: (setq end (point)) ! 87: (backward-page) ! 88: (setq beg (point)) ! 89: (setq total (count-lines beg end) ! 90: before (count-lines beg opoint) ! 91: after (count-lines opoint end)) ! 92: (message "Page has %d lines (%d + %d)" total before after)))) ! 93: ! 94: (defun what-page () ! 95: "Print page and line number of point." ! 96: (interactive) ! 97: (let ((count 1) opoint) ! 98: (save-restriction ! 99: (widen) ! 100: (save-excursion ! 101: (beginning-of-line) ! 102: (setq opoint (point)) ! 103: (goto-char 1) ! 104: (while (re-search-forward page-delimiter opoint t) ! 105: (setq count (1+ count))) ! 106: (message "Page %d, line %d" count (1+ (count-lines (point) opoint)))))))
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.