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