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