1 ;;; edt.el --- Enhanced EDT Keypad Mode Emulation for GNU Emacs 19
3 ;; Copyright (C) 1986, 1992, 1993, 1994, 1995, 2000, 2001
4 ;; Free Software Foundation, Inc.
6 ;; Author: Kevin Gallagher <kevingal@onramp.net>
7 ;; Maintainer: Kevin Gallagher <kevingal@onramp.net>
8 ;; Keywords: emulations
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published
14 ;; by the Free Software Foundation; either version 2, or (at your
15 ;; option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
32 ;; This is Version 4.0 of the EDT Emulation for Emacs 19 and above.
33 ;; It comes with special functions which replicate nearly all of EDT's
34 ;; keypad mode behavior. It sets up default keypad and function key
35 ;; bindings which closely match those found in EDT. Support is
36 ;; provided so that users may reconfigure most keypad and function key
37 ;; bindings to their own liking.
39 ;; NOTE: Version 4.0 contains several enhancements. See the
40 ;; Enhancement section below for the details.
44 ;; To start the EDT Emulation, first start Emacs and then enter
46 ;; M-x edt-emulation-on
48 ;; to begin the emulation. After initialization is complete, the
49 ;; following message will appear below the status line informing you
50 ;; that the emulation has been enabled: "Default EDT keymap active".
52 ;; You can have the EDT Emulation start up automatically, each time
53 ;; you initiate a GNU Emacs session, by adding the following line to
56 ;; (add-hook term-setup-hook 'edt-emulation-on)
58 ;; IMPORTANT: Be sure to read the file, edt-user.doc, located in the
59 ;; Emacs "etc" directory. It contains very helpful user information.
61 ;; The EDT emulation consists of the following files:
63 ;; edt-user.doc - User Instructions and Sample Customization File
64 ;; edt.el - EDT Emulation Functions and Default Configuration
65 ;; edt-lk201.el - Built-in support for DEC LK-201 Keyboards
66 ;; edt-vt100.el - Built-in support for DEC VT-100 (and above) terminals
67 ;; edt-pc.el - Built-in support for PC 101 Keyboards under MS-DOS
68 ;; edt-mapper.el - Create an EDT LK-201 Map File for Keyboards Without
73 ;; Version 4.0 contains the following enhancements:
75 ;; 1. Scroll margins at the top and bottom of the window are now
76 ;; supported. (The design was copied from tpu-extras.el.) By
77 ;; default, this feature is enabled, with the top margin set to
78 ;; 10% of the window and the bottom margin set to 15% of the
79 ;; window. To change these settings, you can invoke the function
80 ;; edt-set-scroll-margins in your .emacs file. For example, the
83 ;; (edt-set-scroll-margins "20%" "25%")
85 ;; sets the top margin to 20% of the window and the bottom margin
86 ;; to 25% of the window. To disable this feature, set each
87 ;; margin to 0%. You can also invoke edt-set-scroll-margins
88 ;; interactively while EDT Emulation is active to change the
89 ;; settings for that session.
91 ;; NOTE: Another way to set the scroll margins is to use the
92 ;; Emacs customization feature (not available in Emacs 19) to set
93 ;; the following two variables directly:
95 ;; edt-top-scroll-margin and edt-bottom-scroll-margin
97 ;; Enter the Emacs `customize' command. First select the Editing
98 ;; group and then select the Emulations group. Finally, select
99 ;; the Edt group and follow the directions.
101 ;; 2. The SUBS command is now supported and bound to GOLD-Enter by
102 ;; default. (This design was copied from tpu-edt.el.) Note, in
103 ;; earlier versions of EDT Emulation, GOLD-Enter was assigned to
104 ;; the Emacs function `query-replace'. The binding of
105 ;; `query-replace' has been moved to GOLD-/. If you prefer to
106 ;; restore `query-replace' to GOLD-Enter, then use an EDT user
107 ;; customization file, edt-user.el, to do this. See edt-user.doc
110 ;; 3. EDT Emulation now also works in XEmacs, including the
111 ;; highlighting of selected text.
113 ;; 4. If you access a workstation using an X Server, observe that
114 ;; the initialization file generated by edt-mapper.el will now
115 ;; contain the name of the X Server vendor. This is a
116 ;; convenience for those who have access to their Unix account
117 ;; from more than one type of X Server. Since different X
118 ;; Servers typically require different EDT emulation
119 ;; initialization files, edt-mapper.el will now generate these
120 ;; different initialization files and save them with different
121 ;; names. Then, the correct initialization file for the
122 ;; particular X server in use is loaded correctly automatically.
124 ;; 5. Also, edt-mapper.el is now capable of binding an ASCII key
125 ;; sequence, providing the ASCII key sequence prefix is already
126 ;; known by Emacs to be a prefix. As a result of providing this
127 ;; support, some terminal/keyboard/window system configurations,
128 ;; which don't have a complete set of sensible function key
129 ;; bindings built into Emacs in `function-key-map', can still be
130 ;; configured for use with EDT Emulation. (Note: In a few rare
131 ;; circumstances this does not work properly. In particular, it
132 ;; does not work if a subset of the leading ASCII characters in a
133 ;; key sequence are recognized by Emacs as having an existing
134 ;; binding. For example, if the keypad 7 (KP-7) key generates
135 ;; the sequence \"<ESC>Ow\" and \"<ESC>O\" is already bound to a
136 ;; function, pressing KP-7 when told to do so by edt-mapper.el
137 ;; will result in edt-mapper.el incorrectly mapping \"<ESC>O\" to
138 ;; KP-7 and \"w\" to KP-8. If something like this happens to
139 ;; you, it is probably a bug in the support for your keyboard
140 ;; within Emacs OR a bug in the Unix termcap/terminfo support for
141 ;; your terminal OR a bug in the terminal emulation software you
144 ;; 6. The edt-quit function (bound to GOLD-q by default) has been
145 ;; modified to warn the user when file-related buffer
146 ;; modifications exist. It now cautions the user that those
147 ;; modifications will be lost if the user quits without saving
153 ;; Version 4.0 2000 Added New Features and Fixed a Few Bugs
159 ;;; Electric Help functions are used for keypad help displays. A few
160 ;;; picture functions are used in rectangular cut and paste commands.
166 ;;;; VARIABLES and CONSTANTS
169 ;; For backward compatibility to Emacs 19, skip this if defgroup is
171 (if (fboundp 'defgroup
)
173 "Emacs emulating EDT."
178 ;;; Version Information
180 (defconst edt-version
"4.0" "EDT Emulation version number.")
183 ;;; User Configurable Variables
186 ;; For backward compatibility to Emacs 19, use defvar if defcustom is
188 (if (fboundp 'defcustom
)
190 (defcustom edt-keep-current-page-delimiter nil
191 "*Emacs MUST be restarted for a change in value to take effect!
192 Non-nil leaves Emacs value of `page-delimiter' unchanged within EDT
193 Emulation. If set to nil (the default), the `page-delimiter' variable
194 is set to \"\\f\" when edt-emulation-on is first invoked. This
195 setting replicates EDT's page delimiter behavior. The original value
196 is restored when edt-emulation-off is called."
200 (defcustom edt-use-EDT-control-key-bindings nil
201 "*Emacs MUST be restarted for a change in value to take effect!
202 Non-nil causes the control key bindings to be replaced with EDT
203 bindings. If set to nil (the default), EDT control key bindings are
204 not used and the current Emacs control key bindings are retained for
205 use within the EDT emulation."
209 (defcustom edt-word-entities
'(?
\t)
210 "*Specifies the list of EDT word entity characters.
211 The default list, (\?\\t), contains just the TAB character, which
212 emulates EDT. Characters are specified in the list using their
213 decimal ASCII values. A question mark, followed by the actual
214 character, can be used to indicate the numerical value of the
215 character, instead of the actual decimal value. So, ?A means the
216 numerical value for the letter A, \?/ means the numerical value for /,
217 etc. Several unprintable and special characters have special
218 representations, which you can also use:
220 \?\\b specifies BS, C-h
221 \?\\t specifies TAB, C-i
222 \?\\n specifies LFD, C-j
223 \?\\v specifies VTAB, C-k
224 \?\\f specifies FF, C-l
225 \?\\r specifies CR, C-m
226 \?\\e specifies ESC, C-[
229 In EDT Emulation movement-by-word commands, each character in the list
230 will be treated as if it were a separate word."
231 :type
'(repeat integer
)
234 (defcustom edt-top-scroll-margin
10
235 "*Scroll margin at the top of the screen.
236 Interpreted as a percent of the current window size with a default
237 setting of 10%. If set to 0, top scroll margin is disabled."
241 (defcustom edt-bottom-scroll-margin
15
242 "*Scroll margin at the bottom of the screen.
243 Interpreted as a percent of the current window size with a default
244 setting of 15%. If set to 0, bottom scroll margin is disabled."
248 (defvar edt-keep-current-page-delimiter nil
249 "*Non-nil leaves Emacs value of `page-delimiter' unchanged within EDT
250 Emulation. If set to nil (the default), the `page-delimiter' variable
251 is set to \"\\f\" when edt-emulation-on is first invoked. This
252 setting replicates EDT's page delimiter behavior. The original value
253 is restored when edt-emulation-off is called.")
255 (defvar edt-use-EDT-control-key-bindings nil
256 "*Non-nil causes the control key bindings to be replaced with EDT
257 bindings. If set to nil (the default), EDT control key bindings are
258 not used and the current Emacs control key bindings are retained for
259 use within the EDT emulation.")
261 (defvar edt-word-entities
'(?
\t)
262 "*Specifies the list of EDT word entity characters.
263 The default list, (\?\\t), contains just the TAB character, which
264 emulates EDT. Characters are specified in the list using their
265 decimal ASCII values. A question mark, followed by the actual
266 character, can be used to indicate the numerical value of the
267 character, instead of the actual decimal value. So, ?A means the
268 numerical value for the letter A, \?/ means the numerical value for /,
269 etc. Several unprintable and special characters have special
270 representations, which you can also use:
272 \?\\b specifies BS, C-h
273 \?\\t specifies TAB, C-i
274 \?\\n specifies LFD, C-j
275 \?\\v specifies VTAB, C-k
276 \?\\f specifies FF, C-l
277 \?\\r specifies CR, C-m
278 \?\\e specifies ESC, C-[
281 In EDT Emulation movement-by-word commands, each character in the list
282 will be treated as if it were a separate word.")
284 (defvar edt-top-scroll-margin
10
285 "*Scroll margin at the top of the screen.
286 Interpreted as a percent of the current window size with a default
287 setting of 10%. If set to 0, top scroll margin is disabled.")
289 (defvar edt-bottom-scroll-margin
15
290 "*Scroll margin at the bottom of the screen.
291 Interpreted as a percent of the current window size with a default
292 setting of 15%. If set to 0, bottom scroll margin is disabled.")))
295 ;;; Internal Variables
298 (defvar edt-last-deleted-lines
""
299 "Last text deleted by the EDT emulation DEL L command.")
301 (defvar edt-last-deleted-words
""
302 "Last text deleted by the EDT emulation DEL W command.")
304 (defvar edt-last-deleted-chars
""
305 "Last text deleted by the EDT emulation DEL C command.")
307 (defvar edt-find-last-text
""
308 "Last text found by the EDT emulation FIND command.")
310 (defvar edt-match-beginning-mark
(make-marker)
311 "Used internally by the EDT emulation SUBS command.")
313 (defvar edt-match-end-mark
(make-marker)
314 "Used internally by the EDT emulation SUBS command.")
316 (defvar edt-last-replaced-key-definition nil
317 "Key definition replaced with `edt-define-key' or `edt-learn' command.")
319 (defvar edt-direction-string
""
320 "String indicating current direction of movement.")
322 (defvar edt-select-mode nil
323 "Non-nil means select mode is active.")
325 (defvar edt-select-mode-current
""
326 "Text displayed in mode line to indicate the state of EDT select mode.
327 When select mode is inactive, it is set to an empty string.")
329 (defconst edt-select-mode-string
" Select"
330 "Used in mode line to indicate select mode is active.")
332 (defconst edt-forward-string
" ADVANCE"
333 "Direction string in mode line to indicate forward movement.")
335 (defconst edt-backward-string
" BACKUP"
336 "Direction string in mode line to indicate backward movement.")
338 (defvar edt-default-map-active nil
339 "Non-nil indicates that default EDT emulation key bindings are active.
340 Nil means user-defined custom bindings are active.")
342 (defvar edt-user-map-configured nil
343 "Non-nil indicates that user custom EDT key bindings are configured.
344 This means that an edt-user.el file was found in the user's `load-path'.")
347 "Specifies the terminal type, if applicable.")
350 ;;; Emacs version identifiers - currently referenced by
352 ;;; o edt-emulation-on o edt-load-keys
354 (defconst edt-emacs19-p
(not (string-lessp emacs-version
"19"))
355 "Non-nil if we are running GNU Emacs or XEmacs version 19, or higher.")
357 (defconst edt-x-emacs19-p
358 (and edt-emacs19-p
(string-match "XEmacs" emacs-version
))
359 "Non-nil if we are running XEmacs version 19, or higher.")
361 (defconst edt-gnu-emacs19-p
(and edt-emacs19-p
(not edt-x-emacs19-p
))
362 "Non-nil if we are running GNU Emacs version 19, or higher.")
364 (defconst edt-emacs-variant
(if edt-gnu-emacs19-p
"gnu" "xemacs")
365 "Indicates Emacs variant: GNU Emacs or XEmacs \(aka Lucid Emacs\).")
367 (defconst edt-window-system
(if edt-gnu-emacs19-p window-system
(console-type))
368 "Indicates window system \(in GNU Emacs\) or console type \(in XEmacs\).")
370 (defconst edt-xserver
(if (eq edt-window-system
'x
)
372 (replace-in-string (x-server-vendor) "[ _]" "-")
373 (subst-char-in-string ? ?-
(x-server-vendor)))
375 "Indicates X server vendor name, if applicable.")
377 (defvar edt-keys-file nil
378 "User's custom keypad and function keys mappings to emulate LK-201 keyboard.")
381 ;;;; EDT Emulation Commands
384 ;;; Almost all of EDT's keypad mode commands have equivalent Emacs
385 ;;; function counterparts. But many of these counterparts behave
386 ;;; somewhat differently in Emacs.
388 ;;; So, the following Emacs functions emulate, where practical, the
389 ;;; exact behavior of the corresponding EDT keypad mode commands. In
390 ;;; a few cases, the emulation is not exact, but it should be close
391 ;;; enough for most EDT die-hards.
397 ;;; Emacs uses the regexp assigned to page-delimiter to determine what
398 ;;; marks a page break. This is normally "^\f", which causes the
399 ;;; edt-page command to ignore form feeds not located at the beginning
400 ;;; of a line. To emulate the EDT PAGE command exactly,
401 ;;; page-delimiter is set to "\f" when EDT emulation is turned on, and
402 ;;; restored to its original value when EDT emulation is turned off.
403 ;;; But this can be overridden if the EDT definition is not desired by
406 ;;; (setq edt-keep-current-page-delimiter t)
408 ;;; in your .emacs file.
410 (defun edt-page-forward (num)
411 "Move forward to just after next page delimiter.
412 Argument NUM is the number of page delimiters to move."
414 (edt-check-prefix num
)
416 (error "End of buffer")
420 (edt-line-to-bottom-of-window)
421 (edt-line-to-top-of-window)))))
423 (defun edt-page-backward (num)
424 "Move backward to just after previous page delimiter.
425 Argument NUM is the number of page delimiters to move."
427 (edt-check-prefix num
)
429 (error "Beginning of buffer")
432 (edt-line-to-top-of-window)
433 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))))
435 (defun edt-page (num)
436 "Move in current direction to next page delimiter.
437 Argument NUM is the number of page delimiters to move."
439 (if (equal edt-direction-string edt-forward-string
)
440 (edt-page-forward num
)
441 (edt-page-backward num
)))
446 ;;; EDT defaults a section size to be 16 lines of its one and only
447 ;;; 24-line window. That's two-thirds of the window at a time. The
448 ;;; EDT SECT commands moves the cursor, not the window.
450 ;;; This emulation of EDT's SECT moves the cursor approximately
451 ;;; two-thirds of the current window at a time.
453 (defun edt-sect-forward (num)
454 "Move cursor forward two-thirds of a window's number of lines.
455 Argument NUM is the number of sections to move."
457 (edt-check-prefix num
)
458 (edt-line-forward (* (* (/ (- (window-height) 1) 3) 2) num
)))
461 (defun edt-sect-backward (num)
462 "Move cursor backward two-thirds of a window.
463 Argument NUM is the number of sections to move."
465 (edt-check-prefix num
)
466 (edt-line-backward (* (* (/ (- (window-height) 1) 3) 2) num
)))
468 (defun edt-sect (num)
469 "Move in current direction a full window.
470 Argument NUM is the number of sections to move."
472 (if (equal edt-direction-string edt-forward-string
)
473 (edt-sect-forward num
)
474 (edt-sect-backward num
)))
477 ;;; BEGINNING OF LINE
479 ;;; EDT's beginning-of-line command is not affected by current
480 ;;; direction, for some unknown reason.
482 (defun edt-beginning-of-line (num)
483 "Move backward to next beginning of line mark.
484 Argument NUM is the number of BOL marks to move."
486 (edt-check-prefix num
)
487 (let ((beg (edt-current-line)))
489 (forward-line (* -
1 num
))
492 (forward-line (* -
1 num
))))
493 (edt-top-check beg num
))
494 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
498 ;;; EOL (End of Line)
501 (defun edt-end-of-line-forward (num)
502 "Move forward to next end of line mark.
503 Argument NUM is the number of EOL marks to move."
505 (edt-check-prefix num
)
506 (let ((beg (edt-current-line)))
509 (edt-bottom-check beg num
))
510 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
513 (defun edt-end-of-line-backward (num)
514 "Move backward to next end of line mark.
515 Argument NUM is the number of EOL marks to move."
517 (edt-check-prefix num
)
518 (let ((beg (edt-current-line)))
519 (end-of-line (1- num
))
520 (edt-top-check beg num
))
521 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
524 (defun edt-end-of-line (num)
525 "Move in current direction to next end of line mark.
526 Argument NUM is the number of EOL marks to move."
528 (if (equal edt-direction-string edt-forward-string
)
529 (edt-end-of-line-forward num
)
530 (edt-end-of-line-backward num
)))
535 ;;; This one is a tad messy. To emulate EDT's behavior everywhere in
536 ;;; the file (beginning of file, end of file, beginning of line, end
537 ;;; of line, etc.) it takes a bit of special handling.
539 ;;; The variable edt-word-entities contains a list of characters which
540 ;;; are to be viewed as distinct words where ever they appear in the
541 ;;; buffer. This emulates the EDT line mode command SET ENTITY WORD.
544 (defun edt-one-word-forward ()
545 "Move forward to first character of next word."
548 (error "End of buffer"))
552 (if (memq (following-char) edt-word-entities
)
557 (not (eq ?\
(char-syntax (following-char))))
558 (not (memq (following-char) edt-word-entities
)))
563 (eq ?\
(char-syntax (following-char)))
564 (not (memq (following-char) edt-word-entities
)))
566 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
568 (defun edt-one-word-backward ()
569 "Move backward to first character of previous word."
572 (error "Beginning of buffer"))
580 (eq ?\
(char-syntax (following-char)))
581 (not (memq (following-char) edt-word-entities
)))
583 (if (not (memq (following-char) edt-word-entities
))
587 (not (eq ?\
(char-syntax (preceding-char))))
588 (not (memq (preceding-char) edt-word-entities
)))
590 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
592 (defun edt-word-forward (num)
593 "Move forward to first character of next word.
594 Argument NUM is the number of words to move."
596 (edt-check-prefix num
)
598 (edt-one-word-forward)
599 (setq num
(1- num
))))
601 (defun edt-word-backward (num)
602 "Move backward to first character of previous word.
603 Argument NUM is the number of words to move."
605 (edt-check-prefix num
)
607 (edt-one-word-backward)
608 (setq num
(1- num
))))
610 (defun edt-word (num)
611 "Move in current direction to first character of next word.
612 Argument NUM is the number of words to move."
614 (if (equal edt-direction-string edt-forward-string
)
615 (edt-word-forward num
)
616 (edt-word-backward num
)))
622 (defun edt-character (num)
623 "Move in current direction to next character.
624 Argument NUM is the number of characters to move."
626 (edt-check-prefix num
)
627 (if (equal edt-direction-string edt-forward-string
)
630 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
635 ;;; When direction is set to BACKUP, LINE behaves just like BEGINNING
636 ;;; OF LINE in EDT. So edt-line-backward is not really needed as a
637 ;;; separate function.
639 (defun edt-line-backward (num)
640 "Move backward to next beginning of line mark.
641 Argument NUM is the number of BOL marks to move."
643 (edt-beginning-of-line num
))
645 (defun edt-line-forward (num)
646 "Move forward to next beginning of line mark.
647 Argument NUM is the number of BOL marks to move."
649 (edt-check-prefix num
)
650 (let ((beg (edt-current-line)))
652 (edt-bottom-check beg num
))
653 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
655 (defun edt-line (num)
656 "Move in current direction to next beginning of line mark.
657 Argument NUM is the number of BOL marks to move."
659 (if (equal edt-direction-string edt-forward-string
)
660 (edt-line-forward num
)
661 (edt-line-backward num
)))
664 ;;; UP and DOWN Arrows
667 (defun edt-next-line (num)
668 "Move cursor down one line.
669 Argument NUM is the number of lines to move."
671 (edt-check-prefix num
)
672 (let ((beg (edt-current-line)))
674 (edt-bottom-check beg num
))
675 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
677 (defun edt-previous-line (num)
678 "Move cursor up one line.
679 Argument NUM is the number of lines to move."
681 (edt-check-prefix num
)
682 (let ((beg (edt-current-line)))
684 (edt-top-check beg num
))
685 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
693 "Move cursor to the beginning of buffer."
695 (goto-char (point-min))
696 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
703 "Move cursor to the end of buffer."
705 (goto-char (point-max))
706 (edt-line-to-bottom-of-window))
712 (defun edt-find-forward (&optional find
)
713 "Find first occurrence of a string in forward direction and save it.
714 Optional argument FIND is t is this function is called from `edt-find'."
717 (set 'edt-find-last-text
(read-string "Search forward: ")))
719 (beg (edt-current-line))
720 (height (window-height))
722 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
724 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
725 (top-margin (/ (* height top-percent
) 100))
726 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
727 (bottom-margin (max beg
(- height bottom-up-margin
1)))
728 (top (save-excursion (move-to-window-line top-margin
) (point)))
729 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
731 (goto-char bottom
) (forward-line (- height
2)) (point))))
732 (if (search-forward edt-find-last-text
)
734 (search-backward edt-find-last-text
)
736 (cond((> (point) far
)
737 (setq left
(save-excursion (forward-line height
)))
738 (if (= 0 left
) (recenter top-margin
)
739 (recenter (- left bottom-up-margin
))))
741 (and (> (point) bottom
) (recenter bottom-margin
)))))))
742 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
744 (defun edt-find-backward (&optional find
)
745 "Find first occurrence of a string in the backward direction and save it.
746 Optional argument FIND is t if this function is called from `edt-find'."
749 (set 'edt-find-last-text
(read-string "Search backward: ")))
751 (beg (edt-current-line))
752 (height (window-height))
754 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
756 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
757 (top-margin (/ (* height top-percent
) 100))
758 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
759 (bottom-margin (max beg
(- height bottom-up-margin
1)))
760 (top (save-excursion (move-to-window-line top-margin
) (point)))
761 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
763 (goto-char bottom
) (forward-line (- height
2)) (point))))
764 (if (search-backward edt-find-last-text
)
766 (and (< (point) top
) (recenter (min beg top-margin
))))
767 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
770 "Find first occurrence of string in current direction and save it."
772 (set 'edt-find-last-text
(read-string "Search: "))
773 (if (equal edt-direction-string edt-forward-string
)
775 (edt-find-backward t
)))
782 (defun edt-find-next-forward ()
783 "Find next occurrence of a string in forward direction."
786 (beg (edt-current-line))
787 (height (window-height))
789 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
791 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
792 (top-margin (/ (* height top-percent
) 100))
793 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
794 (bottom-margin (max beg
(- height bottom-up-margin
1)))
795 (top (save-excursion (move-to-window-line top-margin
) (point)))
796 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
798 (goto-char bottom
) (forward-line (- height
2)) (point))))
800 (if (search-forward edt-find-last-text nil t
)
802 (search-backward edt-find-last-text
)
804 (cond((> (point) far
)
805 (setq left
(save-excursion (forward-line height
)))
806 (if (= 0 left
) (recenter top-margin
)
807 (recenter (- left bottom-up-margin
))))
809 (and (> (point) bottom
) (recenter bottom-margin
)))))
812 (error "Search failed: \"%s\"" edt-find-last-text
))))
813 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
815 (defun edt-find-next-backward ()
816 "Find next occurrence of a string in backward direction."
819 (beg (edt-current-line))
820 (height (window-height))
822 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
824 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
825 (top-margin (/ (* height top-percent
) 100))
826 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
827 (bottom-margin (max beg
(- height bottom-up-margin
1)))
828 (top (save-excursion (move-to-window-line top-margin
) (point)))
829 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
831 (goto-char bottom
) (forward-line (- height
2)) (point))))
832 (if (not (search-backward edt-find-last-text nil t
))
833 (error "Search failed: \"%s\"" edt-find-last-text
)
836 (and (< (point) top
) (recenter (min beg top-margin
))))))
837 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
839 (defun edt-find-next ()
840 "Find next occurrence of a string in current direction."
842 (if (equal edt-direction-string edt-forward-string
)
843 (edt-find-next-forward)
844 (edt-find-next-backward)))
851 "Append this kill region to last killed region."
853 (edt-check-selection)
855 (kill-region (mark) (point))
856 (message "Selected text APPENDED to kill ring"))
862 (defun edt-delete-line (num)
863 "Delete from cursor up to and including the end of line mark.
864 Argument NUM is the number of lines to delete."
866 (edt-check-prefix num
)
869 (if (not (eq (preceding-char) ?
\n))
871 (setq edt-last-deleted-lines
872 (buffer-substring beg
(point)))
873 (delete-region beg
(point))))
879 (defun edt-delete-to-end-of-line (num)
880 "Delete from cursor up to but excluding the end of line mark.
881 Argument NUM is the number of lines to delete."
883 (edt-check-prefix num
)
887 (setq edt-last-deleted-lines
888 (buffer-substring beg
(point)))
889 (delete-region beg
(point))))
895 (defun edt-select-mode (arg)
896 "Turn EDT select mode off if ARG is nil; otherwise, turn EDT select mode on.
897 In select mode, selected text is highlighted."
900 (make-local-variable 'edt-select-mode
)
901 (setq edt-select-mode
'edt-select-mode-current
)
902 (setq rect-start-point
(window-point)))
904 (kill-local-variable 'edt-select-mode
)))
905 (force-mode-line-update))
908 "Set mark at cursor and start text selection."
910 (set-mark-command nil
))
913 "Cancel text selection."
915 (if edt-gnu-emacs19-p
917 (zmacs-deactivate-region)))
924 "Deletes selected text but copies to kill ring."
926 (edt-check-selection)
927 (kill-region (mark) (point))
928 (message "Selected text CUT to kill ring"))
931 ;;; DELETE TO BEGINNING OF LINE
934 (defun edt-delete-to-beginning-of-line (num)
935 "Delete from cursor to beginning of line.
936 Argument NUM is the number of lines to delete."
938 (edt-check-prefix num
)
940 (edt-beginning-of-line num
)
941 (setq edt-last-deleted-lines
942 (buffer-substring (point) beg
))
943 (delete-region beg
(point))))
949 (defun edt-delete-word (num)
950 "Delete from cursor up to but excluding first character of next word.
951 Argument NUM is the number of words to delete."
953 (edt-check-prefix num
)
955 (edt-word-forward num
)
956 (setq edt-last-deleted-words
(buffer-substring beg
(point)))
957 (delete-region beg
(point))))
960 ;;; DELETE TO BEGINNING OF WORD
963 (defun edt-delete-to-beginning-of-word (num)
964 "Delete from cursor to beginning of word.
965 Argument NUM is the number of words to delete."
967 (edt-check-prefix num
)
969 (edt-word-backward num
)
970 (setq edt-last-deleted-words
(buffer-substring (point) beg
))
971 (delete-region beg
(point))))
977 (defun edt-delete-character (num)
978 "Delete character under cursor.
979 Argument NUM is the number of characters to delete."
981 (edt-check-prefix num
)
982 (setq edt-last-deleted-chars
983 (buffer-substring (point) (min (point-max) (+ (point) num
))))
984 (delete-region (point) (min (point-max) (+ (point) num
))))
990 (defun edt-delete-previous-character (num)
991 "Delete character in front of cursor.
992 Argument NUM is the number of characters to delete."
994 (edt-check-prefix num
)
995 (setq edt-last-deleted-chars
996 (buffer-substring (max (point-min) (- (point) num
)) (point)))
997 (delete-region (max (point-min) (- (point) num
)) (point)))
1003 (defun edt-undelete-line ()
1004 "Undelete previous deleted line(s)."
1006 (point-to-register 1)
1007 (insert edt-last-deleted-lines
)
1008 (register-to-point 1))
1014 (defun edt-undelete-word ()
1015 "Undelete previous deleted word(s)."
1017 (point-to-register 1)
1018 (insert edt-last-deleted-words
)
1019 (register-to-point 1))
1025 (defun edt-undelete-character ()
1026 "Undelete previous deleted character(s)."
1028 (point-to-register 1)
1029 (insert edt-last-deleted-chars
)
1030 (register-to-point 1))
1036 (defun edt-replace ()
1037 "Replace marked section with last CUT (killed) text."
1039 (if (edt-check-match)
1040 (replace-match (car kill-ring-yank-pointer
))
1042 (exchange-point-and-mark)
1043 (let ((beg (point)))
1044 (exchange-point-and-mark)
1045 (delete-region beg
(point)))
1052 (defun edt-substitute (num)
1053 "Replace the selected region with the contents of the CUT buffer and.
1054 Repeat the most recent FIND command. (The Emacs kill ring is used as
1056 Argument NUM is the repeat count. A positive value indicates the of times
1057 to repeat the substitution. A negative argument means replace all occurances
1058 of the search text."
1060 (cond ((or edt-select-mode
(edt-check-match))
1061 (while (and (not (= num
0)) (or edt-select-mode
(edt-check-match)))
1064 (setq num
(1- num
))))
1066 (error "No selection active"))))
1068 (defun edt-set-match nil
1069 "Set markers at match beginning and end."
1070 ;; Add one to beginning mark so it stays with the first character of
1071 ;; the string even if characters are added just before the string.
1072 (setq edt-match-beginning-mark
(copy-marker (1+ (match-beginning 0))))
1073 (setq edt-match-end-mark
(copy-marker (match-end 0))))
1075 (defun edt-unset-match nil
1076 "Unset match beginning and end markers."
1077 (set-marker edt-match-beginning-mark nil
)
1078 (set-marker edt-match-end-mark nil
))
1080 (defun edt-match-beginning nil
1081 "Return the location of the last match beginning."
1082 (1- (marker-position edt-match-beginning-mark
)))
1084 (defun edt-match-end nil
1085 "Return the location of the last match end."
1086 (marker-position edt-match-end-mark
))
1088 (defun edt-check-match nil
1089 "Return t if point is between edt-match markers.
1090 Otherwise sets the edt-match markers to nil and returns nil."
1091 ;; make sure 1- marker is in this buffer
1092 ;; 2- point is at or after beginning marker
1093 ;; 3- point is before ending marker, or in the case of
1094 ;; zero length regions (like bol, or eol) that the
1095 ;; beginning, end, and point are equal.
1097 (equal (marker-buffer edt-match-beginning-mark
) (current-buffer))
1098 (>= (point) (1- (marker-position edt-match-beginning-mark
)))
1100 (< (point) (marker-position edt-match-end-mark
))
1101 (and (= (1- (marker-position edt-match-beginning-mark
))
1102 (marker-position edt-match-end-mark
))
1103 (= (marker-position edt-match-end-mark
) (point))))) t
)
1105 (edt-unset-match) nil
)))
1107 (defun edt-show-match-markers nil
1108 "Show the values of the match markers."
1110 (if (markerp edt-match-beginning-mark
)
1111 (let ((beg (marker-position edt-match-beginning-mark
)))
1112 (message "(%s, %s) in %s -- current %s in %s"
1113 (if beg
(1- beg
) nil
)
1114 (marker-position edt-match-end-mark
)
1115 (marker-buffer edt-match-end-mark
)
1116 (point) (current-buffer)))))
1123 (defun edt-advance ()
1124 "Set movement direction forward.
1125 Also, execute command specified if in Minibuffer."
1127 (setq edt-direction-string edt-forward-string
)
1128 (force-mode-line-update)
1129 (if (string-equal " *Minibuf"
1130 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1132 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1139 (defun edt-backup ()
1140 "Set movement direction backward.
1141 Also, execute command specified if in Minibuffer."
1143 (setq edt-direction-string edt-backward-string
)
1144 (force-mode-line-update)
1145 (if (string-equal " *Minibuf"
1146 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1148 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1154 ;; This function is based upon Jeff Kowalski's case-flip function in his
1157 (defun edt-change-case (num)
1158 "Change the case of specified characters.
1159 If text selection IS active, then characters between the cursor and mark are
1160 changed. If text selection is NOT active, there are two cases. First, if the
1161 current direction is ADVANCE, then the prefix number of character(s) under and
1162 following cursor are changed. Second, if the current direction is BACKUP, then
1163 the prefix number of character(s) before the cursor are changed. Accepts a
1164 positive prefix for the number of characters to change, but the prefix is
1165 ignored if text selection is active.
1166 Argument NUM is the numbers of consecutive characters to change."
1168 (edt-check-prefix num
)
1170 (let ((end (max (mark) (point)))
1171 (point-save (point)))
1172 (goto-char (min (point) (mark)))
1173 (while (not (eq (point) end
))
1174 (funcall (if (<= ?a
(following-char))
1175 'upcase-region
'downcase-region
)
1176 (point) (1+ (point)))
1178 (goto-char point-save
))
1180 (if (string= edt-direction-string edt-backward-string
)
1181 (backward-char num
))
1183 (funcall (if (<= ?a
(following-char))
1184 'upcase-region
'downcase-region
)
1185 (point) (1+ (point)))
1187 (setq num
(1- num
))))))
1193 (defun edt-define-key ()
1194 "Assign an interactively-callable function to a specified key sequence.
1195 The current key definition is saved in `edt-last-replaced-key-definition'.
1196 Use `edt-restore-key' to restore last replaced key definition."
1198 (if edt-x-emacs19-p
(setq zmacs-region-stays t
))
1201 (setq edt-key-definition
1202 (read-key-sequence "Press the key to be defined: "))
1203 (if (if edt-gnu-emacs19-p
1204 (string-equal "\C-m" edt-key-definition
)
1205 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1206 (message "Key not defined")
1208 (setq edt-function
(read-command "Enter command name: "))
1209 (if (string-equal "" edt-function
)
1210 (message "Key not defined")
1212 (setq edt-last-replaced-key-definition
1213 (lookup-key (current-global-map) edt-key-definition
))
1214 (define-key (current-global-map)
1215 edt-key-definition edt-function
)))))))
1218 ;;; FORM FEED INSERT
1221 (defun edt-form-feed-insert (num)
1222 "Insert form feed character at cursor position.
1223 Argument NUM is the number of form feeds to insert."
1225 (edt-check-prefix num
)
1228 (setq num
(1- num
))))
1234 (defun edt-tab-insert (num)
1235 "Insert tab character at cursor position.
1236 Argument NUM is the the number of tabs to insert."
1238 (edt-check-prefix num
)
1241 (setq num
(1- num
))))
1247 (defun edt-check-prefix (num)
1248 "Indicate error if prefix is not positive.
1249 Argument NUM is the prefix value tested."
1251 (error "Prefix must be positive")))
1257 (defun edt-check-selection ()
1258 "Indicate error if EDT selection is not active."
1259 (if (not edt-select-mode
)
1260 (error "Selection NOT active")))
1266 (defun edt-top-check (beg lines
)
1267 "Enforce scroll margin at the top of screen.
1268 Argument BEG is the starting line number before cursor was moved.
1269 Argument LINES is the number of lines the cursor moved toward the top."
1270 (let ((margin (/ (* (window-height) edt-top-scroll-margin
) 100)))
1271 (cond ((< beg margin
) (recenter beg
))
1272 ((< (- beg lines
) margin
) (recenter margin
)))))
1274 (defun edt-bottom-check (beg lines
)
1275 "Enforce scroll margin at the bottom of screen.
1276 Argument BEG is the starting line number before cursor was moved.
1277 Argument LINES is the number of lines the cursor moved toward the bottom."
1278 (let* ((height (window-height))
1279 (margin (+ 1 (/ (* height edt-bottom-scroll-margin
) 100)))
1280 ;; subtract 1 from height because it includes mode line
1281 (difference (- height margin
1)))
1282 (cond ((> beg difference
) (recenter beg
))
1283 ((and edt-x-emacs19-p
(> (+ beg lines
1) difference
))
1284 (recenter (- margin
)))
1285 ((> (+ beg lines
) difference
) (recenter (- margin
))))))
1287 (defun edt-current-line nil
1288 "Return the vertical position of point in the selected window.
1289 Top line is 0. Counts each text line only once, even if it wraps."
1290 (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -
1))
1293 (defun edt-set-scroll-margins (top bottom
)
1294 "Set scroll margins.
1295 Argument TOP is the top margin in number of lines or percent of window.
1296 Argument BOTTOM is the bottom margin in number of lines or percent of window."
1298 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \
1299 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
1300 ;; set top scroll margin
1301 (or (string= top
"")
1302 (if (string= "%" (substring top -
1))
1303 (setq edt-top-scroll-margin
(string-to-int top
))
1304 (setq edt-top-scroll-margin
1305 (/ (1- (+ (* (string-to-int top
) 100) (window-height)))
1307 ;; set bottom scroll margin
1308 (or (string= bottom
"")
1309 (if (string= "%" (substring bottom -
1))
1310 (setq edt-bottom-scroll-margin
(string-to-int bottom
))
1311 (setq edt-bottom-scroll-margin
1312 (/ (1- (+ (* (string-to-int bottom
) 100) (window-height)))
1314 ;; report scroll margin settings if running interactively
1315 (and (interactive-p)
1316 (message "Scroll margins set. Top = %s%%, Bottom = %s%%"
1317 edt-top-scroll-margin edt-bottom-scroll-margin
)))
1321 ;;;; ENHANCEMENTS AND ADDITIONS FOR EDT KEYPAD MODE
1325 ;;; Several enhancements and additions to EDT keypad mode commands are
1326 ;;; provided here. Some of these have been motivated by similar
1327 ;;; TPU/EVE and EVE-Plus commands. Others are new.
1330 ;;; CHANGE DIRECTION
1333 (defun edt-change-direction ()
1334 "Toggle movement direction."
1336 (if (equal edt-direction-string edt-forward-string
)
1344 (defun edt-toggle-select ()
1345 "Toggle to start (or cancel) text selection."
1355 (defun edt-sentence-forward (num)
1356 "Move forward to start of next sentence.
1357 Argument NUM is the positive number of sentences to move."
1359 (edt-check-prefix num
)
1361 (beg (edt-current-line))
1362 (height (window-height))
1364 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1366 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1367 (top-margin (/ (* height top-percent
) 100))
1368 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1369 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1370 (top (save-excursion (move-to-window-line top-margin
) (point)))
1371 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1372 (far (save-excursion
1373 (goto-char bottom
) (forward-line (- height
2)) (point))))
1376 (error "End of buffer"))
1378 (forward-sentence num
)
1380 (backward-sentence)))
1381 (cond((> (point) far
)
1382 (setq left
(save-excursion (forward-line height
)))
1383 (if (= 0 left
) (recenter top-margin
)
1384 (recenter (- left bottom-up-margin
))))
1386 (and (> (point) bottom
) (recenter bottom-margin
)))))
1387 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1389 (defun edt-sentence-backward (num)
1390 "Move backward to next sentence beginning.
1391 Argument NUM is the positive number of sentences to move."
1393 (edt-check-prefix num
)
1395 (beg (edt-current-line))
1396 (height (window-height))
1398 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1400 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1401 (top-margin (/ (* height top-percent
) 100))
1402 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1403 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1404 (top (save-excursion (move-to-window-line top-margin
) (point)))
1405 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1406 (far (save-excursion
1407 (goto-char bottom
) (forward-line (- height
2)) (point))))
1410 (error "End of buffer"))
1411 (backward-sentence num
))
1412 (and (< (point) top
) (recenter (min beg top-margin
))))
1413 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1415 (defun edt-sentence (num)
1416 "Move in current direction to next sentence.
1417 Argument NUM is the positive number of sentences to move."
1419 (if (equal edt-direction-string edt-forward-string
)
1420 (edt-sentence-forward num
)
1421 (edt-sentence-backward num
)))
1427 (defun edt-paragraph-forward (num)
1428 "Move forward to beginning of paragraph.
1429 Argument NUM is the positive number of paragraphs to move."
1431 (edt-check-prefix num
)
1433 (beg (edt-current-line))
1434 (height (window-height))
1436 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1438 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1439 (top-margin (/ (* height top-percent
) 100))
1440 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1441 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1442 (top (save-excursion (move-to-window-line top-margin
) (point)))
1443 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1444 (far (save-excursion
1445 (goto-char bottom
) (forward-line (- height
2)) (point))))
1447 (forward-paragraph (+ num
1))
1448 (start-of-paragraph-text)
1451 (setq num
(1- num
)))
1452 (cond((> (point) far
)
1453 (setq left
(save-excursion (forward-line height
)))
1454 (if (= 0 left
) (recenter top-margin
)
1455 (recenter (- left bottom-up-margin
))))
1457 (and (> (point) bottom
) (recenter bottom-margin
)))))
1458 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1460 (defun edt-paragraph-backward (num)
1461 "Move backward to beginning of paragraph.
1462 Argument NUM is the positive number of paragraphs to move."
1464 (edt-check-prefix num
)
1466 (beg (edt-current-line))
1467 (height (window-height))
1469 (if (= 0 edt-top-scroll-margin
) 10 edt-top-scroll-margin
))
1471 (if (= 0 edt-bottom-scroll-margin
) 15 edt-bottom-scroll-margin
))
1472 (top-margin (/ (* height top-percent
) 100))
1473 (bottom-up-margin (+ 1 (/ (* height bottom-percent
) 100)))
1474 (bottom-margin (max beg
(- height bottom-up-margin
1)))
1475 (top (save-excursion (move-to-window-line top-margin
) (point)))
1476 (bottom (save-excursion (move-to-window-line bottom-margin
) (point)))
1477 (far (save-excursion
1478 (goto-char bottom
) (forward-line (- height
2)) (point))))
1480 (start-of-paragraph-text)
1481 (setq num
(1- num
)))
1482 (and (< (point) top
) (recenter (min beg top-margin
))))
1483 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1485 (defun edt-paragraph (num)
1486 "Move in current direction to next paragraph.
1487 Argument NUM is the positive number of paragraphs to move."
1489 (if (equal edt-direction-string edt-forward-string
)
1490 (edt-paragraph-forward num
)
1491 (edt-paragraph-backward num
)))
1497 (defun edt-restore-key ()
1498 "Restore last replaced key definition.
1499 Definition is stored in `edt-last-replaced-key-definition'."
1501 (if edt-x-emacs19-p
(setq zmacs-region-stays t
))
1502 (if edt-last-replaced-key-definition
1504 (let (edt-key-definition)
1505 (set 'edt-key-definition
1506 (read-key-sequence "Press the key to be restored: "))
1507 (if (if edt-gnu-emacs19-p
1508 (string-equal "\C-m" edt-key-definition
)
1509 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1510 (message "Key not restored")
1512 (define-key (current-global-map)
1513 edt-key-definition edt-last-replaced-key-definition
)
1514 (if edt-gnu-emacs19-p
1515 (message "Key definition for %s has been restored."
1517 (message "Key definition for %s has been restored."
1518 (events-to-keys edt-key-definition
)))))))
1519 (error "No replaced key definition to restore!")))
1525 (defun edt-window-top ()
1526 "Move the cursor to the top of the window."
1528 (let ((start-column (current-column)))
1529 (move-to-window-line 0)
1530 (move-to-column start-column
))
1531 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1537 (defun edt-window-bottom ()
1538 "Move the cursor to the bottom of the window."
1540 (let ((start-column (current-column)))
1541 (move-to-window-line (- (window-height) 2))
1542 (move-to-column start-column
))
1543 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1546 ;;; SCROLL WINDOW LINE
1549 (defun edt-scroll-window-forward-line ()
1550 "Move window forward one line leaving cursor at position in window."
1553 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1555 (defun edt-scroll-window-backward-line ()
1556 "Move window backward one line leaving cursor at position in window."
1559 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1561 (defun edt-scroll-line ()
1562 "Move window one line in current direction."
1564 (if (equal edt-direction-string edt-forward-string
)
1565 (edt-scroll-window-forward-line)
1566 (edt-scroll-window-backward-line)))
1571 ;;; Scroll a window (less one line) at a time. Leave cursor in center of
1574 (defun edt-scroll-window-forward (num)
1575 "Scroll forward one window in buffer, less one line.
1576 Argument NUM is the positive number of windows to move."
1578 (edt-check-prefix num
)
1579 (scroll-up (- (* (window-height) num
) 2))
1580 (edt-line-forward (/ (- (window-height) 1) 2)))
1582 (defun edt-scroll-window-backward (num)
1583 "Scroll backward one window in buffer, less one line.
1584 Argument NUM is the positive number of windows to move."
1586 (edt-check-prefix num
)
1587 (scroll-down (- (* (window-height) num
) 2))
1588 (edt-line-backward (/ (- (window-height) 1) 2)))
1590 (defun edt-scroll-window (num)
1591 "Scroll one window in buffer, less one line, in current direction.
1592 Argument NUM is the positive number of windows to move."
1594 (if (equal edt-direction-string edt-forward-string
)
1595 (edt-scroll-window-forward num
)
1596 (edt-scroll-window-backward num
)))
1599 ;;; LINE TO BOTTOM OF WINDOW
1602 (defun edt-line-to-bottom-of-window ()
1603 "Move the current line to the bottom of the window."
1606 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1609 ;;; LINE TO TOP OF WINDOW
1612 (defun edt-line-to-top-of-window ()
1613 "Move the current line to the top of the window."
1616 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1619 ;;; LINE TO MIDDLE OF WINDOW
1622 (defun edt-line-to-middle-of-window ()
1623 "Move window so line with cursor is in the middle of the window."
1626 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1632 (defun edt-goto-percentage (num)
1633 "Move to specified percentage in buffer from top of buffer.
1634 Argument NUM is the percentage into the buffer to move."
1635 (interactive "NGoto-percentage: ")
1636 (if (or (> num
100) (< num
0))
1637 (error "Percentage %d out of range 0 < percent < 100" num
)
1638 (goto-char (/ (* (point-max) num
) 100)))
1639 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1645 (defun edt-fill-region ()
1646 "Fill selected text."
1648 (edt-check-selection)
1649 (fill-region (point) (mark)))
1652 ;;; INDENT OR FILL REGION
1655 (defun edt-indent-or-fill-region ()
1656 "Fill region in text modes, indent region in programming language modes."
1658 (if (string= paragraph-start
"$\\|\f")
1659 (indent-region (point) (mark) nil
)
1660 (fill-region (point) (mark))))
1663 ;;; MARK SECTION WISELY
1666 (defun edt-mark-section-wisely ()
1667 "Mark the section in a manner consistent with the `major-mode'.
1668 Uses `mark-defun' for emacs-lisp and Lisp,
1669 mark-c-function for C,
1670 mark-fortran-subsystem for fortran,
1671 and `mark-paragraph' for other modes."
1677 (cond ((or (eq major-mode
'emacs-lisp-mode
)
1678 (eq major-mode
'lisp-mode
))
1680 (message "Lisp defun selected"))
1681 ((eq major-mode
'c-mode
)
1683 (message "C function selected"))
1684 ((eq major-mode
'fortran-mode
)
1685 (mark-fortran-subprogram)
1686 (message "Fortran subprogram selected"))
1688 (message "Paragraph selected"))))))
1695 "Copy selected region to kill ring, but don't delete it!"
1697 (edt-check-selection)
1698 (copy-region-as-kill (mark) (point))
1700 (message "Selected text COPIED to kill ring"))
1706 (defun edt-cut-or-copy ()
1707 "Cuts (or copies) selected text to kill ring.
1708 Cuts selected text if `buffer-read-only' is nil.
1709 Copies selected text if `buffer-read-only' is t."
1711 (if buffer-read-only
1716 ;;; DELETE ENTIRE LINE
1719 (defun edt-delete-entire-line ()
1720 "Delete entire line regardless of cursor position in the line."
1723 (edt-delete-line 1))
1729 (defun edt-duplicate-line (num)
1730 "Duplicate the line of text containing the cursor.
1731 Argument NUM is the number of times to duplicate the line."
1733 (edt-check-prefix num
)
1734 (let ((old-column (current-column))
1736 (edt-delete-entire-line)
1740 (setq count
(1- count
)))
1741 (edt-line-forward num
)
1742 (move-to-column old-column
)))
1748 (defun edt-duplicate-word()
1749 "Duplicate word (or rest of word) found directly above cursor, if any."
1751 (let ((start (point))
1752 (start-column (current-column)))
1754 (move-to-column start-column
)
1755 (if (and (not (equal start
(point)))
1758 (if (and (equal ?
\t (preceding-char))
1759 (< start-column
(current-column)))
1761 (let ((beg (point)))
1762 (edt-one-word-forward)
1763 (setq edt-last-copied-word
(buffer-substring beg
(point))))
1765 (move-to-column start-column
)
1766 (insert edt-last-copied-word
))
1768 (if (not (equal start
(point)))
1770 (move-to-column start-column
)
1771 (error "Nothing to duplicate!")))))
1774 ;;; KEY NOT ASSIGNED
1777 (defun edt-key-not-assigned ()
1778 "Displays message that key has not been assigned to a function."
1780 (error "Key not assigned"))
1783 ;;; TOGGLE CAPITALIZATION OF WORD
1786 (defun edt-toggle-capitalization-of-word ()
1787 "Toggle the capitalization of the current word and move forward to next."
1789 (edt-one-word-forward)
1790 (edt-one-word-backward)
1792 (edt-one-word-backward)
1793 (edt-one-word-forward))
1796 ;;; ELIMINATE ALL TABS
1799 (defun edt-eliminate-all-tabs ()
1800 "Convert all tabs to spaces in the entire buffer."
1802 (untabify (point-min) (point-max))
1803 (message "TABS converted to SPACES"))
1806 ;;; DISPLAY THE TIME
1809 (defun edt-display-the-time ()
1810 "Display the current time."
1812 (if edt-x-emacs19-p
(setq zmacs-region-stays t
))
1813 (set 'time-string
(current-time-string))
1814 (message "%s" time-string
))
1821 "Learn a sequence of key strokes to bind to a key."
1823 (if (eq defining-kbd-macro t
)
1825 (start-kbd-macro nil
)))
1831 (defun edt-remember ()
1832 "Store the sequence of key strokes started by `edt-learn' to a key."
1834 (if (eq defining-kbd-macro nil
)
1835 (error "Nothing to remember!")
1838 (let (edt-key-definition)
1839 (set 'edt-key-definition
1840 (read-key-sequence "Enter key for binding: "))
1841 (if (if edt-gnu-emacs19-p
1842 (string-equal "\C-m" edt-key-definition
)
1843 (string-equal "\C-m" (events-to-keys edt-key-definition
)))
1844 (message "Key sequence not remembered")
1846 (set 'edt-learn-macro-count
(+ edt-learn-macro-count
1))
1847 (setq edt-last-replaced-key-definition
1848 (lookup-key (current-global-map)
1849 edt-key-definition
))
1850 (define-key (current-global-map) edt-key-definition
1851 (name-last-kbd-macro
1852 (intern (concat "last-learned-sequence-"
1853 (int-to-string edt-learn-macro-count
)))))))))))
1860 "Save current buffer, ask to save other buffers, and then exit Emacs."
1863 (save-buffers-kill-emacs))
1870 "Quit Emacs without saving buffer modifications.
1871 Warn user that modifications will be lost."
1873 (let ((list (buffer-list))
1875 (while (and list working
)
1876 (let ((buffer (car list
)))
1877 (if (and (buffer-file-name buffer
) (buffer-modified-p buffer
))
1879 "Modifications will not be saved, continue quitting? ")
1881 (setq working nil
)))
1882 (setq list
(cdr list
))))
1883 (if working
(kill-emacs))))
1889 (defun edt-split-window ()
1890 "Split current window and place cursor in the new window."
1894 (if edt-x-emacs19-p
(setq zmacs-region-stays t
)))
1900 (defun edt-copy-rectangle ()
1901 "Copy a rectangle of text between mark and cursor to register."
1903 (edt-check-selection)
1904 (copy-rectangle-to-register 3 (region-beginning) (region-end) nil
)
1906 (message "Selected rectangle COPIED to register"))
1912 (defun edt-cut-rectangle-overstrike-mode ()
1913 "Cut a rectangle of text between mark and cursor to register.
1914 Replace cut characters with spaces and moving cursor back to
1917 (edt-check-selection)
1918 (setq edt-rect-start-point
(region-beginning))
1919 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3)
1920 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point
)
1921 (message "Selected rectangle CUT to register"))
1923 (defun edt-cut-rectangle-insert-mode ()
1924 "Cut a rectangle of text between mark and cursor to register.
1925 Move cursor back to upper left corner."
1927 (edt-check-selection)
1928 (setq edt-rect-start-point
(region-beginning))
1929 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3 t
)
1931 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point
)
1932 (message "Selected rectangle CUT to register"))
1934 (defun edt-cut-rectangle ()
1935 "Cut a rectangular region of text to register.
1936 If overwrite mode is active, cut text is replaced with whitespace."
1939 (edt-cut-rectangle-overstrike-mode)
1940 (edt-cut-rectangle-insert-mode)))
1946 (defun edt-paste-rectangle-overstrike-mode ()
1947 "Paste a rectangular region of text from register, replacing text at cursor."
1949 (picture-yank-rectangle-from-register 3))
1951 (defun edt-paste-rectangle-insert-mode ()
1952 "Paste previously deleted rectangular region, inserting text at cursor."
1954 (picture-yank-rectangle-from-register 3 t
))
1956 (defun edt-paste-rectangle ()
1957 "Paste a rectangular region of text.
1958 If overwrite mode is active, existing text is replace with text from register."
1961 (edt-paste-rectangle-overstrike-mode)
1962 (edt-paste-rectangle-insert-mode)))
1968 (defun edt-lowercase ()
1969 "Change specified characters to lower case.
1970 If text selection IS active, then characters between the cursor and
1971 mark are changed. If text selection is NOT active, there are two
1972 situations. If the current direction is ADVANCE, then the word under
1973 the cursor is changed to lower case and the cursor is moved to rest at
1974 the beginning of the next word. If the current direction is BACKUP,
1975 the word prior to the word under the cursor is changed to lower case
1976 and the cursor is left to rest at the beginning of that word."
1980 (downcase-region (mark) (point)))
1982 ;; Move to beginning of current word.
1988 (not (eq ?\
(char-syntax (preceding-char))))
1989 (not (memq (preceding-char) edt-word-entities
))
1990 (not (memq (following-char) edt-word-entities
)))
1991 (edt-one-word-backward))
1992 (if (equal edt-direction-string edt-backward-string
)
1993 (edt-one-word-backward))
1994 (let ((beg (point)))
1995 (edt-one-word-forward)
1996 (downcase-region beg
(point)))
1997 (if (equal edt-direction-string edt-backward-string
)
1998 (edt-one-word-backward)))))
2004 (defun edt-uppercase ()
2005 "Change specified characters to upper case.
2006 If text selection IS active, then characters between the cursor and
2007 mark are changed. If text selection is NOT active, there are two
2008 situations. If the current direction is ADVANCE, then the word under
2009 the cursor is changed to upper case and the cursor is moved to rest at
2010 the beginning of the next word. If the current direction is BACKUP,
2011 the word prior to the word under the cursor is changed to upper case
2012 and the cursor is left to rest at the beginning of that word."
2016 (upcase-region (mark) (point)))
2018 ;; Move to beginning of current word.
2024 (not (eq ?\
(char-syntax (preceding-char))))
2025 (not (memq (preceding-char) edt-word-entities
))
2026 (not (memq (following-char) edt-word-entities
)))
2027 (edt-one-word-backward))
2028 (if (equal edt-direction-string edt-backward-string
)
2029 (edt-one-word-backward))
2030 (let ((beg (point)))
2031 (edt-one-word-forward)
2032 (upcase-region beg
(point)))
2033 (if (equal edt-direction-string edt-backward-string
)
2034 (edt-one-word-backward)))))
2037 ;;; Functions used in loading LK-201 key mapping file.
2039 (defvar edt-last-answer nil
2040 "Most recent response to `edt-y-or-n-p'.")
2042 (defun edt-y-or-n-p (prompt &optional not-yes
)
2043 "Prompt for a y or n answer with positive default.
2044 Like Emacs `y-or-n-p', also accepts space as y and DEL as n.
2045 Argument PROMPT is the prompt string.
2046 Optional argument NOT-YES changes the default to negative."
2047 (message "%s[%s]" prompt
(if not-yes
"n" "y"))
2051 (let ((ans (read-char)))
2052 (cond ((or (= ans ?y
) (= ans ?Y
) (= ans ?\
))
2053 (setq edt-last-answer t
))
2054 ((or (= ans ?n
) (= ans ?N
) (= ans ?\C-?
))
2055 (setq edt-last-answer nil
))
2056 ((= ans ?
\r) (setq edt-last-answer
(not not-yes
)))
2058 (setq doit t
) (beep)
2059 (message "Please answer y or n. %s[%s]"
2060 prompt
(if not-yes
"n" "y")))))))
2064 ;;; INITIALIZATION COMMANDS.
2068 ;;; Function used to load LK-201 key mapping file generated by edt-mapper.el.
2070 (defun edt-load-keys (file)
2071 "Load the LK-201 key mapping FILE generated by edt-mapper.el.
2072 If FILE is nil, which is the normal case, try to load a default file.
2073 The default file names are based upon the window system, terminal
2074 type, and version of Emacs in use: GNU Emacs or XEmacs (aka Lucid
2075 Emacs). If a default file does not exist, ask user if one should be
2077 (interactive "fKey definition file: ")
2079 (setq file
(expand-file-name file
)))
2081 (setq file
(expand-file-name edt-keys-file
)))
2086 "~/.edt-" edt-emacs-variant
2087 (if edt-term
(concat "-" edt-term
))
2088 (if edt-xserver
(concat "-" edt-xserver
))
2089 (if edt-window-system
2090 (concat "-" (upcase (symbol-name edt-window-system
))))
2092 (cond ((file-readable-p file
)
2095 (switch-to-buffer "*scratch*")
2099 Ack!! You're running the Enhanced EDT Emulation without loading an
2100 EDT key mapping file. To create an EDT key mapping file, run the
2101 edt-mapper.el program. It is safest to run it from an Emacs loaded
2102 without any of your own customizations found in your .emacs file, etc.
2103 The reason for this is that some user customizations confuse edt-mapper.
2104 You can do this by quitting Emacs and then invoking Emacs again as
2107 emacs -q -l edt-mapper.el
2109 [NOTE: If you do nothing out of the ordinary in your .emacs file, and
2110 the search for edt-mapper.el is successful, you can try running it now.]
2112 The file edt-mapper.el includes these same directions on how to
2113 use it! Perhaps it's lying around here someplace. \n ")
2114 (let ((file "edt-mapper.el")
2117 (search-list (append (list (expand-file-name ".")) load-path
)))
2118 (while (and (not found
) search-list
)
2119 (setq path
(concat (car search-list
)
2120 (if (string-match "/$" (car search-list
)) "" "/")
2122 (if (and (file-exists-p path
) (not (file-directory-p path
)))
2124 (setq search-list
(cdr search-list
)))
2127 "Ah yes, there it is, in \n\n %s \n\n" path
))
2128 (if (edt-y-or-n-p "Do you want to run it now? ")
2130 (error "EDT Emulation not configured")))
2132 (insert "Nope, I can't seem to find it. :-(\n\n")
2134 (error "EDT Emulation not configured")))))))
2137 ;;; Turning the EDT Emulation on and off.
2141 (defun edt-emulation-on ()
2142 "Turn on EDT Emulation."
2144 ;; If using pc window system (MS-DOS), set terminal type to pc.
2145 ;; If not a window system (GNU) or a tty window system (XEmacs),
2146 ;; get terminal type.
2147 (if (eq edt-window-system
'pc
)
2148 (setq edt-term
"pc")
2149 (if (or (not edt-window-system
) (eq edt-window-system
'tty
))
2150 (setq edt-term
(getenv "TERM"))))
2151 ;; Look for for terminal configuration file for this terminal type.
2152 ;; Otherwise, load the user's custom configuration file.
2153 (if (or (not edt-window-system
) (memq edt-window-system
'(pc tty
)))
2155 ;; Load terminal-specific configuration file, if it exists for this
2156 ;; terminal type. Note: All DEC VT series terminals are supported
2157 ;; by the same terminal configuration file: edt-vt100.el.
2158 (if (string-equal "vt" (substring edt-term
0 (min (length edt-term
) 2)))
2159 (setq edt-term
"vt100"))
2160 (let ((term edt-term
)
2163 (not (load (concat "edt-" term
) t t
)))
2164 ;; Strip off last hyphen and what follows, then try again
2165 (if (setq hyphend
(string-match "[-_][^-_]+$" term
))
2166 (setq term
(substring term
0 hyphend
))
2168 ;; If no terminal-specific configuration file exists, load user's
2169 ;; custom EDT terminal configuration file.
2170 ;; If this is a pc running MS-DOS, then custom configuration files
2171 ;; are not supported. So, if the file is missing, issue an error
2174 (if (equal edt-term
"pc")
2175 (error "Unable to find EDT terminal specific file edt-pc.el")
2176 (edt-load-keys nil
))
2177 (setq edt-term term
))))
2178 (edt-load-keys nil
))
2179 ;; Make highlighting of selected text work properly for EDT commands.
2180 (if edt-gnu-emacs19-p
2182 (setq edt-orig-transient-mark-mode transient-mark-mode
)
2183 (add-hook 'activate-mark-hook
2186 (edt-select-mode t
))))
2187 (add-hook 'deactivate-mark-hook
2190 (edt-select-mode nil
)))))
2192 (add-hook 'zmacs-activate-region-hook
2195 (edt-select-mode t
))))
2196 (add-hook 'zmacs-deactivate-region-hook
2199 (edt-select-mode nil
))))))
2200 ;; Load user's EDT custom key bindings file, if it exists.
2201 ;; Otherwise, use the default bindings.
2202 (if (load "edt-user" t t
)
2203 (edt-user-emulation-setup)
2204 (edt-default-emulation-setup)))
2206 (defun edt-emulation-off()
2207 "Select original global key bindings, disabling EDT Emulation."
2209 (use-global-map global-map
)
2210 (if (not edt-keep-current-page-delimiter
)
2211 (setq page-delimiter edt-orig-page-delimiter
))
2212 (setq edt-direction-string
"")
2213 (setq edt-select-mode-current nil
)
2215 (force-mode-line-update t
)
2216 (if edt-gnu-emacs19-p
2217 (setq transient-mark-mode edt-orig-transient-mark-mode
))
2218 (message "Original key bindings restored; EDT Emulation disabled"))
2220 (defun edt-default-emulation-setup (&optional user-setup
)
2221 "Setup emulation of DEC's EDT editor.
2222 Optional argument USER-SETUP non-nil means called from function
2223 `edt-user-emulation-setup'."
2224 ;; Setup default EDT global map by copying global map bindings.
2225 ;; This preserves ESC and C-x prefix bindings and other bindings we
2226 ;; wish to retain in EDT emulation mode keymaps. It also permits
2227 ;; customization of these bindings in the EDT global maps without
2228 ;; disturbing the original bindings in global-map.
2229 (fset 'edt-default-ESC-prefix
(copy-keymap 'ESC-prefix
))
2230 (setq edt-default-global-map
(copy-keymap (current-global-map)))
2231 (if edt-gnu-emacs19-p
2232 (define-key edt-default-global-map
"\e" 'edt-default-ESC-prefix
)
2233 (define-key edt-default-global-map
[escape] 'edt-default-ESC-prefix))
2234 (define-prefix-command 'edt-default-gold-map)
2235 (edt-setup-default-bindings)
2236 ;; If terminal has additional function keys, the terminal-specific
2237 ;; initialization file can assign bindings to them via the optional
2238 ;; function edt-setup-extra-default-bindings.
2239 (if (fboundp 'edt-setup-extra-default-bindings)
2240 (edt-setup-extra-default-bindings))
2241 ;; Variable needed by edt-learn.
2242 (setq edt-learn-macro-count 0)
2243 ;; Display EDT text selection active within the mode line
2244 (or (assq 'edt-select-mode minor-mode-alist)
2245 (setq minor-mode-alist
2246 (cons '(edt-select-mode edt-select-mode) minor-mode-alist)))
2247 ;; Display EDT direction of motion within the mode line
2248 (or (assq 'edt-direction-string minor-mode-alist)
2249 (setq minor-mode-alist
2251 '(edt-direction-string edt-direction-string) minor-mode-alist)))
2254 (setq edt-user-map-configured t)
2255 (fset 'edt-emulation-on (symbol-function 'edt-select-user-global-map)))
2257 (fset 'edt-emulation-on (symbol-function 'edt-select-default-global-map))
2258 (edt-select-default-global-map))))
2260 (defun edt-user-emulation-setup ()
2261 "Setup user custom emulation of DEC's EDT editor."
2262 ;; Initialize EDT default bindings.
2263 (edt-default-emulation-setup t)
2264 ;; Setup user EDT global map by copying default EDT global map bindings.
2265 (fset 'edt-user-ESC-prefix (copy-keymap 'edt-default-ESC-prefix))
2266 (setq edt-user-global-map (copy-keymap edt-default-global-map))
2267 (if edt-gnu-emacs19-p
2268 (define-key edt-user-global-map "\e" 'edt-user-ESC-prefix)
2269 (define-key edt-user-global-map [escape] 'edt-user-ESC-prefix
))
2270 ;; If terminal has additional function keys, the user's initialization
2271 ;; file can assign bindings to them via the optional
2272 ;; function edt-setup-extra-default-bindings.
2273 (define-prefix-command 'edt-user-gold-map
)
2274 (fset 'edt-user-gold-map
(copy-keymap 'edt-default-gold-map
))
2275 (edt-setup-user-bindings)
2276 (edt-select-user-global-map))
2278 (defun edt-select-default-global-map()
2279 "Select default EDT emulation key bindings."
2281 (if edt-gnu-emacs19-p
2282 (transient-mark-mode 1))
2283 (use-global-map edt-default-global-map
)
2284 (if (not edt-keep-current-page-delimiter
)
2286 (setq edt-orig-page-delimiter page-delimiter
)
2287 (setq page-delimiter
"\f")))
2288 (setq edt-default-map-active t
)
2290 (setq edt-select-mode-current
'edt-select-mode-string
)
2292 (message "Default EDT keymap active"))
2294 (defun edt-select-user-global-map()
2295 "Select user EDT emulation custom key bindings."
2297 (if edt-user-map-configured
2299 (if edt-gnu-emacs19-p
2300 (transient-mark-mode 1))
2301 (use-global-map edt-user-global-map
)
2302 (if (not edt-keep-current-page-delimiter
)
2304 (setq edt-orig-page-delimiter page-delimiter
)
2305 (setq page-delimiter
"\f")))
2306 (setq edt-default-map-active nil
)
2308 (setq edt-select-mode-current
'edt-select-mode-string
)
2310 (message "User EDT custom keymap active"))
2311 (error "User EDT custom keymap NOT configured!")))
2313 (defun edt-switch-global-maps ()
2314 "Toggle between default EDT keymap and user EDT keymap."
2316 (if edt-default-map-active
2317 (edt-select-user-global-map)
2318 (edt-select-default-global-map)))
2321 ;; Functions used to set up DEFAULT bindings to EDT emulation functions.
2324 (defun edt-bind-function-key-default (function-key binding gold-binding
)
2325 "Binds LK-201 function keys to default bindings in the EDT Emulator.
2326 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2327 Argument BINDING is the Emacs function to be bound to <KEY>.
2328 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2329 (let ((key (cdr (assoc function-key
*EDT-keys
*))))
2330 (if (and key
(not (equal key
"")))
2332 (define-key edt-default-global-map key binding
)
2333 (define-key 'edt-default-gold-map key gold-binding
)))))
2335 (defun edt-bind-key-default (key binding
)
2336 "Bind key sequences to default bindings in the EDT Emulator.
2337 Argument KEY is the name of a standard key or a function key.
2338 Argument BINDING is the Emacs function to be bound to <KEY>."
2339 (define-key edt-default-global-map key binding
))
2341 (defun edt-bind-gold-key-default (key gold-binding
)
2342 "Binds <GOLD> key sequences to default bindings in the EDT Emulator.
2343 Argument KEY is the name of a standard key or a function key.
2344 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2345 (define-key 'edt-default-gold-map key gold-binding
))
2348 ;; Functions used to set up USER CUSTOM bindings to EDT emulation functions.
2350 (defun edt-bind-function-key (function-key binding gold-binding
)
2351 "Binds LK-201 function keys to custom bindings in the EDT Emulator.
2352 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2353 Argument BINDING is the Emacs function to be bound to <KEY>.
2354 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2355 (let ((key (cdr (assoc function-key
*EDT-keys
*))))
2356 (if (and key
(not (equal key
"")))
2358 (define-key edt-user-global-map key binding
)
2359 (define-key 'edt-user-gold-map key gold-binding
)))))
2361 (defun edt-bind-key (key binding
)
2362 "Bind standard key sequences to custom bindings in the EDT Emulator.
2363 Argument KEY is the name of a key. It can be a standard key or a function key.
2364 Argument BINDING is the Emacs function to be bound to <KEY>."
2365 (define-key edt-user-global-map key binding
))
2367 ;; For backward compatibility to existing edt-user.el files.
2368 (fset 'edt-bind-standard-key
(symbol-function 'edt-bind-key
))
2370 (defun edt-bind-gold-key (key gold-binding
)
2371 "Binds <GOLD> standard key sequences to custom bindings in the EDT Emulator.
2372 Argument KEY is the name of a standard key or a function key.
2373 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2374 (define-key 'edt-user-gold-map key gold-binding
))
2376 (defun edt-setup-default-bindings ()
2377 "Assigns default EDT Emulation keyboard bindings."
2379 ;; Function Key Bindings: Regular and GOLD.
2381 ;; VT100/VT200/VT300 PF1 (GOLD), PF2, PF3, PF4 Keys
2382 (edt-bind-function-key-default "PF1"
2383 'edt-default-gold-map
'edt-mark-section-wisely
)
2384 (edt-bind-function-key-default "PF2"
2385 'edt-electric-keypad-help
'describe-function
)
2386 (edt-bind-function-key-default "PF3" 'edt-find-next
'edt-find
)
2387 (edt-bind-function-key-default "PF4" 'edt-delete-line
'edt-undelete-line
)
2389 ;; VT100/VT200/VT300 Arrow Keys
2390 (edt-bind-function-key-default "UP" 'edt-previous-line
'edt-window-top
)
2391 (edt-bind-function-key-default "DOWN" 'edt-next-line
'edt-window-bottom
)
2392 (edt-bind-function-key-default "LEFT" 'backward-char
'edt-sentence-backward
)
2393 (edt-bind-function-key-default "RIGHT" 'forward-char
'edt-sentence-forward
)
2395 ;; VT100/VT200/VT300 Keypad Keys
2396 (edt-bind-function-key-default "KP0" 'edt-line
'open-line
)
2397 (edt-bind-function-key-default "KP1" 'edt-word
'edt-change-case
)
2398 (edt-bind-function-key-default "KP2"
2399 'edt-end-of-line
'edt-delete-to-end-of-line
)
2400 (edt-bind-function-key-default "KP3" 'edt-character
'quoted-insert
)
2401 (edt-bind-function-key-default "KP4" 'edt-advance
'edt-bottom
)
2402 (edt-bind-function-key-default "KP5" 'edt-backup
'edt-top
)
2403 (edt-bind-function-key-default "KP6" 'edt-cut
'yank
)
2404 (edt-bind-function-key-default "KP7" 'edt-page
'execute-extended-command
)
2405 (edt-bind-function-key-default "KP8" 'edt-sect
'edt-fill-region
)
2406 (edt-bind-function-key-default "KP9" 'edt-append
'edt-replace
)
2407 (edt-bind-function-key-default "KP-" 'edt-delete-word
'edt-undelete-word
)
2408 (edt-bind-function-key-default "KP,"
2409 'edt-delete-character
'edt-undelete-character
)
2410 (edt-bind-function-key-default "KPP" 'edt-select
'edt-reset
)
2411 (edt-bind-function-key-default "KPE" 'other-window
'edt-substitute
)
2413 ;; VT200/VT300 Function Keys
2414 ;; (F1 through F5, on the VT220, are not programmable, so we skip
2415 ;; making default bindings to those keys.
2416 (edt-bind-function-key-default "FIND" 'edt-find-next
'edt-find
)
2417 (edt-bind-function-key-default "INSERT" 'yank
'edt-key-not-assigned
)
2418 (edt-bind-function-key-default "REMOVE" 'edt-cut
'edt-copy
)
2419 (edt-bind-function-key-default "SELECT"
2420 'edt-toggle-select
'edt-key-not-assigned
)
2421 (edt-bind-function-key-default "NEXT"
2422 'edt-sect-forward
'edt-key-not-assigned
)
2423 (edt-bind-function-key-default "PREVIOUS"
2424 'edt-sect-backward
'edt-key-not-assigned
)
2425 (edt-bind-function-key-default "F6"
2426 'edt-key-not-assigned
'edt-key-not-assigned
)
2427 (edt-bind-function-key-default "F7"
2428 'edt-copy-rectangle
'edt-key-not-assigned
)
2429 (edt-bind-function-key-default "F8"
2430 'edt-cut-rectangle-overstrike-mode
'edt-paste-rectangle-overstrike-mode
)
2431 (edt-bind-function-key-default "F9"
2432 'edt-cut-rectangle-insert-mode
'edt-paste-rectangle-insert-mode
)
2433 (edt-bind-function-key-default "F10" 'edt-cut-rectangle
'edt-paste-rectangle
)
2434 ;; Under X, the F11 key can be bound. If using a VT-200 or higher terminal,
2435 ;; the default emacs terminal support causes the VT F11 key to seem as if it
2436 ;; is an ESC key when in emacs.
2437 (edt-bind-function-key-default "F11"
2438 'edt-key-not-assigned
'edt-key-not-assigned
)
2439 (edt-bind-function-key-default "F12"
2440 'edt-beginning-of-line
'delete-other-windows
) ;BS
2441 (edt-bind-function-key-default "F13"
2442 'edt-delete-to-beginning-of-word
'edt-key-not-assigned
) ;LF
2443 (edt-bind-function-key-default "F14"
2444 'edt-key-not-assigned
'edt-key-not-assigned
)
2445 (edt-bind-function-key-default "HELP"
2446 'edt-electric-keypad-help
'edt-key-not-assigned
)
2447 (edt-bind-function-key-default "DO"
2448 'execute-extended-command
'edt-key-not-assigned
)
2449 (edt-bind-function-key-default "F17"
2450 'edt-key-not-assigned
'edt-key-not-assigned
)
2451 (edt-bind-function-key-default "F18"
2452 'edt-key-not-assigned
'edt-key-not-assigned
)
2453 (edt-bind-function-key-default "F19"
2454 'edt-key-not-assigned
'edt-key-not-assigned
)
2455 (edt-bind-function-key-default "F20"
2456 'edt-key-not-assigned
'edt-key-not-assigned
)
2458 ;; Control key bindings: Regular and GOLD
2460 ;; Standard EDT control key bindings conflict with standard Emacs
2461 ;; control key bindings. Normally, the standard Emacs control key
2462 ;; bindings are left unchanged in the default EDT mode. However, if
2463 ;; the variable edt-use-EDT-control-key-bindings is set to true
2464 ;; before invoking edt-emulation-on for the first time, then the
2465 ;; standard EDT bindings (with some enhancements) as defined here are
2467 (if edt-use-EDT-control-key-bindings
2469 (edt-bind-key-default "\C-a" 'edt-key-not-assigned
)
2470 (edt-bind-key-default "\C-b" 'edt-key-not-assigned
)
2471 ;; Leave binding of C-c to an Emacs prefix key.
2472 (edt-bind-key-default "\C-d" 'edt-key-not-assigned
)
2473 (edt-bind-key-default "\C-e" 'edt-key-not-assigned
)
2474 (edt-bind-key-default "\C-f" 'edt-key-not-assigned
)
2475 ;; Leave binding of C-g to the Emacs keyboard-quit
2476 (edt-bind-key-default "\C-h" 'edt-beginning-of-line
)
2477 (edt-bind-key-default "\C-i" 'edt-tab-insert
)
2478 (edt-bind-key-default "\C-j" 'edt-delete-to-beginning-of-word
)
2479 (edt-bind-key-default "\C-k" 'edt-define-key
)
2480 (edt-bind-gold-key-default "\C-k" 'edt-restore-key
)
2481 (edt-bind-key-default "\C-l" 'edt-form-feed-insert
)
2482 ;; Leave binding of C-m to newline.
2483 (edt-bind-key-default "\C-n" 'edt-set-screen-width-80
)
2484 (edt-bind-key-default "\C-o" 'edt-key-not-assigned
)
2485 (edt-bind-key-default "\C-p" 'edt-key-not-assigned
)
2486 (edt-bind-key-default "\C-q" 'edt-key-not-assigned
)
2487 ;; Leave binding of C-r to isearch-backward.
2488 ;; Leave binding of C-s to isearch-forward.
2489 (edt-bind-key-default "\C-t" 'edt-display-the-time
)
2490 (edt-bind-key-default "\C-u" 'edt-delete-to-beginning-of-line
)
2491 (edt-bind-key-default "\C-v" 'redraw-display
)
2492 (edt-bind-key-default "\C-w" 'edt-set-screen-width-132
)
2493 ;; Leave binding of C-x as original prefix key.
2494 (edt-bind-key-default "\C-y" 'edt-key-not-assigned
)
2495 ;; Leave binding of C-z to suspend-emacs.
2499 ;; GOLD bindings for a few keys.
2500 (edt-bind-gold-key-default "\C-g" 'keyboard-quit
); Just in case.
2501 (edt-bind-gold-key-default "\C-h" 'help-for-help
); Just in case.
2502 (edt-bind-gold-key-default [f1] 'help-for-help)
2503 (edt-bind-gold-key-default [help] 'help-for-help)
2504 (edt-bind-gold-key-default "\C-\\" 'split-window-vertically)
2506 ;; GOLD bindings for regular keys.
2507 (edt-bind-gold-key-default "a" 'edt-key-not-assigned)
2508 (edt-bind-gold-key-default "A" 'edt-key-not-assigned)
2509 (edt-bind-gold-key-default "b" 'buffer-menu)
2510 (edt-bind-gold-key-default "B" 'buffer-menu)
2511 (edt-bind-gold-key-default "c" 'compile)
2512 (edt-bind-gold-key-default "C" 'compile)
2513 (edt-bind-gold-key-default "d" 'delete-window)
2514 (edt-bind-gold-key-default "D" 'delete-window)
2515 (edt-bind-gold-key-default "e" 'edt-exit)
2516 (edt-bind-gold-key-default "E" 'edt-exit)
2517 (edt-bind-gold-key-default "f" 'find-file)
2518 (edt-bind-gold-key-default "F" 'find-file)
2519 (edt-bind-gold-key-default "g" 'find-file-other-window)
2520 (edt-bind-gold-key-default "G" 'find-file-other-window)
2521 (edt-bind-gold-key-default "h" 'edt-electric-keypad-help)
2522 (edt-bind-gold-key-default "H" 'edt-electric-keypad-help)
2523 (edt-bind-gold-key-default "i" 'insert-file)
2524 (edt-bind-gold-key-default "I" 'insert-file)
2525 (edt-bind-gold-key-default "j" 'edt-key-not-assigned)
2526 (edt-bind-gold-key-default "J" 'edt-key-not-assigned)
2527 (edt-bind-gold-key-default "k" 'edt-toggle-capitalization-of-word)
2528 (edt-bind-gold-key-default "K" 'edt-toggle-capitalization-of-word)
2529 (edt-bind-gold-key-default "l" 'edt-lowercase)
2530 (edt-bind-gold-key-default "L" 'edt-lowercase)
2531 (edt-bind-gold-key-default "m" 'save-some-buffers)
2532 (edt-bind-gold-key-default "M" 'save-some-buffers)
2533 (edt-bind-gold-key-default "n" 'next-error)
2534 (edt-bind-gold-key-default "N" 'next-error)
2535 (edt-bind-gold-key-default "o" 'switch-to-buffer-other-window)
2536 (edt-bind-gold-key-default "O" 'switch-to-buffer-other-window)
2537 (edt-bind-gold-key-default "p" 'edt-key-not-assigned)
2538 (edt-bind-gold-key-default "P" 'edt-key-not-assigned)
2539 (edt-bind-gold-key-default "q" 'edt-quit)
2540 (edt-bind-gold-key-default "Q" 'edt-quit)
2541 (edt-bind-gold-key-default "r" 'revert-buffer)
2542 (edt-bind-gold-key-default "R" 'revert-buffer)
2543 (edt-bind-gold-key-default "s" 'save-buffer)
2544 (edt-bind-gold-key-default "S" 'save-buffer)
2545 (edt-bind-gold-key-default "t" 'edt-key-not-assigned)
2546 (edt-bind-gold-key-default "T" 'edt-key-not-assigned)
2547 (edt-bind-gold-key-default "u" 'edt-uppercase)
2548 (edt-bind-gold-key-default "U" 'edt-uppercase)
2549 (edt-bind-gold-key-default "v" 'find-file-other-window)
2550 (edt-bind-gold-key-default "V" 'find-file-other-window)
2551 (edt-bind-gold-key-default "w" 'write-file)
2552 (edt-bind-gold-key-default "W" 'write-file)
2553 (edt-bind-gold-key-default "x" 'edt-key-not-assigned)
2554 (edt-bind-gold-key-default "X" 'edt-key-not-assigned)
2555 (edt-bind-gold-key-default "y" 'edt-emulation-off)
2556 (edt-bind-gold-key-default "Y" 'edt-emulation-off)
2557 (edt-bind-gold-key-default "z" 'edt-switch-global-maps)
2558 (edt-bind-gold-key-default "Z" 'edt-switch-global-maps)
2559 (edt-bind-gold-key-default "1" 'delete-other-windows)
2560 (edt-bind-gold-key-default "!" 'edt-key-not-assigned)
2561 (edt-bind-gold-key-default "2" 'edt-split-window)
2562 (edt-bind-gold-key-default "@" 'edt-key-not-assigned)
2563 (edt-bind-gold-key-default "3" 'edt-key-not-assigned)
2564 (edt-bind-gold-key-default "#" 'edt-key-not-assigned)
2565 (edt-bind-gold-key-default "4" 'edt-key-not-assigned)
2566 (edt-bind-gold-key-default "$" 'edt-key-not-assigned)
2567 (edt-bind-gold-key-default "5" 'edt-key-not-assigned)
2568 (edt-bind-gold-key-default "%" 'edt-goto-percentage)
2569 (edt-bind-gold-key-default "6" 'edt-key-not-assigned)
2570 (edt-bind-gold-key-default "^" 'edt-key-not-assigned)
2571 (edt-bind-gold-key-default "7" 'edt-key-not-assigned)
2572 (edt-bind-gold-key-default "&" 'edt-key-not-assigned)
2573 (edt-bind-gold-key-default "8" 'edt-key-not-assigned)
2574 (edt-bind-gold-key-default "*" 'edt-key-not-assigned)
2575 (edt-bind-gold-key-default "9" 'edt-key-not-assigned)
2576 (edt-bind-gold-key-default "(" 'edt-key-not-assigned)
2577 (edt-bind-gold-key-default "0" 'edt-key-not-assigned)
2578 (edt-bind-gold-key-default ")" 'edt-key-not-assigned)
2579 (edt-bind-gold-key-default " " 'undo)
2580 (edt-bind-gold-key-default "," 'edt-key-not-assigned)
2581 (edt-bind-gold-key-default "<" 'edt-key-not-assigned)
2582 (edt-bind-gold-key-default "." 'edt-key-not-assigned)
2583 (edt-bind-gold-key-default ">" 'edt-key-not-assigned)
2584 (edt-bind-gold-key-default "/" 'query-replace)
2585 (edt-bind-gold-key-default "?" 'edt-key-not-assigned)
2586 (edt-bind-gold-key-default "\\" 'edt-key-not-assigned)
2587 (edt-bind-gold-key-default "|" 'edt-key-not-assigned)
2588 (edt-bind-gold-key-default ";" 'edt-key-not-assigned)
2589 (edt-bind-gold-key-default ":" 'edt-key-not-assigned)
2590 (edt-bind-gold-key-default "'" 'edt-key-not-assigned)
2591 (edt-bind-gold-key-default "\"" 'edt-key-not-assigned)
2592 (edt-bind-gold-key-default "-" 'edt-key-not-assigned)
2593 (edt-bind-gold-key-default "_" 'edt-key-not-assigned)
2594 (edt-bind-gold-key-default "=" 'goto-line)
2595 (edt-bind-gold-key-default "+" 'edt-key-not-assigned)
2596 (edt-bind-gold-key-default "[" 'edt-key-not-assigned)
2597 (edt-bind-gold-key-default "{" 'edt-key-not-assigned)
2598 (edt-bind-gold-key-default "]" 'edt-key-not-assigned)
2599 (edt-bind-gold-key-default "}" 'edt-key-not-assigned)
2600 (edt-bind-gold-key-default "`" 'what-line)
2601 (edt-bind-gold-key-default "~" 'edt-key-not-assigned)
2605 ;;; DEFAULT EDT KEYPAD HELP
2609 ;;; Upper case commands in the keypad diagram below indicate that the
2610 ;;; emulation should look and feel very much like EDT. Lower case
2611 ;;; commands are enhancements and/or additions to the EDT keypad
2612 ;;; commands or are native Emacs commands.
2615 (defun edt-keypad-help ()
2616 "DEFAULT EDT Keypad Active.
2618 F7: Copy Rectangle +----------+----------+----------+----------+
2619 F8: Cut Rect Overstrike |Prev Line |Next Line |Bkwd Char |Frwd Char |
2620 G-F8: Paste Rect Overstrike | (UP) | (DOWN) | (LEFT) | (RIGHT) |
2621 F9: Cut Rect Insert |Window Top|Window Bot|Bkwd Sent |Frwd Sent |
2622 G-F9: Paste Rect Insert +----------+----------+----------+----------+
2624 G-F10: Paste Rectangle
2626 F12: Begining of Line +----------+----------+----------+----------+
2627 G-F12: Delete Other Windows | GOLD | HELP | FNDNXT | DEL L |
2628 F13: Delete to Begin of Word | (PF1) | (PF2) | (PF3) | (PF4) |
2629 HELP: Keypad Help |Mark Wisel|Desc Funct| FIND | UND L |
2630 G-HELP: Emacs Help +----------+----------+----------+----------+
2631 DO: Execute extended command | PAGE | SECT | APPEND | DEL W |
2632 C-g: Keyboard Quit | (7) | (8) | (9) | (-) |
2633 G-C-g: Keyboard Quit |Ex Ext Cmd|Fill Regio| REPLACE | UND W |
2634 C-h: Beginning of Line +----------+----------+----------+----------+
2635 G-C-h: Emacs Help | ADVANCE | BACKUP | CUT | DEL C |
2636 C-i: Tab Insert | (4) | (5) | (6) | (,) |
2637 C-j: Delete to Begin of Word | BOTTOM | TOP | Yank | UND C |
2638 C-k: Define Key +----------+----------+----------+----------+
2639 G-C-k: Restore Key | WORD | EOL | CHAR | Next |
2640 C-l: Form Feed Insert | (1) | (2) | (3) | Window |
2641 C-n: Set Screen Width 80 | CHNGCASE | DEL EOL |Quoted Ins| !
2642 C-r: Isearch Backward +---------------------+----------+ (ENTER) |
2643 C-s: Isearch Forward | LINE | SELECT | !
2644 C-t: Display the Time | (0) | (.) | SUBS |
2645 C-u: Delete to Begin of Line | Open Line | RESET | |
2646 C-v: Redraw Display +---------------------+----------+----------+
2647 C-w: Set Screen Width 132
2648 C-z: Suspend Emacs +----------+----------+----------+
2649 G-C-\\: Split Window | FNDNXT | Yank | CUT |
2650 | (FIND) | (INSERT) | (REMOVE) |
2651 G-b: Buffer Menu | FIND | | COPY |
2652 G-c: Compile +----------+----------+----------+
2653 G-d: Delete Window |SELECT/RES|SECT BACKW|SECT FORWA|
2654 G-e: Exit | (SELECT) |(PREVIOUS)| (NEXT) |
2655 G-f: Find File | | | |
2656 G-g: Find File Other Window +----------+----------+----------+
2659 G-k: Toggle Capitalization Word
2660 G-l: Downcase Region
2661 G-m: Save Some Buffers
2663 G-o: Switch to Next Window
2668 G-v: Find File Other Window
2670 G-y: EDT Emulation OFF
2671 G-z: Switch to User EDT Key Bindings
2672 G-1: Delete Other Windows
2674 G-%: Go to Percentage
2675 G- : Undo (GOLD Spacebar)
2681 (describe-function 'edt-keypad-help))
2683 (defun edt-electric-helpify (fun)
2684 (let ((name "*Help*"))
2685 (if (save-window-excursion
2686 (let* ((p (symbol-function 'print-help-return-message))
2687 (b (get-buffer name))
2688 (m (buffer-modified-p b)))
2689 (and b (not (get-buffer-window b))
2693 (message "%s..." (capitalize (symbol-name fun)))
2697 (set-buffer-modified-p t)))
2698 (fset 'print-help-return-message 'ignore)
2699 (call-interactively fun)
2700 (and (get-buffer name)
2701 (get-buffer-window (get-buffer name))
2703 (not (eq b (get-buffer name)))
2704 (not (buffer-modified-p b)))))
2705 (fset 'print-help-return-message p)
2706 (and b (buffer-name b)
2709 (set-buffer-modified-p m))))))
2710 (with-electric-help 'delete-other-windows name t))))
2712 (defun edt-electric-keypad-help ()
2713 "Display default EDT bindings."
2715 (edt-electric-helpify 'edt-keypad-help))
2717 (defun edt-electric-user-keypad-help ()
2718 "Display user custom EDT bindings."
2720 (edt-electric-helpify 'edt-user-keypad-help))
2723 ;;; EDT emulation screen width commands.
2725 ;; Some terminals require modification of terminal attributes when
2726 ;; changing the number of columns displayed, hence the fboundp tests
2727 ;; below. These functions are defined in the corresponding terminal
2728 ;; specific file, if needed.
2730 (defun edt-set-screen-width-80 ()
2731 "Set screen width to 80 columns."
2733 (if (fboundp 'edt-set-term-width-80)
2734 (edt-set-term-width-80))
2735 (set-frame-width nil 80)
2736 (message "Terminal width 80"))
2738 (defun edt-set-screen-width-132 ()
2739 "Set screen width to 132 columns."
2741 (if (fboundp 'edt-set-term-width-132)
2742 (edt-set-term-width-132))
2743 (set-frame-width nil 132)
2744 (message "Terminal width 132"))
2748 ;;; edt.el ends here