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