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