* lisp/vc/vc.el (vc-region-history): log-view-vc-fileset holds a list!
[emacs.git] / lisp / emulation / edt.el
blob179791b529c51b3739c47bc38cfba996c0de80e6
1 ;;; edt.el --- enhanced EDT keypad mode emulation for GNU Emacs
3 ;; Copyright (C) 1986, 1992-1995, 2000-2018 Free Software Foundation,
4 ;; Inc.
6 ;; Author: Kevin Gallagher <kevin.gal@verizon.net>
7 ;; Maintainer: Kevin Gallagher <kevin.gal@verizon.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 by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
27 ;;; Commentary:
30 ;; This is Version 4.0 of the EDT Emulation for Emacs.
31 ;; It comes with special functions which replicate nearly all of EDT's
32 ;; keypad mode behavior. It sets up default keypad and function key
33 ;; bindings which closely match those found in EDT. Support is
34 ;; provided so that users may reconfigure most keypad and function key
35 ;; bindings to their own liking.
37 ;; NOTE: Version 4.0 contains several enhancements. See the
38 ;; Enhancement section below for the details.
40 ;; Getting Started:
42 ;; To start the EDT Emulation, first start Emacs and then enter
44 ;; M-x edt-emulation-on
46 ;; to begin the emulation. After initialization is complete, the
47 ;; following message will appear below the status line informing you
48 ;; that the emulation has been enabled: "Default EDT keymap active".
50 ;; You can have the EDT Emulation start up automatically, each time
51 ;; you initiate a GNU Emacs session, by adding the following line to
52 ;; your init file:
54 ;; (add-hook 'emacs-startup-hook 'edt-emulation-on)
56 ;; IMPORTANT: Be sure to read the Info node `edt' for more details.
57 ;; It contains very helpful user information.
59 ;; The EDT emulation consists of the following files:
61 ;; edt.texi - User manual
62 ;; edt-user.el - Sample Customization File (located in Emacs
63 ;; distribution etc directory)
64 ;; edt.el - EDT Emulation Functions and Default Configuration
65 ;; edt-lk201.el - Built-in support for DEC LK-201 Keyboards
66 ;; edt-vt100.el - Built-in support for DEC VT-100 (and above) terminals
67 ;; edt-pc.el - Built-in support for PC 101 Keyboards under MS-DOS
68 ;; edt-mapper.el - Create an EDT LK-201 Map File for Keyboards Without
69 ;; Built-in Support
71 ;; Enhancements:
73 ;; Version 4.0 contains the following enhancements:
75 ;; 1. Scroll margins at the top and bottom of the window are now
76 ;; supported. (The design was copied from tpu-extras.el.) By
77 ;; default, this feature is enabled, with the top margin set to
78 ;; 10% of the window and the bottom margin set to 15% of the
79 ;; window. To change these settings, you can invoke the function
80 ;; edt-set-scroll-margins in your init file. For example, the
81 ;; following line
83 ;; (edt-set-scroll-margins "20%" "25%")
85 ;; sets the top margin to 20% of the window and the bottom margin
86 ;; to 25% of the window. To disable this feature, set each
87 ;; margin to 0%. You can also invoke edt-set-scroll-margins
88 ;; interactively while EDT Emulation is active to change the
89 ;; settings for that session.
91 ;; NOTE: Another way to set the scroll margins is to use the
92 ;; Emacs customization feature to set the following two variables
93 ;; 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.
108 ;; See Info node `edt' for more details.
110 ;; 3. EDT Emulation now also works in XEmacs, including the
111 ;; highlighting of selected text.
113 ;; 4. If you access a workstation using an X Server, observe that
114 ;; the initialization file generated by edt-mapper.el will now
115 ;; contain the name of the X Server vendor. This is a
116 ;; convenience for those who have access to their Unix account
117 ;; from more than one type of X Server. Since different X
118 ;; Servers typically require different EDT emulation
119 ;; initialization files, edt-mapper.el will now generate these
120 ;; different initialization files and save them with different
121 ;; names. Then, the correct initialization file for the
122 ;; particular X server in use is loaded correctly automatically.
124 ;; 5. Also, edt-mapper.el is now capable of binding an ASCII key
125 ;; sequence, providing the ASCII key sequence prefix is already
126 ;; known by Emacs to be a prefix. As a result of providing this
127 ;; support, some terminal/keyboard/window system configurations,
128 ;; which don't have a complete set of sensible function key
129 ;; bindings built into Emacs in `function-key-map', can still be
130 ;; configured for use with EDT Emulation. (Note: In a few rare
131 ;; circumstances this does not work properly. In particular, it
132 ;; does not work if a subset of the leading ASCII characters in a
133 ;; key sequence are recognized by Emacs as having an existing
134 ;; binding. For example, if the keypad 7 (KP-7) key generates
135 ;; the sequence \"<ESC>Ow\" and \"<ESC>O\" is already bound to a
136 ;; function, pressing KP-7 when told to do so by edt-mapper.el
137 ;; will result in edt-mapper.el incorrectly mapping \"<ESC>O\" to
138 ;; KP-7 and \"w\" to KP-8. If something like this happens to
139 ;; you, it is probably a bug in the support for your keyboard
140 ;; within Emacs OR a bug in the Unix termcap/terminfo support for
141 ;; your terminal OR a bug in the terminal emulation software you
142 ;; are using.)
144 ;; 6. The edt-quit function (bound to GOLD-q by default) has been
145 ;; modified to warn the user when file-related buffer
146 ;; modifications exist. It now cautions the user that those
147 ;; modifications will be lost if the user quits without saving
148 ;; those buffers.
151 ;;; History:
153 ;; Version 4.0 2000 Added New Features and Fixed a Few Bugs
157 ;;; Code:
159 ;;; Electric Help functions are used for keypad help displays. A few
160 ;;; picture functions are used in rectangular cut and paste commands.
162 (require 'ehelp)
163 (require 'picture)
165 ;;;;
166 ;;;; VARIABLES and CONSTANTS
167 ;;;;
169 (defgroup edt nil
170 "Emacs emulating EDT."
171 :prefix "edt-"
172 :group 'emulations)
174 ;; To silence the byte-compiler
175 (defvar *EDT-keys*)
176 (defvar edt-default-global-map)
177 (defvar edt-last-copied-word)
178 (defvar edt-learn-macro-count)
179 (defvar edt-orig-page-delimiter)
180 (defvar edt-orig-transient-mark-mode)
181 (defvar edt-rect-start-point)
182 (defvar edt-user-global-map)
183 (defvar rect-start-point)
184 (defvar time-string)
185 (defvar zmacs-region-stays)
188 ;;; Version Information
190 (defconst edt-version "4.0" "EDT Emulation version number.")
193 ;;; User Configurable Variables
196 (defcustom edt-keep-current-page-delimiter nil
197 "Emacs MUST be restarted for a change in value to take effect!
198 Non-nil leaves Emacs value of `page-delimiter' unchanged within EDT
199 Emulation. If set to nil (the default), the `page-delimiter' variable
200 is set to \"\\f\" when edt-emulation-on is first invoked. This
201 setting replicates EDT's page delimiter behavior. The original value
202 is restored when edt-emulation-off is called."
203 :type 'boolean
204 :group 'edt)
206 (defcustom edt-use-EDT-control-key-bindings nil
207 "Emacs MUST be restarted for a change in value to take effect!
208 Non-nil causes the control key bindings to be replaced with EDT
209 bindings. If set to nil (the default), EDT control key bindings are
210 not used and the current Emacs control key bindings are retained for
211 use within the EDT emulation."
212 :type 'boolean
213 :group 'edt)
215 (defcustom edt-word-entities '(?\t)
216 "Specifies the list of EDT word entity characters.
217 The default list, (?\\t), contains just the TAB character, which
218 emulates EDT. Characters are specified in the list using their
219 decimal ASCII values. A question mark, followed by the actual
220 character, can be used to indicate the numerical value of the
221 character, instead of the actual decimal value. So, ?A means the
222 numerical value for the letter A, ?/ means the numerical value for /,
223 etc. Several unprintable and special characters have special
224 representations, which you can also use:
226 ?\\b specifies BS, C-h
227 ?\\t specifies TAB, C-i
228 ?\\n specifies LFD, C-j
229 ?\\v specifies VTAB, C-k
230 ?\\f specifies FF, C-l
231 ?\\r specifies CR, C-m
232 ?\\e specifies ESC, C-[
233 ?\\\\ specifies \\
235 In EDT Emulation movement-by-word commands, each character in the list
236 will be treated as if it were a separate word."
237 :type '(repeat integer)
238 :group 'edt)
240 (defcustom edt-top-scroll-margin 10
241 "Scroll margin at the top of the screen.
242 Interpreted as a percent of the current window size with a default
243 setting of 10%. If set to 0, top scroll margin is disabled."
244 :type 'integer
245 :group 'edt)
247 (defcustom edt-bottom-scroll-margin 15
248 "Scroll margin at the bottom of the screen.
249 Interpreted as a percent of the current window size with a default
250 setting of 15%. If set to 0, bottom scroll margin is disabled."
251 :type 'integer
252 :group 'edt)
255 ;;; Internal Variables
258 (defvar edt-last-deleted-lines ""
259 "Last text deleted by the EDT emulation DEL L command.")
261 (defvar edt-last-deleted-words ""
262 "Last text deleted by the EDT emulation DEL W command.")
264 (defvar edt-last-deleted-chars ""
265 "Last text deleted by the EDT emulation DEL C command.")
267 (defvar edt-find-last-text ""
268 "Last text found by the EDT emulation FIND command.")
270 (defvar edt-match-beginning-mark (make-marker)
271 "Used internally by the EDT emulation SUBS command.")
273 (defvar edt-match-end-mark (make-marker)
274 "Used internally by the EDT emulation SUBS command.")
276 (defvar edt-last-replaced-key-definition nil
277 "Key definition replaced with `edt-define-key' or `edt-learn' command.")
279 (defvar edt-direction-string ""
280 "String indicating current direction of movement.")
282 (defvar edt-select-mode nil
283 "Non-nil means select mode is active.")
285 (defvar edt-select-mode-current ""
286 "Text displayed in mode line to indicate the state of EDT select mode.
287 When select mode is inactive, it is set to an empty string.")
289 (defconst edt-select-mode-string " Select"
290 "Used in mode line to indicate select mode is active.")
292 (defconst edt-forward-string " ADVANCE"
293 "Direction string in mode line to indicate forward movement.")
295 (defconst edt-backward-string " BACKUP"
296 "Direction string in mode line to indicate backward movement.")
298 (defvar edt-default-map-active nil
299 "Non-nil indicates that default EDT emulation key bindings are active.
300 nil means user-defined custom bindings are active.")
302 (defvar edt-user-map-configured nil
303 "Non-nil indicates that user custom EDT key bindings are configured.
304 This means that an edt-user.el file was found in the user's `load-path'.")
306 (defvar edt-term nil
307 "Specifies the terminal type, if applicable.")
310 ;;; Emacs version identifiers - currently referenced by
312 ;;; o edt-emulation-on o edt-load-keys
314 (defconst edt-emacs-variant (if (featurep 'emacs) "gnu" "xemacs")
315 "Indicates Emacs variant: GNU Emacs or XEmacs (aka Lucid Emacs).")
317 (defconst edt-window-system (if (featurep 'emacs) window-system (console-type))
318 "Indicates window system (in GNU Emacs) or console type (in XEmacs).")
320 (declare-function x-server-vendor "xfns.c" (&optional terminal))
322 (defconst edt-xserver (when (eq edt-window-system 'x)
323 ;; The Cygwin window manager has a `/' in its
324 ;; name, which breaks the generated file name of
325 ;; the custom key map file. Replace `/' with a
326 ;; `-' to work around that.
327 (if (featurep 'xemacs)
328 (replace-in-string (x-server-vendor) "[ /]" "-")
329 (replace-regexp-in-string "[ /]" "-"
330 (x-server-vendor))))
331 "Indicates X server vendor name, if applicable.")
333 (defvar edt-keys-file nil
334 "User's custom keypad and function keys mappings to emulate LK-201 keyboard.")
336 (defvar edt-last-copied-word nil
337 "Last word that the user copied.")
340 ;;;;
341 ;;;; EDT Emulation Commands
342 ;;;;
344 ;;; Almost all of EDT's keypad mode commands have equivalent Emacs
345 ;;; function counterparts. But many of these counterparts behave
346 ;;; somewhat differently in Emacs.
348 ;;; So, the following Emacs functions emulate, where practical, the
349 ;;; exact behavior of the corresponding EDT keypad mode commands. In
350 ;;; a few cases, the emulation is not exact, but it should be close
351 ;;; enough for most EDT die-hards.
355 ;;; PAGE
357 ;;; Emacs uses the regexp assigned to page-delimiter to determine what
358 ;;; marks a page break. This is normally "^\f", which causes the
359 ;;; edt-page command to ignore form feeds not located at the beginning
360 ;;; of a line. To emulate the EDT PAGE command exactly,
361 ;;; page-delimiter is set to "\f" when EDT emulation is turned on, and
362 ;;; restored to its original value when EDT emulation is turned off.
363 ;;; But this can be overridden if the EDT definition is not desired by
364 ;;; placing
366 ;;; (setq edt-keep-current-page-delimiter t)
368 ;;; in your init file.
370 (defun edt-page-forward (num)
371 "Move forward to just after next page delimiter.
372 Argument NUM is the number of page delimiters to move."
373 (interactive "p")
374 (edt-check-prefix num)
375 (if (eobp)
376 (error "End of buffer")
377 (progn
378 (forward-page num)
379 (if (eobp)
380 (edt-line-to-bottom-of-window)
381 (edt-line-to-top-of-window)))))
383 (defun edt-page-backward (num)
384 "Move backward to just after previous page delimiter.
385 Argument NUM is the number of page delimiters to move."
386 (interactive "p")
387 (edt-check-prefix num)
388 (if (bobp)
389 (error "Beginning of buffer")
390 (progn
391 (backward-page num)
392 (edt-line-to-top-of-window)
393 (if (featurep 'xemacs) (setq zmacs-region-stays t)))))
395 (defun edt-page (num)
396 "Move in current direction to next page delimiter.
397 Argument NUM is the number of page delimiters to move."
398 (interactive "p")
399 (if (equal edt-direction-string edt-forward-string)
400 (edt-page-forward num)
401 (edt-page-backward num)))
404 ;;; SECT
406 ;;; EDT defaults a section size to be 16 lines of its one and only
407 ;;; 24-line window. That's two-thirds of the window at a time. The
408 ;;; EDT SECT commands moves the cursor, not the window.
410 ;;; This emulation of EDT's SECT moves the cursor approximately
411 ;;; two-thirds of the current window at a time.
413 (defun edt-sect-forward (num)
414 "Move cursor forward two-thirds of a window's number of lines.
415 Argument NUM is the number of sections to move."
416 (interactive "p")
417 (edt-check-prefix num)
418 (edt-line-forward (* (* (/ (- (window-height) 1) 3) 2) num)))
421 (defun edt-sect-backward (num)
422 "Move cursor backward two-thirds of a window.
423 Argument NUM is the number of sections to move."
424 (interactive "p")
425 (edt-check-prefix num)
426 (edt-line-backward (* (* (/ (- (window-height) 1) 3) 2) num)))
428 (defun edt-sect (num)
429 "Move in current direction a full window.
430 Argument NUM is the number of sections to move."
431 (interactive "p")
432 (if (equal edt-direction-string edt-forward-string)
433 (edt-sect-forward num)
434 (edt-sect-backward num)))
437 ;;; BEGINNING OF LINE
439 ;;; EDT's beginning-of-line command is not affected by current
440 ;;; direction, for some unknown reason.
442 (defun edt-beginning-of-line (num)
443 "Move backward to next beginning of line mark.
444 Argument NUM is the number of BOL marks to move."
445 (interactive "p")
446 (edt-check-prefix num)
447 (let ((beg (edt-current-line)))
448 (if (bolp)
449 (forward-line (* -1 num))
450 (progn
451 (setq num (1- num))
452 (forward-line (* -1 num))))
453 (edt-top-check beg num))
454 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
458 ;;; EOL (End of Line)
461 (defun edt-end-of-line-forward (num)
462 "Move forward to next end of line mark.
463 Argument NUM is the number of EOL marks to move."
464 (interactive "p")
465 (edt-check-prefix num)
466 (let ((beg (edt-current-line)))
467 (forward-char)
468 (end-of-line num)
469 (edt-bottom-check beg num))
470 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
473 (defun edt-end-of-line-backward (num)
474 "Move backward to next end of line mark.
475 Argument NUM is the number of EOL marks to move."
476 (interactive "p")
477 (edt-check-prefix num)
478 (let ((beg (edt-current-line)))
479 (end-of-line (1- num))
480 (edt-top-check beg num))
481 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
484 (defun edt-end-of-line (num)
485 "Move in current direction to next end of line mark.
486 Argument NUM is the number of EOL marks to move."
487 (interactive "p")
488 (if (equal edt-direction-string edt-forward-string)
489 (edt-end-of-line-forward num)
490 (edt-end-of-line-backward num)))
493 ;;; WORD
495 ;;; This one is a tad messy. To emulate EDT's behavior everywhere in
496 ;;; the file (beginning of file, end of file, beginning of line, end
497 ;;; of line, etc.) it takes a bit of special handling.
499 ;;; The variable edt-word-entities contains a list of characters which
500 ;;; are to be viewed as distinct words wherever they appear in the
501 ;;; buffer. This emulates the EDT line mode command SET ENTITY WORD.
504 (defun edt-one-word-forward ()
505 "Move forward to first character of next word."
506 (interactive)
507 (if (eobp)
508 (error "End of buffer"))
509 (if (eolp)
510 (forward-char)
511 (progn
512 (if (memq (following-char) edt-word-entities)
513 (forward-char)
514 (while (and
515 (not (eolp))
516 (not (eobp))
517 (not (eq ?\ (char-syntax (following-char))))
518 (not (memq (following-char) edt-word-entities)))
519 (forward-char)))
520 (while (and
521 (not (eolp))
522 (not (eobp))
523 (eq ?\ (char-syntax (following-char)))
524 (not (memq (following-char) edt-word-entities)))
525 (forward-char))))
526 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
528 (defun edt-one-word-backward ()
529 "Move backward to first character of previous word."
530 (interactive)
531 (if (bobp)
532 (error "Beginning of buffer"))
533 (if (bolp)
534 (backward-char)
535 (progn
536 (backward-char)
537 (while (and
538 (not (bolp))
539 (not (bobp))
540 (eq ?\ (char-syntax (following-char)))
541 (not (memq (following-char) edt-word-entities)))
542 (backward-char))
543 (if (not (memq (following-char) edt-word-entities))
544 (while (and
545 (not (bolp))
546 (not (bobp))
547 (not (eq ?\ (char-syntax (preceding-char))))
548 (not (memq (preceding-char) edt-word-entities)))
549 (backward-char)))))
550 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
552 (defun edt-word-forward (num)
553 "Move forward to first character of next word.
554 Argument NUM is the number of words to move."
555 (interactive "p")
556 (edt-check-prefix num)
557 (while (> num 0)
558 (edt-one-word-forward)
559 (setq num (1- num))))
561 (defun edt-word-backward (num)
562 "Move backward to first character of previous word.
563 Argument NUM is the number of words to move."
564 (interactive "p")
565 (edt-check-prefix num)
566 (while (> num 0)
567 (edt-one-word-backward)
568 (setq num (1- num))))
570 (defun edt-word (num)
571 "Move in current direction to first character of next word.
572 Argument NUM is the number of words to move."
573 (interactive "p")
574 (if (equal edt-direction-string edt-forward-string)
575 (edt-word-forward num)
576 (edt-word-backward num)))
579 ;;; CHAR
582 (defun edt-character (num)
583 "Move in current direction to next character.
584 Argument NUM is the number of characters to move."
585 (interactive "p")
586 (edt-check-prefix num)
587 (if (equal edt-direction-string edt-forward-string)
588 (forward-char num)
589 (backward-char num))
590 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
593 ;;; LINE
595 ;;; When direction is set to BACKUP, LINE behaves just like BEGINNING
596 ;;; OF LINE in EDT. So edt-line-backward is not really needed as a
597 ;;; separate function.
599 (defun edt-line-backward (num)
600 "Move backward to next beginning of line mark.
601 Argument NUM is the number of BOL marks to move."
602 (interactive "p")
603 (edt-beginning-of-line num))
605 (defun edt-line-forward (num)
606 "Move forward to next beginning of line mark.
607 Argument NUM is the number of BOL marks to move."
608 (interactive "p")
609 (edt-check-prefix num)
610 (let ((beg (edt-current-line)))
611 (forward-line num)
612 (edt-bottom-check beg num))
613 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
615 (defun edt-line (num)
616 "Move in current direction to next beginning of line mark.
617 Argument NUM is the number of BOL marks to move."
618 (interactive "p")
619 (if (equal edt-direction-string edt-forward-string)
620 (edt-line-forward num)
621 (edt-line-backward num)))
624 ;;; UP and DOWN Arrows
627 (defun edt-next-line (num)
628 "Move cursor down one line.
629 Argument NUM is the number of lines to move."
630 (interactive "p")
631 (edt-check-prefix num)
632 (let ((beg (edt-current-line)))
633 ;; We're deliberately using next-line instead of forward-line.
634 (with-no-warnings (next-line num))
635 (edt-bottom-check beg num))
636 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
638 (defun edt-previous-line (num)
639 "Move cursor up one line.
640 Argument NUM is the number of lines to move."
641 (interactive "p")
642 (edt-check-prefix num)
643 (let ((beg (edt-current-line)))
644 ;; We're deliberately using previous-line instead of forward-line.
645 (with-no-warnings (previous-line num))
646 (edt-top-check beg num))
647 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
651 ;;; TOP
654 (defun edt-top ()
655 "Move cursor to the beginning of buffer."
656 (interactive)
657 (goto-char (point-min))
658 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
661 ;;; BOTTOM
664 (defun edt-bottom ()
665 "Move cursor to the end of buffer."
666 (interactive)
667 (goto-char (point-max))
668 (edt-line-to-bottom-of-window))
670 (defmacro edt-with-position (&rest body)
671 "Execute BODY with some position-related variables bound."
672 `(let* ((left nil)
673 (beg (edt-current-line))
674 (height (window-height))
675 (top-percent
676 (if (zerop edt-top-scroll-margin) 10 edt-top-scroll-margin))
677 (bottom-percent
678 (if (zerop edt-bottom-scroll-margin) 15 edt-bottom-scroll-margin))
679 (top-margin (/ (* height top-percent) 100))
680 (bottom-up-margin (1+ (/ (* height bottom-percent) 100)))
681 (bottom-margin (max beg (- height bottom-up-margin 1)))
682 (top (save-excursion (move-to-window-line top-margin) (point)))
683 (bottom (save-excursion (move-to-window-line bottom-margin) (point)))
684 (far (save-excursion
685 (goto-char bottom)
686 (point-at-bol (1- height)))))
687 ,@body))
690 ;;; FIND
693 (defun edt-find-forward (&optional find)
694 "Find first occurrence of a string in forward direction and save it.
695 Optional argument FIND is t is this function is called from `edt-find'."
696 (interactive)
697 (or find
698 (setq edt-find-last-text (read-string "Search forward: ")))
699 (edt-with-position
700 (when (search-forward edt-find-last-text) ; FIXME noerror?
701 (search-backward edt-find-last-text)
702 (edt-set-match)
703 (if (> (point) far)
704 (if (zerop (setq left (save-excursion (forward-line height))))
705 (recenter top-margin)
706 (recenter (- left bottom-up-margin)))
707 (and (> (point) bottom) (recenter bottom-margin)))))
708 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
710 (defun edt-find-backward (&optional find)
711 "Find first occurrence of a string in the backward direction and save it.
712 Optional argument FIND is t if this function is called from `edt-find'."
713 (interactive)
714 (or find
715 (setq edt-find-last-text (read-string "Search backward: ")))
716 (edt-with-position
717 (if (search-backward edt-find-last-text)
718 (edt-set-match))
719 (and (< (point) top) (recenter (min beg top-margin))))
720 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
722 (defun edt-find ()
723 "Find first occurrence of string in current direction and save it."
724 (interactive)
725 (set 'edt-find-last-text (read-string "Search: "))
726 (if (equal edt-direction-string edt-forward-string)
727 (edt-find-forward t)
728 (edt-find-backward t)))
732 ;;; FNDNXT
735 (defun edt-find-next-forward ()
736 "Find next occurrence of a string in forward direction."
737 (interactive)
738 (edt-with-position
739 (forward-char 1)
740 (if (search-forward edt-find-last-text nil t)
741 (progn
742 (search-backward edt-find-last-text)
743 (edt-set-match)
744 (if (> (point) far)
745 (if (zerop (setq left (save-excursion (forward-line height))))
746 (recenter top-margin)
747 (recenter (- left bottom-up-margin)))
748 (and (> (point) bottom) (recenter bottom-margin))))
749 (backward-char 1)
750 (error "Search failed: \"%s\"" edt-find-last-text)))
751 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
753 (defun edt-find-next-backward ()
754 "Find next occurrence of a string in backward direction."
755 (interactive)
756 (edt-with-position
757 (if (not (search-backward edt-find-last-text nil t))
758 (error "Search failed: \"%s\"" edt-find-last-text)
759 (edt-set-match)
760 (and (< (point) top) (recenter (min beg top-margin)))))
761 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
763 (defun edt-find-next ()
764 "Find next occurrence of a string in current direction."
765 (interactive)
766 (if (equal edt-direction-string edt-forward-string)
767 (edt-find-next-forward)
768 (edt-find-next-backward)))
771 ;;; APPEND
774 (defun edt-append ()
775 "Append this kill region to last killed region."
776 (interactive "*")
777 (edt-check-selection)
778 (append-next-kill)
779 (kill-region (mark) (point))
780 (message "Selected text APPENDED to kill ring"))
783 ;;; DEL L
786 (defun edt-delete-line (num)
787 "Delete from cursor up to and including the end of line mark.
788 Argument NUM is the number of lines to delete."
789 (interactive "*p")
790 (edt-check-prefix num)
791 (let ((beg (point)))
792 (forward-line num)
793 (if (not (eq (preceding-char) ?\n))
794 (insert "\n"))
795 (setq edt-last-deleted-lines
796 (buffer-substring beg (point)))
797 (delete-region beg (point))))
800 ;;; DEL EOL
803 (defun edt-delete-to-end-of-line (num)
804 "Delete from cursor up to but excluding the end of line mark.
805 Argument NUM is the number of lines to delete."
806 (interactive "*p")
807 (edt-check-prefix num)
808 (let ((beg (point)))
809 (forward-char 1)
810 (end-of-line num)
811 (setq edt-last-deleted-lines
812 (buffer-substring beg (point)))
813 (delete-region beg (point))))
816 ;;; SELECT
819 (defun edt-select-mode (arg)
820 "Turn EDT select mode off if ARG is nil; otherwise, turn EDT select mode on.
821 In select mode, selected text is highlighted."
822 (if arg
823 (progn
824 (set (make-local-variable 'edt-select-mode) 'edt-select-mode-current)
825 (setq rect-start-point (window-point)))
826 (progn
827 (kill-local-variable 'edt-select-mode)))
828 (force-mode-line-update))
830 (defun edt-select ()
831 "Set mark at cursor and start text selection."
832 (interactive)
833 (set-mark-command nil))
835 (defun edt-reset ()
836 "Cancel text selection."
837 (interactive)
838 (if (featurep 'emacs)
839 (deactivate-mark)
840 (zmacs-deactivate-region)))
843 ;;; CUT
846 (defun edt-cut ()
847 "Deletes selected text but copies to kill ring."
848 (interactive "*")
849 (edt-check-selection)
850 (kill-region (mark) (point))
851 (message "Selected text CUT to kill ring"))
854 ;;; DELETE TO BEGINNING OF LINE
857 (defun edt-delete-to-beginning-of-line (num)
858 "Delete from cursor to beginning of line.
859 Argument NUM is the number of lines to delete."
860 (interactive "*p")
861 (edt-check-prefix num)
862 (let ((beg (point)))
863 (edt-beginning-of-line num)
864 (setq edt-last-deleted-lines
865 (buffer-substring (point) beg))
866 (delete-region beg (point))))
869 ;;; DEL W
872 (defun edt-delete-word (num)
873 "Delete from cursor up to but excluding first character of next word.
874 Argument NUM is the number of words to delete."
875 (interactive "*p")
876 (edt-check-prefix num)
877 (let ((beg (point)))
878 (edt-word-forward num)
879 (setq edt-last-deleted-words (buffer-substring beg (point)))
880 (delete-region beg (point))))
883 ;;; DELETE TO BEGINNING OF WORD
886 (defun edt-delete-to-beginning-of-word (num)
887 "Delete from cursor to beginning of word.
888 Argument NUM is the number of words to delete."
889 (interactive "*p")
890 (edt-check-prefix num)
891 (let ((beg (point)))
892 (edt-word-backward num)
893 (setq edt-last-deleted-words (buffer-substring (point) beg))
894 (delete-region beg (point))))
897 ;;; DEL C
900 (defun edt-delete-character (num)
901 "Delete character under cursor.
902 Argument NUM is the number of characters to delete."
903 (interactive "*p")
904 (edt-check-prefix num)
905 (setq edt-last-deleted-chars
906 (buffer-substring (point) (min (point-max) (+ (point) num))))
907 (delete-region (point) (min (point-max) (+ (point) num))))
910 ;;; DELETE CHAR
913 (defun edt-delete-previous-character (num)
914 "Delete character in front of cursor.
915 Argument NUM is the number of characters to delete."
916 (interactive "*p")
917 (edt-check-prefix num)
918 (setq edt-last-deleted-chars
919 (buffer-substring (max (point-min) (- (point) num)) (point)))
920 (delete-region (max (point-min) (- (point) num)) (point)))
923 ;;; UND L
926 (defun edt-undelete-line ()
927 "Undelete previous deleted line(s)."
928 (interactive "*")
929 (point-to-register 1)
930 (insert edt-last-deleted-lines)
931 (register-to-point 1))
934 ;;; UND W
937 (defun edt-undelete-word ()
938 "Undelete previous deleted word(s)."
939 (interactive "*")
940 (point-to-register 1)
941 (insert edt-last-deleted-words)
942 (register-to-point 1))
945 ;;; UND C
948 (defun edt-undelete-character ()
949 "Undelete previous deleted character(s)."
950 (interactive "*")
951 (point-to-register 1)
952 (insert edt-last-deleted-chars)
953 (register-to-point 1))
956 ;;; REPLACE
959 (defun edt-replace ()
960 "Replace marked section with last CUT (killed) text."
961 (interactive "*")
962 (if (edt-check-match)
963 (replace-match (car kill-ring-yank-pointer))
964 (progn
965 (exchange-point-and-mark)
966 (let ((beg (point)))
967 (exchange-point-and-mark)
968 (delete-region beg (point)))
969 (yank))))
972 ;;; SUBS
975 (defun edt-substitute (num)
976 "Replace the selected region with the contents of the CUT buffer and.
977 Repeat the most recent FIND command. (The Emacs kill ring is used as
978 the CUT buffer.)
979 Argument NUM is the repeat count. A positive value indicates the of times
980 to repeat the substitution. A negative argument means replace all occurrences
981 of the search text."
982 (interactive "p")
983 (cond ((or edt-select-mode (edt-check-match))
984 (while (and (not (= num 0)) (or edt-select-mode (edt-check-match)))
985 (edt-replace)
986 (edt-find-next)
987 (setq num (1- num))))
989 (error "No selection active"))))
991 (defun edt-set-match nil
992 "Set markers at match beginning and end."
993 ;; Add one to beginning mark so it stays with the first character of
994 ;; the string even if characters are added just before the string.
995 (setq edt-match-beginning-mark (copy-marker (1+ (match-beginning 0))))
996 (setq edt-match-end-mark (copy-marker (match-end 0))))
998 (defun edt-unset-match nil
999 "Unset match beginning and end markers."
1000 (set-marker edt-match-beginning-mark nil)
1001 (set-marker edt-match-end-mark nil))
1003 (defun edt-match-beginning nil
1004 "Return the location of the last match beginning."
1005 (1- (marker-position edt-match-beginning-mark)))
1007 (defun edt-match-end nil
1008 "Return the location of the last match end."
1009 (marker-position edt-match-end-mark))
1011 (defun edt-check-match nil
1012 "Return t if point is between edt-match markers.
1013 Otherwise sets the edt-match markers to nil and returns nil."
1014 ;; make sure 1- marker is in this buffer
1015 ;; 2- point is at or after beginning marker
1016 ;; 3- point is before ending marker, or in the case of
1017 ;; zero length regions (like bol, or eol) that the
1018 ;; beginning, end, and point are equal.
1019 (cond ((and
1020 (equal (marker-buffer edt-match-beginning-mark) (current-buffer))
1021 (>= (point) (1- (marker-position edt-match-beginning-mark)))
1023 (< (point) (marker-position edt-match-end-mark))
1024 (and (= (1- (marker-position edt-match-beginning-mark))
1025 (marker-position edt-match-end-mark))
1026 (= (marker-position edt-match-end-mark) (point))))) t)
1028 (edt-unset-match) nil)))
1030 (defun edt-show-match-markers nil
1031 "Show the values of the match markers."
1032 (interactive)
1033 (if (markerp edt-match-beginning-mark)
1034 (let ((beg (marker-position edt-match-beginning-mark)))
1035 (message "(%s, %s) in %s -- current %s in %s"
1036 (if beg (1- beg) nil)
1037 (marker-position edt-match-end-mark)
1038 (marker-buffer edt-match-end-mark)
1039 (point) (current-buffer)))))
1043 ;;; ADVANCE
1046 (defun edt-advance ()
1047 "Set movement direction forward.
1048 Also, execute command specified if in Minibuffer."
1049 (interactive)
1050 (setq edt-direction-string edt-forward-string)
1051 (force-mode-line-update)
1052 (if (string-equal " *Minibuf"
1053 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1054 (exit-minibuffer))
1055 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1059 ;;; BACKUP
1062 (defun edt-backup ()
1063 "Set movement direction backward.
1064 Also, execute command specified if in Minibuffer."
1065 (interactive)
1066 (setq edt-direction-string edt-backward-string)
1067 (force-mode-line-update)
1068 (if (string-equal " *Minibuf"
1069 (substring (buffer-name) 0 (min (length (buffer-name)) 9)))
1070 (exit-minibuffer))
1071 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1075 ;;; CHNGCASE
1077 ;; This function is based upon Jeff Kowalski's case-flip function in his
1078 ;; tpu.el.
1080 (defun edt-change-case (num)
1081 "Change the case of specified characters.
1082 If text selection IS active, then characters between the cursor and mark are
1083 changed. If text selection is NOT active, there are two cases. First, if the
1084 current direction is ADVANCE, then the prefix number of character(s) under and
1085 following cursor are changed. Second, if the current direction is BACKUP, then
1086 the prefix number of character(s) before the cursor are changed. Accepts a
1087 positive prefix for the number of characters to change, but the prefix is
1088 ignored if text selection is active.
1089 Argument NUM is the numbers of consecutive characters to change."
1090 (interactive "*p")
1091 (edt-check-prefix num)
1092 (if edt-select-mode
1093 (let ((end (max (mark) (point)))
1094 (point-save (point)))
1095 (goto-char (min (point) (mark)))
1096 (while (not (eq (point) end))
1097 (funcall (if (<= ?a (following-char))
1098 'upcase-region 'downcase-region)
1099 (point) (1+ (point)))
1100 (forward-char 1))
1101 (goto-char point-save))
1102 (progn
1103 (if (string= edt-direction-string edt-backward-string)
1104 (backward-char num))
1105 (while (> num 0)
1106 (funcall (if (<= ?a (following-char))
1107 'upcase-region 'downcase-region)
1108 (point) (1+ (point)))
1109 (forward-char 1)
1110 (setq num (1- num))))))
1113 ;;; DEFINE KEY
1116 (defun edt-define-key ()
1117 "Assign an interactively-callable function to a specified key sequence.
1118 The current key definition is saved in `edt-last-replaced-key-definition'.
1119 Use `edt-restore-key' to restore last replaced key definition."
1120 (interactive)
1121 (if (featurep 'xemacs) (setq zmacs-region-stays t))
1122 (let (edt-function
1123 edt-key-definition)
1124 (setq edt-key-definition
1125 (read-key-sequence "Press the key to be defined: "))
1126 (if (if (featurep 'emacs)
1127 (string-equal "\C-m" edt-key-definition)
1128 (string-equal "\C-m" (events-to-keys edt-key-definition)))
1129 (message "Key not defined")
1130 (progn
1131 (setq edt-function (read-command "Enter command name: "))
1132 (if (string-equal "" edt-function)
1133 (message "Key not defined")
1134 (progn
1135 (setq edt-last-replaced-key-definition
1136 (lookup-key (current-global-map) edt-key-definition))
1137 (define-key (current-global-map)
1138 edt-key-definition edt-function)))))))
1141 ;;; FORM FEED INSERT
1144 (defun edt-form-feed-insert (num)
1145 "Insert form feed character at cursor position.
1146 Argument NUM is the number of form feeds to insert."
1147 (interactive "*p")
1148 (edt-check-prefix num)
1149 (while (> num 0)
1150 (insert ?\f)
1151 (setq num (1- num))))
1154 ;;; TAB INSERT
1157 (defun edt-tab-insert (num)
1158 "Insert tab character at cursor position.
1159 Argument NUM is the number of tabs to insert."
1160 (interactive "*p")
1161 (edt-check-prefix num)
1162 (while (> num 0)
1163 (insert ?\t)
1164 (setq num (1- num))))
1167 ;;; Check Prefix
1170 (defun edt-check-prefix (num)
1171 "Indicate error if prefix is not positive.
1172 Argument NUM is the prefix value tested."
1173 (if (<= num 0)
1174 (error "Prefix must be positive")))
1177 ;;; Check Selection
1180 (defun edt-check-selection ()
1181 "Indicate error if EDT selection is not active."
1182 (if (not edt-select-mode)
1183 (error "Selection NOT active")))
1186 ;;; Scroll Margins
1189 (defun edt-top-check (beg lines)
1190 "Enforce scroll margin at the top of screen.
1191 Argument BEG is the starting line number before cursor was moved.
1192 Argument LINES is the number of lines the cursor moved toward the top."
1193 (let ((margin (/ (* (window-height) edt-top-scroll-margin) 100)))
1194 (cond ((< beg margin) (recenter beg))
1195 ((< (- beg lines) margin) (recenter margin)))))
1197 (defun edt-bottom-check (beg lines)
1198 "Enforce scroll margin at the bottom of screen.
1199 Argument BEG is the starting line number before cursor was moved.
1200 Argument LINES is the number of lines the cursor moved toward the bottom."
1201 (let* ((height (window-height))
1202 (margin (+ 1 (/ (* height edt-bottom-scroll-margin) 100)))
1203 ;; subtract 1 from height because it includes mode line
1204 (difference (- height margin 1)))
1205 (cond ((> beg difference) (recenter beg))
1206 ((and (featurep 'xemacs) (> (+ beg lines 1) difference))
1207 (recenter (- margin)))
1208 ((> (+ beg lines) difference) (recenter (- margin))))))
1210 (defun edt-current-line nil
1211 "Return the vertical position of point in the selected window.
1212 Top line is 0. Counts each text line only once, even if it wraps."
1213 (+ (count-lines (window-start) (point)) (if (= (current-column) 0) 1 0) -1))
1215 ;;;###autoload
1216 (defun edt-set-scroll-margins (top bottom)
1217 "Set scroll margins.
1218 Argument TOP is the top margin in number of lines or percent of window.
1219 Argument BOTTOM is the bottom margin in number of lines or percent of window."
1220 (interactive
1221 "sEnter top scroll margin (N lines or N%% or RETURN for current value): \
1222 \nsEnter bottom scroll margin (N lines or N%% or RETURN for current value): ")
1223 ;; set top scroll margin
1224 (or (string= top "")
1225 (if (string= "%" (substring top -1))
1226 (setq edt-top-scroll-margin (string-to-number top))
1227 (setq edt-top-scroll-margin
1228 (/ (1- (+ (* (string-to-number top) 100) (window-height)))
1229 (window-height)))))
1230 ;; set bottom scroll margin
1231 (or (string= bottom "")
1232 (if (string= "%" (substring bottom -1))
1233 (setq edt-bottom-scroll-margin (string-to-number bottom))
1234 (setq edt-bottom-scroll-margin
1235 (/ (1- (+ (* (string-to-number bottom) 100) (window-height)))
1236 (window-height)))))
1237 ;; report scroll margin settings if running interactively
1238 (and (called-interactively-p 'interactive)
1239 (message "Scroll margins set. Top = %s%%, Bottom = %s%%"
1240 edt-top-scroll-margin edt-bottom-scroll-margin)))
1243 ;;;;
1244 ;;;; ENHANCEMENTS AND ADDITIONS FOR EDT KEYPAD MODE
1245 ;;;;
1248 ;;; Several enhancements and additions to EDT keypad mode commands are
1249 ;;; provided here. Some of these have been motivated by similar
1250 ;;; TPU/EVE and EVE-Plus commands. Others are new.
1253 ;;; CHANGE DIRECTION
1256 (defun edt-change-direction ()
1257 "Toggle movement direction."
1258 (interactive)
1259 (if (equal edt-direction-string edt-forward-string)
1260 (edt-backup)
1261 (edt-advance)))
1264 ;;; TOGGLE SELECT
1267 (defun edt-toggle-select ()
1268 "Toggle to start (or cancel) text selection."
1269 (interactive)
1270 (if edt-select-mode
1271 (edt-reset)
1272 (edt-select)))
1275 ;;; SENTENCE
1278 (defun edt-sentence-forward (num)
1279 "Move forward to start of next sentence.
1280 Argument NUM is the positive number of sentences to move."
1281 (interactive "p")
1282 (edt-check-prefix num)
1283 (edt-with-position
1284 (if (eobp)
1285 (error "End of buffer")
1286 (forward-sentence num)
1287 (forward-word 1)
1288 (backward-sentence))
1289 (if (> (point) far)
1290 (if (zerop (setq left (save-excursion (forward-line height))))
1291 (recenter top-margin)
1292 (recenter (- left bottom-up-margin)))
1293 (and (> (point) bottom) (recenter bottom-margin))))
1294 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1296 (defun edt-sentence-backward (num)
1297 "Move backward to next sentence beginning.
1298 Argument NUM is the positive number of sentences to move."
1299 (interactive "p")
1300 (edt-check-prefix num)
1301 (edt-with-position
1302 (if (eobp)
1303 (error "End of buffer")
1304 (backward-sentence num))
1305 (and (< (point) top) (recenter (min beg top-margin))))
1306 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1308 (defun edt-sentence (num)
1309 "Move in current direction to next sentence.
1310 Argument NUM is the positive number of sentences to move."
1311 (interactive "p")
1312 (if (equal edt-direction-string edt-forward-string)
1313 (edt-sentence-forward num)
1314 (edt-sentence-backward num)))
1317 ;;; PARAGRAPH
1320 (defun edt-paragraph-forward (num)
1321 "Move forward to beginning of paragraph.
1322 Argument NUM is the positive number of paragraphs to move."
1323 (interactive "p")
1324 (edt-check-prefix num)
1325 (edt-with-position
1326 (while (> num 0)
1327 (forward-paragraph (+ num 1))
1328 (start-of-paragraph-text)
1329 (if (eolp)
1330 (forward-line 1))
1331 (setq num (1- num)))
1332 (if (> (point) far)
1333 (if (zerop (setq left (save-excursion (forward-line height))))
1334 (recenter top-margin)
1335 (recenter (- left bottom-up-margin)))
1336 (and (> (point) bottom) (recenter bottom-margin))))
1337 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1339 (defun edt-paragraph-backward (num)
1340 "Move backward to beginning of paragraph.
1341 Argument NUM is the positive number of paragraphs to move."
1342 (interactive "p")
1343 (edt-check-prefix num)
1344 (edt-with-position
1345 (while (> num 0)
1346 (start-of-paragraph-text)
1347 (setq num (1- num)))
1348 (and (< (point) top) (recenter (min beg top-margin))))
1349 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1351 (defun edt-paragraph (num)
1352 "Move in current direction to next paragraph.
1353 Argument NUM is the positive number of paragraphs to move."
1354 (interactive "p")
1355 (if (equal edt-direction-string edt-forward-string)
1356 (edt-paragraph-forward num)
1357 (edt-paragraph-backward num)))
1360 ;;; RESTORE KEY
1363 (defun edt-restore-key ()
1364 "Restore last replaced key definition.
1365 Definition is stored in `edt-last-replaced-key-definition'."
1366 (interactive)
1367 (if (featurep 'xemacs) (setq zmacs-region-stays t))
1368 (if edt-last-replaced-key-definition
1369 (progn
1370 (let (edt-key-definition)
1371 (set 'edt-key-definition
1372 (read-key-sequence "Press the key to be restored: "))
1373 (if (if (featurep 'emacs)
1374 (string-equal "\C-m" edt-key-definition)
1375 (string-equal "\C-m" (events-to-keys edt-key-definition)))
1376 (message "Key not restored")
1377 (progn
1378 (define-key (current-global-map)
1379 edt-key-definition edt-last-replaced-key-definition)
1380 (if (featurep 'emacs)
1381 (message "Key definition for %s has been restored."
1382 edt-key-definition)
1383 (message "Key definition for %s has been restored."
1384 (events-to-keys edt-key-definition)))))))
1385 (error "No replaced key definition to restore!")))
1388 ;;; WINDOW TOP
1391 (defun edt-window-top ()
1392 "Move the cursor to the top of the window."
1393 (interactive)
1394 (let ((start-column (current-column)))
1395 (move-to-window-line 0)
1396 (move-to-column start-column))
1397 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1400 ;;; WINDOW BOTTOM
1403 (defun edt-window-bottom ()
1404 "Move the cursor to the bottom of the window."
1405 (interactive)
1406 (let ((start-column (current-column)))
1407 (move-to-window-line (- (window-height) 2))
1408 (move-to-column start-column))
1409 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1412 ;;; SCROLL WINDOW LINE
1415 (defun edt-scroll-window-forward-line ()
1416 "Move window forward one line leaving cursor at position in window."
1417 (interactive)
1418 (scroll-up 1)
1419 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1421 (defun edt-scroll-window-backward-line ()
1422 "Move window backward one line leaving cursor at position in window."
1423 (interactive)
1424 (scroll-down 1)
1425 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1427 (defun edt-scroll-line ()
1428 "Move window one line in current direction."
1429 (interactive)
1430 (if (equal edt-direction-string edt-forward-string)
1431 (edt-scroll-window-forward-line)
1432 (edt-scroll-window-backward-line)))
1435 ;;; SCROLL WINDOW
1437 ;;; Scroll a window (less one line) at a time. Leave cursor in center of
1438 ;;; window.
1440 (defun edt-scroll-window-forward (num)
1441 "Scroll forward one window in buffer, less one line.
1442 Argument NUM is the positive number of windows to move."
1443 (interactive "p")
1444 (edt-check-prefix num)
1445 (scroll-up (- (* (window-height) num) 2))
1446 (edt-line-forward (/ (- (window-height) 1) 2)))
1448 (defun edt-scroll-window-backward (num)
1449 "Scroll backward one window in buffer, less one line.
1450 Argument NUM is the positive number of windows to move."
1451 (interactive "p")
1452 (edt-check-prefix num)
1453 (scroll-down (- (* (window-height) num) 2))
1454 (edt-line-backward (/ (- (window-height) 1) 2)))
1456 (defun edt-scroll-window (num)
1457 "Scroll one window in buffer, less one line, in current direction.
1458 Argument NUM is the positive number of windows to move."
1459 (interactive "p")
1460 (if (equal edt-direction-string edt-forward-string)
1461 (edt-scroll-window-forward num)
1462 (edt-scroll-window-backward num)))
1465 ;;; LINE TO BOTTOM OF WINDOW
1468 (defun edt-line-to-bottom-of-window ()
1469 "Move the current line to the bottom of the window."
1470 (interactive)
1471 (recenter -1)
1472 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1475 ;;; LINE TO TOP OF WINDOW
1478 (defun edt-line-to-top-of-window ()
1479 "Move the current line to the top of the window."
1480 (interactive)
1481 (recenter 0)
1482 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1485 ;;; LINE TO MIDDLE OF WINDOW
1488 (defun edt-line-to-middle-of-window ()
1489 "Move window so line with cursor is in the middle of the window."
1490 (interactive)
1491 (recenter '(4))
1492 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1495 ;;; GOTO PERCENTAGE
1498 (defun edt-goto-percentage (num)
1499 "Move to specified percentage in buffer from top of buffer.
1500 Argument NUM is the percentage into the buffer to move."
1501 (interactive "NGoto-percentage: ")
1502 (if (or (> num 100) (< num 0))
1503 (error "Percentage %d out of range 0 < percent < 100" num)
1504 (goto-char (/ (* (point-max) num) 100)))
1505 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1508 ;;; FILL REGION
1511 (defun edt-fill-region ()
1512 "Fill selected text."
1513 (interactive "*")
1514 (edt-check-selection)
1515 (fill-region (point) (mark)))
1518 ;;; INDENT OR FILL REGION
1521 (defun edt-indent-or-fill-region ()
1522 "Fill region in text modes, indent region in programming language modes."
1523 (interactive "*")
1524 (if (string= paragraph-start "$\\|\f")
1525 (indent-region (point) (mark) nil)
1526 (fill-region (point) (mark))))
1529 (declare-function c-mark-function "cc-cmds" ())
1531 ;;; MARK SECTION WISELY
1534 (defun edt-mark-section-wisely ()
1535 "Mark the section in a manner consistent with the `major-mode'.
1536 Uses `mark-defun' for Emacs-Lisp and Lisp, and for Fortran,
1537 `c-mark-function' for C,
1538 and `mark-paragraph' for other modes."
1539 (interactive)
1540 (if edt-select-mode
1541 (progn
1542 (edt-reset))
1543 (progn
1544 (cond ((or (eq major-mode 'emacs-lisp-mode)
1545 (eq major-mode 'fortran-mode)
1546 (eq major-mode 'lisp-mode))
1547 (mark-defun)
1548 (message "Lisp defun selected"))
1549 ((eq major-mode 'c-mode)
1550 (c-mark-function)
1551 (message "C function selected"))
1552 (t (mark-paragraph)
1553 (message "Paragraph selected"))))))
1556 ;;; COPY
1559 (defun edt-copy ()
1560 "Copy selected region to kill ring, but don't delete it!"
1561 (interactive)
1562 (edt-check-selection)
1563 (copy-region-as-kill (mark) (point))
1564 (edt-reset)
1565 (message "Selected text COPIED to kill ring"))
1568 ;;; CUT or COPY
1571 (defun edt-cut-or-copy ()
1572 "Cuts (or copies) selected text to kill ring.
1573 Cuts selected text if `buffer-read-only' is nil.
1574 Copies selected text if `buffer-read-only' is t."
1575 (interactive)
1576 (if buffer-read-only
1577 (edt-copy)
1578 (edt-cut)))
1581 ;;; DELETE ENTIRE LINE
1584 (defun edt-delete-entire-line ()
1585 "Delete entire line regardless of cursor position in the line."
1586 (interactive "*")
1587 (beginning-of-line)
1588 (edt-delete-line 1))
1591 ;;; DUPLICATE LINE
1594 (defun edt-duplicate-line (num)
1595 "Duplicate the line of text containing the cursor.
1596 Argument NUM is the number of times to duplicate the line."
1597 (interactive "*p")
1598 (edt-check-prefix num)
1599 (let ((old-column (current-column))
1600 (count num))
1601 (edt-delete-entire-line)
1602 (edt-undelete-line)
1603 (while (> count 0)
1604 (edt-undelete-line)
1605 (setq count (1- count)))
1606 (edt-line-forward num)
1607 (move-to-column old-column)))
1610 ;;; DUPLICATE WORD
1613 (defun edt-duplicate-word()
1614 "Duplicate word (or rest of word) found directly above cursor, if any."
1615 (interactive "*")
1616 (let ((start (point))
1617 (start-column (current-column)))
1618 (forward-line -1)
1619 (move-to-column start-column)
1620 (if (and (not (equal start (point)))
1621 (not (eolp)))
1622 (progn
1623 (if (and (equal ?\t (preceding-char))
1624 (< start-column (current-column)))
1625 (backward-char))
1626 (let ((beg (point)))
1627 (edt-one-word-forward)
1628 (setq edt-last-copied-word (buffer-substring beg (point))))
1629 (forward-line)
1630 (move-to-column start-column)
1631 (insert edt-last-copied-word))
1632 (progn
1633 (if (not (equal start (point)))
1634 (forward-line))
1635 (move-to-column start-column)
1636 (error "Nothing to duplicate!")))))
1639 ;;; KEY NOT ASSIGNED
1642 (defun edt-key-not-assigned ()
1643 "Displays message that key has not been assigned to a function."
1644 (interactive)
1645 (error "Key not assigned"))
1648 ;;; TOGGLE CAPITALIZATION OF WORD
1651 (defun edt-toggle-capitalization-of-word ()
1652 "Toggle the capitalization of the current word and move forward to next."
1653 (interactive "*")
1654 (edt-one-word-forward)
1655 (edt-one-word-backward)
1656 (edt-change-case 1)
1657 (edt-one-word-backward)
1658 (edt-one-word-forward))
1661 ;;; ELIMINATE ALL TABS
1664 (defun edt-eliminate-all-tabs ()
1665 "Convert all tabs to spaces in the entire buffer."
1666 (interactive "*")
1667 (untabify (point-min) (point-max))
1668 (message "TABS converted to SPACES"))
1671 ;;; DISPLAY THE TIME
1674 (defun edt-display-the-time ()
1675 "Display the current time."
1676 (interactive)
1677 (if (featurep 'xemacs) (setq zmacs-region-stays t))
1678 (message "%s" (current-time-string)))
1681 ;;; LEARN
1684 (defun edt-learn ()
1685 "Learn a sequence of key strokes to bind to a key."
1686 (interactive)
1687 (if (eq defining-kbd-macro t)
1688 (edt-remember)
1689 (start-kbd-macro nil)))
1692 ;;; REMEMBER
1695 (defun edt-remember ()
1696 "Store the sequence of key strokes started by `edt-learn' to a key."
1697 (interactive)
1698 (if (eq defining-kbd-macro nil)
1699 (error "Nothing to remember!")
1700 (progn
1701 (end-kbd-macro nil)
1702 (let (edt-key-definition)
1703 (set 'edt-key-definition
1704 (read-key-sequence "Enter key for binding: "))
1705 (if (if (featurep 'emacs)
1706 (string-equal "\C-m" edt-key-definition)
1707 (string-equal "\C-m" (events-to-keys edt-key-definition)))
1708 (message "Key sequence not remembered")
1709 (progn
1710 (set 'edt-learn-macro-count (+ edt-learn-macro-count 1))
1711 (setq edt-last-replaced-key-definition
1712 (lookup-key (current-global-map)
1713 edt-key-definition))
1714 (define-key (current-global-map) edt-key-definition
1715 (name-last-kbd-macro
1716 (intern (concat "last-learned-sequence-"
1717 (int-to-string edt-learn-macro-count)))))))))))
1720 ;;; EXIT
1723 (defun edt-exit ()
1724 "Save current buffer, ask to save other buffers, and then exit Emacs."
1725 (interactive)
1726 (save-buffer)
1727 (save-buffers-kill-emacs))
1730 ;;; QUIT
1733 (defun edt-quit ()
1734 "Quit Emacs without saving buffer modifications.
1735 Warn user that modifications will be lost."
1736 (interactive)
1737 (let ((list (buffer-list))
1738 (working t))
1739 (while (and list working)
1740 (let ((buffer (car list)))
1741 (if (and (buffer-file-name buffer) (buffer-modified-p buffer))
1742 (if (edt-y-or-n-p
1743 "Modifications will not be saved, continue quitting? ")
1744 (kill-emacs)
1745 (setq working nil)))
1746 (setq list (cdr list))))
1747 (if working (kill-emacs))))
1750 ;;; SPLIT WINDOW
1753 (defun edt-split-window ()
1754 "Split current window and place cursor in the new window."
1755 (interactive)
1756 (split-window)
1757 (other-window 1)
1758 (if (featurep 'xemacs) (setq zmacs-region-stays t)))
1761 ;;; COPY RECTANGLE
1764 (defun edt-copy-rectangle ()
1765 "Copy a rectangle of text between mark and cursor to register."
1766 (interactive)
1767 (edt-check-selection)
1768 (copy-rectangle-to-register 3 (region-beginning) (region-end) nil)
1769 (edt-reset)
1770 (message "Selected rectangle COPIED to register"))
1773 ;;; CUT RECTANGLE
1776 (defun edt-cut-rectangle-overstrike-mode ()
1777 "Cut a rectangle of text between mark and cursor to register.
1778 Replace cut characters with spaces and moving cursor back to
1779 upper left corner."
1780 (interactive "*")
1781 (edt-check-selection)
1782 (setq edt-rect-start-point (region-beginning))
1783 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3)
1784 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point)
1785 (message "Selected rectangle CUT to register"))
1787 (defun edt-cut-rectangle-insert-mode ()
1788 "Cut a rectangle of text between mark and cursor to register.
1789 Move cursor back to upper left corner."
1790 (interactive "*")
1791 (edt-check-selection)
1792 (setq edt-rect-start-point (region-beginning))
1793 (picture-clear-rectangle-to-register (region-beginning) (region-end) 3 t)
1794 (fixup-whitespace)
1795 (set-window-point (get-buffer-window (window-buffer)) edt-rect-start-point)
1796 (message "Selected rectangle CUT to register"))
1798 (defun edt-cut-rectangle ()
1799 "Cut a rectangular region of text to register.
1800 If overwrite mode is active, cut text is replaced with whitespace."
1801 (interactive "*")
1802 (if overwrite-mode
1803 (edt-cut-rectangle-overstrike-mode)
1804 (edt-cut-rectangle-insert-mode)))
1807 ;;; PASTE RECTANGLE
1810 (defun edt-paste-rectangle-overstrike-mode ()
1811 "Paste a rectangular region of text from register, replacing text at cursor."
1812 (interactive "*")
1813 (picture-yank-rectangle-from-register 3))
1815 (defun edt-paste-rectangle-insert-mode ()
1816 "Paste previously deleted rectangular region, inserting text at cursor."
1817 (interactive "*")
1818 (picture-yank-rectangle-from-register 3 t))
1820 (defun edt-paste-rectangle ()
1821 "Paste a rectangular region of text.
1822 If overwrite mode is active, existing text is replace with text from register."
1823 (interactive)
1824 (if overwrite-mode
1825 (edt-paste-rectangle-overstrike-mode)
1826 (edt-paste-rectangle-insert-mode)))
1829 ;;; DOWNCASE REGION
1832 (defun edt-lowercase ()
1833 "Change specified characters to lower case.
1834 If text selection IS active, then characters between the cursor and
1835 mark are changed. If text selection is NOT active, there are two
1836 situations. If the current direction is ADVANCE, then the word under
1837 the cursor is changed to lower case and the cursor is moved to rest at
1838 the beginning of the next word. If the current direction is BACKUP,
1839 the word prior to the word under the cursor is changed to lower case
1840 and the cursor is left to rest at the beginning of that word."
1841 (interactive "*")
1842 (if edt-select-mode
1843 (progn
1844 (downcase-region (mark) (point)))
1845 (progn
1846 ;; Move to beginning of current word.
1847 (if (and
1848 (not (bobp))
1849 (not (eobp))
1850 (not (bolp))
1851 (not (eolp))
1852 (not (eq ?\ (char-syntax (preceding-char))))
1853 (not (memq (preceding-char) edt-word-entities))
1854 (not (memq (following-char) edt-word-entities)))
1855 (edt-one-word-backward))
1856 (if (equal edt-direction-string edt-backward-string)
1857 (edt-one-word-backward))
1858 (let ((beg (point)))
1859 (edt-one-word-forward)
1860 (downcase-region beg (point)))
1861 (if (equal edt-direction-string edt-backward-string)
1862 (edt-one-word-backward)))))
1865 ;;; UPCASE REGION
1868 (defun edt-uppercase ()
1869 "Change specified characters to upper case.
1870 If text selection IS active, then characters between the cursor and
1871 mark are changed. If text selection is NOT active, there are two
1872 situations. If the current direction is ADVANCE, then the word under
1873 the cursor is changed to upper case and the cursor is moved to rest at
1874 the beginning of the next word. If the current direction is BACKUP,
1875 the word prior to the word under the cursor is changed to upper case
1876 and the cursor is left to rest at the beginning of that word."
1877 (interactive "*")
1878 (if edt-select-mode
1879 (progn
1880 (upcase-region (mark) (point)))
1881 (progn
1882 ;; Move to beginning of current word.
1883 (if (and
1884 (not (bobp))
1885 (not (eobp))
1886 (not (bolp))
1887 (not (eolp))
1888 (not (eq ?\ (char-syntax (preceding-char))))
1889 (not (memq (preceding-char) edt-word-entities))
1890 (not (memq (following-char) edt-word-entities)))
1891 (edt-one-word-backward))
1892 (if (equal edt-direction-string edt-backward-string)
1893 (edt-one-word-backward))
1894 (let ((beg (point)))
1895 (edt-one-word-forward)
1896 (upcase-region beg (point)))
1897 (if (equal edt-direction-string edt-backward-string)
1898 (edt-one-word-backward)))))
1901 ;;; Functions used in loading LK-201 key mapping file.
1903 (defvar edt-last-answer nil
1904 "Most recent response to `edt-y-or-n-p'.")
1906 (defun edt-y-or-n-p (prompt &optional not-yes)
1907 "Prompt for a y or n answer with positive default.
1908 Like Emacs `y-or-n-p', also accepts space as y and DEL as n.
1909 Argument PROMPT is the prompt string.
1910 Optional argument NOT-YES changes the default to negative."
1911 (message "%s[%s]" prompt (if not-yes "n" "y"))
1912 (let ((doit t))
1913 (while doit
1914 (setq doit nil)
1915 (let ((ans (read-char)))
1916 (cond ((or (= ans ?y) (= ans ?Y) (= ans ?\ ))
1917 (setq edt-last-answer t))
1918 ((or (= ans ?n) (= ans ?N) (= ans ?\C-?))
1919 (setq edt-last-answer nil))
1920 ((= ans ?\r) (setq edt-last-answer (not not-yes)))
1922 (setq doit t) (beep)
1923 (message "Please answer y or n. %s[%s]"
1924 prompt (if not-yes "n" "y")))))))
1925 edt-last-answer)
1928 ;;; INITIALIZATION COMMANDS.
1931 (declare-function edt-mapper "edt-mapper" ())
1934 ;;; Function used to load LK-201 key mapping file generated by edt-mapper.el.
1936 (defun edt-load-keys (file)
1937 "Load the LK-201 key mapping FILE generated by edt-mapper.el.
1938 If FILE is nil, which is the normal case, try to load a default file.
1939 The default file names are based upon the window system, terminal
1940 type, and version of Emacs in use: GNU Emacs or XEmacs (aka Lucid
1941 Emacs). If a default file does not exist, ask user if one should be
1942 created."
1943 (interactive "fKey definition file: ")
1944 (cond (file
1945 (setq file (expand-file-name file)))
1946 (edt-keys-file
1947 (setq file (expand-file-name edt-keys-file)))
1949 (setq file
1950 (expand-file-name
1951 (concat
1952 "~/.edt-" edt-emacs-variant
1953 (if edt-term (concat "-" edt-term))
1954 (if edt-xserver (concat "-" edt-xserver))
1955 (if edt-window-system
1956 (concat "-" (upcase (symbol-name edt-window-system))))
1957 "-keys")))))
1958 (cond ((file-readable-p file)
1959 (load-file file))
1961 (switch-to-buffer "*scratch*")
1962 (erase-buffer)
1963 (insert "
1965 Ack!! You're running the Enhanced EDT Emulation without loading an
1966 EDT key mapping file. To create an EDT key mapping file, run the
1967 edt-mapper program. It is safest to run it from an Emacs loaded
1968 without any of your own customizations found in your init file, etc.
1969 The reason for this is that some user customizations confuse edt-mapper.
1970 You can do this by quitting Emacs and then invoking Emacs again as
1971 follows:
1973 emacs -q -l edt-mapper -f edt-mapper
1975 [NOTE: If you do nothing out of the ordinary in your init file, and
1976 the search for edt-mapper is successful, you can try running it now.]
1978 The library edt-mapper includes these same directions on how to
1979 use it! Perhaps it's lying around here someplace. \n ")
1980 (let ((path (locate-library
1981 "edt-mapper"
1982 nil (append (list default-directory) load-path))))
1983 (if path
1984 (progn
1985 (insert (format
1986 "Ah yes, there it is, in \n\n %s \n\n" path))
1987 (if (edt-y-or-n-p "Do you want to run it now? ")
1988 (progn
1989 (load-file path)
1990 (edt-mapper))
1991 (error "EDT Emulation not configured")))
1992 (insert (substitute-command-keys
1993 "Nope, I can't seem to find it. :-(\n\n"))
1994 (sit-for 20)
1995 (error "EDT Emulation not configured"))))))
1998 ;;; Turning the EDT Emulation on and off.
2001 ;;;###autoload
2002 (defun edt-emulation-on ()
2003 "Turn on EDT Emulation."
2004 (interactive)
2005 ;; If using pc window system (MS-DOS), set terminal type to pc.
2006 ;; If not a window system (GNU) or a tty window system (XEmacs),
2007 ;; get terminal type.
2008 (if (eq edt-window-system 'pc)
2009 (setq edt-term "pc")
2010 (if (or (not edt-window-system) (eq edt-window-system 'tty))
2011 (setq edt-term (getenv "TERM"))))
2012 ;; Look for a terminal configuration file for this terminal type.
2013 ;; Otherwise, load the user's custom configuration file.
2014 (if (or (not edt-window-system) (memq edt-window-system '(pc tty)))
2015 (progn
2016 ;; Load terminal-specific configuration file, if it exists for this
2017 ;; terminal type. Note: All DEC VT series terminals are supported
2018 ;; by the same terminal configuration file: edt-vt100.el.
2019 (if (string-equal "vt" (substring edt-term 0 (min (length edt-term) 2)))
2020 (setq edt-term "vt100"))
2021 (let ((term edt-term)
2022 hyphend)
2023 (while (and term
2024 (not (load (concat "edt-" term) t t)))
2025 ;; Strip off last hyphen and what follows, then try again
2026 (if (setq hyphend (string-match "[-_][^-_]+$" term))
2027 (setq term (substring term 0 hyphend))
2028 (setq term nil)))
2029 ;; If no terminal-specific configuration file exists, load user's
2030 ;; custom EDT terminal configuration file.
2031 ;; If this is a pc running MS-DOS, then custom configuration files
2032 ;; are not supported. So, if the file is missing, issue an error
2033 ;; message.
2034 (if (null term)
2035 (if (equal edt-term "pc")
2036 (error "Unable to find EDT terminal specific file edt-pc.el")
2037 (edt-load-keys nil))
2038 (setq edt-term term))))
2039 (edt-load-keys nil))
2040 ;; Make highlighting of selected text work properly for EDT commands.
2041 (if (featurep 'emacs)
2042 (progn
2043 (setq edt-orig-transient-mark-mode
2044 (default-value 'transient-mark-mode))
2045 (add-hook 'activate-mark-hook
2046 (function
2047 (lambda ()
2048 (edt-select-mode t))))
2049 (add-hook 'deactivate-mark-hook
2050 (function
2051 (lambda ()
2052 (edt-select-mode nil)))))
2053 (progn
2054 (add-hook 'zmacs-activate-region-hook
2055 (function
2056 (lambda ()
2057 (edt-select-mode t))))
2058 (add-hook 'zmacs-deactivate-region-hook
2059 (function
2060 (lambda ()
2061 (edt-select-mode nil))))))
2062 ;; Load user's EDT custom key bindings file, if it exists.
2063 ;; Otherwise, use the default bindings.
2064 (if (load "edt-user" t t)
2065 (edt-user-emulation-setup)
2066 (edt-default-emulation-setup)))
2068 (defun edt-emulation-off()
2069 "Select original global key bindings, disabling EDT Emulation."
2070 (interactive)
2071 (use-global-map global-map)
2072 (if (not edt-keep-current-page-delimiter)
2073 (setq page-delimiter edt-orig-page-delimiter))
2074 (setq edt-direction-string "")
2075 (setq edt-select-mode-current nil)
2076 (edt-reset)
2077 (force-mode-line-update t)
2078 (if (featurep 'emacs)
2079 (setq-default transient-mark-mode edt-orig-transient-mark-mode))
2080 (message "Original key bindings restored; EDT Emulation disabled"))
2082 (defun edt-default-menu-bar-update-buffers ()
2083 ;; Update edt-default-global-map with latest copy of
2084 ;; `global-buffers-menu-map' each time `menu-bar-update-buffers'
2085 ;; updates global-map.
2086 (define-key edt-default-global-map [menu-bar buffer]
2087 (cons "Buffers" global-buffers-menu-map)))
2089 (defun edt-user-menu-bar-update-buffers ()
2090 ;; We need to update edt-user-global-map with latest copy of
2091 ;; `global-buffers-menu-map' each time `menu-bar-update-buffers'
2092 ;; updates global-map.
2093 (define-key edt-user-global-map [menu-bar buffer]
2094 (cons "Buffers" global-buffers-menu-map)))
2096 (defun edt-default-emulation-setup (&optional user-setup)
2097 "Setup emulation of DEC's EDT editor.
2098 Optional argument USER-SETUP non-nil means called from function
2099 `edt-user-emulation-setup'."
2100 ;; Setup default EDT global map by copying global map bindings.
2101 ;; This preserves ESC and C-x prefix bindings and other bindings we
2102 ;; wish to retain in EDT emulation mode keymaps. It also permits
2103 ;; customization of these bindings in the EDT global maps without
2104 ;; disturbing the original bindings in global-map.
2105 (fset 'edt-default-ESC-prefix (copy-keymap 'ESC-prefix))
2106 (setq edt-default-global-map (copy-keymap (current-global-map)))
2107 (if (featurep 'emacs)
2108 (define-key edt-default-global-map "\e" 'edt-default-ESC-prefix)
2109 (define-key edt-default-global-map [escape] 'edt-default-ESC-prefix))
2110 (define-prefix-command 'edt-default-gold-map)
2111 (edt-setup-default-bindings)
2112 ;; If terminal has additional function keys, the terminal-specific
2113 ;; initialization file can assign bindings to them via the optional
2114 ;; function edt-setup-extra-default-bindings.
2115 (if (fboundp 'edt-setup-extra-default-bindings)
2116 (edt-setup-extra-default-bindings))
2117 ;; Variable needed by edt-learn.
2118 (setq edt-learn-macro-count 0)
2119 ;; Display EDT text selection active within the mode line
2120 (or (assq 'edt-select-mode minor-mode-alist)
2121 (setq minor-mode-alist
2122 (cons '(edt-select-mode edt-select-mode) minor-mode-alist)))
2123 ;; Display EDT direction of motion within the mode line
2124 (or (assq 'edt-direction-string minor-mode-alist)
2125 (setq minor-mode-alist
2126 (cons
2127 '(edt-direction-string edt-direction-string) minor-mode-alist)))
2128 (if user-setup
2129 (progn
2130 (setq edt-user-map-configured t)
2131 (fset 'edt-emulation-on (symbol-function 'edt-select-user-global-map)))
2132 (progn
2133 (fset 'edt-emulation-on (symbol-function 'edt-select-default-global-map))
2134 (edt-select-default-global-map)))
2135 ;; Keep the menu bar Buffers menu up-to-date in edt-default-global-map.
2136 (add-hook 'menu-bar-update-hook 'edt-default-menu-bar-update-buffers))
2138 (defun edt-user-emulation-setup ()
2139 "Setup user custom emulation of DEC's EDT editor."
2140 ;; Initialize EDT default bindings.
2141 (edt-default-emulation-setup t)
2142 ;; Setup user EDT global map by copying default EDT global map bindings.
2143 (fset 'edt-user-ESC-prefix (copy-keymap 'edt-default-ESC-prefix))
2144 (setq edt-user-global-map (copy-keymap edt-default-global-map))
2145 (if (featurep 'emacs)
2146 (define-key edt-user-global-map "\e" 'edt-user-ESC-prefix)
2147 (define-key edt-user-global-map [escape] 'edt-user-ESC-prefix))
2148 ;; If terminal has additional function keys, the user's initialization
2149 ;; file can assign bindings to them via the optional
2150 ;; function edt-setup-extra-default-bindings.
2151 (define-prefix-command 'edt-user-gold-map)
2152 (fset 'edt-user-gold-map (copy-keymap 'edt-default-gold-map))
2153 ;; This is a function that the user can define for custom bindings.
2154 ;; See Info node `edt' for more details, and sample edt-user.el file.
2155 (if (fboundp 'edt-setup-user-bindings)
2156 (edt-setup-user-bindings))
2157 (edt-select-user-global-map)
2158 ;; Keep the menu bar Buffers menu up-to-date in edt-user-global-map.
2159 (add-hook 'menu-bar-update-hook 'edt-user-menu-bar-update-buffers))
2161 (defun edt-select-default-global-map()
2162 "Select default EDT emulation key bindings."
2163 (interactive)
2164 (if (featurep 'emacs)
2165 (transient-mark-mode 1))
2166 (use-global-map edt-default-global-map)
2167 (if (not edt-keep-current-page-delimiter)
2168 (progn
2169 (setq edt-orig-page-delimiter page-delimiter)
2170 (setq page-delimiter "\f")))
2171 (setq edt-default-map-active t)
2172 (edt-advance)
2173 (setq edt-select-mode-current 'edt-select-mode-string)
2174 (edt-reset)
2175 (message "Default EDT keymap active"))
2177 (defun edt-select-user-global-map()
2178 "Select user EDT emulation custom key bindings."
2179 (interactive)
2180 (if edt-user-map-configured
2181 (progn
2182 (if (featurep 'emacs)
2183 (transient-mark-mode 1))
2184 (use-global-map edt-user-global-map)
2185 (if (not edt-keep-current-page-delimiter)
2186 (progn
2187 (setq edt-orig-page-delimiter page-delimiter)
2188 (setq page-delimiter "\f")))
2189 (setq edt-default-map-active nil)
2190 (edt-advance)
2191 (setq edt-select-mode-current 'edt-select-mode-string)
2192 (edt-reset)
2193 (message "User EDT custom keymap active"))
2194 (error "User EDT custom keymap NOT configured!")))
2196 (defun edt-switch-global-maps ()
2197 "Toggle between default EDT keymap and user EDT keymap."
2198 (interactive)
2199 (if edt-default-map-active
2200 (edt-select-user-global-map)
2201 (edt-select-default-global-map)))
2204 ;; Functions used to set up DEFAULT bindings to EDT emulation functions.
2207 (defun edt-bind-function-key-default (function-key binding gold-binding)
2208 "Binds LK-201 function keys to default bindings in the EDT Emulator.
2209 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2210 Argument BINDING is the Emacs function to be bound to <KEY>.
2211 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2212 (let ((key (cdr (assoc function-key *EDT-keys*))))
2213 (if (and key (not (equal key "")))
2214 (progn
2215 (define-key edt-default-global-map key binding)
2216 (define-key 'edt-default-gold-map key gold-binding)))))
2218 (defun edt-bind-key-default (key binding)
2219 "Bind key sequences to default bindings in the EDT Emulator.
2220 Argument KEY is the name of a standard key or a function key.
2221 Argument BINDING is the Emacs function to be bound to <KEY>."
2222 (define-key edt-default-global-map key binding))
2224 (defun edt-bind-gold-key-default (key gold-binding)
2225 "Binds <GOLD> key sequences to default bindings in the EDT Emulator.
2226 Argument KEY is the name of a standard key or a function key.
2227 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2228 (define-key 'edt-default-gold-map key gold-binding))
2231 ;; Functions used to set up USER CUSTOM bindings to EDT emulation functions.
2233 (defun edt-bind-function-key (function-key binding gold-binding)
2234 "Binds LK-201 function keys to custom bindings in the EDT Emulator.
2235 Argument FUNCTION-KEY is the name of the function key or keypad function key.
2236 Argument BINDING is the Emacs function to be bound to <KEY>.
2237 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2238 (let ((key (cdr (assoc function-key *EDT-keys*))))
2239 (if (and key (not (equal key "")))
2240 (progn
2241 (define-key edt-user-global-map key binding)
2242 (define-key 'edt-user-gold-map key gold-binding)))))
2244 (defun edt-bind-key (key binding)
2245 "Bind standard key sequences to custom bindings in the EDT Emulator.
2246 Argument KEY is the name of a key. It can be a standard key or a function key.
2247 Argument BINDING is the Emacs function to be bound to <KEY>."
2248 (define-key edt-user-global-map key binding))
2250 ;; For backward compatibility to existing edt-user.el files.
2251 (fset 'edt-bind-standard-key (symbol-function 'edt-bind-key))
2253 (defun edt-bind-gold-key (key gold-binding)
2254 "Binds <GOLD> standard key sequences to custom bindings in the EDT Emulator.
2255 Argument KEY is the name of a standard key or a function key.
2256 Argument GOLD-BINDING is the Emacs function to be bound to GOLD <KEY>."
2257 (define-key 'edt-user-gold-map key gold-binding))
2259 (defun edt-setup-default-bindings ()
2260 "Assigns default EDT Emulation keyboard bindings."
2262 ;; Function Key Bindings: Regular and GOLD.
2264 ;; VT100/VT200/VT300 PF1 (GOLD), PF2, PF3, PF4 Keys
2265 (edt-bind-function-key-default "PF1"
2266 'edt-default-gold-map 'edt-mark-section-wisely)
2267 (edt-bind-function-key-default "PF2"
2268 'edt-electric-keypad-help 'describe-function)
2269 (edt-bind-function-key-default "PF3" 'edt-find-next 'edt-find)
2270 (edt-bind-function-key-default "PF4" 'edt-delete-line 'edt-undelete-line)
2272 ;; VT100/VT200/VT300 Arrow Keys
2273 (edt-bind-function-key-default "UP" 'edt-previous-line 'edt-window-top)
2274 (edt-bind-function-key-default "DOWN" 'edt-next-line 'edt-window-bottom)
2275 (edt-bind-function-key-default "LEFT" 'backward-char 'edt-sentence-backward)
2276 (edt-bind-function-key-default "RIGHT" 'forward-char 'edt-sentence-forward)
2278 ;; VT100/VT200/VT300 Keypad Keys
2279 (edt-bind-function-key-default "KP0" 'edt-line 'open-line)
2280 (edt-bind-function-key-default "KP1" 'edt-word 'edt-change-case)
2281 (edt-bind-function-key-default "KP2"
2282 'edt-end-of-line 'edt-delete-to-end-of-line)
2283 (edt-bind-function-key-default "KP3" 'edt-character 'quoted-insert)
2284 (edt-bind-function-key-default "KP4" 'edt-advance 'edt-bottom)
2285 (edt-bind-function-key-default "KP5" 'edt-backup 'edt-top)
2286 (edt-bind-function-key-default "KP6" 'edt-cut 'yank)
2287 (edt-bind-function-key-default "KP7" 'edt-page 'execute-extended-command)
2288 (edt-bind-function-key-default "KP8" 'edt-sect 'edt-fill-region)
2289 (edt-bind-function-key-default "KP9" 'edt-append 'edt-replace)
2290 (edt-bind-function-key-default "KP-" 'edt-delete-word 'edt-undelete-word)
2291 (edt-bind-function-key-default "KP,"
2292 'edt-delete-character 'edt-undelete-character)
2293 (edt-bind-function-key-default "KPP" 'edt-select 'edt-reset)
2294 (edt-bind-function-key-default "KPE" 'other-window 'edt-substitute)
2296 ;; VT200/VT300 Function Keys
2297 ;; (F1 through F5, on the VT220, are not programmable, so we skip
2298 ;; making default bindings to those keys.
2299 (edt-bind-function-key-default "FIND" 'edt-find-next 'edt-find)
2300 (edt-bind-function-key-default "INSERT" 'yank 'edt-key-not-assigned)
2301 (edt-bind-function-key-default "REMOVE" 'edt-cut 'edt-copy)
2302 (edt-bind-function-key-default "SELECT"
2303 'edt-toggle-select 'edt-key-not-assigned)
2304 (edt-bind-function-key-default "NEXT"
2305 'edt-sect-forward 'edt-key-not-assigned)
2306 (edt-bind-function-key-default "PREVIOUS"
2307 'edt-sect-backward 'edt-key-not-assigned)
2308 (edt-bind-function-key-default "F6"
2309 'edt-key-not-assigned 'edt-key-not-assigned)
2310 (edt-bind-function-key-default "F7"
2311 'edt-copy-rectangle 'edt-key-not-assigned)
2312 (edt-bind-function-key-default "F8"
2313 'edt-cut-rectangle-overstrike-mode 'edt-paste-rectangle-overstrike-mode)
2314 (edt-bind-function-key-default "F9"
2315 'edt-cut-rectangle-insert-mode 'edt-paste-rectangle-insert-mode)
2316 (edt-bind-function-key-default "F10" 'edt-cut-rectangle 'edt-paste-rectangle)
2317 ;; Under X, the F11 key can be bound. If using a VT-200 or higher terminal,
2318 ;; the default emacs terminal support causes the VT F11 key to seem as if it
2319 ;; is an ESC key when in emacs.
2320 (edt-bind-function-key-default "F11"
2321 'edt-key-not-assigned 'edt-key-not-assigned)
2322 (edt-bind-function-key-default "F12"
2323 'edt-beginning-of-line 'delete-other-windows) ;BS
2324 (edt-bind-function-key-default "F13"
2325 'edt-delete-to-beginning-of-word 'edt-key-not-assigned) ;LF
2326 (edt-bind-function-key-default "F14"
2327 'edt-key-not-assigned 'edt-key-not-assigned)
2328 (edt-bind-function-key-default "HELP"
2329 'edt-electric-keypad-help 'edt-key-not-assigned)
2330 (edt-bind-function-key-default "DO"
2331 'execute-extended-command 'edt-key-not-assigned)
2332 (edt-bind-function-key-default "F17"
2333 'edt-key-not-assigned 'edt-key-not-assigned)
2334 (edt-bind-function-key-default "F18"
2335 'edt-key-not-assigned 'edt-key-not-assigned)
2336 (edt-bind-function-key-default "F19"
2337 'edt-key-not-assigned 'edt-key-not-assigned)
2338 (edt-bind-function-key-default "F20"
2339 'edt-key-not-assigned 'edt-key-not-assigned)
2341 ;; Control key bindings: Regular and GOLD
2343 ;; Standard EDT control key bindings conflict with standard Emacs
2344 ;; control key bindings. Normally, the standard Emacs control key
2345 ;; bindings are left unchanged in the default EDT mode. However, if
2346 ;; the variable edt-use-EDT-control-key-bindings is set to true
2347 ;; before invoking edt-emulation-on for the first time, then the
2348 ;; standard EDT bindings (with some enhancements) as defined here are
2349 ;; used, instead.
2350 (if edt-use-EDT-control-key-bindings
2351 (progn
2352 (edt-bind-key-default "\C-a" 'edt-key-not-assigned)
2353 (edt-bind-key-default "\C-b" 'edt-key-not-assigned)
2354 ;; Leave binding of C-c to an Emacs prefix key.
2355 (edt-bind-key-default "\C-d" 'edt-key-not-assigned)
2356 (edt-bind-key-default "\C-e" 'edt-key-not-assigned)
2357 (edt-bind-key-default "\C-f" 'edt-key-not-assigned)
2358 ;; Leave binding of C-g to the Emacs keyboard-quit
2359 (edt-bind-key-default "\C-h" 'edt-beginning-of-line)
2360 (edt-bind-key-default "\C-i" 'edt-tab-insert)
2361 (edt-bind-key-default "\C-j" 'edt-delete-to-beginning-of-word)
2362 (edt-bind-key-default "\C-k" 'edt-define-key)
2363 (edt-bind-gold-key-default "\C-k" 'edt-restore-key)
2364 (edt-bind-key-default "\C-l" 'edt-form-feed-insert)
2365 ;; Leave binding of C-m to newline.
2366 (edt-bind-key-default "\C-n" 'edt-set-screen-width-80)
2367 (edt-bind-key-default "\C-o" 'edt-key-not-assigned)
2368 (edt-bind-key-default "\C-p" 'edt-key-not-assigned)
2369 (edt-bind-key-default "\C-q" 'edt-key-not-assigned)
2370 ;; Leave binding of C-r to isearch-backward.
2371 ;; Leave binding of C-s to isearch-forward.
2372 (edt-bind-key-default "\C-t" 'edt-display-the-time)
2373 (edt-bind-key-default "\C-u" 'edt-delete-to-beginning-of-line)
2374 (edt-bind-key-default "\C-v" 'redraw-display)
2375 (edt-bind-key-default "\C-w" 'edt-set-screen-width-132)
2376 ;; Leave binding of C-x as original prefix key.
2377 (edt-bind-key-default "\C-y" 'edt-key-not-assigned)
2378 ;; Leave binding of C-z to suspend-emacs.
2382 ;; GOLD bindings for a few keys.
2383 (edt-bind-gold-key-default "\C-g" 'keyboard-quit); Just in case.
2384 (edt-bind-gold-key-default "\C-h" 'help-for-help); Just in case.
2385 (edt-bind-gold-key-default [f1] 'help-for-help)
2386 (edt-bind-gold-key-default [help] 'help-for-help)
2387 (edt-bind-gold-key-default "\C-\\" 'split-window-below)
2389 ;; GOLD bindings for regular keys.
2390 (edt-bind-gold-key-default "a" 'edt-key-not-assigned)
2391 (edt-bind-gold-key-default "A" 'edt-key-not-assigned)
2392 (edt-bind-gold-key-default "b" 'buffer-menu)
2393 (edt-bind-gold-key-default "B" 'buffer-menu)
2394 (edt-bind-gold-key-default "c" 'compile)
2395 (edt-bind-gold-key-default "C" 'compile)
2396 (edt-bind-gold-key-default "d" 'delete-window)
2397 (edt-bind-gold-key-default "D" 'delete-window)
2398 (edt-bind-gold-key-default "e" 'edt-exit)
2399 (edt-bind-gold-key-default "E" 'edt-exit)
2400 (edt-bind-gold-key-default "f" 'find-file)
2401 (edt-bind-gold-key-default "F" 'find-file)
2402 (edt-bind-gold-key-default "g" 'find-file-other-window)
2403 (edt-bind-gold-key-default "G" 'find-file-other-window)
2404 (edt-bind-gold-key-default "h" 'edt-electric-keypad-help)
2405 (edt-bind-gold-key-default "H" 'edt-electric-keypad-help)
2406 (edt-bind-gold-key-default "i" 'insert-file)
2407 (edt-bind-gold-key-default "I" 'insert-file)
2408 (edt-bind-gold-key-default "j" 'edt-key-not-assigned)
2409 (edt-bind-gold-key-default "J" 'edt-key-not-assigned)
2410 (edt-bind-gold-key-default "k" 'edt-toggle-capitalization-of-word)
2411 (edt-bind-gold-key-default "K" 'edt-toggle-capitalization-of-word)
2412 (edt-bind-gold-key-default "l" 'edt-lowercase)
2413 (edt-bind-gold-key-default "L" 'edt-lowercase)
2414 (edt-bind-gold-key-default "m" 'save-some-buffers)
2415 (edt-bind-gold-key-default "M" 'save-some-buffers)
2416 (edt-bind-gold-key-default "n" 'next-error)
2417 (edt-bind-gold-key-default "N" 'next-error)
2418 (edt-bind-gold-key-default "o" 'switch-to-buffer-other-window)
2419 (edt-bind-gold-key-default "O" 'switch-to-buffer-other-window)
2420 (edt-bind-gold-key-default "p" 'edt-key-not-assigned)
2421 (edt-bind-gold-key-default "P" 'edt-key-not-assigned)
2422 (edt-bind-gold-key-default "q" 'edt-quit)
2423 (edt-bind-gold-key-default "Q" 'edt-quit)
2424 (edt-bind-gold-key-default "r" 'revert-buffer)
2425 (edt-bind-gold-key-default "R" 'revert-buffer)
2426 (edt-bind-gold-key-default "s" 'save-buffer)
2427 (edt-bind-gold-key-default "S" 'save-buffer)
2428 (edt-bind-gold-key-default "t" 'edt-key-not-assigned)
2429 (edt-bind-gold-key-default "T" 'edt-key-not-assigned)
2430 (edt-bind-gold-key-default "u" 'edt-uppercase)
2431 (edt-bind-gold-key-default "U" 'edt-uppercase)
2432 (edt-bind-gold-key-default "v" 'find-file-other-window)
2433 (edt-bind-gold-key-default "V" 'find-file-other-window)
2434 (edt-bind-gold-key-default "w" 'write-file)
2435 (edt-bind-gold-key-default "W" 'write-file)
2436 (edt-bind-gold-key-default "x" 'edt-key-not-assigned)
2437 (edt-bind-gold-key-default "X" 'edt-key-not-assigned)
2438 (edt-bind-gold-key-default "y" 'edt-emulation-off)
2439 (edt-bind-gold-key-default "Y" 'edt-emulation-off)
2440 (edt-bind-gold-key-default "z" 'edt-switch-global-maps)
2441 (edt-bind-gold-key-default "Z" 'edt-switch-global-maps)
2442 (edt-bind-gold-key-default "1" 'delete-other-windows)
2443 (edt-bind-gold-key-default "!" 'edt-key-not-assigned)
2444 (edt-bind-gold-key-default "2" 'edt-split-window)
2445 (edt-bind-gold-key-default "@" 'edt-key-not-assigned)
2446 (edt-bind-gold-key-default "3" 'edt-key-not-assigned)
2447 (edt-bind-gold-key-default "#" 'edt-key-not-assigned)
2448 (edt-bind-gold-key-default "4" 'edt-key-not-assigned)
2449 (edt-bind-gold-key-default "$" 'edt-key-not-assigned)
2450 (edt-bind-gold-key-default "5" 'edt-key-not-assigned)
2451 (edt-bind-gold-key-default "%" 'edt-goto-percentage)
2452 (edt-bind-gold-key-default "6" 'edt-key-not-assigned)
2453 (edt-bind-gold-key-default "^" 'edt-key-not-assigned)
2454 (edt-bind-gold-key-default "7" 'edt-key-not-assigned)
2455 (edt-bind-gold-key-default "&" 'edt-key-not-assigned)
2456 (edt-bind-gold-key-default "8" 'edt-key-not-assigned)
2457 (edt-bind-gold-key-default "*" 'edt-key-not-assigned)
2458 (edt-bind-gold-key-default "9" 'edt-key-not-assigned)
2459 (edt-bind-gold-key-default "(" 'edt-key-not-assigned)
2460 (edt-bind-gold-key-default "0" 'edt-key-not-assigned)
2461 (edt-bind-gold-key-default ")" 'edt-key-not-assigned)
2462 (edt-bind-gold-key-default " " 'undo)
2463 (edt-bind-gold-key-default "," 'edt-key-not-assigned)
2464 (edt-bind-gold-key-default "<" 'edt-key-not-assigned)
2465 (edt-bind-gold-key-default "." 'edt-key-not-assigned)
2466 (edt-bind-gold-key-default ">" 'edt-key-not-assigned)
2467 (edt-bind-gold-key-default "/" 'query-replace)
2468 (edt-bind-gold-key-default "?" 'edt-key-not-assigned)
2469 (edt-bind-gold-key-default "\\" 'edt-key-not-assigned)
2470 (edt-bind-gold-key-default "|" 'edt-key-not-assigned)
2471 (edt-bind-gold-key-default ";" 'edt-key-not-assigned)
2472 (edt-bind-gold-key-default ":" 'edt-key-not-assigned)
2473 (edt-bind-gold-key-default "'" 'edt-key-not-assigned)
2474 (edt-bind-gold-key-default "\"" 'edt-key-not-assigned)
2475 (edt-bind-gold-key-default "-" 'edt-key-not-assigned)
2476 (edt-bind-gold-key-default "_" 'edt-key-not-assigned)
2477 (edt-bind-gold-key-default "=" 'goto-line)
2478 (edt-bind-gold-key-default "+" 'edt-key-not-assigned)
2479 (edt-bind-gold-key-default "[" 'edt-key-not-assigned)
2480 (edt-bind-gold-key-default "{" 'edt-key-not-assigned)
2481 (edt-bind-gold-key-default "]" 'edt-key-not-assigned)
2482 (edt-bind-gold-key-default "}" 'edt-key-not-assigned)
2483 (edt-bind-gold-key-default "`" 'what-line)
2484 (edt-bind-gold-key-default "~" 'edt-key-not-assigned)
2488 ;;; DEFAULT EDT KEYPAD HELP
2492 ;; Upper case commands in the keypad diagram below indicate that the
2493 ;; emulation should look and feel very much like EDT. Lower case
2494 ;; commands are enhancements and/or additions to the EDT keypad
2495 ;; commands or are native Emacs commands.
2498 (defun edt-keypad-help ()
2499 "DEFAULT EDT Keypad Active.
2501 F7: Copy Rectangle +----------+----------+----------+----------+
2502 F8: Cut Rect Overstrike |Prev Line |Next Line |Bkwd Char |Frwd Char |
2503 G-F8: Paste Rect Overstrike | (UP) | (DOWN) | (LEFT) | (RIGHT) |
2504 F9: Cut Rect Insert |Window Top|Window Bot|Bkwd Sent |Frwd Sent |
2505 G-F9: Paste Rect Insert +----------+----------+----------+----------+
2506 F10: Cut Rectangle
2507 G-F10: Paste Rectangle
2508 F11: ESC
2509 F12: Beginning of Line +----------+----------+----------+----------+
2510 G-F12: Delete Other Windows | GOLD | HELP | FNDNXT | DEL L |
2511 F13: Delete to Begin of Word | (PF1) | (PF2) | (PF3) | (PF4) |
2512 HELP: Keypad Help |Mark Wisel|Desc Funct| FIND | UND L |
2513 G-HELP: Emacs Help +----------+----------+----------+----------+
2514 DO: Execute extended command | PAGE | SECT | APPEND | DEL W |
2515 C-g: Keyboard Quit | (7) | (8) | (9) | (-) |
2516 G-C-g: Keyboard Quit |Ex Ext Cmd|Fill Regio| REPLACE | UND W |
2517 C-h: Beginning of Line +----------+----------+----------+----------+
2518 G-C-h: Emacs Help | ADVANCE | BACKUP | CUT | DEL C |
2519 C-i: Tab Insert | (4) | (5) | (6) | (,) |
2520 C-j: Delete to Begin of Word | BOTTOM | TOP | Yank | UND C |
2521 C-k: Define Key +----------+----------+----------+----------+
2522 G-C-k: Restore Key | WORD | EOL | CHAR | Next |
2523 C-l: Form Feed Insert | (1) | (2) | (3) | Window |
2524 C-n: Set Screen Width 80 | CHNGCASE | DEL EOL |Quoted Ins| !
2525 C-r: Isearch Backward +---------------------+----------+ (ENTER) |
2526 C-s: Isearch Forward | LINE | SELECT | !
2527 C-t: Display the Time | (0) | (.) | SUBS |
2528 C-u: Delete to Begin of Line | Open Line | RESET | |
2529 C-v: Redraw Display +---------------------+----------+----------+
2530 C-w: Set Screen Width 132
2531 C-z: Suspend Emacs +----------+----------+----------+
2532 G-C-\\: Split Window | FNDNXT | Yank | CUT |
2533 | (FIND) | (INSERT) | (REMOVE) |
2534 G-b: Buffer Menu | FIND | | COPY |
2535 G-c: Compile +----------+----------+----------+
2536 G-d: Delete Window |SELECT/RES|SECT BACKW|SECT FORWA|
2537 G-e: Exit | (SELECT) |(PREVIOUS)| (NEXT) |
2538 G-f: Find File | | | |
2539 G-g: Find File Other Window +----------+----------+----------+
2540 G-h: Keypad Help
2541 G-i: Insert File
2542 G-k: Toggle Capitalization Word
2543 G-l: Downcase Region
2544 G-m: Save Some Buffers
2545 G-n: Next Error
2546 G-o: Switch to Next Window
2547 G-q: Quit
2548 G-r: Revert File
2549 G-s: Save Buffer
2550 G-u: Upcase Region
2551 G-v: Find File Other Window
2552 G-w: Write file
2553 G-y: EDT Emulation OFF
2554 G-z: Switch to User EDT Key Bindings
2555 G-1: Delete Other Windows
2556 G-2: Split Window
2557 G-%: Go to Percentage
2558 G- : Undo (GOLD Spacebar)
2559 G-=: Go to Line
2560 G-`: What line
2561 G-/: Query-Replace"
2563 (interactive)
2564 (describe-function 'edt-keypad-help))
2566 (defun edt-electric-helpify (fun)
2567 (let ((name "*Help*"))
2568 (if (save-window-excursion
2569 (let* ((p (symbol-function 'help-print-return-message))
2570 (b (get-buffer name))
2571 (m (buffer-modified-p b)))
2572 (and b (not (get-buffer-window b))
2573 (setq b nil))
2574 (unwind-protect
2575 (progn
2576 (message "%s..." (capitalize (symbol-name fun)))
2577 (and b
2578 (with-current-buffer b
2579 (set-buffer-modified-p t)))
2580 (fset 'help-print-return-message 'ignore)
2581 (call-interactively fun)
2582 (and (get-buffer name)
2583 (get-buffer-window (get-buffer name))
2584 (or (not b)
2585 (not (eq b (get-buffer name)))
2586 (not (buffer-modified-p b)))))
2587 (fset 'help-print-return-message p)
2588 (and b (buffer-name b)
2589 (with-current-buffer b
2590 (set-buffer-modified-p m))))))
2591 (with-electric-help 'delete-other-windows name t))))
2593 (defun edt-electric-keypad-help ()
2594 "Display default EDT bindings."
2595 (interactive)
2596 (edt-electric-helpify 'edt-keypad-help))
2598 (defun edt-electric-user-keypad-help ()
2599 "Display user custom EDT bindings."
2600 (interactive)
2601 (edt-electric-helpify 'edt-user-keypad-help))
2604 ;;; EDT emulation screen width commands.
2606 ;; Some terminals require modification of terminal attributes when
2607 ;; changing the number of columns displayed, hence the fboundp tests
2608 ;; below. These functions are defined in the corresponding terminal
2609 ;; specific file, if needed.
2611 (defun edt-set-screen-width-80 ()
2612 "Set screen width to 80 columns."
2613 (interactive)
2614 (if (fboundp 'edt-set-term-width-80)
2615 (edt-set-term-width-80))
2616 (set-frame-width nil 80)
2617 (message "Terminal width 80"))
2619 (defun edt-set-screen-width-132 ()
2620 "Set screen width to 132 columns."
2621 (interactive)
2622 (if (fboundp 'edt-set-term-width-132)
2623 (edt-set-term-width-132))
2624 (set-frame-width nil 132)
2625 (message "Terminal width 132"))
2627 (provide 'edt)
2629 ;;; edt.el ends here