annotate lisp/emulation/tpu-extras.el @ 16423:ecbb741d054c

(tpu-load-xkeys): Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Sat, 12 Oct 1996 02:34:32 +0000
parents 83f275dcd93a
children 4a3e3887c0dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; tpu-extras.el --- Scroll margins and free cursor mode for TPU-edt
4524
3d55b6a74eec (tpu-search-internal): Changed variable
Richard M. Stallman <rms@gnu.org>
parents: 4503
diff changeset
2
11594
ddef149290ed Removed reference to tpu-gnu-emacs18-p.
Richard M. Stallman <rms@gnu.org>
parents: 7981
diff changeset
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Rob Riepel <riepel@networking.stanford.edu>
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
5140
9cde7d7fea1f Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 4524
diff changeset
7 ;; Keywords: emulations
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
4450
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
9 ;; This file is part of GNU Emacs.
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
10
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
14 ;; any later version.
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
4450
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
19 ;; GNU General Public License for more details.
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
20
325bc5407213 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 4421
diff changeset
21 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12687
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12687
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 12687
diff changeset
24 ;; Boston, MA 02111-1307, USA.
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
12687
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
28 ;; Use the functions defined here to customize TPU-edt to your tastes by
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
29 ;; setting scroll margins and/or turning on free cursor mode. Here's an
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
30 ;; example for your .emacs file.
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
31
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
32 ;; (tpu-set-cursor-free) ; Set cursor free.
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
33 ;; (tpu-set-scroll-margins "10%" "15%") ; Set scroll margins.
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
34
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
35 ;; Scroll margins and cursor binding can be changed from within emacs using
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
36 ;; the following commands:
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
37
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
38 ;; tpu-set-scroll-margins or set scroll margins
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
39 ;; tpu-set-cursor-bound or set cursor bound
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
40 ;; tpu-set-cursor-free or set cursor free
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
41
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
42 ;; Additionally, Gold-F toggles between bound and free cursor modes.
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
43
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
44 ;; Note that switching out of free cursor mode or exiting TPU-edt while in
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
45 ;; free cursor mode strips trailing whitespace from every line in the file.
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
46
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
47
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
48 ;;; Details:
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
49
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; The functions contained in this file implement scroll margins and free
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; cursor mode. The following keys and commands are affected.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; key/command function scroll cursor
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; Up-Arrow previous line x x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; Down-Arrow next line x x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; Right-Arrow next character x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; Left-Arrow previous character x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; KP0 next or previous line x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; KP7 next or previous page x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; KP8 next or previous screen x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; KP2 next or previous end-of-line x x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; Control-e current end-of-line x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; Control-h previous beginning-of-line x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; Next Scr next screen x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; Prev Scr previous screen x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; Search find a string x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;; Replace find and replace a string x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; Newline insert a newline x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;; Paragraph next or previous paragraph x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;; Auto-Fill break lines on spaces x
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; These functions are not part of the base TPU-edt for the following
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; reasons:
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;; Free cursor mode is implemented with the emacs picture-mode functions.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; These functions support moving the cursor all over the screen, however,
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; when the cursor is moved past the end of a line, spaces or tabs are
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; appended to the line - even if no text is entered in that area. In
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; order for a free cursor mode to work exactly like TPU/edt, this trailing
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; whitespace needs to be dealt with in every function that might encounter
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; it. Such global changes are impractical, however, free cursor mode is
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; too valuable to abandon completely, so it has been implemented in those
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; functions where it serves best.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; The implementation of scroll margins adds overhead to previously
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; simple and often used commands. These commands are now responsible
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;; for their normal operation and part of the display function. There
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; is a possibility that this display overhead could adversely affect the
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; performance of TPU-edt on slower computers. In order to support the
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; widest range of computers, scroll margin support is optional.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
12687
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
93 ;; It's actually not known whether the overhead associated with scroll
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
94 ;; margin support is significant. If you find that it is, please send
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; a note describing the extent of the performance degradation. Be sure
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; to include a description of the platform where you're running TPU-edt.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; Send your note to the address provided by Gold-V.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; Even with these differences and limitations, these functions implement
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; important aspects of the real TPU/edt. Those who miss free cursor mode
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; and/or scroll margins will appreciate these implementations.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;;; Code:
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
7981
54e029bb5894 Require tpu-edt.
Richard M. Stallman <rms@gnu.org>
parents: 5187
diff changeset
106 ;;; Gotta have tpu-edt
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
7981
54e029bb5894 Require tpu-edt.
Richard M. Stallman <rms@gnu.org>
parents: 5187
diff changeset
108 (require 'tpu-edt)
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 ;;; Customization variables
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (defconst tpu-top-scroll-margin 0
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 "*Scroll margin at the top of the screen.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 Interpreted as a percent of the current window size.")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (defconst tpu-bottom-scroll-margin 0
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 "*Scroll margin at the bottom of the screen.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 Interpreted as a percent of the current window size.")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (defvar tpu-backward-char-like-tpu t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 "*If non-nil, in free cursor mode backward-char (left-arrow) works
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 just like TPU/edt. Otherwise, backward-char will move to the end of
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 the previous line when starting from a line beginning.")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 ;;; Global variables
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (defvar tpu-cursor-free nil
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 "If non-nil, let the cursor roam free.")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;;; Hooks -- Set cursor free in picture mode.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ;;; Clean up when writing a file from cursor free mode.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134
11594
ddef149290ed Removed reference to tpu-gnu-emacs18-p.
Richard M. Stallman <rms@gnu.org>
parents: 7981
diff changeset
135 (add-hook 'picture-mode-hook 'tpu-set-cursor-free)
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (defun tpu-write-file-hook nil
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 "Eliminate whitespace at ends of lines, if the cursor is free."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (if (and (buffer-modified-p) tpu-cursor-free) (picture-clean)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (or (memq 'tpu-write-file-hook write-file-hooks)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (setq write-file-hooks
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (cons 'tpu-write-file-hook write-file-hooks)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;;; Utility routines for implementing scroll margins
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (defun tpu-top-check (beg lines)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 "Enforce scroll margin at the top of screen."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (let ((margin (/ (* (window-height) tpu-top-scroll-margin) 100)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (cond ((< beg margin) (recenter beg))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ((< (- beg lines) margin) (recenter margin)))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defun tpu-bottom-check (beg lines)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "Enforce scroll margin at the bottom of screen."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (let* ((height (window-height))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (margin (+ 1 (/ (* height tpu-bottom-scroll-margin) 100)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 ;; subtract 1 from height because it includes mode line
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (difference (- height margin 1)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (cond ((> beg difference) (recenter beg))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ((> (+ beg lines) difference) (recenter (- margin))))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;;; Movement by character
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (defun tpu-forward-char (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 "Move right ARG characters (left if ARG is negative)."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (if tpu-cursor-free (picture-forward-column num) (forward-char num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (defun tpu-backward-char (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 "Move left ARG characters (right if ARG is negative)."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (cond ((not tpu-cursor-free)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (backward-char num))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (tpu-backward-char-like-tpu
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (picture-backward-column num))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 ((bolp)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (backward-char 1)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (picture-end-of-line)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (picture-backward-column (1- num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (picture-backward-column num))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;;; Movement by line
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defun tpu-next-line (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "Move to next line.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 Prefix argument serves as a repeat count."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (if tpu-cursor-free (or (eobp) (picture-move-down num))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (next-line-internal num))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (tpu-bottom-check beg num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (setq this-command 'next-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (defun tpu-previous-line (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 "Move to previous line.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 Prefix argument serves as a repeat count."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (if tpu-cursor-free (picture-move-up num) (next-line-internal (- num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (tpu-top-check beg num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (setq this-command 'previous-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (defun tpu-next-beginning-of-line (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 "Move to beginning of line; if at beginning, move to beginning of next line.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 Accepts a prefix argument for the number of lines to move."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (backward-char 1)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (forward-line (- 1 num))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (tpu-top-check beg num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (defun tpu-next-end-of-line (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 "Move to end of line; if at end, move to end of next line.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 Accepts a prefix argument for the number of lines to move."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (cond (tpu-cursor-free
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (let ((beg (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (if (< 1 num) (forward-line num))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (picture-end-of-line)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (if (<= (point) beg) (progn (forward-line) (picture-end-of-line)))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (forward-char)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (end-of-line num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (tpu-bottom-check beg num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (defun tpu-previous-end-of-line (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 "Move EOL upward.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 Accepts a prefix argument for the number of lines to move."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (cond (tpu-cursor-free
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (picture-end-of-line (- 1 num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (end-of-line (- 1 num))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (tpu-top-check beg num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (defun tpu-current-end-of-line nil
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 "Move point to end of current line."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (interactive)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (let ((beg (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (if tpu-cursor-free (picture-end-of-line) (end-of-line))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (if (= beg (point)) (message "You are already at the end of a line."))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (defun tpu-forward-line (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 "Move to beginning of next line.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 Prefix argument serves as a repeat count."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (next-line-internal num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (tpu-bottom-check beg num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (beginning-of-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defun tpu-backward-line (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 "Move to beginning of previous line.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 Prefix argument serves as repeat count."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (let ((beg (tpu-current-line)))
12687
e7e04fe05a17 (tpu-backward-line): Only move to BOL if not already there.
Richard M. Stallman <rms@gnu.org>
parents: 11594
diff changeset
263 (or (bolp) (>= 0 num) (setq num (- num 1)))
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (next-line-internal (- num))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (tpu-top-check beg num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (beginning-of-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 ;;; Movement by paragraph
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (defun tpu-paragraph (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 "Move to the next paragraph in the current direction.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 A repeat count means move that many paragraphs."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (let* ((left nil)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (beg (tpu-current-line))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (height (window-height))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (top-percent
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (bottom-percent
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (top-margin (/ (* height top-percent) 100))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (bottom-margin (max beg (- height bottom-up-margin 1)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (top (save-excursion (move-to-window-line top-margin) (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (far (save-excursion
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (goto-char bottom) (forward-line (- height 2)) (point))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (cond (tpu-advance
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (tpu-next-paragraph num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (cond((> (point) far)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (setq left (save-excursion (forward-line height)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (if (= 0 left) (recenter top-margin)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (recenter (- left bottom-up-margin))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (and (> (point) bottom) (recenter bottom-margin)))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (tpu-previous-paragraph num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (and (< (point) top) (recenter (min beg top-margin)))))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ;;; Movement by page
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (defun tpu-page (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 "Move to the next page in the current direction.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 A repeat count means move that many pages."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (let* ((left nil)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (beg (tpu-current-line))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (height (window-height))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (top-percent
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (bottom-percent
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (top-margin (/ (* height top-percent) 100))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (bottom-margin (max beg (- height bottom-up-margin 1)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (top (save-excursion (move-to-window-line top-margin) (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (far (save-excursion
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (goto-char bottom) (forward-line (- height 2)) (point))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (cond (tpu-advance
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (forward-page num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (cond((> (point) far)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (setq left (save-excursion (forward-line height)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (if (= 0 left) (recenter top-margin)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (recenter (- left bottom-up-margin))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (and (> (point) bottom) (recenter bottom-margin)))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (backward-page num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (and (< (point) top) (recenter (min beg top-margin)))))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 ;;; Scrolling
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (defun tpu-scroll-window-down (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 "Scroll the display down to the next section.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 A repeat count means scroll that many sections."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (let* ((beg (tpu-current-line))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (height (1- (window-height)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (lines (* num (/ (* height tpu-percent-scroll) 100))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (next-line-internal (- lines))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (tpu-top-check beg lines)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (defun tpu-scroll-window-up (num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 "Scroll the display up to the next section.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 A repeat count means scroll that many sections."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (let* ((beg (tpu-current-line))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (height (1- (window-height)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (lines (* num (/ (* height tpu-percent-scroll) 100))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (next-line-internal lines)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (tpu-bottom-check beg lines)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 ;;; Replace the TPU-edt internal search function
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (defun tpu-search-internal (pat &optional quiet)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 "Search for a string or regular expression."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (let* ((left nil)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (beg (tpu-current-line))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (height (window-height))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (top-percent
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (if (= 0 tpu-top-scroll-margin) 10 tpu-top-scroll-margin))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (bottom-percent
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (if (= 0 tpu-bottom-scroll-margin) 15 tpu-bottom-scroll-margin))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (top-margin (/ (* height top-percent) 100))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (bottom-up-margin (+ 1 (/ (* height bottom-percent) 100)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (bottom-margin (max beg (- height bottom-up-margin 1)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (top (save-excursion (move-to-window-line top-margin) (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (far (save-excursion
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (goto-char bottom) (forward-line (- height 2)) (point))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (tpu-search-internal-core pat quiet)
4524
3d55b6a74eec (tpu-search-internal): Changed variable
Richard M. Stallman <rms@gnu.org>
parents: 4503
diff changeset
377 (if tpu-searching-forward
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (cond((> (point) far)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (setq left (save-excursion (forward-line height)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (if (= 0 left) (recenter top-margin)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (recenter (- left bottom-up-margin))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (t
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (and (> (point) bottom) (recenter bottom-margin))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (and (< (point) top) (recenter (min beg top-margin))))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 ;;; Replace the newline, newline-and-indent, and do-auto-fill functions
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (or (fboundp 'tpu-old-newline)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (fset 'tpu-old-newline (symbol-function 'newline)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (or (fboundp 'tpu-old-do-auto-fill)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (fset 'tpu-old-do-auto-fill (symbol-function 'do-auto-fill)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (or (fboundp 'tpu-old-newline-and-indent)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (fset 'tpu-old-newline-and-indent (symbol-function 'newline-and-indent)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (defun newline (&optional num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 "Insert a newline. With arg, insert that many newlines.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 In Auto Fill mode, can break the preceding line if no numeric arg.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 This is the TPU-edt version that respects the bottom scroll margin."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (interactive "p")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (or num (setq num 1))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (tpu-old-newline num)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (tpu-bottom-check beg num)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (defun newline-and-indent nil
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 "Insert a newline, then indent according to major mode.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 Indentation is done using the current indent-line-function.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 In programming language modes, this is the same as TAB.
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 In some text modes, where TAB inserts a tab, this indents
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 to the specified left-margin column. This is the TPU-edt
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 version that respects the bottom scroll margin."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (interactive)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (tpu-old-newline-and-indent)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (tpu-bottom-check beg 1)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (defun do-auto-fill nil
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 "TPU-edt version that respects the bottom scroll margin."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (let ((beg (tpu-current-line)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (tpu-old-do-auto-fill)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (tpu-bottom-check beg 1)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 ;;; Function to set scroll margins
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427
5187
3c6f2b0ecf8b Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents: 5140
diff changeset
428 ;;;###autoload
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (defun tpu-set-scroll-margins (top bottom)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 "Set scroll margins."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (interactive
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 ;; set top scroll margin
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (or (string= top "")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (if (string= "%" (substring top -1))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (setq tpu-top-scroll-margin (string-to-int top))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (setq tpu-top-scroll-margin
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (/ (1- (+ (* (string-to-int top) 100) (window-height)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (window-height)))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 ;; set bottom scroll margin
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (or (string= bottom "")
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (if (string= "%" (substring bottom -1))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (setq tpu-bottom-scroll-margin (string-to-int bottom))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (setq tpu-bottom-scroll-margin
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (/ (1- (+ (* (string-to-int bottom) 100) (window-height)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (window-height)))))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 ;; report scroll margin settings if running interactively
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (and (interactive-p)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (message "Scroll margins set. Top = %s%%, Bottom = %s%%"
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 tpu-top-scroll-margin tpu-bottom-scroll-margin)))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 ;;; Functions to set cursor bound or free
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455
5187
3c6f2b0ecf8b Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents: 5140
diff changeset
456 ;;;###autoload
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (defun tpu-set-cursor-free nil
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 "Allow the cursor to move freely about the screen."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (interactive)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (setq tpu-cursor-free t)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (substitute-key-definition 'tpu-set-cursor-free
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 'tpu-set-cursor-bound
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 GOLD-map)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (message "The cursor will now move freely about the screen."))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465
5187
3c6f2b0ecf8b Remove free/bound cursor and scroll
Richard M. Stallman <rms@gnu.org>
parents: 5140
diff changeset
466 ;;;###autoload
4421
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (defun tpu-set-cursor-bound nil
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 "Constrain the cursor to the flow of the text."
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (interactive)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (picture-clean)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (setq tpu-cursor-free nil)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (substitute-key-definition 'tpu-set-cursor-bound
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 'tpu-set-cursor-free
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 GOLD-map)
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (message "The cursor is now bound to the flow of your text."))
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476
95bb7e28d761 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 ;;; tpu-extras.el ends here