72
|
1 ;;; tpu-edt.el --- Emacs emulating TPU emulating EDT
|
|
2
|
|
3 ;; Copyright (C) 1993, 1994, 1995 Free Software Foundation, Inc.
|
0
|
4
|
|
5 ;; Author: Rob Riepel <riepel@networking.stanford.edu>
|
|
6 ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu>
|
72
|
7 ;; Version: 4.2
|
0
|
8 ;; Keywords: emulations
|
|
9
|
72
|
10 ;; This file is part of XEmacs.
|
185
|
11 ;; Modified for XEmacs by Kevin Oberman <oberman@es.net>
|
0
|
12
|
72
|
13 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
14 ;; under the terms of the GNU General Public License as published by
|
0
|
15 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
16 ;; any later version.
|
|
17
|
72
|
18 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
185
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
21 ;; GNU General Public License for more details.
|
0
|
22
|
|
23 ;; You should have received a copy of the GNU General Public License
|
185
|
24 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
26 ;; Boston, MA 02111-1307, USA.
|
72
|
27
|
185
|
28 ;;; Synced up with FSF 19.34 and XEmacs 19.16
|
72
|
29
|
|
30 ;; TPU-edt is based on tpu.el by Jeff Kowalski and Bob Covey.
|
|
31
|
|
32 ;;; Commentary:
|
|
33
|
|
34 ;; %% TPU-edt -- Emacs emulating TPU emulating EDT
|
|
35
|
|
36 ;; %% Contents
|
|
37
|
|
38 ;; % Introduction
|
|
39 ;; % Differences Between TPU-edt and DEC TPU/edt
|
|
40 ;; % Starting TPU-edt
|
|
41 ;; % Customizing TPU-edt using the Emacs Initialization File
|
|
42 ;; % Regular Expressions in TPU-edt
|
|
43
|
|
44
|
|
45 ;; %% Introduction
|
|
46
|
|
47 ;; TPU-edt emulates the popular DEC VMS editor EDT (actually, it emulates
|
|
48 ;; DEC TPU's EDT emulation, hence the name TPU-edt). TPU-edt features the
|
|
49 ;; following TPU/edt functionality:
|
|
50
|
|
51 ;; . EDT keypad
|
|
52 ;; . On-line help
|
|
53 ;; . Repeat counts
|
|
54 ;; . Scroll margins
|
|
55 ;; . Learn sequences
|
|
56 ;; . Free cursor mode
|
|
57 ;; . Rectangular cut and paste
|
|
58 ;; . Multiple windows and buffers
|
|
59 ;; . TPU line-mode REPLACE command
|
|
60 ;; . Wild card search and substitution
|
|
61 ;; . Configurable through an initialization file
|
|
62 ;; . History recall of search strings, file names, and commands
|
|
63
|
|
64 ;; Please note that TPU-edt does NOT emulate TPU. It emulates TPU's EDT
|
|
65 ;; emulation. Very few TPU line-mode commands are supported.
|
|
66
|
185
|
67 ;; TPU-edt, like its VMS cousin, works on VT-series terminals with DEC
|
72
|
68 ;; style keyboards. VT terminal emulators, including xterm with the
|
|
69 ;; appropriate key translations, work just fine too.
|
|
70
|
|
71 ;; TPU-edt works with X-windows. This is accomplished through a TPU-edt X
|
|
72 ;; key map. The TPU-edt module tpu-mapper creates this map and stores it
|
|
73 ;; in a file. Tpu-mapper will be run automatically the first time you
|
|
74 ;; invoke the X-windows version of emacs, or you can run it by hand. See
|
|
75 ;; the commentary in tpu-mapper.el for details.
|
|
76
|
|
77
|
|
78 ;; %% Differences Between TPU-edt and DEC TPU/edt
|
|
79
|
|
80 ;; In some cases, Emacs doesn't support text highlighting, so selected
|
|
81 ;; regions are not shown in inverse video. Emacs uses the concept of "the
|
|
82 ;; mark". The mark is set at one end of a selected region; the cursor is
|
|
83 ;; at the other. The letter "M" appears in the mode line when the mark is
|
|
84 ;; set. The native emacs command ^X^X (Control-X twice) exchanges the
|
|
85 ;; cursor with the mark; this provides a handy way to find the location of
|
|
86 ;; the mark.
|
|
87
|
|
88 ;; In TPU the cursor can be either bound or free. Bound means the cursor
|
|
89 ;; cannot wander outside the text of the file being edited. Free means
|
|
90 ;; the arrow keys can move the cursor past the ends of lines. Free is the
|
|
91 ;; default mode in TPU; bound is the only mode in EDT. Bound is the only
|
|
92 ;; mode in the base version of TPU-edt; optional extensions add an
|
|
93 ;; approximation of free mode, see the commentary in tpu-extras.el for
|
|
94 ;; details.
|
|
95
|
|
96 ;; Like TPU, emacs uses multiple buffers. Some buffers are used to hold
|
|
97 ;; files you are editing; other "internal" buffers are used for emacs' own
|
|
98 ;; purposes (like showing you help). Here are some commands for dealing
|
|
99 ;; with buffers.
|
|
100
|
|
101 ;; Gold-B moves to next buffer, including internal buffers
|
|
102 ;; Gold-N moves to next buffer containing a file
|
|
103 ;; Gold-M brings up a buffer menu (like TPU "show buffers")
|
|
104
|
|
105 ;; Emacs is very fond of throwing up new windows. Dealing with all these
|
|
106 ;; windows can be a little confusing at first, so here are a few commands
|
|
107 ;; to that may help:
|
|
108
|
|
109 ;; Gold-Next_Scr moves to the next window on the screen
|
|
110 ;; Gold-Prev_Scr moves to the previous window on the screen
|
|
111 ;; Gold-TAB also moves to the next window on the screen
|
|
112
|
|
113 ;; Control-x 1 deletes all but the current window
|
|
114 ;; Control-x 0 deletes the current window
|
|
115
|
|
116 ;; Note that the buffers associated with deleted windows still exist!
|
|
117
|
|
118 ;; Like TPU, TPU-edt has a "command" function, invoked with Gold-KP7 or
|
|
119 ;; Do. Most of the commands available are emacs commands. Some TPU
|
|
120 ;; commands are available, they are: replace, exit, quit, include, and
|
|
121 ;; Get (unfortunately, "get" is an internal emacs function, so we are
|
|
122 ;; stuck with "Get" - to make life easier, Get is available as Gold-g).
|
|
123
|
|
124 ;; TPU-edt supports the recall of commands, file names, and search
|
|
125 ;; strings. The history of strings recalled differs slightly from
|
|
126 ;; TPU/edt, but it is still very convenient.
|
|
127
|
|
128 ;; Help is available! The traditional help keys (Help and PF2) display
|
|
129 ;; a small help file showing the default keypad layout, control key
|
|
130 ;; functions, and Gold key functions. Pressing any key inside of help
|
|
131 ;; splits the screen and prints a description of the function of the
|
185
|
132 ;; pressed key. Gold-PF2 invokes the native emacs help, with its
|
72
|
133 ;; zillions of options.
|
|
134
|
|
135 ;; Thanks to emacs, TPU-edt has some extensions that may make your life
|
|
136 ;; easier, or at least more interesting. For example, Gold-r toggles
|
|
137 ;; TPU-edt rectangular mode. In rectangular mode, Remove and Insert work
|
|
138 ;; on rectangles. Likewise, Gold-* toggles TPU-edt regular expression
|
|
139 ;; mode. In regular expression mode Find, Find Next, and the line-mode
|
|
140 ;; replace command work with regular expressions. [A regular expression
|
|
141 ;; is a pattern that denotes a set of strings; like VMS wildcards.]
|
|
142
|
|
143 ;; Emacs also gives TPU-edt the undo and occur functions. Undo does
|
|
144 ;; what it says; it undoes the last change. Multiple undos in a row
|
|
145 ;; undo multiple changes. For your convenience, undo is available on
|
|
146 ;; Gold-u. Occur shows all the lines containing a specific string in
|
|
147 ;; another window. Moving to that window, and typing ^C^C (Control-C
|
|
148 ;; twice) on a particular line moves you back to the original window
|
|
149 ;; at that line. Occur is on Gold-o.
|
|
150
|
|
151 ;; Finally, as you edit, remember that all the power of emacs is at
|
|
152 ;; your disposal. It really is a fantastic tool. You may even want to
|
|
153 ;; take some time and read the emacs tutorial; perhaps not to learn the
|
|
154 ;; native emacs key bindings, but to get a feel for all the things
|
|
155 ;; emacs can do for you. The emacs tutorial is available from the
|
|
156 ;; emacs help function: "Gold-PF2 t"
|
|
157
|
|
158
|
|
159 ;; %% Starting TPU-edt
|
|
160
|
|
161 ;; All you have to do to start TPU-edt, is turn it on. This can be
|
|
162 ;; done from the command line when running emacs.
|
|
163
|
|
164 ;; prompt> emacs -f tpu-edt
|
|
165
|
|
166 ;; If you've already started emacs, turn on TPU-edt using the tpu-edt
|
|
167 ;; command. First press `M-x' (that's usually `ESC' followed by `x')
|
|
168 ;; and type `tpu-edt' followed by a carriage return.
|
|
169
|
|
170 ;; If you like TPU-edt and want to use it all the time, you can start
|
|
171 ;; TPU-edt using the emacs initialization file, .emacs. Simply create
|
|
172 ;; a .emacs file in your home directory containing the line:
|
|
173
|
|
174 ;; (tpu-edt)
|
|
175
|
|
176 ;; That's all you need to do to start TPU-edt.
|
|
177
|
|
178
|
|
179 ;; %% Customizing TPU-edt using the Emacs Initialization File
|
|
180
|
|
181 ;; The following is a sample emacs initialization file. It shows how to
|
|
182 ;; invoke TPU-edt, and how to customize it.
|
|
183
|
|
184 ;; ; .emacs - a sample emacs initialization file
|
|
185
|
|
186 ;; ; Turn on TPU-edt
|
|
187 ;; (tpu-edt)
|
|
188
|
|
189 ;; ; Set scroll margins 10% (top) and 15% (bottom).
|
|
190 ;; (tpu-set-scroll-margins "10%" "15%")
|
|
191
|
|
192 ;; ; Load the vtxxx terminal control functions.
|
|
193 ;; (load "vt-control" t)
|
|
194
|
|
195 ;; ; TPU-edt treats words like EDT; here's how to add word separators.
|
|
196 ;; ; Note that backslash (\) and double quote (") are quoted with '\'.
|
|
197 ;; (tpu-add-word-separators "]\\[-_,.\"=+()'/*#:!&;$")
|
|
198
|
|
199 ;; ; Emacs is happy to save files without a final newline; other Unix
|
|
200 ;; ; programs hate that! Here we make sure that files end with newlines.
|
|
201 ;; (setq require-final-newline t)
|
|
202
|
|
203 ;; ; Emacs uses Control-s and Control-q. Problems can occur when using
|
|
204 ;; ; emacs on terminals that use these codes for flow control (Xon/Xoff
|
|
205 ;; ; flow control). These lines disable emacs' use of these characters.
|
|
206 ;; (global-unset-key "\C-s")
|
|
207 ;; (global-unset-key "\C-q")
|
|
208
|
|
209 ;; ; The emacs universal-argument function is very useful.
|
|
210 ;; ; This line maps universal-argument to Gold-PF1.
|
|
211 ;; (define-key GOLD-SS3-map "P" 'universal-argument) ; Gold-PF1
|
|
212
|
|
213 ;; ; Make KP7 move by paragraphs, instead of pages.
|
|
214 ;; (define-key SS3-map "w" 'tpu-paragraph) ; KP7
|
|
215
|
|
216 ;; ; Repeat the preceding mappings for X-windows.
|
|
217 ;; (cond
|
|
218 ;; (window-system
|
134
|
219 ;; (global-set-key [kp_7] 'tpu-paragraph) ; KP7
|
|
220 ;; (define-key GOLD-map [kp_f1] 'universal-argument))) ; GOLD-PF1
|
72
|
221
|
|
222 ;; ; Display the TPU-edt version.
|
|
223 ;; (tpu-version)
|
|
224
|
|
225
|
|
226 ;; %% Regular Expressions in TPU-edt
|
|
227
|
|
228 ;; Gold-* toggles TPU-edt regular expression mode. In regular expression
|
|
229 ;; mode, find, find next, replace, and substitute accept emacs regular
|
|
230 ;; expressions. A complete list of emacs regular expressions can be found
|
|
231 ;; using the emacs "info" command (it's somewhat like the VMS help
|
|
232 ;; command). Try the following sequence of commands:
|
|
233
|
|
234 ;; DO info <enter info mode>
|
|
235 ;; m emacs <select the "emacs" topic>
|
|
236 ;; m regexs <select the "regular expression" topic>
|
|
237
|
|
238 ;; Type "q" to quit out of info mode.
|
|
239
|
|
240 ;; There is a problem in regular expression mode when searching for empty
|
|
241 ;; strings, like beginning-of-line (^) and end-of-line ($). When searching
|
|
242 ;; for these strings, find-next may find the current string, instead of the
|
|
243 ;; next one. This can cause global replace and substitute commands to loop
|
|
244 ;; forever in the same location. For this reason, commands like
|
|
245
|
|
246 ;; replace "^" "> " <add "> " to beginning of line>
|
|
247 ;; replace "$" "00711" <add "00711" to end of line>
|
|
248
|
|
249 ;; may not work properly.
|
|
250
|
|
251 ;; Commands like those above are very useful for adding text to the
|
|
252 ;; beginning or end of lines. They might work on a line-by-line basis, but
|
|
253 ;; go into an infinite loop if the "all" response is specified. If the
|
|
254 ;; goal is to add a string to the beginning or end of a particular set of
|
|
255 ;; lines TPU-edt provides functions to do this.
|
|
256
|
|
257 ;; Gold-^ Add a string at BOL in region or buffer
|
|
258 ;; Gold-$ Add a string at EOL in region or buffer
|
|
259
|
|
260 ;; There is also a TPU-edt interface to the native emacs string replacement
|
|
261 ;; commands. Gold-/ invokes this command. It accepts regular expressions
|
|
262 ;; if TPU-edt is in regular expression mode. Given a repeat count, it will
|
|
263 ;; perform the replacement without prompting for confirmation.
|
|
264
|
|
265 ;; This command replaces empty strings correctly, however, it has its
|
|
266 ;; drawbacks. As a native emacs command, it has a different interface
|
|
267 ;; than the emulated TPU commands. Also, it works only in the forward
|
|
268 ;; direction, regardless of the current TPU-edt direction.
|
|
269
|
0
|
270 ;;; Code:
|
|
271
|
|
272
|
|
273 ;;;
|
72
|
274 ;;; Version Information
|
0
|
275 ;;;
|
185
|
276 (defconst tpu-version "4.2X" "TPU-edt version number.")
|
0
|
277
|
|
278
|
|
279 ;;;
|
|
280 ;;; User Configurable Variables
|
|
281 ;;;
|
|
282 (defconst tpu-have-ispell t
|
|
283 "*If non-nil (default), TPU-edt uses ispell for spell checking.")
|
|
284
|
|
285 (defconst tpu-kill-buffers-silently nil
|
|
286 "*If non-nil, TPU-edt kills modified buffers without asking.")
|
|
287
|
|
288 (defvar tpu-percent-scroll 75
|
|
289 "*Percentage of the screen to scroll for next/previous screen commands.")
|
|
290
|
|
291 (defvar tpu-pan-columns 16
|
|
292 "*Number of columns the tpu-pan functions scroll left or right.")
|
|
293
|
|
294
|
|
295 ;;;
|
|
296 ;;; Emacs version identifiers - currently referenced by
|
|
297 ;;;
|
|
298 ;;; o tpu-mark o tpu-set-mark
|
|
299 ;;; o tpu-string-prompt o tpu-regexp-prompt
|
|
300 ;;; o tpu-edt-on o tpu-load-xkeys
|
|
301 ;;; o tpu-update-mode-line o mode line section
|
|
302 ;;;
|
|
303 (defconst tpu-emacs19-p (not (string-lessp emacs-version "19"))
|
72
|
304 "Non-nil if we are running Lucid Emacs or version 19.")
|
0
|
305
|
72
|
306 (defconst tpu-lucid-emacs19-p
|
|
307 (and tpu-emacs19-p (string-match "Lucid" emacs-version))
|
|
308 "Non-nil if we are running Lucid Emacs version 19.")
|
0
|
309
|
|
310
|
|
311 ;;;
|
|
312 ;;; Global Keymaps
|
|
313 ;;;
|
|
314 (defvar CSI-map (make-sparse-keymap)
|
|
315 "Maps the CSI function keys on the VT100 keyboard.
|
|
316 CSI is DEC's name for the sequence <ESC>[.")
|
|
317
|
|
318 (defvar SS3-map (make-sparse-keymap)
|
|
319 "Maps the SS3 function keys on the VT100 keyboard.
|
|
320 SS3 is DEC's name for the sequence <ESC>O.")
|
|
321
|
|
322 (defvar GOLD-map (make-keymap)
|
72
|
323 "Maps the function keys on the VT100 keyboard preceded by PF1.
|
0
|
324 GOLD is the ASCII 7-bit escape sequence <ESC>OP.")
|
|
325
|
|
326 (defvar GOLD-CSI-map (make-sparse-keymap)
|
72
|
327 "Maps the function keys on the VT100 keyboard preceded by GOLD-CSI.")
|
0
|
328
|
|
329 (defvar GOLD-SS3-map (make-sparse-keymap)
|
72
|
330 "Maps the function keys on the VT100 keyboard preceded by GOLD-SS3.")
|
0
|
331
|
|
332 (defvar tpu-global-map nil "TPU-edt global keymap.")
|
|
333 (defvar tpu-original-global-map (copy-keymap global-map)
|
|
334 "Original global keymap.")
|
|
335
|
72
|
336 (and tpu-lucid-emacs19-p
|
0
|
337 (defvar minibuffer-local-ns-map (make-sparse-keymap)
|
72
|
338 "Hack to give Lucid Emacs the same maps as ordinary Emacs."))
|
0
|
339
|
|
340
|
|
341 ;;;
|
|
342 ;;; Global Variables
|
|
343 ;;;
|
|
344 (defvar tpu-edt-mode nil
|
|
345 "If non-nil, TPU-edt mode is active.")
|
|
346
|
|
347 (defvar tpu-last-replaced-text ""
|
|
348 "Last text deleted by a TPU-edt replace command.")
|
|
349 (defvar tpu-last-deleted-region ""
|
|
350 "Last text deleted by a TPU-edt remove command.")
|
|
351 (defvar tpu-last-deleted-lines ""
|
|
352 "Last text deleted by a TPU-edt line-delete command.")
|
|
353 (defvar tpu-last-deleted-words ""
|
|
354 "Last text deleted by a TPU-edt word-delete command.")
|
|
355 (defvar tpu-last-deleted-char ""
|
|
356 "Last character deleted by a TPU-edt character-delete command.")
|
|
357
|
|
358 (defvar tpu-searching-forward t
|
|
359 "If non-nil, TPU-edt is searching in the forward direction.")
|
|
360 (defvar tpu-search-last-string ""
|
|
361 "Last text searched for by the TPU-edt search commands.")
|
|
362
|
|
363 (defvar tpu-regexp-p nil
|
|
364 "If non-nil, TPU-edt uses regexp search and replace routines.")
|
|
365 (defvar tpu-rectangular-p nil
|
|
366 "If non-nil, TPU-edt removes and inserts rectangles.")
|
|
367 (defvar tpu-advance t
|
|
368 "True when TPU-edt is operating in the forward direction.")
|
|
369 (defvar tpu-reverse nil
|
|
370 "True when TPU-edt is operating in the backward direction.")
|
72
|
371 (defvar tpu-control-keys nil
|
0
|
372 "If non-nil, control keys are set to perform TPU functions.")
|
|
373 (defvar tpu-xkeys-file nil
|
|
374 "File containing TPU-edt X key map.")
|
|
375
|
|
376 (defvar tpu-rectangle-string nil
|
|
377 "Mode line string to identify rectangular mode.")
|
|
378 (defvar tpu-direction-string nil
|
|
379 "Mode line string to identify current direction.")
|
|
380
|
|
381 (defvar tpu-add-at-bol-hist nil
|
|
382 "History variable for tpu-edt-add-at-bol function.")
|
|
383 (defvar tpu-add-at-eol-hist nil
|
|
384 "History variable for tpu-edt-add-at-eol function.")
|
|
385 (defvar tpu-regexp-prompt-hist nil
|
|
386 "History variable for search and replace functions.")
|
|
387
|
|
388
|
|
389 ;;;
|
|
390 ;;; Buffer Local Variables
|
|
391 ;;;
|
|
392 (defvar tpu-newline-and-indent-p nil
|
|
393 "If non-nil, Return produces a newline and indents.")
|
|
394 (make-variable-buffer-local 'tpu-newline-and-indent-p)
|
|
395
|
|
396 (defvar tpu-newline-and-indent-string nil
|
|
397 "Mode line string to identify AutoIndent mode.")
|
|
398 (make-variable-buffer-local 'tpu-newline-and-indent-string)
|
|
399
|
|
400 (defvar tpu-saved-delete-func nil
|
|
401 "Saved value of the delete key.")
|
|
402 (make-variable-buffer-local 'tpu-saved-delete-func)
|
|
403
|
|
404 (defvar tpu-buffer-local-map nil
|
|
405 "TPU-edt buffer local key map.")
|
|
406 (make-variable-buffer-local 'tpu-buffer-local-map)
|
|
407
|
|
408
|
|
409 ;;;
|
|
410 ;;; Mode Line - Modify the mode line to show the following
|
|
411 ;;;
|
|
412 ;;; o If the mark is set.
|
|
413 ;;; o Direction of motion.
|
|
414 ;;; o Active rectangle mode.
|
|
415 ;;;
|
|
416 (defvar tpu-original-mode-line mode-line-format)
|
|
417 (defvar tpu-original-mm-alist minor-mode-alist)
|
|
418
|
|
419 (defvar tpu-mark-flag " ")
|
|
420 (make-variable-buffer-local 'tpu-mark-flag)
|
|
421
|
|
422 (defun tpu-set-mode-line (for-tpu)
|
|
423 "Set the mode for TPU-edt, or reset it to default Emacs."
|
|
424 (cond ((not for-tpu)
|
|
425 (setq mode-line-format tpu-original-mode-line)
|
|
426 (setq minor-mode-alist tpu-original-mm-alist))
|
|
427 (t
|
|
428 (setq-default mode-line-format
|
185
|
429 (list (purecopy "-")
|
0
|
430 'mode-line-modified
|
185
|
431 'mode-line-frame-identification
|
0
|
432 'mode-line-buffer-identification
|
|
433 (purecopy " ")
|
|
434 'global-mode-string
|
|
435 (purecopy " ")
|
|
436 'tpu-mark-flag
|
|
437 (purecopy " %[(")
|
72
|
438 'mode-name 'mode-line-process 'minor-mode-alist
|
|
439 (purecopy "%n")
|
|
440 (purecopy ")%]--")
|
|
441 (purecopy '(line-number-mode "L%l--"))
|
|
442 (purecopy '(column-number-mode "C%c--"))
|
0
|
443 (purecopy '(-3 . "%p"))
|
|
444 (purecopy "-%-")))
|
|
445 (or (assq 'tpu-newline-and-indent-p minor-mode-alist)
|
|
446 (setq minor-mode-alist
|
|
447 (cons '(tpu-newline-and-indent-p
|
|
448 tpu-newline-and-indent-string)
|
|
449 minor-mode-alist)))
|
|
450 (or (assq 'tpu-rectangular-p minor-mode-alist)
|
|
451 (setq minor-mode-alist
|
|
452 (cons '(tpu-rectangular-p tpu-rectangle-string)
|
|
453 minor-mode-alist)))
|
|
454 (or (assq 'tpu-direction-string minor-mode-alist)
|
|
455 (setq minor-mode-alist
|
|
456 (cons '(tpu-direction-string tpu-direction-string)
|
|
457 minor-mode-alist))))))
|
|
458
|
|
459 (defun tpu-update-mode-line nil
|
|
460 "Make sure mode-line in the current buffer reflects all changes."
|
|
461 (setq tpu-mark-flag (if (tpu-mark) "M" " "))
|
|
462 (cond (tpu-emacs19-p (force-mode-line-update))
|
|
463 (t (set-buffer-modified-p (buffer-modified-p)) (sit-for 0))))
|
|
464
|
72
|
465 (cond (tpu-lucid-emacs19-p
|
|
466 (add-hook 'zmacs-deactivate-region-hook 'tpu-update-mode-line)
|
|
467 (add-hook 'zmacs-activate-region-hook 'tpu-update-mode-line))
|
|
468 (tpu-emacs19-p
|
70
|
469 (add-hook 'activate-mark-hook 'tpu-update-mode-line)
|
72
|
470 (add-hook 'deactivate-mark-hook 'tpu-update-mode-line)))
|
0
|
471
|
|
472
|
|
473 ;;;
|
|
474 ;;; Match Markers -
|
|
475 ;;;
|
|
476 ;;; Set in: Search
|
|
477 ;;;
|
|
478 ;;; Used in: Replace, Substitute, Store-Text, Cut/Remove,
|
|
479 ;;; Append, and Change-Case
|
|
480 ;;;
|
|
481 (defvar tpu-match-beginning-mark (make-marker))
|
|
482 (defvar tpu-match-end-mark (make-marker))
|
|
483
|
|
484 (defun tpu-set-match nil
|
|
485 "Set markers at match beginning and end."
|
|
486 ;; Add one to beginning mark so it stays with the first character of
|
|
487 ;; the string even if characters are added just before the string.
|
|
488 (setq tpu-match-beginning-mark (copy-marker (1+ (match-beginning 0))))
|
|
489 (setq tpu-match-end-mark (copy-marker (match-end 0))))
|
|
490
|
|
491 (defun tpu-unset-match nil
|
|
492 "Unset match beginning and end markers."
|
|
493 (set-marker tpu-match-beginning-mark nil)
|
|
494 (set-marker tpu-match-end-mark nil))
|
|
495
|
|
496 (defun tpu-match-beginning nil
|
|
497 "Returns the location of the last match beginning."
|
|
498 (1- (marker-position tpu-match-beginning-mark)))
|
|
499
|
|
500 (defun tpu-match-end nil
|
|
501 "Returns the location of the last match end."
|
|
502 (marker-position tpu-match-end-mark))
|
|
503
|
|
504 (defun tpu-check-match nil
|
|
505 "Returns t if point is between tpu-match markers.
|
|
506 Otherwise sets the tpu-match markers to nil and returns nil."
|
|
507 ;; make sure 1- marker is in this buffer
|
|
508 ;; 2- point is at or after beginning marker
|
|
509 ;; 3- point is before ending marker, or in the case of
|
|
510 ;; zero length regions (like bol, or eol) that the
|
|
511 ;; beginning, end, and point are equal.
|
|
512 (cond ((and
|
|
513 (equal (marker-buffer tpu-match-beginning-mark) (current-buffer))
|
|
514 (>= (point) (1- (marker-position tpu-match-beginning-mark)))
|
|
515 (or
|
|
516 (< (point) (marker-position tpu-match-end-mark))
|
|
517 (and (= (1- (marker-position tpu-match-beginning-mark))
|
|
518 (marker-position tpu-match-end-mark))
|
|
519 (= (marker-position tpu-match-end-mark) (point))))) t)
|
|
520 (t
|
|
521 (tpu-unset-match) nil)))
|
|
522
|
|
523 (defun tpu-show-match-markers nil
|
|
524 "Show the values of the match markers."
|
72
|
525 (interactive)
|
134
|
526 (setq zmacs-region-stays t)
|
0
|
527 (if (markerp tpu-match-beginning-mark)
|
|
528 (let ((beg (marker-position tpu-match-beginning-mark)))
|
|
529 (message "(%s, %s) in %s -- current %s in %s"
|
|
530 (if beg (1- beg) nil)
|
|
531 (marker-position tpu-match-end-mark)
|
|
532 (marker-buffer tpu-match-end-mark)
|
|
533 (point) (current-buffer)))))
|
|
534
|
|
535
|
|
536 ;;;
|
|
537 ;;; Utilities
|
|
538 ;;;
|
|
539 (defun tpu-caar (thingy) (car (car thingy)))
|
|
540 (defun tpu-cadr (thingy) (car (cdr thingy)))
|
|
541
|
|
542 (defun tpu-mark nil
|
|
543 "TPU-edt version of the mark function.
|
|
544 Return the appropriate value of the mark for the current
|
72
|
545 version of Emacs."
|
|
546 (cond (tpu-lucid-emacs19-p (mark (not zmacs-regions)))
|
|
547 (tpu-emacs19-p (and mark-active (mark (not transient-mark-mode))))
|
0
|
548 (t (mark))))
|
|
549
|
|
550 (defun tpu-set-mark (pos)
|
72
|
551 "TPU-edt verion of the `set-mark' function.
|
|
552 Sets the mark at POS and activates the region according to the
|
|
553 current version of Emacs."
|
0
|
554 (set-mark pos)
|
72
|
555 (and tpu-lucid-emacs19-p pos (zmacs-activate-region)))
|
0
|
556
|
|
557 (defun tpu-string-prompt (prompt history-symbol)
|
|
558 "Read a string with PROMPT."
|
|
559 (if tpu-emacs19-p
|
|
560 (read-from-minibuffer prompt nil nil nil history-symbol)
|
|
561 (read-string prompt)))
|
|
562
|
|
563 (defvar tpu-last-answer nil "Most recent response to tpu-y-or-n-p.")
|
|
564
|
|
565 (defun tpu-y-or-n-p (prompt &optional not-yes)
|
|
566 "Prompt for a y or n answer with positive default.
|
|
567 Optional second argument NOT-YES changes default to negative.
|
72
|
568 Like Emacs `y-or-n-p', but also accepts space as y and DEL as n."
|
4
|
569 (message "%s[%s]" prompt (if not-yes "n" "y"))
|
0
|
570 (let ((doit t))
|
|
571 (while doit
|
|
572 (setq doit nil)
|
|
573 (let ((ans (read-char)))
|
|
574 (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\ ))
|
|
575 (setq tpu-last-answer t))
|
|
576 ((or (= ans ?n) (= ans ?N) (= ans ?\C-?))
|
|
577 (setq tpu-last-answer nil))
|
|
578 ((= ans ?\r) (setq tpu-last-answer (not not-yes)))
|
|
579 (t
|
|
580 (setq doit t) (beep)
|
4
|
581 (message "Please answer y or n. %s[%s]"
|
|
582 prompt (if not-yes "n" "y")))))))
|
0
|
583 tpu-last-answer)
|
|
584
|
|
585 (defun tpu-local-set-key (key func)
|
|
586 "Replace a key in the TPU-edt local key map.
|
|
587 Create the key map if necessary."
|
|
588 (cond ((not (keymapp tpu-buffer-local-map))
|
|
589 (setq tpu-buffer-local-map (if (current-local-map)
|
|
590 (copy-keymap (current-local-map))
|
|
591 (make-sparse-keymap)))
|
|
592 (use-local-map tpu-buffer-local-map)))
|
|
593 (local-set-key key func))
|
|
594
|
|
595 (defun tpu-current-line nil
|
|
596 "Return the vertical position of point in the selected window.
|
|
597 Top line is 0. Counts each text line only once, even if it wraps."
|
|
598 (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -1))
|
|
599
|
|
600
|
|
601 ;;;
|
|
602 ;;; Breadcrumbs
|
|
603 ;;;
|
|
604 (defvar tpu-breadcrumb-plist nil
|
|
605 "The set of user-defined markers (breadcrumbs), as a plist.")
|
|
606
|
|
607 (defun tpu-drop-breadcrumb (num)
|
|
608 "Drops a breadcrumb that can be returned to later with goto-breadcrumb."
|
72
|
609 (interactive "p")
|
134
|
610 (setq zmacs-region-stays t)
|
0
|
611 (put tpu-breadcrumb-plist num (list (current-buffer) (point)))
|
|
612 (message "Mark %d set." num))
|
|
613
|
|
614 (defun tpu-goto-breadcrumb (num)
|
|
615 "Returns to a breadcrumb set with drop-breadcrumb."
|
72
|
616 (interactive "p")
|
134
|
617 (setq zmacs-region-stays t)
|
0
|
618 (cond ((get tpu-breadcrumb-plist num)
|
|
619 (switch-to-buffer (car (get tpu-breadcrumb-plist num)))
|
|
620 (goto-char (tpu-cadr (get tpu-breadcrumb-plist num)))
|
|
621 (message "mark %d found." num))
|
|
622 (t
|
|
623 (message "mark %d not found." num))))
|
|
624
|
|
625
|
|
626 ;;;
|
|
627 ;;; Miscellaneous
|
|
628 ;;;
|
|
629 (defun tpu-change-case (num)
|
|
630 "Change the case of the character under the cursor or region.
|
|
631 Accepts a prefix argument of the number of characters to invert."
|
72
|
632 (interactive "p")
|
0
|
633 (cond ((tpu-mark)
|
|
634 (let ((beg (region-beginning)) (end (region-end)))
|
|
635 (while (> end beg)
|
|
636 (funcall (if (= (downcase (char-after beg)) (char-after beg))
|
|
637 'upcase-region 'downcase-region)
|
|
638 beg (1+ beg))
|
|
639 (setq beg (1+ beg)))
|
|
640 (tpu-unselect t)))
|
|
641 ((tpu-check-match)
|
|
642 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
|
|
643 (while (> end beg)
|
|
644 (funcall (if (= (downcase (char-after beg)) (char-after beg))
|
|
645 'upcase-region 'downcase-region)
|
|
646 beg (1+ beg))
|
|
647 (setq beg (1+ beg)))
|
|
648 (tpu-unset-match)))
|
|
649 (t
|
|
650 (while (> num 0)
|
|
651 (funcall (if (= (downcase (following-char)) (following-char))
|
|
652 'upcase-region 'downcase-region)
|
|
653 (point) (1+ (point)))
|
|
654 (forward-char (if tpu-reverse -1 1))
|
|
655 (setq num (1- num))))))
|
|
656
|
|
657 (defun tpu-fill (num)
|
|
658 "Fill paragraph or marked region.
|
|
659 With argument, fill and justify."
|
72
|
660 (interactive "P")
|
0
|
661 (cond ((tpu-mark)
|
|
662 (fill-region (point) (tpu-mark) num)
|
|
663 (tpu-unselect t))
|
|
664 (t
|
|
665 (fill-paragraph num))))
|
|
666
|
|
667 (defun tpu-version nil
|
|
668 "Print the TPU-edt version number."
|
72
|
669 (interactive)
|
134
|
670 (setq zmacs-region-stays t)
|
0
|
671 (message
|
|
672 "TPU-edt version %s by Rob Riepel (riepel@networking.stanford.edu)"
|
|
673 tpu-version))
|
|
674
|
|
675 (defun tpu-reset-screen-size (height width)
|
|
676 "Sets the screen size."
|
72
|
677 (interactive "nnew screen height: \nnnew screen width: ")
|
134
|
678 (setq zmacs-region-stays t)
|
185
|
679 (set-frame-height height)
|
|
680 (set-frame-width width))
|
0
|
681
|
|
682 (defun tpu-toggle-newline-and-indent nil
|
|
683 "Toggle between 'newline and indent' and 'simple newline'."
|
72
|
684 (interactive)
|
134
|
685 (setq zmacs-region-stays t)
|
0
|
686 (cond (tpu-newline-and-indent-p
|
|
687 (setq tpu-newline-and-indent-string "")
|
|
688 (setq tpu-newline-and-indent-p nil)
|
|
689 (tpu-local-set-key "\C-m" 'newline))
|
|
690 (t
|
|
691 (setq tpu-newline-and-indent-string " AutoIndent")
|
|
692 (setq tpu-newline-and-indent-p t)
|
|
693 (tpu-local-set-key "\C-m" 'newline-and-indent)))
|
|
694 (tpu-update-mode-line)
|
|
695 (and (interactive-p)
|
|
696 (message "Carriage return inserts a newline%s"
|
|
697 (if tpu-newline-and-indent-p " and indents." "."))))
|
|
698
|
|
699 (defun tpu-spell-check nil
|
|
700 "Checks the spelling of the region, or of the entire buffer if no
|
|
701 region is selected."
|
72
|
702 (interactive)
|
0
|
703 (cond (tpu-have-ispell
|
|
704 (if (tpu-mark) (ispell-region (tpu-mark) (point)) (ispell-buffer)))
|
|
705 (t
|
|
706 (if (tpu-mark) (spell-region (tpu-mark) (point)) (spell-buffer))))
|
|
707 (if (tpu-mark) (tpu-unselect t)))
|
|
708
|
|
709 (defun tpu-toggle-overwrite-mode nil
|
|
710 "Switches in and out of overwrite mode"
|
72
|
711 (interactive)
|
134
|
712 (setq zmacs-region-stays t)
|
0
|
713 (cond (overwrite-mode
|
|
714 (tpu-local-set-key "\177" tpu-saved-delete-func)
|
|
715 (overwrite-mode 0))
|
|
716 (t
|
|
717 (setq tpu-saved-delete-func (local-key-binding "\177"))
|
|
718 (tpu-local-set-key "\177" 'picture-backward-clear-column)
|
|
719 (overwrite-mode 1))))
|
|
720
|
|
721 (defun tpu-special-insert (num)
|
|
722 "Insert a character or control code according to
|
|
723 its ASCII decimal value."
|
72
|
724 (interactive "P")
|
134
|
725 (setq zmacs-region-stays t)
|
0
|
726 (if overwrite-mode (delete-char 1))
|
|
727 (insert (if num num 0)))
|
|
728
|
|
729 (defun tpu-quoted-insert (num)
|
|
730 "Read next input character and insert it.
|
|
731 This is useful for inserting control characters."
|
72
|
732 (interactive "*p")
|
134
|
733 (setq zmacs-region-stays t)
|
0
|
734 (let ((char (read-char)) )
|
|
735 (if overwrite-mode (delete-char num))
|
|
736 (insert-char char num)))
|
|
737
|
|
738
|
|
739 ;;;
|
|
740 ;;; TPU line-mode commands
|
|
741 ;;;
|
|
742 (defun tpu-include (file)
|
|
743 "TPU-like include file"
|
72
|
744 (interactive "fInclude file: ")
|
134
|
745 (setq zmacs-region-stays t)
|
0
|
746 (save-excursion
|
|
747 (insert-file file)
|
|
748 (message "")))
|
|
749
|
|
750 (defun tpu-get (file)
|
|
751 "TPU-like get file"
|
72
|
752 (interactive "FFile to get: ")
|
134
|
753 (setq zmacs-region-stays t)
|
0
|
754 (find-file file))
|
|
755
|
|
756 (defun tpu-what-line nil
|
|
757 "Tells what line the point is on,
|
|
758 and the total number of lines in the buffer."
|
72
|
759 (interactive)
|
134
|
760 (setq zmacs-region-stays t)
|
0
|
761 (if (eobp)
|
|
762 (message "You are at the End of Buffer. The last line is %d."
|
|
763 (count-lines 1 (point-max)))
|
|
764 (message "Line %d of %d"
|
|
765 (count-lines 1 (1+ (point)))
|
|
766 (count-lines 1 (point-max)))))
|
|
767
|
|
768 (defun tpu-exit nil
|
|
769 "Exit the way TPU does, save current buffer and ask about others."
|
72
|
770 (interactive)
|
0
|
771 (if (not (eq (recursion-depth) 0))
|
|
772 (exit-recursive-edit)
|
|
773 (progn (save-buffer) (save-buffers-kill-emacs))))
|
|
774
|
|
775 (defun tpu-quit nil
|
|
776 "Quit the way TPU does, ask to make sure changes should be abandoned."
|
72
|
777 (interactive)
|
0
|
778 (let ((list (buffer-list))
|
|
779 (working t))
|
|
780 (while (and list working)
|
|
781 (let ((buffer (car list)))
|
|
782 (if (and (buffer-file-name buffer) (buffer-modified-p buffer))
|
|
783 (if (tpu-y-or-n-p
|
|
784 "Modifications will not be saved, continue quitting? ")
|
|
785 (kill-emacs t) (setq working nil)))
|
|
786 (setq list (cdr list))))
|
|
787 (if working (kill-emacs t))))
|
|
788
|
|
789
|
|
790 ;;;
|
|
791 ;;; Command and Function Aliases
|
|
792 ;;;
|
|
793 ;;;###autoload
|
|
794 (fset 'tpu-edt-mode 'tpu-edt-on)
|
|
795 (fset 'TPU-EDT-MODE 'tpu-edt-on)
|
|
796
|
|
797 ;;;###autoload
|
|
798 (fset 'tpu-edt 'tpu-edt-on)
|
|
799 (fset 'TPU-EDT 'tpu-edt-on)
|
|
800
|
|
801 (fset 'exit 'tpu-exit)
|
|
802 (fset 'EXIT 'tpu-exit)
|
|
803
|
|
804 (fset 'Get 'tpu-get)
|
|
805 (fset 'GET 'tpu-get)
|
|
806
|
|
807 (fset 'include 'tpu-include)
|
|
808 (fset 'INCLUDE 'tpu-include)
|
|
809
|
|
810 (fset 'quit 'tpu-quit)
|
|
811 (fset 'QUIT 'tpu-quit)
|
|
812
|
|
813 (fset 'spell 'tpu-spell-check)
|
|
814 (fset 'SPELL 'tpu-spell-check)
|
|
815
|
|
816 (fset 'what\ line 'tpu-what-line)
|
|
817 (fset 'WHAT\ LINE 'tpu-what-line)
|
|
818
|
|
819 (fset 'replace 'tpu-lm-replace)
|
|
820 (fset 'REPLACE 'tpu-lm-replace)
|
|
821
|
185
|
822 ;; Apparently TPU users really expect to do M-x help RET to get help.
|
|
823 ;; So it is really necessary to redefine this.
|
0
|
824 (fset 'help 'tpu-help)
|
|
825 (fset 'HELP 'tpu-help)
|
|
826
|
|
827 (fset 'set\ cursor\ free 'tpu-set-cursor-free)
|
|
828 (fset 'SET\ CURSOR\ FREE 'tpu-set-cursor-free)
|
|
829
|
|
830 (fset 'set\ cursor\ bound 'tpu-set-cursor-bound)
|
|
831 (fset 'SET\ CURSOR\ BOUND 'tpu-set-cursor-bound)
|
|
832
|
|
833 (fset 'set\ scroll\ margins 'tpu-set-scroll-margins)
|
|
834 (fset 'SET\ SCROLL\ MARGINS 'tpu-set-scroll-margins)
|
|
835
|
|
836
|
|
837 ;; Around emacs version 18.57, function line-move was renamed to
|
|
838 ;; next-line-internal. If we're running under an older emacs,
|
|
839 ;; make next-line-internal equivalent to line-move.
|
|
840
|
|
841 (if (not (fboundp 'next-line-internal)) (fset 'next-line-internal 'line-move))
|
|
842
|
|
843
|
|
844 ;;;
|
|
845 ;;; Help
|
|
846 ;;;
|
|
847 (defconst tpu-help-keypad-map "\f
|
|
848 _______________________ _______________________________
|
|
849 | HELP | Do | | | | | |
|
|
850 |KeyDefs| | | | | | |
|
|
851 |_______|_______________| |_______|_______|_______|_______|
|
|
852 _______________________ _______________________________
|
|
853 | Find |Insert |Remove | | Gold | HELP |FndNxt | Del L |
|
|
854 | | |Sto Tex| | key |E-Help | Find |Undel L|
|
|
855 |_______|_______|_______| |_______|_______|_______|_______|
|
|
856 |Select |Pre Scr|Nex Scr| | Page | Sect |Append | Del W |
|
|
857 | Reset |Pre Win|Nex Win| | Do | Fill |Replace|Undel W|
|
|
858 |_______|_______|_______| |_______|_______|_______|_______|
|
|
859 |Move up| |Forward|Reverse|Remove | Del C |
|
|
860 | Top | |Bottom | Top |Insert |Undel C|
|
|
861 _______|_______|_______ |_______|_______|_______|_______|
|
|
862 |Mov Lef|Mov Dow|Mov Rig| | Word | EOL | Char | |
|
|
863 |StaOfLi|Bottom |EndOfLi| |ChngCas|Del EOL|SpecIns| Enter |
|
|
864 |_______|_______|_______| |_______|_______|_______| |
|
|
865 | Line |Select | Subs |
|
|
866 | Open Line | Reset | |
|
|
867 |_______________|_______|_______|
|
|
868 ")
|
|
869
|
|
870 (defconst tpu-help-text "
|
|
871 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\f
|
|
872
|
|
873 Control Characters
|
|
874
|
|
875 ^A toggle insert and overwrite
|
|
876 ^B recall
|
|
877 ^E end of line
|
|
878
|
|
879 ^G Cancel current operation
|
|
880 ^H beginning of line
|
|
881 ^J delete previous word
|
|
882
|
|
883 ^K learn
|
|
884 ^L insert page break
|
|
885 ^R remember (during learn), re-center
|
|
886
|
|
887 ^U delete to beginning of line
|
|
888 ^V quote
|
|
889 ^W refresh
|
|
890
|
|
891 ^Z exit
|
|
892 ^X^X exchange point and mark - useful for checking region boundaries
|
|
893
|
|
894 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\f
|
|
895 Gold-<key> Functions
|
|
896
|
|
897 B Next Buffer - display the next buffer (all buffers)
|
|
898 C Recall - edit and possibly repeat previous commands
|
|
899 E Exit - save current buffer and ask about others
|
72
|
900 G Get - load a file into a new edit buffer
|
70
|
901
|
0
|
902 I Include - include a file in this buffer
|
|
903 K Kill Buffer - abandon edits and delete buffer
|
|
904 M Buffer Menu - display a list of all buffers
|
|
905 N Next File Buffer - display next buffer containing a file
|
72
|
906
|
70
|
907 O Occur - show following lines containing REGEXP
|
0
|
908 Q Quit - exit without saving anything
|
|
909 R Toggle rectangular mode for remove and insert
|
|
910 S Search and substitute - line mode REPLACE command
|
|
911
|
72
|
912 ^T Toggle control key bindings between TPU and emacs
|
0
|
913 U Undo - undo the last edit
|
|
914 W Write - save current buffer
|
|
915 X Exit - save all modified buffers and exit
|
|
916
|
|
917 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\f
|
|
918
|
72
|
919 More extensive documentation on TPU-edt can be found in the `Commentary'
|
|
920 section of tpu-edt.el. This section can be accessed through the standard
|
|
921 Emacs help facility using the `p' option. Once you exit TPU-edt Help, one
|
|
922 of the following key sequences is sure to get you there.
|
|
923
|
|
924 ^h p if you're not yet using TPU-edt
|
|
925 Gold-PF2 p if you're using TPU-edt
|
|
926
|
|
927 Alternatively, fire up Emacs help from the command prompt, with
|
|
928
|
|
929 M-x help-for-help <CR> p <CR>
|
|
930
|
|
931 Where `M-x' might be any of `Gold-KP7', 'Do', or 'ESC-x'.
|
|
932
|
|
933 When you successfully invoke this part of the Emacs help facility, you
|
|
934 will see a buffer named `*Finder*' listing a number of topics. Look for
|
|
935 tpu-edt under `emulations'.
|
|
936
|
|
937 \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\f
|
|
938
|
0
|
939 *** No more help, use P to view previous screen")
|
|
940
|
|
941 (defvar tpu-help-enter (format "%s" "\eOM")) ; tpu-help enter key symbol
|
|
942 (defvar tpu-help-return (format "%s" "\r")) ; tpu-help enter key symbol
|
|
943 (defvar tpu-help-N "N") ; tpu-help "N" symbol
|
|
944 (defvar tpu-help-n "n") ; tpu-help "n" symbol
|
|
945 (defvar tpu-help-P "P") ; tpu-help "P" symbol
|
|
946 (defvar tpu-help-p "p") ; tpu-help "p" symbol
|
|
947
|
|
948 (defun tpu-help nil
|
|
949 "Display TPU-edt help."
|
72
|
950 (interactive)
|
134
|
951 (setq zmacs-region-stays t)
|
0
|
952 ;; Save current window configuration
|
|
953 (save-window-excursion
|
|
954 ;; Create and fill help buffer if necessary
|
|
955 (if (not (get-buffer "*TPU-edt Help*"))
|
|
956 (progn (generate-new-buffer "*TPU-edt Help*")
|
|
957 (switch-to-buffer "*TPU-edt Help*")
|
|
958 (insert tpu-help-keypad-map)
|
|
959 (insert tpu-help-text)
|
|
960 (setq buffer-read-only t)))
|
|
961
|
|
962 ;; Display the help buffer
|
|
963 (switch-to-buffer "*TPU-edt Help*")
|
|
964 (delete-other-windows)
|
|
965 (tpu-move-to-beginning)
|
|
966 (forward-line 1)
|
|
967 (tpu-line-to-top-of-window)
|
|
968
|
|
969 ;; Prompt for keys to describe, based on screen state (split/not split)
|
|
970 (let ((key nil) (fkey nil) (split nil))
|
|
971 (while (not (equal tpu-help-return fkey))
|
|
972 (if split
|
|
973 (setq key
|
|
974 (read-key-sequence
|
185
|
975 "Press the key you want help on (RET=exit, ENTER=redisplay, N=next,
|
|
976 P=prev): "))
|
0
|
977 (setq key
|
|
978 (read-key-sequence
|
185
|
979 "Press the key you want help on (RET to exit, N next screen, P prev
|
|
980 screen): ")))
|
0
|
981
|
|
982 ;; Process the read key
|
|
983 ;;
|
|
984 ;; ENTER - Display just the help window
|
|
985 ;; N or n - Next help or describe-key screen
|
|
986 ;; P or p - Previous help or describe-key screen
|
|
987 ;; RETURN - Exit from TPU-help
|
|
988 ;; default - describe the key
|
|
989 ;;
|
|
990 (setq fkey (format "%s" key))
|
|
991 (cond ((equal tpu-help-enter fkey)
|
|
992 (setq split nil)
|
|
993 (delete-other-windows))
|
|
994 ((or (equal tpu-help-N fkey) (equal tpu-help-n fkey))
|
|
995 (cond (split
|
|
996 (condition-case nil
|
|
997 (scroll-other-window 8)
|
|
998 (error nil)))
|
|
999 (t
|
|
1000 (forward-page)
|
|
1001 (forward-line 1)
|
|
1002 (tpu-line-to-top-of-window))))
|
|
1003 ((or (equal tpu-help-P fkey) (equal tpu-help-p fkey))
|
|
1004 (cond (split
|
|
1005 (condition-case nil
|
|
1006 (scroll-other-window -8)
|
|
1007 (error nil)))
|
|
1008 (t
|
72
|
1009 (backward-page)
|
0
|
1010 (forward-line 1)
|
|
1011 (tpu-line-to-top-of-window))))
|
|
1012 ((not (equal tpu-help-return fkey))
|
|
1013 (setq split t)
|
|
1014 (describe-key key)
|
|
1015 ;; If the key is undefined, leave the
|
|
1016 ;; message in the mini-buffer for 3 seconds
|
|
1017 (if (not (key-binding key)) (sit-for 3))))))))
|
|
1018
|
|
1019
|
|
1020 ;;;
|
|
1021 ;;; Auto-insert
|
|
1022 ;;;
|
|
1023 (defun tpu-insert-escape nil
|
|
1024 "Inserts an escape character, and so becomes the escape-key alias."
|
72
|
1025 (interactive)
|
134
|
1026 (setq zmacs-region-stays t)
|
0
|
1027 (insert "\e"))
|
|
1028
|
|
1029 (defun tpu-insert-formfeed nil
|
|
1030 "Inserts a formfeed character."
|
72
|
1031 (interactive)
|
134
|
1032 (setq zmacs-region-stays t)
|
0
|
1033 (insert "\C-L"))
|
|
1034
|
|
1035
|
|
1036 ;;;
|
|
1037 ;;; Define key
|
|
1038 ;;;
|
|
1039 (defvar tpu-saved-control-r nil "Saved value of Control-r.")
|
|
1040
|
|
1041 (defun tpu-end-define-macro-key (key)
|
|
1042 "Ends the current macro definition"
|
72
|
1043 (interactive "kPress the key you want to use to do what was just learned: ")
|
134
|
1044 (setq zmacs-region-stays t)
|
0
|
1045 (end-kbd-macro nil)
|
|
1046 (global-set-key key last-kbd-macro)
|
|
1047 (global-set-key "\C-r" tpu-saved-control-r))
|
|
1048
|
|
1049 (defun tpu-define-macro-key nil
|
|
1050 "Bind a set of keystrokes to a single key, or key combination."
|
72
|
1051 (interactive)
|
134
|
1052 (setq zmacs-region-stays t)
|
0
|
1053 (setq tpu-saved-control-r (global-key-binding "\C-r"))
|
|
1054 (global-set-key "\C-r" 'tpu-end-define-macro-key)
|
|
1055 (start-kbd-macro nil))
|
|
1056
|
|
1057
|
|
1058 ;;;
|
|
1059 ;;; Buffers and Windows
|
|
1060 ;;;
|
|
1061 (defun tpu-kill-buffer nil
|
|
1062 "Kills the current buffer. If tpu-kill-buffers-silently is non-nil,
|
|
1063 kills modified buffers without asking."
|
|
1064 (interactive)
|
|
1065 (if tpu-kill-buffers-silently (set-buffer-modified-p nil))
|
|
1066 (kill-buffer (current-buffer)))
|
|
1067
|
|
1068 (defun tpu-save-all-buffers-kill-emacs nil
|
|
1069 "Save all buffers and exit emacs."
|
|
1070 (interactive)
|
72
|
1071 (let ((delete-old-versions t))
|
|
1072 (save-buffers-kill-emacs t)))
|
0
|
1073
|
|
1074 (defun tpu-write-current-buffers nil
|
|
1075 "Save all modified buffers without exiting."
|
72
|
1076 (interactive)
|
134
|
1077 (setq zmacs-region-stays t)
|
0
|
1078 (save-some-buffers t))
|
|
1079
|
|
1080 (defun tpu-next-buffer nil
|
|
1081 "Go to next buffer in ring."
|
|
1082 (interactive)
|
|
1083 (switch-to-buffer (car (reverse (buffer-list)))))
|
|
1084
|
|
1085 (defun tpu-next-file-buffer nil
|
72
|
1086 "Go to next buffer in ring that is visiting a file or directory."
|
0
|
1087 (interactive)
|
72
|
1088 (let ((list (tpu-make-file-buffer-list (buffer-list))))
|
|
1089 (setq list (delq (current-buffer) list))
|
|
1090 (if (not list) (error "No other buffers."))
|
|
1091 (switch-to-buffer (car (reverse list)))))
|
|
1092
|
|
1093 (defun tpu-make-file-buffer-list (buffer-list)
|
185
|
1094 "Returns names from BUFFER-LIST excluding those beginning with a space or
|
|
1095 star."
|
72
|
1096 (delq nil (mapcar '(lambda (b)
|
|
1097 (if (or (= (aref (buffer-name b) 0) ? )
|
|
1098 (= (aref (buffer-name b) 0) ?*)) nil b))
|
|
1099 buffer-list)))
|
0
|
1100
|
|
1101 (defun tpu-next-window nil
|
|
1102 "Move to the next window."
|
|
1103 (interactive)
|
134
|
1104 (setq zmacs-region-stays t)
|
0
|
1105 (if (one-window-p) (message "There is only one window on screen.")
|
|
1106 (other-window 1)))
|
|
1107
|
|
1108 (defun tpu-previous-window nil
|
|
1109 "Move to the previous window."
|
|
1110 (interactive)
|
134
|
1111 (setq zmacs-region-stays t)
|
0
|
1112 (if (one-window-p) (message "There is only one window on screen.")
|
|
1113 (select-window (previous-window))))
|
|
1114
|
|
1115
|
|
1116 ;;;
|
|
1117 ;;; Search
|
|
1118 ;;;
|
|
1119 (defun tpu-toggle-regexp nil
|
|
1120 "Switches in and out of regular expression search and replace mode."
|
72
|
1121 (interactive)
|
134
|
1122 (setq zmacs-region-stays t)
|
0
|
1123 (setq tpu-regexp-p (not tpu-regexp-p))
|
|
1124 (tpu-set-search)
|
|
1125 (and (interactive-p)
|
|
1126 (message "Regular expression search and substitute %sabled."
|
|
1127 (if tpu-regexp-p "en" "dis"))))
|
|
1128
|
|
1129 (defun tpu-regexp-prompt (prompt)
|
|
1130 "Read a string, adding 'RE' to the prompt if tpu-regexp-p is set."
|
|
1131 (let ((re-prompt (concat (if tpu-regexp-p "RE ") prompt)))
|
|
1132 (if tpu-emacs19-p
|
|
1133 (read-from-minibuffer re-prompt nil nil nil 'tpu-regexp-prompt-hist)
|
|
1134 (read-string re-prompt))))
|
|
1135
|
|
1136 (defun tpu-search nil
|
|
1137 "Search for a string or regular expression.
|
|
1138 The search is performed in the current direction."
|
72
|
1139 (interactive)
|
134
|
1140 (setq zmacs-region-stays t)
|
0
|
1141 (tpu-set-search)
|
|
1142 (tpu-search-internal ""))
|
|
1143
|
|
1144 (defun tpu-search-forward nil
|
|
1145 "Search for a string or regular expression.
|
|
1146 The search is begins in the forward direction."
|
72
|
1147 (interactive)
|
134
|
1148 (setq zmacs-region-stays t)
|
0
|
1149 (setq tpu-searching-forward t)
|
|
1150 (tpu-set-search t)
|
|
1151 (tpu-search-internal ""))
|
|
1152
|
|
1153 (defun tpu-search-reverse nil
|
|
1154 "Search for a string or regular expression.
|
|
1155 The search is begins in the reverse direction."
|
72
|
1156 (interactive)
|
134
|
1157 (setq zmacs-region-stays t)
|
0
|
1158 (setq tpu-searching-forward nil)
|
|
1159 (tpu-set-search t)
|
|
1160 (tpu-search-internal ""))
|
|
1161
|
|
1162 (defun tpu-search-again nil
|
|
1163 "Search for the same string or regular expression as last time.
|
|
1164 The search is performed in the current direction."
|
72
|
1165 (interactive)
|
134
|
1166 (setq zmacs-region-stays t)
|
0
|
1167 (tpu-search-internal tpu-search-last-string))
|
|
1168
|
|
1169 ;; tpu-set-search defines the search functions used by the TPU-edt internal
|
|
1170 ;; search function. It should be called whenever the direction changes, or
|
|
1171 ;; the regular expression mode is turned on or off. It can also be called
|
|
1172 ;; to ensure that the next search will be in the current direction. It is
|
|
1173 ;; called from:
|
|
1174
|
72
|
1175 ;; tpu-advance tpu-backup
|
|
1176 ;; tpu-toggle-regexp tpu-toggle-search-direction (t)
|
|
1177 ;; tpu-search tpu-lm-replace
|
|
1178 ;; tpu-search-forward (t) tpu-search-reverse (t)
|
|
1179 ;; tpu-search-forward-exit (t) tpu-search-backward-exit (t)
|
0
|
1180
|
|
1181 (defun tpu-set-search (&optional arg)
|
|
1182 "Set the search functions and set the search direction to the current
|
|
1183 direction. If an argument is specified, don't set the search direction."
|
|
1184 (if (not arg) (setq tpu-searching-forward (if tpu-advance t nil)))
|
|
1185 (cond (tpu-searching-forward
|
|
1186 (cond (tpu-regexp-p
|
|
1187 (fset 'tpu-emacs-search 're-search-forward)
|
|
1188 (fset 'tpu-emacs-rev-search 're-search-backward))
|
|
1189 (t
|
|
1190 (fset 'tpu-emacs-search 'search-forward)
|
|
1191 (fset 'tpu-emacs-rev-search 'search-backward))))
|
|
1192 (t
|
|
1193 (cond (tpu-regexp-p
|
|
1194 (fset 'tpu-emacs-search 're-search-backward)
|
|
1195 (fset 'tpu-emacs-rev-search 're-search-forward))
|
|
1196 (t
|
|
1197 (fset 'tpu-emacs-search 'search-backward)
|
|
1198 (fset 'tpu-emacs-rev-search 'search-forward))))))
|
|
1199
|
|
1200 (defun tpu-search-internal (pat &optional quiet)
|
|
1201 "Search for a string or regular expression."
|
|
1202 (setq tpu-search-last-string
|
|
1203 (if (not (string= "" pat)) pat (tpu-regexp-prompt "Search: ")))
|
|
1204
|
|
1205 (tpu-unset-match)
|
|
1206 (tpu-adjust-search)
|
|
1207
|
72
|
1208 (let ((case-fold-search
|
|
1209 (and case-fold-search (tpu-check-search-case tpu-search-last-string))))
|
0
|
1210
|
72
|
1211 (cond ((tpu-emacs-search tpu-search-last-string nil t)
|
|
1212 (tpu-set-match) (goto-char (tpu-match-beginning)))
|
0
|
1213
|
72
|
1214 (t
|
|
1215 (tpu-adjust-search t)
|
|
1216 (let ((found nil) (pos nil))
|
|
1217 (save-excursion
|
|
1218 (let ((tpu-searching-forward (not tpu-searching-forward)))
|
|
1219 (tpu-adjust-search)
|
|
1220 (setq found (tpu-emacs-rev-search tpu-search-last-string nil t))
|
|
1221 (setq pos (match-beginning 0))))
|
0
|
1222
|
72
|
1223 (cond
|
|
1224 (found
|
|
1225 (cond ((tpu-y-or-n-p
|
|
1226 (format "Found in %s direction. Go there? "
|
|
1227 (if tpu-searching-forward "reverse" "forward")))
|
|
1228 (goto-char pos) (tpu-set-match)
|
|
1229 (tpu-toggle-search-direction))))
|
|
1230
|
|
1231 (t
|
|
1232 (if (not quiet)
|
|
1233 (message
|
|
1234 "%sSearch failed: \"%s\""
|
|
1235 (if tpu-regexp-p "RE " "") tpu-search-last-string)))))))))
|
0
|
1236
|
|
1237 (fset 'tpu-search-internal-core (symbol-function 'tpu-search-internal))
|
|
1238
|
72
|
1239 (defun tpu-check-search-case (string)
|
|
1240 "Returns t if string contains upper case."
|
|
1241 ;; if using regexp, eliminate upper case forms (\B \W \S.)
|
|
1242 (if tpu-regexp-p
|
|
1243 (let ((pat (copy-sequence string)) (case-fold-search nil) (pos 0))
|
|
1244 (while (setq pos (string-match "\\\\\\\\" pat)) (aset pat (+ 1 pos) ?.))
|
|
1245 (while (setq pos (string-match "\\\\B" pat)) (aset pat (+ 1 pos) ?.))
|
|
1246 (while (setq pos (string-match "\\\\W" pat)) (aset pat (+ 1 pos) ?.))
|
|
1247 (while (setq pos (string-match "\\\\S." pat))
|
|
1248 (aset pat (+ 1 pos) ?.) (aset pat (+ 2 pos) ?.))
|
|
1249 (string-equal pat (downcase pat)))
|
|
1250 (string-equal string (downcase string))))
|
|
1251
|
0
|
1252 (defun tpu-adjust-search (&optional arg)
|
|
1253 "For forward searches, move forward a character before searching,
|
|
1254 and backward a character after a failed search. Arg means end of search."
|
|
1255 (if tpu-searching-forward
|
|
1256 (cond (arg (if (not (bobp)) (forward-char -1)))
|
|
1257 (t (if (not (eobp)) (forward-char 1))))))
|
|
1258
|
|
1259 (defun tpu-toggle-search-direction nil
|
|
1260 "Toggle the TPU-edt search direction.
|
|
1261 Used for reversing a search in progress."
|
72
|
1262 (interactive)
|
134
|
1263 (setq zmacs-region-stays t)
|
0
|
1264 (setq tpu-searching-forward (not tpu-searching-forward))
|
|
1265 (tpu-set-search t)
|
|
1266 (and (interactive-p)
|
|
1267 (message "Searching %sward."
|
|
1268 (if tpu-searching-forward "for" "back"))))
|
|
1269
|
72
|
1270 (defun tpu-search-forward-exit nil
|
|
1271 "Set search direction forward and exit minibuffer."
|
|
1272 (interactive)
|
134
|
1273 (setq zmacs-region-stays t)
|
72
|
1274 (setq tpu-searching-forward t)
|
|
1275 (tpu-set-search t)
|
|
1276 (exit-minibuffer))
|
|
1277
|
|
1278 (defun tpu-search-backward-exit nil
|
|
1279 "Set search direction backward and exit minibuffer."
|
|
1280 (interactive)
|
134
|
1281 (setq zmacs-region-stays t)
|
72
|
1282 (setq tpu-searching-forward nil)
|
|
1283 (tpu-set-search t)
|
|
1284 (exit-minibuffer))
|
|
1285
|
0
|
1286
|
|
1287 ;;;
|
|
1288 ;;; Select / Unselect
|
|
1289 ;;;
|
|
1290 (defun tpu-select (&optional quiet)
|
|
1291 "Sets the mark to define one end of a region."
|
72
|
1292 (interactive "P")
|
0
|
1293 (cond ((tpu-mark)
|
|
1294 (tpu-unselect quiet))
|
|
1295 (t
|
|
1296 (tpu-set-mark (point))
|
|
1297 (tpu-update-mode-line)
|
|
1298 (if (not quiet) (message "Move the text cursor to select text.")))))
|
|
1299
|
|
1300 (defun tpu-unselect (&optional quiet)
|
|
1301 "Removes the mark to unselect the current region."
|
|
1302 (interactive "P")
|
|
1303 (setq mark-ring nil)
|
|
1304 (tpu-set-mark nil)
|
|
1305 (tpu-update-mode-line)
|
|
1306 (if (not quiet) (message "Selection canceled.")))
|
|
1307
|
|
1308
|
|
1309 ;;;
|
|
1310 ;;; Delete / Cut
|
|
1311 ;;;
|
|
1312 (defun tpu-toggle-rectangle nil
|
|
1313 "Toggle rectangular mode for remove and insert."
|
72
|
1314 (interactive)
|
134
|
1315 (setq zmacs-region-stays t)
|
0
|
1316 (setq tpu-rectangular-p (not tpu-rectangular-p))
|
|
1317 (setq tpu-rectangle-string (if tpu-rectangular-p " Rect" ""))
|
|
1318 (tpu-update-mode-line)
|
|
1319 (and (interactive-p)
|
|
1320 (message "Rectangular cut and paste %sabled."
|
|
1321 (if tpu-rectangular-p "en" "dis"))))
|
|
1322
|
|
1323 (defun tpu-arrange-rectangle nil
|
|
1324 "Adjust point and mark to mark upper left and lower right
|
|
1325 corners of a rectangle."
|
|
1326 (let ((mc (current-column))
|
|
1327 (pc (progn (exchange-point-and-mark) (current-column))))
|
|
1328
|
72
|
1329 (cond ((> (point) (tpu-mark)) ; point on lower line
|
0
|
1330 (cond ((> pc mc) ; point @ lower-right
|
|
1331 (exchange-point-and-mark)) ; point -> upper-left
|
|
1332
|
|
1333 (t ; point @ lower-left
|
|
1334 (move-to-column-force mc) ; point -> lower-right
|
|
1335 (exchange-point-and-mark) ; point -> upper-right
|
|
1336 (move-to-column-force pc)))) ; point -> upper-left
|
|
1337
|
|
1338 (t ; point on upper line
|
|
1339 (cond ((> pc mc) ; point @ upper-right
|
|
1340 (move-to-column-force mc) ; point -> upper-left
|
|
1341 (exchange-point-and-mark) ; point -> lower-left
|
|
1342 (move-to-column-force pc) ; point -> lower-right
|
|
1343 (exchange-point-and-mark))))))) ; point -> upper-left
|
|
1344
|
|
1345 (defun tpu-cut-text nil
|
|
1346 "Delete the selected region.
|
|
1347 The text is saved for the tpu-paste command."
|
|
1348 (interactive)
|
|
1349 (cond ((tpu-mark)
|
|
1350 (cond (tpu-rectangular-p
|
|
1351 (tpu-arrange-rectangle)
|
|
1352 (picture-clear-rectangle (point) (tpu-mark) (not overwrite-mode))
|
|
1353 (tpu-unselect t))
|
|
1354 (t
|
|
1355 (setq tpu-last-deleted-region
|
|
1356 (buffer-substring (tpu-mark) (point)))
|
|
1357 (delete-region (tpu-mark) (point))
|
|
1358 (tpu-unselect t))))
|
|
1359 ((tpu-check-match)
|
|
1360 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
|
|
1361 (setq tpu-last-deleted-region (buffer-substring beg end))
|
|
1362 (delete-region beg end)
|
|
1363 (tpu-unset-match)))
|
|
1364 (t
|
|
1365 (error "No selection active."))))
|
|
1366
|
|
1367 (defun tpu-store-text nil
|
|
1368 "Copy the selected region to the cut buffer without deleting it.
|
|
1369 The text is saved for the tpu-paste command."
|
|
1370 (interactive)
|
134
|
1371 (setq zmacs-region-stays t)
|
0
|
1372 (cond ((tpu-mark)
|
|
1373 (cond (tpu-rectangular-p
|
|
1374 (save-excursion
|
|
1375 (tpu-arrange-rectangle)
|
|
1376 (setq picture-killed-rectangle
|
|
1377 (extract-rectangle (point) (tpu-mark))))
|
|
1378 (tpu-unselect t))
|
|
1379 (t
|
|
1380 (setq tpu-last-deleted-region
|
|
1381 (buffer-substring (tpu-mark) (point)))
|
|
1382 (tpu-unselect t))))
|
|
1383 ((tpu-check-match)
|
|
1384 (setq tpu-last-deleted-region
|
|
1385 (buffer-substring (tpu-match-beginning) (tpu-match-end)))
|
|
1386 (tpu-unset-match))
|
|
1387 (t
|
|
1388 (error "No selection active."))))
|
|
1389
|
|
1390 (defun tpu-cut (arg)
|
|
1391 "Copy selected region to the cut buffer. In the absence of an
|
|
1392 argument, delete the selected region too."
|
|
1393 (interactive "P")
|
|
1394 (if arg (tpu-store-text) (tpu-cut-text)))
|
|
1395
|
|
1396 (defun tpu-append-region (arg)
|
|
1397 "Append selected region to the tpu-cut buffer. In the absence of an
|
|
1398 argument, delete the selected region too."
|
72
|
1399 (interactive "P")
|
0
|
1400 (cond ((tpu-mark)
|
|
1401 (let ((beg (region-beginning)) (end (region-end)))
|
|
1402 (setq tpu-last-deleted-region
|
|
1403 (concat tpu-last-deleted-region
|
|
1404 (buffer-substring beg end)))
|
|
1405 (if (not arg) (delete-region beg end))
|
|
1406 (tpu-unselect t)))
|
|
1407 ((tpu-check-match)
|
|
1408 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
|
|
1409 (setq tpu-last-deleted-region
|
|
1410 (concat tpu-last-deleted-region
|
|
1411 (buffer-substring beg end)))
|
|
1412 (if (not arg) (delete-region beg end))
|
|
1413 (tpu-unset-match)))
|
|
1414 (t
|
|
1415 (error "No selection active."))))
|
|
1416
|
|
1417 (defun tpu-delete-current-line (num)
|
|
1418 "Delete one or specified number of lines after point.
|
|
1419 This includes the newline character at the end of each line.
|
|
1420 They are saved for the TPU-edt undelete-lines command."
|
72
|
1421 (interactive "p")
|
134
|
1422 (setq zmacs-region-stays t)
|
0
|
1423 (let ((beg (point)))
|
|
1424 (forward-line num)
|
|
1425 (if (not (eq (preceding-char) ?\n))
|
|
1426 (insert "\n"))
|
|
1427 (setq tpu-last-deleted-lines
|
|
1428 (buffer-substring beg (point)))
|
|
1429 (delete-region beg (point))))
|
|
1430
|
|
1431 (defun tpu-delete-to-eol (num)
|
|
1432 "Delete text up to end of line.
|
|
1433 With argument, delete up to to Nth line-end past point.
|
|
1434 They are saved for the TPU-edt undelete-lines command."
|
72
|
1435 (interactive "p")
|
134
|
1436 (setq zmacs-region-stays t)
|
0
|
1437 (let ((beg (point)))
|
|
1438 (forward-char 1)
|
|
1439 (end-of-line num)
|
|
1440 (setq tpu-last-deleted-lines
|
|
1441 (buffer-substring beg (point)))
|
|
1442 (delete-region beg (point))))
|
|
1443
|
|
1444 (defun tpu-delete-to-bol (num)
|
|
1445 "Delete text back to beginning of line.
|
|
1446 With argument, delete up to to Nth line-end past point.
|
|
1447 They are saved for the TPU-edt undelete-lines command."
|
72
|
1448 (interactive "p")
|
134
|
1449 (setq zmacs-region-stays t)
|
0
|
1450 (let ((beg (point)))
|
|
1451 (tpu-next-beginning-of-line num)
|
|
1452 (setq tpu-last-deleted-lines
|
|
1453 (buffer-substring (point) beg))
|
|
1454 (delete-region (point) beg)))
|
|
1455
|
|
1456 (defun tpu-delete-current-word (num)
|
|
1457 "Delete one or specified number of words after point.
|
|
1458 They are saved for the TPU-edt undelete-words command."
|
72
|
1459 (interactive "p")
|
134
|
1460 (setq zmacs-region-stays t)
|
0
|
1461 (let ((beg (point)))
|
|
1462 (tpu-forward-to-word num)
|
|
1463 (setq tpu-last-deleted-words
|
|
1464 (buffer-substring beg (point)))
|
|
1465 (delete-region beg (point))))
|
|
1466
|
|
1467 (defun tpu-delete-previous-word (num)
|
|
1468 "Delete one or specified number of words before point.
|
|
1469 They are saved for the TPU-edt undelete-words command."
|
72
|
1470 (interactive "p")
|
134
|
1471 (setq zmacs-region-stays t)
|
0
|
1472 (let ((beg (point)))
|
|
1473 (tpu-backward-to-word num)
|
|
1474 (setq tpu-last-deleted-words
|
|
1475 (buffer-substring (point) beg))
|
|
1476 (delete-region beg (point))))
|
|
1477
|
|
1478 (defun tpu-delete-current-char (num)
|
|
1479 "Delete one or specified number of characters after point. The last
|
|
1480 character deleted is saved for the TPU-edt undelete-char command."
|
72
|
1481 (interactive "p")
|
134
|
1482 (setq zmacs-region-stays t)
|
0
|
1483 (while (and (> num 0) (not (eobp)))
|
|
1484 (setq tpu-last-deleted-char (char-after (point)))
|
|
1485 (cond (overwrite-mode
|
|
1486 (picture-clear-column 1)
|
|
1487 (forward-char 1))
|
|
1488 (t
|
|
1489 (delete-char 1)))
|
|
1490 (setq num (1- num))))
|
|
1491
|
|
1492
|
|
1493 ;;;
|
|
1494 ;;; Undelete / Paste
|
|
1495 ;;;
|
|
1496 (defun tpu-paste (num)
|
|
1497 "Insert the last region or rectangle of killed text.
|
|
1498 With argument reinserts the text that many times."
|
72
|
1499 (interactive "p")
|
134
|
1500 (setq zmacs-region-stays t)
|
0
|
1501 (while (> num 0)
|
|
1502 (cond (tpu-rectangular-p
|
|
1503 (let ((beg (point)))
|
|
1504 (save-excursion
|
|
1505 (picture-yank-rectangle (not overwrite-mode))
|
|
1506 (message ""))
|
|
1507 (goto-char beg)))
|
|
1508 (t
|
|
1509 (insert tpu-last-deleted-region)))
|
|
1510 (setq num (1- num))))
|
|
1511
|
|
1512 (defun tpu-undelete-lines (num)
|
|
1513 "Insert lines deleted by last TPU-edt line-deletion command.
|
|
1514 With argument reinserts lines that many times."
|
72
|
1515 (interactive "p")
|
134
|
1516 (setq zmacs-region-stays t)
|
0
|
1517 (let ((beg (point)))
|
|
1518 (while (> num 0)
|
|
1519 (insert tpu-last-deleted-lines)
|
|
1520 (setq num (1- num)))
|
|
1521 (goto-char beg)))
|
|
1522
|
|
1523 (defun tpu-undelete-words (num)
|
|
1524 "Insert words deleted by last TPU-edt word-deletion command.
|
|
1525 With argument reinserts words that many times."
|
72
|
1526 (interactive "p")
|
134
|
1527 (setq zmacs-region-stays t)
|
0
|
1528 (let ((beg (point)))
|
|
1529 (while (> num 0)
|
|
1530 (insert tpu-last-deleted-words)
|
|
1531 (setq num (1- num)))
|
|
1532 (goto-char beg)))
|
|
1533
|
|
1534 (defun tpu-undelete-char (num)
|
|
1535 "Insert character deleted by last TPU-edt character-deletion command.
|
|
1536 With argument reinserts the character that many times."
|
72
|
1537 (interactive "p")
|
134
|
1538 (setq zmacs-region-stays t)
|
0
|
1539 (while (> num 0)
|
|
1540 (if overwrite-mode (prog1 (forward-char -1) (delete-char 1)))
|
|
1541 (insert tpu-last-deleted-char)
|
|
1542 (forward-char -1)
|
|
1543 (setq num (1- num))))
|
|
1544
|
|
1545
|
|
1546 ;;;
|
|
1547 ;;; Replace and Substitute
|
|
1548 ;;;
|
|
1549 (defun tpu-replace nil
|
|
1550 "Replace the selected region with the contents of the cut buffer."
|
|
1551 (interactive)
|
|
1552 (cond ((tpu-mark)
|
|
1553 (let ((beg (region-beginning)) (end (region-end)))
|
|
1554 (setq tpu-last-replaced-text (buffer-substring beg end))
|
|
1555 (delete-region beg end)
|
|
1556 (insert tpu-last-deleted-region)
|
|
1557 (tpu-unselect t)))
|
|
1558 ((tpu-check-match)
|
|
1559 (let ((beg (tpu-match-beginning)) (end (tpu-match-end)))
|
|
1560 (setq tpu-last-replaced-text (buffer-substring beg end))
|
|
1561 (replace-match tpu-last-deleted-region
|
|
1562 (not case-replace) (not tpu-regexp-p))
|
|
1563 (tpu-unset-match)))
|
|
1564 (t
|
|
1565 (error "No selection active."))))
|
|
1566
|
|
1567 (defun tpu-substitute (num)
|
|
1568 "Replace the selected region with the contents of the cut buffer, and
|
|
1569 repeat most recent search. A numeric argument serves as a repeat count.
|
|
1570 A negative argument means replace all occurrences of the search string."
|
72
|
1571 (interactive "p")
|
0
|
1572 (cond ((or (tpu-mark) (tpu-check-match))
|
|
1573 (while (and (not (= num 0)) (or (tpu-mark) (tpu-check-match)))
|
|
1574 (let ((beg (point)))
|
|
1575 (tpu-replace)
|
|
1576 (if tpu-searching-forward (forward-char -1) (goto-char beg))
|
|
1577 (if (= num 1) (tpu-search-internal tpu-search-last-string)
|
|
1578 (tpu-search-internal-core tpu-search-last-string)))
|
|
1579 (setq num (1- num))))
|
|
1580 (t
|
|
1581 (error "No selection active."))))
|
|
1582
|
|
1583 (defun tpu-lm-replace (from to)
|
|
1584 "Interactively search for OLD-string and substitute NEW-string."
|
|
1585 (interactive (list (tpu-regexp-prompt "Old String: ")
|
|
1586 (tpu-regexp-prompt "New String: ")))
|
|
1587
|
|
1588 (let ((doit t) (strings 0))
|
|
1589
|
|
1590 ;; Can't replace null strings
|
|
1591 (if (string= "" from) (error "No string to replace."))
|
|
1592
|
|
1593 ;; Find the first occurrence
|
|
1594 (tpu-set-search)
|
|
1595 (tpu-search-internal from t)
|
|
1596
|
|
1597 ;; Loop on replace question - yes, no, all, last, or quit.
|
|
1598 (while doit
|
|
1599 (if (not (tpu-check-match)) (setq doit nil)
|
|
1600 (progn (message "Replace? Type Yes, No, All, Last, or Quit: ")
|
|
1601 (let ((ans (read-char)))
|
|
1602
|
|
1603 (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\r) (= ans ?\ ))
|
|
1604 (let ((beg (point)))
|
|
1605 (replace-match to (not case-replace) (not tpu-regexp-p))
|
|
1606 (setq strings (1+ strings))
|
|
1607 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
|
|
1608 (tpu-search-internal from t))
|
|
1609
|
|
1610 ((or (= ans ?n) (= ans ?N) (= ans ?\C-?))
|
|
1611 (tpu-search-internal from t))
|
|
1612
|
|
1613 ((or (= ans ?a) (= ans ?A))
|
|
1614 (save-excursion
|
|
1615 (let ((beg (point)))
|
|
1616 (replace-match to (not case-replace) (not tpu-regexp-p))
|
|
1617 (setq strings (1+ strings))
|
|
1618 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
|
|
1619 (tpu-search-internal-core from t)
|
|
1620 (while (tpu-check-match)
|
|
1621 (let ((beg (point)))
|
|
1622 (replace-match to (not case-replace) (not tpu-regexp-p))
|
|
1623 (setq strings (1+ strings))
|
|
1624 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
|
|
1625 (tpu-search-internal-core from t)))
|
|
1626 (setq doit nil))
|
|
1627
|
|
1628 ((or (= ans ?l) (= ans ?L))
|
|
1629 (let ((beg (point)))
|
|
1630 (replace-match to (not case-replace) (not tpu-regexp-p))
|
|
1631 (setq strings (1+ strings))
|
|
1632 (if tpu-searching-forward (forward-char -1) (goto-char beg)))
|
|
1633 (setq doit nil))
|
|
1634
|
|
1635 ((or (= ans ?q) (= ans ?Q))
|
|
1636 (setq doit nil)))))))
|
|
1637
|
|
1638 (message "Replaced %s occurrence%s." strings
|
|
1639 (if (not (= 1 strings)) "s" ""))))
|
|
1640
|
|
1641 (defun tpu-emacs-replace (&optional dont-ask)
|
|
1642 "A TPU-edt interface to the emacs replace functions. If TPU-edt is
|
|
1643 currently in regular expression mode, the emacs regular expression
|
|
1644 replace functions are used. If an argument is supplied, replacements
|
|
1645 are performed without asking. Only works in forward direction."
|
72
|
1646 (interactive "P")
|
0
|
1647 (cond (dont-ask
|
|
1648 (setq current-prefix-arg nil)
|
|
1649 (call-interactively
|
|
1650 (if tpu-regexp-p 'replace-regexp 'replace-string)))
|
|
1651 (t
|
|
1652 (call-interactively
|
|
1653 (if tpu-regexp-p 'query-replace-regexp 'query-replace)))))
|
|
1654
|
|
1655 (defun tpu-add-at-bol (text)
|
|
1656 "Add text to the beginning of each line in a region,
|
|
1657 or each line in the entire buffer if no region is selected."
|
|
1658 (interactive
|
|
1659 (list (tpu-string-prompt "String to add: " 'tpu-add-at-bol-hist)))
|
134
|
1660 (setq zmacs-region-stays t)
|
0
|
1661 (if (string= "" text) (error "No string specified."))
|
|
1662 (cond ((tpu-mark)
|
|
1663 (save-excursion
|
|
1664 (if (> (point) (tpu-mark)) (exchange-point-and-mark))
|
|
1665 (while (and (< (point) (tpu-mark)) (re-search-forward "^" (tpu-mark) t))
|
|
1666 (if (< (point) (tpu-mark)) (replace-match text))))
|
|
1667 (tpu-unselect t))
|
|
1668 (t
|
|
1669 (save-excursion
|
|
1670 (goto-char (point-min))
|
|
1671 (while (and (re-search-forward "^" nil t) (not (eobp)))
|
|
1672 (replace-match text))))))
|
|
1673
|
|
1674 (defun tpu-add-at-eol (text)
|
|
1675 "Add text to the end of each line in a region,
|
|
1676 or each line of the entire buffer if no region is selected."
|
|
1677 (interactive
|
|
1678 (list (tpu-string-prompt "String to add: " 'tpu-add-at-eol-hist)))
|
185
|
1679 (setq zmacs-region-stays t)
|
0
|
1680 (if (string= "" text) (error "No string specified."))
|
|
1681 (cond ((tpu-mark)
|
|
1682 (save-excursion
|
|
1683 (if (> (point) (tpu-mark)) (exchange-point-and-mark))
|
|
1684 (while (< (point) (tpu-mark))
|
|
1685 (end-of-line)
|
|
1686 (if (<= (point) (tpu-mark)) (insert text))
|
|
1687 (forward-line)))
|
|
1688 (tpu-unselect t))
|
|
1689 (t
|
|
1690 (save-excursion
|
|
1691 (goto-char (point-min))
|
|
1692 (while (not (eobp))
|
|
1693 (end-of-line) (insert text) (forward-line))))))
|
|
1694
|
|
1695 (defun tpu-trim-line-ends nil
|
|
1696 "Removes trailing whitespace from every line in the buffer."
|
|
1697 (interactive)
|
134
|
1698 (setq zmacs-region-stays t)
|
0
|
1699 (picture-clean))
|
|
1700
|
|
1701
|
|
1702 ;;;
|
|
1703 ;;; Movement by character
|
|
1704 ;;;
|
|
1705 (defun tpu-char (num)
|
|
1706 "Move to the next character in the current direction.
|
|
1707 A repeat count means move that many characters."
|
72
|
1708 (interactive "p")
|
134
|
1709 (setq zmacs-region-stays t)
|
0
|
1710 (if tpu-advance (tpu-forward-char num) (tpu-backward-char num)))
|
|
1711
|
|
1712 (defun tpu-forward-char (num)
|
|
1713 "Move right ARG characters (left if ARG is negative)."
|
72
|
1714 (interactive "p")
|
134
|
1715 (setq zmacs-region-stays t)
|
0
|
1716 (forward-char num))
|
|
1717
|
|
1718 (defun tpu-backward-char (num)
|
|
1719 "Move left ARG characters (right if ARG is negative)."
|
72
|
1720 (interactive "p")
|
134
|
1721 (setq zmacs-region-stays t)
|
0
|
1722 (backward-char num))
|
|
1723
|
|
1724
|
|
1725 ;;;
|
|
1726 ;;; Movement by word
|
|
1727 ;;;
|
|
1728 (defconst tpu-word-separator-list '()
|
|
1729 "List of additional word separators.")
|
|
1730 (defconst tpu-skip-chars "^ \t"
|
|
1731 "Characters to skip when moving by word.
|
|
1732 Additional word separators are added to this string.")
|
|
1733
|
|
1734 (defun tpu-word (num)
|
|
1735 "Move to the beginning of the next word in the current direction.
|
|
1736 A repeat count means move that many words."
|
72
|
1737 (interactive "p")
|
134
|
1738 (setq zmacs-region-stays t)
|
0
|
1739 (if tpu-advance (tpu-forward-to-word num) (tpu-backward-to-word num)))
|
|
1740
|
|
1741 (defun tpu-forward-to-word (num)
|
|
1742 "Move forward until encountering the beginning of a word.
|
|
1743 With argument, do this that many times."
|
72
|
1744 (interactive "p")
|
134
|
1745 (setq zmacs-region-stays t)
|
0
|
1746 (while (and (> num 0) (not (eobp)))
|
|
1747 (let* ((beg (point))
|
|
1748 (end (prog2 (end-of-line) (point) (goto-char beg))))
|
|
1749 (cond ((eolp)
|
|
1750 (forward-char 1))
|
|
1751 ((memq (char-after (point)) tpu-word-separator-list)
|
|
1752 (forward-char 1)
|
|
1753 (skip-chars-forward " \t" end))
|
|
1754 (t
|
|
1755 (skip-chars-forward tpu-skip-chars end)
|
|
1756 (skip-chars-forward " \t" end))))
|
|
1757 (setq num (1- num))))
|
|
1758
|
|
1759 (defun tpu-backward-to-word (num)
|
|
1760 "Move backward until encountering the beginning of a word.
|
|
1761 With argument, do this that many times."
|
72
|
1762 (interactive "p")
|
134
|
1763 (setq zmacs-region-stays t)
|
0
|
1764 (while (and (> num 0) (not (bobp)))
|
|
1765 (let* ((beg (point))
|
|
1766 (end (prog2 (beginning-of-line) (point) (goto-char beg))))
|
|
1767 (cond ((bolp)
|
|
1768 ( forward-char -1))
|
|
1769 ((memq (char-after (1- (point))) tpu-word-separator-list)
|
|
1770 (forward-char -1))
|
|
1771 (t
|
|
1772 (skip-chars-backward " \t" end)
|
|
1773 (skip-chars-backward tpu-skip-chars end)
|
|
1774 (if (and (not (bolp)) (= ? (char-syntax (char-after (point)))))
|
|
1775 (forward-char -1)))))
|
|
1776 (setq num (1- num))))
|
|
1777
|
|
1778 (defun tpu-add-word-separators (separators)
|
|
1779 "Add new word separators for TPU-edt word commands."
|
72
|
1780 (interactive "sSeparators: ")
|
134
|
1781 (setq zmacs-region-stays t)
|
0
|
1782 (let* ((n 0) (length (length separators)))
|
|
1783 (while (< n length)
|
|
1784 (let ((char (aref separators n))
|
|
1785 (ss (substring separators n (1+ n))))
|
|
1786 (cond ((not (memq char tpu-word-separator-list))
|
|
1787 (setq tpu-word-separator-list
|
|
1788 (append ss tpu-word-separator-list))
|
|
1789 (cond ((= char ?-)
|
|
1790 (setq tpu-skip-chars (concat tpu-skip-chars "\\-")))
|
|
1791 ((= char ?\\)
|
|
1792 (setq tpu-skip-chars (concat tpu-skip-chars "\\\\")))
|
|
1793 ((= char ?^)
|
|
1794 (setq tpu-skip-chars (concat tpu-skip-chars "\\^")))
|
|
1795 (t
|
|
1796 (setq tpu-skip-chars (concat tpu-skip-chars ss))))))
|
|
1797 (setq n (1+ n))))))
|
|
1798
|
|
1799 (defun tpu-reset-word-separators nil
|
|
1800 "Reset word separators to default value."
|
72
|
1801 (interactive)
|
134
|
1802 (setq zmacs-region-stays t)
|
0
|
1803 (setq tpu-word-separator-list nil)
|
|
1804 (setq tpu-skip-chars "^ \t"))
|
|
1805
|
|
1806 (defun tpu-set-word-separators (separators)
|
|
1807 "Set new word separators for TPU-edt word commands."
|
72
|
1808 (interactive "sSeparators: ")
|
134
|
1809 (setq zmacs-region-stays t)
|
0
|
1810 (tpu-reset-word-separators)
|
|
1811 (tpu-add-word-separators separators))
|
|
1812
|
|
1813
|
|
1814 ;;;
|
|
1815 ;;; Movement by line
|
|
1816 ;;;
|
|
1817 (defun tpu-next-line (num)
|
|
1818 "Move to next line.
|
|
1819 Prefix argument serves as a repeat count."
|
72
|
1820 (interactive "p")
|
134
|
1821 (setq zmacs-region-stays t)
|
185
|
1822 (line-move num)
|
0
|
1823 (setq this-command 'next-line))
|
|
1824
|
|
1825 (defun tpu-previous-line (num)
|
|
1826 "Move to previous line.
|
|
1827 Prefix argument serves as a repeat count."
|
72
|
1828 (interactive "p")
|
134
|
1829 (setq zmacs-region-stays t)
|
185
|
1830 (line-move (- num))
|
0
|
1831 (setq this-command 'previous-line))
|
|
1832
|
|
1833 (defun tpu-next-beginning-of-line (num)
|
|
1834 "Move to beginning of line; if at beginning, move to beginning of next line.
|
|
1835 Accepts a prefix argument for the number of lines to move."
|
72
|
1836 (interactive "p")
|
134
|
1837 (setq zmacs-region-stays t)
|
0
|
1838 (backward-char 1)
|
|
1839 (forward-line (- 1 num)))
|
|
1840
|
|
1841 (defun tpu-end-of-line (num)
|
|
1842 "Move to the next end of line in the current direction.
|
|
1843 A repeat count means move that many lines."
|
72
|
1844 (interactive "p")
|
134
|
1845 (setq zmacs-region-stays t)
|
0
|
1846 (if tpu-advance (tpu-next-end-of-line num) (tpu-previous-end-of-line num)))
|
|
1847
|
|
1848 (defun tpu-next-end-of-line (num)
|
|
1849 "Move to end of line; if at end, move to end of next line.
|
|
1850 Accepts a prefix argument for the number of lines to move."
|
72
|
1851 (interactive "p")
|
134
|
1852 (setq zmacs-region-stays t)
|
0
|
1853 (forward-char 1)
|
|
1854 (end-of-line num))
|
|
1855
|
|
1856 (defun tpu-previous-end-of-line (num)
|
|
1857 "Move EOL upward.
|
|
1858 Accepts a prefix argument for the number of lines to move."
|
72
|
1859 (interactive "p")
|
134
|
1860 (setq zmacs-region-stays t)
|
0
|
1861 (end-of-line (- 1 num)))
|
|
1862
|
|
1863 (defun tpu-current-end-of-line nil
|
|
1864 "Move point to end of current line."
|
72
|
1865 (interactive)
|
134
|
1866 (setq zmacs-region-stays t)
|
0
|
1867 (let ((beg (point)))
|
|
1868 (end-of-line)
|
|
1869 (if (= beg (point)) (message "You are already at the end of a line."))))
|
|
1870
|
|
1871 (defun tpu-line (num)
|
|
1872 "Move to the beginning of the next line in the current direction.
|
|
1873 A repeat count means move that many lines."
|
72
|
1874 (interactive "p")
|
134
|
1875 (setq zmacs-region-stays t)
|
0
|
1876 (if tpu-advance (tpu-forward-line num) (tpu-backward-line num)))
|
|
1877
|
|
1878 (defun tpu-forward-line (num)
|
|
1879 "Move to beginning of next line.
|
|
1880 Prefix argument serves as a repeat count."
|
72
|
1881 (interactive "p")
|
134
|
1882 (setq zmacs-region-stays t)
|
0
|
1883 (forward-line num))
|
|
1884
|
|
1885 (defun tpu-backward-line (num)
|
|
1886 "Move to beginning of previous line.
|
|
1887 Prefix argument serves as repeat count."
|
72
|
1888 (interactive "p")
|
134
|
1889 (setq zmacs-region-stays t)
|
72
|
1890 (or (bolp) (>= 0 num) (setq num (- num 1)))
|
0
|
1891 (forward-line (- num)))
|
|
1892
|
|
1893
|
|
1894 ;;;
|
|
1895 ;;; Movement by paragraph
|
|
1896 ;;;
|
|
1897 (defun tpu-paragraph (num)
|
|
1898 "Move to the next paragraph in the current direction.
|
|
1899 A repeat count means move that many paragraphs."
|
72
|
1900 (interactive "p")
|
134
|
1901 (setq zmacs-region-stays t)
|
0
|
1902 (if tpu-advance
|
|
1903 (tpu-next-paragraph num) (tpu-previous-paragraph num)))
|
|
1904
|
|
1905 (defun tpu-next-paragraph (num)
|
|
1906 "Move to beginning of the next paragraph.
|
|
1907 Accepts a prefix argument for the number of paragraphs."
|
72
|
1908 (interactive "p")
|
134
|
1909 (setq zmacs-region-stays t)
|
0
|
1910 (beginning-of-line)
|
|
1911 (while (and (not (eobp)) (> num 0))
|
|
1912 (if (re-search-forward "^[ \t]*$" nil t)
|
|
1913 (if (re-search-forward "[^ \t\n]" nil t)
|
|
1914 (goto-char (match-beginning 0))
|
|
1915 (goto-char (point-max))))
|
|
1916 (setq num (1- num)))
|
|
1917 (beginning-of-line))
|
|
1918
|
|
1919
|
|
1920 (defun tpu-previous-paragraph (num)
|
|
1921 "Move to beginning of previous paragraph.
|
|
1922 Accepts a prefix argument for the number of paragraphs."
|
72
|
1923 (interactive "p")
|
134
|
1924 (setq zmacs-region-stays t)
|
0
|
1925 (end-of-line)
|
|
1926 (while (and (not (bobp)) (> num 0))
|
|
1927 (if (not (and (re-search-backward "^[ \t]*$" nil t)
|
|
1928 (re-search-backward "[^ \t\n]" nil t)
|
|
1929 (re-search-backward "^[ \t]*$" nil t)
|
|
1930 (progn (re-search-forward "[^ \t\n]" nil t)
|
|
1931 (goto-char (match-beginning 0)))))
|
|
1932 (goto-char (point-min)))
|
|
1933 (setq num (1- num)))
|
|
1934 (beginning-of-line))
|
|
1935
|
|
1936
|
|
1937 ;;;
|
|
1938 ;;; Movement by page
|
|
1939 ;;;
|
|
1940 (defun tpu-page (num)
|
|
1941 "Move to the next page in the current direction.
|
|
1942 A repeat count means move that many pages."
|
72
|
1943 (interactive "p")
|
134
|
1944 (setq zmacs-region-stays t)
|
0
|
1945 (if tpu-advance (forward-page num) (backward-page num))
|
|
1946 (if (eobp) (recenter -1)))
|
|
1947
|
|
1948
|
|
1949 ;;;
|
|
1950 ;;; Scrolling and movement within the buffer
|
|
1951 ;;;
|
|
1952 (defun tpu-scroll-window (num)
|
|
1953 "Scroll the display to the next section in the current direction.
|
|
1954 A repeat count means scroll that many sections."
|
72
|
1955 (interactive "p")
|
134
|
1956 (setq zmacs-region-stays t)
|
0
|
1957 (if tpu-advance (tpu-scroll-window-up num) (tpu-scroll-window-down num)))
|
|
1958
|
|
1959 (defun tpu-scroll-window-down (num)
|
|
1960 "Scroll the display down to the next section.
|
|
1961 A repeat count means scroll that many sections."
|
72
|
1962 (interactive "p")
|
134
|
1963 (setq zmacs-region-stays t)
|
185
|
1964 (let* (
|
|
1965 (beg (tpu-current-line))
|
0
|
1966 (height (1- (window-height)))
|
|
1967 (lines (* num (/ (* height tpu-percent-scroll) 100))))
|
185
|
1968 (setq zmacs-region-stays t)
|
|
1969 (line-move (- lines))
|
0
|
1970 (if (> lines beg) (recenter 0))))
|
|
1971
|
|
1972 (defun tpu-scroll-window-up (num)
|
|
1973 "Scroll the display up to the next section.
|
|
1974 A repeat count means scroll that many sections."
|
72
|
1975 (interactive "p")
|
134
|
1976 (setq zmacs-region-stays t)
|
185
|
1977 (let* (
|
|
1978 (beg (tpu-current-line))
|
0
|
1979 (height (1- (window-height)))
|
|
1980 (lines (* num (/ (* height tpu-percent-scroll) 100))))
|
185
|
1981 (setq zmacs-region-stays t)
|
|
1982 (line-move lines)
|
0
|
1983 (if (>= (+ lines beg) height) (recenter -1))))
|
|
1984
|
|
1985 (defun tpu-pan-right (num)
|
|
1986 "Pan right tpu-pan-columns (16 by default).
|
|
1987 Accepts a prefix argument for the number of tpu-pan-columns to scroll."
|
72
|
1988 (interactive "p")
|
134
|
1989 (setq zmacs-region-stays t)
|
0
|
1990 (scroll-left (* tpu-pan-columns num)))
|
|
1991
|
|
1992 (defun tpu-pan-left (num)
|
|
1993 "Pan left tpu-pan-columns (16 by default).
|
|
1994 Accepts a prefix argument for the number of tpu-pan-columns to scroll."
|
72
|
1995 (interactive "p")
|
134
|
1996 (setq zmacs-region-stays t)
|
0
|
1997 (scroll-right (* tpu-pan-columns num)))
|
|
1998
|
|
1999 (defun tpu-move-to-beginning nil
|
|
2000 "Move cursor to the beginning of buffer, but don't set the mark."
|
72
|
2001 (interactive)
|
134
|
2002 (setq zmacs-region-stays t)
|
0
|
2003 (goto-char (point-min)))
|
|
2004
|
|
2005 (defun tpu-move-to-end nil
|
|
2006 "Move cursor to the end of buffer, but don't set the mark."
|
72
|
2007 (interactive)
|
134
|
2008 (setq zmacs-region-stays t)
|
0
|
2009 (goto-char (point-max))
|
|
2010 (recenter -1))
|
|
2011
|
|
2012 (defun tpu-goto-percent (perc)
|
|
2013 "Move point to ARG percentage of the buffer."
|
72
|
2014 (interactive "NGoto-percentage: ")
|
134
|
2015 (setq zmacs-region-stays t)
|
0
|
2016 (if (or (> perc 100) (< perc 0))
|
|
2017 (error "Percentage %d out of range 0 < percent < 100" perc)
|
|
2018 (goto-char (/ (* (point-max) perc) 100))))
|
|
2019
|
|
2020 (defun tpu-beginning-of-window nil
|
|
2021 "Move cursor to top of window."
|
72
|
2022 (interactive)
|
134
|
2023 (setq zmacs-region-stays t)
|
0
|
2024 (move-to-window-line 0))
|
|
2025
|
|
2026 (defun tpu-end-of-window nil
|
|
2027 "Move cursor to bottom of window."
|
72
|
2028 (interactive)
|
134
|
2029 (setq zmacs-region-stays t)
|
0
|
2030 (move-to-window-line -1))
|
|
2031
|
|
2032 (defun tpu-line-to-bottom-of-window nil
|
|
2033 "Move the current line to the bottom of the window."
|
72
|
2034 (interactive)
|
134
|
2035 (setq zmacs-region-stays t)
|
0
|
2036 (recenter -1))
|
|
2037
|
|
2038 (defun tpu-line-to-top-of-window nil
|
|
2039 "Move the current line to the top of the window."
|
72
|
2040 (interactive)
|
134
|
2041 (setq zmacs-region-stays t)
|
0
|
2042 (recenter 0))
|
|
2043
|
|
2044
|
|
2045 ;;;
|
|
2046 ;;; Direction
|
|
2047 ;;;
|
|
2048 (defun tpu-advance-direction nil
|
|
2049 "Set TPU Advance mode so keypad commands move forward."
|
72
|
2050 (interactive)
|
134
|
2051 (setq zmacs-region-stays t)
|
0
|
2052 (setq tpu-direction-string " Advance")
|
|
2053 (setq tpu-advance t)
|
|
2054 (setq tpu-reverse nil)
|
|
2055 (tpu-set-search)
|
|
2056 (tpu-update-mode-line))
|
|
2057
|
|
2058 (defun tpu-backup-direction nil
|
|
2059 "Set TPU Backup mode so keypad commands move backward."
|
72
|
2060 (interactive)
|
134
|
2061 (setq zmacs-region-stays t)
|
0
|
2062 (setq tpu-direction-string " Reverse")
|
|
2063 (setq tpu-advance nil)
|
|
2064 (setq tpu-reverse t)
|
|
2065 (tpu-set-search)
|
|
2066 (tpu-update-mode-line))
|
|
2067
|
|
2068
|
|
2069 ;;;
|
|
2070 ;;; Define keymaps
|
|
2071 ;;;
|
|
2072 (define-key global-map "\e[" CSI-map) ; CSI map
|
|
2073 (define-key global-map "\eO" SS3-map) ; SS3 map
|
|
2074 (define-key SS3-map "P" GOLD-map) ; GOLD map
|
|
2075 (define-key GOLD-map "\e[" GOLD-CSI-map) ; GOLD-CSI map
|
|
2076 (define-key GOLD-map "\eO" GOLD-SS3-map) ; GOLD-SS3 map
|
|
2077
|
|
2078
|
|
2079 ;;;
|
|
2080 ;;; CSI-map key definitions
|
|
2081 ;;;
|
|
2082 (define-key CSI-map "A" 'tpu-previous-line) ; up
|
|
2083 (define-key CSI-map "B" 'tpu-next-line) ; down
|
|
2084 (define-key CSI-map "D" 'tpu-backward-char) ; left
|
|
2085 (define-key CSI-map "C" 'tpu-forward-char) ; right
|
|
2086
|
|
2087 (define-key CSI-map "1~" 'tpu-search) ; Find
|
|
2088 (define-key CSI-map "2~" 'tpu-paste) ; Insert Here
|
|
2089 (define-key CSI-map "3~" 'tpu-cut) ; Remove
|
|
2090 (define-key CSI-map "4~" 'tpu-select) ; Select
|
|
2091 (define-key CSI-map "5~" 'tpu-scroll-window-down) ; Prev Screen
|
|
2092 (define-key CSI-map "6~" 'tpu-scroll-window-up) ; Next Screen
|
|
2093
|
|
2094 (define-key CSI-map "11~" 'nil) ; F1
|
|
2095 (define-key CSI-map "12~" 'nil) ; F2
|
|
2096 (define-key CSI-map "13~" 'nil) ; F3
|
|
2097 (define-key CSI-map "14~" 'nil) ; F4
|
|
2098 (define-key CSI-map "15~" 'nil) ; F5
|
|
2099 (define-key CSI-map "17~" 'nil) ; F6
|
|
2100 (define-key CSI-map "18~" 'nil) ; F7
|
|
2101 (define-key CSI-map "19~" 'nil) ; F8
|
|
2102 (define-key CSI-map "20~" 'nil) ; F9
|
|
2103 (define-key CSI-map "21~" 'tpu-exit) ; F10
|
|
2104 (define-key CSI-map "23~" 'tpu-insert-escape) ; F11 (ESC)
|
|
2105 (define-key CSI-map "24~" 'tpu-next-beginning-of-line) ; F12 (BS)
|
|
2106 (define-key CSI-map "25~" 'tpu-delete-previous-word) ; F13 (LF)
|
|
2107 (define-key CSI-map "26~" 'tpu-toggle-overwrite-mode) ; F14
|
|
2108 (define-key CSI-map "28~" 'tpu-help) ; HELP
|
|
2109 (define-key CSI-map "29~" 'execute-extended-command) ; DO
|
|
2110 (define-key CSI-map "31~" 'tpu-goto-breadcrumb) ; F17
|
|
2111 (define-key CSI-map "32~" 'nil) ; F18
|
|
2112 (define-key CSI-map "33~" 'nil) ; F19
|
|
2113 (define-key CSI-map "34~" 'nil) ; F20
|
|
2114
|
|
2115
|
|
2116 ;;;
|
|
2117 ;;; SS3-map key definitions
|
|
2118 ;;;
|
|
2119 (define-key SS3-map "A" 'tpu-previous-line) ; up
|
|
2120 (define-key SS3-map "B" 'tpu-next-line) ; down
|
|
2121 (define-key SS3-map "C" 'tpu-forward-char) ; right
|
|
2122 (define-key SS3-map "D" 'tpu-backward-char) ; left
|
|
2123
|
|
2124 (define-key SS3-map "Q" 'tpu-help) ; PF2
|
|
2125 (define-key SS3-map "R" 'tpu-search-again) ; PF3
|
|
2126 (define-key SS3-map "S" 'tpu-delete-current-line) ; PF4
|
|
2127 (define-key SS3-map "p" 'tpu-line) ; KP0
|
|
2128 (define-key SS3-map "q" 'tpu-word) ; KP1
|
|
2129 (define-key SS3-map "r" 'tpu-end-of-line) ; KP2
|
|
2130 (define-key SS3-map "s" 'tpu-char) ; KP3
|
|
2131 (define-key SS3-map "t" 'tpu-advance-direction) ; KP4
|
|
2132 (define-key SS3-map "u" 'tpu-backup-direction) ; KP5
|
|
2133 (define-key SS3-map "v" 'tpu-cut) ; KP6
|
|
2134 (define-key SS3-map "w" 'tpu-page) ; KP7
|
|
2135 (define-key SS3-map "x" 'tpu-scroll-window) ; KP8
|
|
2136 (define-key SS3-map "y" 'tpu-append-region) ; KP9
|
|
2137 (define-key SS3-map "m" 'tpu-delete-current-word) ; KP-
|
|
2138 (define-key SS3-map "l" 'tpu-delete-current-char) ; KP,
|
|
2139 (define-key SS3-map "n" 'tpu-select) ; KP.
|
|
2140 (define-key SS3-map "M" 'newline) ; KPenter
|
|
2141
|
|
2142
|
|
2143 ;;;
|
|
2144 ;;; GOLD-map key definitions
|
|
2145 ;;;
|
|
2146 (define-key GOLD-map "\C-A" 'tpu-toggle-overwrite-mode) ; ^A
|
|
2147 (define-key GOLD-map "\C-B" 'nil) ; ^B
|
|
2148 (define-key GOLD-map "\C-C" 'nil) ; ^C
|
|
2149 (define-key GOLD-map "\C-D" 'nil) ; ^D
|
|
2150 (define-key GOLD-map "\C-E" 'nil) ; ^E
|
|
2151 (define-key GOLD-map "\C-F" 'set-visited-file-name) ; ^F
|
|
2152 (define-key GOLD-map "\C-g" 'keyboard-quit) ; safety first
|
|
2153 (define-key GOLD-map "\C-h" 'delete-other-windows) ; BS
|
|
2154 (define-key GOLD-map "\C-i" 'other-window) ; TAB
|
|
2155 (define-key GOLD-map "\C-J" 'nil) ; ^J
|
|
2156 (define-key GOLD-map "\C-K" 'tpu-define-macro-key) ; ^K
|
|
2157 (define-key GOLD-map "\C-l" 'downcase-region) ; ^L
|
|
2158 (define-key GOLD-map "\C-M" 'nil) ; ^M
|
|
2159 (define-key GOLD-map "\C-N" 'nil) ; ^N
|
|
2160 (define-key GOLD-map "\C-O" 'nil) ; ^O
|
|
2161 (define-key GOLD-map "\C-P" 'nil) ; ^P
|
|
2162 (define-key GOLD-map "\C-Q" 'nil) ; ^Q
|
|
2163 (define-key GOLD-map "\C-R" 'nil) ; ^R
|
|
2164 (define-key GOLD-map "\C-S" 'nil) ; ^S
|
|
2165 (define-key GOLD-map "\C-T" 'tpu-toggle-control-keys) ; ^T
|
|
2166 (define-key GOLD-map "\C-u" 'upcase-region) ; ^U
|
|
2167 (define-key GOLD-map "\C-V" 'nil) ; ^V
|
|
2168 (define-key GOLD-map "\C-w" 'tpu-write-current-buffers) ; ^W
|
|
2169 (define-key GOLD-map "\C-X" 'nil) ; ^X
|
|
2170 (define-key GOLD-map "\C-Y" 'nil) ; ^Y
|
|
2171 (define-key GOLD-map "\C-Z" 'nil) ; ^Z
|
|
2172 (define-key GOLD-map " " 'undo) ; SPC
|
|
2173 (define-key GOLD-map "!" 'nil) ; !
|
|
2174 (define-key GOLD-map "#" 'nil) ; #
|
|
2175 (define-key GOLD-map "$" 'tpu-add-at-eol) ; $
|
|
2176 (define-key GOLD-map "%" 'tpu-goto-percent) ; %
|
|
2177 (define-key GOLD-map "&" 'nil) ; &
|
|
2178 (define-key GOLD-map "(" 'nil) ; (
|
|
2179 (define-key GOLD-map ")" 'nil) ; )
|
|
2180 (define-key GOLD-map "*" 'tpu-toggle-regexp) ; *
|
|
2181 (define-key GOLD-map "+" 'nil) ; +
|
|
2182 (define-key GOLD-map "," 'tpu-goto-breadcrumb) ; ,
|
|
2183 (define-key GOLD-map "-" 'negative-argument) ; -
|
|
2184 (define-key GOLD-map "." 'tpu-drop-breadcrumb) ; .
|
|
2185 (define-key GOLD-map "/" 'tpu-emacs-replace) ; /
|
|
2186 (define-key GOLD-map "0" 'digit-argument) ; 0
|
|
2187 (define-key GOLD-map "1" 'digit-argument) ; 1
|
|
2188 (define-key GOLD-map "2" 'digit-argument) ; 2
|
|
2189 (define-key GOLD-map "3" 'digit-argument) ; 3
|
|
2190 (define-key GOLD-map "4" 'digit-argument) ; 4
|
|
2191 (define-key GOLD-map "5" 'digit-argument) ; 5
|
|
2192 (define-key GOLD-map "6" 'digit-argument) ; 6
|
|
2193 (define-key GOLD-map "7" 'digit-argument) ; 7
|
|
2194 (define-key GOLD-map "8" 'digit-argument) ; 8
|
|
2195 (define-key GOLD-map "9" 'digit-argument) ; 9
|
|
2196 (define-key GOLD-map ":" 'nil) ; :
|
|
2197 (define-key GOLD-map ";" 'tpu-trim-line-ends) ; ;
|
|
2198 (define-key GOLD-map "<" 'nil) ; <
|
|
2199 (define-key GOLD-map "=" 'nil) ; =
|
|
2200 (define-key GOLD-map ">" 'nil) ; >
|
|
2201 (define-key GOLD-map "?" 'tpu-spell-check) ; ?
|
|
2202 (define-key GOLD-map "A" 'tpu-toggle-newline-and-indent) ; A
|
|
2203 (define-key GOLD-map "B" 'tpu-next-buffer) ; B
|
|
2204 (define-key GOLD-map "C" 'repeat-complex-command) ; C
|
|
2205 (define-key GOLD-map "D" 'shell-command) ; D
|
|
2206 (define-key GOLD-map "E" 'tpu-exit) ; E
|
|
2207 (define-key GOLD-map "F" 'tpu-set-cursor-free) ; F
|
|
2208 (define-key GOLD-map "G" 'tpu-get) ; G
|
|
2209 (define-key GOLD-map "H" 'nil) ; H
|
|
2210 (define-key GOLD-map "I" 'tpu-include) ; I
|
|
2211 (define-key GOLD-map "K" 'tpu-kill-buffer) ; K
|
|
2212 (define-key GOLD-map "L" 'tpu-what-line) ; L
|
|
2213 (define-key GOLD-map "M" 'buffer-menu) ; M
|
|
2214 (define-key GOLD-map "N" 'tpu-next-file-buffer) ; N
|
|
2215 (define-key GOLD-map "O" 'occur) ; O
|
|
2216 (define-key GOLD-map "P" 'lpr-buffer) ; P
|
|
2217 (define-key GOLD-map "Q" 'tpu-quit) ; Q
|
|
2218 (define-key GOLD-map "R" 'tpu-toggle-rectangle) ; R
|
|
2219 (define-key GOLD-map "S" 'replace) ; S
|
|
2220 (define-key GOLD-map "T" 'tpu-line-to-top-of-window) ; T
|
|
2221 (define-key GOLD-map "U" 'undo) ; U
|
|
2222 (define-key GOLD-map "V" 'tpu-version) ; V
|
|
2223 (define-key GOLD-map "W" 'save-buffer) ; W
|
|
2224 (define-key GOLD-map "X" 'tpu-save-all-buffers-kill-emacs) ; X
|
|
2225 (define-key GOLD-map "Y" 'copy-region-as-kill) ; Y
|
|
2226 (define-key GOLD-map "Z" 'suspend-emacs) ; Z
|
|
2227 (define-key GOLD-map "[" 'blink-matching-open) ; [
|
|
2228 (define-key GOLD-map "\\" 'nil) ; \
|
|
2229 (define-key GOLD-map "]" 'blink-matching-open) ; ]
|
|
2230 (define-key GOLD-map "^" 'tpu-add-at-bol) ; ^
|
|
2231 (define-key GOLD-map "_" 'split-window-vertically) ; -
|
|
2232 (define-key GOLD-map "`" 'what-line) ; `
|
|
2233 (define-key GOLD-map "a" 'tpu-toggle-newline-and-indent) ; a
|
|
2234 (define-key GOLD-map "b" 'tpu-next-buffer) ; b
|
|
2235 (define-key GOLD-map "c" 'repeat-complex-command) ; c
|
|
2236 (define-key GOLD-map "d" 'shell-command) ; d
|
|
2237 (define-key GOLD-map "e" 'tpu-exit) ; e
|
|
2238 (define-key GOLD-map "f" 'tpu-set-cursor-free) ; f
|
|
2239 (define-key GOLD-map "g" 'tpu-get) ; g
|
|
2240 (define-key GOLD-map "h" 'nil) ; h
|
|
2241 (define-key GOLD-map "i" 'tpu-include) ; i
|
|
2242 (define-key GOLD-map "k" 'tpu-kill-buffer) ; k
|
|
2243 (define-key GOLD-map "l" 'goto-line) ; l
|
|
2244 (define-key GOLD-map "m" 'buffer-menu) ; m
|
|
2245 (define-key GOLD-map "n" 'tpu-next-file-buffer) ; n
|
|
2246 (define-key GOLD-map "o" 'occur) ; o
|
|
2247 (define-key GOLD-map "p" 'lpr-region) ; p
|
|
2248 (define-key GOLD-map "q" 'tpu-quit) ; q
|
|
2249 (define-key GOLD-map "r" 'tpu-toggle-rectangle) ; r
|
|
2250 (define-key GOLD-map "s" 'replace) ; s
|
|
2251 (define-key GOLD-map "t" 'tpu-line-to-top-of-window) ; t
|
|
2252 (define-key GOLD-map "u" 'undo) ; u
|
|
2253 (define-key GOLD-map "v" 'tpu-version) ; v
|
|
2254 (define-key GOLD-map "w" 'save-buffer) ; w
|
|
2255 (define-key GOLD-map "x" 'tpu-save-all-buffers-kill-emacs) ; x
|
|
2256 (define-key GOLD-map "y" 'copy-region-as-kill) ; y
|
|
2257 (define-key GOLD-map "z" 'suspend-emacs) ; z
|
|
2258 (define-key GOLD-map "{" 'nil) ; {
|
|
2259 (define-key GOLD-map "|" 'split-window-horizontally) ; |
|
|
2260 (define-key GOLD-map "}" 'nil) ; }
|
|
2261 (define-key GOLD-map "~" 'exchange-point-and-mark) ; ~
|
|
2262 (define-key GOLD-map "\177" 'delete-window) ; <X]
|
|
2263
|
|
2264
|
|
2265 ;;;
|
|
2266 ;;; GOLD-CSI-map key definitions
|
|
2267 ;;;
|
|
2268 (define-key GOLD-CSI-map "A" 'tpu-move-to-beginning) ; up-arrow
|
|
2269 (define-key GOLD-CSI-map "B" 'tpu-move-to-end) ; down-arrow
|
|
2270 (define-key GOLD-CSI-map "C" 'end-of-line) ; right-arrow
|
|
2271 (define-key GOLD-CSI-map "D" 'beginning-of-line) ; left-arrow
|
|
2272
|
|
2273 (define-key GOLD-CSI-map "1~" 'nil) ; Find
|
|
2274 (define-key GOLD-CSI-map "2~" 'nil) ; Insert Here
|
|
2275 (define-key GOLD-CSI-map "3~" 'tpu-store-text) ; Remove
|
|
2276 (define-key GOLD-CSI-map "4~" 'tpu-unselect) ; Select
|
|
2277 (define-key GOLD-CSI-map "5~" 'tpu-previous-window) ; Prev Screen
|
|
2278 (define-key GOLD-CSI-map "6~" 'tpu-next-window) ; Next Screen
|
|
2279
|
|
2280 (define-key GOLD-CSI-map "11~" 'nil) ; F1
|
|
2281 (define-key GOLD-CSI-map "12~" 'nil) ; F2
|
|
2282 (define-key GOLD-CSI-map "13~" 'nil) ; F3
|
|
2283 (define-key GOLD-CSI-map "14~" 'nil) ; F4
|
|
2284 (define-key GOLD-CSI-map "16~" 'nil) ; F5
|
|
2285 (define-key GOLD-CSI-map "17~" 'nil) ; F6
|
|
2286 (define-key GOLD-CSI-map "18~" 'nil) ; F7
|
|
2287 (define-key GOLD-CSI-map "19~" 'nil) ; F8
|
|
2288 (define-key GOLD-CSI-map "20~" 'nil) ; F9
|
|
2289 (define-key GOLD-CSI-map "21~" 'nil) ; F10
|
|
2290 (define-key GOLD-CSI-map "23~" 'nil) ; F11
|
|
2291 (define-key GOLD-CSI-map "24~" 'nil) ; F12
|
|
2292 (define-key GOLD-CSI-map "25~" 'nil) ; F13
|
|
2293 (define-key GOLD-CSI-map "26~" 'nil) ; F14
|
|
2294 (define-key GOLD-CSI-map "28~" 'describe-bindings) ; HELP
|
|
2295 (define-key GOLD-CSI-map "29~" 'nil) ; DO
|
|
2296 (define-key GOLD-CSI-map "31~" 'tpu-drop-breadcrumb) ; F17
|
|
2297 (define-key GOLD-CSI-map "32~" 'nil) ; F18
|
|
2298 (define-key GOLD-CSI-map "33~" 'nil) ; F19
|
|
2299 (define-key GOLD-CSI-map "34~" 'nil) ; F20
|
|
2300
|
|
2301
|
|
2302 ;;;
|
|
2303 ;;; GOLD-SS3-map key definitions
|
|
2304 ;;;
|
|
2305 (define-key GOLD-SS3-map "A" 'tpu-move-to-beginning) ; up-arrow
|
|
2306 (define-key GOLD-SS3-map "B" 'tpu-move-to-end) ; down-arrow
|
|
2307 (define-key GOLD-SS3-map "C" 'end-of-line) ; right-arrow
|
|
2308 (define-key GOLD-SS3-map "D" 'beginning-of-line) ; left-arrow
|
|
2309
|
|
2310 (define-key GOLD-SS3-map "P" 'keyboard-quit) ; PF1
|
|
2311 (define-key GOLD-SS3-map "Q" 'help-for-help) ; PF2
|
|
2312 (define-key GOLD-SS3-map "R" 'tpu-search) ; PF3
|
|
2313 (define-key GOLD-SS3-map "S" 'tpu-undelete-lines) ; PF4
|
|
2314 (define-key GOLD-SS3-map "p" 'open-line) ; KP0
|
|
2315 (define-key GOLD-SS3-map "q" 'tpu-change-case) ; KP1
|
|
2316 (define-key GOLD-SS3-map "r" 'tpu-delete-to-eol) ; KP2
|
|
2317 (define-key GOLD-SS3-map "s" 'tpu-special-insert) ; KP3
|
|
2318 (define-key GOLD-SS3-map "t" 'tpu-move-to-end) ; KP4
|
|
2319 (define-key GOLD-SS3-map "u" 'tpu-move-to-beginning) ; KP5
|
|
2320 (define-key GOLD-SS3-map "v" 'tpu-paste) ; KP6
|
|
2321 (define-key GOLD-SS3-map "w" 'execute-extended-command) ; KP7
|
|
2322 (define-key GOLD-SS3-map "x" 'tpu-fill) ; KP8
|
|
2323 (define-key GOLD-SS3-map "y" 'tpu-replace) ; KP9
|
|
2324 (define-key GOLD-SS3-map "m" 'tpu-undelete-words) ; KP-
|
|
2325 (define-key GOLD-SS3-map "l" 'tpu-undelete-char) ; KP,
|
|
2326 (define-key GOLD-SS3-map "n" 'tpu-unselect) ; KP.
|
|
2327 (define-key GOLD-SS3-map "M" 'tpu-substitute) ; KPenter
|
|
2328
|
|
2329
|
|
2330 ;;;
|
|
2331 ;;; Repeat complex command map additions to make arrows work
|
|
2332 ;;;
|
|
2333 (cond ((boundp 'repeat-complex-command-map)
|
|
2334 (define-key repeat-complex-command-map "\e[A" 'previous-complex-command)
|
|
2335 (define-key repeat-complex-command-map "\e[B" 'next-complex-command)
|
|
2336 (define-key repeat-complex-command-map "\eOA" 'previous-complex-command)
|
|
2337 (define-key repeat-complex-command-map "\eOB" 'next-complex-command)))
|
|
2338
|
|
2339
|
|
2340 ;;;
|
134
|
2341 ;;; Minibuffer map additions to make KP_enter = RET
|
0
|
2342 ;;;
|
|
2343 (define-key minibuffer-local-map "\eOM" 'exit-minibuffer)
|
|
2344 (define-key minibuffer-local-ns-map "\eOM" 'exit-minibuffer)
|
|
2345 (define-key minibuffer-local-completion-map "\eOM" 'exit-minibuffer)
|
185
|
2346 (define-key minibuffer-local-must-match-map "\eOM"
|
|
2347 'minibuffer-complete-and-exit)
|
0
|
2348 (and (boundp 'repeat-complex-command-map)
|
|
2349 (define-key repeat-complex-command-map "\eOM" 'exit-minibuffer))
|
|
2350
|
|
2351
|
|
2352 ;;;
|
72
|
2353 ;;; Minibuffer map additions to set search direction
|
0
|
2354 ;;;
|
72
|
2355 (define-key minibuffer-local-map "\eOt" 'tpu-search-forward-exit)
|
|
2356 (define-key minibuffer-local-map "\eOu" 'tpu-search-backward-exit)
|
0
|
2357
|
|
2358
|
|
2359 ;;;
|
72
|
2360 ;;; Functions to set, reset, and toggle the control key bindings
|
0
|
2361 ;;;
|
72
|
2362 (defun tpu-set-control-keys nil
|
|
2363 "Set control keys to TPU style functions."
|
|
2364 (define-key global-map "\C-\\" 'quoted-insert) ; ^\
|
|
2365 (define-key global-map "\C-a" 'tpu-toggle-overwrite-mode) ; ^A
|
|
2366 (define-key global-map "\C-b" 'repeat-complex-command) ; ^B
|
|
2367 (define-key global-map "\C-e" 'tpu-current-end-of-line) ; ^E
|
|
2368 (define-key global-map "\C-h" 'tpu-next-beginning-of-line) ; ^H (BS)
|
|
2369 (define-key global-map "\C-j" 'tpu-delete-previous-word) ; ^J (LF)
|
|
2370 (define-key global-map "\C-k" 'tpu-define-macro-key) ; ^K
|
|
2371 (define-key global-map "\C-l" 'tpu-insert-formfeed) ; ^L (FF)
|
|
2372 (define-key global-map "\C-r" 'recenter) ; ^R
|
|
2373 (define-key global-map "\C-u" 'tpu-delete-to-bol) ; ^U
|
|
2374 (define-key global-map "\C-v" 'tpu-quoted-insert) ; ^V
|
|
2375 (define-key global-map "\C-w" 'redraw-display) ; ^W
|
|
2376 (define-key global-map "\C-z" 'tpu-exit) ; ^Z
|
|
2377 (setq tpu-control-keys t))
|
|
2378
|
0
|
2379 (defun tpu-reset-control-keys (tpu-style)
|
|
2380 "Set control keys to TPU or emacs style functions."
|
|
2381 (let* ((tpu (and tpu-style (not tpu-control-keys)))
|
|
2382 (emacs (and (not tpu-style) tpu-control-keys))
|
|
2383 (doit (or tpu emacs)))
|
|
2384 (cond (doit
|
|
2385 (if emacs (setq tpu-global-map (copy-keymap global-map)))
|
|
2386 (let ((map (if tpu
|
|
2387 (copy-keymap tpu-global-map)
|
|
2388 (copy-keymap tpu-original-global-map))))
|
|
2389
|
|
2390 (define-key global-map "\C-\\" (lookup-key map "\C-\\")) ; ^\
|
|
2391 (define-key global-map "\C-a" (lookup-key map "\C-a")) ; ^A
|
|
2392 (define-key global-map "\C-b" (lookup-key map "\C-b")) ; ^B
|
|
2393 (define-key global-map "\C-e" (lookup-key map "\C-e")) ; ^E
|
|
2394 (define-key global-map "\C-h" (lookup-key map "\C-h")) ; ^H (BS)
|
|
2395 (define-key global-map "\C-j" (lookup-key map "\C-j")) ; ^J (LF)
|
|
2396 (define-key global-map "\C-k" (lookup-key map "\C-k")) ; ^K
|
|
2397 (define-key global-map "\C-l" (lookup-key map "\C-l")) ; ^L (FF)
|
|
2398 (define-key global-map "\C-r" (lookup-key map "\C-r")) ; ^R
|
|
2399 (define-key global-map "\C-u" (lookup-key map "\C-u")) ; ^U
|
|
2400 (define-key global-map "\C-v" (lookup-key map "\C-v")) ; ^V
|
|
2401 (define-key global-map "\C-w" (lookup-key map "\C-w")) ; ^W
|
|
2402 (define-key global-map "\C-z" (lookup-key map "\C-z")) ; ^Z
|
|
2403 (setq tpu-control-keys tpu-style))))))
|
|
2404
|
|
2405 (defun tpu-toggle-control-keys nil
|
|
2406 "Toggles control key bindings between TPU-edt and Emacs."
|
72
|
2407 (interactive)
|
134
|
2408 (setq zmacs-region-stays t)
|
0
|
2409 (tpu-reset-control-keys (not tpu-control-keys))
|
|
2410 (and (interactive-p)
|
|
2411 (message "Control keys function with %s bindings."
|
|
2412 (if tpu-control-keys "TPU-edt" "Emacs"))))
|
|
2413
|
|
2414
|
|
2415 ;;;
|
|
2416 ;;; Emacs version 19 minibuffer history support
|
|
2417 ;;;
|
|
2418 (defun tpu-next-history-element (n)
|
|
2419 "Insert the next element of the minibuffer history into the minibuffer."
|
72
|
2420 (interactive "p")
|
134
|
2421 (setq zmacs-region-stays t)
|
0
|
2422 (next-history-element n)
|
|
2423 (goto-char (point-max)))
|
|
2424
|
|
2425 (defun tpu-previous-history-element (n)
|
|
2426 "Insert the previous element of the minibuffer history into the minibuffer."
|
72
|
2427 (interactive "p")
|
134
|
2428 (setq zmacs-region-stays t)
|
0
|
2429 (previous-history-element n)
|
|
2430 (goto-char (point-max)))
|
|
2431
|
|
2432 (defun tpu-arrow-history nil
|
|
2433 "Modify minibuffer maps to use arrows for history recall."
|
72
|
2434 (interactive)
|
134
|
2435 (setq zmacs-region-stays t)
|
0
|
2436 (let ((loc (where-is-internal 'tpu-previous-line)) (cur nil))
|
|
2437 (while (setq cur (car loc))
|
|
2438 (define-key read-expression-map cur 'tpu-previous-history-element)
|
|
2439 (define-key minibuffer-local-map cur 'tpu-previous-history-element)
|
|
2440 (define-key minibuffer-local-ns-map cur 'tpu-previous-history-element)
|
185
|
2441 (define-key minibuffer-local-completion-map cur
|
|
2442 'tpu-previous-history-element)
|
|
2443 (define-key minibuffer-local-must-match-map cur
|
|
2444 'tpu-previous-history-element)
|
0
|
2445 (setq loc (cdr loc)))
|
|
2446
|
|
2447 (setq loc (where-is-internal 'tpu-next-line))
|
|
2448 (while (setq cur (car loc))
|
|
2449 (define-key read-expression-map cur 'tpu-next-history-element)
|
|
2450 (define-key minibuffer-local-map cur 'tpu-next-history-element)
|
|
2451 (define-key minibuffer-local-ns-map cur 'tpu-next-history-element)
|
185
|
2452 (define-key minibuffer-local-completion-map cur
|
|
2453 'tpu-next-history-element)
|
|
2454 (define-key minibuffer-local-must-match-map cur
|
|
2455 'tpu-next-history-element)
|
0
|
2456 (setq loc (cdr loc)))))
|
|
2457
|
|
2458
|
|
2459 ;;;
|
|
2460 ;;; Emacs version 19 X-windows key definition support
|
|
2461 ;;;
|
|
2462 (defun tpu-load-xkeys (file)
|
|
2463 "Load the TPU-edt X-windows key definitions FILE.
|
|
2464 If FILE is nil, try to load a default file. The default file names are
|
72
|
2465 `~/.tpu-lucid-keys' for Lucid emacs, and `~/.tpu-keys' for Emacs."
|
|
2466 (interactive "fX key definition file: ")
|
134
|
2467 (setq zmacs-region-stays t)
|
0
|
2468 (cond (file
|
|
2469 (setq file (expand-file-name file)))
|
|
2470 (tpu-xkeys-file
|
|
2471 (setq file (expand-file-name tpu-xkeys-file)))
|
72
|
2472 (tpu-lucid-emacs19-p
|
|
2473 (setq file (convert-standard-filename
|
|
2474 (expand-file-name "~/.tpu-lucid-keys"))))
|
|
2475 (tpu-emacs19-p
|
|
2476 (setq file (convert-standard-filename
|
|
2477 (expand-file-name "~/.tpu-keys")))
|
|
2478 (and (not (file-exists-p file))
|
|
2479 (file-exists-p
|
|
2480 (convert-standard-filename
|
|
2481 (expand-file-name "~/.tpu-gnu-keys")))
|
|
2482 (tpu-copy-keyfile
|
|
2483 (convert-standard-filename
|
|
2484 (expand-file-name "~/.tpu-gnu-keys")) file))))
|
0
|
2485 (cond ((file-readable-p file)
|
|
2486 (load-file file))
|
|
2487 (t
|
|
2488 (switch-to-buffer "*scratch*")
|
|
2489 (erase-buffer)
|
|
2490 (insert "
|
|
2491
|
|
2492 Ack!! You're running TPU-edt under X-windows without loading an
|
|
2493 X key definition file. To create a TPU-edt X key definition
|
|
2494 file, run the tpu-mapper.el program. It came with TPU-edt. It
|
185
|
2495 even includes directions on how to use it! Perhaps it's lying
|
0
|
2496 around here someplace. ")
|
|
2497 (let ((file "tpu-mapper.el")
|
|
2498 (found nil)
|
|
2499 (path nil)
|
|
2500 (search-list (append (list (expand-file-name ".")) load-path)))
|
|
2501 (while (and (not found) search-list)
|
|
2502 (setq path (concat (car search-list)
|
|
2503 (if (string-match "/$" (car search-list)) "" "/")
|
|
2504 file))
|
|
2505 (if (and (file-exists-p path) (not (file-directory-p path)))
|
|
2506 (setq found t))
|
|
2507 (setq search-list (cdr search-list)))
|
|
2508 (cond (found
|
|
2509 (insert (format
|
|
2510 "Ah yes, there it is, in \n\n %s \n\n" path))
|
|
2511 (if (tpu-y-or-n-p "Do you want to run it now? ")
|
|
2512 (load-file path)))
|
|
2513 (t
|
|
2514 (insert "Nope, I can't seem to find it. :-(\n\n")
|
|
2515 (sit-for 120)))))))
|
|
2516
|
72
|
2517 (defun tpu-copy-keyfile (oldname newname)
|
|
2518 "Copy the TPU-edt X key definitions file to the new default name."
|
|
2519 (interactive "fOld name: \nFNew name: ")
|
134
|
2520 (setq zmacs-region-stays t)
|
72
|
2521 (if (not (get-buffer "*TPU-Notice*")) (generate-new-buffer "*TPU-Notice*"))
|
|
2522 (set-buffer "*TPU-Notice*")
|
|
2523 (erase-buffer)
|
|
2524 (insert "
|
|
2525 NOTICE --
|
|
2526
|
|
2527 The default name of the TPU-edt key definition file has changed
|
|
2528 from `~/.tpu-gnu-keys' to `~/.tpu-keys'. With your permission,
|
|
2529 your key definitions will be copied to the new file. If you'll
|
|
2530 never use older versions of Emacs, you can remove the old file.
|
|
2531 If the copy fails, you'll be asked if you want to create a new
|
|
2532 key definitions file. Do you want to copy your key definition
|
|
2533 file now?
|
|
2534 ")
|
|
2535 (save-window-excursion
|
|
2536 (switch-to-buffer-other-window "*TPU-Notice*")
|
|
2537 (shrink-window-if-larger-than-buffer)
|
|
2538 (goto-char (point-min))
|
|
2539 (beep)
|
|
2540 (and (tpu-y-or-n-p "Copy key definitions to the new file now? ")
|
|
2541 (condition-case conditions
|
|
2542 (copy-file oldname newname)
|
|
2543 (error (message "Sorry, couldn't copy - %s" (cdr conditions)))))
|
|
2544 (kill-buffer "*TPU-Notice*")))
|
|
2545
|
0
|
2546
|
|
2547 ;;;
|
|
2548 ;;; Start and Stop TPU-edt
|
|
2549 ;;;
|
|
2550 ;;;###autoload
|
|
2551 (defun tpu-edt-on nil
|
|
2552 "Turn on TPU/edt emulation."
|
|
2553 (interactive)
|
|
2554 (cond
|
|
2555 ((not tpu-edt-mode)
|
|
2556 ;; we use picture-mode functions
|
|
2557 (require 'picture)
|
72
|
2558 (tpu-set-control-keys)
|
0
|
2559 (cond (tpu-emacs19-p
|
|
2560 (and window-system (tpu-load-xkeys nil))
|
|
2561 (tpu-arrow-history))
|
|
2562 (t
|
|
2563 ;; define ispell functions
|
185
|
2564 (autoload 'ispell-word "ispell" "Check spelling of word at or before
|
|
2565 point" t)
|
|
2566 (autoload 'ispell-complete-word "ispell" "Complete word at or before
|
|
2567 point" t)
|
0
|
2568 (autoload 'ispell-buffer "ispell" "Check spelling of entire buffer" t)
|
|
2569 (autoload 'ispell-region "ispell" "Check spelling of region" t)))
|
|
2570 (tpu-set-mode-line t)
|
|
2571 (tpu-advance-direction)
|
|
2572 ;; set page delimiter, display line truncation, and scrolling like TPU
|
|
2573 (setq-default page-delimiter "\f")
|
|
2574 (setq-default truncate-lines t)
|
|
2575 (setq scroll-step 1)
|
|
2576 (setq tpu-edt-mode t))))
|
|
2577
|
|
2578 (defun tpu-edt-off nil
|
|
2579 "Turn off TPU/edt emulation. Note that the keypad is left on."
|
|
2580 (interactive)
|
|
2581 (cond
|
|
2582 (tpu-edt-mode
|
|
2583 (tpu-reset-control-keys nil)
|
|
2584 (tpu-set-mode-line nil)
|
|
2585 (setq-default page-delimiter "^\f")
|
|
2586 (setq-default truncate-lines nil)
|
|
2587 (setq scroll-step 0)
|
72
|
2588 (setq global-map (copy-keymap tpu-original-global-map))
|
0
|
2589 (use-global-map global-map)
|
|
2590 (setq tpu-edt-mode nil))))
|
|
2591
|
|
2592 (provide 'tpu-edt)
|
|
2593
|
|
2594 ;;; tpu-edt.el ends here
|