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, 2010 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/>.
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.
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
54 ;; (add-hook term-setup-hook 'edt-emulation-on)
56 ;; IMPORTANT: Be sure to read the Info node `edt' for more details.
57 ;; It contains very helpful user information.
59 ;; The EDT emulation consists of the following files:
61 ;; edt.texi - User manual
62 ;; edt-user.el - Sample Customization File
63 ;; edt.el - EDT Emulation Functions and Default Configuration
64 ;; edt-lk201.el - Built-in support for DEC LK-201 Keyboards
65 ;; edt-vt100.el - Built-in support for DEC VT-100 (and above) terminals
66 ;; edt-pc.el - Built-in support for PC 101 Keyboards under MS-DOS
67 ;; edt-mapper.el - Create an EDT LK-201 Map File for Keyboards Without
72 ;; Version 4.0 contains the following enhancements:
74 ;; 1. Scroll margins at the top and bottom of the window are now
75 ;; supported. (The design was copied from tpu-extras.el.) By
76 ;; default, this feature is enabled, with the top margin set to
77 ;; 10% of the window and the bottom margin set to 15% of the
78 ;; window. To change these settings, you can invoke the function
79 ;; edt-set-scroll-margins in your .emacs file. For example, the
82 ;; (edt-set-scroll-margins "20%" "25%")
84 ;; sets the top margin to 20% of the window and the bottom margin
85 ;; to 25% of the window. To disable this feature, set each
86 ;; margin to 0%. You can also invoke edt-set-scroll-margins
87 ;; interactively while EDT Emulation is active to change the
88 ;; settings for that session.
90 ;; NOTE: Another way to set the scroll margins is to use the
91 ;; Emacs customization feature (not available in Emacs 19) to set
92 ;; the following two variables directly:
94 ;; edt-top-scroll-margin and edt-bottom-scroll-margin
96 ;; Enter the Emacs `customize' command. First select the Editing
97 ;; group and then select the Emulations group. Finally, select
98 ;; the Edt group and follow the directions.
100 ;; 2. The SUBS command is now supported and bound to GOLD-Enter by
101 ;; default. (This design was copied from tpu-edt.el.) Note, in
102 ;; earlier versions of EDT Emulation, GOLD-Enter was assigned to
103 ;; the Emacs function `query-replace'. The binding of
104 ;; `query-replace' has been moved to GOLD-/. If you prefer to
105 ;; restore `query-replace' to GOLD-Enter, then use an EDT user
106 ;; customization file, edt-user.el, to do this.
107 ;; See Info node `edt' for more details.
109 ;; 3. EDT Emulation now also works in XEmacs, including the
110 ;; highlighting of selected text.
112 ;; 4. If you access a workstation using an X Server, observe that
113 ;; the initialization file generated by edt-mapper.el will now
114 ;; contain the name of the X Server vendor. This is a
115 ;; convenience for those who have access to their Unix account
116 ;; from more than one type of X Server. Since different X
117 ;; Servers typically require different EDT emulation
118 ;; initialization files, edt-mapper.el will now generate these
119 ;; different initialization files and save them with different
120 ;; names. Then, the correct initialization file for the
121 ;; particular X server in use is loaded correctly automatically.
123 ;; 5. Also, edt-mapper.el is now capable of binding an ASCII key
124 ;; sequence, providing the ASCII key sequence prefix is already
125 ;; known by Emacs to be a prefix. As a result of providing this
126 ;; support, some terminal/keyboard/window system configurations,
127 ;; which don't have a complete set of sensible function key
128 ;; bindings built into Emacs in `function-key-map', can still be
129 ;; configured for use with EDT Emulation. (Note: In a few rare
130 ;; circumstances this does not work properly. In particular, it
131 ;; does not work if a subset of the leading ASCII characters in a
132 ;; key sequence are recognized by Emacs as having an existing
133 ;; binding. For example, if the keypad 7 (KP-7) key generates
134 ;; the sequence \"<ESC>Ow\" and \"<ESC>O\" is already bound to a
135 ;; function, pressing KP-7 when told to do so by edt-mapper.el
136 ;; will result in edt-mapper.el incorrectly mapping \"<ESC>O\" to
137 ;; KP-7 and \"w\" to KP-8. If something like this happens to
138 ;; you, it is probably a bug in the support for your keyboard
139 ;; within Emacs OR a bug in the Unix termcap/terminfo support for
140 ;; your terminal OR a bug in the terminal emulation software you
143 ;; 6. The edt-quit function (bound to GOLD-q by default) has been
144 ;; modified to warn the user when file-related buffer
145 ;; modifications exist. It now cautions the user that those
146 ;; modifications will be lost if the user quits without saving
152 ;; Version 4.0 2000 Added New Features and Fixed a Few Bugs
158 ;;; Electric Help functions are used for keypad help displays. A few
159 ;;; picture functions are used in rectangular cut and paste commands.
165 ;;;; VARIABLES and CONSTANTS
169 "Emacs emulating EDT."
173 ;; To silence the byte-compiler
175 (defvar edt-default-global-map
)
176 (defvar edt-last-copied-word
)
177 (defvar edt-learn-macro-count
)
178 (defvar edt-orig-page-delimiter
)
179 (defvar edt-orig-transient-mark-mode
)
180 (defvar edt-rect-start-point
)
181 (defvar edt-user-global-map
)
182 (defvar rect-start-point
)
184 (defvar zmacs-region-stays
)
187 ;;; Version Information
189 (defconst edt-version
"4.0" "EDT Emulation version number.")
192 ;;; User Configurable Variables
195 (defcustom edt-keep-current-page-delimiter nil
196 "*Emacs MUST be restarted for a change in value to take effect!
197 Non-nil leaves Emacs value of `page-delimiter' unchanged within EDT
198 Emulation. If set to nil (the default), the `page-delimiter' variable
199 is set to \"\\f\" when edt-emulation-on is first invoked. This
200 setting replicates EDT's page delimiter behavior. The original value
201 is restored when edt-emulation-off is called."
205 (defcustom edt-use-EDT-control-key-bindings nil
206 "*Emacs MUST be restarted for a change in value to take effect!
207 Non-nil causes the control key bindings to be replaced with EDT
208 bindings. If set to nil (the default), EDT control key bindings are
209 not used and the current Emacs control key bindings are retained for
210 use within the EDT emulation."
214 (defcustom edt-word-entities
'(?
\t)
215 "*Specifies the list of EDT word entity characters.
216 The default list, (\?\\t), contains just the TAB character, which
217 emulates EDT. Characters are specified in the list using their
218 decimal ASCII values. A question mark, followed by the actual
219 character, can be used to indicate the numerical value of the
220 character, instead of the actual decimal value. So, ?A means the
221 numerical value for the letter A, \?/ means the numerical value for /,
222 etc. Several unprintable and special characters have special
223 representations, which you can also use:
225 \?\\b specifies BS, C-h
226 \?\\t specifies TAB, C-i
227 \?\\n specifies LFD, C-j
228 \?\\v specifies VTAB, C-k
229 \?\\f specifies FF, C-l
230 \?\\r specifies CR, C-m
231 \?\\e specifies ESC, C-[
234 In EDT Emulation movement-by-word commands, each character in the list
235 will be treated as if it were a separate word."
236 :type
'(repeat integer
)
239 (defcustom edt-top-scroll-margin
10
240 "*Scroll margin at the top of the screen.
241 Interpreted as a percent of the current window size with a default
242 setting of 10%. If set to 0, top scroll margin is disabled."
246 (defcustom edt-bottom-scroll-margin
15
247 "*Scroll margin at the bottom of the screen.
248 Interpreted as a percent of the current window size with a default
249 setting of 15%. If set to 0, bottom scroll margin is disabled."
254 ;;; Internal Variables
257 (defvar edt-last-deleted-lines
""
258 "Last text deleted by the EDT emulation DEL L command.")
260 (defvar edt-last-deleted-words
""
261 "Last text deleted by the EDT emulation DEL W command.")
263 (defvar edt-last-deleted-chars
""
264 "Last text deleted by the EDT emulation DEL C command.")
266 (defvar edt-find-last-text
""
267 "Last text found by the EDT emulation FIND command.")
269 (defvar edt-match-beginning-mark
(make-marker)
270 "Used internally by the EDT emulation SUBS command.")
272 (defvar edt-match-end-mark
(make-marker)
273 "Used internally by the EDT emulation SUBS command.")
275 (defvar edt-last-replaced-key-definition nil
276 "Key definition replaced with `edt-define-key' or `edt-learn' command.")
278 (defvar edt-direction-string
""
279 "String indicating current direction of movement.")
281 (defvar edt-select-mode nil
282 "Non-nil means select mode is active.")
284 (defvar edt-select-mode-current
""
285 "Text displayed in mode line to indicate the state of EDT select mode.
286 When select mode is inactive, it is set to an empty string.")
288 (defconst edt-select-mode-string
" Select"
289 "Used in mode line to indicate select mode is active.")
291 (defconst edt-forward-string
" ADVANCE"
292 "Direction string in mode line to indicate forward movement.")
294 (defconst edt-backward-string
" BACKUP"
295 "Direction string in mode line to indicate backward movement.")
297 (defvar edt-default-map-active nil
298 "Non-nil indicates that default EDT emulation key bindings are active.
299 nil means user-defined custom bindings are active.")
301 (defvar edt-user-map-configured nil
302 "Non-nil indicates that user custom EDT key bindings are configured.
303 This means that an edt-user.el file was found in the user's `load-path'.")
306 "Specifies the terminal type, if applicable.")
309 ;;; Emacs version identifiers - currently referenced by
311 ;;; o edt-emulation-on o edt-load-keys
313 (defconst edt-emacs-variant
(if (featurep 'emacs
) "gnu" "xemacs")
314 "Indicates Emacs variant: GNU Emacs or XEmacs \(aka Lucid Emacs\).")
316 (defconst edt-window-system
(if (featurep 'emacs
) window-system
(console-type))
317 "Indicates window system \(in GNU Emacs\) or console type \(in XEmacs\).")
319 (declare-function x-server-vendor
"xfns.c" (&optional terminal
))
321 (defconst edt-xserver
(when (eq edt-window-system
'x
)
322 ;; The Cygwin window manager has a `/' in its
323 ;; name, which breaks the generated file name of
324 ;; the custom key map file. Replace `/' with a
325 ;; `-' to work around that.
326 (if (featurep 'xemacs
)
327 (replace-in-string (x-server-vendor) "[ /]" "-")
328 (replace-regexp-in-string "[ /]" "-"
330 "Indicates X server vendor name, if applicable.")
332 (defvar edt-keys-file nil
333 "User's custom keypad and function keys mappings to emulate LK-201 keyboard.")
335 (defvar edt-last-copied-word nil
336 "Last word that the user copied.")
340 ;;;; EDT Emulation Commands
343 ;;; Almost all of EDT's keypad mode commands have equivalent Emacs
344 ;;; function counterparts. But many of these counterparts behave
345 ;;; somewhat differently in Emacs.
347 ;;; So, the following Emacs functions emulate, where practical, the
348 ;;; exact behavior of the corresponding EDT keypad mode commands. In
349 ;;; a few cases, the emulation is not exact, but it should be close
350 ;;; enough for most EDT die-hards.
356 ;;; Emacs uses the regexp assigned to page-delimiter to determine what
357 ;;; marks a page break. This is normally "^\f", which causes the
358 ;;; edt-page command to ignore form feeds not located at the beginning
359 ;;; of a line. To emulate the EDT PAGE command exactly,
360 ;;; page-delimiter is set to "\f" when EDT emulation is turned on, and
361 ;;; restored to its original value when EDT emulation is turned off.
362 ;;; But this can be overridden if the EDT definition is not desired by
365 ;;; (setq edt-keep-current-page-delimiter t)
367 ;;; in your .emacs file.
369 (defun edt-page-forward (num)
370 "Move forward to just after next page delimiter.
371 Argument NUM is the number of page delimiters to move."
373 (edt-check-prefix num
)
375 (error "End of buffer")
379 (edt-line-to-bottom-of-window)
380 (edt-line-to-top-of-window)))))
382 (defun edt-page-backward (num)
383 "Move backward to just after previous page delimiter.
384 Argument NUM is the number of page delimiters to move."
386 (edt-check-prefix num
)
388 (error "Beginning of buffer")
391 (edt-line-to-top-of-window)
392 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))))
394 (defun edt-page (num)
395 "Move in current direction to next page delimiter.
396 Argument NUM is the number of page delimiters to move."
398 (if (equal edt-direction-string edt-forward-string
)
399 (edt-page-forward num
)
400 (edt-page-backward num
)))
405 ;;; EDT defaults a section size to be 16 lines of its one and only
406 ;;; 24-line window. That's two-thirds of the window at a time. The
407 ;;; EDT SECT commands moves the cursor, not the window.
409 ;;; This emulation of EDT's SECT moves the cursor approximately
410 ;;; two-thirds of the current window at a time.
412 (defun edt-sect-forward (num)
413 "Move cursor forward two-thirds of a window's number of lines.
414 Argument NUM is the number of sections to move."
416 (edt-check-prefix num
)
417 (edt-line-forward (* (* (/ (- (window-height) 1) 3) 2) num
)))
420 (defun edt-sect-backward (num)
421 "Move cursor backward two-thirds of a window.
422 Argument NUM is the number of sections to move."
424 (edt-check-prefix num
)
425 (edt-line-backward (* (* (/ (- (window-height) 1) 3) 2) num
)))
427 (defun edt-sect (num)
428 "Move in current direction a full window.
429 Argument NUM is the number of sections to move."
431 (if (equal edt-direction-string edt-forward-string
)
432 (edt-sect-forward num
)
433 (edt-sect-backward num
)))
436 ;;; BEGINNING OF LINE
438 ;;; EDT's beginning-of-line command is not affected by current
439 ;;; direction, for some unknown reason.
441 (defun edt-beginning-of-line (num)
442 "Move backward to next beginning of line mark.
443 Argument NUM is the number of BOL marks to move."
445 (edt-check-prefix num
)
446 (let ((beg (edt-current-line)))
448 (forward-line (* -
1 num
))
451 (forward-line (* -
1 num
))))
452 (edt-top-check beg num
))
453 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
457 ;;; EOL (End of Line)
460 (defun edt-end-of-line-forward (num)
461 "Move forward to next end of line mark.
462 Argument NUM is the number of EOL marks to move."
464 (edt-check-prefix num
)
465 (let ((beg (edt-current-line)))
468 (edt-bottom-check beg num
))
469 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
472 (defun edt-end-of-line-backward (num)
473 "Move backward to next end of line mark.
474 Argument NUM is the number of EOL marks to move."
476 (edt-check-prefix num
)
477 (let ((beg (edt-current-line)))
478 (end-of-line (1- num
))
479 (edt-top-check beg num
))
480 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
483 (defun edt-end-of-line (num)
484 "Move in current direction to next end of line mark.
485 Argument NUM is the number of EOL marks to move."
487 (if (equal edt-direction-string edt-forward-string
)
488 (edt-end-of-line-forward num
)
489 (edt-end-of-line-backward num
)))
494 ;;; This one is a tad messy. To emulate EDT's behavior everywhere in
495 ;;; the file (beginning of file, end of file, beginning of line, end
496 ;;; of line, etc.) it takes a bit of special handling.
498 ;;; The variable edt-word-entities contains a list of characters which
499 ;;; are to be viewed as distinct words where ever they appear in the
500 ;;; buffer. This emulates the EDT line mode command SET ENTITY WORD.
503 (defun edt-one-word-forward ()
504 "Move forward to first character of next word."
507 (error "End of buffer"))
511 (if (memq (following-char) edt-word-entities
)
516 (not (eq ?\
(char-syntax (following-char))))
517 (not (memq (following-char) edt-word-entities
)))
522 (eq ?\
(char-syntax (following-char)))
523 (not (memq (following-char) edt-word-entities
)))
525 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
527 (defun edt-one-word-backward ()
528 "Move backward to first character of previous word."
531 (error "Beginning of buffer"))
539 (eq ?\
(char-syntax (following-char)))
540 (not (memq (following-char) edt-word-entities
)))
542 (if (not (memq (following-char) edt-word-entities
))
546 (not (eq ?\
(char-syntax (preceding-char))))
547 (not (memq (preceding-char) edt-word-entities
)))
549 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
551 (defun edt-word-forward (num)
552 "Move forward to first character of next word.
553 Argument NUM is the number of words to move."
555 (edt-check-prefix num
)
557 (edt-one-word-forward)
558 (setq num
(1- num
))))
560 (defun edt-word-backward (num)
561 "Move backward to first character of previous word.
562 Argument NUM is the number of words to move."
564 (edt-check-prefix num
)
566 (edt-one-word-backward)
567 (setq num
(1- num
))))
569 (defun edt-word (num)
570 "Move in current direction to first character of next word.
571 Argument NUM is the number of words to move."
573 (if (equal edt-direction-string edt-forward-string
)
574 (edt-word-forward num
)
575 (edt-word-backward num
)))
581 (defun edt-character (num)
582 "Move in current direction to next character.
583 Argument NUM is the number of characters to move."
585 (edt-check-prefix num
)
586 (if (equal edt-direction-string edt-forward-string
)
589 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
594 ;;; When direction is set to BACKUP, LINE behaves just like BEGINNING
595 ;;; OF LINE in EDT. So edt-line-backward is not really needed as a
596 ;;; separate function.
598 (defun edt-line-backward (num)
599 "Move backward to next beginning of line mark.
600 Argument NUM is the number of BOL marks to move."
602 (edt-beginning-of-line num
))
604 (defun edt-line-forward (num)
605 "Move forward to next beginning of line mark.
606 Argument NUM is the number of BOL marks to move."
608 (edt-check-prefix num
)
609 (let ((beg (edt-current-line)))
611 (edt-bottom-check beg num
))
612 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
614 (defun edt-line (num)
615 "Move in current direction to next beginning of line mark.
616 Argument NUM is the number of BOL marks to move."
618 (if (equal edt-direction-string edt-forward-string
)
619 (edt-line-forward num
)
620 (edt-line-backward num
)))
623 ;;; UP and DOWN Arrows
626 (defun edt-next-line (num)
627 "Move cursor down one line.
628 Argument NUM is the number of lines to move."
630 (edt-check-prefix num
)
631 (let ((beg (edt-current-line)))
632 ;; We're deliberately using next-line instead of forward-line.
633 (with-no-warnings (next-line num
))
634 (edt-bottom-check beg num
))
635 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
637 (defun edt-previous-line (num)
638 "Move cursor up one line.
639 Argument NUM is the number of lines to move."
641 (edt-check-prefix num
)
642 (let ((beg (edt-current-line)))
643 ;; We're deliberately using previous-line instead of forward-line.
644 (with-no-warnings (previous-line num
))
645 (edt-top-check beg num
))
646 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
654 "Move cursor to the beginning of buffer."
656 (goto-char (point-min))
657 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
664 "Move cursor to the end of buffer."
666 (goto-char (point-max))
667 (edt-line-to-bottom-of-window))
673 (defun edt-find-forward (&optional find
)
674 "Find first occurrence of a string in forward direction and save it.
675 Optional argument FIND is t is this function is called from `edt-find'."
678 (set 'edt-find-last-text
(read-string "Search forward: ")))
680 (beg (edt-current-line))
681 (height (window-height))
683 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
685 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
686 (top-margin (/ (* height top-percent
) 100))
687 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
688 (bottom-margin (max beg
(- height bottom-up-margin
1)))
689 (top (save-excursion (move-to-window-line top-margin
) (point)))
690 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
692 (goto-char bottom
) (forward-line (- height
2)) (point))))
693 (if (search-forward edt-find-last-text
)
695 (search-backward edt-find-last-text
)
697 (cond((> (point) far
)
698 (setq left
(save-excursion (forward-line height
)))
699 (if (= 0 left
) (recenter top-margin
)
700 (recenter (- left bottom-up-margin
))))
702 (and (> (point) bottom
) (recenter bottom-margin
)))))))
703 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
705 (defun edt-find-backward (&optional find
)
706 "Find first occurrence of a string in the backward direction and save it.
707 Optional argument FIND is t if this function is called from `edt-find'."
710 (set 'edt-find-last-text
(read-string "Search backward: ")))
712 (beg (edt-current-line))
713 (height (window-height))
715 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
717 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
718 (top-margin (/ (* height top-percent
) 100))
719 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
720 (bottom-margin (max beg
(- height bottom-up-margin
1)))
721 (top (save-excursion (move-to-window-line top-margin
) (point)))
722 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
724 (goto-char bottom
) (forward-line (- height
2)) (point))))
725 (if (search-backward edt-find-last-text
)
727 (and (< (point) top
) (recenter (min beg top-margin
))))
728 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
731 "Find first occurrence of string in current direction and save it."
733 (set 'edt-find-last-text
(read-string "Search: "))
734 (if (equal edt-direction-string edt-forward-string
)
736 (edt-find-backward t
)))
743 (defun edt-find-next-forward ()
744 "Find next occurrence of a string in forward direction."
747 (beg (edt-current-line))
748 (height (window-height))
750 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
752 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
753 (top-margin (/ (* height top-percent
) 100))
754 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
755 (bottom-margin (max beg
(- height bottom-up-margin
1)))
756 (top (save-excursion (move-to-window-line top-margin
) (point)))
757 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
759 (goto-char bottom
) (forward-line (- height
2)) (point))))
761 (if (search-forward edt-find-last-text nil t
)
763 (search-backward edt-find-last-text
)
765 (cond((> (point) far
)
766 (setq left
(save-excursion (forward-line height
)))
767 (if (= 0 left
) (recenter top-margin
)
768 (recenter (- left bottom-up-margin
))))
770 (and (> (point) bottom
) (recenter bottom-margin
)))))
773 (error "Search failed: \"%s\"" edt-find-last-text
))))
774 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
776 (defun edt-find-next-backward ()
777 "Find next occurrence of a string in backward direction."
780 (beg (edt-current-line))
781 (height (window-height))
783 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
785 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
786 (top-margin (/ (* height top-percent
) 100))
787 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
788 (bottom-margin (max beg
(- height bottom-up-margin
1)))
789 (top (save-excursion (move-to-window-line top-margin
) (point)))
790 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
792 (goto-char bottom
) (forward-line (- height
2)) (point))))
793 (if (not (search-backward edt-find-last-text nil t
))
794 (error "Search failed: \"%s\"" edt-find-last-text
)
797 (and (< (point) top
) (recenter (min beg top-margin
))))))
798 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
800 (defun edt-find-next ()
801 "Find next occurrence of a string in current direction."
803 (if (equal edt-direction-string edt-forward-string
)
804 (edt-find-next-forward)
805 (edt-find-next-backward)))
812 "Append this kill region to last killed region."
814 (edt-check-selection)
816 (kill-region (mark) (point))
817 (message "Selected text APPENDED to kill ring"))
823 (defun edt-delete-line (num)
824 "Delete from cursor up to and including the end of line mark.
825 Argument NUM is the number of lines to delete."
827 (edt-check-prefix num
)
830 (if (not (eq (preceding-char) ?
\n))
832 (setq edt-last-deleted-lines
833 (buffer-substring beg
(point)))
834 (delete-region beg
(point))))
840 (defun edt-delete-to-end-of-line (num)
841 "Delete from cursor up to but excluding the end of line mark.
842 Argument NUM is the number of lines to delete."
844 (edt-check-prefix num
)
848 (setq edt-last-deleted-lines
849 (buffer-substring beg
(point)))
850 (delete-region beg
(point))))
856 (defun edt-select-mode (arg)
857 "Turn EDT select mode off if ARG is nil; otherwise, turn EDT select mode on.
858 In select mode, selected text is highlighted."
861 (make-local-variable 'edt-select-mode
)
862 (setq edt-select-mode
'edt-select-mode-current
)
863 (setq rect-start-point
(window-point)))
865 (kill-local-variable 'edt-select-mode
)))
866 (force-mode-line-update))
869 "Set mark at cursor and start text selection."
871 (set-mark-command nil
))
874 "Cancel text selection."
876 (if (featurep 'emacs
)
878 (zmacs-deactivate-region)))
885 "Deletes selected text but copies to kill ring."
887 (edt-check-selection)
888 (kill-region (mark) (point))
889 (message "Selected text CUT to kill ring"))
892 ;;; DELETE TO BEGINNING OF LINE
895 (defun edt-delete-to-beginning-of-line (num)
896 "Delete from cursor to beginning of line.
897 Argument NUM is the number of lines to delete."
899 (edt-check-prefix num
)
901 (edt-beginning-of-line num
)
902 (setq edt-last-deleted-lines
903 (buffer-substring (point) beg
))
904 (delete-region beg
(point))))
910 (defun edt-delete-word (num)
911 "Delete from cursor up to but excluding first character of next word.
912 Argument NUM is the number of words to delete."
914 (edt-check-prefix num
)
916 (edt-word-forward num
)
917 (setq edt-last-deleted-words
(buffer-substring beg
(point)))
918 (delete-region beg
(point))))
921 ;;; DELETE TO BEGINNING OF WORD
924 (defun edt-delete-to-beginning-of-word (num)
925 "Delete from cursor to beginning of word.
926 Argument NUM is the number of words to delete."
928 (edt-check-prefix num
)
930 (edt-word-backward num
)
931 (setq edt-last-deleted-words
(buffer-substring (point) beg
))
932 (delete-region beg
(point))))
938 (defun edt-delete-character (num)
939 "Delete character under cursor.
940 Argument NUM is the number of characters to delete."
942 (edt-check-prefix num
)
943 (setq edt-last-deleted-chars
944 (buffer-substring (point) (min (point-max) (+ (point) num
))))
945 (delete-region (point) (min (point-max) (+ (point) num
))))
951 (defun edt-delete-previous-character (num)
952 "Delete character in front of cursor.
953 Argument NUM is the number of characters to delete."
955 (edt-check-prefix num
)
956 (setq edt-last-deleted-chars
957 (buffer-substring (max (point-min) (- (point) num
)) (point)))
958 (delete-region (max (point-min) (- (point) num
)) (point)))
964 (defun edt-undelete-line ()
965 "Undelete previous deleted line(s)."
967 (point-to-register 1)
968 (insert edt-last-deleted-lines
)
969 (register-to-point 1))
975 (defun edt-undelete-word ()
976 "Undelete previous deleted word(s)."
978 (point-to-register 1)
979 (insert edt-last-deleted-words
)
980 (register-to-point 1))
986 (defun edt-undelete-character ()
987 "Undelete previous deleted character(s)."
989 (point-to-register 1)
990 (insert edt-last-deleted-chars
)
991 (register-to-point 1))
997 (defun edt-replace ()
998 "Replace marked section with last CUT (killed) text."
1000 (if (edt-check-match)
1001 (replace-match (car kill-ring-yank-pointer
))
1003 (exchange-point-and-mark)
1004 (let ((beg (point)))
1005 (exchange-point-and-mark)
1006 (delete-region beg
(point)))
1013 (defun edt-substitute (num)
1014 "Replace the selected region with the contents of the CUT buffer and.
1015 Repeat the most recent FIND command. (The Emacs kill ring is used as
1017 Argument NUM is the repeat count. A positive value indicates the of times
1018 to repeat the substitution. A negative argument means replace all occurrences
1019 of the search text."
1021 (cond ((or edt-select-mode
(edt-check-match))
1022 (while (and (not (= num
0)) (or edt-select-mode
(edt-check-match)))
1025 (setq num
(1- num
))))
1027 (error "No selection active"))))
1029 (defun edt-set-match nil
1030 "Set markers at match beginning and end."
1031 ;; Add one to beginning mark so it stays with the first character of
1032 ;; the string even if characters are added just before the string.
1033 (setq edt-match-beginning-mark
(copy-marker (1+ (match-beginning 0))))
1034 (setq edt-match-end-mark
(copy-marker (match-end 0))))
1036 (defun edt-unset-match nil
1037 "Unset match beginning and end markers."
1038 (set-marker edt-match-beginning-mark nil
)
1039 (set-marker edt-match-end-mark nil
))
1041 (defun edt-match-beginning nil
1042 "Return the location of the last match beginning."
1043 (1- (marker-position edt-match-beginning-mark
)))
1045 (defun edt-match-end nil
1046 "Return the location of the last match end."
1047 (marker-position edt-match-end-mark
))
1049 (defun edt-check-match nil
1050 "Return t if point is between edt-match markers.
1051 Otherwise sets the edt-match markers to nil and returns nil."
1052 ;; make sure 1- marker is in this buffer
1053 ;; 2- point is at or after beginning marker
1054 ;; 3- point is before ending marker, or in the case of
1055 ;; zero length regions (like bol, or eol) that the
1056 ;; beginning, end, and point are equal.
1058 (equal (marker-buffer edt-match-beginning-mark
) (current-buffer))
1059 (>= (point) (1- (marker-position edt-match-beginning-mark
)))
1061 (< (point) (marker-position edt-match-end-mark
))
1062 (and (= (1- (marker-position edt-match-beginning-mark
))
1063 (marker-position edt-match-end-mark
))
1064 (= (marker-position edt-match-end-mark
) (point))))) t
)
1066 (edt-unset-match) nil
)))
1068 (defun edt-show-match-markers nil
1069 "Show the values of the match markers."
1071 (if (markerp edt-match-beginning-mark
)
1072 (let ((beg (marker-position edt-match-beginning-mark
)))
1073 (message "(%s, %s) in %s -- current %s in %s"
1074 (if beg
(1- beg
) nil
)
1075 (marker-position edt-match-end-mark
)
1076 (marker-buffer edt-match-end-mark
)
1077 (point) (current-buffer)))))
1084 (defun edt-advance ()
1085 "Set movement direction forward.
1086 Also, execute command specified if in Minibuffer."
1088 (setq edt-direction-string edt-forward-string
)
1089 (force-mode-line-update)
1090 (if (string-equal " *Minibuf"
1091 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1093 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1100 (defun edt-backup ()
1101 "Set movement direction backward.
1102 Also, execute command specified if in Minibuffer."
1104 (setq edt-direction-string edt-backward-string
)
1105 (force-mode-line-update)
1106 (if (string-equal " *Minibuf"
1107 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1109 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1115 ;; This function is based upon Jeff Kowalski's case-flip function in his
1118 (defun edt-change-case (num)
1119 "Change the case of specified characters.
1120 If text selection IS active, then characters between the cursor and mark are
1121 changed. If text selection is NOT active, there are two cases. First, if the
1122 current direction is ADVANCE, then the prefix number of character(s) under and
1123 following cursor are changed. Second, if the current direction is BACKUP, then
1124 the prefix number of character(s) before the cursor are changed. Accepts a
1125 positive prefix for the number of characters to change, but the prefix is
1126 ignored if text selection is active.
1127 Argument NUM is the numbers of consecutive characters to change."
1129 (edt-check-prefix num
)
1131 (let ((end (max (mark) (point)))
1132 (point-save (point)))
1133 (goto-char (min (point) (mark)))
1134 (while (not (eq (point) end
))
1135 (funcall (if (<= ?a
(following-char))
1136 'upcase-region
'downcase-region
)
1137 (point) (1+ (point)))
1139 (goto-char point-save
))
1141 (if (string= edt-direction-string edt-backward-string
)
1142 (backward-char num
))
1144 (funcall (if (<= ?a
(following-char))
1145 'upcase-region
'downcase-region
)
1146 (point) (1+ (point)))
1148 (setq num
(1- num
))))))
1154 (defun edt-define-key ()
1155 "Assign an interactively-callable function to a specified key sequence.
1156 The current key definition is saved in `edt-last-replaced-key-definition'.
1157 Use `edt-restore-key' to restore last replaced key definition."
1159 (if (featurep 'xemacs
) (setq zmacs-region-stays t
))
1162 (setq edt-key-definition
1163 (read-key-sequence "Press the key to be defined: "))
1164 (if (if (featurep 'emacs
)
1165 (string-equal "\C-m" edt-key-definition
)
1166 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1167 (message "Key not defined")
1169 (setq edt-function
(read-command "Enter command name: "))
1170 (if (string-equal "" edt-function
)
1171 (message "Key not defined")
1173 (setq edt-last-replaced-key-definition
1174 (lookup-key (current-global-map) edt-key-definition
))
1175 (define-key (current-global-map)
1176 edt-key-definition edt-function
)))))))
1179 ;;; FORM FEED INSERT
1182 (defun edt-form-feed-insert (num)
1183 "Insert form feed character at cursor position.
1184 Argument NUM is the number of form feeds to insert."
1186 (edt-check-prefix num
)
1189 (setq num
(1- num
))))
1195 (defun edt-tab-insert (num)
1196 "Insert tab character at cursor position.
1197 Argument NUM is the number of tabs to insert."
1199 (edt-check-prefix num
)
1202 (setq num
(1- num
))))
1208 (defun edt-check-prefix (num)
1209 "Indicate error if prefix is not positive.
1210 Argument NUM is the prefix value tested."
1212 (error "Prefix must be positive")))
1218 (defun edt-check-selection ()
1219 "Indicate error if EDT selection is not active."
1220 (if (not edt-select-mode
)
1221 (error "Selection NOT active")))
1227 (defun edt-top-check (beg lines
)
1228 "Enforce scroll margin at the top of screen.
1229 Argument BEG is the starting line number before cursor was moved.
1230 Argument LINES is the number of lines the cursor moved toward the top."
1231 (let ((margin (/ (* (window-height) edt-top-scroll-margin
) 100)))
1232 (cond ((< beg margin
) (recenter beg
))
1233 ((< (- beg lines
) margin
) (recenter margin
)))))
1235 (defun edt-bottom-check (beg lines
)
1236 "Enforce scroll margin at the bottom of screen.
1237 Argument BEG is the starting line number before cursor was moved.
1238 Argument LINES is the number of lines the cursor moved toward the bottom."
1239 (let* ((height (window-height))
1240 (margin (+ 1 (/ (* height edt-bottom-scroll-margin
) 100)))
1241 ;; subtract 1 from height because it includes mode line
1242 (difference (- height margin
1)))
1243 (cond ((> beg difference
) (recenter beg
))
1244 ((and (featurep 'xemacs
) (> (+ beg lines
1) difference
))
1245 (recenter (- margin
)))
1246 ((> (+ beg lines
) difference
) (recenter (- margin
))))))
1248 (defun edt-current-line nil
1249 "Return the vertical position of point in the selected window.
1250 Top line is 0. Counts each text line only once, even if it wraps."
1251 (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -
1))
1254 (defun edt-set-scroll-margins (top bottom
)
1255 "Set scroll margins.
1256 Argument TOP is the top margin in number of lines or percent of window.
1257 Argument BOTTOM is the bottom margin in number of lines or percent of window."
1259 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \
1260 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
1261 ;; set top scroll margin
1262 (or (string= top
"")
1263 (if (string= "%" (substring top -
1))
1264 (setq edt-top-scroll-margin
(string-to-number top
))
1265 (setq edt-top-scroll-margin
1266 (/ (1- (+ (* (string-to-number top
) 100) (window-height)))
1268 ;; set bottom scroll margin
1269 (or (string= bottom
"")
1270 (if (string= "%" (substring bottom -
1))
1271 (setq edt-bottom-scroll-margin
(string-to-number bottom
))
1272 (setq edt-bottom-scroll-margin
1273 (/ (1- (+ (* (string-to-number bottom
) 100) (window-height)))
1275 ;; report scroll margin settings if running interactively
1276 (and (called-interactively-p 'interactive
)
1277 (message "Scroll margins set. Top = %s%%, Bottom = %s%%"
1278 edt-top-scroll-margin edt-bottom-scroll-margin
)))
1282 ;;;; ENHANCEMENTS AND ADDITIONS FOR EDT KEYPAD MODE
1286 ;;; Several enhancements and additions to EDT keypad mode commands are
1287 ;;; provided here. Some of these have been motivated by similar
1288 ;;; TPU/EVE and EVE-Plus commands. Others are new.
1291 ;;; CHANGE DIRECTION
1294 (defun edt-change-direction ()
1295 "Toggle movement direction."
1297 (if (equal edt-direction-string edt-forward-string
)
1305 (defun edt-toggle-select ()
1306 "Toggle to start (or cancel) text selection."
1316 (defun edt-sentence-forward (num)
1317 "Move forward to start of next sentence.
1318 Argument NUM is the positive number of sentences to move."
1320 (edt-check-prefix num
)
1322 (beg (edt-current-line))
1323 (height (window-height))
1325 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1327 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1328 (top-margin (/ (* height top-percent
) 100))
1329 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1330 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1331 (top (save-excursion (move-to-window-line top-margin
) (point)))
1332 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1333 (far (save-excursion
1334 (goto-char bottom
) (forward-line (- height
2)) (point))))
1337 (error "End of buffer"))
1339 (forward-sentence num
)
1341 (backward-sentence)))
1342 (cond((> (point) far
)
1343 (setq left
(save-excursion (forward-line height
)))
1344 (if (= 0 left
) (recenter top-margin
)
1345 (recenter (- left bottom-up-margin
))))
1347 (and (> (point) bottom
) (recenter bottom-margin
)))))
1348 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1350 (defun edt-sentence-backward (num)
1351 "Move backward to next sentence beginning.
1352 Argument NUM is the positive number of sentences to move."
1354 (edt-check-prefix num
)
1356 (beg (edt-current-line))
1357 (height (window-height))
1359 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1361 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1362 (top-margin (/ (* height top-percent
) 100))
1363 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1364 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1365 (top (save-excursion (move-to-window-line top-margin
) (point)))
1366 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1367 (far (save-excursion
1368 (goto-char bottom
) (forward-line (- height
2)) (point))))
1371 (error "End of buffer"))
1372 (backward-sentence num
))
1373 (and (< (point) top
) (recenter (min beg top-margin
))))
1374 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1376 (defun edt-sentence (num)
1377 "Move in current direction to next sentence.
1378 Argument NUM is the positive number of sentences to move."
1380 (if (equal edt-direction-string edt-forward-string
)
1381 (edt-sentence-forward num
)
1382 (edt-sentence-backward num
)))
1388 (defun edt-paragraph-forward (num)
1389 "Move forward to beginning of paragraph.
1390 Argument NUM is the positive number of paragraphs to move."
1392 (edt-check-prefix num
)
1394 (beg (edt-current-line))
1395 (height (window-height))
1397 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1399 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1400 (top-margin (/ (* height top-percent
) 100))
1401 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1402 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1403 (top (save-excursion (move-to-window-line top-margin
) (point)))
1404 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1405 (far (save-excursion
1406 (goto-char bottom
) (forward-line (- height
2)) (point))))
1408 (forward-paragraph (+ num
1))
1409 (start-of-paragraph-text)
1412 (setq num
(1- num
)))
1413 (cond((> (point) far
)
1414 (setq left
(save-excursion (forward-line height
)))
1415 (if (= 0 left
) (recenter top-margin
)
1416 (recenter (- left bottom-up-margin
))))
1418 (and (> (point) bottom
) (recenter bottom-margin
)))))
1419 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1421 (defun edt-paragraph-backward (num)
1422 "Move backward to beginning of paragraph.
1423 Argument NUM is the positive number of paragraphs to move."
1425 (edt-check-prefix num
)
1427 (beg (edt-current-line))
1428 (height (window-height))
1430 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1432 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1433 (top-margin (/ (* height top-percent
) 100))
1434 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1435 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1436 (top (save-excursion (move-to-window-line top-margin
) (point)))
1437 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1438 (far (save-excursion
1439 (goto-char bottom
) (forward-line (- height
2)) (point))))
1441 (start-of-paragraph-text)
1442 (setq num
(1- num
)))
1443 (and (< (point) top
) (recenter (min beg top-margin
))))
1444 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1446 (defun edt-paragraph (num)
1447 "Move in current direction to next paragraph.
1448 Argument NUM is the positive number of paragraphs to move."
1450 (if (equal edt-direction-string edt-forward-string
)
1451 (edt-paragraph-forward num
)
1452 (edt-paragraph-backward num
)))
1458 (defun edt-restore-key ()
1459 "Restore last replaced key definition.
1460 Definition is stored in `edt-last-replaced-key-definition'."
1462 (if (featurep 'xemacs
) (setq zmacs-region-stays t
))
1463 (if edt-last-replaced-key-definition
1465 (let (edt-key-definition)
1466 (set 'edt-key-definition
1467 (read-key-sequence "Press the key to be restored: "))
1468 (if (if (featurep 'emacs
)
1469 (string-equal "\C-m" edt-key-definition
)
1470 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1471 (message "Key not restored")
1473 (define-key (current-global-map)
1474 edt-key-definition edt-last-replaced-key-definition
)
1475 (if (featurep 'emacs
)
1476 (message "Key definition for %s has been restored."
1478 (message "Key definition for %s has been restored."
1479 (events-to-keys edt-key-definition
)))))))
1480 (error "No replaced key definition to restore!")))
1486 (defun edt-window-top ()
1487 "Move the cursor to the top of the window."
1489 (let ((start-column (current-column)))
1490 (move-to-window-line 0)
1491 (move-to-column start-column
))
1492 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1498 (defun edt-window-bottom ()
1499 "Move the cursor to the bottom of the window."
1501 (let ((start-column (current-column)))
1502 (move-to-window-line (- (window-height) 2))
1503 (move-to-column start-column
))
1504 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1507 ;;; SCROLL WINDOW LINE
1510 (defun edt-scroll-window-forward-line ()
1511 "Move window forward one line leaving cursor at position in window."
1514 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1516 (defun edt-scroll-window-backward-line ()
1517 "Move window backward one line leaving cursor at position in window."
1520 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1522 (defun edt-scroll-line ()
1523 "Move window one line in current direction."
1525 (if (equal edt-direction-string edt-forward-string
)
1526 (edt-scroll-window-forward-line)
1527 (edt-scroll-window-backward-line)))
1532 ;;; Scroll a window (less one line) at a time. Leave cursor in center of
1535 (defun edt-scroll-window-forward (num)
1536 "Scroll forward one window in buffer, less one line.
1537 Argument NUM is the positive number of windows to move."
1539 (edt-check-prefix num
)
1540 (scroll-up (- (* (window-height) num
) 2))
1541 (edt-line-forward (/ (- (window-height) 1) 2)))
1543 (defun edt-scroll-window-backward (num)
1544 "Scroll backward one window in buffer, less one line.
1545 Argument NUM is the positive number of windows to move."
1547 (edt-check-prefix num
)
1548 (scroll-down (- (* (window-height) num
) 2))
1549 (edt-line-backward (/ (- (window-height) 1) 2)))
1551 (defun edt-scroll-window (num)
1552 "Scroll one window in buffer, less one line, in current direction.
1553 Argument NUM is the positive number of windows to move."
1555 (if (equal edt-direction-string edt-forward-string
)
1556 (edt-scroll-window-forward num
)
1557 (edt-scroll-window-backward num
)))
1560 ;;; LINE TO BOTTOM OF WINDOW
1563 (defun edt-line-to-bottom-of-window ()
1564 "Move the current line to the bottom of the window."
1567 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1570 ;;; LINE TO TOP OF WINDOW
1573 (defun edt-line-to-top-of-window ()
1574 "Move the current line to the top of the window."
1577 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1580 ;;; LINE TO MIDDLE OF WINDOW
1583 (defun edt-line-to-middle-of-window ()
1584 "Move window so line with cursor is in the middle of the window."
1587 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1593 (defun edt-goto-percentage (num)
1594 "Move to specified percentage in buffer from top of buffer.
1595 Argument NUM is the percentage into the buffer to move."
1596 (interactive "NGoto-percentage: ")
1597 (if (or (> num
100) (< num
0))
1598 (error "Percentage %d out of range 0 < percent < 100" num
)
1599 (goto-char (/ (* (point-max) num
) 100)))
1600 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1606 (defun edt-fill-region ()
1607 "Fill selected text."
1609 (edt-check-selection)
1610 (fill-region (point) (mark)))
1613 ;;; INDENT OR FILL REGION
1616 (defun edt-indent-or-fill-region ()
1617 "Fill region in text modes, indent region in programming language modes."
1619 (if (string= paragraph-start
"$\\|\f")
1620 (indent-region (point) (mark) nil
)
1621 (fill-region (point) (mark))))
1624 (declare-function c-mark-function
"cc-cmds" ())
1626 ;;; MARK SECTION WISELY
1629 (defun edt-mark-section-wisely ()
1630 "Mark the section in a manner consistent with the `major-mode'.
1631 Uses `mark-defun' for Emacs-Lisp and Lisp, and for Fortran,
1632 `c-mark-function' for C,
1633 and `mark-paragraph' for other modes."
1639 (cond ((or (eq major-mode
'emacs-lisp-mode
)
1640 (eq major-mode
'fortran-mode
)
1641 (eq major-mode
'lisp-mode
))
1643 (message "Lisp defun selected"))
1644 ((eq major-mode
'c-mode
)
1646 (message "C function selected"))
1648 (message "Paragraph selected"))))))
1655 "Copy selected region to kill ring, but don't delete it!"
1657 (edt-check-selection)
1658 (copy-region-as-kill (mark) (point))
1660 (message "Selected text COPIED to kill ring"))
1666 (defun edt-cut-or-copy ()
1667 "Cuts (or copies) selected text to kill ring.
1668 Cuts selected text if `buffer-read-only' is nil.
1669 Copies selected text if `buffer-read-only' is t."
1671 (if buffer-read-only
1676 ;;; DELETE ENTIRE LINE
1679 (defun edt-delete-entire-line ()
1680 "Delete entire line regardless of cursor position in the line."
1683 (edt-delete-line 1))
1689 (defun edt-duplicate-line (num)
1690 "Duplicate the line of text containing the cursor.
1691 Argument NUM is the number of times to duplicate the line."
1693 (edt-check-prefix num
)
1694 (let ((old-column (current-column))
1696 (edt-delete-entire-line)
1700 (setq count
(1- count
)))
1701 (edt-line-forward num
)
1702 (move-to-column old-column
)))
1708 (defun edt-duplicate-word()
1709 "Duplicate word (or rest of word) found directly above cursor, if any."
1711 (let ((start (point))
1712 (start-column (current-column)))
1714 (move-to-column start-column
)
1715 (if (and (not (equal start
(point)))
1718 (if (and (equal ?
\t (preceding-char))
1719 (< start-column
(current-column)))
1721 (let ((beg (point)))
1722 (edt-one-word-forward)
1723 (setq edt-last-copied-word
(buffer-substring beg
(point))))
1725 (move-to-column start-column
)
1726 (insert edt-last-copied-word
))
1728 (if (not (equal start
(point)))
1730 (move-to-column start-column
)
1731 (error "Nothing to duplicate!")))))
1734 ;;; KEY NOT ASSIGNED
1737 (defun edt-key-not-assigned ()
1738 "Displays message that key has not been assigned to a function."
1740 (error "Key not assigned"))
1743 ;;; TOGGLE CAPITALIZATION OF WORD
1746 (defun edt-toggle-capitalization-of-word ()
1747 "Toggle the capitalization of the current word and move forward to next."
1749 (edt-one-word-forward)
1750 (edt-one-word-backward)
1752 (edt-one-word-backward)
1753 (edt-one-word-forward))
1756 ;;; ELIMINATE ALL TABS
1759 (defun edt-eliminate-all-tabs ()
1760 "Convert all tabs to spaces in the entire buffer."
1762 (untabify (point-min) (point-max))
1763 (message "TABS converted to SPACES"))
1766 ;;; DISPLAY THE TIME
1769 (defun edt-display-the-time ()
1770 "Display the current time."
1772 (if (featurep 'xemacs
) (setq zmacs-region-stays t
))
1773 (message "%s" (current-time-string)))
1780 "Learn a sequence of key strokes to bind to a key."
1782 (if (eq defining-kbd-macro t
)
1784 (start-kbd-macro nil
)))
1790 (defun edt-remember ()
1791 "Store the sequence of key strokes started by `edt-learn' to a key."
1793 (if (eq defining-kbd-macro nil
)
1794 (error "Nothing to remember!")
1797 (let (edt-key-definition)
1798 (set 'edt-key-definition
1799 (read-key-sequence "Enter key for binding: "))
1800 (if (if (featurep 'emacs
)
1801 (string-equal "\C-m" edt-key-definition
)
1802 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1803 (message "Key sequence not remembered")
1805 (set 'edt-learn-macro-count
(+ edt-learn-macro-count
1))
1806 (setq edt-last-replaced-key-definition
1807 (lookup-key (current-global-map)
1808 edt-key-definition
))
1809 (define-key (current-global-map) edt-key-definition
1810 (name-last-kbd-macro
1811 (intern (concat "last-learned-sequence-"
1812 (int-to-string edt-learn-macro-count
)))))))))))
1819 "Save current buffer, ask to save other buffers, and then exit Emacs."
1822 (save-buffers-kill-emacs))
1829 "Quit Emacs without saving buffer modifications.
1830 Warn user that modifications will be lost."
1832 (let ((list (buffer-list))
1834 (while (and list working
)
1835 (let ((buffer (car list
)))
1836 (if (and (buffer-file-name buffer
) (buffer-modified-p buffer
))
1838 "Modifications will not be saved, continue quitting? ")
1840 (setq working nil
)))
1841 (setq list
(cdr list
))))
1842 (if working
(kill-emacs))))
1848 (defun edt-split-window ()
1849 "Split current window and place cursor in the new window."
1853 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1859 (defun edt-copy-rectangle ()
1860 "Copy a rectangle of text between mark and cursor to register."
1862 (edt-check-selection)
1863 (copy-rectangle-to-register 3 (region-beginning) (region-end) nil
)
1865 (message "Selected rectangle COPIED to register"))
1871 (defun edt-cut-rectangle-overstrike-mode ()
1872 "Cut a rectangle of text between mark and cursor to register.
1873 Replace cut characters with spaces and moving cursor back to
1876 (edt-check-selection)
1877 (setq edt-rect-start-point
(region-beginning))
1878 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3)
1879 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point
)
1880 (message "Selected rectangle CUT to register"))
1882 (defun edt-cut-rectangle-insert-mode ()
1883 "Cut a rectangle of text between mark and cursor to register.
1884 Move cursor back to upper left corner."
1886 (edt-check-selection)
1887 (setq edt-rect-start-point
(region-beginning))
1888 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3 t
)
1890 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point
)
1891 (message "Selected rectangle CUT to register"))
1893 (defun edt-cut-rectangle ()
1894 "Cut a rectangular region of text to register.
1895 If overwrite mode is active, cut text is replaced with whitespace."
1898 (edt-cut-rectangle-overstrike-mode)
1899 (edt-cut-rectangle-insert-mode)))
1905 (defun edt-paste-rectangle-overstrike-mode ()
1906 "Paste a rectangular region of text from register, replacing text at cursor."
1908 (picture-yank-rectangle-from-register 3))
1910 (defun edt-paste-rectangle-insert-mode ()
1911 "Paste previously deleted rectangular region, inserting text at cursor."
1913 (picture-yank-rectangle-from-register 3 t
))
1915 (defun edt-paste-rectangle ()
1916 "Paste a rectangular region of text.
1917 If overwrite mode is active, existing text is replace with text from register."
1920 (edt-paste-rectangle-overstrike-mode)
1921 (edt-paste-rectangle-insert-mode)))
1927 (defun edt-lowercase ()
1928 "Change specified characters to lower case.
1929 If text selection IS active, then characters between the cursor and
1930 mark are changed. If text selection is NOT active, there are two
1931 situations. If the current direction is ADVANCE, then the word under
1932 the cursor is changed to lower case and the cursor is moved to rest at
1933 the beginning of the next word. If the current direction is BACKUP,
1934 the word prior to the word under the cursor is changed to lower case
1935 and the cursor is left to rest at the beginning of that word."
1939 (downcase-region (mark) (point)))
1941 ;; Move to beginning of current word.
1947 (not (eq ?\
(char-syntax (preceding-char))))
1948 (not (memq (preceding-char) edt-word-entities
))
1949 (not (memq (following-char) edt-word-entities
)))
1950 (edt-one-word-backward))
1951 (if (equal edt-direction-string edt-backward-string
)
1952 (edt-one-word-backward))
1953 (let ((beg (point)))
1954 (edt-one-word-forward)
1955 (downcase-region beg
(point)))
1956 (if (equal edt-direction-string edt-backward-string
)
1957 (edt-one-word-backward)))))
1963 (defun edt-uppercase ()
1964 "Change specified characters to upper case.
1965 If text selection IS active, then characters between the cursor and
1966 mark are changed. If text selection is NOT active, there are two
1967 situations. If the current direction is ADVANCE, then the word under
1968 the cursor is changed to upper case and the cursor is moved to rest at
1969 the beginning of the next word. If the current direction is BACKUP,
1970 the word prior to the word under the cursor is changed to upper case
1971 and the cursor is left to rest at the beginning of that word."
1975 (upcase-region (mark) (point)))
1977 ;; Move to beginning of current word.
1983 (not (eq ?\
(char-syntax (preceding-char))))
1984 (not (memq (preceding-char) edt-word-entities
))
1985 (not (memq (following-char) edt-word-entities
)))
1986 (edt-one-word-backward))
1987 (if (equal edt-direction-string edt-backward-string
)
1988 (edt-one-word-backward))
1989 (let ((beg (point)))
1990 (edt-one-word-forward)
1991 (upcase-region beg
(point)))
1992 (if (equal edt-direction-string edt-backward-string
)
1993 (edt-one-word-backward)))))
1996 ;;; Functions used in loading LK-201 key mapping file.
1998 (defvar edt-last-answer nil
1999 "Most recent response to `edt-y-or-n-p'.")
2001 (defun edt-y-or-n-p (prompt &optional not-yes
)
2002 "Prompt for a y or n answer with positive default.
2003 Like Emacs `y-or-n-p', also accepts space as y and DEL as n.
2004 Argument PROMPT is the prompt string.
2005 Optional argument NOT-YES changes the default to negative."
2006 (message "%s[%s]" prompt
(if not-yes
"n" "y"))
2010 (let ((ans (read-char)))
2011 (cond ((or (= ans ?y
) (= ans ?Y
) (= ans ?\
))
2012 (setq edt-last-answer t
))
2013 ((or (= ans ?n
) (= ans ?N
) (= ans ?\C-?
))
2014 (setq edt-last-answer nil
))
2015 ((= ans ?
\r) (setq edt-last-answer
(not not-yes
)))
2017 (setq doit t
) (beep)
2018 (message "Please answer y or n. %s[%s]"
2019 prompt
(if not-yes
"n" "y")))))))
2023 ;;; INITIALIZATION COMMANDS.
2027 ;;; Function used to load LK-201 key mapping file generated by edt-mapper.el.
2029 (defun edt-load-keys (file)
2030 "Load the LK-201 key mapping FILE generated by edt-mapper.el.
2031 If FILE is nil, which is the normal case, try to load a default file.
2032 The default file names are based upon the window system, terminal
2033 type, and version of Emacs in use: GNU Emacs or XEmacs (aka Lucid
2034 Emacs). If a default file does not exist, ask user if one should be
2036 (interactive "fKey definition file: ")
2038 (setq file
(expand-file-name file
)))
2040 (setq file
(expand-file-name edt-keys-file
)))
2045 "~/.edt-" edt-emacs-variant
2046 (if edt-term
(concat "-" edt-term
))
2047 (if edt-xserver
(concat "-" edt-xserver
))
2048 (if edt-window-system
2049 (concat "-" (upcase (symbol-name edt-window-system
))))
2051 (cond ((file-readable-p file
)
2054 (switch-to-buffer "*scratch*")
2058 Ack!! You're running the Enhanced EDT Emulation without loading an
2059 EDT key mapping file. To create an EDT key mapping file, run the
2060 edt-mapper.el program. It is safest to run it from an Emacs loaded
2061 without any of your own customizations found in your .emacs file, etc.
2062 The reason for this is that some user customizations confuse edt-mapper.
2063 You can do this by quitting Emacs and then invoking Emacs again as
2066 emacs -q -l edt-mapper.el
2068 [NOTE: If you do nothing out of the ordinary in your .emacs file, and
2069 the search for edt-mapper.el is successful, you can try running it now.]
2071 The file edt-mapper.el includes these same directions on how to
2072 use it! Perhaps it's lying around here someplace. \n ")
2073 (let ((file "edt-mapper.el")
2076 (search-list (append (list (expand-file-name ".")) load-path
)))
2077 (while (and (not found
) search-list
)
2078 (setq path
(concat (car search-list
)
2079 (if (string-match "/$" (car search-list
)) "" "/")
2081 (if (and (file-exists-p path
) (not (file-directory-p path
)))
2083 (setq search-list
(cdr search-list
)))
2086 "Ah yes, there it is, in \n\n %s \n\n" path
))
2087 (if (edt-y-or-n-p "Do you want to run it now? ")
2089 (error "EDT Emulation not configured")))
2091 (insert "Nope, I can't seem to find it. :-(\n\n")
2093 (error "EDT Emulation not configured")))))))
2096 ;;; Turning the EDT Emulation on and off.
2100 (defun edt-emulation-on ()
2101 "Turn on EDT Emulation."
2103 ;; If using pc window system (MS-DOS), set terminal type to pc.
2104 ;; If not a window system (GNU) or a tty window system (XEmacs),
2105 ;; get terminal type.
2106 (if (eq edt-window-system
'pc
)
2107 (setq edt-term
"pc")
2108 (if (or (not edt-window-system
) (eq edt-window-system
'tty
))
2109 (setq edt-term
(getenv "TERM"))))
2110 ;; Look for a terminal configuration file for this terminal type.
2111 ;; Otherwise, load the user's custom configuration file.
2112 (if (or (not edt-window-system
) (memq edt-window-system
'(pc tty
)))
2114 ;; Load terminal-specific configuration file, if it exists for this
2115 ;; terminal type. Note: All DEC VT series terminals are supported
2116 ;; by the same terminal configuration file: edt-vt100.el.
2117 (if (string-equal "vt" (substring edt-term
0 (min (length edt-term
) 2)))
2118 (setq edt-term
"vt100"))
2119 (let ((term edt-term
)
2122 (not (load (concat "edt-" term
) t t
)))
2123 ;; Strip off last hyphen and what follows, then try again
2124 (if (setq hyphend
(string-match "[-_][^-_]+$" term
))
2125 (setq term
(substring term
0 hyphend
))
2127 ;; If no terminal-specific configuration file exists, load user's
2128 ;; custom EDT terminal configuration file.
2129 ;; If this is a pc running MS-DOS, then custom configuration files
2130 ;; are not supported. So, if the file is missing, issue an error
2133 (if (equal edt-term
"pc")
2134 (error "Unable to find EDT terminal specific file edt-pc.el")
2135 (edt-load-keys nil
))
2136 (setq edt-term term
))))
2137 (edt-load-keys nil
))
2138 ;; Make highlighting of selected text work properly for EDT commands.
2139 (if (featurep 'emacs
)
2141 (setq edt-orig-transient-mark-mode transient-mark-mode
)
2142 (add-hook 'activate-mark-hook
2145 (edt-select-mode t
))))
2146 (add-hook 'deactivate-mark-hook
2149 (edt-select-mode nil
)))))
2151 (add-hook 'zmacs-activate-region-hook
2154 (edt-select-mode t
))))
2155 (add-hook 'zmacs-deactivate-region-hook
2158 (edt-select-mode nil
))))))
2159 ;; Load user's EDT custom key bindings file, if it exists.
2160 ;; Otherwise, use the default bindings.
2161 (if (load "edt-user" t t
)
2162 (edt-user-emulation-setup)
2163 (edt-default-emulation-setup)))
2165 (defun edt-emulation-off()
2166 "Select original global key bindings, disabling EDT Emulation."
2168 (use-global-map global-map
)
2169 (if (not edt-keep-current-page-delimiter
)
2170 (setq page-delimiter edt-orig-page-delimiter
))
2171 (setq edt-direction-string
"")
2172 (setq edt-select-mode-current nil
)
2174 (force-mode-line-update t
)
2175 (if (featurep 'emacs
)
2176 (setq transient-mark-mode edt-orig-transient-mark-mode
))
2177 (message "Original key bindings restored; EDT Emulation disabled"))
2179 (defun edt-default-emulation-setup (&optional user-setup
)
2180 "Setup emulation of DEC's EDT editor.
2181 Optional argument USER-SETUP non-nil means called from function
2182 `edt-user-emulation-setup'."
2183 ;; Setup default EDT global map by copying global map bindings.
2184 ;; This preserves ESC and C-x prefix bindings and other bindings we
2185 ;; wish to retain in EDT emulation mode keymaps. It also permits
2186 ;; customization of these bindings in the EDT global maps without
2187 ;; disturbing the original bindings in global-map.
2188 (fset 'edt-default-ESC-prefix
(copy-keymap 'ESC-prefix
))
2189 (setq edt-default-global-map
(copy-keymap (current-global-map)))
2190 (if (featurep 'emacs
)
2191 (define-key edt-default-global-map
"\e" 'edt-default-ESC-prefix
)
2192 (define-key edt-default-global-map
[escape] 'edt-default-ESC-prefix))
2193 (define-prefix-command 'edt-default-gold-map)
2194 (edt-setup-default-bindings)
2195 ;; If terminal has additional function keys, the terminal-specific
2196 ;; initialization file can assign bindings to them via the optional
2197 ;; function edt-setup-extra-default-bindings.
2198 (if (fboundp 'edt-setup-extra-default-bindings)
2199 (edt-setup-extra-default-bindings))
2200 ;; Variable needed by edt-learn.
2201 (setq edt-learn-macro-count 0)
2202 ;; Display EDT text selection active within the mode line
2203 (or (assq 'edt-select-mode minor-mode-alist)
2204 (setq minor-mode-alist
2205 (cons '(edt-select-mode edt-select-mode) minor-mode-alist)))
2206 ;; Display EDT direction of motion within the mode line
2207 (or (assq 'edt-direction-string minor-mode-alist)
2208 (setq minor-mode-alist
2210 '(edt-direction-string edt-direction-string) minor-mode-alist)))
2213 (setq edt-user-map-configured t)
2214 (fset 'edt-emulation-on (symbol-function 'edt-select-user-global-map)))
2216 (fset 'edt-emulation-on (symbol-function 'edt-select-default-global-map))
2217 (edt-select-default-global-map)))
2218 ;; We need to share `global-buffers-menu-map' with the saved global
2219 ;; keymap, because `menu-bar-update-buffers' directly changes it.
2220 (define-key (current-global-map) [menu-bar buffer]
2221 (cons "Buffers" global-buffers-menu-map)))
2223 (defun edt-user-emulation-setup ()
2224 "Setup user custom emulation of DEC's EDT editor."
2225 ;; Initialize EDT default bindings.
2226 (edt-default-emulation-setup t)
2227 ;; Setup user EDT global map by copying default EDT global map bindings.
2228 (fset 'edt-user-ESC-prefix (copy-keymap 'edt-default-ESC-prefix))
2229 (setq edt-user-global-map (copy-keymap edt-default-global-map))
2230 (if (featurep 'emacs)
2231 (define-key edt-user-global-map "\e" 'edt-user-ESC-prefix)
2232 (define-key edt-user-global-map [escape] 'edt-user-ESC-prefix
))
2233 ;; If terminal has additional function keys, the user's initialization
2234 ;; file can assign bindings to them via the optional
2235 ;; function edt-setup-extra-default-bindings.
2236 (define-prefix-command 'edt-user-gold-map
)
2237 (fset 'edt-user-gold-map
(copy-keymap 'edt-default-gold-map
))
2238 ;; This is a function that the user can define for custom bindings.
2239 ;; See Info node `edt' for more details, and sample edt-user.el file.
2240 (if (fboundp 'edt-setup-user-bindings
)
2241 (edt-setup-user-bindings))
2242 (edt-select-user-global-map))
2244 (defun edt-select-default-global-map()
2245 "Select default EDT emulation key bindings."
2247 (if (featurep 'emacs
)
2248 (transient-mark-mode 1))
2249 (use-global-map edt-default-global-map
)
2250 (if (not edt-keep-current-page-delimiter
)
2252 (setq edt-orig-page-delimiter page-delimiter
)
2253 (setq page-delimiter
"\f")))
2254 (setq edt-default-map-active t
)
2256 (setq edt-select-mode-current
'edt-select-mode-string
)
2258 (message "Default EDT keymap active"))
2260 (defun edt-select-user-global-map()
2261 "Select user EDT emulation custom key bindings."
2263 (if edt-user-map-configured
2265 (if (featurep 'emacs
)
2266 (transient-mark-mode 1))
2267 (use-global-map edt-user-global-map
)
2268 (if (not edt-keep-current-page-delimiter
)
2270 (setq edt-orig-page-delimiter page-delimiter
)
2271 (setq page-delimiter
"\f")))
2272 (setq edt-default-map-active nil
)
2274 (setq edt-select-mode-current
'edt-select-mode-string
)
2276 (message "User EDT custom keymap active"))
2277 (error "User EDT custom keymap NOT configured!")))
2279 (defun edt-switch-global-maps ()
2280 "Toggle between default EDT keymap and user EDT keymap."
2282 (if edt-default-map-active
2283 (edt-select-user-global-map)
2284 (edt-select-default-global-map)))
2287 ;; Functions used to set up DEFAULT bindings to EDT emulation functions.
2290 (defun edt-bind-function-key-default (function-key binding gold-binding
)
2291 "Binds LK-201 function keys to default bindings in the EDT Emulator.
2292 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2293 Argument BINDING is the Emacs function to be bound to <KEY>.
2294 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2295 (let ((key (cdr (assoc function-key
*EDT-keys
*))))
2296 (if (and key
(not (equal key
"")))
2298 (define-key edt-default-global-map key binding
)
2299 (define-key 'edt-default-gold-map key gold-binding
)))))
2301 (defun edt-bind-key-default (key binding
)
2302 "Bind key sequences to default bindings in the EDT Emulator.
2303 Argument KEY is the name of a standard key or a function key.
2304 Argument BINDING is the Emacs function to be bound to <KEY>."
2305 (define-key edt-default-global-map key binding
))
2307 (defun edt-bind-gold-key-default (key gold-binding
)
2308 "Binds <GOLD> key sequences to default bindings in the EDT Emulator.
2309 Argument KEY is the name of a standard key or a function key.
2310 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2311 (define-key 'edt-default-gold-map key gold-binding
))
2314 ;; Functions used to set up USER CUSTOM bindings to EDT emulation functions.
2316 (defun edt-bind-function-key (function-key binding gold-binding
)
2317 "Binds LK-201 function keys to custom bindings in the EDT Emulator.
2318 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2319 Argument BINDING is the Emacs function to be bound to <KEY>.
2320 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2321 (let ((key (cdr (assoc function-key
*EDT-keys
*))))
2322 (if (and key
(not (equal key
"")))
2324 (define-key edt-user-global-map key binding
)
2325 (define-key 'edt-user-gold-map key gold-binding
)))))
2327 (defun edt-bind-key (key binding
)
2328 "Bind standard key sequences to custom bindings in the EDT Emulator.
2329 Argument KEY is the name of a key. It can be a standard key or a function key.
2330 Argument BINDING is the Emacs function to be bound to <KEY>."
2331 (define-key edt-user-global-map key binding
))
2333 ;; For backward compatibility to existing edt-user.el files.
2334 (fset 'edt-bind-standard-key
(symbol-function 'edt-bind-key
))
2336 (defun edt-bind-gold-key (key gold-binding
)
2337 "Binds <GOLD> standard key sequences to custom bindings in the EDT Emulator.
2338 Argument KEY is the name of a standard key or a function key.
2339 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2340 (define-key 'edt-user-gold-map key gold-binding
))
2342 (defun edt-setup-default-bindings ()
2343 "Assigns default EDT Emulation keyboard bindings."
2345 ;; Function Key Bindings: Regular and GOLD.
2347 ;; VT100/VT200/VT300 PF1 (GOLD), PF2, PF3, PF4 Keys
2348 (edt-bind-function-key-default "PF1"
2349 'edt-default-gold-map
'edt-mark-section-wisely
)
2350 (edt-bind-function-key-default "PF2"
2351 'edt-electric-keypad-help
'describe-function
)
2352 (edt-bind-function-key-default "PF3" 'edt-find-next
'edt-find
)
2353 (edt-bind-function-key-default "PF4" 'edt-delete-line
'edt-undelete-line
)
2355 ;; VT100/VT200/VT300 Arrow Keys
2356 (edt-bind-function-key-default "UP" 'edt-previous-line
'edt-window-top
)
2357 (edt-bind-function-key-default "DOWN" 'edt-next-line
'edt-window-bottom
)
2358 (edt-bind-function-key-default "LEFT" 'backward-char
'edt-sentence-backward
)
2359 (edt-bind-function-key-default "RIGHT" 'forward-char
'edt-sentence-forward
)
2361 ;; VT100/VT200/VT300 Keypad Keys
2362 (edt-bind-function-key-default "KP0" 'edt-line
'open-line
)
2363 (edt-bind-function-key-default "KP1" 'edt-word
'edt-change-case
)
2364 (edt-bind-function-key-default "KP2"
2365 'edt-end-of-line
'edt-delete-to-end-of-line
)
2366 (edt-bind-function-key-default "KP3" 'edt-character
'quoted-insert
)
2367 (edt-bind-function-key-default "KP4" 'edt-advance
'edt-bottom
)
2368 (edt-bind-function-key-default "KP5" 'edt-backup
'edt-top
)
2369 (edt-bind-function-key-default "KP6" 'edt-cut
'yank
)
2370 (edt-bind-function-key-default "KP7" 'edt-page
'execute-extended-command
)
2371 (edt-bind-function-key-default "KP8" 'edt-sect
'edt-fill-region
)
2372 (edt-bind-function-key-default "KP9" 'edt-append
'edt-replace
)
2373 (edt-bind-function-key-default "KP-" 'edt-delete-word
'edt-undelete-word
)
2374 (edt-bind-function-key-default "KP,"
2375 'edt-delete-character
'edt-undelete-character
)
2376 (edt-bind-function-key-default "KPP" 'edt-select
'edt-reset
)
2377 (edt-bind-function-key-default "KPE" 'other-window
'edt-substitute
)
2379 ;; VT200/VT300 Function Keys
2380 ;; (F1 through F5, on the VT220, are not programmable, so we skip
2381 ;; making default bindings to those keys.
2382 (edt-bind-function-key-default "FIND" 'edt-find-next
'edt-find
)
2383 (edt-bind-function-key-default "INSERT" 'yank
'edt-key-not-assigned
)
2384 (edt-bind-function-key-default "REMOVE" 'edt-cut
'edt-copy
)
2385 (edt-bind-function-key-default "SELECT"
2386 'edt-toggle-select
'edt-key-not-assigned
)
2387 (edt-bind-function-key-default "NEXT"
2388 'edt-sect-forward
'edt-key-not-assigned
)
2389 (edt-bind-function-key-default "PREVIOUS"
2390 'edt-sect-backward
'edt-key-not-assigned
)
2391 (edt-bind-function-key-default "F6"
2392 'edt-key-not-assigned
'edt-key-not-assigned
)
2393 (edt-bind-function-key-default "F7"
2394 'edt-copy-rectangle
'edt-key-not-assigned
)
2395 (edt-bind-function-key-default "F8"
2396 'edt-cut-rectangle-overstrike-mode
'edt-paste-rectangle-overstrike-mode
)
2397 (edt-bind-function-key-default "F9"
2398 'edt-cut-rectangle-insert-mode
'edt-paste-rectangle-insert-mode
)
2399 (edt-bind-function-key-default "F10" 'edt-cut-rectangle
'edt-paste-rectangle
)
2400 ;; Under X, the F11 key can be bound. If using a VT-200 or higher terminal,
2401 ;; the default emacs terminal support causes the VT F11 key to seem as if it
2402 ;; is an ESC key when in emacs.
2403 (edt-bind-function-key-default "F11"
2404 'edt-key-not-assigned
'edt-key-not-assigned
)
2405 (edt-bind-function-key-default "F12"
2406 'edt-beginning-of-line
'delete-other-windows
) ;BS
2407 (edt-bind-function-key-default "F13"
2408 'edt-delete-to-beginning-of-word
'edt-key-not-assigned
) ;LF
2409 (edt-bind-function-key-default "F14"
2410 'edt-key-not-assigned
'edt-key-not-assigned
)
2411 (edt-bind-function-key-default "HELP"
2412 'edt-electric-keypad-help
'edt-key-not-assigned
)
2413 (edt-bind-function-key-default "DO"
2414 'execute-extended-command
'edt-key-not-assigned
)
2415 (edt-bind-function-key-default "F17"
2416 'edt-key-not-assigned
'edt-key-not-assigned
)
2417 (edt-bind-function-key-default "F18"
2418 'edt-key-not-assigned
'edt-key-not-assigned
)
2419 (edt-bind-function-key-default "F19"
2420 'edt-key-not-assigned
'edt-key-not-assigned
)
2421 (edt-bind-function-key-default "F20"
2422 'edt-key-not-assigned
'edt-key-not-assigned
)
2424 ;; Control key bindings: Regular and GOLD
2426 ;; Standard EDT control key bindings conflict with standard Emacs
2427 ;; control key bindings. Normally, the standard Emacs control key
2428 ;; bindings are left unchanged in the default EDT mode. However, if
2429 ;; the variable edt-use-EDT-control-key-bindings is set to true
2430 ;; before invoking edt-emulation-on for the first time, then the
2431 ;; standard EDT bindings (with some enhancements) as defined here are
2433 (if edt-use-EDT-control-key-bindings
2435 (edt-bind-key-default "\C-a" 'edt-key-not-assigned
)
2436 (edt-bind-key-default "\C-b" 'edt-key-not-assigned
)
2437 ;; Leave binding of C-c to an Emacs prefix key.
2438 (edt-bind-key-default "\C-d" 'edt-key-not-assigned
)
2439 (edt-bind-key-default "\C-e" 'edt-key-not-assigned
)
2440 (edt-bind-key-default "\C-f" 'edt-key-not-assigned
)
2441 ;; Leave binding of C-g to the Emacs keyboard-quit
2442 (edt-bind-key-default "\C-h" 'edt-beginning-of-line
)
2443 (edt-bind-key-default "\C-i" 'edt-tab-insert
)
2444 (edt-bind-key-default "\C-j" 'edt-delete-to-beginning-of-word
)
2445 (edt-bind-key-default "\C-k" 'edt-define-key
)
2446 (edt-bind-gold-key-default "\C-k" 'edt-restore-key
)
2447 (edt-bind-key-default "\C-l" 'edt-form-feed-insert
)
2448 ;; Leave binding of C-m to newline.
2449 (edt-bind-key-default "\C-n" 'edt-set-screen-width-80
)
2450 (edt-bind-key-default "\C-o" 'edt-key-not-assigned
)
2451 (edt-bind-key-default "\C-p" 'edt-key-not-assigned
)
2452 (edt-bind-key-default "\C-q" 'edt-key-not-assigned
)
2453 ;; Leave binding of C-r to isearch-backward.
2454 ;; Leave binding of C-s to isearch-forward.
2455 (edt-bind-key-default "\C-t" 'edt-display-the-time
)
2456 (edt-bind-key-default "\C-u" 'edt-delete-to-beginning-of-line
)
2457 (edt-bind-key-default "\C-v" 'redraw-display
)
2458 (edt-bind-key-default "\C-w" 'edt-set-screen-width-132
)
2459 ;; Leave binding of C-x as original prefix key.
2460 (edt-bind-key-default "\C-y" 'edt-key-not-assigned
)
2461 ;; Leave binding of C-z to suspend-emacs.
2465 ;; GOLD bindings for a few keys.
2466 (edt-bind-gold-key-default "\C-g" 'keyboard-quit
); Just in case.
2467 (edt-bind-gold-key-default "\C-h" 'help-for-help
); Just in case.
2468 (edt-bind-gold-key-default [f1] 'help-for-help)
2469 (edt-bind-gold-key-default [help] 'help-for-help)
2470 (edt-bind-gold-key-default "\C-\\" 'split-window-vertically)
2472 ;; GOLD bindings for regular keys.
2473 (edt-bind-gold-key-default "a" 'edt-key-not-assigned)
2474 (edt-bind-gold-key-default "A" 'edt-key-not-assigned)
2475 (edt-bind-gold-key-default "b" 'buffer-menu)
2476 (edt-bind-gold-key-default "B" 'buffer-menu)
2477 (edt-bind-gold-key-default "c" 'compile)
2478 (edt-bind-gold-key-default "C" 'compile)
2479 (edt-bind-gold-key-default "d" 'delete-window)
2480 (edt-bind-gold-key-default "D" 'delete-window)
2481 (edt-bind-gold-key-default "e" 'edt-exit)
2482 (edt-bind-gold-key-default "E" 'edt-exit)
2483 (edt-bind-gold-key-default "f" 'find-file)
2484 (edt-bind-gold-key-default "F" 'find-file)
2485 (edt-bind-gold-key-default "g" 'find-file-other-window)
2486 (edt-bind-gold-key-default "G" 'find-file-other-window)
2487 (edt-bind-gold-key-default "h" 'edt-electric-keypad-help)
2488 (edt-bind-gold-key-default "H" 'edt-electric-keypad-help)
2489 (edt-bind-gold-key-default "i" 'insert-file)
2490 (edt-bind-gold-key-default "I" 'insert-file)
2491 (edt-bind-gold-key-default "j" 'edt-key-not-assigned)
2492 (edt-bind-gold-key-default "J" 'edt-key-not-assigned)
2493 (edt-bind-gold-key-default "k" 'edt-toggle-capitalization-of-word)
2494 (edt-bind-gold-key-default "K" 'edt-toggle-capitalization-of-word)
2495 (edt-bind-gold-key-default "l" 'edt-lowercase)
2496 (edt-bind-gold-key-default "L" 'edt-lowercase)
2497 (edt-bind-gold-key-default "m" 'save-some-buffers)
2498 (edt-bind-gold-key-default "M" 'save-some-buffers)
2499 (edt-bind-gold-key-default "n" 'next-error)
2500 (edt-bind-gold-key-default "N" 'next-error)
2501 (edt-bind-gold-key-default "o" 'switch-to-buffer-other-window)
2502 (edt-bind-gold-key-default "O" 'switch-to-buffer-other-window)
2503 (edt-bind-gold-key-default "p" 'edt-key-not-assigned)
2504 (edt-bind-gold-key-default "P" 'edt-key-not-assigned)
2505 (edt-bind-gold-key-default "q" 'edt-quit)
2506 (edt-bind-gold-key-default "Q" 'edt-quit)
2507 (edt-bind-gold-key-default "r" 'revert-buffer)
2508 (edt-bind-gold-key-default "R" 'revert-buffer)
2509 (edt-bind-gold-key-default "s" 'save-buffer)
2510 (edt-bind-gold-key-default "S" 'save-buffer)
2511 (edt-bind-gold-key-default "t" 'edt-key-not-assigned)
2512 (edt-bind-gold-key-default "T" 'edt-key-not-assigned)
2513 (edt-bind-gold-key-default "u" 'edt-uppercase)
2514 (edt-bind-gold-key-default "U" 'edt-uppercase)
2515 (edt-bind-gold-key-default "v" 'find-file-other-window)
2516 (edt-bind-gold-key-default "V" 'find-file-other-window)
2517 (edt-bind-gold-key-default "w" 'write-file)
2518 (edt-bind-gold-key-default "W" 'write-file)
2519 (edt-bind-gold-key-default "x" 'edt-key-not-assigned)
2520 (edt-bind-gold-key-default "X" 'edt-key-not-assigned)
2521 (edt-bind-gold-key-default "y" 'edt-emulation-off)
2522 (edt-bind-gold-key-default "Y" 'edt-emulation-off)
2523 (edt-bind-gold-key-default "z" 'edt-switch-global-maps)
2524 (edt-bind-gold-key-default "Z" 'edt-switch-global-maps)
2525 (edt-bind-gold-key-default "1" 'delete-other-windows)
2526 (edt-bind-gold-key-default "!" 'edt-key-not-assigned)
2527 (edt-bind-gold-key-default "2" 'edt-split-window)
2528 (edt-bind-gold-key-default "@" 'edt-key-not-assigned)
2529 (edt-bind-gold-key-default "3" 'edt-key-not-assigned)
2530 (edt-bind-gold-key-default "#" 'edt-key-not-assigned)
2531 (edt-bind-gold-key-default "4" 'edt-key-not-assigned)
2532 (edt-bind-gold-key-default "$" 'edt-key-not-assigned)
2533 (edt-bind-gold-key-default "5" 'edt-key-not-assigned)
2534 (edt-bind-gold-key-default "%" 'edt-goto-percentage)
2535 (edt-bind-gold-key-default "6" 'edt-key-not-assigned)
2536 (edt-bind-gold-key-default "^" 'edt-key-not-assigned)
2537 (edt-bind-gold-key-default "7" 'edt-key-not-assigned)
2538 (edt-bind-gold-key-default "&" 'edt-key-not-assigned)
2539 (edt-bind-gold-key-default "8" 'edt-key-not-assigned)
2540 (edt-bind-gold-key-default "*" 'edt-key-not-assigned)
2541 (edt-bind-gold-key-default "9" 'edt-key-not-assigned)
2542 (edt-bind-gold-key-default "(" 'edt-key-not-assigned)
2543 (edt-bind-gold-key-default "0" 'edt-key-not-assigned)
2544 (edt-bind-gold-key-default ")" 'edt-key-not-assigned)
2545 (edt-bind-gold-key-default " " 'undo)
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 ">" 'edt-key-not-assigned)
2550 (edt-bind-gold-key-default "/" 'query-replace)
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 "_" 'edt-key-not-assigned)
2560 (edt-bind-gold-key-default "=" 'goto-line)
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 "}" 'edt-key-not-assigned)
2566 (edt-bind-gold-key-default "`" 'what-line)
2567 (edt-bind-gold-key-default "~" 'edt-key-not-assigned)
2571 ;;; DEFAULT EDT KEYPAD HELP
2575 ;;; Upper case commands in the keypad diagram below indicate that the
2576 ;;; emulation should look and feel very much like EDT. Lower case
2577 ;;; commands are enhancements and/or additions to the EDT keypad
2578 ;;; commands or are native Emacs commands.
2581 (defun edt-keypad-help ()
2582 "DEFAULT EDT Keypad Active.
2584 F7: Copy Rectangle +----------+----------+----------+----------+
2585 F8: Cut Rect Overstrike |Prev Line |Next Line |Bkwd Char |Frwd Char |
2586 G-F8: Paste Rect Overstrike | (UP) | (DOWN) | (LEFT) | (RIGHT) |
2587 F9: Cut Rect Insert |Window Top|Window Bot|Bkwd Sent |Frwd Sent |
2588 G-F9: Paste Rect Insert +----------+----------+----------+----------+
2590 G-F10: Paste Rectangle
2592 F12: Begining of Line +----------+----------+----------+----------+
2593 G-F12: Delete Other Windows | GOLD | HELP | FNDNXT | DEL L |
2594 F13: Delete to Begin of Word | (PF1) | (PF2) | (PF3) | (PF4) |
2595 HELP: Keypad Help |Mark Wisel|Desc Funct| FIND | UND L |
2596 G-HELP: Emacs Help +----------+----------+----------+----------+
2597 DO: Execute extended command | PAGE | SECT | APPEND | DEL W |
2598 C-g: Keyboard Quit | (7) | (8) | (9) | (-) |
2599 G-C-g: Keyboard Quit |Ex Ext Cmd|Fill Regio| REPLACE | UND W |
2600 C-h: Beginning of Line +----------+----------+----------+----------+
2601 G-C-h: Emacs Help | ADVANCE | BACKUP | CUT | DEL C |
2602 C-i: Tab Insert | (4) | (5) | (6) | (,) |
2603 C-j: Delete to Begin of Word | BOTTOM | TOP | Yank | UND C |
2604 C-k: Define Key +----------+----------+----------+----------+
2605 G-C-k: Restore Key | WORD | EOL | CHAR | Next |
2606 C-l: Form Feed Insert | (1) | (2) | (3) | Window |
2607 C-n: Set Screen Width 80 | CHNGCASE | DEL EOL |Quoted Ins| !
2608 C-r: Isearch Backward +---------------------+----------+ (ENTER) |
2609 C-s: Isearch Forward | LINE | SELECT | !
2610 C-t: Display the Time | (0) | (.) | SUBS |
2611 C-u: Delete to Begin of Line | Open Line | RESET | |
2612 C-v: Redraw Display +---------------------+----------+----------+
2613 C-w: Set Screen Width 132
2614 C-z: Suspend Emacs +----------+----------+----------+
2615 G-C-\\: Split Window | FNDNXT | Yank | CUT |
2616 | (FIND) | (INSERT) | (REMOVE) |
2617 G-b: Buffer Menu | FIND | | COPY |
2618 G-c: Compile +----------+----------+----------+
2619 G-d: Delete Window |SELECT/RES|SECT BACKW|SECT FORWA|
2620 G-e: Exit | (SELECT) |(PREVIOUS)| (NEXT) |
2621 G-f: Find File | | | |
2622 G-g: Find File Other Window +----------+----------+----------+
2625 G-k: Toggle Capitalization Word
2626 G-l: Downcase Region
2627 G-m: Save Some Buffers
2629 G-o: Switch to Next Window
2634 G-v: Find File Other Window
2636 G-y: EDT Emulation OFF
2637 G-z: Switch to User EDT Key Bindings
2638 G-1: Delete Other Windows
2640 G-%: Go to Percentage
2641 G- : Undo (GOLD Spacebar)
2647 (describe-function 'edt-keypad-help))
2649 (defun edt-electric-helpify (fun)
2650 (let ((name "*Help*"))
2651 (if (save-window-excursion
2652 (let* ((p (symbol-function 'help-print-return-message))
2653 (b (get-buffer name))
2654 (m (buffer-modified-p b)))
2655 (and b (not (get-buffer-window b))
2659 (message "%s..." (capitalize (symbol-name fun)))
2661 (with-current-buffer b
2662 (set-buffer-modified-p t)))
2663 (fset 'help-print-return-message 'ignore)
2664 (call-interactively fun)
2665 (and (get-buffer name)
2666 (get-buffer-window (get-buffer name))
2668 (not (eq b (get-buffer name)))
2669 (not (buffer-modified-p b)))))
2670 (fset 'help-print-return-message p)
2671 (and b (buffer-name b)
2672 (with-current-buffer b
2673 (set-buffer-modified-p m))))))
2674 (with-electric-help 'delete-other-windows name t))))
2676 (defun edt-electric-keypad-help ()
2677 "Display default EDT bindings."
2679 (edt-electric-helpify 'edt-keypad-help))
2681 (defun edt-electric-user-keypad-help ()
2682 "Display user custom EDT bindings."
2684 (edt-electric-helpify 'edt-user-keypad-help))
2687 ;;; EDT emulation screen width commands.
2689 ;; Some terminals require modification of terminal attributes when
2690 ;; changing the number of columns displayed, hence the fboundp tests
2691 ;; below. These functions are defined in the corresponding terminal
2692 ;; specific file, if needed.
2694 (defun edt-set-screen-width-80 ()
2695 "Set screen width to 80 columns."
2697 (if (fboundp 'edt-set-term-width-80)
2698 (edt-set-term-width-80))
2699 (set-frame-width nil 80)
2700 (message "Terminal width 80"))
2702 (defun edt-set-screen-width-132 ()
2703 "Set screen width to 132 columns."
2705 (if (fboundp 'edt-set-term-width-132)
2706 (edt-set-term-width-132))
2707 (set-frame-width nil 132)
2708 (message "Terminal width 132"))
2712 ;; arch-tag: 18d1c54f-6900-4078-8bbc-7c2292f48941
2713 ;;; edt.el ends here