home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / lisp / prim / page.el < prev    next >
Encoding:
Text File  |  1992-06-29  |  4.2 KB  |  128 lines

  1. ;; Page motion commands for emacs.
  2. ;; Copyright (C) 1985 Free Software Foundation, Inc.
  3.  
  4. ;; This file is part of GNU Emacs.
  5.  
  6. ;; GNU Emacs is free software; you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation; either version 1, or (at your option)
  9. ;; any later version.
  10.  
  11. ;; GNU Emacs is distributed in the hope that it will be useful,
  12. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. ;; GNU General Public License for more details.
  15.  
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  18. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.  
  21. (defun forward-page (&optional count)
  22.   "Move forward to page boundary.  With arg, repeat, or go back if negative.
  23. A page boundary is any line whose beginning matches the regexp  page-delimiter."
  24.   (interactive "p")
  25.   (or count (setq count 1))
  26.   (while (and (> count 0) (not (eobp)))
  27.     (if (re-search-forward page-delimiter nil t)
  28.     nil
  29.       (goto-char (point-max)))
  30.     (setq count (1- count)))
  31.   (while (and (< count 0) (not (bobp)))
  32.     (forward-char -1)
  33.     (if (re-search-backward page-delimiter nil t)
  34.     (goto-char (match-end 0))
  35.       (goto-char (point-min)))
  36.     (setq count (1+ count)))
  37.   (setq zmacs-region-stays t))
  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.   (push-mark nil t)
  58.   (forward-page -1)
  59.   (zmacs-activate-region))
  60.  
  61. (defun narrow-to-page (&optional arg)
  62.   "Make text outside current page invisible.
  63. A numeric arg specifies to move forward or backward by that many pages,
  64. thus showing a page other than the one point was originally in."
  65.   (interactive "P")
  66.   (setq arg (if arg (prefix-numeric-value arg) 0))
  67.   (save-excursion
  68.     (widen)
  69.     (if (> arg 0)
  70.     (forward-page arg)
  71.       (if (< arg 0)
  72.       (forward-page (1- arg))))
  73.     ;; Find the end of the page.
  74.     (forward-page)
  75.     ;; If we stopped due to end of buffer, stay there.
  76.     ;; If we stopped after a page delimiter, put end of restriction
  77.     ;; at the beginning of that line.
  78.     (if (save-excursion (beginning-of-line)
  79.             (looking-at page-delimiter))
  80.     (beginning-of-line))
  81.     (narrow-to-region (point)
  82.               (progn
  83.             ;; Find the top of the page.
  84.             (forward-page -1)
  85.             ;; If we found beginning of buffer, stay there.
  86.             ;; If extra text follows page delimiter on same line,
  87.             ;; include it.
  88.             ;; Otherwise, show text starting with following line.
  89.             (if (and (eolp) (not (bobp)))
  90.                 (forward-line 1))
  91.             (point)))))
  92.  
  93. (defun count-lines-page ()
  94.   "Report number of lines on current page, and how many are before or after point."
  95.   (interactive)
  96.   (save-excursion
  97.     (let ((opoint (point)) beg end
  98.       total before after)
  99.       (forward-page)
  100.       (beginning-of-line)
  101.       (or (looking-at page-delimiter)
  102.       (end-of-line))
  103.       (setq end (point))
  104.       (backward-page)
  105.       (setq beg (point))
  106.       (setq total (count-lines beg end)
  107.         before (count-lines beg opoint)
  108.         after (count-lines opoint end))
  109.       (message "Page has %d lines (%d + %d)" total before after)))
  110.   (setq zmacs-region-stays t))
  111.  
  112. (defun what-page ()
  113.   "Print page and line number of point."
  114.   (interactive)
  115.   (save-restriction
  116.     (widen)
  117.     (save-excursion
  118.       (beginning-of-line)
  119.       (let ((count 1)
  120.         (opoint (point)))
  121.     (goto-char 1)
  122.     (while (re-search-forward page-delimiter opoint t)
  123.       (setq count (1+ count)))
  124.     (message "Page %d, line %d"
  125.          count
  126.          (1+ (count-lines (point) opoint))))))
  127.   (setq zmacs-region-stays t))
  128.