Mercurial > emacs
annotate lisp/emulation/tpu-edt.el @ 4971:8175d30c0181
Initial revision
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 10 Nov 1993 21:03:53 +0000 |
parents | 076ad69b0c77 |
children | 9cde7d7fea1f |
rev | line source |
---|---|
4421 | 1 ;;; tpu-edt.el --- Emacs emulating TPU emulating EDT |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
2 |
4421 | 3 ;; Copyright (C) 1993 Free Software Foundation, Inc. |
4 | |
5 ;; Author: Rob Riepel <riepel@networking.stanford.edu> | |
6 ;; Maintainer: Rob Riepel <riepel@networking.stanford.edu> | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
7 ;; Version: 3.1 |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
8 ;; Keywords: edt emulations |
4421 | 9 |
4450 | 10 ;; This file is part of GNU Emacs. |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; it under the terms of the GNU General Public License as published by | |
14 ;; the Free Software Foundation; either version 2, or (at your option) | |
15 ;; any later version. | |
4421 | 16 |
4450 | 17 ;; GNU Emacs is distributed in the hope that it will be useful, |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
4421 | 25 |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
26 ;;; Code: |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
27 |
4421 | 28 |
29 ;;; | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
30 ;;; Revision and Version Information |
4421 | 31 ;;; |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
32 (defconst tpu-version "3.1" "TPU-edt version number.") |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
33 (defconst tpu-revision "$Revision: 6.11 $" "Revision number of TPU-edt.") |
4421 | 34 |
35 | |
36 ;;; | |
37 ;;; User Configurable Variables | |
38 ;;; | |
39 (defconst tpu-have-ispell t | |
40 "*If non-nil (default), TPU-edt uses ispell for spell checking.") | |
41 | |
42 (defconst tpu-kill-buffers-silently nil | |
43 "*If non-nil, TPU-edt kills modified buffers without asking.") | |
44 | |
45 (defvar tpu-percent-scroll 75 | |
46 "*Percentage of the screen to scroll for next/previous screen commands.") | |
47 | |
48 (defvar tpu-pan-columns 16 | |
49 "*Number of columns the tpu-pan functions scroll left or right.") | |
50 | |
51 | |
52 ;;; | |
53 ;;; Emacs version identifiers - currently referenced by | |
54 ;;; | |
55 ;;; o tpu-mark o tpu-set-mark | |
56 ;;; o tpu-string-prompt o tpu-regexp-prompt | |
57 ;;; o tpu-edt-on o tpu-load-xkeys | |
58 ;;; o tpu-update-mode-line o mode line section | |
59 ;;; | |
60 (defconst tpu-emacs19-p (not (string-lessp emacs-version "19")) | |
61 "Non-NIL if we are running Lucid or GNU Emacs version 19.") | |
62 | |
63 (defconst tpu-gnu-emacs18-p (not tpu-emacs19-p) | |
64 "Non-NIL if we are running GNU Emacs version 18.") | |
65 | |
66 (defconst tpu-lucid-emacs19-p | |
67 (and tpu-emacs19-p (string-match "Lucid" emacs-version)) | |
68 "Non-NIL if we are running Lucid Emacs version 19.") | |
69 | |
70 (defconst tpu-gnu-emacs19-p (and tpu-emacs19-p (not tpu-lucid-emacs19-p)) | |
71 "Non-NIL if we are running GNU Emacs version 19.") | |
72 | |
73 | |
74 ;;; | |
75 ;;; Global Keymaps | |
76 ;;; | |
77 (defvar CSI-map (make-sparse-keymap) | |
78 "Maps the CSI function keys on the VT100 keyboard. | |
79 CSI is DEC's name for the sequence <ESC>[.") | |
80 | |
81 (defvar SS3-map (make-sparse-keymap) | |
82 "Maps the SS3 function keys on the VT100 keyboard. | |
83 SS3 is DEC's name for the sequence <ESC>O.") | |
84 | |
85 (defvar GOLD-map (make-keymap) | |
86 "Maps the function keys on the VT100 keyboard preceeded by PF1. | |
87 GOLD is the ASCII 7-bit escape sequence <ESC>OP.") | |
88 | |
89 (defvar GOLD-CSI-map (make-sparse-keymap) | |
90 "Maps the function keys on the VT100 keyboard preceeded by GOLD-CSI.") | |
91 | |
92 (defvar GOLD-SS3-map (make-sparse-keymap) | |
93 "Maps the function keys on the VT100 keyboard preceeded by GOLD-SS3.") | |
94 | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
95 (defvar tpu-global-map nil "TPU-edt global keymap.") |
4421 | 96 (defvar tpu-original-global-map (copy-keymap global-map) |
97 "Original global keymap.") | |
98 | |
99 (and tpu-lucid-emacs19-p | |
100 (defvar minibuffer-local-ns-map (make-sparse-keymap) | |
101 "Hack to give Lucid emacs the same maps as GNU emacs.")) | |
102 | |
103 | |
104 ;;; | |
105 ;;; Global Variables | |
106 ;;; | |
107 (defvar tpu-edt-mode nil | |
108 "If non-nil, TPU-edt mode is active.") | |
109 | |
110 (defvar tpu-last-replaced-text "" | |
111 "Last text deleted by a TPU-edt replace command.") | |
112 (defvar tpu-last-deleted-region "" | |
113 "Last text deleted by a TPU-edt remove command.") | |
114 (defvar tpu-last-deleted-lines "" | |
115 "Last text deleted by a TPU-edt line-delete command.") | |
116 (defvar tpu-last-deleted-words "" | |
117 "Last text deleted by a TPU-edt word-delete command.") | |
118 (defvar tpu-last-deleted-char "" | |
119 "Last character deleted by a TPU-edt character-delete command.") | |
120 | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
121 (defvar tpu-searching-forward t |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
122 "If non-nil, TPU-edt is searching in the forward direction.") |
4421 | 123 (defvar tpu-search-last-string "" |
124 "Last text searched for by the TPU-edt search commands.") | |
125 | |
126 (defvar tpu-regexp-p nil | |
127 "If non-nil, TPU-edt uses regexp search and replace routines.") | |
128 (defvar tpu-rectangular-p nil | |
129 "If non-nil, TPU-edt removes and inserts rectangles.") | |
130 (defvar tpu-advance t | |
131 "True when TPU-edt is operating in the forward direction.") | |
132 (defvar tpu-reverse nil | |
133 "True when TPU-edt is operating in the backward direction.") | |
134 (defvar tpu-control-keys t | |
135 "If non-nil, control keys are set to perform TPU functions.") | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
136 (defvar tpu-xkeys-file nil |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
137 "File containing TPU-edt X key map.") |
4421 | 138 |
139 (defvar tpu-rectangle-string nil | |
140 "Mode line string to identify rectangular mode.") | |
141 (defvar tpu-direction-string nil | |
142 "Mode line string to identify current direction.") | |
143 | |
144 (defvar tpu-add-at-bol-hist nil | |
145 "History variable for tpu-edt-add-at-bol function.") | |
146 (defvar tpu-add-at-eol-hist nil | |
147 "History variable for tpu-edt-add-at-eol function.") | |
148 (defvar tpu-regexp-prompt-hist nil | |
149 "History variable for search and replace functions.") | |
150 | |
151 | |
152 ;;; | |
153 ;;; Buffer Local Variables | |
154 ;;; | |
155 (defvar tpu-newline-and-indent-p nil | |
156 "If non-nil, Return produces a newline and indents.") | |
157 (make-variable-buffer-local 'tpu-newline-and-indent-p) | |
158 | |
159 (defvar tpu-newline-and-indent-string nil | |
160 "Mode line string to identify AutoIndent mode.") | |
161 (make-variable-buffer-local 'tpu-newline-and-indent-string) | |
162 | |
163 (defvar tpu-saved-delete-func nil | |
164 "Saved value of the delete key.") | |
165 (make-variable-buffer-local 'tpu-saved-delete-func) | |
166 | |
167 (defvar tpu-buffer-local-map nil | |
168 "TPU-edt buffer local key map.") | |
169 (make-variable-buffer-local 'tpu-buffer-local-map) | |
170 | |
171 | |
172 ;;; | |
173 ;;; Mode Line - Modify the mode line to show the following | |
174 ;;; | |
175 ;;; o If the mark is set. | |
176 ;;; o Direction of motion. | |
177 ;;; o Active rectangle mode. | |
178 ;;; | |
179 (defvar tpu-original-mode-line mode-line-format) | |
180 (defvar tpu-original-mm-alist minor-mode-alist) | |
181 | |
182 (defvar tpu-mark-flag " ") | |
183 (make-variable-buffer-local 'tpu-mark-flag) | |
184 | |
185 (defun tpu-set-mode-line (for-tpu) | |
186 "Set the mode for TPU-edt, or reset it to default Emacs." | |
187 (cond ((not for-tpu) | |
188 (setq mode-line-format tpu-original-mode-line) | |
189 (setq minor-mode-alist tpu-original-mm-alist)) | |
190 (t | |
191 (setq-default mode-line-format | |
192 (list (purecopy "") | |
193 'mode-line-modified | |
194 'mode-line-buffer-identification | |
195 (purecopy " ") | |
196 'global-mode-string | |
197 (purecopy " ") | |
198 'tpu-mark-flag | |
199 (purecopy " %[(") | |
200 'mode-name 'minor-mode-alist "%n" 'mode-line-process | |
201 (purecopy ")%]----") | |
202 (purecopy '(-3 . "%p")) | |
203 (purecopy "-%-"))) | |
204 (or (assq 'tpu-newline-and-indent-p minor-mode-alist) | |
205 (setq minor-mode-alist | |
206 (cons '(tpu-newline-and-indent-p | |
207 tpu-newline-and-indent-string) | |
208 minor-mode-alist))) | |
209 (or (assq 'tpu-rectangular-p minor-mode-alist) | |
210 (setq minor-mode-alist | |
211 (cons '(tpu-rectangular-p tpu-rectangle-string) | |
212 minor-mode-alist))) | |
213 (or (assq 'tpu-direction-string minor-mode-alist) | |
214 (setq minor-mode-alist | |
215 (cons '(tpu-direction-string tpu-direction-string) | |
216 minor-mode-alist)))))) | |
217 | |
218 (defun tpu-update-mode-line nil | |
219 "Make sure mode-line in the current buffer reflects all changes." | |
220 (setq tpu-mark-flag (if (tpu-mark) "M" " ")) | |
221 (cond (tpu-emacs19-p (force-mode-line-update)) | |
222 (t (set-buffer-modified-p (buffer-modified-p)) (sit-for 0)))) | |
223 | |
224 (cond (tpu-gnu-emacs19-p | |
225 (add-hook 'activate-mark-hook 'tpu-update-mode-line) | |
226 (add-hook 'deactivate-mark-hook 'tpu-update-mode-line)) | |
227 (tpu-lucid-emacs19-p | |
228 (add-hook 'zmacs-deactivate-region-hook 'tpu-update-mode-line) | |
229 (add-hook 'zmacs-activate-region-hook 'tpu-update-mode-line))) | |
230 | |
231 | |
232 ;;; | |
233 ;;; Match Markers - | |
234 ;;; | |
235 ;;; Set in: Search | |
236 ;;; | |
237 ;;; Used in: Replace, Substitute, Store-Text, Cut/Remove, | |
238 ;;; Append, and Change-Case | |
239 ;;; | |
240 (defvar tpu-match-beginning-mark (make-marker)) | |
241 (defvar tpu-match-end-mark (make-marker)) | |
242 | |
243 (defun tpu-set-match nil | |
244 "Set markers at match beginning and end." | |
245 ;; Add one to beginning mark so it stays with the first character of | |
246 ;; the string even if characters are added just before the string. | |
247 (setq tpu-match-beginning-mark (copy-marker (1+ (match-beginning 0)))) | |
248 (setq tpu-match-end-mark (copy-marker (match-end 0)))) | |
249 | |
250 (defun tpu-unset-match nil | |
251 "Unset match beginning and end markers." | |
252 (set-marker tpu-match-beginning-mark nil) | |
253 (set-marker tpu-match-end-mark nil)) | |
254 | |
255 (defun tpu-match-beginning nil | |
256 "Returns the location of the last match beginning." | |
257 (1- (marker-position tpu-match-beginning-mark))) | |
258 | |
259 (defun tpu-match-end nil | |
260 "Returns the location of the last match end." | |
261 (marker-position tpu-match-end-mark)) | |
262 | |
263 (defun tpu-check-match nil | |
264 "Returns t if point is between tpu-match markers. | |
265 Otherwise sets the tpu-match markers to nil and returns nil." | |
266 ;; make sure 1- marker is in this buffer | |
267 ;; 2- point is at or after beginning marker | |
268 ;; 3- point is before ending marker, or in the case of | |
269 ;; zero length regions (like bol, or eol) that the | |
270 ;; beginning, end, and point are equal. | |
271 (cond ((and | |
272 (equal (marker-buffer tpu-match-beginning-mark) (current-buffer)) | |
273 (>= (point) (1- (marker-position tpu-match-beginning-mark))) | |
274 (or | |
275 (< (point) (marker-position tpu-match-end-mark)) | |
276 (and (= (1- (marker-position tpu-match-beginning-mark)) | |
277 (marker-position tpu-match-end-mark)) | |
278 (= (marker-position tpu-match-end-mark) (point))))) t) | |
279 (t | |
280 (tpu-unset-match) nil))) | |
281 | |
282 (defun tpu-show-match-markers nil | |
283 "Show the values of the match markers." | |
284 (interactive) | |
285 (if (markerp tpu-match-beginning-mark) | |
286 (let ((beg (marker-position tpu-match-beginning-mark))) | |
287 (message "(%s, %s) in %s -- current %s in %s" | |
288 (if beg (1- beg) nil) | |
289 (marker-position tpu-match-end-mark) | |
290 (marker-buffer tpu-match-end-mark) | |
291 (point) (current-buffer))))) | |
292 | |
293 | |
294 ;;; | |
295 ;;; Utilities | |
296 ;;; | |
297 (defun tpu-caar (thingy) (car (car thingy))) | |
298 (defun tpu-cadr (thingy) (car (cdr thingy))) | |
299 | |
300 (defun tpu-mark nil | |
301 "TPU-edt version of the mark function. | |
302 Return the appropriate value of the mark for the current | |
303 version of emacs." | |
304 (cond (tpu-lucid-emacs19-p (mark (not zmacs-regions))) | |
305 (tpu-gnu-emacs19-p (and mark-active (mark (not transient-mark-mode)))) | |
306 (t (mark)))) | |
307 | |
308 (defun tpu-set-mark (pos) | |
309 "TPU-edt verion of the set-mark function. | |
310 Sets the mark at POS and activates the region acording to the | |
311 current version of emacs." | |
312 (set-mark pos) | |
313 (and tpu-lucid-emacs19-p pos (zmacs-activate-region))) | |
314 | |
315 (defun tpu-string-prompt (prompt history-symbol) | |
316 "Read a string with PROMPT." | |
317 (if tpu-emacs19-p | |
318 (read-from-minibuffer prompt nil nil nil history-symbol) | |
319 (read-string prompt))) | |
320 | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
321 (defvar tpu-last-answer nil "Most recent response to tpu-y-or-n-p.") |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
322 |
4421 | 323 (defun tpu-y-or-n-p (prompt &optional not-yes) |
324 "Prompt for a y or n answer with positive default. | |
325 Optional second argument NOT-YES changes default to negative. | |
326 Like emacs y-or-n-p, also accepts space as y and DEL as n." | |
327 (message (format "%s[%s]" prompt (if not-yes "n" "y"))) | |
328 (let ((doit t)) | |
329 (while doit | |
330 (setq doit nil) | |
331 (let ((ans (read-char))) | |
332 (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\ )) | |
333 (setq tpu-last-answer t)) | |
334 ((or (= ans ?n) (= ans ?N) (= ans ?\C-?)) | |
335 (setq tpu-last-answer nil)) | |
336 ((= ans ?\r) (setq tpu-last-answer (not not-yes))) | |
337 (t | |
338 (setq doit t) (beep) | |
339 (message (format "Please answer y or n. %s[%s]" | |
340 prompt (if not-yes "n" "y")))))))) | |
341 tpu-last-answer) | |
342 | |
343 (defun tpu-local-set-key (key func) | |
344 "Replace a key in the TPU-edt local key map. | |
345 Create the key map if necessary." | |
346 (cond ((not (keymapp tpu-buffer-local-map)) | |
347 (setq tpu-buffer-local-map (if (current-local-map) | |
348 (copy-keymap (current-local-map)) | |
349 (make-sparse-keymap))) | |
350 (use-local-map tpu-buffer-local-map))) | |
351 (local-set-key key func)) | |
352 | |
353 (defun tpu-current-line nil | |
354 "Return the vertical position of point in the selected window. | |
355 Top line is 0. Counts each text line only once, even if it wraps." | |
356 (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -1)) | |
357 | |
358 | |
359 ;;; | |
360 ;;; Breadcrumbs | |
361 ;;; | |
362 (defvar tpu-breadcrumb-plist nil | |
363 "The set of user-defined markers (breadcrumbs), as a plist.") | |
364 | |
365 (defun tpu-drop-breadcrumb (num) | |
366 "Drops a breadcrumb that can be returned to later with goto-breadcrumb." | |
367 (interactive "p") | |
368 (put tpu-breadcrumb-plist num (list (current-buffer) (point))) | |
369 (message "Mark %d set." num)) | |
370 | |
371 (defun tpu-goto-breadcrumb (num) | |
372 "Returns to a breadcrumb set with drop-breadcrumb." | |
373 (interactive "p") | |
374 (cond ((get tpu-breadcrumb-plist num) | |
375 (switch-to-buffer (car (get tpu-breadcrumb-plist num))) | |
376 (goto-char (tpu-cadr (get tpu-breadcrumb-plist num))) | |
377 (message "mark %d found." num)) | |
378 (t | |
379 (message "mark %d not found." num)))) | |
380 | |
381 | |
382 ;;; | |
383 ;;; Miscellaneous | |
384 ;;; | |
385 (defun tpu-change-case (num) | |
386 "Change the case of the character under the cursor or region. | |
387 Accepts a prefix argument of the number of characters to invert." | |
388 (interactive "p") | |
389 (cond ((tpu-mark) | |
390 (let ((beg (region-beginning)) (end (region-end))) | |
391 (while (> end beg) | |
392 (funcall (if (= (downcase (char-after beg)) (char-after beg)) | |
393 'upcase-region 'downcase-region) | |
394 beg (1+ beg)) | |
395 (setq beg (1+ beg))) | |
396 (tpu-unselect t))) | |
397 ((tpu-check-match) | |
398 (let ((beg (tpu-match-beginning)) (end (tpu-match-end))) | |
399 (while (> end beg) | |
400 (funcall (if (= (downcase (char-after beg)) (char-after beg)) | |
401 'upcase-region 'downcase-region) | |
402 beg (1+ beg)) | |
403 (setq beg (1+ beg))) | |
404 (tpu-unset-match))) | |
405 (t | |
406 (while (> num 0) | |
407 (funcall (if (= (downcase (following-char)) (following-char)) | |
408 'upcase-region 'downcase-region) | |
409 (point) (1+ (point))) | |
410 (forward-char (if tpu-reverse -1 1)) | |
411 (setq num (1- num)))))) | |
412 | |
413 (defun tpu-fill (num) | |
414 "Fill paragraph or marked region. | |
415 With argument, fill and justify." | |
416 (interactive "P") | |
417 (cond ((tpu-mark) | |
418 (fill-region (point) (tpu-mark) num) | |
419 (tpu-unselect t)) | |
420 (t | |
421 (fill-paragraph num)))) | |
422 | |
423 (defun tpu-version nil | |
424 "Print the TPU-edt version number." | |
425 (interactive) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
426 (message |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
427 "TPU-edt version %s by Rob Riepel (riepel@networking.stanford.edu)" |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
428 tpu-version)) |
4421 | 429 |
430 (defun tpu-reset-screen-size (height width) | |
431 "Sets the screen size." | |
432 (interactive "nnew screen height: \nnnew screen width: ") | |
433 (set-screen-height height) | |
434 (set-screen-width width)) | |
435 | |
436 (defun tpu-toggle-newline-and-indent nil | |
437 "Toggle between 'newline and indent' and 'simple newline'." | |
438 (interactive) | |
439 (cond (tpu-newline-and-indent-p | |
440 (setq tpu-newline-and-indent-string "") | |
441 (setq tpu-newline-and-indent-p nil) | |
442 (tpu-local-set-key "\C-m" 'newline)) | |
443 (t | |
444 (setq tpu-newline-and-indent-string " AutoIndent") | |
445 (setq tpu-newline-and-indent-p t) | |
446 (tpu-local-set-key "\C-m" 'newline-and-indent))) | |
447 (tpu-update-mode-line) | |
448 (and (interactive-p) | |
449 (message "Carriage return inserts a newline%s" | |
450 (if tpu-newline-and-indent-p " and indents." ".")))) | |
451 | |
452 (defun tpu-spell-check nil | |
453 "Checks the spelling of the region, or of the entire buffer if no | |
454 region is selected." | |
455 (interactive) | |
456 (cond (tpu-have-ispell | |
457 (if (tpu-mark) (ispell-region (tpu-mark) (point)) (ispell-buffer))) | |
458 (t | |
459 (if (tpu-mark) (spell-region (tpu-mark) (point)) (spell-buffer)))) | |
460 (if (tpu-mark) (tpu-unselect t))) | |
461 | |
462 (defun tpu-toggle-overwrite-mode nil | |
463 "Switches in and out of overwrite mode" | |
464 (interactive) | |
465 (cond (overwrite-mode | |
466 (tpu-local-set-key "\177" tpu-saved-delete-func) | |
467 (overwrite-mode 0)) | |
468 (t | |
469 (setq tpu-saved-delete-func (local-key-binding "\177")) | |
470 (tpu-local-set-key "\177" 'picture-backward-clear-column) | |
471 (overwrite-mode 1)))) | |
472 | |
473 (defun tpu-special-insert (num) | |
474 "Insert a character or control code according to | |
475 its ASCII decimal value." | |
476 (interactive "P") | |
477 (if overwrite-mode (delete-char 1)) | |
478 (insert (if num num 0))) | |
479 | |
480 | |
481 ;;; | |
482 ;;; TPU line-mode commands | |
483 ;;; | |
484 (defun tpu-include (file) | |
485 "TPU-like include file" | |
486 (interactive "fInclude file: ") | |
487 (save-excursion | |
488 (insert-file file) | |
489 (message ""))) | |
490 | |
491 (defun tpu-get (file) | |
492 "TPU-like get file" | |
493 (interactive "FFile to get: ") | |
494 (find-file file)) | |
495 | |
496 (defun tpu-what-line nil | |
497 "Tells what line the point is on, | |
498 and the total number of lines in the buffer." | |
499 (interactive) | |
500 (if (eobp) | |
501 (message "You are at the End of Buffer. The last line is %d." | |
502 (count-lines 1 (point-max))) | |
503 (message "Line %d of %d" | |
504 (count-lines 1 (1+ (point))) | |
505 (count-lines 1 (point-max))))) | |
506 | |
507 (defun tpu-exit nil | |
508 "Exit the way TPU does, save current buffer and ask about others." | |
509 (interactive) | |
510 (if (not (eq (recursion-depth) 0)) | |
511 (exit-recursive-edit) | |
512 (progn (save-buffer) (save-buffers-kill-emacs)))) | |
513 | |
514 (defun tpu-quit nil | |
515 "Quit the way TPU does, ask to make sure changes should be abandoned." | |
516 (interactive) | |
517 (let ((list (buffer-list)) | |
518 (working t)) | |
519 (while (and list working) | |
520 (let ((buffer (car list))) | |
521 (if (and (buffer-file-name buffer) (buffer-modified-p buffer)) | |
522 (if (tpu-y-or-n-p | |
523 "Modifications will not be saved, continue quitting? ") | |
524 (kill-emacs t) (setq working nil))) | |
525 (setq list (cdr list)))) | |
526 (if working (kill-emacs t)))) | |
527 | |
528 | |
529 ;;; | |
530 ;;; Command and Function Aliases | |
531 ;;; | |
532 ;;;###autoload | |
533 (fset 'tpu-edt-mode 'tpu-edt-on) | |
534 (fset 'TPU-EDT-MODE 'tpu-edt-on) | |
535 | |
536 ;;;###autoload | |
537 (fset 'tpu-edt 'tpu-edt-on) | |
538 (fset 'TPU-EDT 'tpu-edt-on) | |
539 | |
540 (fset 'exit 'tpu-exit) | |
541 (fset 'EXIT 'tpu-exit) | |
542 | |
543 (fset 'Get 'tpu-get) | |
544 (fset 'GET 'tpu-get) | |
545 | |
546 (fset 'include 'tpu-include) | |
547 (fset 'INCLUDE 'tpu-include) | |
548 | |
549 (fset 'quit 'tpu-quit) | |
550 (fset 'QUIT 'tpu-quit) | |
551 | |
552 (fset 'spell 'tpu-spell-check) | |
553 (fset 'SPELL 'tpu-spell-check) | |
554 | |
555 (fset 'what\ line 'tpu-what-line) | |
556 (fset 'WHAT\ LINE 'tpu-what-line) | |
557 | |
558 (fset 'replace 'tpu-lm-replace) | |
559 (fset 'REPLACE 'tpu-lm-replace) | |
560 | |
561 (fset 'help 'tpu-help) | |
562 (fset 'HELP 'tpu-help) | |
563 | |
564 ;; Around emacs version 18.57, function line-move was renamed to | |
565 ;; next-line-internal. If we're running under an older emacs, | |
566 ;; make next-line-internal equivalent to line-move. | |
567 | |
568 (if (not (fboundp 'next-line-internal)) (fset 'next-line-internal 'line-move)) | |
569 | |
570 | |
571 ;;; | |
572 ;;; Help | |
573 ;;; | |
574 (defconst tpu-help-keypad-map "\f | |
575 _______________________ _______________________________ | |
576 | HELP | Do | | | | | | | |
577 |KeyDefs| | | | | | | | |
578 |_______|_______________| |_______|_______|_______|_______| | |
579 _______________________ _______________________________ | |
580 | Find |Insert |Remove | | Gold | HELP |FndNxt | Del L | | |
581 | | |Sto Tex| | key |E-Help | Find |Undel L| | |
582 |_______|_______|_______| |_______|_______|_______|_______| | |
583 |Select |Pre Scr|Nex Scr| | Page | Sect |Append | Del W | | |
584 | Reset |Pre Win|Nex Win| | Do | Fill |Replace|Undel W| | |
585 |_______|_______|_______| |_______|_______|_______|_______| | |
586 |Move up| |Forward|Reverse|Remove | Del C | | |
587 | Top | |Bottom | Top |Insert |Undel C| | |
588 _______|_______|_______ |_______|_______|_______|_______| | |
589 |Mov Lef|Mov Dow|Mov Rig| | Word | EOL | Char | | | |
590 |StaOfLi|Bottom |EndOfLi| |ChngCas|Del EOL|SpecIns| Enter | | |
591 |_______|_______|_______| |_______|_______|_______| | | |
592 | Line |Select | Subs | | |
593 | Open Line | Reset | | | |
594 |_______________|_______|_______| | |
595 ") | |
596 | |
597 (defconst tpu-help-text " | |
598 \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 | |
599 | |
600 Control Characters | |
601 | |
602 ^A toggle insert and overwrite | |
603 ^B recall | |
604 ^E end of line | |
605 | |
606 ^G Cancel current operation | |
607 ^H beginning of line | |
608 ^J delete previous word | |
609 | |
610 ^K learn | |
611 ^L insert page break | |
612 ^R remember (during learn), re-center | |
613 | |
614 ^U delete to beginning of line | |
615 ^V quote | |
616 ^W refresh | |
617 | |
618 ^Z exit | |
619 ^X^X exchange point and mark - useful for checking region boundaries | |
620 | |
621 \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 | |
622 Gold-<key> Functions | |
623 | |
624 B Next Buffer - display the next buffer (all buffers) | |
625 C Recall - edit and possibly repeat previous commands | |
626 E Exit - save current buffer and ask about others | |
627 | |
628 G Get - load a file into a new edit buffer | |
629 I Include - include a file in this buffer | |
630 K Kill Buffer - abandon edits and delete buffer | |
631 | |
632 M Buffer Menu - display a list of all buffers | |
633 N Next File Buffer - display next buffer containing a file | |
634 O Occur - show following lines containing REGEXP | |
635 | |
636 Q Quit - exit without saving anything | |
637 R Toggle rectangular mode for remove and insert | |
638 S Search and substitute - line mode REPLACE command | |
639 | |
640 U Undo - undo the last edit | |
641 W Write - save current buffer | |
642 X Exit - save all modified buffers and exit | |
643 | |
644 \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 | |
645 | |
646 *** No more help, use P to view previous screen") | |
647 | |
648 (defvar tpu-help-enter (format "%s" "\eOM")) ; tpu-help enter key symbol | |
649 (defvar tpu-help-return (format "%s" "\r")) ; tpu-help enter key symbol | |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
650 (defvar tpu-help-N "N") ; tpu-help "N" symbol |
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
651 (defvar tpu-help-n "n") ; tpu-help "n" symbol |
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
652 (defvar tpu-help-P "P") ; tpu-help "P" symbol |
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
653 (defvar tpu-help-p "p") ; tpu-help "p" symbol |
4421 | 654 |
655 (defun tpu-help nil | |
656 "Display TPU-edt help." | |
657 (interactive) | |
658 ;; Save current window configuration | |
659 (save-window-excursion | |
660 ;; Create and fill help buffer if necessary | |
661 (if (not (get-buffer "*TPU-edt Help*")) | |
662 (progn (generate-new-buffer "*TPU-edt Help*") | |
663 (switch-to-buffer "*TPU-edt Help*") | |
664 (insert tpu-help-keypad-map) | |
665 (insert tpu-help-text) | |
666 (setq buffer-read-only t))) | |
667 | |
668 ;; Display the help buffer | |
669 (switch-to-buffer "*TPU-edt Help*") | |
670 (delete-other-windows) | |
671 (tpu-move-to-beginning) | |
672 (forward-line 1) | |
673 (tpu-line-to-top-of-window) | |
674 | |
675 ;; Prompt for keys to describe, based on screen state (split/not split) | |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
676 (let ((key nil) (fkey nil) (split nil)) |
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
677 (while (not (equal tpu-help-return fkey)) |
4421 | 678 (if split |
679 (setq key | |
680 (read-key-sequence | |
681 "Press the key you want help on (RET=exit, ENTER=redisplay, N=next, P=prev): ")) | |
682 (setq key | |
683 (read-key-sequence | |
684 "Press the key you want help on (RET to exit, N next screen, P prev screen): "))) | |
685 | |
686 ;; Process the read key | |
687 ;; | |
688 ;; ENTER - Display just the help window | |
689 ;; N or n - Next help or describe-key screen | |
690 ;; P or p - Previous help or describe-key screen | |
691 ;; RETURN - Exit from TPU-help | |
692 ;; default - describe the key | |
693 ;; | |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
694 (setq fkey (format "%s" key)) |
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
695 (cond ((equal tpu-help-enter fkey) |
4421 | 696 (setq split nil) |
697 (delete-other-windows)) | |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
698 ((or (equal tpu-help-N fkey) (equal tpu-help-n fkey)) |
4421 | 699 (cond (split |
700 (condition-case nil | |
701 (scroll-other-window 8) | |
702 (error nil))) | |
703 (t | |
704 (forward-page) | |
705 (forward-line 1) | |
706 (tpu-line-to-top-of-window)))) | |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
707 ((or (equal tpu-help-P fkey) (equal tpu-help-p fkey)) |
4421 | 708 (cond (split |
709 (condition-case nil | |
710 (scroll-other-window -8) | |
711 (error nil))) | |
712 (t | |
713 (backward-page 2) | |
714 (forward-line 1) | |
715 (tpu-line-to-top-of-window)))) | |
4549
076ad69b0c77
(tpu-help): Use variables for "n" and "p".
Richard M. Stallman <rms@gnu.org>
parents:
4523
diff
changeset
|
716 ((not (equal tpu-help-return fkey)) |
4421 | 717 (setq split t) |
718 (describe-key key) | |
719 ;; If the key is undefined, leave the | |
720 ;; message in the mini-buffer for 3 seconds | |
721 (if (not (key-binding key)) (sit-for 3)))))))) | |
722 | |
723 | |
724 ;;; | |
725 ;;; Auto-insert | |
726 ;;; | |
727 (defun tpu-insert-escape nil | |
728 "Inserts an escape character, and so becomes the escape-key alias." | |
729 (interactive) | |
730 (insert "\e")) | |
731 | |
732 (defun tpu-insert-formfeed nil | |
733 "Inserts a formfeed character." | |
734 (interactive) | |
735 (insert "\C-L")) | |
736 | |
737 | |
738 ;;; | |
739 ;;; Define key | |
740 ;;; | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
741 (defvar tpu-saved-control-r nil "Saved value of Control-r.") |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
742 |
4421 | 743 (defun tpu-end-define-macro-key (key) |
744 "Ends the current macro definition" | |
745 (interactive "kPress the key you want to use to do what was just learned: ") | |
746 (end-kbd-macro nil) | |
747 (global-set-key key last-kbd-macro) | |
748 (global-set-key "\C-r" tpu-saved-control-r)) | |
749 | |
750 (defun tpu-define-macro-key nil | |
751 "Bind a set of keystrokes to a single key, or key combination." | |
752 (interactive) | |
753 (setq tpu-saved-control-r (global-key-binding "\C-r")) | |
754 (global-set-key "\C-r" 'tpu-end-define-macro-key) | |
755 (start-kbd-macro nil)) | |
756 | |
757 | |
758 ;;; | |
759 ;;; Buffers and Windows | |
760 ;;; | |
761 (defun tpu-kill-buffer nil | |
762 "Kills the current buffer. If tpu-kill-buffers-silently is non-nil, | |
763 kills modified buffers without asking." | |
764 (interactive) | |
765 (if tpu-kill-buffers-silently (set-buffer-modified-p nil)) | |
766 (kill-buffer (current-buffer))) | |
767 | |
768 (defun tpu-save-all-buffers-kill-emacs nil | |
769 "Save all buffers and exit emacs." | |
770 (interactive) | |
771 (setq trim-versions-without-asking t) | |
772 (save-buffers-kill-emacs t)) | |
773 | |
774 (defun tpu-write-current-buffers nil | |
775 "Save all modified buffers without exiting." | |
776 (interactive) | |
777 (save-some-buffers t)) | |
778 | |
779 (defun tpu-next-buffer nil | |
780 "Go to next buffer in ring." | |
781 (interactive) | |
782 (switch-to-buffer (car (reverse (buffer-list))))) | |
783 | |
784 (defun tpu-next-file-buffer nil | |
785 "Go to next buffer in ring that is visiting a file." | |
786 (interactive) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
787 (let ((starting-buffer (buffer-name))) |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
788 (switch-to-buffer (car (reverse (buffer-list)))) |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
789 (while (and (not (equal (buffer-name) starting-buffer)) |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
790 (not (buffer-file-name))) |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
791 (switch-to-buffer (car (reverse (buffer-list))))) |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
792 (if (equal (buffer-name) starting-buffer) (error "No other buffers.")))) |
4421 | 793 |
794 (defun tpu-next-window nil | |
795 "Move to the next window." | |
796 (interactive) | |
797 (if (one-window-p) (message "There is only one window on screen.") | |
798 (other-window 1))) | |
799 | |
800 (defun tpu-previous-window nil | |
801 "Move to the previous window." | |
802 (interactive) | |
803 (if (one-window-p) (message "There is only one window on screen.") | |
804 (select-window (previous-window)))) | |
805 | |
806 | |
807 ;;; | |
808 ;;; Search | |
809 ;;; | |
810 (defun tpu-toggle-regexp nil | |
811 "Switches in and out of regular expression search and replace mode." | |
812 (interactive) | |
813 (setq tpu-regexp-p (not tpu-regexp-p)) | |
814 (tpu-set-search) | |
815 (and (interactive-p) | |
816 (message "Regular expression search and substitute %sabled." | |
817 (if tpu-regexp-p "en" "dis")))) | |
818 | |
819 (defun tpu-regexp-prompt (prompt) | |
820 "Read a string, adding 'RE' to the prompt if tpu-regexp-p is set." | |
821 (let ((re-prompt (concat (if tpu-regexp-p "RE ") prompt))) | |
822 (if tpu-emacs19-p | |
823 (read-from-minibuffer re-prompt nil nil nil 'tpu-regexp-prompt-hist) | |
824 (read-string re-prompt)))) | |
825 | |
826 (defun tpu-search nil | |
827 "Search for a string or regular expression. | |
828 The search is performed in the current direction." | |
829 (interactive) | |
830 (tpu-set-search) | |
831 (tpu-search-internal "")) | |
832 | |
833 (defun tpu-search-forward nil | |
834 "Search for a string or regular expression. | |
835 The search is begins in the forward direction." | |
836 (interactive) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
837 (setq tpu-searching-forward t) |
4421 | 838 (tpu-set-search t) |
839 (tpu-search-internal "")) | |
840 | |
841 (defun tpu-search-reverse nil | |
842 "Search for a string or regular expression. | |
843 The search is begins in the reverse direction." | |
844 (interactive) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
845 (setq tpu-searching-forward nil) |
4421 | 846 (tpu-set-search t) |
847 (tpu-search-internal "")) | |
848 | |
849 (defun tpu-search-again nil | |
850 "Search for the same string or regular expression as last time. | |
851 The search is performed in the current direction." | |
852 (interactive) | |
853 (tpu-search-internal tpu-search-last-string)) | |
854 | |
855 ;; tpu-set-search defines the search functions used by the TPU-edt internal | |
856 ;; search function. It should be called whenever the direction changes, or | |
857 ;; the regular expression mode is turned on or off. It can also be called | |
858 ;; to ensure that the next search will be in the current direction. It is | |
859 ;; called from: | |
860 | |
861 ;; tpu-advance tpu-backup | |
862 ;; tpu-toggle-regexp tpu-toggle-search-direction (t) | |
863 ;; tpu-search tpu-lm-replace | |
864 ;; tpu-search-forward (t) tpu-search-reverse (t) | |
865 | |
866 (defun tpu-set-search (&optional arg) | |
867 "Set the search functions and set the search direction to the current | |
868 direction. If an argument is specified, don't set the search direction." | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
869 (if (not arg) (setq tpu-searching-forward (if tpu-advance t nil))) |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
870 (cond (tpu-searching-forward |
4421 | 871 (cond (tpu-regexp-p |
872 (fset 'tpu-emacs-search 're-search-forward) | |
873 (fset 'tpu-emacs-rev-search 're-search-backward)) | |
874 (t | |
875 (fset 'tpu-emacs-search 'search-forward) | |
876 (fset 'tpu-emacs-rev-search 'search-backward)))) | |
877 (t | |
878 (cond (tpu-regexp-p | |
879 (fset 'tpu-emacs-search 're-search-backward) | |
880 (fset 'tpu-emacs-rev-search 're-search-forward)) | |
881 (t | |
882 (fset 'tpu-emacs-search 'search-backward) | |
883 (fset 'tpu-emacs-rev-search 'search-forward)))))) | |
884 | |
885 (defun tpu-search-internal (pat &optional quiet) | |
886 "Search for a string or regular expression." | |
887 (setq tpu-search-last-string | |
888 (if (not (string= "" pat)) pat (tpu-regexp-prompt "Search: "))) | |
889 | |
890 (tpu-unset-match) | |
891 (tpu-adjust-search) | |
892 | |
893 (cond ((tpu-emacs-search tpu-search-last-string nil t) | |
894 (tpu-set-match) (goto-char (tpu-match-beginning))) | |
895 | |
896 (t | |
897 (tpu-adjust-search t) | |
898 (let ((found nil) (pos nil)) | |
899 (save-excursion | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
900 (let ((tpu-searching-forward (not tpu-searching-forward))) |
4421 | 901 (tpu-adjust-search) |
902 (setq found (tpu-emacs-rev-search tpu-search-last-string nil t)) | |
903 (setq pos (match-beginning 0)))) | |
904 | |
905 (cond (found | |
906 (cond ((tpu-y-or-n-p | |
907 (format "Found in %s direction. Go there? " | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
908 (if tpu-searching-forward "reverse" "forward"))) |
4421 | 909 (goto-char pos) (tpu-set-match) |
910 (tpu-toggle-search-direction)))) | |
911 | |
912 (t | |
913 (if (not quiet) | |
914 (message | |
915 "%sSearch failed: \"%s\"" | |
916 (if tpu-regexp-p "RE " "") tpu-search-last-string)))))))) | |
917 | |
918 (fset 'tpu-search-internal-core (symbol-function 'tpu-search-internal)) | |
919 | |
920 (defun tpu-adjust-search (&optional arg) | |
921 "For forward searches, move forward a character before searching, | |
922 and backward a character after a failed search. Arg means end of search." | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
923 (if tpu-searching-forward |
4421 | 924 (cond (arg (if (not (bobp)) (forward-char -1))) |
925 (t (if (not (eobp)) (forward-char 1)))))) | |
926 | |
927 (defun tpu-toggle-search-direction nil | |
928 "Toggle the TPU-edt search direction. | |
929 Used for reversing a search in progress." | |
930 (interactive) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
931 (setq tpu-searching-forward (not tpu-searching-forward)) |
4421 | 932 (tpu-set-search t) |
933 (and (interactive-p) | |
934 (message "Searching %sward." | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
935 (if tpu-searching-forward "for" "back")))) |
4421 | 936 |
937 | |
938 ;;; | |
939 ;;; Select / Unselect | |
940 ;;; | |
941 (defun tpu-select (&optional quiet) | |
942 "Sets the mark to define one end of a region." | |
943 (interactive "P") | |
944 (cond ((tpu-mark) | |
945 (tpu-unselect quiet)) | |
946 (t | |
947 (tpu-set-mark (point)) | |
948 (tpu-update-mode-line) | |
949 (if (not quiet) (message "Move the text cursor to select text."))))) | |
950 | |
951 (defun tpu-unselect (&optional quiet) | |
952 "Removes the mark to unselect the current region." | |
953 (interactive "P") | |
954 (setq mark-ring nil) | |
955 (tpu-set-mark nil) | |
956 (tpu-update-mode-line) | |
957 (if (not quiet) (message "Selection canceled."))) | |
958 | |
959 | |
960 ;;; | |
961 ;;; Delete / Cut | |
962 ;;; | |
963 (defun tpu-toggle-rectangle nil | |
964 "Toggle rectangular mode for remove and insert." | |
965 (interactive) | |
966 (setq tpu-rectangular-p (not tpu-rectangular-p)) | |
967 (setq tpu-rectangle-string (if tpu-rectangular-p " Rect" "")) | |
968 (tpu-update-mode-line) | |
969 (and (interactive-p) | |
970 (message "Rectangular cut and paste %sabled." | |
971 (if tpu-rectangular-p "en" "dis")))) | |
972 | |
973 (defun tpu-arrange-rectangle nil | |
974 "Adjust point and mark to mark upper left and lower right | |
975 corners of a rectangle." | |
976 (let ((mc (current-column)) | |
977 (pc (progn (exchange-point-and-mark) (current-column)))) | |
978 | |
979 (cond ((> (point) (tpu-mark)) ; point on lower line | |
980 (cond ((> pc mc) ; point @ lower-right | |
981 (exchange-point-and-mark)) ; point -> upper-left | |
982 | |
983 (t ; point @ lower-left | |
984 (move-to-column-force mc) ; point -> lower-right | |
985 (exchange-point-and-mark) ; point -> upper-right | |
986 (move-to-column-force pc)))) ; point -> upper-left | |
987 | |
988 (t ; point on upper line | |
989 (cond ((> pc mc) ; point @ upper-right | |
990 (move-to-column-force mc) ; point -> upper-left | |
991 (exchange-point-and-mark) ; point -> lower-left | |
992 (move-to-column-force pc) ; point -> lower-right | |
993 (exchange-point-and-mark))))))) ; point -> upper-left | |
994 | |
995 (defun tpu-cut-text nil | |
996 "Delete the selected region. | |
997 The text is saved for the tpu-paste command." | |
998 (interactive) | |
999 (cond ((tpu-mark) | |
1000 (cond (tpu-rectangular-p | |
1001 (tpu-arrange-rectangle) | |
1002 (picture-clear-rectangle (point) (tpu-mark) (not overwrite-mode)) | |
1003 (tpu-unselect t)) | |
1004 (t | |
1005 (setq tpu-last-deleted-region | |
1006 (buffer-substring (tpu-mark) (point))) | |
1007 (delete-region (tpu-mark) (point)) | |
1008 (tpu-unselect t)))) | |
1009 ((tpu-check-match) | |
1010 (let ((beg (tpu-match-beginning)) (end (tpu-match-end))) | |
1011 (setq tpu-last-deleted-region (buffer-substring beg end)) | |
1012 (delete-region beg end) | |
1013 (tpu-unset-match))) | |
1014 (t | |
1015 (error "No selection active.")))) | |
1016 | |
1017 (defun tpu-store-text nil | |
1018 "Copy the selected region to the cut buffer without deleting it. | |
1019 The text is saved for the tpu-paste command." | |
1020 (interactive) | |
1021 (cond ((tpu-mark) | |
1022 (cond (tpu-rectangular-p | |
1023 (save-excursion | |
1024 (tpu-arrange-rectangle) | |
1025 (setq picture-killed-rectangle | |
1026 (extract-rectangle (point) (tpu-mark)))) | |
1027 (tpu-unselect t)) | |
1028 (t | |
1029 (setq tpu-last-deleted-region | |
1030 (buffer-substring (tpu-mark) (point))) | |
1031 (tpu-unselect t)))) | |
1032 ((tpu-check-match) | |
1033 (setq tpu-last-deleted-region | |
1034 (buffer-substring (tpu-match-beginning) (tpu-match-end))) | |
1035 (tpu-unset-match)) | |
1036 (t | |
1037 (error "No selection active.")))) | |
1038 | |
1039 (defun tpu-cut (arg) | |
1040 "Copy selected region to the cut buffer. In the absence of an | |
1041 argument, delete the selected region too." | |
1042 (interactive "P") | |
1043 (if arg (tpu-store-text) (tpu-cut-text))) | |
1044 | |
1045 (defun tpu-append-region (arg) | |
1046 "Append selected region to the tpu-cut buffer. In the absence of an | |
1047 argument, delete the selected region too." | |
1048 (interactive "P") | |
1049 (cond ((tpu-mark) | |
1050 (let ((beg (region-beginning)) (end (region-end))) | |
1051 (setq tpu-last-deleted-region | |
1052 (concat tpu-last-deleted-region | |
1053 (buffer-substring beg end))) | |
1054 (if (not arg) (delete-region beg end)) | |
1055 (tpu-unselect t))) | |
1056 ((tpu-check-match) | |
1057 (let ((beg (tpu-match-beginning)) (end (tpu-match-end))) | |
1058 (setq tpu-last-deleted-region | |
1059 (concat tpu-last-deleted-region | |
1060 (buffer-substring beg end))) | |
1061 (if (not arg) (delete-region beg end)) | |
1062 (tpu-unset-match))) | |
1063 (t | |
1064 (error "No selection active.")))) | |
1065 | |
1066 (defun tpu-delete-current-line (num) | |
1067 "Delete one or specified number of lines after point. | |
1068 This includes the newline character at the end of each line. | |
1069 They are saved for the TPU-edt undelete-lines command." | |
1070 (interactive "p") | |
1071 (let ((beg (point))) | |
1072 (forward-line num) | |
1073 (if (not (eq (preceding-char) ?\n)) | |
1074 (insert "\n")) | |
1075 (setq tpu-last-deleted-lines | |
1076 (buffer-substring beg (point))) | |
1077 (delete-region beg (point)))) | |
1078 | |
1079 (defun tpu-delete-to-eol (num) | |
1080 "Delete text up to end of line. | |
1081 With argument, delete up to to Nth line-end past point. | |
1082 They are saved for the TPU-edt undelete-lines command." | |
1083 (interactive "p") | |
1084 (let ((beg (point))) | |
1085 (forward-char 1) | |
1086 (end-of-line num) | |
1087 (setq tpu-last-deleted-lines | |
1088 (buffer-substring beg (point))) | |
1089 (delete-region beg (point)))) | |
1090 | |
1091 (defun tpu-delete-to-bol (num) | |
1092 "Delete text back to beginning of line. | |
1093 With argument, delete up to to Nth line-end past point. | |
1094 They are saved for the TPU-edt undelete-lines command." | |
1095 (interactive "p") | |
1096 (let ((beg (point))) | |
1097 (tpu-next-beginning-of-line num) | |
1098 (setq tpu-last-deleted-lines | |
1099 (buffer-substring (point) beg)) | |
1100 (delete-region (point) beg))) | |
1101 | |
1102 (defun tpu-delete-current-word (num) | |
1103 "Delete one or specified number of words after point. | |
1104 They are saved for the TPU-edt undelete-words command." | |
1105 (interactive "p") | |
1106 (let ((beg (point))) | |
1107 (tpu-forward-to-word num) | |
1108 (setq tpu-last-deleted-words | |
1109 (buffer-substring beg (point))) | |
1110 (delete-region beg (point)))) | |
1111 | |
1112 (defun tpu-delete-previous-word (num) | |
1113 "Delete one or specified number of words before point. | |
1114 They are saved for the TPU-edt undelete-words command." | |
1115 (interactive "p") | |
1116 (let ((beg (point))) | |
1117 (tpu-backward-to-word num) | |
1118 (setq tpu-last-deleted-words | |
1119 (buffer-substring (point) beg)) | |
1120 (delete-region beg (point)))) | |
1121 | |
1122 (defun tpu-delete-current-char (num) | |
1123 "Delete one or specified number of characters after point. The last | |
1124 character deleted is saved for the TPU-edt undelete-char command." | |
1125 (interactive "p") | |
1126 (while (and (> num 0) (not (eobp))) | |
1127 (setq tpu-last-deleted-char (char-after (point))) | |
1128 (cond (overwrite-mode | |
1129 (picture-clear-column 1) | |
1130 (forward-char 1)) | |
1131 (t | |
1132 (delete-char 1))) | |
1133 (setq num (1- num)))) | |
1134 | |
1135 | |
1136 ;;; | |
1137 ;;; Undelete / Paste | |
1138 ;;; | |
1139 (defun tpu-paste (num) | |
1140 "Insert the last region or rectangle of killed text. | |
1141 With argument reinserts the text that many times." | |
1142 (interactive "p") | |
1143 (while (> num 0) | |
1144 (cond (tpu-rectangular-p | |
1145 (let ((beg (point))) | |
1146 (save-excursion | |
1147 (picture-yank-rectangle (not overwrite-mode)) | |
1148 (message "")) | |
1149 (goto-char beg))) | |
1150 (t | |
1151 (insert tpu-last-deleted-region))) | |
1152 (setq num (1- num)))) | |
1153 | |
1154 (defun tpu-undelete-lines (num) | |
1155 "Insert lines deleted by last TPU-edt line-deletion command. | |
1156 With argument reinserts lines that many times." | |
1157 (interactive "p") | |
1158 (let ((beg (point))) | |
1159 (while (> num 0) | |
1160 (insert tpu-last-deleted-lines) | |
1161 (setq num (1- num))) | |
1162 (goto-char beg))) | |
1163 | |
1164 (defun tpu-undelete-words (num) | |
1165 "Insert words deleted by last TPU-edt word-deletion command. | |
1166 With argument reinserts words that many times." | |
1167 (interactive "p") | |
1168 (let ((beg (point))) | |
1169 (while (> num 0) | |
1170 (insert tpu-last-deleted-words) | |
1171 (setq num (1- num))) | |
1172 (goto-char beg))) | |
1173 | |
1174 (defun tpu-undelete-char (num) | |
1175 "Insert character deleted by last TPU-edt character-deletion command. | |
1176 With argument reinserts the character that many times." | |
1177 (interactive "p") | |
1178 (while (> num 0) | |
1179 (if overwrite-mode (prog1 (forward-char -1) (delete-char 1))) | |
1180 (insert tpu-last-deleted-char) | |
1181 (forward-char -1) | |
1182 (setq num (1- num)))) | |
1183 | |
1184 | |
1185 ;;; | |
1186 ;;; Replace and Substitute | |
1187 ;;; | |
1188 (defun tpu-replace nil | |
1189 "Replace the selected region with the contents of the cut buffer." | |
1190 (interactive) | |
1191 (cond ((tpu-mark) | |
1192 (let ((beg (region-beginning)) (end (region-end))) | |
1193 (setq tpu-last-replaced-text (buffer-substring beg end)) | |
1194 (delete-region beg end) | |
1195 (insert tpu-last-deleted-region) | |
1196 (tpu-unselect t))) | |
1197 ((tpu-check-match) | |
1198 (let ((beg (tpu-match-beginning)) (end (tpu-match-end))) | |
1199 (setq tpu-last-replaced-text (buffer-substring beg end)) | |
1200 (replace-match tpu-last-deleted-region | |
1201 (not case-replace) (not tpu-regexp-p)) | |
1202 (tpu-unset-match))) | |
1203 (t | |
1204 (error "No selection active.")))) | |
1205 | |
1206 (defun tpu-substitute (num) | |
1207 "Replace the selected region with the contents of the cut buffer, and | |
1208 repeat most recent search. A numeric argument serves as a repeat count. | |
1209 A negative argument means replace all occurrences of the search string." | |
1210 (interactive "p") | |
1211 (cond ((or (tpu-mark) (tpu-check-match)) | |
1212 (while (and (not (= num 0)) (or (tpu-mark) (tpu-check-match))) | |
1213 (let ((beg (point))) | |
1214 (tpu-replace) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
1215 (if tpu-searching-forward (forward-char -1) (goto-char beg)) |
4421 | 1216 (if (= num 1) (tpu-search-internal tpu-search-last-string) |
1217 (tpu-search-internal-core tpu-search-last-string))) | |
1218 (setq num (1- num)))) | |
1219 (t | |
1220 (error "No selection active.")))) | |
1221 | |
1222 (defun tpu-lm-replace (from to) | |
1223 "Interactively search for OLD-string and substitute NEW-string." | |
1224 (interactive (list (tpu-regexp-prompt "Old String: ") | |
1225 (tpu-regexp-prompt "New String: "))) | |
1226 | |
1227 (let ((doit t) (strings 0)) | |
1228 | |
1229 ;; Can't replace null strings | |
1230 (if (string= "" from) (error "No string to replace.")) | |
1231 | |
1232 ;; Find the first occurrence | |
1233 (tpu-set-search) | |
1234 (tpu-search-internal from t) | |
1235 | |
1236 ;; Loop on replace question - yes, no, all, last, or quit. | |
1237 (while doit | |
1238 (if (not (tpu-check-match)) (setq doit nil) | |
1239 (progn (message "Replace? Type Yes, No, All, Last, or Quit: ") | |
1240 (let ((ans (read-char))) | |
1241 | |
1242 (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\r) (= ans ?\ )) | |
1243 (let ((beg (point))) | |
1244 (replace-match to (not case-replace) (not tpu-regexp-p)) | |
1245 (setq strings (1+ strings)) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
1246 (if tpu-searching-forward (forward-char -1) (goto-char beg))) |
4421 | 1247 (tpu-search-internal from t)) |
1248 | |
1249 ((or (= ans ?n) (= ans ?N) (= ans ?\C-?)) | |
1250 (tpu-search-internal from t)) | |
1251 | |
1252 ((or (= ans ?a) (= ans ?A)) | |
1253 (save-excursion | |
1254 (let ((beg (point))) | |
1255 (replace-match to (not case-replace) (not tpu-regexp-p)) | |
1256 (setq strings (1+ strings)) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
1257 (if tpu-searching-forward (forward-char -1) (goto-char beg))) |
4421 | 1258 (tpu-search-internal-core from t) |
1259 (while (tpu-check-match) | |
1260 (let ((beg (point))) | |
1261 (replace-match to (not case-replace) (not tpu-regexp-p)) | |
1262 (setq strings (1+ strings)) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
1263 (if tpu-searching-forward (forward-char -1) (goto-char beg))) |
4421 | 1264 (tpu-search-internal-core from t))) |
1265 (setq doit nil)) | |
1266 | |
1267 ((or (= ans ?l) (= ans ?L)) | |
1268 (let ((beg (point))) | |
1269 (replace-match to (not case-replace) (not tpu-regexp-p)) | |
1270 (setq strings (1+ strings)) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
1271 (if tpu-searching-forward (forward-char -1) (goto-char beg))) |
4421 | 1272 (setq doit nil)) |
1273 | |
1274 ((or (= ans ?q) (= ans ?Q)) | |
1275 (setq doit nil))))))) | |
1276 | |
1277 (message "Replaced %s occurrence%s." strings | |
1278 (if (not (= 1 strings)) "s" "")))) | |
1279 | |
1280 (defun tpu-emacs-replace (&optional dont-ask) | |
1281 "A TPU-edt interface to the emacs replace functions. If TPU-edt is | |
1282 currently in regular expression mode, the emacs regular expression | |
1283 replace functions are used. If an argument is supplied, replacements | |
1284 are performed without asking. Only works in forward direction." | |
1285 (interactive "P") | |
1286 (cond (dont-ask | |
1287 (setq current-prefix-arg nil) | |
1288 (call-interactively | |
1289 (if tpu-regexp-p 'replace-regexp 'replace-string))) | |
1290 (t | |
1291 (call-interactively | |
1292 (if tpu-regexp-p 'query-replace-regexp 'query-replace))))) | |
1293 | |
1294 (defun tpu-add-at-bol (text) | |
1295 "Add text to the beginning of each line in a region, | |
1296 or each line in the entire buffer if no region is selected." | |
1297 (interactive | |
1298 (list (tpu-string-prompt "String to add: " 'tpu-add-at-bol-hist))) | |
1299 (if (string= "" text) (error "No string specified.")) | |
1300 (cond ((tpu-mark) | |
1301 (save-excursion | |
1302 (if (> (point) (tpu-mark)) (exchange-point-and-mark)) | |
1303 (while (and (< (point) (tpu-mark)) (re-search-forward "^" (tpu-mark) t)) | |
1304 (if (< (point) (tpu-mark)) (replace-match text)))) | |
1305 (tpu-unselect t)) | |
1306 (t | |
1307 (save-excursion | |
1308 (goto-char (point-min)) | |
1309 (while (and (re-search-forward "^" nil t) (not (eobp))) | |
1310 (replace-match text)))))) | |
1311 | |
1312 (defun tpu-add-at-eol (text) | |
1313 "Add text to the end of each line in a region, | |
1314 or each line of the entire buffer if no region is selected." | |
1315 (interactive | |
1316 (list (tpu-string-prompt "String to add: " 'tpu-add-at-eol-hist))) | |
1317 (if (string= "" text) (error "No string specified.")) | |
1318 (cond ((tpu-mark) | |
1319 (save-excursion | |
1320 (if (> (point) (tpu-mark)) (exchange-point-and-mark)) | |
1321 (while (< (point) (tpu-mark)) | |
1322 (end-of-line) | |
1323 (if (<= (point) (tpu-mark)) (insert text)) | |
1324 (forward-line))) | |
1325 (tpu-unselect t)) | |
1326 (t | |
1327 (save-excursion | |
1328 (goto-char (point-min)) | |
1329 (while (not (eobp)) | |
1330 (end-of-line) (insert text) (forward-line)))))) | |
1331 | |
1332 (defun tpu-trim-line-ends nil | |
1333 "Removes trailing whitespace from every line in the buffer." | |
1334 (interactive) | |
1335 (picture-clean)) | |
1336 | |
1337 | |
1338 ;;; | |
1339 ;;; Movement by character | |
1340 ;;; | |
1341 (defun tpu-char (num) | |
1342 "Move to the next character in the current direction. | |
1343 A repeat count means move that many characters." | |
1344 (interactive "p") | |
1345 (if tpu-advance (tpu-forward-char num) (tpu-backward-char num))) | |
1346 | |
1347 (defun tpu-forward-char (num) | |
1348 "Move right ARG characters (left if ARG is negative)." | |
1349 (interactive "p") | |
1350 (forward-char num)) | |
1351 | |
1352 (defun tpu-backward-char (num) | |
1353 "Move left ARG characters (right if ARG is negative)." | |
1354 (interactive "p") | |
1355 (backward-char num)) | |
1356 | |
1357 | |
1358 ;;; | |
1359 ;;; Movement by word | |
1360 ;;; | |
1361 (defconst tpu-word-separator-list '() | |
1362 "List of additional word separators.") | |
1363 (defconst tpu-skip-chars "^ \t" | |
1364 "Characters to skip when moving by word. | |
1365 Additional word separators are added to this string.") | |
1366 | |
1367 (defun tpu-word (num) | |
1368 "Move to the beginning of the next word in the current direction. | |
1369 A repeat count means move that many words." | |
1370 (interactive "p") | |
1371 (if tpu-advance (tpu-forward-to-word num) (tpu-backward-to-word num))) | |
1372 | |
1373 (defun tpu-forward-to-word (num) | |
1374 "Move forward until encountering the beginning of a word. | |
1375 With argument, do this that many times." | |
1376 (interactive "p") | |
1377 (while (and (> num 0) (not (eobp))) | |
1378 (let* ((beg (point)) | |
1379 (end (prog2 (end-of-line) (point) (goto-char beg)))) | |
1380 (cond ((eolp) | |
1381 (forward-char 1)) | |
1382 ((memq (char-after (point)) tpu-word-separator-list) | |
1383 (forward-char 1) | |
1384 (skip-chars-forward " \t" end)) | |
1385 (t | |
1386 (skip-chars-forward tpu-skip-chars end) | |
1387 (skip-chars-forward " \t" end)))) | |
1388 (setq num (1- num)))) | |
1389 | |
1390 (defun tpu-backward-to-word (num) | |
1391 "Move backward until encountering the beginning of a word. | |
1392 With argument, do this that many times." | |
1393 (interactive "p") | |
1394 (while (and (> num 0) (not (bobp))) | |
1395 (let* ((beg (point)) | |
1396 (end (prog2 (beginning-of-line) (point) (goto-char beg)))) | |
1397 (cond ((bolp) | |
1398 ( forward-char -1)) | |
1399 ((memq (char-after (1- (point))) tpu-word-separator-list) | |
1400 (forward-char -1)) | |
1401 (t | |
1402 (skip-chars-backward " \t" end) | |
1403 (skip-chars-backward tpu-skip-chars end) | |
1404 (if (and (not (bolp)) (= ? (char-syntax (char-after (point))))) | |
1405 (forward-char -1))))) | |
1406 (setq num (1- num)))) | |
1407 | |
1408 (defun tpu-add-word-separators (separators) | |
1409 "Add new word separators for TPU-edt word commands." | |
1410 (interactive "sSeparators: ") | |
1411 (let* ((n 0) (length (length separators))) | |
1412 (while (< n length) | |
1413 (let ((char (aref separators n)) | |
1414 (ss (substring separators n (1+ n)))) | |
1415 (cond ((not (memq char tpu-word-separator-list)) | |
1416 (setq tpu-word-separator-list | |
1417 (append ss tpu-word-separator-list)) | |
1418 (cond ((= char ?-) | |
1419 (setq tpu-skip-chars (concat tpu-skip-chars "\\-"))) | |
1420 ((= char ?\\) | |
1421 (setq tpu-skip-chars (concat tpu-skip-chars "\\\\"))) | |
1422 ((= char ?^) | |
1423 (setq tpu-skip-chars (concat tpu-skip-chars "\\^"))) | |
1424 (t | |
1425 (setq tpu-skip-chars (concat tpu-skip-chars ss)))))) | |
1426 (setq n (1+ n)))))) | |
1427 | |
1428 (defun tpu-reset-word-separators nil | |
1429 "Reset word separators to default value." | |
1430 (interactive) | |
1431 (setq tpu-word-separator-list nil) | |
1432 (setq tpu-skip-chars "^ \t")) | |
1433 | |
1434 (defun tpu-set-word-separators (separators) | |
1435 "Set new word separators for TPU-edt word commands." | |
1436 (interactive "sSeparators: ") | |
1437 (tpu-reset-word-separators) | |
1438 (tpu-add-word-separators separators)) | |
1439 | |
1440 | |
1441 ;;; | |
1442 ;;; Movement by line | |
1443 ;;; | |
1444 (defun tpu-next-line (num) | |
1445 "Move to next line. | |
1446 Prefix argument serves as a repeat count." | |
1447 (interactive "p") | |
1448 (next-line-internal num) | |
1449 (setq this-command 'next-line)) | |
1450 | |
1451 (defun tpu-previous-line (num) | |
1452 "Move to previous line. | |
1453 Prefix argument serves as a repeat count." | |
1454 (interactive "p") | |
1455 (next-line-internal (- num)) | |
1456 (setq this-command 'previous-line)) | |
1457 | |
1458 (defun tpu-next-beginning-of-line (num) | |
1459 "Move to beginning of line; if at beginning, move to beginning of next line. | |
1460 Accepts a prefix argument for the number of lines to move." | |
1461 (interactive "p") | |
1462 (backward-char 1) | |
1463 (forward-line (- 1 num))) | |
1464 | |
1465 (defun tpu-end-of-line (num) | |
1466 "Move to the next end of line in the current direction. | |
1467 A repeat count means move that many lines." | |
1468 (interactive "p") | |
1469 (if tpu-advance (tpu-next-end-of-line num) (tpu-previous-end-of-line num))) | |
1470 | |
1471 (defun tpu-next-end-of-line (num) | |
1472 "Move to end of line; if at end, move to end of next line. | |
1473 Accepts a prefix argument for the number of lines to move." | |
1474 (interactive "p") | |
1475 (forward-char 1) | |
1476 (end-of-line num)) | |
1477 | |
1478 (defun tpu-previous-end-of-line (num) | |
1479 "Move EOL upward. | |
1480 Accepts a prefix argument for the number of lines to move." | |
1481 (interactive "p") | |
1482 (end-of-line (- 1 num))) | |
1483 | |
1484 (defun tpu-current-end-of-line nil | |
1485 "Move point to end of current line." | |
1486 (interactive) | |
1487 (let ((beg (point))) | |
1488 (end-of-line) | |
1489 (if (= beg (point)) (message "You are already at the end of a line.")))) | |
1490 | |
1491 (defun tpu-line (num) | |
1492 "Move to the beginning of the next line in the current direction. | |
1493 A repeat count means move that many lines." | |
1494 (interactive "p") | |
1495 (if tpu-advance (tpu-forward-line num) (tpu-backward-line num))) | |
1496 | |
1497 (defun tpu-forward-line (num) | |
1498 "Move to beginning of next line. | |
1499 Prefix argument serves as a repeat count." | |
1500 (interactive "p") | |
1501 (forward-line num)) | |
1502 | |
1503 (defun tpu-backward-line (num) | |
1504 "Move to beginning of previous line. | |
1505 Prefix argument serves as repeat count." | |
1506 (interactive "p") | |
1507 (forward-line (- num))) | |
1508 | |
1509 | |
1510 ;;; | |
1511 ;;; Movement by paragraph | |
1512 ;;; | |
1513 (defun tpu-paragraph (num) | |
1514 "Move to the next paragraph in the current direction. | |
1515 A repeat count means move that many paragraphs." | |
1516 (interactive "p") | |
1517 (if tpu-advance | |
1518 (tpu-next-paragraph num) (tpu-previous-paragraph num))) | |
1519 | |
1520 (defun tpu-next-paragraph (num) | |
1521 "Move to beginning of the next paragraph. | |
1522 Accepts a prefix argument for the number of paragraphs." | |
1523 (interactive "p") | |
1524 (beginning-of-line) | |
1525 (while (and (not (eobp)) (> num 0)) | |
1526 (if (re-search-forward "^[ \t]*$" nil t) | |
1527 (if (re-search-forward "[^ \t\n]" nil t) | |
1528 (goto-char (match-beginning 0)) | |
1529 (goto-char (point-max)))) | |
1530 (setq num (1- num))) | |
1531 (beginning-of-line)) | |
1532 | |
1533 | |
1534 (defun tpu-previous-paragraph (num) | |
1535 "Move to beginning of previous paragraph. | |
1536 Accepts a prefix argument for the number of paragraphs." | |
1537 (interactive "p") | |
1538 (end-of-line) | |
1539 (while (and (not (bobp)) (> num 0)) | |
1540 (if (not (and (re-search-backward "^[ \t]*$" nil t) | |
1541 (re-search-backward "[^ \t\n]" nil t) | |
1542 (re-search-backward "^[ \t]*$" nil t) | |
1543 (progn (re-search-forward "[^ \t\n]" nil t) | |
1544 (goto-char (match-beginning 0))))) | |
1545 (goto-char (point-min))) | |
1546 (setq num (1- num))) | |
1547 (beginning-of-line)) | |
1548 | |
1549 | |
1550 ;;; | |
1551 ;;; Movement by page | |
1552 ;;; | |
1553 (defun tpu-page (num) | |
1554 "Move to the next page in the current direction. | |
1555 A repeat count means move that many pages." | |
1556 (interactive "p") | |
1557 (if tpu-advance (forward-page num) (backward-page num)) | |
1558 (if (eobp) (recenter -1))) | |
1559 | |
1560 | |
1561 ;;; | |
1562 ;;; Scrolling and movement within the buffer | |
1563 ;;; | |
1564 (defun tpu-scroll-window (num) | |
1565 "Scroll the display to the next section in the current direction. | |
1566 A repeat count means scroll that many sections." | |
1567 (interactive "p") | |
1568 (if tpu-advance (tpu-scroll-window-up num) (tpu-scroll-window-down num))) | |
1569 | |
1570 (defun tpu-scroll-window-down (num) | |
1571 "Scroll the display down to the next section. | |
1572 A repeat count means scroll that many sections." | |
1573 (interactive "p") | |
1574 (let* ((beg (tpu-current-line)) | |
1575 (height (1- (window-height))) | |
1576 (lines (* num (/ (* height tpu-percent-scroll) 100)))) | |
1577 (next-line-internal (- lines)) | |
1578 (if (> lines beg) (recenter 0)))) | |
1579 | |
1580 (defun tpu-scroll-window-up (num) | |
1581 "Scroll the display up to the next section. | |
1582 A repeat count means scroll that many sections." | |
1583 (interactive "p") | |
1584 (let* ((beg (tpu-current-line)) | |
1585 (height (1- (window-height))) | |
1586 (lines (* num (/ (* height tpu-percent-scroll) 100)))) | |
1587 (next-line-internal lines) | |
1588 (if (>= (+ lines beg) height) (recenter -1)))) | |
1589 | |
1590 (defun tpu-pan-right (num) | |
1591 "Pan right tpu-pan-columns (16 by default). | |
1592 Accepts a prefix argument for the number of tpu-pan-columns to scroll." | |
1593 (interactive "p") | |
1594 (scroll-left (* tpu-pan-columns num))) | |
1595 | |
1596 (defun tpu-pan-left (num) | |
1597 "Pan left tpu-pan-columns (16 by default). | |
1598 Accepts a prefix argument for the number of tpu-pan-columns to scroll." | |
1599 (interactive "p") | |
1600 (scroll-right (* tpu-pan-columns num))) | |
1601 | |
1602 (defun tpu-move-to-beginning nil | |
1603 "Move cursor to the beginning of buffer, but don't set the mark." | |
1604 (interactive) | |
1605 (goto-char (point-min))) | |
1606 | |
1607 (defun tpu-move-to-end nil | |
1608 "Move cursor to the end of buffer, but don't set the mark." | |
1609 (interactive) | |
1610 (goto-char (point-max)) | |
1611 (recenter -1)) | |
1612 | |
1613 (defun tpu-goto-percent (perc) | |
1614 "Move point to ARG percentage of the buffer." | |
1615 (interactive "NGoto-percentage: ") | |
1616 (if (or (> perc 100) (< perc 0)) | |
1617 (error "Percentage %d out of range 0 < percent < 100" perc) | |
1618 (goto-char (/ (* (point-max) perc) 100)))) | |
1619 | |
1620 (defun tpu-beginning-of-window nil | |
1621 "Move cursor to top of window." | |
1622 (interactive) | |
1623 (move-to-window-line 0)) | |
1624 | |
1625 (defun tpu-end-of-window nil | |
1626 "Move cursor to bottom of window." | |
1627 (interactive) | |
1628 (move-to-window-line -1)) | |
1629 | |
1630 (defun tpu-line-to-bottom-of-window nil | |
1631 "Move the current line to the bottom of the window." | |
1632 (interactive) | |
1633 (recenter -1)) | |
1634 | |
1635 (defun tpu-line-to-top-of-window nil | |
1636 "Move the current line to the top of the window." | |
1637 (interactive) | |
1638 (recenter 0)) | |
1639 | |
1640 | |
1641 ;;; | |
1642 ;;; Direction | |
1643 ;;; | |
1644 (defun tpu-advance-direction nil | |
1645 "Set TPU Advance mode so keypad commands move forward." | |
1646 (interactive) | |
1647 (setq tpu-direction-string " Advance") | |
1648 (setq tpu-advance t) | |
1649 (setq tpu-reverse nil) | |
1650 (tpu-set-search) | |
1651 (tpu-update-mode-line)) | |
1652 | |
1653 (defun tpu-backup-direction nil | |
1654 "Set TPU Backup mode so keypad commands move backward." | |
1655 (interactive) | |
1656 (setq tpu-direction-string " Reverse") | |
1657 (setq tpu-advance nil) | |
1658 (setq tpu-reverse t) | |
1659 (tpu-set-search) | |
1660 (tpu-update-mode-line)) | |
1661 | |
1662 | |
1663 ;;; | |
1664 ;;; Define keymaps | |
1665 ;;; | |
1666 (define-key global-map "\e[" CSI-map) ; CSI map | |
1667 (define-key global-map "\eO" SS3-map) ; SS3 map | |
1668 (define-key SS3-map "P" GOLD-map) ; GOLD map | |
1669 (define-key GOLD-map "\e[" GOLD-CSI-map) ; GOLD-CSI map | |
1670 (define-key GOLD-map "\eO" GOLD-SS3-map) ; GOLD-SS3 map | |
1671 | |
1672 | |
1673 ;;; | |
1674 ;;; CSI-map key definitions | |
1675 ;;; | |
1676 (define-key CSI-map "A" 'tpu-previous-line) ; up | |
1677 (define-key CSI-map "B" 'tpu-next-line) ; down | |
1678 (define-key CSI-map "D" 'tpu-backward-char) ; left | |
1679 (define-key CSI-map "C" 'tpu-forward-char) ; right | |
1680 | |
1681 (define-key CSI-map "1~" 'tpu-search) ; Find | |
1682 (define-key CSI-map "2~" 'tpu-paste) ; Insert Here | |
1683 (define-key CSI-map "3~" 'tpu-cut) ; Remove | |
1684 (define-key CSI-map "4~" 'tpu-select) ; Select | |
1685 (define-key CSI-map "5~" 'tpu-scroll-window-down) ; Prev Screen | |
1686 (define-key CSI-map "6~" 'tpu-scroll-window-up) ; Next Screen | |
1687 | |
1688 (define-key CSI-map "11~" 'nil) ; F1 | |
1689 (define-key CSI-map "12~" 'nil) ; F2 | |
1690 (define-key CSI-map "13~" 'nil) ; F3 | |
1691 (define-key CSI-map "14~" 'nil) ; F4 | |
1692 (define-key CSI-map "15~" 'nil) ; F5 | |
1693 (define-key CSI-map "17~" 'nil) ; F6 | |
1694 (define-key CSI-map "18~" 'nil) ; F7 | |
1695 (define-key CSI-map "19~" 'nil) ; F8 | |
1696 (define-key CSI-map "20~" 'nil) ; F9 | |
1697 (define-key CSI-map "21~" 'tpu-exit) ; F10 | |
1698 (define-key CSI-map "23~" 'tpu-insert-escape) ; F11 (ESC) | |
1699 (define-key CSI-map "24~" 'tpu-next-beginning-of-line) ; F12 (BS) | |
1700 (define-key CSI-map "25~" 'tpu-delete-previous-word) ; F13 (LF) | |
1701 (define-key CSI-map "26~" 'tpu-toggle-overwrite-mode) ; F14 | |
1702 (define-key CSI-map "28~" 'tpu-help) ; HELP | |
1703 (define-key CSI-map "29~" 'execute-extended-command) ; DO | |
1704 (define-key CSI-map "31~" 'tpu-goto-breadcrumb) ; F17 | |
1705 (define-key CSI-map "32~" 'nil) ; F18 | |
1706 (define-key CSI-map "33~" 'nil) ; F19 | |
1707 (define-key CSI-map "34~" 'nil) ; F20 | |
1708 | |
1709 | |
1710 ;;; | |
1711 ;;; SS3-map key definitions | |
1712 ;;; | |
1713 (define-key SS3-map "A" 'tpu-previous-line) ; up | |
1714 (define-key SS3-map "B" 'tpu-next-line) ; down | |
1715 (define-key SS3-map "C" 'tpu-forward-char) ; right | |
1716 (define-key SS3-map "D" 'tpu-backward-char) ; left | |
1717 | |
1718 (define-key SS3-map "Q" 'tpu-help) ; PF2 | |
1719 (define-key SS3-map "R" 'tpu-search-again) ; PF3 | |
1720 (define-key SS3-map "S" 'tpu-delete-current-line) ; PF4 | |
1721 (define-key SS3-map "p" 'tpu-line) ; KP0 | |
1722 (define-key SS3-map "q" 'tpu-word) ; KP1 | |
1723 (define-key SS3-map "r" 'tpu-end-of-line) ; KP2 | |
1724 (define-key SS3-map "s" 'tpu-char) ; KP3 | |
1725 (define-key SS3-map "t" 'tpu-advance-direction) ; KP4 | |
1726 (define-key SS3-map "u" 'tpu-backup-direction) ; KP5 | |
1727 (define-key SS3-map "v" 'tpu-cut) ; KP6 | |
1728 (define-key SS3-map "w" 'tpu-page) ; KP7 | |
1729 (define-key SS3-map "x" 'tpu-scroll-window) ; KP8 | |
1730 (define-key SS3-map "y" 'tpu-append-region) ; KP9 | |
1731 (define-key SS3-map "m" 'tpu-delete-current-word) ; KP- | |
1732 (define-key SS3-map "l" 'tpu-delete-current-char) ; KP, | |
1733 (define-key SS3-map "n" 'tpu-select) ; KP. | |
1734 (define-key SS3-map "M" 'newline) ; KPenter | |
1735 | |
1736 | |
1737 ;;; | |
1738 ;;; GOLD-map key definitions | |
1739 ;;; | |
1740 (define-key GOLD-map "\C-A" 'tpu-toggle-overwrite-mode) ; ^A | |
1741 (define-key GOLD-map "\C-B" 'nil) ; ^B | |
1742 (define-key GOLD-map "\C-C" 'nil) ; ^C | |
1743 (define-key GOLD-map "\C-D" 'nil) ; ^D | |
1744 (define-key GOLD-map "\C-E" 'nil) ; ^E | |
1745 (define-key GOLD-map "\C-F" 'set-visited-file-name) ; ^F | |
1746 (define-key GOLD-map "\C-g" 'keyboard-quit) ; safety first | |
1747 (define-key GOLD-map "\C-h" 'delete-other-windows) ; BS | |
1748 (define-key GOLD-map "\C-i" 'other-window) ; TAB | |
1749 (define-key GOLD-map "\C-J" 'nil) ; ^J | |
1750 (define-key GOLD-map "\C-K" 'tpu-define-macro-key) ; ^K | |
1751 (define-key GOLD-map "\C-l" 'downcase-region) ; ^L | |
1752 (define-key GOLD-map "\C-M" 'nil) ; ^M | |
1753 (define-key GOLD-map "\C-N" 'nil) ; ^N | |
1754 (define-key GOLD-map "\C-O" 'nil) ; ^O | |
1755 (define-key GOLD-map "\C-P" 'nil) ; ^P | |
1756 (define-key GOLD-map "\C-Q" 'nil) ; ^Q | |
1757 (define-key GOLD-map "\C-R" 'nil) ; ^R | |
1758 (define-key GOLD-map "\C-S" 'nil) ; ^S | |
1759 (define-key GOLD-map "\C-T" 'tpu-toggle-control-keys) ; ^T | |
1760 (define-key GOLD-map "\C-u" 'upcase-region) ; ^U | |
1761 (define-key GOLD-map "\C-V" 'nil) ; ^V | |
1762 (define-key GOLD-map "\C-w" 'tpu-write-current-buffers) ; ^W | |
1763 (define-key GOLD-map "\C-X" 'nil) ; ^X | |
1764 (define-key GOLD-map "\C-Y" 'nil) ; ^Y | |
1765 (define-key GOLD-map "\C-Z" 'nil) ; ^Z | |
1766 (define-key GOLD-map " " 'undo) ; SPC | |
1767 (define-key GOLD-map "!" 'nil) ; ! | |
1768 (define-key GOLD-map "#" 'nil) ; # | |
1769 (define-key GOLD-map "$" 'tpu-add-at-eol) ; $ | |
1770 (define-key GOLD-map "%" 'tpu-goto-percent) ; % | |
1771 (define-key GOLD-map "&" 'nil) ; & | |
1772 (define-key GOLD-map "(" 'nil) ; ( | |
1773 (define-key GOLD-map ")" 'nil) ; ) | |
1774 (define-key GOLD-map "*" 'tpu-toggle-regexp) ; * | |
1775 (define-key GOLD-map "+" 'nil) ; + | |
1776 (define-key GOLD-map "," 'tpu-goto-breadcrumb) ; , | |
1777 (define-key GOLD-map "-" 'negative-argument) ; - | |
1778 (define-key GOLD-map "." 'tpu-drop-breadcrumb) ; . | |
1779 (define-key GOLD-map "/" 'tpu-emacs-replace) ; / | |
1780 (define-key GOLD-map "0" 'digit-argument) ; 0 | |
1781 (define-key GOLD-map "1" 'digit-argument) ; 1 | |
1782 (define-key GOLD-map "2" 'digit-argument) ; 2 | |
1783 (define-key GOLD-map "3" 'digit-argument) ; 3 | |
1784 (define-key GOLD-map "4" 'digit-argument) ; 4 | |
1785 (define-key GOLD-map "5" 'digit-argument) ; 5 | |
1786 (define-key GOLD-map "6" 'digit-argument) ; 6 | |
1787 (define-key GOLD-map "7" 'digit-argument) ; 7 | |
1788 (define-key GOLD-map "8" 'digit-argument) ; 8 | |
1789 (define-key GOLD-map "9" 'digit-argument) ; 9 | |
1790 (define-key GOLD-map ":" 'nil) ; : | |
1791 (define-key GOLD-map ";" 'tpu-trim-line-ends) ; ; | |
1792 (define-key GOLD-map "<" 'nil) ; < | |
1793 (define-key GOLD-map "=" 'nil) ; = | |
1794 (define-key GOLD-map ">" 'nil) ; > | |
1795 (define-key GOLD-map "?" 'tpu-spell-check) ; ? | |
1796 (define-key GOLD-map "A" 'tpu-toggle-newline-and-indent) ; A | |
1797 (define-key GOLD-map "B" 'tpu-next-buffer) ; B | |
1798 (define-key GOLD-map "C" 'repeat-complex-command) ; C | |
1799 (define-key GOLD-map "D" 'shell-command) ; D | |
1800 (define-key GOLD-map "E" 'tpu-exit) ; E | |
1801 (define-key GOLD-map "F" 'nil) ; F | |
1802 (define-key GOLD-map "G" 'tpu-get) ; G | |
1803 (define-key GOLD-map "H" 'nil) ; H | |
1804 (define-key GOLD-map "I" 'tpu-include) ; I | |
1805 (define-key GOLD-map "K" 'tpu-kill-buffer) ; K | |
1806 (define-key GOLD-map "L" 'tpu-what-line) ; L | |
1807 (define-key GOLD-map "M" 'buffer-menu) ; M | |
1808 (define-key GOLD-map "N" 'tpu-next-file-buffer) ; N | |
1809 (define-key GOLD-map "O" 'occur) ; O | |
1810 (define-key GOLD-map "P" 'lpr-buffer) ; P | |
1811 (define-key GOLD-map "Q" 'tpu-quit) ; Q | |
1812 (define-key GOLD-map "R" 'tpu-toggle-rectangle) ; R | |
1813 (define-key GOLD-map "S" 'replace) ; S | |
1814 (define-key GOLD-map "T" 'tpu-line-to-top-of-window) ; T | |
1815 (define-key GOLD-map "U" 'undo) ; U | |
1816 (define-key GOLD-map "V" 'tpu-version) ; V | |
1817 (define-key GOLD-map "W" 'save-buffer) ; W | |
1818 (define-key GOLD-map "X" 'tpu-save-all-buffers-kill-emacs) ; X | |
1819 (define-key GOLD-map "Y" 'copy-region-as-kill) ; Y | |
1820 (define-key GOLD-map "Z" 'suspend-emacs) ; Z | |
1821 (define-key GOLD-map "[" 'blink-matching-open) ; [ | |
1822 (define-key GOLD-map "\\" 'nil) ; \ | |
1823 (define-key GOLD-map "]" 'blink-matching-open) ; ] | |
1824 (define-key GOLD-map "^" 'tpu-add-at-bol) ; ^ | |
1825 (define-key GOLD-map "_" 'split-window-vertically) ; - | |
1826 (define-key GOLD-map "`" 'what-line) ; ` | |
1827 (define-key GOLD-map "a" 'tpu-toggle-newline-and-indent) ; a | |
1828 (define-key GOLD-map "b" 'tpu-next-buffer) ; b | |
1829 (define-key GOLD-map "c" 'repeat-complex-command) ; c | |
1830 (define-key GOLD-map "d" 'shell-command) ; d | |
1831 (define-key GOLD-map "e" 'tpu-exit) ; e | |
1832 (define-key GOLD-map "f" 'nil) ; f | |
1833 (define-key GOLD-map "g" 'tpu-get) ; g | |
1834 (define-key GOLD-map "h" 'nil) ; h | |
1835 (define-key GOLD-map "i" 'tpu-include) ; i | |
1836 (define-key GOLD-map "k" 'tpu-kill-buffer) ; k | |
1837 (define-key GOLD-map "l" 'goto-line) ; l | |
1838 (define-key GOLD-map "m" 'buffer-menu) ; m | |
1839 (define-key GOLD-map "n" 'tpu-next-file-buffer) ; n | |
1840 (define-key GOLD-map "o" 'occur) ; o | |
1841 (define-key GOLD-map "p" 'lpr-region) ; p | |
1842 (define-key GOLD-map "q" 'tpu-quit) ; q | |
1843 (define-key GOLD-map "r" 'tpu-toggle-rectangle) ; r | |
1844 (define-key GOLD-map "s" 'replace) ; s | |
1845 (define-key GOLD-map "t" 'tpu-line-to-top-of-window) ; t | |
1846 (define-key GOLD-map "u" 'undo) ; u | |
1847 (define-key GOLD-map "v" 'tpu-version) ; v | |
1848 (define-key GOLD-map "w" 'save-buffer) ; w | |
1849 (define-key GOLD-map "x" 'tpu-save-all-buffers-kill-emacs) ; x | |
1850 (define-key GOLD-map "y" 'copy-region-as-kill) ; y | |
1851 (define-key GOLD-map "z" 'suspend-emacs) ; z | |
1852 (define-key GOLD-map "{" 'nil) ; { | |
1853 (define-key GOLD-map "|" 'split-window-horizontally) ; | | |
1854 (define-key GOLD-map "}" 'nil) ; } | |
1855 (define-key GOLD-map "~" 'exchange-point-and-mark) ; ~ | |
1856 (define-key GOLD-map "\177" 'delete-window) ; <X] | |
1857 | |
1858 | |
1859 ;;; | |
1860 ;;; GOLD-CSI-map key definitions | |
1861 ;;; | |
1862 (define-key GOLD-CSI-map "A" 'tpu-move-to-beginning) ; up-arrow | |
1863 (define-key GOLD-CSI-map "B" 'tpu-move-to-end) ; down-arrow | |
1864 (define-key GOLD-CSI-map "C" 'end-of-line) ; right-arrow | |
1865 (define-key GOLD-CSI-map "D" 'beginning-of-line) ; left-arrow | |
1866 | |
1867 (define-key GOLD-CSI-map "1~" 'nil) ; Find | |
1868 (define-key GOLD-CSI-map "2~" 'nil) ; Insert Here | |
1869 (define-key GOLD-CSI-map "3~" 'tpu-store-text) ; Remove | |
1870 (define-key GOLD-CSI-map "4~" 'tpu-unselect) ; Select | |
1871 (define-key GOLD-CSI-map "5~" 'tpu-previous-window) ; Prev Screen | |
1872 (define-key GOLD-CSI-map "6~" 'tpu-next-window) ; Next Screen | |
1873 | |
1874 (define-key GOLD-CSI-map "11~" 'nil) ; F1 | |
1875 (define-key GOLD-CSI-map "12~" 'nil) ; F2 | |
1876 (define-key GOLD-CSI-map "13~" 'nil) ; F3 | |
1877 (define-key GOLD-CSI-map "14~" 'nil) ; F4 | |
1878 (define-key GOLD-CSI-map "16~" 'nil) ; F5 | |
1879 (define-key GOLD-CSI-map "17~" 'nil) ; F6 | |
1880 (define-key GOLD-CSI-map "18~" 'nil) ; F7 | |
1881 (define-key GOLD-CSI-map "19~" 'nil) ; F8 | |
1882 (define-key GOLD-CSI-map "20~" 'nil) ; F9 | |
1883 (define-key GOLD-CSI-map "21~" 'nil) ; F10 | |
1884 (define-key GOLD-CSI-map "23~" 'nil) ; F11 | |
1885 (define-key GOLD-CSI-map "24~" 'nil) ; F12 | |
1886 (define-key GOLD-CSI-map "25~" 'nil) ; F13 | |
1887 (define-key GOLD-CSI-map "26~" 'nil) ; F14 | |
1888 (define-key GOLD-CSI-map "28~" 'describe-bindings) ; HELP | |
1889 (define-key GOLD-CSI-map "29~" 'nil) ; DO | |
1890 (define-key GOLD-CSI-map "31~" 'tpu-drop-breadcrumb) ; F17 | |
1891 (define-key GOLD-CSI-map "32~" 'nil) ; F18 | |
1892 (define-key GOLD-CSI-map "33~" 'nil) ; F19 | |
1893 (define-key GOLD-CSI-map "34~" 'nil) ; F20 | |
1894 | |
1895 | |
1896 ;;; | |
1897 ;;; GOLD-SS3-map key definitions | |
1898 ;;; | |
1899 (define-key GOLD-SS3-map "A" 'tpu-move-to-beginning) ; up-arrow | |
1900 (define-key GOLD-SS3-map "B" 'tpu-move-to-end) ; down-arrow | |
1901 (define-key GOLD-SS3-map "C" 'end-of-line) ; right-arrow | |
1902 (define-key GOLD-SS3-map "D" 'beginning-of-line) ; left-arrow | |
1903 | |
1904 (define-key GOLD-SS3-map "P" 'keyboard-quit) ; PF1 | |
1905 (define-key GOLD-SS3-map "Q" 'help-for-help) ; PF2 | |
1906 (define-key GOLD-SS3-map "R" 'tpu-search) ; PF3 | |
1907 (define-key GOLD-SS3-map "S" 'tpu-undelete-lines) ; PF4 | |
1908 (define-key GOLD-SS3-map "p" 'open-line) ; KP0 | |
1909 (define-key GOLD-SS3-map "q" 'tpu-change-case) ; KP1 | |
1910 (define-key GOLD-SS3-map "r" 'tpu-delete-to-eol) ; KP2 | |
1911 (define-key GOLD-SS3-map "s" 'tpu-special-insert) ; KP3 | |
1912 (define-key GOLD-SS3-map "t" 'tpu-move-to-end) ; KP4 | |
1913 (define-key GOLD-SS3-map "u" 'tpu-move-to-beginning) ; KP5 | |
1914 (define-key GOLD-SS3-map "v" 'tpu-paste) ; KP6 | |
1915 (define-key GOLD-SS3-map "w" 'execute-extended-command) ; KP7 | |
1916 (define-key GOLD-SS3-map "x" 'tpu-fill) ; KP8 | |
1917 (define-key GOLD-SS3-map "y" 'tpu-replace) ; KP9 | |
1918 (define-key GOLD-SS3-map "m" 'tpu-undelete-words) ; KP- | |
1919 (define-key GOLD-SS3-map "l" 'tpu-undelete-char) ; KP, | |
1920 (define-key GOLD-SS3-map "n" 'tpu-unselect) ; KP. | |
1921 (define-key GOLD-SS3-map "M" 'tpu-substitute) ; KPenter | |
1922 | |
1923 | |
1924 ;;; | |
1925 ;;; Repeat complex command map additions to make arrows work | |
1926 ;;; | |
1927 (cond ((boundp 'repeat-complex-command-map) | |
1928 (define-key repeat-complex-command-map "\e[A" 'previous-complex-command) | |
1929 (define-key repeat-complex-command-map "\e[B" 'next-complex-command) | |
1930 (define-key repeat-complex-command-map "\eOA" 'previous-complex-command) | |
1931 (define-key repeat-complex-command-map "\eOB" 'next-complex-command))) | |
1932 | |
1933 | |
1934 ;;; | |
1935 ;;; Minibuffer map additions to make KP_enter = RET | |
1936 ;;; | |
1937 (define-key minibuffer-local-map "\eOM" 'exit-minibuffer) | |
1938 (define-key minibuffer-local-ns-map "\eOM" 'exit-minibuffer) | |
1939 (define-key minibuffer-local-completion-map "\eOM" 'exit-minibuffer) | |
1940 (define-key minibuffer-local-must-match-map "\eOM" 'minibuffer-complete-and-exit) | |
1941 (and (boundp 'repeat-complex-command-map) | |
1942 (define-key repeat-complex-command-map "\eOM" 'exit-minibuffer)) | |
1943 | |
1944 | |
1945 ;;; | |
1946 ;;; Map control keys | |
1947 ;;; | |
1948 (define-key global-map "\C-\\" 'quoted-insert) ; ^\ | |
1949 (define-key global-map "\C-a" 'tpu-toggle-overwrite-mode) ; ^A | |
1950 (define-key global-map "\C-b" 'repeat-complex-command) ; ^B | |
1951 (define-key global-map "\C-e" 'tpu-current-end-of-line) ; ^E | |
1952 (define-key global-map "\C-f" 'set-visited-file-name) ; ^F | |
1953 (define-key global-map "\C-h" 'tpu-next-beginning-of-line) ; ^H (BS) | |
1954 (define-key global-map "\C-j" 'tpu-delete-previous-word) ; ^J (LF) | |
1955 (define-key global-map "\C-k" 'tpu-define-macro-key) ; ^K | |
1956 (define-key global-map "\C-l" 'tpu-insert-formfeed) ; ^L (FF) | |
1957 (define-key global-map "\C-r" 'recenter) ; ^R | |
1958 (define-key global-map "\C-u" 'tpu-delete-to-bol) ; ^U | |
1959 (define-key global-map "\C-v" 'quoted-insert) ; ^V | |
1960 (define-key global-map "\C-w" 'redraw-display) ; ^W | |
1961 (define-key global-map "\C-z" 'tpu-exit) ; ^Z | |
1962 | |
1963 | |
1964 ;;; | |
1965 ;;; Functions to reset and toggle the control key bindings | |
1966 ;;; | |
1967 (defun tpu-reset-control-keys (tpu-style) | |
1968 "Set control keys to TPU or emacs style functions." | |
1969 (let* ((tpu (and tpu-style (not tpu-control-keys))) | |
1970 (emacs (and (not tpu-style) tpu-control-keys)) | |
1971 (doit (or tpu emacs))) | |
1972 (cond (doit | |
1973 (if emacs (setq tpu-global-map (copy-keymap global-map))) | |
1974 (let ((map (if tpu | |
1975 (copy-keymap tpu-global-map) | |
1976 (copy-keymap tpu-original-global-map)))) | |
1977 | |
1978 (define-key global-map "\C-\\" (lookup-key map "\C-\\")) ; ^\ | |
1979 (define-key global-map "\C-a" (lookup-key map "\C-a")) ; ^A | |
1980 (define-key global-map "\C-b" (lookup-key map "\C-b")) ; ^B | |
1981 (define-key global-map "\C-e" (lookup-key map "\C-e")) ; ^E | |
1982 (define-key global-map "\C-f" (lookup-key map "\C-f")) ; ^F | |
1983 (define-key global-map "\C-h" (lookup-key map "\C-h")) ; ^H (BS) | |
1984 (define-key global-map "\C-j" (lookup-key map "\C-j")) ; ^J (LF) | |
1985 (define-key global-map "\C-k" (lookup-key map "\C-k")) ; ^K | |
1986 (define-key global-map "\C-l" (lookup-key map "\C-l")) ; ^L (FF) | |
1987 (define-key global-map "\C-r" (lookup-key map "\C-r")) ; ^R | |
1988 (define-key global-map "\C-u" (lookup-key map "\C-u")) ; ^U | |
1989 (define-key global-map "\C-v" (lookup-key map "\C-v")) ; ^V | |
1990 (define-key global-map "\C-w" (lookup-key map "\C-w")) ; ^W | |
1991 (define-key global-map "\C-z" (lookup-key map "\C-z")) ; ^Z | |
1992 (setq tpu-control-keys tpu-style)))))) | |
1993 | |
1994 (defun tpu-toggle-control-keys nil | |
1995 "Toggles control key bindings between TPU-edt and Emacs." | |
1996 (interactive) | |
1997 (tpu-reset-control-keys (not tpu-control-keys)) | |
1998 (and (interactive-p) | |
1999 (message "Control keys function with %s bindings." | |
2000 (if tpu-control-keys "TPU-edt" "Emacs")))) | |
2001 | |
2002 | |
2003 ;;; | |
2004 ;;; Emacs version 19 minibuffer history support | |
2005 ;;; | |
2006 (defun tpu-next-history-element (n) | |
2007 "Insert the next element of the minibuffer history into the minibuffer." | |
2008 (interactive "p") | |
2009 (next-history-element n) | |
2010 (goto-char (point-max))) | |
2011 | |
2012 (defun tpu-previous-history-element (n) | |
2013 "Insert the previous element of the minibuffer history into the minibuffer." | |
2014 (interactive "p") | |
2015 (previous-history-element n) | |
2016 (goto-char (point-max))) | |
2017 | |
2018 (defun tpu-arrow-history nil | |
2019 "Modify minibuffer maps to use arrows for history recall." | |
2020 (interactive) | |
2021 (let ((loc (where-is-internal 'tpu-previous-line)) (cur nil)) | |
2022 (while (setq cur (car loc)) | |
2023 (define-key read-expression-map cur 'tpu-previous-history-element) | |
2024 (define-key minibuffer-local-map cur 'tpu-previous-history-element) | |
2025 (define-key minibuffer-local-ns-map cur 'tpu-previous-history-element) | |
2026 (define-key minibuffer-local-completion-map cur 'tpu-previous-history-element) | |
2027 (define-key minibuffer-local-must-match-map cur 'tpu-previous-history-element) | |
2028 (setq loc (cdr loc))) | |
2029 | |
2030 (setq loc (where-is-internal 'tpu-next-line)) | |
2031 (while (setq cur (car loc)) | |
2032 (define-key read-expression-map cur 'tpu-next-history-element) | |
2033 (define-key minibuffer-local-map cur 'tpu-next-history-element) | |
2034 (define-key minibuffer-local-ns-map cur 'tpu-next-history-element) | |
2035 (define-key minibuffer-local-completion-map cur 'tpu-next-history-element) | |
2036 (define-key minibuffer-local-must-match-map cur 'tpu-next-history-element) | |
2037 (setq loc (cdr loc))))) | |
2038 | |
2039 | |
2040 ;;; | |
2041 ;;; Emacs version 19 X-windows key definition support | |
2042 ;;; | |
2043 (defun tpu-load-xkeys (file) | |
2044 "Load the TPU-edt X-windows key definitions FILE. | |
2045 If FILE is nil, try to load a default file. The default file names are | |
2046 ~/.tpu-lucid-keys for Lucid emacs, and ~/.tpu-gnu-keys for GNU emacs." | |
2047 (interactive "fX key definition file: ") | |
2048 (cond (file | |
2049 (setq file (expand-file-name file))) | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
2050 (tpu-xkeys-file |
4421 | 2051 (setq file (expand-file-name tpu-xkeys-file))) |
2052 (tpu-gnu-emacs19-p | |
2053 (setq file (expand-file-name "~/.tpu-gnu-keys"))) | |
2054 (tpu-lucid-emacs19-p | |
2055 (setq file (expand-file-name "~/.tpu-lucid-keys")))) | |
2056 (cond ((file-readable-p file) | |
2057 (load-file file)) | |
2058 (t | |
4523
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
2059 (switch-to-buffer "*scratch*") |
73cc2b215834
(tpu-version): Print version number rather than the RCS revision number.
Richard M. Stallman <rms@gnu.org>
parents:
4450
diff
changeset
|
2060 (erase-buffer) |
4421 | 2061 (insert " |
2062 | |
2063 Ack!! You're running TPU-edt under X-windows without loading an | |
2064 X key definition file. To create a TPU-edt X key definition | |
2065 file, run the tpu-mapper.el program. It came with TPU-edt. It | |
2066 even includes directions on how to use it! Perhaps it's laying | |
2067 around here someplace. ") | |
2068 (let ((file "tpu-mapper.el") | |
2069 (found nil) | |
2070 (path nil) | |
2071 (search-list (append (list (expand-file-name ".")) load-path))) | |
2072 (while (and (not found) search-list) | |
2073 (setq path (concat (car search-list) | |
2074 (if (string-match "/$" (car search-list)) "" "/") | |
2075 file)) | |
2076 (if (and (file-exists-p path) (not (file-directory-p path))) | |
2077 (setq found t)) | |
2078 (setq search-list (cdr search-list))) | |
2079 (cond (found | |
2080 (insert (format | |
2081 "Ah yes, there it is, in \n\n %s \n\n" path)) | |
2082 (if (tpu-y-or-n-p "Do you want to run it now? ") | |
2083 (load-file path))) | |
2084 (t | |
2085 (insert "Nope, I can't seem to find it. :-(\n\n") | |
2086 (sit-for 120))))))) | |
2087 | |
2088 | |
2089 ;;; | |
2090 ;;; Start and Stop TPU-edt | |
2091 ;;; | |
2092 ;;;###autoload | |
2093 (defun tpu-edt-on nil | |
2094 "Turn on TPU/edt emulation." | |
2095 (interactive) | |
2096 (cond | |
2097 ((not tpu-edt-mode) | |
2098 ;; we use picture-mode functions | |
2099 (require 'picture) | |
2100 (tpu-reset-control-keys t) | |
2101 (cond (tpu-emacs19-p | |
2102 (and window-system (tpu-load-xkeys nil)) | |
2103 (tpu-arrow-history)) | |
2104 (t | |
2105 ;; define ispell functions | |
2106 (autoload 'ispell-word "ispell" "Check spelling of word at or before point" t) | |
2107 (autoload 'ispell-complete-word "ispell" "Complete word at or before point" t) | |
2108 (autoload 'ispell-buffer "ispell" "Check spelling of entire buffer" t) | |
2109 (autoload 'ispell-region "ispell" "Check spelling of region" t))) | |
2110 (tpu-set-mode-line t) | |
2111 (tpu-advance-direction) | |
2112 ;; set page delimiter, display line truncation, and scrolling like TPU | |
2113 (setq-default page-delimiter "\f") | |
2114 (setq-default truncate-lines t) | |
2115 (setq scroll-step 1) | |
2116 (setq tpu-edt-mode t)))) | |
2117 | |
2118 (defun tpu-edt-off nil | |
2119 "Turn off TPU/edt emulation. Note that the keypad is left on." | |
2120 (interactive) | |
2121 (cond | |
2122 (tpu-edt-mode | |
2123 (tpu-reset-control-keys nil) | |
2124 (tpu-set-mode-line nil) | |
2125 (setq-default page-delimiter "^\f") | |
2126 (setq-default truncate-lines nil) | |
2127 (setq scroll-step 0) | |
2128 (use-global-map global-map) | |
2129 (setq tpu-edt-mode nil)))) | |
2130 | |
2131 | |
2132 ;;; | |
2133 ;;; Turn on TPU-edt and announce it as a feature | |
2134 ;;; | |
2135 (tpu-edt-mode) | |
2136 | |
2137 (provide 'tpu-edt) | |
2138 | |
2139 ;;; tpu-edt.el ends here |