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