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