]> code.delx.au - gnu-emacs/blob - lisp/emulation/edt.el
Remove compatibility with Emacs 24.3 in octave-mode
[gnu-emacs] / lisp / emulation / edt.el
1 ;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs
2
3 ;; Copyright (C) 1986, 1992-1995, 2000-2016 Free Software Foundation,
4 ;; Inc.
5
6 ;; Author: Kevin Gallagher <kevin.gal@verizon.net>
7 ;; Maintainer: Kevin Gallagher <kevin.gal@verizon.net>
8 ;; Keywords: emulations
9
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 3 of the License, or
15 ;; (at your option) any later version.
16
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. If not, see <http://www.gnu.org/licenses/>.
24
25
26 \f
27 ;;; Commentary:
28 ;;
29
30 ;; This is Version 4.0 of the EDT Emulation for Emacs.
31 ;; It comes with special functions which replicate nearly all of EDT's
32 ;; keypad mode behavior. It sets up default keypad and function key
33 ;; bindings which closely match those found in EDT. Support is
34 ;; provided so that users may reconfigure most keypad and function key
35 ;; bindings to their own liking.
36
37 ;; NOTE: Version 4.0 contains several enhancements. See the
38 ;; Enhancement section below for the details.
39
40 ;; Getting Started:
41
42 ;; To start the EDT Emulation, first start Emacs and then enter
43 ;;
44 ;; M-x edt-emulation-on
45 ;;
46 ;; to begin the emulation. After initialization is complete, the
47 ;; following message will appear below the status line informing you
48 ;; that the emulation has been enabled: "Default EDT keymap active".
49
50 ;; You can have the EDT Emulation start up automatically, each time
51 ;; you initiate a GNU Emacs session, by adding the following line to
52 ;; your init file:
53 ;;
54 ;; (add-hook 'emacs-startup-hook 'edt-emulation-on)
55
56 ;; IMPORTANT: Be sure to read the Info node `edt' for more details.
57 ;; It contains very helpful user information.
58
59 ;; The EDT emulation consists of the following files:
60 ;;
61 ;; edt.texi - User manual
62 ;; edt-user.el - Sample Customization File (located in Emacs
63 ;; distribution etc directory)
64 ;; edt.el - EDT Emulation Functions and Default Configuration
65 ;; edt-lk201.el - Built-in support for DEC LK-201 Keyboards
66 ;; edt-vt100.el - Built-in support for DEC VT-100 (and above) terminals
67 ;; edt-pc.el - Built-in support for PC 101 Keyboards under MS-DOS
68 ;; edt-mapper.el - Create an EDT LK-201 Map File for Keyboards Without
69 ;; Built-in Support
70
71 ;; Enhancements:
72
73 ;; Version 4.0 contains the following enhancements:
74
75 ;; 1. Scroll margins at the top and bottom of the window are now
76 ;; supported. (The design was copied from tpu-extras.el.) By
77 ;; default, this feature is enabled, with the top margin set to
78 ;; 10% of the window and the bottom margin set to 15% of the
79 ;; window. To change these settings, you can invoke the function
80 ;; edt-set-scroll-margins in your init file. For example, the
81 ;; following line
82 ;;
83 ;; (edt-set-scroll-margins "20%" "25%")
84 ;;
85 ;; sets the top margin to 20% of the window and the bottom margin
86 ;; to 25% of the window. To disable this feature, set each
87 ;; margin to 0%. You can also invoke edt-set-scroll-margins
88 ;; interactively while EDT Emulation is active to change the
89 ;; settings for that session.
90 ;;
91 ;; NOTE: Another way to set the scroll margins is to use the
92 ;; Emacs customization feature to set the following two variables
93 ;; directly:
94 ;;
95 ;; edt-top-scroll-margin and edt-bottom-scroll-margin
96 ;;
97 ;; Enter the Emacs `customize' command. First select the Editing
98 ;; group and then select the Emulations group. Finally, select
99 ;; the Edt group and follow the directions.
100 ;;
101 ;; 2. The SUBS command is now supported and bound to GOLD-Enter by
102 ;; default. (This design was copied from tpu-edt.el.) Note, in
103 ;; earlier versions of EDT Emulation, GOLD-Enter was assigned to
104 ;; the Emacs function `query-replace'. The binding of
105 ;; `query-replace' has been moved to GOLD-/. If you prefer to
106 ;; restore `query-replace' to GOLD-Enter, then use an EDT user
107 ;; customization file, edt-user.el, to do this.
108 ;; See Info node `edt' for more details.
109
110 ;; 3. EDT Emulation now also works in XEmacs, including the
111 ;; highlighting of selected text.
112
113 ;; 4. If you access a workstation using an X Server, observe that
114 ;; the initialization file generated by edt-mapper.el will now
115 ;; contain the name of the X Server vendor. This is a
116 ;; convenience for those who have access to their Unix account
117 ;; from more than one type of X Server. Since different X
118 ;; Servers typically require different EDT emulation
119 ;; initialization files, edt-mapper.el will now generate these
120 ;; different initialization files and save them with different
121 ;; names. Then, the correct initialization file for the
122 ;; particular X server in use is loaded correctly automatically.
123
124 ;; 5. Also, edt-mapper.el is now capable of binding an ASCII key
125 ;; sequence, providing the ASCII key sequence prefix is already
126 ;; known by Emacs to be a prefix. As a result of providing this
127 ;; support, some terminal/keyboard/window system configurations,
128 ;; which don't have a complete set of sensible function key
129 ;; bindings built into Emacs in `function-key-map', can still be
130 ;; configured for use with EDT Emulation. (Note: In a few rare
131 ;; circumstances this does not work properly. In particular, it
132 ;; does not work if a subset of the leading ASCII characters in a
133 ;; key sequence are recognized by Emacs as having an existing
134 ;; binding. For example, if the keypad 7 (KP-7) key generates
135 ;; the sequence \"<ESC>Ow\" and \"<ESC>O\" is already bound to a
136 ;; function, pressing KP-7 when told to do so by edt-mapper.el
137 ;; will result in edt-mapper.el incorrectly mapping \"<ESC>O\" to
138 ;; KP-7 and \"w\" to KP-8. If something like this happens to
139 ;; you, it is probably a bug in the support for your keyboard
140 ;; within Emacs OR a bug in the Unix termcap/terminfo support for
141 ;; your terminal OR a bug in the terminal emulation software you
142 ;; are using.)
143
144 ;; 6. The edt-quit function (bound to GOLD-q by default) has been
145 ;; modified to warn the user when file-related buffer
146 ;; modifications exist. It now cautions the user that those
147 ;; modifications will be lost if the user quits without saving
148 ;; those buffers.
149
150
151 ;;; History:
152 ;;
153 ;; Version 4.0 2000 Added New Features and Fixed a Few Bugs
154 ;;
155
156 \f
157 ;;; Code:
158
159 ;;; Electric Help functions are used for keypad help displays. A few
160 ;;; picture functions are used in rectangular cut and paste commands.
161
162 (require 'ehelp)
163 (require 'picture)
164
165 ;;;;
166 ;;;; VARIABLES and CONSTANTS
167 ;;;;
168
169 (defgroup edt nil
170 "Emacs emulating EDT."
171 :prefix "edt-"
172 :group 'emulations)
173
174 ;; To silence the byte-compiler
175 (defvar *EDT-keys*)
176 (defvar edt-default-global-map)
177 (defvar edt-last-copied-word)
178 (defvar edt-learn-macro-count)
179 (defvar edt-orig-page-delimiter)
180 (defvar edt-orig-transient-mark-mode)
181 (defvar edt-rect-start-point)
182 (defvar edt-user-global-map)
183 (defvar rect-start-point)
184 (defvar time-string)
185 (defvar zmacs-region-stays)
186
187 ;;;
188 ;;; Version Information
189 ;;;
190 (defconst edt-version "4.0" "EDT Emulation version number.")
191
192 ;;;
193 ;;; User Configurable Variables
194 ;;;
195
196 (defcustom edt-keep-current-page-delimiter nil
197 "Emacs MUST be restarted for a change in value to take effect!
198 Non-nil leaves Emacs value of `page-delimiter' unchanged within EDT
199 Emulation. If set to nil (the default), the `page-delimiter' variable
200 is set to \"\\f\" when edt-emulation-on is first invoked. This
201 setting replicates EDT's page delimiter behavior. The original value
202 is restored when edt-emulation-off is called."
203 :type 'boolean
204 :group 'edt)
205
206 (defcustom edt-use-EDT-control-key-bindings nil
207 "Emacs MUST be restarted for a change in value to take effect!
208 Non-nil causes the control key bindings to be replaced with EDT
209 bindings. If set to nil (the default), EDT control key bindings are
210 not used and the current Emacs control key bindings are retained for
211 use within the EDT emulation."
212 :type 'boolean
213 :group 'edt)
214
215 (defcustom edt-word-entities '(?\t)
216 "Specifies the list of EDT word entity characters.
217 The default list, (?\\t), contains just the TAB character, which
218 emulates EDT. Characters are specified in the list using their
219 decimal ASCII values. A question mark, followed by the actual
220 character, can be used to indicate the numerical value of the
221 character, instead of the actual decimal value. So, ?A means the
222 numerical value for the letter A, ?/ means the numerical value for /,
223 etc. Several unprintable and special characters have special
224 representations, which you can also use:
225
226 ?\\b specifies BS, C-h
227 ?\\t specifies TAB, C-i
228 ?\\n specifies LFD, C-j
229 ?\\v specifies VTAB, C-k
230 ?\\f specifies FF, C-l
231 ?\\r specifies CR, C-m
232 ?\\e specifies ESC, C-[
233 ?\\\\ specifies \\
234
235 In EDT Emulation movement-by-word commands, each character in the list
236 will be treated as if it were a separate word."
237 :type '(repeat integer)
238 :group 'edt)
239
240 (defcustom edt-top-scroll-margin 10
241 "Scroll margin at the top of the screen.
242 Interpreted as a percent of the current window size with a default
243 setting of 10%. If set to 0, top scroll margin is disabled."
244 :type 'integer
245 :group 'edt)
246
247 (defcustom edt-bottom-scroll-margin 15
248 "Scroll margin at the bottom of the screen.
249 Interpreted as a percent of the current window size with a default
250 setting of 15%. If set to 0, bottom scroll margin is disabled."
251 :type 'integer
252 :group 'edt)
253
254 ;;;
255 ;;; Internal Variables
256 ;;;
257
258 (defvar edt-last-deleted-lines ""
259 "Last text deleted by the EDT emulation DEL L command.")
260
261 (defvar edt-last-deleted-words ""
262 "Last text deleted by the EDT emulation DEL W command.")
263
264 (defvar edt-last-deleted-chars ""
265 "Last text deleted by the EDT emulation DEL C command.")
266
267 (defvar edt-find-last-text ""
268 "Last text found by the EDT emulation FIND command.")
269
270 (defvar edt-match-beginning-mark (make-marker)
271 "Used internally by the EDT emulation SUBS command.")
272
273 (defvar edt-match-end-mark (make-marker)
274 "Used internally by the EDT emulation SUBS command.")
275
276 (defvar edt-last-replaced-key-definition nil
277 "Key definition replaced with `edt-define-key' or `edt-learn' command.")
278
279 (defvar edt-direction-string ""
280 "String indicating current direction of movement.")
281
282 (defvar edt-select-mode nil
283 "Non-nil means select mode is active.")
284
285 (defvar edt-select-mode-current ""
286 "Text displayed in mode line to indicate the state of EDT select mode.
287 When select mode is inactive, it is set to an empty string.")
288
289 (defconst edt-select-mode-string " Select"
290 "Used in mode line to indicate select mode is active.")
291
292 (defconst edt-forward-string " ADVANCE"
293 "Direction string in mode line to indicate forward movement.")
294
295 (defconst edt-backward-string " BACKUP"
296 "Direction string in mode line to indicate backward movement.")
297
298 (defvar edt-default-map-active nil
299 "Non-nil indicates that default EDT emulation key bindings are active.
300 nil means user-defined custom bindings are active.")
301
302 (defvar edt-user-map-configured nil
303 "Non-nil indicates that user custom EDT key bindings are configured.
304 This means that an edt-user.el file was found in the user's `load-path'.")
305
306 (defvar edt-term nil
307 "Specifies the terminal type, if applicable.")
308
309 ;;;
310 ;;; Emacs version identifiers - currently referenced by
311 ;;;
312 ;;; o edt-emulation-on o edt-load-keys
313 ;;;
314 (defconst edt-emacs-variant (if (featurep 'emacs) "gnu" "xemacs")
315 "Indicates Emacs variant: GNU Emacs or XEmacs (aka Lucid Emacs).")
316
317 (defconst edt-window-system (if (featurep 'emacs) window-system (console-type))
318 "Indicates window system (in GNU Emacs) or console type (in XEmacs).")
319
320 (declare-function x-server-vendor "xfns.c" (&optional terminal))
321
322 (defconst edt-xserver (when (eq edt-window-system 'x)
323 ;; The Cygwin window manager has a `/' in its
324 ;; name, which breaks the generated file name of
325 ;; the custom key map file. Replace `/' with a
326 ;; `-' to work around that.
327 (if (featurep 'xemacs)
328 (replace-in-string (x-server-vendor) "[ /]" "-")
329 (replace-regexp-in-string "[ /]" "-"
330 (x-server-vendor))))
331 "Indicates X server vendor name, if applicable.")
332
333 (defvar edt-keys-file nil
334 "User's custom keypad and function keys mappings to emulate LK-201 keyboard.")
335
336 (defvar edt-last-copied-word nil
337 "Last word that the user copied.")
338
339 \f
340 ;;;;
341 ;;;; EDT Emulation Commands
342 ;;;;
343
344 ;;; Almost all of EDT's keypad mode commands have equivalent Emacs
345 ;;; function counterparts. But many of these counterparts behave
346 ;;; somewhat differently in Emacs.
347 ;;;
348 ;;; So, the following Emacs functions emulate, where practical, the
349 ;;; exact behavior of the corresponding EDT keypad mode commands. In
350 ;;; a few cases, the emulation is not exact, but it should be close
351 ;;; enough for most EDT die-hards.
352 ;;;
353
354 ;;;
355 ;;; PAGE
356 ;;;
357 ;;; Emacs uses the regexp assigned to page-delimiter to determine what
358 ;;; marks a page break. This is normally "^\f", which causes the
359 ;;; edt-page command to ignore form feeds not located at the beginning
360 ;;; of a line. To emulate the EDT PAGE command exactly,
361 ;;; page-delimiter is set to "\f" when EDT emulation is turned on, and
362 ;;; restored to its original value when EDT emulation is turned off.
363 ;;; But this can be overridden if the EDT definition is not desired by
364 ;;; placing
365 ;;;
366 ;;; (setq edt-keep-current-page-delimiter t)
367 ;;;
368 ;;; in your init file.
369
370 (defun edt-page-forward (num)
371 "Move forward to just after next page delimiter.
372 Argument NUM is the number of page delimiters to move."
373 (interactive "p")
374 (edt-check-prefix num)
375 (if (eobp)
376 (error "End of buffer")
377 (progn
378 (forward-page num)
379 (if (eobp)
380 (edt-line-to-bottom-of-window)
381 (edt-line-to-top-of-window)))))
382
383 (defun edt-page-backward (num)
384 "Move backward to just after previous page delimiter.
385 Argument NUM is the number of page delimiters to move."
386 (interactive "p")
387 (edt-check-prefix num)
388 (if (bobp)
389 (error "Beginning of buffer")
390 (progn
391 (backward-page num)
392 (edt-line-to-top-of-window)
393 (if (featurep 'xemacs) (setq zmacs-region-stays t)))))
394
395 (defun edt-page (num)
396 "Move in current direction to next page delimiter.
397 Argument NUM is the number of page delimiters to move."
398 (interactive "p")
399 (if (equal edt-direction-string edt-forward-string)
400 (edt-page-forward num)
401 (edt-page-backward num)))
402
403 ;;;
404 ;;; SECT
405 ;;;
406 ;;; EDT defaults a section size to be 16 lines of its one and only
407 ;;; 24-line window. That's two-thirds of the window at a time. The
408 ;;; EDT SECT commands moves the cursor, not the window.
409 ;;;
410 ;;; This emulation of EDT's SECT moves the cursor approximately
411 ;;; two-thirds of the current window at a time.
412
413 (defun edt-sect-forward (num)
414 "Move cursor forward two-thirds of a window's number of lines.
415 Argument NUM is the number of sections to move."
416 (interactive "p")
417 (edt-check-prefix num)
418 (edt-line-forward (* (* (/ (- (window-height) 1) 3) 2) num)))
419
420
421 (defun edt-sect-backward (num)
422 "Move cursor backward two-thirds of a window.
423 Argument NUM is the number of sections to move."
424 (interactive "p")
425 (edt-check-prefix num)
426 (edt-line-backward (* (* (/ (- (window-height) 1) 3) 2) num)))
427
428 (defun edt-sect (num)
429 "Move in current direction a full window.
430 Argument NUM is the number of sections to move."
431 (interactive "p")
432 (if (equal edt-direction-string edt-forward-string)
433 (edt-sect-forward num)
434 (edt-sect-backward num)))
435
436 ;;;
437 ;;; BEGINNING OF LINE
438 ;;;
439 ;;; EDT's beginning-of-line command is not affected by current
440 ;;; direction, for some unknown reason.
441
442 (defun edt-beginning-of-line (num)
443 "Move backward to next beginning of line mark.
444 Argument NUM is the number of BOL marks to move."
445 (interactive "p")
446 (edt-check-prefix num)
447 (let ((beg (edt-current-line)))
448 (if (bolp)
449 (forward-line (* -1 num))
450 (progn
451 (setq num (1- num))
452 (forward-line (* -1 num))))
453 (edt-top-check beg num))
454 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
455
456
457 ;;;
458 ;;; EOL (End of Line)
459 ;;;
460
461 (defun edt-end-of-line-forward (num)
462 "Move forward to next end of line mark.
463 Argument NUM is the number of EOL marks to move."
464 (interactive "p")
465 (edt-check-prefix num)
466 (let ((beg (edt-current-line)))
467 (forward-char)
468 (end-of-line num)
469 (edt-bottom-check beg num))
470 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
471
472
473 (defun edt-end-of-line-backward (num)
474 "Move backward to next end of line mark.
475 Argument NUM is the number of EOL marks to move."
476 (interactive "p")
477 (edt-check-prefix num)
478 (let ((beg (edt-current-line)))
479 (end-of-line (1- num))
480 (edt-top-check beg num))
481 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
482
483
484 (defun edt-end-of-line (num)
485 "Move in current direction to next end of line mark.
486 Argument NUM is the number of EOL marks to move."
487 (interactive "p")
488 (if (equal edt-direction-string edt-forward-string)
489 (edt-end-of-line-forward num)
490 (edt-end-of-line-backward num)))
491
492 ;;;
493 ;;; WORD
494 ;;;
495 ;;; This one is a tad messy. To emulate EDT's behavior everywhere in
496 ;;; the file (beginning of file, end of file, beginning of line, end
497 ;;; of line, etc.) it takes a bit of special handling.
498 ;;;
499 ;;; The variable edt-word-entities contains a list of characters which
500 ;;; are to be viewed as distinct words where ever they appear in the
501 ;;; buffer. This emulates the EDT line mode command SET ENTITY WORD.
502
503
504 (defun edt-one-word-forward ()
505 "Move forward to first character of next word."
506 (interactive)
507 (if (eobp)
508 (error "End of buffer"))
509 (if (eolp)
510 (forward-char)
511 (progn
512 (if (memq (following-char) edt-word-entities)
513 (forward-char)
514 (while (and
515 (not (eolp))
516 (not (eobp))
517 (not (eq ?\ (char-syntax (following-char))))
518 (not (memq (following-char) edt-word-entities)))
519 (forward-char)))
520 (while (and
521 (not (eolp))
522 (not (eobp))
523 (eq ?\ (char-syntax (following-char)))
524 (not (memq (following-char) edt-word-entities)))
525 (forward-char))))
526 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
527
528 (defun edt-one-word-backward ()
529 "Move backward to first character of previous word."
530 (interactive)
531 (if (bobp)
532 (error "Beginning of buffer"))
533 (if (bolp)
534 (backward-char)
535 (progn
536 (backward-char)
537 (while (and
538 (not (bolp))
539 (not (bobp))
540 (eq ?\ (char-syntax (following-char)))
541 (not (memq (following-char) edt-word-entities)))
542 (backward-char))
543 (if (not (memq (following-char) edt-word-entities))
544 (while (and
545 (not (bolp))
546 (not (bobp))
547 (not (eq ?\ (char-syntax (preceding-char))))
548 (not (memq (preceding-char) edt-word-entities)))
549 (backward-char)))))
550 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
551
552 (defun edt-word-forward (num)
553 "Move forward to first character of next word.
554 Argument NUM is the number of words to move."
555 (interactive "p")
556 (edt-check-prefix num)
557 (while (> num 0)
558 (edt-one-word-forward)
559 (setq num (1- num))))
560
561 (defun edt-word-backward (num)
562 "Move backward to first character of previous word.
563 Argument NUM is the number of words to move."
564 (interactive "p")
565 (edt-check-prefix num)
566 (while (> num 0)
567 (edt-one-word-backward)
568 (setq num (1- num))))
569
570 (defun edt-word (num)
571 "Move in current direction to first character of next word.
572 Argument NUM is the number of words to move."
573 (interactive "p")
574 (if (equal edt-direction-string edt-forward-string)
575 (edt-word-forward num)
576 (edt-word-backward num)))
577
578 ;;;
579 ;;; CHAR
580 ;;;
581
582 (defun edt-character (num)
583 "Move in current direction to next character.
584 Argument NUM is the number of characters to move."
585 (interactive "p")
586 (edt-check-prefix num)
587 (if (equal edt-direction-string edt-forward-string)
588 (forward-char num)
589 (backward-char num))
590 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
591
592 ;;;
593 ;;; LINE
594 ;;;
595 ;;; When direction is set to BACKUP, LINE behaves just like BEGINNING
596 ;;; OF LINE in EDT. So edt-line-backward is not really needed as a
597 ;;; separate function.
598
599 (defun edt-line-backward (num)
600 "Move backward to next beginning of line mark.
601 Argument NUM is the number of BOL marks to move."
602 (interactive "p")
603 (edt-beginning-of-line num))
604
605 (defun edt-line-forward (num)
606 "Move forward to next beginning of line mark.
607 Argument NUM is the number of BOL marks to move."
608 (interactive "p")
609 (edt-check-prefix num)
610 (let ((beg (edt-current-line)))
611 (forward-line num)
612 (edt-bottom-check beg num))
613 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
614
615 (defun edt-line (num)
616 "Move in current direction to next beginning of line mark.
617 Argument NUM is the number of BOL marks to move."
618 (interactive "p")
619 (if (equal edt-direction-string edt-forward-string)
620 (edt-line-forward num)
621 (edt-line-backward num)))
622
623 ;;;
624 ;;; UP and DOWN Arrows
625 ;;;
626
627 (defun edt-next-line (num)
628 "Move cursor down one line.
629 Argument NUM is the number of lines to move."
630 (interactive "p")
631 (edt-check-prefix num)
632 (let ((beg (edt-current-line)))
633 ;; We're deliberately using next-line instead of forward-line.
634 (with-no-warnings (next-line num))
635 (edt-bottom-check beg num))
636 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
637
638 (defun edt-previous-line (num)
639 "Move cursor up one line.
640 Argument NUM is the number of lines to move."
641 (interactive "p")
642 (edt-check-prefix num)
643 (let ((beg (edt-current-line)))
644 ;; We're deliberately using previous-line instead of forward-line.
645 (with-no-warnings (previous-line num))
646 (edt-top-check beg num))
647 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
648
649
650 ;;;
651 ;;; TOP
652 ;;;
653
654 (defun edt-top ()
655 "Move cursor to the beginning of buffer."
656 (interactive)
657 (goto-char (point-min))
658 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
659
660 ;;;
661 ;;; BOTTOM
662 ;;;
663
664 (defun edt-bottom ()
665 "Move cursor to the end of buffer."
666 (interactive)
667 (goto-char (point-max))
668 (edt-line-to-bottom-of-window))
669
670 (defmacro edt-with-position (&rest body)
671 "Execute BODY with some position-related variables bound."
672 `(let* ((left nil)
673 (beg (edt-current-line))
674 (height (window-height))
675 (top-percent
676 (if (zerop edt-top-scroll-margin) 10 edt-top-scroll-margin))
677 (bottom-percent
678 (if (zerop edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
679 (top-margin (/ (* height top-percent) 100))
680 (bottom-up-margin (1+ (/ (* height bottom-percent) 100)))
681 (bottom-margin (max beg (- height bottom-up-margin 1)))
682 (top (save-excursion (move-to-window-line top-margin) (point)))
683 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
684 (far (save-excursion
685 (goto-char bottom)
686 (point-at-bol (1- height)))))
687 ,@body))
688
689 ;;;
690 ;;; FIND
691 ;;;
692
693 (defun edt-find-forward (&optional find)
694 "Find first occurrence of a string in forward direction and save it.
695 Optional argument FIND is t is this function is called from `edt-find'."
696 (interactive)
697 (or find
698 (setq edt-find-last-text (read-string "Search forward: ")))
699 (edt-with-position
700 (when (search-forward edt-find-last-text) ; FIXME noerror?
701 (search-backward edt-find-last-text)
702 (edt-set-match)
703 (if (> (point) far)
704 (if (zerop (setq left (save-excursion (forward-line height))))
705 (recenter top-margin)
706 (recenter (- left bottom-up-margin)))
707 (and (> (point) bottom) (recenter bottom-margin)))))
708 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
709
710 (defun edt-find-backward (&optional find)
711 "Find first occurrence of a string in the backward direction and save it.
712 Optional argument FIND is t if this function is called from `edt-find'."
713 (interactive)
714 (or find
715 (setq edt-find-last-text (read-string "Search backward: ")))
716 (edt-with-position
717 (if (search-backward edt-find-last-text)
718 (edt-set-match))
719 (and (< (point) top) (recenter (min beg top-margin))))
720 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
721
722 (defun edt-find ()
723 "Find first occurrence of string in current direction and save it."
724 (interactive)
725 (set 'edt-find-last-text (read-string "Search: "))
726 (if (equal edt-direction-string edt-forward-string)
727 (edt-find-forward t)
728 (edt-find-backward t)))
729
730
731 ;;;
732 ;;; FNDNXT
733 ;;;
734
735 (defun edt-find-next-forward ()
736 "Find next occurrence of a string in forward direction."
737 (interactive)
738 (edt-with-position
739 (forward-char 1)
740 (if (search-forward edt-find-last-text nil t)
741 (progn
742 (search-backward edt-find-last-text)
743 (edt-set-match)
744 (if (> (point) far)
745 (if (zerop (setq left (save-excursion (forward-line height))))
746 (recenter top-margin)
747 (recenter (- left bottom-up-margin)))
748 (and (> (point) bottom) (recenter bottom-margin))))
749 (backward-char 1)
750 (error "Search failed: \"%s\"" edt-find-last-text)))
751 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
752
753 (defun edt-find-next-backward ()
754 "Find next occurrence of a string in backward direction."
755 (interactive)
756 (edt-with-position
757 (if (not (search-backward edt-find-last-text nil t))
758 (error "Search failed: \"%s\"" edt-find-last-text)
759 (edt-set-match)
760 (and (< (point) top) (recenter (min beg top-margin)))))
761 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
762
763 (defun edt-find-next ()
764 "Find next occurrence of a string in current direction."
765 (interactive)
766 (if (equal edt-direction-string edt-forward-string)
767 (edt-find-next-forward)
768 (edt-find-next-backward)))
769
770 ;;;
771 ;;; APPEND
772 ;;;
773
774 (defun edt-append ()
775 "Append this kill region to last killed region."
776 (interactive "*")
777 (edt-check-selection)
778 (append-next-kill)
779 (kill-region (mark) (point))
780 (message "Selected text APPENDED to kill ring"))
781
782 ;;;
783 ;;; DEL L
784 ;;;
785
786 (defun edt-delete-line (num)
787 "Delete from cursor up to and including the end of line mark.
788 Argument NUM is the number of lines to delete."
789 (interactive "*p")
790 (edt-check-prefix num)
791 (let ((beg (point)))
792 (forward-line num)
793 (if (not (eq (preceding-char) ?\n))
794 (insert "\n"))
795 (setq edt-last-deleted-lines
796 (buffer-substring beg (point)))
797 (delete-region beg (point))))
798
799 ;;;
800 ;;; DEL EOL
801 ;;;
802
803 (defun edt-delete-to-end-of-line (num)
804 "Delete from cursor up to but excluding the end of line mark.
805 Argument NUM is the number of lines to delete."
806 (interactive "*p")
807 (edt-check-prefix num)
808 (let ((beg (point)))
809 (forward-char 1)
810 (end-of-line num)
811 (setq edt-last-deleted-lines
812 (buffer-substring beg (point)))
813 (delete-region beg (point))))
814
815 ;;;
816 ;;; SELECT
817 ;;;
818
819 (defun edt-select-mode (arg)
820 "Turn EDT select mode off if ARG is nil; otherwise, turn EDT select mode on.
821 In select mode, selected text is highlighted."
822 (if arg
823 (progn
824 (set (make-local-variable 'edt-select-mode) 'edt-select-mode-current)
825 (setq rect-start-point (window-point)))
826 (progn
827 (kill-local-variable 'edt-select-mode)))
828 (force-mode-line-update))
829
830 (defun edt-select ()
831 "Set mark at cursor and start text selection."
832 (interactive)
833 (set-mark-command nil))
834
835 (defun edt-reset ()
836 "Cancel text selection."
837 (interactive)
838 (if (featurep 'emacs)
839 (deactivate-mark)
840 (zmacs-deactivate-region)))
841
842 ;;;
843 ;;; CUT
844 ;;;
845
846 (defun edt-cut ()
847 "Deletes selected text but copies to kill ring."
848 (interactive "*")
849 (edt-check-selection)
850 (kill-region (mark) (point))
851 (message "Selected text CUT to kill ring"))
852
853 ;;;
854 ;;; DELETE TO BEGINNING OF LINE
855 ;;;
856
857 (defun edt-delete-to-beginning-of-line (num)
858 "Delete from cursor to beginning of line.
859 Argument NUM is the number of lines to delete."
860 (interactive "*p")
861 (edt-check-prefix num)
862 (let ((beg (point)))
863 (edt-beginning-of-line num)
864 (setq edt-last-deleted-lines
865 (buffer-substring (point) beg))
866 (delete-region beg (point))))
867
868 ;;;
869 ;;; DEL W
870 ;;;
871
872 (defun edt-delete-word (num)
873 "Delete from cursor up to but excluding first character of next word.
874 Argument NUM is the number of words to delete."
875 (interactive "*p")
876 (edt-check-prefix num)
877 (let ((beg (point)))
878 (edt-word-forward num)
879 (setq edt-last-deleted-words (buffer-substring beg (point)))
880 (delete-region beg (point))))
881
882 ;;;
883 ;;; DELETE TO BEGINNING OF WORD
884 ;;;
885
886 (defun edt-delete-to-beginning-of-word (num)
887 "Delete from cursor to beginning of word.
888 Argument NUM is the number of words to delete."
889 (interactive "*p")
890 (edt-check-prefix num)
891 (let ((beg (point)))
892 (edt-word-backward num)
893 (setq edt-last-deleted-words (buffer-substring (point) beg))
894 (delete-region beg (point))))
895
896 ;;;
897 ;;; DEL C
898 ;;;
899
900 (defun edt-delete-character (num)
901 "Delete character under cursor.
902 Argument NUM is the number of characters to delete."
903 (interactive "*p")
904 (edt-check-prefix num)
905 (setq edt-last-deleted-chars
906 (buffer-substring (point) (min (point-max) (+ (point) num))))
907 (delete-region (point) (min (point-max) (+ (point) num))))
908
909 ;;;
910 ;;; DELETE CHAR
911 ;;;
912
913 (defun edt-delete-previous-character (num)
914 "Delete character in front of cursor.
915 Argument NUM is the number of characters to delete."
916 (interactive "*p")
917 (edt-check-prefix num)
918 (setq edt-last-deleted-chars
919 (buffer-substring (max (point-min) (- (point) num)) (point)))
920 (delete-region (max (point-min) (- (point) num)) (point)))
921
922 ;;;
923 ;;; UND L
924 ;;;
925
926 (defun edt-undelete-line ()
927 "Undelete previous deleted line(s)."
928 (interactive "*")
929 (point-to-register 1)
930 (insert edt-last-deleted-lines)
931 (register-to-point 1))
932
933 ;;;
934 ;;; UND W
935 ;;;
936
937 (defun edt-undelete-word ()
938 "Undelete previous deleted word(s)."
939 (interactive "*")
940 (point-to-register 1)
941 (insert edt-last-deleted-words)
942 (register-to-point 1))
943
944 ;;;
945 ;;; UND C
946 ;;;
947
948 (defun edt-undelete-character ()
949 "Undelete previous deleted character(s)."
950 (interactive "*")
951 (point-to-register 1)
952 (insert edt-last-deleted-chars)
953 (register-to-point 1))
954
955 ;;;
956 ;;; REPLACE
957 ;;;
958
959 (defun edt-replace ()
960 "Replace marked section with last CUT (killed) text."
961 (interactive "*")
962 (if (edt-check-match)
963 (replace-match (car kill-ring-yank-pointer))
964 (progn
965 (exchange-point-and-mark)
966 (let ((beg (point)))
967 (exchange-point-and-mark)
968 (delete-region beg (point)))
969 (yank))))
970
971 ;;;
972 ;;; SUBS
973 ;;;
974
975 (defun edt-substitute (num)
976 "Replace the selected region with the contents of the CUT buffer and.
977 Repeat the most recent FIND command. (The Emacs kill ring is used as
978 the CUT buffer.)
979 Argument NUM is the repeat count. A positive value indicates the of times
980 to repeat the substitution. A negative argument means replace all occurrences
981 of the search text."
982 (interactive "p")
983 (cond ((or edt-select-mode (edt-check-match))
984 (while (and (not (= num 0)) (or edt-select-mode (edt-check-match)))
985 (edt-replace)
986 (edt-find-next)
987 (setq num (1- num))))
988 (t
989 (error "No selection active"))))
990
991 (defun edt-set-match nil
992 "Set markers at match beginning and end."
993 ;; Add one to beginning mark so it stays with the first character of
994 ;; the string even if characters are added just before the string.
995 (setq edt-match-beginning-mark (copy-marker (1+ (match-beginning 0))))
996 (setq edt-match-end-mark (copy-marker (match-end 0))))
997
998 (defun edt-unset-match nil
999 "Unset match beginning and end markers."
1000 (set-marker edt-match-beginning-mark nil)
1001 (set-marker edt-match-end-mark nil))
1002
1003 (defun edt-match-beginning nil
1004 "Return the location of the last match beginning."
1005 (1- (marker-position edt-match-beginning-mark)))
1006
1007 (defun edt-match-end nil
1008 "Return the location of the last match end."
1009 (marker-position edt-match-end-mark))
1010
1011 (defun edt-check-match nil
1012 "Return t if point is between edt-match markers.
1013 Otherwise sets the edt-match markers to nil and returns nil."
1014 ;; make sure 1- marker is in this buffer
1015 ;; 2- point is at or after beginning marker
1016 ;; 3- point is before ending marker, or in the case of
1017 ;; zero length regions (like bol, or eol) that the
1018 ;; beginning, end, and point are equal.
1019 (cond ((and
1020 (equal (marker-buffer edt-match-beginning-mark) (current-buffer))
1021 (>= (point) (1- (marker-position edt-match-beginning-mark)))
1022 (or
1023 (< (point) (marker-position edt-match-end-mark))
1024 (and (= (1- (marker-position edt-match-beginning-mark))
1025 (marker-position edt-match-end-mark))
1026 (= (marker-position edt-match-end-mark) (point))))) t)
1027 (t
1028 (edt-unset-match) nil)))
1029
1030 (defun edt-show-match-markers nil
1031 "Show the values of the match markers."
1032 (interactive)
1033 (if (markerp edt-match-beginning-mark)
1034 (let ((beg (marker-position edt-match-beginning-mark)))
1035 (message "(%s, %s) in %s -- current %s in %s"
1036 (if beg (1- beg) nil)
1037 (marker-position edt-match-end-mark)
1038 (marker-buffer edt-match-end-mark)
1039 (point) (current-buffer)))))
1040
1041
1042 ;;;
1043 ;;; ADVANCE
1044 ;;;
1045
1046 (defun edt-advance ()
1047 "Set movement direction forward.
1048 Also, execute command specified if in Minibuffer."
1049 (interactive)
1050 (setq edt-direction-string edt-forward-string)
1051 (force-mode-line-update)
1052 (if (string-equal " *Minibuf"
1053 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1054 (exit-minibuffer))
1055 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1056
1057
1058 ;;;
1059 ;;; BACKUP
1060 ;;;
1061
1062 (defun edt-backup ()
1063 "Set movement direction backward.
1064 Also, execute command specified if in Minibuffer."
1065 (interactive)
1066 (setq edt-direction-string edt-backward-string)
1067 (force-mode-line-update)
1068 (if (string-equal " *Minibuf"
1069 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1070 (exit-minibuffer))
1071 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1072
1073
1074 ;;;
1075 ;;; CHNGCASE
1076 ;;;
1077 ;; This function is based upon Jeff Kowalski's case-flip function in his
1078 ;; tpu.el.
1079
1080 (defun edt-change-case (num)
1081 "Change the case of specified characters.
1082 If text selection IS active, then characters between the cursor and mark are
1083 changed. If text selection is NOT active, there are two cases. First, if the
1084 current direction is ADVANCE, then the prefix number of character(s) under and
1085 following cursor are changed. Second, if the current direction is BACKUP, then
1086 the prefix number of character(s) before the cursor are changed. Accepts a
1087 positive prefix for the number of characters to change, but the prefix is
1088 ignored if text selection is active.
1089 Argument NUM is the numbers of consecutive characters to change."
1090 (interactive "*p")
1091 (edt-check-prefix num)
1092 (if edt-select-mode
1093 (let ((end (max (mark) (point)))
1094 (point-save (point)))
1095 (goto-char (min (point) (mark)))
1096 (while (not (eq (point) end))
1097 (funcall (if (<= ?a (following-char))
1098 'upcase-region 'downcase-region)
1099 (point) (1+ (point)))
1100 (forward-char 1))
1101 (goto-char point-save))
1102 (progn
1103 (if (string= edt-direction-string edt-backward-string)
1104 (backward-char num))
1105 (while (> num 0)
1106 (funcall (if (<= ?a (following-char))
1107 'upcase-region 'downcase-region)
1108 (point) (1+ (point)))
1109 (forward-char 1)
1110 (setq num (1- num))))))
1111
1112 ;;;
1113 ;;; DEFINE KEY
1114 ;;;
1115
1116 (defun edt-define-key ()
1117 "Assign an interactively-callable function to a specified key sequence.
1118 The current key definition is saved in `edt-last-replaced-key-definition'.
1119 Use `edt-restore-key' to restore last replaced key definition."
1120 (interactive)
1121 (if (featurep 'xemacs) (setq zmacs-region-stays t))
1122 (let (edt-function
1123 edt-key-definition)
1124 (setq edt-key-definition
1125 (read-key-sequence "Press the key to be defined: "))
1126 (if (if (featurep 'emacs)
1127 (string-equal "\C-m" edt-key-definition)
1128 (string-equal "\C-m" (events-to-keys edt-key-definition)))
1129 (message "Key not defined")
1130 (progn
1131 (setq edt-function (read-command "Enter command name: "))
1132 (if (string-equal "" edt-function)
1133 (message "Key not defined")
1134 (progn
1135 (setq edt-last-replaced-key-definition
1136 (lookup-key (current-global-map) edt-key-definition))
1137 (define-key (current-global-map)
1138 edt-key-definition edt-function)))))))
1139
1140 ;;;
1141 ;;; FORM FEED INSERT
1142 ;;;
1143
1144 (defun edt-form-feed-insert (num)
1145 "Insert form feed character at cursor position.
1146 Argument NUM is the number of form feeds to insert."
1147 (interactive "*p")
1148 (edt-check-prefix num)
1149 (while (> num 0)
1150 (insert ?\f)
1151 (setq num (1- num))))
1152
1153 ;;;
1154 ;;; TAB INSERT
1155 ;;;
1156
1157 (defun edt-tab-insert (num)
1158 "Insert tab character at cursor position.
1159 Argument NUM is the number of tabs to insert."
1160 (interactive "*p")
1161 (edt-check-prefix num)
1162 (while (> num 0)
1163 (insert ?\t)
1164 (setq num (1- num))))
1165
1166 ;;;
1167 ;;; Check Prefix
1168 ;;;
1169
1170 (defun edt-check-prefix (num)
1171 "Indicate error if prefix is not positive.
1172 Argument NUM is the prefix value tested."
1173 (if (<= num 0)
1174 (error "Prefix must be positive")))
1175
1176 ;;;
1177 ;;; Check Selection
1178 ;;;
1179
1180 (defun edt-check-selection ()
1181 "Indicate error if EDT selection is not active."
1182 (if (not edt-select-mode)
1183 (error "Selection NOT active")))
1184
1185 ;;;
1186 ;;; Scroll Margins
1187 ;;;
1188
1189 (defun edt-top-check (beg lines)
1190 "Enforce scroll margin at the top of screen.
1191 Argument BEG is the starting line number before cursor was moved.
1192 Argument LINES is the number of lines the cursor moved toward the top."
1193 (let ((margin (/ (* (window-height) edt-top-scroll-margin) 100)))
1194 (cond ((< beg margin) (recenter beg))
1195 ((< (- beg lines) margin) (recenter margin)))))
1196
1197 (defun edt-bottom-check (beg lines)
1198 "Enforce scroll margin at the bottom of screen.
1199 Argument BEG is the starting line number before cursor was moved.
1200 Argument LINES is the number of lines the cursor moved toward the bottom."
1201 (let* ((height (window-height))
1202 (margin (+ 1 (/ (* height edt-bottom-scroll-margin) 100)))
1203 ;; subtract 1 from height because it includes mode line
1204 (difference (- height margin 1)))
1205 (cond ((> beg difference) (recenter beg))
1206 ((and (featurep 'xemacs) (> (+ beg lines 1) difference))
1207 (recenter (- margin)))
1208 ((> (+ beg lines) difference) (recenter (- margin))))))
1209
1210 (defun edt-current-line nil
1211 "Return the vertical position of point in the selected window.
1212 Top line is 0. Counts each text line only once, even if it wraps."
1213 (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -1))
1214
1215 ;;;###autoload
1216 (defun edt-set-scroll-margins (top bottom)
1217 "Set scroll margins.
1218 Argument TOP is the top margin in number of lines or percent of window.
1219 Argument BOTTOM is the bottom margin in number of lines or percent of window."
1220 (interactive
1221 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \
1222 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
1223 ;; set top scroll margin
1224 (or (string= top "")
1225 (if (string= "%" (substring top -1))
1226 (setq edt-top-scroll-margin (string-to-number top))
1227 (setq edt-top-scroll-margin
1228 (/ (1- (+ (* (string-to-number top) 100) (window-height)))
1229 (window-height)))))
1230 ;; set bottom scroll margin
1231 (or (string= bottom "")
1232 (if (string= "%" (substring bottom -1))
1233 (setq edt-bottom-scroll-margin (string-to-number bottom))
1234 (setq edt-bottom-scroll-margin
1235 (/ (1- (+ (* (string-to-number bottom) 100) (window-height)))
1236 (window-height)))))
1237 ;; report scroll margin settings if running interactively
1238 (and (called-interactively-p 'interactive)
1239 (message "Scroll margins set. Top = %s%%, Bottom = %s%%"
1240 edt-top-scroll-margin edt-bottom-scroll-margin)))
1241
1242 \f
1243 ;;;;
1244 ;;;; ENHANCEMENTS AND ADDITIONS FOR EDT KEYPAD MODE
1245 ;;;;
1246
1247 ;;;
1248 ;;; Several enhancements and additions to EDT keypad mode commands are
1249 ;;; provided here. Some of these have been motivated by similar
1250 ;;; TPU/EVE and EVE-Plus commands. Others are new.
1251
1252 ;;;
1253 ;;; CHANGE DIRECTION
1254 ;;;
1255
1256 (defun edt-change-direction ()
1257 "Toggle movement direction."
1258 (interactive)
1259 (if (equal edt-direction-string edt-forward-string)
1260 (edt-backup)
1261 (edt-advance)))
1262
1263 ;;;
1264 ;;; TOGGLE SELECT
1265 ;;;
1266
1267 (defun edt-toggle-select ()
1268 "Toggle to start (or cancel) text selection."
1269 (interactive)
1270 (if edt-select-mode
1271 (edt-reset)
1272 (edt-select)))
1273
1274 ;;;
1275 ;;; SENTENCE
1276 ;;;
1277
1278 (defun edt-sentence-forward (num)
1279 "Move forward to start of next sentence.
1280 Argument NUM is the positive number of sentences to move."
1281 (interactive "p")
1282 (edt-check-prefix num)
1283 (edt-with-position
1284 (if (eobp)
1285 (error "End of buffer")
1286 (forward-sentence num)
1287 (forward-word 1)
1288 (backward-sentence))
1289 (if (> (point) far)
1290 (if (zerop (setq left (save-excursion (forward-line height))))
1291 (recenter top-margin)
1292 (recenter (- left bottom-up-margin)))
1293 (and (> (point) bottom) (recenter bottom-margin))))
1294 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1295
1296 (defun edt-sentence-backward (num)
1297 "Move backward to next sentence beginning.
1298 Argument NUM is the positive number of sentences to move."
1299 (interactive "p")
1300 (edt-check-prefix num)
1301 (edt-with-position
1302 (if (eobp)
1303 (error "End of buffer")
1304 (backward-sentence num))
1305 (and (< (point) top) (recenter (min beg top-margin))))
1306 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1307
1308 (defun edt-sentence (num)
1309 "Move in current direction to next sentence.
1310 Argument NUM is the positive number of sentences to move."
1311 (interactive "p")
1312 (if (equal edt-direction-string edt-forward-string)
1313 (edt-sentence-forward num)
1314 (edt-sentence-backward num)))
1315
1316 ;;;
1317 ;;; PARAGRAPH
1318 ;;;
1319
1320 (defun edt-paragraph-forward (num)
1321 "Move forward to beginning of paragraph.
1322 Argument NUM is the positive number of paragraphs to move."
1323 (interactive "p")
1324 (edt-check-prefix num)
1325 (edt-with-position
1326 (while (> num 0)
1327 (forward-paragraph (+ num 1))
1328 (start-of-paragraph-text)
1329 (if (eolp)
1330 (forward-line 1))
1331 (setq num (1- num)))
1332 (if (> (point) far)
1333 (if (zerop (setq left (save-excursion (forward-line height))))
1334 (recenter top-margin)
1335 (recenter (- left bottom-up-margin)))
1336 (and (> (point) bottom) (recenter bottom-margin))))
1337 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1338
1339 (defun edt-paragraph-backward (num)
1340 "Move backward to beginning of paragraph.
1341 Argument NUM is the positive number of paragraphs to move."
1342 (interactive "p")
1343 (edt-check-prefix num)
1344 (edt-with-position
1345 (while (> num 0)
1346 (start-of-paragraph-text)
1347 (setq num (1- num)))
1348 (and (< (point) top) (recenter (min beg top-margin))))
1349 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1350
1351 (defun edt-paragraph (num)
1352 "Move in current direction to next paragraph.
1353 Argument NUM is the positive number of paragraphs to move."
1354 (interactive "p")
1355 (if (equal edt-direction-string edt-forward-string)
1356 (edt-paragraph-forward num)
1357 (edt-paragraph-backward num)))
1358
1359 ;;;
1360 ;;; RESTORE KEY
1361 ;;;
1362
1363 (defun edt-restore-key ()
1364 "Restore last replaced key definition.
1365 Definition is stored in `edt-last-replaced-key-definition'."
1366 (interactive)
1367 (if (featurep 'xemacs) (setq zmacs-region-stays t))
1368 (if edt-last-replaced-key-definition
1369 (progn
1370 (let (edt-key-definition)
1371 (set 'edt-key-definition
1372 (read-key-sequence "Press the key to be restored: "))
1373 (if (if (featurep 'emacs)
1374 (string-equal "\C-m" edt-key-definition)
1375 (string-equal "\C-m" (events-to-keys edt-key-definition)))
1376 (message "Key not restored")
1377 (progn
1378 (define-key (current-global-map)
1379 edt-key-definition edt-last-replaced-key-definition)
1380 (if (featurep 'emacs)
1381 (message "Key definition for %s has been restored."
1382 edt-key-definition)
1383 (message "Key definition for %s has been restored."
1384 (events-to-keys edt-key-definition)))))))
1385 (error "No replaced key definition to restore!")))
1386
1387 ;;;
1388 ;;; WINDOW TOP
1389 ;;;
1390
1391 (defun edt-window-top ()
1392 "Move the cursor to the top of the window."
1393 (interactive)
1394 (let ((start-column (current-column)))
1395 (move-to-window-line 0)
1396 (move-to-column start-column))
1397 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1398
1399 ;;;
1400 ;;; WINDOW BOTTOM
1401 ;;;
1402
1403 (defun edt-window-bottom ()
1404 "Move the cursor to the bottom of the window."
1405 (interactive)
1406 (let ((start-column (current-column)))
1407 (move-to-window-line (- (window-height) 2))
1408 (move-to-column start-column))
1409 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1410
1411 ;;;
1412 ;;; SCROLL WINDOW LINE
1413 ;;;
1414
1415 (defun edt-scroll-window-forward-line ()
1416 "Move window forward one line leaving cursor at position in window."
1417 (interactive)
1418 (scroll-up 1)
1419 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1420
1421 (defun edt-scroll-window-backward-line ()
1422 "Move window backward one line leaving cursor at position in window."
1423 (interactive)
1424 (scroll-down 1)
1425 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1426
1427 (defun edt-scroll-line ()
1428 "Move window one line in current direction."
1429 (interactive)
1430 (if (equal edt-direction-string edt-forward-string)
1431 (edt-scroll-window-forward-line)
1432 (edt-scroll-window-backward-line)))
1433
1434 ;;;
1435 ;;; SCROLL WINDOW
1436 ;;;
1437 ;;; Scroll a window (less one line) at a time. Leave cursor in center of
1438 ;;; window.
1439
1440 (defun edt-scroll-window-forward (num)
1441 "Scroll forward one window in buffer, less one line.
1442 Argument NUM is the positive number of windows to move."
1443 (interactive "p")
1444 (edt-check-prefix num)
1445 (scroll-up (- (* (window-height) num) 2))
1446 (edt-line-forward (/ (- (window-height) 1) 2)))
1447
1448 (defun edt-scroll-window-backward (num)
1449 "Scroll backward one window in buffer, less one line.
1450 Argument NUM is the positive number of windows to move."
1451 (interactive "p")
1452 (edt-check-prefix num)
1453 (scroll-down (- (* (window-height) num) 2))
1454 (edt-line-backward (/ (- (window-height) 1) 2)))
1455
1456 (defun edt-scroll-window (num)
1457 "Scroll one window in buffer, less one line, in current direction.
1458 Argument NUM is the positive number of windows to move."
1459 (interactive "p")
1460 (if (equal edt-direction-string edt-forward-string)
1461 (edt-scroll-window-forward num)
1462 (edt-scroll-window-backward num)))
1463
1464 ;;;
1465 ;;; LINE TO BOTTOM OF WINDOW
1466 ;;;
1467
1468 (defun edt-line-to-bottom-of-window ()
1469 "Move the current line to the bottom of the window."
1470 (interactive)
1471 (recenter -1)
1472 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1473
1474 ;;;
1475 ;;; LINE TO TOP OF WINDOW
1476 ;;;
1477
1478 (defun edt-line-to-top-of-window ()
1479 "Move the current line to the top of the window."
1480 (interactive)
1481 (recenter 0)
1482 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1483
1484 ;;;
1485 ;;; LINE TO MIDDLE OF WINDOW
1486 ;;;
1487
1488 (defun edt-line-to-middle-of-window ()
1489 "Move window so line with cursor is in the middle of the window."
1490 (interactive)
1491 (recenter '(4))
1492 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1493
1494 ;;;
1495 ;;; GOTO PERCENTAGE
1496 ;;;
1497
1498 (defun edt-goto-percentage (num)
1499 "Move to specified percentage in buffer from top of buffer.
1500 Argument NUM is the percentage into the buffer to move."
1501 (interactive "NGoto-percentage: ")
1502 (if (or (> num 100) (< num 0))
1503 (error "Percentage %d out of range 0 < percent < 100" num)
1504 (goto-char (/ (* (point-max) num) 100)))
1505 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1506
1507 ;;;
1508 ;;; FILL REGION
1509 ;;;
1510
1511 (defun edt-fill-region ()
1512 "Fill selected text."
1513 (interactive "*")
1514 (edt-check-selection)
1515 (fill-region (point) (mark)))
1516
1517 ;;;
1518 ;;; INDENT OR FILL REGION
1519 ;;;
1520
1521 (defun edt-indent-or-fill-region ()
1522 "Fill region in text modes, indent region in programming language modes."
1523 (interactive "*")
1524 (if (string= paragraph-start "$\\|\f")
1525 (indent-region (point) (mark) nil)
1526 (fill-region (point) (mark))))
1527
1528
1529 (declare-function c-mark-function "cc-cmds" ())
1530 ;;;
1531 ;;; MARK SECTION WISELY
1532 ;;;
1533
1534 (defun edt-mark-section-wisely ()
1535 "Mark the section in a manner consistent with the `major-mode'.
1536 Uses `mark-defun' for Emacs-Lisp and Lisp, and for Fortran,
1537 `c-mark-function' for C,
1538 and `mark-paragraph' for other modes."
1539 (interactive)
1540 (if edt-select-mode
1541 (progn
1542 (edt-reset))
1543 (progn
1544 (cond ((or (eq major-mode 'emacs-lisp-mode)
1545 (eq major-mode 'fortran-mode)
1546 (eq major-mode 'lisp-mode))
1547 (mark-defun)
1548 (message "Lisp defun selected"))
1549 ((eq major-mode 'c-mode)
1550 (c-mark-function)
1551 (message "C function selected"))
1552 (t (mark-paragraph)
1553 (message "Paragraph selected"))))))
1554
1555 ;;;
1556 ;;; COPY
1557 ;;;
1558
1559 (defun edt-copy ()
1560 "Copy selected region to kill ring, but don't delete it!"
1561 (interactive)
1562 (edt-check-selection)
1563 (copy-region-as-kill (mark) (point))
1564 (edt-reset)
1565 (message "Selected text COPIED to kill ring"))
1566
1567 ;;;
1568 ;;; CUT or COPY
1569 ;;;
1570
1571 (defun edt-cut-or-copy ()
1572 "Cuts (or copies) selected text to kill ring.
1573 Cuts selected text if `buffer-read-only' is nil.
1574 Copies selected text if `buffer-read-only' is t."
1575 (interactive)
1576 (if buffer-read-only
1577 (edt-copy)
1578 (edt-cut)))
1579
1580 ;;;
1581 ;;; DELETE ENTIRE LINE
1582 ;;;
1583
1584 (defun edt-delete-entire-line ()
1585 "Delete entire line regardless of cursor position in the line."
1586 (interactive "*")
1587 (beginning-of-line)
1588 (edt-delete-line 1))
1589
1590 ;;;
1591 ;;; DUPLICATE LINE
1592 ;;;
1593
1594 (defun edt-duplicate-line (num)
1595 "Duplicate the line of text containing the cursor.
1596 Argument NUM is the number of times to duplicate the line."
1597 (interactive "*p")
1598 (edt-check-prefix num)
1599 (let ((old-column (current-column))
1600 (count num))
1601 (edt-delete-entire-line)
1602 (edt-undelete-line)
1603 (while (> count 0)
1604 (edt-undelete-line)
1605 (setq count (1- count)))
1606 (edt-line-forward num)
1607 (move-to-column old-column)))
1608
1609 ;;;
1610 ;;; DUPLICATE WORD
1611 ;;;
1612
1613 (defun edt-duplicate-word()
1614 "Duplicate word (or rest of word) found directly above cursor, if any."
1615 (interactive "*")
1616 (let ((start (point))
1617 (start-column (current-column)))
1618 (forward-line -1)
1619 (move-to-column start-column)
1620 (if (and (not (equal start (point)))
1621 (not (eolp)))
1622 (progn
1623 (if (and (equal ?\t (preceding-char))
1624 (< start-column (current-column)))
1625 (backward-char))
1626 (let ((beg (point)))
1627 (edt-one-word-forward)
1628 (setq edt-last-copied-word (buffer-substring beg (point))))
1629 (forward-line)
1630 (move-to-column start-column)
1631 (insert edt-last-copied-word))
1632 (progn
1633 (if (not (equal start (point)))
1634 (forward-line))
1635 (move-to-column start-column)
1636 (error "Nothing to duplicate!")))))
1637
1638 ;;;
1639 ;;; KEY NOT ASSIGNED
1640 ;;;
1641
1642 (defun edt-key-not-assigned ()
1643 "Displays message that key has not been assigned to a function."
1644 (interactive)
1645 (error "Key not assigned"))
1646
1647 ;;;
1648 ;;; TOGGLE CAPITALIZATION OF WORD
1649 ;;;
1650
1651 (defun edt-toggle-capitalization-of-word ()
1652 "Toggle the capitalization of the current word and move forward to next."
1653 (interactive "*")
1654 (edt-one-word-forward)
1655 (edt-one-word-backward)
1656 (edt-change-case 1)
1657 (edt-one-word-backward)
1658 (edt-one-word-forward))
1659
1660 ;;;
1661 ;;; ELIMINATE ALL TABS
1662 ;;;
1663
1664 (defun edt-eliminate-all-tabs ()
1665 "Convert all tabs to spaces in the entire buffer."
1666 (interactive "*")
1667 (untabify (point-min) (point-max))
1668 (message "TABS converted to SPACES"))
1669
1670 ;;;
1671 ;;; DISPLAY THE TIME
1672 ;;;
1673
1674 (defun edt-display-the-time ()
1675 "Display the current time."
1676 (interactive)
1677 (if (featurep 'xemacs) (setq zmacs-region-stays t))
1678 (message "%s" (current-time-string)))
1679
1680 ;;;
1681 ;;; LEARN
1682 ;;;
1683
1684 (defun edt-learn ()
1685 "Learn a sequence of key strokes to bind to a key."
1686 (interactive)
1687 (if (eq defining-kbd-macro t)
1688 (edt-remember)
1689 (start-kbd-macro nil)))
1690
1691 ;;;
1692 ;;; REMEMBER
1693 ;;;
1694
1695 (defun edt-remember ()
1696 "Store the sequence of key strokes started by `edt-learn' to a key."
1697 (interactive)
1698 (if (eq defining-kbd-macro nil)
1699 (error "Nothing to remember!")
1700 (progn
1701 (end-kbd-macro nil)
1702 (let (edt-key-definition)
1703 (set 'edt-key-definition
1704 (read-key-sequence "Enter key for binding: "))
1705 (if (if (featurep 'emacs)
1706 (string-equal "\C-m" edt-key-definition)
1707 (string-equal "\C-m" (events-to-keys edt-key-definition)))
1708 (message "Key sequence not remembered")
1709 (progn
1710 (set 'edt-learn-macro-count (+ edt-learn-macro-count 1))
1711 (setq edt-last-replaced-key-definition
1712 (lookup-key (current-global-map)
1713 edt-key-definition))
1714 (define-key (current-global-map) edt-key-definition
1715 (name-last-kbd-macro
1716 (intern (concat "last-learned-sequence-"
1717 (int-to-string edt-learn-macro-count)))))))))))
1718
1719 ;;;
1720 ;;; EXIT
1721 ;;;
1722
1723 (defun edt-exit ()
1724 "Save current buffer, ask to save other buffers, and then exit Emacs."
1725 (interactive)
1726 (save-buffer)
1727 (save-buffers-kill-emacs))
1728
1729 ;;;
1730 ;;; QUIT
1731 ;;;
1732
1733 (defun edt-quit ()
1734 "Quit Emacs without saving buffer modifications.
1735 Warn user that modifications will be lost."
1736 (interactive)
1737 (let ((list (buffer-list))
1738 (working t))
1739 (while (and list working)
1740 (let ((buffer (car list)))
1741 (if (and (buffer-file-name buffer) (buffer-modified-p buffer))
1742 (if (edt-y-or-n-p
1743 "Modifications will not be saved, continue quitting? ")
1744 (kill-emacs)
1745 (setq working nil)))
1746 (setq list (cdr list))))
1747 (if working (kill-emacs))))
1748
1749 ;;;
1750 ;;; SPLIT WINDOW
1751 ;;;
1752
1753 (defun edt-split-window ()
1754 "Split current window and place cursor in the new window."
1755 (interactive)
1756 (split-window)
1757 (other-window 1)
1758 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1759
1760 ;;;
1761 ;;; COPY RECTANGLE
1762 ;;;
1763
1764 (defun edt-copy-rectangle ()
1765 "Copy a rectangle of text between mark and cursor to register."
1766 (interactive)
1767 (edt-check-selection)
1768 (copy-rectangle-to-register 3 (region-beginning) (region-end) nil)
1769 (edt-reset)
1770 (message "Selected rectangle COPIED to register"))
1771
1772 ;;;
1773 ;;; CUT RECTANGLE
1774 ;;;
1775
1776 (defun edt-cut-rectangle-overstrike-mode ()
1777 "Cut a rectangle of text between mark and cursor to register.
1778 Replace cut characters with spaces and moving cursor back to
1779 upper left corner."
1780 (interactive "*")
1781 (edt-check-selection)
1782 (setq edt-rect-start-point (region-beginning))
1783 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3)
1784 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point)
1785 (message "Selected rectangle CUT to register"))
1786
1787 (defun edt-cut-rectangle-insert-mode ()
1788 "Cut a rectangle of text between mark and cursor to register.
1789 Move cursor back to upper left corner."
1790 (interactive "*")
1791 (edt-check-selection)
1792 (setq edt-rect-start-point (region-beginning))
1793 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3 t)
1794 (fixup-whitespace)
1795 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point)
1796 (message "Selected rectangle CUT to register"))
1797
1798 (defun edt-cut-rectangle ()
1799 "Cut a rectangular region of text to register.
1800 If overwrite mode is active, cut text is replaced with whitespace."
1801 (interactive "*")
1802 (if overwrite-mode
1803 (edt-cut-rectangle-overstrike-mode)
1804 (edt-cut-rectangle-insert-mode)))
1805
1806 ;;;
1807 ;;; PASTE RECTANGLE
1808 ;;;
1809
1810 (defun edt-paste-rectangle-overstrike-mode ()
1811 "Paste a rectangular region of text from register, replacing text at cursor."
1812 (interactive "*")
1813 (picture-yank-rectangle-from-register 3))
1814
1815 (defun edt-paste-rectangle-insert-mode ()
1816 "Paste previously deleted rectangular region, inserting text at cursor."
1817 (interactive "*")
1818 (picture-yank-rectangle-from-register 3 t))
1819
1820 (defun edt-paste-rectangle ()
1821 "Paste a rectangular region of text.
1822 If overwrite mode is active, existing text is replace with text from register."
1823 (interactive)
1824 (if overwrite-mode
1825 (edt-paste-rectangle-overstrike-mode)
1826 (edt-paste-rectangle-insert-mode)))
1827
1828 ;;;
1829 ;;; DOWNCASE REGION
1830 ;;;
1831
1832 (defun edt-lowercase ()
1833 "Change specified characters to lower case.
1834 If text selection IS active, then characters between the cursor and
1835 mark are changed. If text selection is NOT active, there are two
1836 situations. If the current direction is ADVANCE, then the word under
1837 the cursor is changed to lower case and the cursor is moved to rest at
1838 the beginning of the next word. If the current direction is BACKUP,
1839 the word prior to the word under the cursor is changed to lower case
1840 and the cursor is left to rest at the beginning of that word."
1841 (interactive "*")
1842 (if edt-select-mode
1843 (progn
1844 (downcase-region (mark) (point)))
1845 (progn
1846 ;; Move to beginning of current word.
1847 (if (and
1848 (not (bobp))
1849 (not (eobp))
1850 (not (bolp))
1851 (not (eolp))
1852 (not (eq ?\ (char-syntax (preceding-char))))
1853 (not (memq (preceding-char) edt-word-entities))
1854 (not (memq (following-char) edt-word-entities)))
1855 (edt-one-word-backward))
1856 (if (equal edt-direction-string edt-backward-string)
1857 (edt-one-word-backward))
1858 (let ((beg (point)))
1859 (edt-one-word-forward)
1860 (downcase-region beg (point)))
1861 (if (equal edt-direction-string edt-backward-string)
1862 (edt-one-word-backward)))))
1863
1864 ;;;
1865 ;;; UPCASE REGION
1866 ;;;
1867
1868 (defun edt-uppercase ()
1869 "Change specified characters to upper case.
1870 If text selection IS active, then characters between the cursor and
1871 mark are changed. If text selection is NOT active, there are two
1872 situations. If the current direction is ADVANCE, then the word under
1873 the cursor is changed to upper case and the cursor is moved to rest at
1874 the beginning of the next word. If the current direction is BACKUP,
1875 the word prior to the word under the cursor is changed to upper case
1876 and the cursor is left to rest at the beginning of that word."
1877 (interactive "*")
1878 (if edt-select-mode
1879 (progn
1880 (upcase-region (mark) (point)))
1881 (progn
1882 ;; Move to beginning of current word.
1883 (if (and
1884 (not (bobp))
1885 (not (eobp))
1886 (not (bolp))
1887 (not (eolp))
1888 (not (eq ?\ (char-syntax (preceding-char))))
1889 (not (memq (preceding-char) edt-word-entities))
1890 (not (memq (following-char) edt-word-entities)))
1891 (edt-one-word-backward))
1892 (if (equal edt-direction-string edt-backward-string)
1893 (edt-one-word-backward))
1894 (let ((beg (point)))
1895 (edt-one-word-forward)
1896 (upcase-region beg (point)))
1897 (if (equal edt-direction-string edt-backward-string)
1898 (edt-one-word-backward)))))
1899
1900 ;;;
1901 ;;; Functions used in loading LK-201 key mapping file.
1902 ;;;
1903 (defvar edt-last-answer nil
1904 "Most recent response to `edt-y-or-n-p'.")
1905
1906 (defun edt-y-or-n-p (prompt &optional not-yes)
1907 "Prompt for a y or n answer with positive default.
1908 Like Emacs `y-or-n-p', also accepts space as y and DEL as n.
1909 Argument PROMPT is the prompt string.
1910 Optional argument NOT-YES changes the default to negative."
1911 (message "%s[%s]" prompt (if not-yes "n" "y"))
1912 (let ((doit t))
1913 (while doit
1914 (setq doit nil)
1915 (let ((ans (read-char)))
1916 (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\ ))
1917 (setq edt-last-answer t))
1918 ((or (= ans ?n) (= ans ?N) (= ans ?\C-?))
1919 (setq edt-last-answer nil))
1920 ((= ans ?\r) (setq edt-last-answer (not not-yes)))
1921 (t
1922 (setq doit t) (beep)
1923 (message "Please answer y or n. %s[%s]"
1924 prompt (if not-yes "n" "y")))))))
1925 edt-last-answer)
1926 \f
1927 ;;;
1928 ;;; INITIALIZATION COMMANDS.
1929 ;;;
1930
1931 ;;;
1932 ;;; Function used to load LK-201 key mapping file generated by edt-mapper.el.
1933 ;;;
1934 (defun edt-load-keys (file)
1935 "Load the LK-201 key mapping FILE generated by edt-mapper.el.
1936 If FILE is nil, which is the normal case, try to load a default file.
1937 The default file names are based upon the window system, terminal
1938 type, and version of Emacs in use: GNU Emacs or XEmacs (aka Lucid
1939 Emacs). If a default file does not exist, ask user if one should be
1940 created."
1941 (interactive "fKey definition file: ")
1942 (cond (file
1943 (setq file (expand-file-name file)))
1944 (edt-keys-file
1945 (setq file (expand-file-name edt-keys-file)))
1946 (t
1947 (setq file
1948 (expand-file-name
1949 (concat
1950 "~/.edt-" edt-emacs-variant
1951 (if edt-term (concat "-" edt-term))
1952 (if edt-xserver (concat "-" edt-xserver))
1953 (if edt-window-system
1954 (concat "-" (upcase (symbol-name edt-window-system))))
1955 "-keys")))))
1956 (cond ((file-readable-p file)
1957 (load-file file))
1958 (t
1959 (switch-to-buffer "*scratch*")
1960 (erase-buffer)
1961 (insert "
1962
1963 Ack!! You're running the Enhanced EDT Emulation without loading an
1964 EDT key mapping file. To create an EDT key mapping file, run the
1965 edt-mapper program. It is safest to run it from an Emacs loaded
1966 without any of your own customizations found in your init file, etc.
1967 The reason for this is that some user customizations confuse edt-mapper.
1968 You can do this by quitting Emacs and then invoking Emacs again as
1969 follows:
1970
1971 emacs -q -l edt-mapper
1972
1973 [NOTE: If you do nothing out of the ordinary in your init file, and
1974 the search for edt-mapper is successful, you can try running it now.]
1975
1976 The library edt-mapper includes these same directions on how to
1977 use it! Perhaps it's lying around here someplace. \n ")
1978 (let ((path (locate-library
1979 "edt-mapper"
1980 nil (append (list default-directory) load-path))))
1981 (if path
1982 (progn
1983 (insert (format
1984 "Ah yes, there it is, in \n\n %s \n\n" path))
1985 (if (edt-y-or-n-p "Do you want to run it now? ")
1986 (load-file path)
1987 (error "EDT Emulation not configured")))
1988 (insert (substitute-command-keys
1989 "Nope, I can't seem to find it. :-(\n\n"))
1990 (sit-for 20)
1991 (error "EDT Emulation not configured"))))))
1992
1993 ;;;
1994 ;;; Turning the EDT Emulation on and off.
1995 ;;;
1996
1997 ;;;###autoload
1998 (defun edt-emulation-on ()
1999 "Turn on EDT Emulation."
2000 (interactive)
2001 ;; If using pc window system (MS-DOS), set terminal type to pc.
2002 ;; If not a window system (GNU) or a tty window system (XEmacs),
2003 ;; get terminal type.
2004 (if (eq edt-window-system 'pc)
2005 (setq edt-term "pc")
2006 (if (or (not edt-window-system) (eq edt-window-system 'tty))
2007 (setq edt-term (getenv "TERM"))))
2008 ;; Look for a terminal configuration file for this terminal type.
2009 ;; Otherwise, load the user's custom configuration file.
2010 (if (or (not edt-window-system) (memq edt-window-system '(pc tty)))
2011 (progn
2012 ;; Load terminal-specific configuration file, if it exists for this
2013 ;; terminal type. Note: All DEC VT series terminals are supported
2014 ;; by the same terminal configuration file: edt-vt100.el.
2015 (if (string-equal "vt" (substring edt-term 0 (min (length edt-term) 2)))
2016 (setq edt-term "vt100"))
2017 (let ((term edt-term)
2018 hyphend)
2019 (while (and term
2020 (not (load (concat "edt-" term) t t)))
2021 ;; Strip off last hyphen and what follows, then try again
2022 (if (setq hyphend (string-match "[-_][^-_]+$" term))
2023 (setq term (substring term 0 hyphend))
2024 (setq term nil)))
2025 ;; If no terminal-specific configuration file exists, load user's
2026 ;; custom EDT terminal configuration file.
2027 ;; If this is a pc running MS-DOS, then custom configuration files
2028 ;; are not supported. So, if the file is missing, issue an error
2029 ;; message.
2030 (if (null term)
2031 (if (equal edt-term "pc")
2032 (error "Unable to find EDT terminal specific file edt-pc.el")
2033 (edt-load-keys nil))
2034 (setq edt-term term))))
2035 (edt-load-keys nil))
2036 ;; Make highlighting of selected text work properly for EDT commands.
2037 (if (featurep 'emacs)
2038 (progn
2039 (setq edt-orig-transient-mark-mode
2040 (default-value 'transient-mark-mode))
2041 (add-hook 'activate-mark-hook
2042 (function
2043 (lambda ()
2044 (edt-select-mode t))))
2045 (add-hook 'deactivate-mark-hook
2046 (function
2047 (lambda ()
2048 (edt-select-mode nil)))))
2049 (progn
2050 (add-hook 'zmacs-activate-region-hook
2051 (function
2052 (lambda ()
2053 (edt-select-mode t))))
2054 (add-hook 'zmacs-deactivate-region-hook
2055 (function
2056 (lambda ()
2057 (edt-select-mode nil))))))
2058 ;; Load user's EDT custom key bindings file, if it exists.
2059 ;; Otherwise, use the default bindings.
2060 (if (load "edt-user" t t)
2061 (edt-user-emulation-setup)
2062 (edt-default-emulation-setup)))
2063
2064 (defun edt-emulation-off()
2065 "Select original global key bindings, disabling EDT Emulation."
2066 (interactive)
2067 (use-global-map global-map)
2068 (if (not edt-keep-current-page-delimiter)
2069 (setq page-delimiter edt-orig-page-delimiter))
2070 (setq edt-direction-string "")
2071 (setq edt-select-mode-current nil)
2072 (edt-reset)
2073 (force-mode-line-update t)
2074 (if (featurep 'emacs)
2075 (setq-default transient-mark-mode edt-orig-transient-mark-mode))
2076 (message "Original key bindings restored; EDT Emulation disabled"))
2077
2078 (defun edt-default-menu-bar-update-buffers ()
2079 ;; Update edt-default-global-map with latest copy of
2080 ;; `global-buffers-menu-map' each time `menu-bar-update-buffers'
2081 ;; updates global-map.
2082 (define-key edt-default-global-map [menu-bar buffer]
2083 (cons "Buffers" global-buffers-menu-map)))
2084
2085 (defun edt-user-menu-bar-update-buffers ()
2086 ;; We need to update edt-user-global-map with latest copy of
2087 ;; `global-buffers-menu-map' each time `menu-bar-update-buffers'
2088 ;; updates global-map.
2089 (define-key edt-user-global-map [menu-bar buffer]
2090 (cons "Buffers" global-buffers-menu-map)))
2091
2092 (defun edt-default-emulation-setup (&optional user-setup)
2093 "Setup emulation of DEC's EDT editor.
2094 Optional argument USER-SETUP non-nil means called from function
2095 `edt-user-emulation-setup'."
2096 ;; Setup default EDT global map by copying global map bindings.
2097 ;; This preserves ESC and C-x prefix bindings and other bindings we
2098 ;; wish to retain in EDT emulation mode keymaps. It also permits
2099 ;; customization of these bindings in the EDT global maps without
2100 ;; disturbing the original bindings in global-map.
2101 (fset 'edt-default-ESC-prefix (copy-keymap 'ESC-prefix))
2102 (setq edt-default-global-map (copy-keymap (current-global-map)))
2103 (if (featurep 'emacs)
2104 (define-key edt-default-global-map "\e" 'edt-default-ESC-prefix)
2105 (define-key edt-default-global-map [escape] 'edt-default-ESC-prefix))
2106 (define-prefix-command 'edt-default-gold-map)
2107 (edt-setup-default-bindings)
2108 ;; If terminal has additional function keys, the terminal-specific
2109 ;; initialization file can assign bindings to them via the optional
2110 ;; function edt-setup-extra-default-bindings.
2111 (if (fboundp 'edt-setup-extra-default-bindings)
2112 (edt-setup-extra-default-bindings))
2113 ;; Variable needed by edt-learn.
2114 (setq edt-learn-macro-count 0)
2115 ;; Display EDT text selection active within the mode line
2116 (or (assq 'edt-select-mode minor-mode-alist)
2117 (setq minor-mode-alist
2118 (cons '(edt-select-mode edt-select-mode) minor-mode-alist)))
2119 ;; Display EDT direction of motion within the mode line
2120 (or (assq 'edt-direction-string minor-mode-alist)
2121 (setq minor-mode-alist
2122 (cons
2123 '(edt-direction-string edt-direction-string) minor-mode-alist)))
2124 (if user-setup
2125 (progn
2126 (setq edt-user-map-configured t)
2127 (fset 'edt-emulation-on (symbol-function 'edt-select-user-global-map)))
2128 (progn
2129 (fset 'edt-emulation-on (symbol-function 'edt-select-default-global-map))
2130 (edt-select-default-global-map)))
2131 ;; Keep the menu bar Buffers menu up-to-date in edt-default-global-map.
2132 (add-hook 'menu-bar-update-hook 'edt-default-menu-bar-update-buffers))
2133
2134 (defun edt-user-emulation-setup ()
2135 "Setup user custom emulation of DEC's EDT editor."
2136 ;; Initialize EDT default bindings.
2137 (edt-default-emulation-setup t)
2138 ;; Setup user EDT global map by copying default EDT global map bindings.
2139 (fset 'edt-user-ESC-prefix (copy-keymap 'edt-default-ESC-prefix))
2140 (setq edt-user-global-map (copy-keymap edt-default-global-map))
2141 (if (featurep 'emacs)
2142 (define-key edt-user-global-map "\e" 'edt-user-ESC-prefix)
2143 (define-key edt-user-global-map [escape] 'edt-user-ESC-prefix))
2144 ;; If terminal has additional function keys, the user's initialization
2145 ;; file can assign bindings to them via the optional
2146 ;; function edt-setup-extra-default-bindings.
2147 (define-prefix-command 'edt-user-gold-map)
2148 (fset 'edt-user-gold-map (copy-keymap 'edt-default-gold-map))
2149 ;; This is a function that the user can define for custom bindings.
2150 ;; See Info node `edt' for more details, and sample edt-user.el file.
2151 (if (fboundp 'edt-setup-user-bindings)
2152 (edt-setup-user-bindings))
2153 (edt-select-user-global-map)
2154 ;; Keep the menu bar Buffers menu up-to-date in edt-user-global-map.
2155 (add-hook 'menu-bar-update-hook 'edt-user-menu-bar-update-buffers))
2156
2157 (defun edt-select-default-global-map()
2158 "Select default EDT emulation key bindings."
2159 (interactive)
2160 (if (featurep 'emacs)
2161 (transient-mark-mode 1))
2162 (use-global-map edt-default-global-map)
2163 (if (not edt-keep-current-page-delimiter)
2164 (progn
2165 (setq edt-orig-page-delimiter page-delimiter)
2166 (setq page-delimiter "\f")))
2167 (setq edt-default-map-active t)
2168 (edt-advance)
2169 (setq edt-select-mode-current 'edt-select-mode-string)
2170 (edt-reset)
2171 (message "Default EDT keymap active"))
2172
2173 (defun edt-select-user-global-map()
2174 "Select user EDT emulation custom key bindings."
2175 (interactive)
2176 (if edt-user-map-configured
2177 (progn
2178 (if (featurep 'emacs)
2179 (transient-mark-mode 1))
2180 (use-global-map edt-user-global-map)
2181 (if (not edt-keep-current-page-delimiter)
2182 (progn
2183 (setq edt-orig-page-delimiter page-delimiter)
2184 (setq page-delimiter "\f")))
2185 (setq edt-default-map-active nil)
2186 (edt-advance)
2187 (setq edt-select-mode-current 'edt-select-mode-string)
2188 (edt-reset)
2189 (message "User EDT custom keymap active"))
2190 (error "User EDT custom keymap NOT configured!")))
2191
2192 (defun edt-switch-global-maps ()
2193 "Toggle between default EDT keymap and user EDT keymap."
2194 (interactive)
2195 (if edt-default-map-active
2196 (edt-select-user-global-map)
2197 (edt-select-default-global-map)))
2198
2199 ;;
2200 ;; Functions used to set up DEFAULT bindings to EDT emulation functions.
2201 ;;
2202
2203 (defun edt-bind-function-key-default (function-key binding gold-binding)
2204 "Binds LK-201 function keys to default bindings in the EDT Emulator.
2205 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2206 Argument BINDING is the Emacs function to be bound to <KEY>.
2207 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2208 (let ((key (cdr (assoc function-key *EDT-keys*))))
2209 (if (and key (not (equal key "")))
2210 (progn
2211 (define-key edt-default-global-map key binding)
2212 (define-key 'edt-default-gold-map key gold-binding)))))
2213
2214 (defun edt-bind-key-default (key binding)
2215 "Bind key sequences to default bindings in the EDT Emulator.
2216 Argument KEY is the name of a standard key or a function key.
2217 Argument BINDING is the Emacs function to be bound to <KEY>."
2218 (define-key edt-default-global-map key binding))
2219
2220 (defun edt-bind-gold-key-default (key gold-binding)
2221 "Binds <GOLD> key sequences to default bindings in the EDT Emulator.
2222 Argument KEY is the name of a standard key or a function key.
2223 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2224 (define-key 'edt-default-gold-map key gold-binding))
2225
2226 ;;
2227 ;; Functions used to set up USER CUSTOM bindings to EDT emulation functions.
2228 ;;
2229 (defun edt-bind-function-key (function-key binding gold-binding)
2230 "Binds LK-201 function keys to custom bindings in the EDT Emulator.
2231 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2232 Argument BINDING is the Emacs function to be bound to <KEY>.
2233 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2234 (let ((key (cdr (assoc function-key *EDT-keys*))))
2235 (if (and key (not (equal key "")))
2236 (progn
2237 (define-key edt-user-global-map key binding)
2238 (define-key 'edt-user-gold-map key gold-binding)))))
2239
2240 (defun edt-bind-key (key binding)
2241 "Bind standard key sequences to custom bindings in the EDT Emulator.
2242 Argument KEY is the name of a key. It can be a standard key or a function key.
2243 Argument BINDING is the Emacs function to be bound to <KEY>."
2244 (define-key edt-user-global-map key binding))
2245
2246 ;; For backward compatibility to existing edt-user.el files.
2247 (fset 'edt-bind-standard-key (symbol-function 'edt-bind-key))
2248
2249 (defun edt-bind-gold-key (key gold-binding)
2250 "Binds <GOLD> standard key sequences to custom bindings in the EDT Emulator.
2251 Argument KEY is the name of a standard key or a function key.
2252 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2253 (define-key 'edt-user-gold-map key gold-binding))
2254
2255 (defun edt-setup-default-bindings ()
2256 "Assigns default EDT Emulation keyboard bindings."
2257
2258 ;; Function Key Bindings: Regular and GOLD.
2259
2260 ;; VT100/VT200/VT300 PF1 (GOLD), PF2, PF3, PF4 Keys
2261 (edt-bind-function-key-default "PF1"
2262 'edt-default-gold-map 'edt-mark-section-wisely)
2263 (edt-bind-function-key-default "PF2"
2264 'edt-electric-keypad-help 'describe-function)
2265 (edt-bind-function-key-default "PF3" 'edt-find-next 'edt-find)
2266 (edt-bind-function-key-default "PF4" 'edt-delete-line 'edt-undelete-line)
2267
2268 ;; VT100/VT200/VT300 Arrow Keys
2269 (edt-bind-function-key-default "UP" 'edt-previous-line 'edt-window-top)
2270 (edt-bind-function-key-default "DOWN" 'edt-next-line 'edt-window-bottom)
2271 (edt-bind-function-key-default "LEFT" 'backward-char 'edt-sentence-backward)
2272 (edt-bind-function-key-default "RIGHT" 'forward-char 'edt-sentence-forward)
2273
2274 ;; VT100/VT200/VT300 Keypad Keys
2275 (edt-bind-function-key-default "KP0" 'edt-line 'open-line)
2276 (edt-bind-function-key-default "KP1" 'edt-word 'edt-change-case)
2277 (edt-bind-function-key-default "KP2"
2278 'edt-end-of-line 'edt-delete-to-end-of-line)
2279 (edt-bind-function-key-default "KP3" 'edt-character 'quoted-insert)
2280 (edt-bind-function-key-default "KP4" 'edt-advance 'edt-bottom)
2281 (edt-bind-function-key-default "KP5" 'edt-backup 'edt-top)
2282 (edt-bind-function-key-default "KP6" 'edt-cut 'yank)
2283 (edt-bind-function-key-default "KP7" 'edt-page 'execute-extended-command)
2284 (edt-bind-function-key-default "KP8" 'edt-sect 'edt-fill-region)
2285 (edt-bind-function-key-default "KP9" 'edt-append 'edt-replace)
2286 (edt-bind-function-key-default "KP-" 'edt-delete-word 'edt-undelete-word)
2287 (edt-bind-function-key-default "KP,"
2288 'edt-delete-character 'edt-undelete-character)
2289 (edt-bind-function-key-default "KPP" 'edt-select 'edt-reset)
2290 (edt-bind-function-key-default "KPE" 'other-window 'edt-substitute)
2291
2292 ;; VT200/VT300 Function Keys
2293 ;; (F1 through F5, on the VT220, are not programmable, so we skip
2294 ;; making default bindings to those keys.
2295 (edt-bind-function-key-default "FIND" 'edt-find-next 'edt-find)
2296 (edt-bind-function-key-default "INSERT" 'yank 'edt-key-not-assigned)
2297 (edt-bind-function-key-default "REMOVE" 'edt-cut 'edt-copy)
2298 (edt-bind-function-key-default "SELECT"
2299 'edt-toggle-select 'edt-key-not-assigned)
2300 (edt-bind-function-key-default "NEXT"
2301 'edt-sect-forward 'edt-key-not-assigned)
2302 (edt-bind-function-key-default "PREVIOUS"
2303 'edt-sect-backward 'edt-key-not-assigned)
2304 (edt-bind-function-key-default "F6"
2305 'edt-key-not-assigned 'edt-key-not-assigned)
2306 (edt-bind-function-key-default "F7"
2307 'edt-copy-rectangle 'edt-key-not-assigned)
2308 (edt-bind-function-key-default "F8"
2309 'edt-cut-rectangle-overstrike-mode 'edt-paste-rectangle-overstrike-mode)
2310 (edt-bind-function-key-default "F9"
2311 'edt-cut-rectangle-insert-mode 'edt-paste-rectangle-insert-mode)
2312 (edt-bind-function-key-default "F10" 'edt-cut-rectangle 'edt-paste-rectangle)
2313 ;; Under X, the F11 key can be bound. If using a VT-200 or higher terminal,
2314 ;; the default emacs terminal support causes the VT F11 key to seem as if it
2315 ;; is an ESC key when in emacs.
2316 (edt-bind-function-key-default "F11"
2317 'edt-key-not-assigned 'edt-key-not-assigned)
2318 (edt-bind-function-key-default "F12"
2319 'edt-beginning-of-line 'delete-other-windows) ;BS
2320 (edt-bind-function-key-default "F13"
2321 'edt-delete-to-beginning-of-word 'edt-key-not-assigned) ;LF
2322 (edt-bind-function-key-default "F14"
2323 'edt-key-not-assigned 'edt-key-not-assigned)
2324 (edt-bind-function-key-default "HELP"
2325 'edt-electric-keypad-help 'edt-key-not-assigned)
2326 (edt-bind-function-key-default "DO"
2327 'execute-extended-command 'edt-key-not-assigned)
2328 (edt-bind-function-key-default "F17"
2329 'edt-key-not-assigned 'edt-key-not-assigned)
2330 (edt-bind-function-key-default "F18"
2331 'edt-key-not-assigned 'edt-key-not-assigned)
2332 (edt-bind-function-key-default "F19"
2333 'edt-key-not-assigned 'edt-key-not-assigned)
2334 (edt-bind-function-key-default "F20"
2335 'edt-key-not-assigned 'edt-key-not-assigned)
2336
2337 ;; Control key bindings: Regular and GOLD
2338 ;;
2339 ;; Standard EDT control key bindings conflict with standard Emacs
2340 ;; control key bindings. Normally, the standard Emacs control key
2341 ;; bindings are left unchanged in the default EDT mode. However, if
2342 ;; the variable edt-use-EDT-control-key-bindings is set to true
2343 ;; before invoking edt-emulation-on for the first time, then the
2344 ;; standard EDT bindings (with some enhancements) as defined here are
2345 ;; used, instead.
2346 (if edt-use-EDT-control-key-bindings
2347 (progn
2348 (edt-bind-key-default "\C-a" 'edt-key-not-assigned)
2349 (edt-bind-key-default "\C-b" 'edt-key-not-assigned)
2350 ;; Leave binding of C-c to an Emacs prefix key.
2351 (edt-bind-key-default "\C-d" 'edt-key-not-assigned)
2352 (edt-bind-key-default "\C-e" 'edt-key-not-assigned)
2353 (edt-bind-key-default "\C-f" 'edt-key-not-assigned)
2354 ;; Leave binding of C-g to the Emacs keyboard-quit
2355 (edt-bind-key-default "\C-h" 'edt-beginning-of-line)
2356 (edt-bind-key-default "\C-i" 'edt-tab-insert)
2357 (edt-bind-key-default "\C-j" 'edt-delete-to-beginning-of-word)
2358 (edt-bind-key-default "\C-k" 'edt-define-key)
2359 (edt-bind-gold-key-default "\C-k" 'edt-restore-key)
2360 (edt-bind-key-default "\C-l" 'edt-form-feed-insert)
2361 ;; Leave binding of C-m to newline.
2362 (edt-bind-key-default "\C-n" 'edt-set-screen-width-80)
2363 (edt-bind-key-default "\C-o" 'edt-key-not-assigned)
2364 (edt-bind-key-default "\C-p" 'edt-key-not-assigned)
2365 (edt-bind-key-default "\C-q" 'edt-key-not-assigned)
2366 ;; Leave binding of C-r to isearch-backward.
2367 ;; Leave binding of C-s to isearch-forward.
2368 (edt-bind-key-default "\C-t" 'edt-display-the-time)
2369 (edt-bind-key-default "\C-u" 'edt-delete-to-beginning-of-line)
2370 (edt-bind-key-default "\C-v" 'redraw-display)
2371 (edt-bind-key-default "\C-w" 'edt-set-screen-width-132)
2372 ;; Leave binding of C-x as original prefix key.
2373 (edt-bind-key-default "\C-y" 'edt-key-not-assigned)
2374 ;; Leave binding of C-z to suspend-emacs.
2375 )
2376 )
2377
2378 ;; GOLD bindings for a few keys.
2379 (edt-bind-gold-key-default "\C-g" 'keyboard-quit); Just in case.
2380 (edt-bind-gold-key-default "\C-h" 'help-for-help); Just in case.
2381 (edt-bind-gold-key-default [f1] 'help-for-help)
2382 (edt-bind-gold-key-default [help] 'help-for-help)
2383 (edt-bind-gold-key-default "\C-\\" 'split-window-below)
2384
2385 ;; GOLD bindings for regular keys.
2386 (edt-bind-gold-key-default "a" 'edt-key-not-assigned)
2387 (edt-bind-gold-key-default "A" 'edt-key-not-assigned)
2388 (edt-bind-gold-key-default "b" 'buffer-menu)
2389 (edt-bind-gold-key-default "B" 'buffer-menu)
2390 (edt-bind-gold-key-default "c" 'compile)
2391 (edt-bind-gold-key-default "C" 'compile)
2392 (edt-bind-gold-key-default "d" 'delete-window)
2393 (edt-bind-gold-key-default "D" 'delete-window)
2394 (edt-bind-gold-key-default "e" 'edt-exit)
2395 (edt-bind-gold-key-default "E" 'edt-exit)
2396 (edt-bind-gold-key-default "f" 'find-file)
2397 (edt-bind-gold-key-default "F" 'find-file)
2398 (edt-bind-gold-key-default "g" 'find-file-other-window)
2399 (edt-bind-gold-key-default "G" 'find-file-other-window)
2400 (edt-bind-gold-key-default "h" 'edt-electric-keypad-help)
2401 (edt-bind-gold-key-default "H" 'edt-electric-keypad-help)
2402 (edt-bind-gold-key-default "i" 'insert-file)
2403 (edt-bind-gold-key-default "I" 'insert-file)
2404 (edt-bind-gold-key-default "j" 'edt-key-not-assigned)
2405 (edt-bind-gold-key-default "J" 'edt-key-not-assigned)
2406 (edt-bind-gold-key-default "k" 'edt-toggle-capitalization-of-word)
2407 (edt-bind-gold-key-default "K" 'edt-toggle-capitalization-of-word)
2408 (edt-bind-gold-key-default "l" 'edt-lowercase)
2409 (edt-bind-gold-key-default "L" 'edt-lowercase)
2410 (edt-bind-gold-key-default "m" 'save-some-buffers)
2411 (edt-bind-gold-key-default "M" 'save-some-buffers)
2412 (edt-bind-gold-key-default "n" 'next-error)
2413 (edt-bind-gold-key-default "N" 'next-error)
2414 (edt-bind-gold-key-default "o" 'switch-to-buffer-other-window)
2415 (edt-bind-gold-key-default "O" 'switch-to-buffer-other-window)
2416 (edt-bind-gold-key-default "p" 'edt-key-not-assigned)
2417 (edt-bind-gold-key-default "P" 'edt-key-not-assigned)
2418 (edt-bind-gold-key-default "q" 'edt-quit)
2419 (edt-bind-gold-key-default "Q" 'edt-quit)
2420 (edt-bind-gold-key-default "r" 'revert-buffer)
2421 (edt-bind-gold-key-default "R" 'revert-buffer)
2422 (edt-bind-gold-key-default "s" 'save-buffer)
2423 (edt-bind-gold-key-default "S" 'save-buffer)
2424 (edt-bind-gold-key-default "t" 'edt-key-not-assigned)
2425 (edt-bind-gold-key-default "T" 'edt-key-not-assigned)
2426 (edt-bind-gold-key-default "u" 'edt-uppercase)
2427 (edt-bind-gold-key-default "U" 'edt-uppercase)
2428 (edt-bind-gold-key-default "v" 'find-file-other-window)
2429 (edt-bind-gold-key-default "V" 'find-file-other-window)
2430 (edt-bind-gold-key-default "w" 'write-file)
2431 (edt-bind-gold-key-default "W" 'write-file)
2432 (edt-bind-gold-key-default "x" 'edt-key-not-assigned)
2433 (edt-bind-gold-key-default "X" 'edt-key-not-assigned)
2434 (edt-bind-gold-key-default "y" 'edt-emulation-off)
2435 (edt-bind-gold-key-default "Y" 'edt-emulation-off)
2436 (edt-bind-gold-key-default "z" 'edt-switch-global-maps)
2437 (edt-bind-gold-key-default "Z" 'edt-switch-global-maps)
2438 (edt-bind-gold-key-default "1" 'delete-other-windows)
2439 (edt-bind-gold-key-default "!" 'edt-key-not-assigned)
2440 (edt-bind-gold-key-default "2" 'edt-split-window)
2441 (edt-bind-gold-key-default "@" 'edt-key-not-assigned)
2442 (edt-bind-gold-key-default "3" 'edt-key-not-assigned)
2443 (edt-bind-gold-key-default "#" 'edt-key-not-assigned)
2444 (edt-bind-gold-key-default "4" 'edt-key-not-assigned)
2445 (edt-bind-gold-key-default "$" 'edt-key-not-assigned)
2446 (edt-bind-gold-key-default "5" 'edt-key-not-assigned)
2447 (edt-bind-gold-key-default "%" 'edt-goto-percentage)
2448 (edt-bind-gold-key-default "6" 'edt-key-not-assigned)
2449 (edt-bind-gold-key-default "^" 'edt-key-not-assigned)
2450 (edt-bind-gold-key-default "7" 'edt-key-not-assigned)
2451 (edt-bind-gold-key-default "&" 'edt-key-not-assigned)
2452 (edt-bind-gold-key-default "8" 'edt-key-not-assigned)
2453 (edt-bind-gold-key-default "*" 'edt-key-not-assigned)
2454 (edt-bind-gold-key-default "9" 'edt-key-not-assigned)
2455 (edt-bind-gold-key-default "(" 'edt-key-not-assigned)
2456 (edt-bind-gold-key-default "0" 'edt-key-not-assigned)
2457 (edt-bind-gold-key-default ")" 'edt-key-not-assigned)
2458 (edt-bind-gold-key-default " " 'undo)
2459 (edt-bind-gold-key-default "," 'edt-key-not-assigned)
2460 (edt-bind-gold-key-default "<" 'edt-key-not-assigned)
2461 (edt-bind-gold-key-default "." 'edt-key-not-assigned)
2462 (edt-bind-gold-key-default ">" 'edt-key-not-assigned)
2463 (edt-bind-gold-key-default "/" 'query-replace)
2464 (edt-bind-gold-key-default "?" 'edt-key-not-assigned)
2465 (edt-bind-gold-key-default "\\" 'edt-key-not-assigned)
2466 (edt-bind-gold-key-default "|" 'edt-key-not-assigned)
2467 (edt-bind-gold-key-default ";" 'edt-key-not-assigned)
2468 (edt-bind-gold-key-default ":" 'edt-key-not-assigned)
2469 (edt-bind-gold-key-default "'" 'edt-key-not-assigned)
2470 (edt-bind-gold-key-default "\"" 'edt-key-not-assigned)
2471 (edt-bind-gold-key-default "-" 'edt-key-not-assigned)
2472 (edt-bind-gold-key-default "_" 'edt-key-not-assigned)
2473 (edt-bind-gold-key-default "=" 'goto-line)
2474 (edt-bind-gold-key-default "+" 'edt-key-not-assigned)
2475 (edt-bind-gold-key-default "[" 'edt-key-not-assigned)
2476 (edt-bind-gold-key-default "{" 'edt-key-not-assigned)
2477 (edt-bind-gold-key-default "]" 'edt-key-not-assigned)
2478 (edt-bind-gold-key-default "}" 'edt-key-not-assigned)
2479 (edt-bind-gold-key-default "`" 'what-line)
2480 (edt-bind-gold-key-default "~" 'edt-key-not-assigned)
2481 )
2482 \f
2483 ;;;
2484 ;;; DEFAULT EDT KEYPAD HELP
2485 ;;;
2486
2487 ;;
2488 ;; Upper case commands in the keypad diagram below indicate that the
2489 ;; emulation should look and feel very much like EDT. Lower case
2490 ;; commands are enhancements and/or additions to the EDT keypad
2491 ;; commands or are native Emacs commands.
2492 ;;
2493
2494 (defun edt-keypad-help ()
2495 "DEFAULT EDT Keypad Active.
2496
2497 F7: Copy Rectangle +----------+----------+----------+----------+
2498 F8: Cut Rect Overstrike |Prev Line |Next Line |Bkwd Char |Frwd Char |
2499 G-F8: Paste Rect Overstrike | (UP) | (DOWN) | (LEFT) | (RIGHT) |
2500 F9: Cut Rect Insert |Window Top|Window Bot|Bkwd Sent |Frwd Sent |
2501 G-F9: Paste Rect Insert +----------+----------+----------+----------+
2502 F10: Cut Rectangle
2503 G-F10: Paste Rectangle
2504 F11: ESC
2505 F12: Beginning of Line +----------+----------+----------+----------+
2506 G-F12: Delete Other Windows | GOLD | HELP | FNDNXT | DEL L |
2507 F13: Delete to Begin of Word | (PF1) | (PF2) | (PF3) | (PF4) |
2508 HELP: Keypad Help |Mark Wisel|Desc Funct| FIND | UND L |
2509 G-HELP: Emacs Help +----------+----------+----------+----------+
2510 DO: Execute extended command | PAGE | SECT | APPEND | DEL W |
2511 C-g: Keyboard Quit | (7) | (8) | (9) | (-) |
2512 G-C-g: Keyboard Quit |Ex Ext Cmd|Fill Regio| REPLACE | UND W |
2513 C-h: Beginning of Line +----------+----------+----------+----------+
2514 G-C-h: Emacs Help | ADVANCE | BACKUP | CUT | DEL C |
2515 C-i: Tab Insert | (4) | (5) | (6) | (,) |
2516 C-j: Delete to Begin of Word | BOTTOM | TOP | Yank | UND C |
2517 C-k: Define Key +----------+----------+----------+----------+
2518 G-C-k: Restore Key | WORD | EOL | CHAR | Next |
2519 C-l: Form Feed Insert | (1) | (2) | (3) | Window |
2520 C-n: Set Screen Width 80 | CHNGCASE | DEL EOL |Quoted Ins| !
2521 C-r: Isearch Backward +---------------------+----------+ (ENTER) |
2522 C-s: Isearch Forward | LINE | SELECT | !
2523 C-t: Display the Time | (0) | (.) | SUBS |
2524 C-u: Delete to Begin of Line | Open Line | RESET | |
2525 C-v: Redraw Display +---------------------+----------+----------+
2526 C-w: Set Screen Width 132
2527 C-z: Suspend Emacs +----------+----------+----------+
2528 G-C-\\: Split Window | FNDNXT | Yank | CUT |
2529 | (FIND) | (INSERT) | (REMOVE) |
2530 G-b: Buffer Menu | FIND | | COPY |
2531 G-c: Compile +----------+----------+----------+
2532 G-d: Delete Window |SELECT/RES|SECT BACKW|SECT FORWA|
2533 G-e: Exit | (SELECT) |(PREVIOUS)| (NEXT) |
2534 G-f: Find File | | | |
2535 G-g: Find File Other Window +----------+----------+----------+
2536 G-h: Keypad Help
2537 G-i: Insert File
2538 G-k: Toggle Capitalization Word
2539 G-l: Downcase Region
2540 G-m: Save Some Buffers
2541 G-n: Next Error
2542 G-o: Switch to Next Window
2543 G-q: Quit
2544 G-r: Revert File
2545 G-s: Save Buffer
2546 G-u: Upcase Region
2547 G-v: Find File Other Window
2548 G-w: Write file
2549 G-y: EDT Emulation OFF
2550 G-z: Switch to User EDT Key Bindings
2551 G-1: Delete Other Windows
2552 G-2: Split Window
2553 G-%: Go to Percentage
2554 G- : Undo (GOLD Spacebar)
2555 G-=: Go to Line
2556 G-`: What line
2557 G-/: Query-Replace"
2558
2559 (interactive)
2560 (describe-function 'edt-keypad-help))
2561
2562 (defun edt-electric-helpify (fun)
2563 (let ((name "*Help*"))
2564 (if (save-window-excursion
2565 (let* ((p (symbol-function 'help-print-return-message))
2566 (b (get-buffer name))
2567 (m (buffer-modified-p b)))
2568 (and b (not (get-buffer-window b))
2569 (setq b nil))
2570 (unwind-protect
2571 (progn
2572 (message "%s..." (capitalize (symbol-name fun)))
2573 (and b
2574 (with-current-buffer b
2575 (set-buffer-modified-p t)))
2576 (fset 'help-print-return-message 'ignore)
2577 (call-interactively fun)
2578 (and (get-buffer name)
2579 (get-buffer-window (get-buffer name))
2580 (or (not b)
2581 (not (eq b (get-buffer name)))
2582 (not (buffer-modified-p b)))))
2583 (fset 'help-print-return-message p)
2584 (and b (buffer-name b)
2585 (with-current-buffer b
2586 (set-buffer-modified-p m))))))
2587 (with-electric-help 'delete-other-windows name t))))
2588
2589 (defun edt-electric-keypad-help ()
2590 "Display default EDT bindings."
2591 (interactive)
2592 (edt-electric-helpify 'edt-keypad-help))
2593
2594 (defun edt-electric-user-keypad-help ()
2595 "Display user custom EDT bindings."
2596 (interactive)
2597 (edt-electric-helpify 'edt-user-keypad-help))
2598
2599 ;;;
2600 ;;; EDT emulation screen width commands.
2601 ;;
2602 ;; Some terminals require modification of terminal attributes when
2603 ;; changing the number of columns displayed, hence the fboundp tests
2604 ;; below. These functions are defined in the corresponding terminal
2605 ;; specific file, if needed.
2606
2607 (defun edt-set-screen-width-80 ()
2608 "Set screen width to 80 columns."
2609 (interactive)
2610 (if (fboundp 'edt-set-term-width-80)
2611 (edt-set-term-width-80))
2612 (set-frame-width nil 80)
2613 (message "Terminal width 80"))
2614
2615 (defun edt-set-screen-width-132 ()
2616 "Set screen width to 132 columns."
2617 (interactive)
2618 (if (fboundp 'edt-set-term-width-132)
2619 (edt-set-term-width-132))
2620 (set-frame-width nil 132)
2621 (message "Terminal width 132"))
2622
2623 (provide 'edt)
2624
2625 ;;; edt.el ends here