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