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