pjb-page.el 3.68 KB
Newer Older
1
;;;; -*- mode:emacs-lisp;coding:utf-8 -*-
Pascal Bourguignon's avatar
Pascal Bourguignon committed
2 3 4 5 6 7
;;;;****************************************************************************
;;;;FILE:               pjb-page.el
;;;;LANGUAGE:           emacs lisp
;;;;SYSTEM:             POSIX
;;;;USER-INTERFACE:     NONE
;;;;DESCRIPTION
8
;;;;
Pascal Bourguignon's avatar
Pascal Bourguignon committed
9
;;;;    View a buffer page by page.
10
;;;;
Pascal Bourguignon's avatar
Pascal Bourguignon committed
11 12 13 14 15 16 17
;;;;AUTHORS
;;;;    <PJB> Pascal Bourguignon <pjb@informatimago.com>
;;;;MODIFICATIONS
;;;;    2005-06-01 <PJB> Created.
;;;;BUGS
;;;;LEGAL
;;;;    GPL
18
;;;;
19
;;;;    Copyright Pascal Bourguignon 2005 - 2011
20
;;;;
Pascal Bourguignon's avatar
Pascal Bourguignon committed
21 22 23 24
;;;;    This program is free software; you can redistribute it and/or
;;;;    modify it under the terms of the GNU General Public License
;;;;    as published by the Free Software Foundation; either version
;;;;    2 of the License, or (at your option) any later version.
25
;;;;
Pascal Bourguignon's avatar
Pascal Bourguignon committed
26 27 28 29
;;;;    This program is distributed in the hope that it will be
;;;;    useful, but WITHOUT ANY WARRANTY; without even the implied
;;;;    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
;;;;    PURPOSE.  See the GNU General Public License for more details.
30
;;;;
Pascal Bourguignon's avatar
Pascal Bourguignon committed
31 32 33 34 35 36 37 38
;;;;    You should have received a copy of the GNU General Public
;;;;    License along with this program; if not, write to the Free
;;;;    Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;;    Boston, MA 02111-1307 USA
;;;;****************************************************************************

(defvar *saved-scroll-functions* nil)
(make-local-variable '*saved-scroll-functions*)
39

Pascal Bourguignon's avatar
Pascal Bourguignon committed
40 41 42 43 44 45 46 47 48 49 50 51 52
(defun page-mode (&optional on)
  (interactive "p")
  (if (if on (plusp on) (not *saved-scroll-functions*))
    (progn
      (narrow-to-page)
      (unless *saved-scroll-functions*
        (setf *saved-scroll-functions*
              (list (key-binding [prior]) (key-binding [next])
                    (key-binding [home])  (key-binding [end]))))
      (local-set-key [prior] (function pm-backward-page))
      (local-set-key [next]  (function pm-forward-page))
      (local-set-key [home]  (function pm-beginning-of-buffer))
      (local-set-key [end]   (function pm-end-of-buffer)))
53
    (progn
Pascal Bourguignon's avatar
Pascal Bourguignon committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
      (widen)
      (if *saved-scroll-functions*
        (progn
          (local-set-key [prior] (first  *saved-scroll-functions*))
          (local-set-key [next]  (second *saved-scroll-functions*))
          (local-set-key [home]  (third  *saved-scroll-functions*))
          (local-set-key [end]   (fourth *saved-scroll-functions*))
          (setf *saved-scroll-functions* nil))
        (progn
          (local-set-key [prior] (function scroll-down))
          (local-set-key [next]  (function scroll-up))
          (local-set-key [home]  (function beginning-of-buffer))
          (local-set-key [end]   (function end-of-buffer)))))))


(defun pm-forward-page (&optional count)
  (interactive "p")
  (setf count (or count 1))
  (widen)
  (unless (search-forward "\f" nil 'at-limit count)
    (goto-char (point-max)))
  (narrow-to-page))


(defun pm-backward-page (&optional count)
  (interactive "p")
  (setf count (or count 1))
  (widen)
  (unless (search-backward "\f" nil 'at-limit (1+ count))
    (goto-char (point-max)))
  (narrow-to-page))


(defun pm-beginning-of-buffer ()
  (interactive)
  (widen)
  (goto-char (point-min))
  (narrow-to-page))


(defun pm-end-of-buffer ()
  (interactive)
  (widen)
  (goto-char (point-max))
  (narrow-to-page))



(defun pjb-animate (speed)
  (interactive "nSpeed: ")
  (let ((delay (/ 1.0  speed))
        (done  nil))
    (widen)
    (goto-char (point-min))
    (message "Animating...")
    (while (not done)
      (widen)
      (if (search-forward "\f" nil 'at-limit)
        nil
        (goto-char (point-max))
        (setq done t))
      (narrow-to-page)
      (sit-for delay)
      (force-mode-line-update t)
      ) ;;while
119
    (message "Done.")))