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