1 ;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs
3 ;; Copyright (C) 1986, 1992-1995, 2000-2012 Free Software Foundation, Inc.
5 ;; Author: Kevin Gallagher <Kevin.Gallagher@boeing.com>
6 ;; Maintainer: Kevin Gallagher <Kevin.Gallagher@boeing.com>
7 ;; Keywords: emulations
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; This is Version 4.0 of the EDT Emulation for Emacs.
30 ;; It comes with special functions which replicate nearly all of EDT's
31 ;; keypad mode behavior. It sets up default keypad and function key
32 ;; bindings which closely match those found in EDT. Support is
33 ;; provided so that users may reconfigure most keypad and function key
34 ;; bindings to their own liking.
36 ;; NOTE: Version 4.0 contains several enhancements. See the
37 ;; Enhancement section below for the details.
41 ;; To start the EDT Emulation, first start Emacs and then enter
43 ;; M-x edt-emulation-on
45 ;; to begin the emulation. After initialization is complete, the
46 ;; following message will appear below the status line informing you
47 ;; that the emulation has been enabled: "Default EDT keymap active".
49 ;; You can have the EDT Emulation start up automatically, each time
50 ;; you initiate a GNU Emacs session, by adding the following line to
53 ;; (add-hook term-setup-hook 'edt-emulation-on)
55 ;; IMPORTANT: Be sure to read the Info node `edt' for more details.
56 ;; It contains very helpful user information.
58 ;; The EDT emulation consists of the following files:
60 ;; edt.texi - User manual
61 ;; edt-user.el - 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
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
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 to set the following two variables
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.
106 ;; See Info node `edt' for more 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
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
151 ;; Version 4.0 2000 Added New Features and Fixed a Few Bugs
157 ;;; Electric Help functions are used for keypad help displays. A few
158 ;;; picture functions are used in rectangular cut and paste commands.
164 ;;;; VARIABLES and CONSTANTS
168 "Emacs emulating EDT."
172 ;; To silence the byte-compiler
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
)
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."
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."
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-[
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
)
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."
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."
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'.")
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 "[ /]" "-"
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.")
339 ;;;; EDT Emulation Commands
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.
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
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."
372 (edt-check-prefix num
)
374 (error "End of buffer")
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."
385 (edt-check-prefix num
)
387 (error "Beginning of buffer")
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."
397 (if (equal edt-direction-string edt-forward-string
)
398 (edt-page-forward num
)
399 (edt-page-backward num
)))
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."
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."
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."
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."
444 (edt-check-prefix num
)
445 (let ((beg (edt-current-line)))
447 (forward-line (* -
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."
463 (edt-check-prefix num
)
464 (let ((beg (edt-current-line)))
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."
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."
486 (if (equal edt-direction-string edt-forward-string
)
487 (edt-end-of-line-forward num
)
488 (edt-end-of-line-backward num
)))
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."
506 (error "End of buffer"))
510 (if (memq (following-char) edt-word-entities
)
515 (not (eq ?\
(char-syntax (following-char))))
516 (not (memq (following-char) edt-word-entities
)))
521 (eq ?\
(char-syntax (following-char)))
522 (not (memq (following-char) edt-word-entities
)))
524 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
526 (defun edt-one-word-backward ()
527 "Move backward to first character of previous word."
530 (error "Beginning of buffer"))
538 (eq ?\
(char-syntax (following-char)))
539 (not (memq (following-char) edt-word-entities
)))
541 (if (not (memq (following-char) edt-word-entities
))
545 (not (eq ?\
(char-syntax (preceding-char))))
546 (not (memq (preceding-char) edt-word-entities
)))
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."
554 (edt-check-prefix num
)
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."
563 (edt-check-prefix num
)
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."
572 (if (equal edt-direction-string edt-forward-string
)
573 (edt-word-forward num
)
574 (edt-word-backward num
)))
580 (defun edt-character (num)
581 "Move in current direction to next character.
582 Argument NUM is the number of characters to move."
584 (edt-check-prefix num
)
585 (if (equal edt-direction-string edt-forward-string
)
588 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
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."
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."
607 (edt-check-prefix num
)
608 (let ((beg (edt-current-line)))
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."
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."
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."
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
)))
653 "Move cursor to the beginning of buffer."
655 (goto-char (point-min))
656 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
663 "Move cursor to the end of buffer."
665 (goto-char (point-max))
666 (edt-line-to-bottom-of-window))
668 (defmacro edt-with-position
(&rest body
)
669 "Execute BODY with some position-related variables bound."
671 (beg (edt-current-line))
672 (height (window-height))
674 (if (zerop edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
676 (if (zerop edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
677 (top-margin (/ (* height top-percent
) 100))
678 (bottom-up-margin (1+ (/ (* height bottom-percent
) 100)))
679 (bottom-margin (max beg
(- height bottom-up-margin
1)))
680 (top (save-excursion (move-to-window-line top-margin
) (point)))
681 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
684 (point-at-bol (1- height
)))))
691 (defun edt-find-forward (&optional find
)
692 "Find first occurrence of a string in forward direction and save it.
693 Optional argument FIND is t is this function is called from `edt-find'."
696 (setq edt-find-last-text
(read-string "Search forward: ")))
698 (when (search-forward edt-find-last-text
) ; FIXME noerror?
699 (search-backward edt-find-last-text
)
702 (if (zerop (setq left
(save-excursion (forward-line height
))))
703 (recenter top-margin
)
704 (recenter (- left bottom-up-margin
)))
705 (and (> (point) bottom
) (recenter bottom-margin
)))))
706 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
708 (defun edt-find-backward (&optional find
)
709 "Find first occurrence of a string in the backward direction and save it.
710 Optional argument FIND is t if this function is called from `edt-find'."
713 (setq edt-find-last-text
(read-string "Search backward: ")))
715 (if (search-backward edt-find-last-text
)
717 (and (< (point) top
) (recenter (min beg top-margin
))))
718 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
721 "Find first occurrence of string in current direction and save it."
723 (set 'edt-find-last-text
(read-string "Search: "))
724 (if (equal edt-direction-string edt-forward-string
)
726 (edt-find-backward t
)))
733 (defun edt-find-next-forward ()
734 "Find next occurrence of a string in forward direction."
738 (if (search-forward edt-find-last-text nil t
)
740 (search-backward edt-find-last-text
)
743 (if (zerop (setq left
(save-excursion (forward-line height
))))
744 (recenter top-margin
)
745 (recenter (- left bottom-up-margin
)))
746 (and (> (point) bottom
) (recenter bottom-margin
))))
748 (error "Search failed: \"%s\"" edt-find-last-text
)))
749 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
751 (defun edt-find-next-backward ()
752 "Find next occurrence of a string in backward direction."
755 (if (not (search-backward edt-find-last-text nil t
))
756 (error "Search failed: \"%s\"" edt-find-last-text
)
758 (and (< (point) top
) (recenter (min beg top-margin
)))))
759 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
761 (defun edt-find-next ()
762 "Find next occurrence of a string in current direction."
764 (if (equal edt-direction-string edt-forward-string
)
765 (edt-find-next-forward)
766 (edt-find-next-backward)))
773 "Append this kill region to last killed region."
775 (edt-check-selection)
777 (kill-region (mark) (point))
778 (message "Selected text APPENDED to kill ring"))
784 (defun edt-delete-line (num)
785 "Delete from cursor up to and including the end of line mark.
786 Argument NUM is the number of lines to delete."
788 (edt-check-prefix num
)
791 (if (not (eq (preceding-char) ?
\n))
793 (setq edt-last-deleted-lines
794 (buffer-substring beg
(point)))
795 (delete-region beg
(point))))
801 (defun edt-delete-to-end-of-line (num)
802 "Delete from cursor up to but excluding the end of line mark.
803 Argument NUM is the number of lines to delete."
805 (edt-check-prefix num
)
809 (setq edt-last-deleted-lines
810 (buffer-substring beg
(point)))
811 (delete-region beg
(point))))
817 (defun edt-select-mode (arg)
818 "Turn EDT select mode off if ARG is nil; otherwise, turn EDT select mode on.
819 In select mode, selected text is highlighted."
822 (set (make-local-variable 'edt-select-mode
) 'edt-select-mode-current
)
823 (setq rect-start-point
(window-point)))
825 (kill-local-variable 'edt-select-mode
)))
826 (force-mode-line-update))
829 "Set mark at cursor and start text selection."
831 (set-mark-command nil
))
834 "Cancel text selection."
836 (if (featurep 'emacs
)
838 (zmacs-deactivate-region)))
845 "Deletes selected text but copies to kill ring."
847 (edt-check-selection)
848 (kill-region (mark) (point))
849 (message "Selected text CUT to kill ring"))
852 ;;; DELETE TO BEGINNING OF LINE
855 (defun edt-delete-to-beginning-of-line (num)
856 "Delete from cursor to beginning of line.
857 Argument NUM is the number of lines to delete."
859 (edt-check-prefix num
)
861 (edt-beginning-of-line num
)
862 (setq edt-last-deleted-lines
863 (buffer-substring (point) beg
))
864 (delete-region beg
(point))))
870 (defun edt-delete-word (num)
871 "Delete from cursor up to but excluding first character of next word.
872 Argument NUM is the number of words to delete."
874 (edt-check-prefix num
)
876 (edt-word-forward num
)
877 (setq edt-last-deleted-words
(buffer-substring beg
(point)))
878 (delete-region beg
(point))))
881 ;;; DELETE TO BEGINNING OF WORD
884 (defun edt-delete-to-beginning-of-word (num)
885 "Delete from cursor to beginning of word.
886 Argument NUM is the number of words to delete."
888 (edt-check-prefix num
)
890 (edt-word-backward num
)
891 (setq edt-last-deleted-words
(buffer-substring (point) beg
))
892 (delete-region beg
(point))))
898 (defun edt-delete-character (num)
899 "Delete character under cursor.
900 Argument NUM is the number of characters to delete."
902 (edt-check-prefix num
)
903 (setq edt-last-deleted-chars
904 (buffer-substring (point) (min (point-max) (+ (point) num
))))
905 (delete-region (point) (min (point-max) (+ (point) num
))))
911 (defun edt-delete-previous-character (num)
912 "Delete character in front of cursor.
913 Argument NUM is the number of characters to delete."
915 (edt-check-prefix num
)
916 (setq edt-last-deleted-chars
917 (buffer-substring (max (point-min) (- (point) num
)) (point)))
918 (delete-region (max (point-min) (- (point) num
)) (point)))
924 (defun edt-undelete-line ()
925 "Undelete previous deleted line(s)."
927 (point-to-register 1)
928 (insert edt-last-deleted-lines
)
929 (register-to-point 1))
935 (defun edt-undelete-word ()
936 "Undelete previous deleted word(s)."
938 (point-to-register 1)
939 (insert edt-last-deleted-words
)
940 (register-to-point 1))
946 (defun edt-undelete-character ()
947 "Undelete previous deleted character(s)."
949 (point-to-register 1)
950 (insert edt-last-deleted-chars
)
951 (register-to-point 1))
957 (defun edt-replace ()
958 "Replace marked section with last CUT (killed) text."
960 (if (edt-check-match)
961 (replace-match (car kill-ring-yank-pointer
))
963 (exchange-point-and-mark)
965 (exchange-point-and-mark)
966 (delete-region beg
(point)))
973 (defun edt-substitute (num)
974 "Replace the selected region with the contents of the CUT buffer and.
975 Repeat the most recent FIND command. (The Emacs kill ring is used as
977 Argument NUM is the repeat count. A positive value indicates the of times
978 to repeat the substitution. A negative argument means replace all occurrences
981 (cond ((or edt-select-mode
(edt-check-match))
982 (while (and (not (= num
0)) (or edt-select-mode
(edt-check-match)))
985 (setq num
(1- num
))))
987 (error "No selection active"))))
989 (defun edt-set-match nil
990 "Set markers at match beginning and end."
991 ;; Add one to beginning mark so it stays with the first character of
992 ;; the string even if characters are added just before the string.
993 (setq edt-match-beginning-mark
(copy-marker (1+ (match-beginning 0))))
994 (setq edt-match-end-mark
(copy-marker (match-end 0))))
996 (defun edt-unset-match nil
997 "Unset match beginning and end markers."
998 (set-marker edt-match-beginning-mark nil
)
999 (set-marker edt-match-end-mark nil
))
1001 (defun edt-match-beginning nil
1002 "Return the location of the last match beginning."
1003 (1- (marker-position edt-match-beginning-mark
)))
1005 (defun edt-match-end nil
1006 "Return the location of the last match end."
1007 (marker-position edt-match-end-mark
))
1009 (defun edt-check-match nil
1010 "Return t if point is between edt-match markers.
1011 Otherwise sets the edt-match markers to nil and returns nil."
1012 ;; make sure 1- marker is in this buffer
1013 ;; 2- point is at or after beginning marker
1014 ;; 3- point is before ending marker, or in the case of
1015 ;; zero length regions (like bol, or eol) that the
1016 ;; beginning, end, and point are equal.
1018 (equal (marker-buffer edt-match-beginning-mark
) (current-buffer))
1019 (>= (point) (1- (marker-position edt-match-beginning-mark
)))
1021 (< (point) (marker-position edt-match-end-mark
))
1022 (and (= (1- (marker-position edt-match-beginning-mark
))
1023 (marker-position edt-match-end-mark
))
1024 (= (marker-position edt-match-end-mark
) (point))))) t
)
1026 (edt-unset-match) nil
)))
1028 (defun edt-show-match-markers nil
1029 "Show the values of the match markers."
1031 (if (markerp edt-match-beginning-mark
)
1032 (let ((beg (marker-position edt-match-beginning-mark
)))
1033 (message "(%s, %s) in %s -- current %s in %s"
1034 (if beg
(1- beg
) nil
)
1035 (marker-position edt-match-end-mark
)
1036 (marker-buffer edt-match-end-mark
)
1037 (point) (current-buffer)))))
1044 (defun edt-advance ()
1045 "Set movement direction forward.
1046 Also, execute command specified if in Minibuffer."
1048 (setq edt-direction-string edt-forward-string
)
1049 (force-mode-line-update)
1050 (if (string-equal " *Minibuf"
1051 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1053 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1060 (defun edt-backup ()
1061 "Set movement direction backward.
1062 Also, execute command specified if in Minibuffer."
1064 (setq edt-direction-string edt-backward-string
)
1065 (force-mode-line-update)
1066 (if (string-equal " *Minibuf"
1067 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1069 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1075 ;; This function is based upon Jeff Kowalski's case-flip function in his
1078 (defun edt-change-case (num)
1079 "Change the case of specified characters.
1080 If text selection IS active, then characters between the cursor and mark are
1081 changed. If text selection is NOT active, there are two cases. First, if the
1082 current direction is ADVANCE, then the prefix number of character(s) under and
1083 following cursor are changed. Second, if the current direction is BACKUP, then
1084 the prefix number of character(s) before the cursor are changed. Accepts a
1085 positive prefix for the number of characters to change, but the prefix is
1086 ignored if text selection is active.
1087 Argument NUM is the numbers of consecutive characters to change."
1089 (edt-check-prefix num
)
1091 (let ((end (max (mark) (point)))
1092 (point-save (point)))
1093 (goto-char (min (point) (mark)))
1094 (while (not (eq (point) end
))
1095 (funcall (if (<= ?a
(following-char))
1096 'upcase-region
'downcase-region
)
1097 (point) (1+ (point)))
1099 (goto-char point-save
))
1101 (if (string= edt-direction-string edt-backward-string
)
1102 (backward-char num
))
1104 (funcall (if (<= ?a
(following-char))
1105 'upcase-region
'downcase-region
)
1106 (point) (1+ (point)))
1108 (setq num
(1- num
))))))
1114 (defun edt-define-key ()
1115 "Assign an interactively-callable function to a specified key sequence.
1116 The current key definition is saved in `edt-last-replaced-key-definition'.
1117 Use `edt-restore-key' to restore last replaced key definition."
1119 (if (featurep 'xemacs
) (setq zmacs-region-stays t
))
1122 (setq edt-key-definition
1123 (read-key-sequence "Press the key to be defined: "))
1124 (if (if (featurep 'emacs
)
1125 (string-equal "\C-m" edt-key-definition
)
1126 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1127 (message "Key not defined")
1129 (setq edt-function
(read-command "Enter command name: "))
1130 (if (string-equal "" edt-function
)
1131 (message "Key not defined")
1133 (setq edt-last-replaced-key-definition
1134 (lookup-key (current-global-map) edt-key-definition
))
1135 (define-key (current-global-map)
1136 edt-key-definition edt-function
)))))))
1139 ;;; FORM FEED INSERT
1142 (defun edt-form-feed-insert (num)
1143 "Insert form feed character at cursor position.
1144 Argument NUM is the number of form feeds to insert."
1146 (edt-check-prefix num
)
1149 (setq num
(1- num
))))
1155 (defun edt-tab-insert (num)
1156 "Insert tab character at cursor position.
1157 Argument NUM is the number of tabs to insert."
1159 (edt-check-prefix num
)
1162 (setq num
(1- num
))))
1168 (defun edt-check-prefix (num)
1169 "Indicate error if prefix is not positive.
1170 Argument NUM is the prefix value tested."
1172 (error "Prefix must be positive")))
1178 (defun edt-check-selection ()
1179 "Indicate error if EDT selection is not active."
1180 (if (not edt-select-mode
)
1181 (error "Selection NOT active")))
1187 (defun edt-top-check (beg lines
)
1188 "Enforce scroll margin at the top of screen.
1189 Argument BEG is the starting line number before cursor was moved.
1190 Argument LINES is the number of lines the cursor moved toward the top."
1191 (let ((margin (/ (* (window-height) edt-top-scroll-margin
) 100)))
1192 (cond ((< beg margin
) (recenter beg
))
1193 ((< (- beg lines
) margin
) (recenter margin
)))))
1195 (defun edt-bottom-check (beg lines
)
1196 "Enforce scroll margin at the bottom of screen.
1197 Argument BEG is the starting line number before cursor was moved.
1198 Argument LINES is the number of lines the cursor moved toward the bottom."
1199 (let* ((height (window-height))
1200 (margin (+ 1 (/ (* height edt-bottom-scroll-margin
) 100)))
1201 ;; subtract 1 from height because it includes mode line
1202 (difference (- height margin
1)))
1203 (cond ((> beg difference
) (recenter beg
))
1204 ((and (featurep 'xemacs
) (> (+ beg lines
1) difference
))
1205 (recenter (- margin
)))
1206 ((> (+ beg lines
) difference
) (recenter (- margin
))))))
1208 (defun edt-current-line nil
1209 "Return the vertical position of point in the selected window.
1210 Top line is 0. Counts each text line only once, even if it wraps."
1211 (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -
1))
1214 (defun edt-set-scroll-margins (top bottom
)
1215 "Set scroll margins.
1216 Argument TOP is the top margin in number of lines or percent of window.
1217 Argument BOTTOM is the bottom margin in number of lines or percent of window."
1219 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \
1220 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
1221 ;; set top scroll margin
1222 (or (string= top
"")
1223 (if (string= "%" (substring top -
1))
1224 (setq edt-top-scroll-margin
(string-to-number top
))
1225 (setq edt-top-scroll-margin
1226 (/ (1- (+ (* (string-to-number top
) 100) (window-height)))
1228 ;; set bottom scroll margin
1229 (or (string= bottom
"")
1230 (if (string= "%" (substring bottom -
1))
1231 (setq edt-bottom-scroll-margin
(string-to-number bottom
))
1232 (setq edt-bottom-scroll-margin
1233 (/ (1- (+ (* (string-to-number bottom
) 100) (window-height)))
1235 ;; report scroll margin settings if running interactively
1236 (and (called-interactively-p 'interactive
)
1237 (message "Scroll margins set. Top = %s%%, Bottom = %s%%"
1238 edt-top-scroll-margin edt-bottom-scroll-margin
)))
1242 ;;;; ENHANCEMENTS AND ADDITIONS FOR EDT KEYPAD MODE
1246 ;;; Several enhancements and additions to EDT keypad mode commands are
1247 ;;; provided here. Some of these have been motivated by similar
1248 ;;; TPU/EVE and EVE-Plus commands. Others are new.
1251 ;;; CHANGE DIRECTION
1254 (defun edt-change-direction ()
1255 "Toggle movement direction."
1257 (if (equal edt-direction-string edt-forward-string
)
1265 (defun edt-toggle-select ()
1266 "Toggle to start (or cancel) text selection."
1276 (defun edt-sentence-forward (num)
1277 "Move forward to start of next sentence.
1278 Argument NUM is the positive number of sentences to move."
1280 (edt-check-prefix num
)
1283 (error "End of buffer")
1284 (forward-sentence num
)
1286 (backward-sentence))
1288 (if (zerop (setq left
(save-excursion (forward-line height
))))
1289 (recenter top-margin
)
1290 (recenter (- left bottom-up-margin
)))
1291 (and (> (point) bottom
) (recenter bottom-margin
))))
1292 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1294 (defun edt-sentence-backward (num)
1295 "Move backward to next sentence beginning.
1296 Argument NUM is the positive number of sentences to move."
1298 (edt-check-prefix num
)
1301 (error "End of buffer")
1302 (backward-sentence num
))
1303 (and (< (point) top
) (recenter (min beg top-margin
))))
1304 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1306 (defun edt-sentence (num)
1307 "Move in current direction to next sentence.
1308 Argument NUM is the positive number of sentences to move."
1310 (if (equal edt-direction-string edt-forward-string
)
1311 (edt-sentence-forward num
)
1312 (edt-sentence-backward num
)))
1318 (defun edt-paragraph-forward (num)
1319 "Move forward to beginning of paragraph.
1320 Argument NUM is the positive number of paragraphs to move."
1322 (edt-check-prefix num
)
1325 (forward-paragraph (+ num
1))
1326 (start-of-paragraph-text)
1329 (setq num
(1- num
)))
1331 (if (zerop (setq left
(save-excursion (forward-line height
))))
1332 (recenter top-margin
)
1333 (recenter (- left bottom-up-margin
)))
1334 (and (> (point) bottom
) (recenter bottom-margin
))))
1335 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1337 (defun edt-paragraph-backward (num)
1338 "Move backward to beginning of paragraph.
1339 Argument NUM is the positive number of paragraphs to move."
1341 (edt-check-prefix num
)
1344 (start-of-paragraph-text)
1345 (setq num
(1- num
)))
1346 (and (< (point) top
) (recenter (min beg top-margin
))))
1347 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1349 (defun edt-paragraph (num)
1350 "Move in current direction to next paragraph.
1351 Argument NUM is the positive number of paragraphs to move."
1353 (if (equal edt-direction-string edt-forward-string
)
1354 (edt-paragraph-forward num
)
1355 (edt-paragraph-backward num
)))
1361 (defun edt-restore-key ()
1362 "Restore last replaced key definition.
1363 Definition is stored in `edt-last-replaced-key-definition'."
1365 (if (featurep 'xemacs
) (setq zmacs-region-stays t
))
1366 (if edt-last-replaced-key-definition
1368 (let (edt-key-definition)
1369 (set 'edt-key-definition
1370 (read-key-sequence "Press the key to be restored: "))
1371 (if (if (featurep 'emacs
)
1372 (string-equal "\C-m" edt-key-definition
)
1373 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1374 (message "Key not restored")
1376 (define-key (current-global-map)
1377 edt-key-definition edt-last-replaced-key-definition
)
1378 (if (featurep 'emacs
)
1379 (message "Key definition for %s has been restored."
1381 (message "Key definition for %s has been restored."
1382 (events-to-keys edt-key-definition
)))))))
1383 (error "No replaced key definition to restore!")))
1389 (defun edt-window-top ()
1390 "Move the cursor to the top of the window."
1392 (let ((start-column (current-column)))
1393 (move-to-window-line 0)
1394 (move-to-column start-column
))
1395 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1401 (defun edt-window-bottom ()
1402 "Move the cursor to the bottom of the window."
1404 (let ((start-column (current-column)))
1405 (move-to-window-line (- (window-height) 2))
1406 (move-to-column start-column
))
1407 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1410 ;;; SCROLL WINDOW LINE
1413 (defun edt-scroll-window-forward-line ()
1414 "Move window forward one line leaving cursor at position in window."
1417 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1419 (defun edt-scroll-window-backward-line ()
1420 "Move window backward one line leaving cursor at position in window."
1423 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1425 (defun edt-scroll-line ()
1426 "Move window one line in current direction."
1428 (if (equal edt-direction-string edt-forward-string
)
1429 (edt-scroll-window-forward-line)
1430 (edt-scroll-window-backward-line)))
1435 ;;; Scroll a window (less one line) at a time. Leave cursor in center of
1438 (defun edt-scroll-window-forward (num)
1439 "Scroll forward one window in buffer, less one line.
1440 Argument NUM is the positive number of windows to move."
1442 (edt-check-prefix num
)
1443 (scroll-up (- (* (window-height) num
) 2))
1444 (edt-line-forward (/ (- (window-height) 1) 2)))
1446 (defun edt-scroll-window-backward (num)
1447 "Scroll backward one window in buffer, less one line.
1448 Argument NUM is the positive number of windows to move."
1450 (edt-check-prefix num
)
1451 (scroll-down (- (* (window-height) num
) 2))
1452 (edt-line-backward (/ (- (window-height) 1) 2)))
1454 (defun edt-scroll-window (num)
1455 "Scroll one window in buffer, less one line, in current direction.
1456 Argument NUM is the positive number of windows to move."
1458 (if (equal edt-direction-string edt-forward-string
)
1459 (edt-scroll-window-forward num
)
1460 (edt-scroll-window-backward num
)))
1463 ;;; LINE TO BOTTOM OF WINDOW
1466 (defun edt-line-to-bottom-of-window ()
1467 "Move the current line to the bottom of the window."
1470 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1473 ;;; LINE TO TOP OF WINDOW
1476 (defun edt-line-to-top-of-window ()
1477 "Move the current line to the top of the window."
1480 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1483 ;;; LINE TO MIDDLE OF WINDOW
1486 (defun edt-line-to-middle-of-window ()
1487 "Move window so line with cursor is in the middle of the window."
1490 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1496 (defun edt-goto-percentage (num)
1497 "Move to specified percentage in buffer from top of buffer.
1498 Argument NUM is the percentage into the buffer to move."
1499 (interactive "NGoto-percentage: ")
1500 (if (or (> num
100) (< num
0))
1501 (error "Percentage %d out of range 0 < percent < 100" num
)
1502 (goto-char (/ (* (point-max) num
) 100)))
1503 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1509 (defun edt-fill-region ()
1510 "Fill selected text."
1512 (edt-check-selection)
1513 (fill-region (point) (mark)))
1516 ;;; INDENT OR FILL REGION
1519 (defun edt-indent-or-fill-region ()
1520 "Fill region in text modes, indent region in programming language modes."
1522 (if (string= paragraph-start
"$\\|\f")
1523 (indent-region (point) (mark) nil
)
1524 (fill-region (point) (mark))))
1527 (declare-function c-mark-function
"cc-cmds" ())
1529 ;;; MARK SECTION WISELY
1532 (defun edt-mark-section-wisely ()
1533 "Mark the section in a manner consistent with the `major-mode'.
1534 Uses `mark-defun' for Emacs-Lisp and Lisp, and for Fortran,
1535 `c-mark-function' for C,
1536 and `mark-paragraph' for other modes."
1542 (cond ((or (eq major-mode
'emacs-lisp-mode
)
1543 (eq major-mode
'fortran-mode
)
1544 (eq major-mode
'lisp-mode
))
1546 (message "Lisp defun selected"))
1547 ((eq major-mode
'c-mode
)
1549 (message "C function selected"))
1551 (message "Paragraph selected"))))))
1558 "Copy selected region to kill ring, but don't delete it!"
1560 (edt-check-selection)
1561 (copy-region-as-kill (mark) (point))
1563 (message "Selected text COPIED to kill ring"))
1569 (defun edt-cut-or-copy ()
1570 "Cuts (or copies) selected text to kill ring.
1571 Cuts selected text if `buffer-read-only' is nil.
1572 Copies selected text if `buffer-read-only' is t."
1574 (if buffer-read-only
1579 ;;; DELETE ENTIRE LINE
1582 (defun edt-delete-entire-line ()
1583 "Delete entire line regardless of cursor position in the line."
1586 (edt-delete-line 1))
1592 (defun edt-duplicate-line (num)
1593 "Duplicate the line of text containing the cursor.
1594 Argument NUM is the number of times to duplicate the line."
1596 (edt-check-prefix num
)
1597 (let ((old-column (current-column))
1599 (edt-delete-entire-line)
1603 (setq count
(1- count
)))
1604 (edt-line-forward num
)
1605 (move-to-column old-column
)))
1611 (defun edt-duplicate-word()
1612 "Duplicate word (or rest of word) found directly above cursor, if any."
1614 (let ((start (point))
1615 (start-column (current-column)))
1617 (move-to-column start-column
)
1618 (if (and (not (equal start
(point)))
1621 (if (and (equal ?
\t (preceding-char))
1622 (< start-column
(current-column)))
1624 (let ((beg (point)))
1625 (edt-one-word-forward)
1626 (setq edt-last-copied-word
(buffer-substring beg
(point))))
1628 (move-to-column start-column
)
1629 (insert edt-last-copied-word
))
1631 (if (not (equal start
(point)))
1633 (move-to-column start-column
)
1634 (error "Nothing to duplicate!")))))
1637 ;;; KEY NOT ASSIGNED
1640 (defun edt-key-not-assigned ()
1641 "Displays message that key has not been assigned to a function."
1643 (error "Key not assigned"))
1646 ;;; TOGGLE CAPITALIZATION OF WORD
1649 (defun edt-toggle-capitalization-of-word ()
1650 "Toggle the capitalization of the current word and move forward to next."
1652 (edt-one-word-forward)
1653 (edt-one-word-backward)
1655 (edt-one-word-backward)
1656 (edt-one-word-forward))
1659 ;;; ELIMINATE ALL TABS
1662 (defun edt-eliminate-all-tabs ()
1663 "Convert all tabs to spaces in the entire buffer."
1665 (untabify (point-min) (point-max))
1666 (message "TABS converted to SPACES"))
1669 ;;; DISPLAY THE TIME
1672 (defun edt-display-the-time ()
1673 "Display the current time."
1675 (if (featurep 'xemacs
) (setq zmacs-region-stays t
))
1676 (message "%s" (current-time-string)))
1683 "Learn a sequence of key strokes to bind to a key."
1685 (if (eq defining-kbd-macro t
)
1687 (start-kbd-macro nil
)))
1693 (defun edt-remember ()
1694 "Store the sequence of key strokes started by `edt-learn' to a key."
1696 (if (eq defining-kbd-macro nil
)
1697 (error "Nothing to remember!")
1700 (let (edt-key-definition)
1701 (set 'edt-key-definition
1702 (read-key-sequence "Enter key for binding: "))
1703 (if (if (featurep 'emacs
)
1704 (string-equal "\C-m" edt-key-definition
)
1705 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1706 (message "Key sequence not remembered")
1708 (set 'edt-learn-macro-count
(+ edt-learn-macro-count
1))
1709 (setq edt-last-replaced-key-definition
1710 (lookup-key (current-global-map)
1711 edt-key-definition
))
1712 (define-key (current-global-map) edt-key-definition
1713 (name-last-kbd-macro
1714 (intern (concat "last-learned-sequence-"
1715 (int-to-string edt-learn-macro-count
)))))))))))
1722 "Save current buffer, ask to save other buffers, and then exit Emacs."
1725 (save-buffers-kill-emacs))
1732 "Quit Emacs without saving buffer modifications.
1733 Warn user that modifications will be lost."
1735 (let ((list (buffer-list))
1737 (while (and list working
)
1738 (let ((buffer (car list
)))
1739 (if (and (buffer-file-name buffer
) (buffer-modified-p buffer
))
1741 "Modifications will not be saved, continue quitting? ")
1743 (setq working nil
)))
1744 (setq list
(cdr list
))))
1745 (if working
(kill-emacs))))
1751 (defun edt-split-window ()
1752 "Split current window and place cursor in the new window."
1756 (if (featurep 'xemacs
) (setq zmacs-region-stays t
)))
1762 (defun edt-copy-rectangle ()
1763 "Copy a rectangle of text between mark and cursor to register."
1765 (edt-check-selection)
1766 (copy-rectangle-to-register 3 (region-beginning) (region-end) nil
)
1768 (message "Selected rectangle COPIED to register"))
1774 (defun edt-cut-rectangle-overstrike-mode ()
1775 "Cut a rectangle of text between mark and cursor to register.
1776 Replace cut characters with spaces and moving cursor back to
1779 (edt-check-selection)
1780 (setq edt-rect-start-point
(region-beginning))
1781 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3)
1782 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point
)
1783 (message "Selected rectangle CUT to register"))
1785 (defun edt-cut-rectangle-insert-mode ()
1786 "Cut a rectangle of text between mark and cursor to register.
1787 Move cursor back to upper left corner."
1789 (edt-check-selection)
1790 (setq edt-rect-start-point
(region-beginning))
1791 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3 t
)
1793 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point
)
1794 (message "Selected rectangle CUT to register"))
1796 (defun edt-cut-rectangle ()
1797 "Cut a rectangular region of text to register.
1798 If overwrite mode is active, cut text is replaced with whitespace."
1801 (edt-cut-rectangle-overstrike-mode)
1802 (edt-cut-rectangle-insert-mode)))
1808 (defun edt-paste-rectangle-overstrike-mode ()
1809 "Paste a rectangular region of text from register, replacing text at cursor."
1811 (picture-yank-rectangle-from-register 3))
1813 (defun edt-paste-rectangle-insert-mode ()
1814 "Paste previously deleted rectangular region, inserting text at cursor."
1816 (picture-yank-rectangle-from-register 3 t
))
1818 (defun edt-paste-rectangle ()
1819 "Paste a rectangular region of text.
1820 If overwrite mode is active, existing text is replace with text from register."
1823 (edt-paste-rectangle-overstrike-mode)
1824 (edt-paste-rectangle-insert-mode)))
1830 (defun edt-lowercase ()
1831 "Change specified characters to lower case.
1832 If text selection IS active, then characters between the cursor and
1833 mark are changed. If text selection is NOT active, there are two
1834 situations. If the current direction is ADVANCE, then the word under
1835 the cursor is changed to lower case and the cursor is moved to rest at
1836 the beginning of the next word. If the current direction is BACKUP,
1837 the word prior to the word under the cursor is changed to lower case
1838 and the cursor is left to rest at the beginning of that word."
1842 (downcase-region (mark) (point)))
1844 ;; Move to beginning of current word.
1850 (not (eq ?\
(char-syntax (preceding-char))))
1851 (not (memq (preceding-char) edt-word-entities
))
1852 (not (memq (following-char) edt-word-entities
)))
1853 (edt-one-word-backward))
1854 (if (equal edt-direction-string edt-backward-string
)
1855 (edt-one-word-backward))
1856 (let ((beg (point)))
1857 (edt-one-word-forward)
1858 (downcase-region beg
(point)))
1859 (if (equal edt-direction-string edt-backward-string
)
1860 (edt-one-word-backward)))))
1866 (defun edt-uppercase ()
1867 "Change specified characters to upper case.
1868 If text selection IS active, then characters between the cursor and
1869 mark are changed. If text selection is NOT active, there are two
1870 situations. If the current direction is ADVANCE, then the word under
1871 the cursor is changed to upper case and the cursor is moved to rest at
1872 the beginning of the next word. If the current direction is BACKUP,
1873 the word prior to the word under the cursor is changed to upper case
1874 and the cursor is left to rest at the beginning of that word."
1878 (upcase-region (mark) (point)))
1880 ;; Move to beginning of current word.
1886 (not (eq ?\
(char-syntax (preceding-char))))
1887 (not (memq (preceding-char) edt-word-entities
))
1888 (not (memq (following-char) edt-word-entities
)))
1889 (edt-one-word-backward))
1890 (if (equal edt-direction-string edt-backward-string
)
1891 (edt-one-word-backward))
1892 (let ((beg (point)))
1893 (edt-one-word-forward)
1894 (upcase-region beg
(point)))
1895 (if (equal edt-direction-string edt-backward-string
)
1896 (edt-one-word-backward)))))
1899 ;;; Functions used in loading LK-201 key mapping file.
1901 (defvar edt-last-answer nil
1902 "Most recent response to `edt-y-or-n-p'.")
1904 (defun edt-y-or-n-p (prompt &optional not-yes
)
1905 "Prompt for a y or n answer with positive default.
1906 Like Emacs `y-or-n-p', also accepts space as y and DEL as n.
1907 Argument PROMPT is the prompt string.
1908 Optional argument NOT-YES changes the default to negative."
1909 (message "%s[%s]" prompt
(if not-yes
"n" "y"))
1913 (let ((ans (read-char)))
1914 (cond ((or (= ans ?y
) (= ans ?Y
) (= ans ?\
))
1915 (setq edt-last-answer t
))
1916 ((or (= ans ?n
) (= ans ?N
) (= ans ?\C-?
))
1917 (setq edt-last-answer nil
))
1918 ((= ans ?
\r) (setq edt-last-answer
(not not-yes
)))
1920 (setq doit t
) (beep)
1921 (message "Please answer y or n. %s[%s]"
1922 prompt
(if not-yes
"n" "y")))))))
1926 ;;; INITIALIZATION COMMANDS.
1930 ;;; Function used to load LK-201 key mapping file generated by edt-mapper.el.
1932 (defun edt-load-keys (file)
1933 "Load the LK-201 key mapping FILE generated by edt-mapper.el.
1934 If FILE is nil, which is the normal case, try to load a default file.
1935 The default file names are based upon the window system, terminal
1936 type, and version of Emacs in use: GNU Emacs or XEmacs (aka Lucid
1937 Emacs). If a default file does not exist, ask user if one should be
1939 (interactive "fKey definition file: ")
1941 (setq file
(expand-file-name file
)))
1943 (setq file
(expand-file-name edt-keys-file
)))
1948 "~/.edt-" edt-emacs-variant
1949 (if edt-term
(concat "-" edt-term
))
1950 (if edt-xserver
(concat "-" edt-xserver
))
1951 (if edt-window-system
1952 (concat "-" (upcase (symbol-name edt-window-system
))))
1954 (cond ((file-readable-p file
)
1957 (switch-to-buffer "*scratch*")
1961 Ack!! You're running the Enhanced EDT Emulation without loading an
1962 EDT key mapping file. To create an EDT key mapping file, run the
1963 edt-mapper program. It is safest to run it from an Emacs loaded
1964 without any of your own customizations found in your .emacs file, etc.
1965 The reason for this is that some user customizations confuse edt-mapper.
1966 You can do this by quitting Emacs and then invoking Emacs again as
1969 emacs -q -l edt-mapper
1971 [NOTE: If you do nothing out of the ordinary in your .emacs file, and
1972 the search for edt-mapper is successful, you can try running it now.]
1974 The library edt-mapper includes these same directions on how to
1975 use it! Perhaps it's lying around here someplace. \n ")
1976 (let ((path (locate-library
1978 nil
(append (list default-directory
) load-path
))))
1982 "Ah yes, there it is, in \n\n %s \n\n" path
))
1983 (if (edt-y-or-n-p "Do you want to run it now? ")
1985 (error "EDT Emulation not configured")))
1986 (insert "Nope, I can't seem to find it. :-(\n\n")
1988 (error "EDT Emulation not configured"))))))
1991 ;;; Turning the EDT Emulation on and off.
1995 (defun edt-emulation-on ()
1996 "Turn on EDT Emulation."
1998 ;; If using pc window system (MS-DOS), set terminal type to pc.
1999 ;; If not a window system (GNU) or a tty window system (XEmacs),
2000 ;; get terminal type.
2001 (if (eq edt-window-system
'pc
)
2002 (setq edt-term
"pc")
2003 (if (or (not edt-window-system
) (eq edt-window-system
'tty
))
2004 (setq edt-term
(getenv "TERM"))))
2005 ;; Look for a terminal configuration file for this terminal type.
2006 ;; Otherwise, load the user's custom configuration file.
2007 (if (or (not edt-window-system
) (memq edt-window-system
'(pc tty
)))
2009 ;; Load terminal-specific configuration file, if it exists for this
2010 ;; terminal type. Note: All DEC VT series terminals are supported
2011 ;; by the same terminal configuration file: edt-vt100.el.
2012 (if (string-equal "vt" (substring edt-term
0 (min (length edt-term
) 2)))
2013 (setq edt-term
"vt100"))
2014 (let ((term edt-term
)
2017 (not (load (concat "edt-" term
) t t
)))
2018 ;; Strip off last hyphen and what follows, then try again
2019 (if (setq hyphend
(string-match "[-_][^-_]+$" term
))
2020 (setq term
(substring term
0 hyphend
))
2022 ;; If no terminal-specific configuration file exists, load user's
2023 ;; custom EDT terminal configuration file.
2024 ;; If this is a pc running MS-DOS, then custom configuration files
2025 ;; are not supported. So, if the file is missing, issue an error
2028 (if (equal edt-term
"pc")
2029 (error "Unable to find EDT terminal specific file edt-pc.el")
2030 (edt-load-keys nil
))
2031 (setq edt-term term
))))
2032 (edt-load-keys nil
))
2033 ;; Make highlighting of selected text work properly for EDT commands.
2034 (if (featurep 'emacs
)
2036 (setq edt-orig-transient-mark-mode transient-mark-mode
)
2037 (add-hook 'activate-mark-hook
2040 (edt-select-mode t
))))
2041 (add-hook 'deactivate-mark-hook
2044 (edt-select-mode nil
)))))
2046 (add-hook 'zmacs-activate-region-hook
2049 (edt-select-mode t
))))
2050 (add-hook 'zmacs-deactivate-region-hook
2053 (edt-select-mode nil
))))))
2054 ;; Load user's EDT custom key bindings file, if it exists.
2055 ;; Otherwise, use the default bindings.
2056 (if (load "edt-user" t t
)
2057 (edt-user-emulation-setup)
2058 (edt-default-emulation-setup)))
2060 (defun edt-emulation-off()
2061 "Select original global key bindings, disabling EDT Emulation."
2063 (use-global-map global-map
)
2064 (if (not edt-keep-current-page-delimiter
)
2065 (setq page-delimiter edt-orig-page-delimiter
))
2066 (setq edt-direction-string
"")
2067 (setq edt-select-mode-current nil
)
2069 (force-mode-line-update t
)
2070 (if (featurep 'emacs
)
2071 (setq transient-mark-mode edt-orig-transient-mark-mode
))
2072 (message "Original key bindings restored; EDT Emulation disabled"))
2074 (defun edt-default-emulation-setup (&optional user-setup
)
2075 "Setup emulation of DEC's EDT editor.
2076 Optional argument USER-SETUP non-nil means called from function
2077 `edt-user-emulation-setup'."
2078 ;; Setup default EDT global map by copying global map bindings.
2079 ;; This preserves ESC and C-x prefix bindings and other bindings we
2080 ;; wish to retain in EDT emulation mode keymaps. It also permits
2081 ;; customization of these bindings in the EDT global maps without
2082 ;; disturbing the original bindings in global-map.
2083 (fset 'edt-default-ESC-prefix
(copy-keymap 'ESC-prefix
))
2084 (setq edt-default-global-map
(copy-keymap (current-global-map)))
2085 (if (featurep 'emacs
)
2086 (define-key edt-default-global-map
"\e" 'edt-default-ESC-prefix
)
2087 (define-key edt-default-global-map
[escape] 'edt-default-ESC-prefix))
2088 (define-prefix-command 'edt-default-gold-map)
2089 (edt-setup-default-bindings)
2090 ;; If terminal has additional function keys, the terminal-specific
2091 ;; initialization file can assign bindings to them via the optional
2092 ;; function edt-setup-extra-default-bindings.
2093 (if (fboundp 'edt-setup-extra-default-bindings)
2094 (edt-setup-extra-default-bindings))
2095 ;; Variable needed by edt-learn.
2096 (setq edt-learn-macro-count 0)
2097 ;; Display EDT text selection active within the mode line
2098 (or (assq 'edt-select-mode minor-mode-alist)
2099 (setq minor-mode-alist
2100 (cons '(edt-select-mode edt-select-mode) minor-mode-alist)))
2101 ;; Display EDT direction of motion within the mode line
2102 (or (assq 'edt-direction-string minor-mode-alist)
2103 (setq minor-mode-alist
2105 '(edt-direction-string edt-direction-string) minor-mode-alist)))
2108 (setq edt-user-map-configured t)
2109 (fset 'edt-emulation-on (symbol-function 'edt-select-user-global-map)))
2111 (fset 'edt-emulation-on (symbol-function 'edt-select-default-global-map))
2112 (edt-select-default-global-map)))
2113 ;; We need to share `global-buffers-menu-map' with the saved global
2114 ;; keymap, because `menu-bar-update-buffers' directly changes it.
2115 (define-key (current-global-map) [menu-bar buffer]
2116 (cons "Buffers" global-buffers-menu-map)))
2118 (defun edt-user-emulation-setup ()
2119 "Setup user custom emulation of DEC's EDT editor."
2120 ;; Initialize EDT default bindings.
2121 (edt-default-emulation-setup t)
2122 ;; Setup user EDT global map by copying default EDT global map bindings.
2123 (fset 'edt-user-ESC-prefix (copy-keymap 'edt-default-ESC-prefix))
2124 (setq edt-user-global-map (copy-keymap edt-default-global-map))
2125 (if (featurep 'emacs)
2126 (define-key edt-user-global-map "\e" 'edt-user-ESC-prefix)
2127 (define-key edt-user-global-map [escape] 'edt-user-ESC-prefix
))
2128 ;; If terminal has additional function keys, the user's initialization
2129 ;; file can assign bindings to them via the optional
2130 ;; function edt-setup-extra-default-bindings.
2131 (define-prefix-command 'edt-user-gold-map
)
2132 (fset 'edt-user-gold-map
(copy-keymap 'edt-default-gold-map
))
2133 ;; This is a function that the user can define for custom bindings.
2134 ;; See Info node `edt' for more details, and sample edt-user.el file.
2135 (if (fboundp 'edt-setup-user-bindings
)
2136 (edt-setup-user-bindings))
2137 (edt-select-user-global-map))
2139 (defun edt-select-default-global-map()
2140 "Select default EDT emulation key bindings."
2142 (if (featurep 'emacs
)
2143 (transient-mark-mode 1))
2144 (use-global-map edt-default-global-map
)
2145 (if (not edt-keep-current-page-delimiter
)
2147 (setq edt-orig-page-delimiter page-delimiter
)
2148 (setq page-delimiter
"\f")))
2149 (setq edt-default-map-active t
)
2151 (setq edt-select-mode-current
'edt-select-mode-string
)
2153 (message "Default EDT keymap active"))
2155 (defun edt-select-user-global-map()
2156 "Select user EDT emulation custom key bindings."
2158 (if edt-user-map-configured
2160 (if (featurep 'emacs
)
2161 (transient-mark-mode 1))
2162 (use-global-map edt-user-global-map
)
2163 (if (not edt-keep-current-page-delimiter
)
2165 (setq edt-orig-page-delimiter page-delimiter
)
2166 (setq page-delimiter
"\f")))
2167 (setq edt-default-map-active nil
)
2169 (setq edt-select-mode-current
'edt-select-mode-string
)
2171 (message "User EDT custom keymap active"))
2172 (error "User EDT custom keymap NOT configured!")))
2174 (defun edt-switch-global-maps ()
2175 "Toggle between default EDT keymap and user EDT keymap."
2177 (if edt-default-map-active
2178 (edt-select-user-global-map)
2179 (edt-select-default-global-map)))
2182 ;; Functions used to set up DEFAULT bindings to EDT emulation functions.
2185 (defun edt-bind-function-key-default (function-key binding gold-binding
)
2186 "Binds LK-201 function keys to default bindings in the EDT Emulator.
2187 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2188 Argument BINDING is the Emacs function to be bound to <KEY>.
2189 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2190 (let ((key (cdr (assoc function-key
*EDT-keys
*))))
2191 (if (and key
(not (equal key
"")))
2193 (define-key edt-default-global-map key binding
)
2194 (define-key 'edt-default-gold-map key gold-binding
)))))
2196 (defun edt-bind-key-default (key binding
)
2197 "Bind key sequences to default bindings in the EDT Emulator.
2198 Argument KEY is the name of a standard key or a function key.
2199 Argument BINDING is the Emacs function to be bound to <KEY>."
2200 (define-key edt-default-global-map key binding
))
2202 (defun edt-bind-gold-key-default (key gold-binding
)
2203 "Binds <GOLD> key sequences to default bindings in the EDT Emulator.
2204 Argument KEY is the name of a standard key or a function key.
2205 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2206 (define-key 'edt-default-gold-map key gold-binding
))
2209 ;; Functions used to set up USER CUSTOM bindings to EDT emulation functions.
2211 (defun edt-bind-function-key (function-key binding gold-binding
)
2212 "Binds LK-201 function keys to custom bindings in the EDT Emulator.
2213 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2214 Argument BINDING is the Emacs function to be bound to <KEY>.
2215 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2216 (let ((key (cdr (assoc function-key
*EDT-keys
*))))
2217 (if (and key
(not (equal key
"")))
2219 (define-key edt-user-global-map key binding
)
2220 (define-key 'edt-user-gold-map key gold-binding
)))))
2222 (defun edt-bind-key (key binding
)
2223 "Bind standard key sequences to custom bindings in the EDT Emulator.
2224 Argument KEY is the name of a key. It can be a standard key or a function key.
2225 Argument BINDING is the Emacs function to be bound to <KEY>."
2226 (define-key edt-user-global-map key binding
))
2228 ;; For backward compatibility to existing edt-user.el files.
2229 (fset 'edt-bind-standard-key
(symbol-function 'edt-bind-key
))
2231 (defun edt-bind-gold-key (key gold-binding
)
2232 "Binds <GOLD> standard key sequences to custom bindings in the EDT Emulator.
2233 Argument KEY is the name of a standard key or a function key.
2234 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2235 (define-key 'edt-user-gold-map key gold-binding
))
2237 (defun edt-setup-default-bindings ()
2238 "Assigns default EDT Emulation keyboard bindings."
2240 ;; Function Key Bindings: Regular and GOLD.
2242 ;; VT100/VT200/VT300 PF1 (GOLD), PF2, PF3, PF4 Keys
2243 (edt-bind-function-key-default "PF1"
2244 'edt-default-gold-map
'edt-mark-section-wisely
)
2245 (edt-bind-function-key-default "PF2"
2246 'edt-electric-keypad-help
'describe-function
)
2247 (edt-bind-function-key-default "PF3" 'edt-find-next
'edt-find
)
2248 (edt-bind-function-key-default "PF4" 'edt-delete-line
'edt-undelete-line
)
2250 ;; VT100/VT200/VT300 Arrow Keys
2251 (edt-bind-function-key-default "UP" 'edt-previous-line
'edt-window-top
)
2252 (edt-bind-function-key-default "DOWN" 'edt-next-line
'edt-window-bottom
)
2253 (edt-bind-function-key-default "LEFT" 'backward-char
'edt-sentence-backward
)
2254 (edt-bind-function-key-default "RIGHT" 'forward-char
'edt-sentence-forward
)
2256 ;; VT100/VT200/VT300 Keypad Keys
2257 (edt-bind-function-key-default "KP0" 'edt-line
'open-line
)
2258 (edt-bind-function-key-default "KP1" 'edt-word
'edt-change-case
)
2259 (edt-bind-function-key-default "KP2"
2260 'edt-end-of-line
'edt-delete-to-end-of-line
)
2261 (edt-bind-function-key-default "KP3" 'edt-character
'quoted-insert
)
2262 (edt-bind-function-key-default "KP4" 'edt-advance
'edt-bottom
)
2263 (edt-bind-function-key-default "KP5" 'edt-backup
'edt-top
)
2264 (edt-bind-function-key-default "KP6" 'edt-cut
'yank
)
2265 (edt-bind-function-key-default "KP7" 'edt-page
'execute-extended-command
)
2266 (edt-bind-function-key-default "KP8" 'edt-sect
'edt-fill-region
)
2267 (edt-bind-function-key-default "KP9" 'edt-append
'edt-replace
)
2268 (edt-bind-function-key-default "KP-" 'edt-delete-word
'edt-undelete-word
)
2269 (edt-bind-function-key-default "KP,"
2270 'edt-delete-character
'edt-undelete-character
)
2271 (edt-bind-function-key-default "KPP" 'edt-select
'edt-reset
)
2272 (edt-bind-function-key-default "KPE" 'other-window
'edt-substitute
)
2274 ;; VT200/VT300 Function Keys
2275 ;; (F1 through F5, on the VT220, are not programmable, so we skip
2276 ;; making default bindings to those keys.
2277 (edt-bind-function-key-default "FIND" 'edt-find-next
'edt-find
)
2278 (edt-bind-function-key-default "INSERT" 'yank
'edt-key-not-assigned
)
2279 (edt-bind-function-key-default "REMOVE" 'edt-cut
'edt-copy
)
2280 (edt-bind-function-key-default "SELECT"
2281 'edt-toggle-select
'edt-key-not-assigned
)
2282 (edt-bind-function-key-default "NEXT"
2283 'edt-sect-forward
'edt-key-not-assigned
)
2284 (edt-bind-function-key-default "PREVIOUS"
2285 'edt-sect-backward
'edt-key-not-assigned
)
2286 (edt-bind-function-key-default "F6"
2287 'edt-key-not-assigned
'edt-key-not-assigned
)
2288 (edt-bind-function-key-default "F7"
2289 'edt-copy-rectangle
'edt-key-not-assigned
)
2290 (edt-bind-function-key-default "F8"
2291 'edt-cut-rectangle-overstrike-mode
'edt-paste-rectangle-overstrike-mode
)
2292 (edt-bind-function-key-default "F9"
2293 'edt-cut-rectangle-insert-mode
'edt-paste-rectangle-insert-mode
)
2294 (edt-bind-function-key-default "F10" 'edt-cut-rectangle
'edt-paste-rectangle
)
2295 ;; Under X, the F11 key can be bound. If using a VT-200 or higher terminal,
2296 ;; the default emacs terminal support causes the VT F11 key to seem as if it
2297 ;; is an ESC key when in emacs.
2298 (edt-bind-function-key-default "F11"
2299 'edt-key-not-assigned
'edt-key-not-assigned
)
2300 (edt-bind-function-key-default "F12"
2301 'edt-beginning-of-line
'delete-other-windows
) ;BS
2302 (edt-bind-function-key-default "F13"
2303 'edt-delete-to-beginning-of-word
'edt-key-not-assigned
) ;LF
2304 (edt-bind-function-key-default "F14"
2305 'edt-key-not-assigned
'edt-key-not-assigned
)
2306 (edt-bind-function-key-default "HELP"
2307 'edt-electric-keypad-help
'edt-key-not-assigned
)
2308 (edt-bind-function-key-default "DO"
2309 'execute-extended-command
'edt-key-not-assigned
)
2310 (edt-bind-function-key-default "F17"
2311 'edt-key-not-assigned
'edt-key-not-assigned
)
2312 (edt-bind-function-key-default "F18"
2313 'edt-key-not-assigned
'edt-key-not-assigned
)
2314 (edt-bind-function-key-default "F19"
2315 'edt-key-not-assigned
'edt-key-not-assigned
)
2316 (edt-bind-function-key-default "F20"
2317 'edt-key-not-assigned
'edt-key-not-assigned
)
2319 ;; Control key bindings: Regular and GOLD
2321 ;; Standard EDT control key bindings conflict with standard Emacs
2322 ;; control key bindings. Normally, the standard Emacs control key
2323 ;; bindings are left unchanged in the default EDT mode. However, if
2324 ;; the variable edt-use-EDT-control-key-bindings is set to true
2325 ;; before invoking edt-emulation-on for the first time, then the
2326 ;; standard EDT bindings (with some enhancements) as defined here are
2328 (if edt-use-EDT-control-key-bindings
2330 (edt-bind-key-default "\C-a" 'edt-key-not-assigned
)
2331 (edt-bind-key-default "\C-b" 'edt-key-not-assigned
)
2332 ;; Leave binding of C-c to an Emacs prefix key.
2333 (edt-bind-key-default "\C-d" 'edt-key-not-assigned
)
2334 (edt-bind-key-default "\C-e" 'edt-key-not-assigned
)
2335 (edt-bind-key-default "\C-f" 'edt-key-not-assigned
)
2336 ;; Leave binding of C-g to the Emacs keyboard-quit
2337 (edt-bind-key-default "\C-h" 'edt-beginning-of-line
)
2338 (edt-bind-key-default "\C-i" 'edt-tab-insert
)
2339 (edt-bind-key-default "\C-j" 'edt-delete-to-beginning-of-word
)
2340 (edt-bind-key-default "\C-k" 'edt-define-key
)
2341 (edt-bind-gold-key-default "\C-k" 'edt-restore-key
)
2342 (edt-bind-key-default "\C-l" 'edt-form-feed-insert
)
2343 ;; Leave binding of C-m to newline.
2344 (edt-bind-key-default "\C-n" 'edt-set-screen-width-80
)
2345 (edt-bind-key-default "\C-o" 'edt-key-not-assigned
)
2346 (edt-bind-key-default "\C-p" 'edt-key-not-assigned
)
2347 (edt-bind-key-default "\C-q" 'edt-key-not-assigned
)
2348 ;; Leave binding of C-r to isearch-backward.
2349 ;; Leave binding of C-s to isearch-forward.
2350 (edt-bind-key-default "\C-t" 'edt-display-the-time
)
2351 (edt-bind-key-default "\C-u" 'edt-delete-to-beginning-of-line
)
2352 (edt-bind-key-default "\C-v" 'redraw-display
)
2353 (edt-bind-key-default "\C-w" 'edt-set-screen-width-132
)
2354 ;; Leave binding of C-x as original prefix key.
2355 (edt-bind-key-default "\C-y" 'edt-key-not-assigned
)
2356 ;; Leave binding of C-z to suspend-emacs.
2360 ;; GOLD bindings for a few keys.
2361 (edt-bind-gold-key-default "\C-g" 'keyboard-quit
); Just in case.
2362 (edt-bind-gold-key-default "\C-h" 'help-for-help
); Just in case.
2363 (edt-bind-gold-key-default [f1] 'help-for-help)
2364 (edt-bind-gold-key-default [help] 'help-for-help)
2365 (edt-bind-gold-key-default "\C-\\" 'split-window-below)
2367 ;; GOLD bindings for regular keys.
2368 (edt-bind-gold-key-default "a" 'edt-key-not-assigned)
2369 (edt-bind-gold-key-default "A" 'edt-key-not-assigned)
2370 (edt-bind-gold-key-default "b" 'buffer-menu)
2371 (edt-bind-gold-key-default "B" 'buffer-menu)
2372 (edt-bind-gold-key-default "c" 'compile)
2373 (edt-bind-gold-key-default "C" 'compile)
2374 (edt-bind-gold-key-default "d" 'delete-window)
2375 (edt-bind-gold-key-default "D" 'delete-window)
2376 (edt-bind-gold-key-default "e" 'edt-exit)
2377 (edt-bind-gold-key-default "E" 'edt-exit)
2378 (edt-bind-gold-key-default "f" 'find-file)
2379 (edt-bind-gold-key-default "F" 'find-file)
2380 (edt-bind-gold-key-default "g" 'find-file-other-window)
2381 (edt-bind-gold-key-default "G" 'find-file-other-window)
2382 (edt-bind-gold-key-default "h" 'edt-electric-keypad-help)
2383 (edt-bind-gold-key-default "H" 'edt-electric-keypad-help)
2384 (edt-bind-gold-key-default "i" 'insert-file)
2385 (edt-bind-gold-key-default "I" 'insert-file)
2386 (edt-bind-gold-key-default "j" 'edt-key-not-assigned)
2387 (edt-bind-gold-key-default "J" 'edt-key-not-assigned)
2388 (edt-bind-gold-key-default "k" 'edt-toggle-capitalization-of-word)
2389 (edt-bind-gold-key-default "K" 'edt-toggle-capitalization-of-word)
2390 (edt-bind-gold-key-default "l" 'edt-lowercase)
2391 (edt-bind-gold-key-default "L" 'edt-lowercase)
2392 (edt-bind-gold-key-default "m" 'save-some-buffers)
2393 (edt-bind-gold-key-default "M" 'save-some-buffers)
2394 (edt-bind-gold-key-default "n" 'next-error)
2395 (edt-bind-gold-key-default "N" 'next-error)
2396 (edt-bind-gold-key-default "o" 'switch-to-buffer-other-window)
2397 (edt-bind-gold-key-default "O" 'switch-to-buffer-other-window)
2398 (edt-bind-gold-key-default "p" 'edt-key-not-assigned)
2399 (edt-bind-gold-key-default "P" 'edt-key-not-assigned)
2400 (edt-bind-gold-key-default "q" 'edt-quit)
2401 (edt-bind-gold-key-default "Q" 'edt-quit)
2402 (edt-bind-gold-key-default "r" 'revert-buffer)
2403 (edt-bind-gold-key-default "R" 'revert-buffer)
2404 (edt-bind-gold-key-default "s" 'save-buffer)
2405 (edt-bind-gold-key-default "S" 'save-buffer)
2406 (edt-bind-gold-key-default "t" 'edt-key-not-assigned)
2407 (edt-bind-gold-key-default "T" 'edt-key-not-assigned)
2408 (edt-bind-gold-key-default "u" 'edt-uppercase)
2409 (edt-bind-gold-key-default "U" 'edt-uppercase)
2410 (edt-bind-gold-key-default "v" 'find-file-other-window)
2411 (edt-bind-gold-key-default "V" 'find-file-other-window)
2412 (edt-bind-gold-key-default "w" 'write-file)
2413 (edt-bind-gold-key-default "W" 'write-file)
2414 (edt-bind-gold-key-default "x" 'edt-key-not-assigned)
2415 (edt-bind-gold-key-default "X" 'edt-key-not-assigned)
2416 (edt-bind-gold-key-default "y" 'edt-emulation-off)
2417 (edt-bind-gold-key-default "Y" 'edt-emulation-off)
2418 (edt-bind-gold-key-default "z" 'edt-switch-global-maps)
2419 (edt-bind-gold-key-default "Z" 'edt-switch-global-maps)
2420 (edt-bind-gold-key-default "1" 'delete-other-windows)
2421 (edt-bind-gold-key-default "!" 'edt-key-not-assigned)
2422 (edt-bind-gold-key-default "2" 'edt-split-window)
2423 (edt-bind-gold-key-default "@" 'edt-key-not-assigned)
2424 (edt-bind-gold-key-default "3" 'edt-key-not-assigned)
2425 (edt-bind-gold-key-default "#" 'edt-key-not-assigned)
2426 (edt-bind-gold-key-default "4" 'edt-key-not-assigned)
2427 (edt-bind-gold-key-default "$" 'edt-key-not-assigned)
2428 (edt-bind-gold-key-default "5" 'edt-key-not-assigned)
2429 (edt-bind-gold-key-default "%" 'edt-goto-percentage)
2430 (edt-bind-gold-key-default "6" 'edt-key-not-assigned)
2431 (edt-bind-gold-key-default "^" 'edt-key-not-assigned)
2432 (edt-bind-gold-key-default "7" 'edt-key-not-assigned)
2433 (edt-bind-gold-key-default "&" 'edt-key-not-assigned)
2434 (edt-bind-gold-key-default "8" 'edt-key-not-assigned)
2435 (edt-bind-gold-key-default "*" 'edt-key-not-assigned)
2436 (edt-bind-gold-key-default "9" 'edt-key-not-assigned)
2437 (edt-bind-gold-key-default "(" 'edt-key-not-assigned)
2438 (edt-bind-gold-key-default "0" 'edt-key-not-assigned)
2439 (edt-bind-gold-key-default ")" 'edt-key-not-assigned)
2440 (edt-bind-gold-key-default " " 'undo)
2441 (edt-bind-gold-key-default "," 'edt-key-not-assigned)
2442 (edt-bind-gold-key-default "<" 'edt-key-not-assigned)
2443 (edt-bind-gold-key-default "." 'edt-key-not-assigned)
2444 (edt-bind-gold-key-default ">" 'edt-key-not-assigned)
2445 (edt-bind-gold-key-default "/" 'query-replace)
2446 (edt-bind-gold-key-default "?" 'edt-key-not-assigned)
2447 (edt-bind-gold-key-default "\\" 'edt-key-not-assigned)
2448 (edt-bind-gold-key-default "|" 'edt-key-not-assigned)
2449 (edt-bind-gold-key-default ";" 'edt-key-not-assigned)
2450 (edt-bind-gold-key-default ":" 'edt-key-not-assigned)
2451 (edt-bind-gold-key-default "'" 'edt-key-not-assigned)
2452 (edt-bind-gold-key-default "\"" 'edt-key-not-assigned)
2453 (edt-bind-gold-key-default "-" 'edt-key-not-assigned)
2454 (edt-bind-gold-key-default "_" 'edt-key-not-assigned)
2455 (edt-bind-gold-key-default "=" 'goto-line)
2456 (edt-bind-gold-key-default "+" 'edt-key-not-assigned)
2457 (edt-bind-gold-key-default "[" 'edt-key-not-assigned)
2458 (edt-bind-gold-key-default "{" 'edt-key-not-assigned)
2459 (edt-bind-gold-key-default "]" 'edt-key-not-assigned)
2460 (edt-bind-gold-key-default "}" 'edt-key-not-assigned)
2461 (edt-bind-gold-key-default "`" 'what-line)
2462 (edt-bind-gold-key-default "~" 'edt-key-not-assigned)
2466 ;;; DEFAULT EDT KEYPAD HELP
2470 ;; Upper case commands in the keypad diagram below indicate that the
2471 ;; emulation should look and feel very much like EDT. Lower case
2472 ;; commands are enhancements and/or additions to the EDT keypad
2473 ;; commands or are native Emacs commands.
2476 (defun edt-keypad-help ()
2477 "DEFAULT EDT Keypad Active.
2479 F7: Copy Rectangle +----------+----------+----------+----------+
2480 F8: Cut Rect Overstrike |Prev Line |Next Line |Bkwd Char |Frwd Char |
2481 G-F8: Paste Rect Overstrike | (UP) | (DOWN) | (LEFT) | (RIGHT) |
2482 F9: Cut Rect Insert |Window Top|Window Bot|Bkwd Sent |Frwd Sent |
2483 G-F9: Paste Rect Insert +----------+----------+----------+----------+
2485 G-F10: Paste Rectangle
2487 F12: Beginning of Line +----------+----------+----------+----------+
2488 G-F12: Delete Other Windows | GOLD | HELP | FNDNXT | DEL L |
2489 F13: Delete to Begin of Word | (PF1) | (PF2) | (PF3) | (PF4) |
2490 HELP: Keypad Help |Mark Wisel|Desc Funct| FIND | UND L |
2491 G-HELP: Emacs Help +----------+----------+----------+----------+
2492 DO: Execute extended command | PAGE | SECT | APPEND | DEL W |
2493 C-g: Keyboard Quit | (7) | (8) | (9) | (-) |
2494 G-C-g: Keyboard Quit |Ex Ext Cmd|Fill Regio| REPLACE | UND W |
2495 C-h: Beginning of Line +----------+----------+----------+----------+
2496 G-C-h: Emacs Help | ADVANCE | BACKUP | CUT | DEL C |
2497 C-i: Tab Insert | (4) | (5) | (6) | (,) |
2498 C-j: Delete to Begin of Word | BOTTOM | TOP | Yank | UND C |
2499 C-k: Define Key +----------+----------+----------+----------+
2500 G-C-k: Restore Key | WORD | EOL | CHAR | Next |
2501 C-l: Form Feed Insert | (1) | (2) | (3) | Window |
2502 C-n: Set Screen Width 80 | CHNGCASE | DEL EOL |Quoted Ins| !
2503 C-r: Isearch Backward +---------------------+----------+ (ENTER) |
2504 C-s: Isearch Forward | LINE | SELECT | !
2505 C-t: Display the Time | (0) | (.) | SUBS |
2506 C-u: Delete to Begin of Line | Open Line | RESET | |
2507 C-v: Redraw Display +---------------------+----------+----------+
2508 C-w: Set Screen Width 132
2509 C-z: Suspend Emacs +----------+----------+----------+
2510 G-C-\\: Split Window | FNDNXT | Yank | CUT |
2511 | (FIND) | (INSERT) | (REMOVE) |
2512 G-b: Buffer Menu | FIND | | COPY |
2513 G-c: Compile +----------+----------+----------+
2514 G-d: Delete Window |SELECT/RES|SECT BACKW|SECT FORWA|
2515 G-e: Exit | (SELECT) |(PREVIOUS)| (NEXT) |
2516 G-f: Find File | | | |
2517 G-g: Find File Other Window +----------+----------+----------+
2520 G-k: Toggle Capitalization Word
2521 G-l: Downcase Region
2522 G-m: Save Some Buffers
2524 G-o: Switch to Next Window
2529 G-v: Find File Other Window
2531 G-y: EDT Emulation OFF
2532 G-z: Switch to User EDT Key Bindings
2533 G-1: Delete Other Windows
2535 G-%: Go to Percentage
2536 G- : Undo (GOLD Spacebar)
2542 (describe-function 'edt-keypad-help))
2544 (defun edt-electric-helpify (fun)
2545 (let ((name "*Help*"))
2546 (if (save-window-excursion
2547 (let* ((p (symbol-function 'help-print-return-message))
2548 (b (get-buffer name))
2549 (m (buffer-modified-p b)))
2550 (and b (not (get-buffer-window b))
2554 (message "%s..." (capitalize (symbol-name fun)))
2556 (with-current-buffer b
2557 (set-buffer-modified-p t)))
2558 (fset 'help-print-return-message 'ignore)
2559 (call-interactively fun)
2560 (and (get-buffer name)
2561 (get-buffer-window (get-buffer name))
2563 (not (eq b (get-buffer name)))
2564 (not (buffer-modified-p b)))))
2565 (fset 'help-print-return-message p)
2566 (and b (buffer-name b)
2567 (with-current-buffer b
2568 (set-buffer-modified-p m))))))
2569 (with-electric-help 'delete-other-windows name t))))
2571 (defun edt-electric-keypad-help ()
2572 "Display default EDT bindings."
2574 (edt-electric-helpify 'edt-keypad-help))
2576 (defun edt-electric-user-keypad-help ()
2577 "Display user custom EDT bindings."
2579 (edt-electric-helpify 'edt-user-keypad-help))
2582 ;;; EDT emulation screen width commands.
2584 ;; Some terminals require modification of terminal attributes when
2585 ;; changing the number of columns displayed, hence the fboundp tests
2586 ;; below. These functions are defined in the corresponding terminal
2587 ;; specific file, if needed.
2589 (defun edt-set-screen-width-80 ()
2590 "Set screen width to 80 columns."
2592 (if (fboundp 'edt-set-term-width-80)
2593 (edt-set-term-width-80))
2594 (set-frame-width nil 80)
2595 (message "Terminal width 80"))
2597 (defun edt-set-screen-width-132 ()
2598 "Set screen width to 132 columns."
2600 (if (fboundp 'edt-set-term-width-132)
2601 (edt-set-term-width-132))
2602 (set-frame-width nil 132)
2603 (message "Terminal width 132"))
2607 ;;; edt.el ends here