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