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