Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!steinmetz!moose!mroz From: mroz@moose.steinmetz (peter a mroz) Newsgroups: comp.emacs Subject: Re: Gold key Message-ID: <7597@steinmetz.steinmetz.UUCP> Date: Sun, 11-Oct-87 22:08:47 EDT Article-I.D.: steinmet.7597 Posted: Sun Oct 11 22:08:47 1987 Date-Received: Tue, 13-Oct-87 01:37:05 EDT References: <8710091905.AA10399@ametek.UUCP> Sender: news@steinmetz.steinmetz.UUCP Reply-To: mroz@moose.UUCP (peter a mroz) Organization: General Electric CRD, Schenectady, NY Lines: 566 Keywords: EDT mode Summary: Modified EDT mode that works better than the original In article <8710091905.AA10399@ametek.UUCP> david@ametek.UUCP (David Lim) writes: >I have a vt100 terminal in which I would like to program the Gold key, in >the terminal-independent way as described in keypad.el. > >I tried to do this by simply copying the method in $EMACS/lisp/edt.el >But I haven't been able to get this to work. > . >stuff deleted > . > . This may be of some help. I modified the original edt.el that comes with gnuemacs these days because I had trouble getting the original to work properly. Enjoy, Peter Mroz ----------cut here----------cut here----------cut here----------cut here------- ;; EDT.EL: EDT emulation mode for gnuemacs ;; Copyright (C) 1986 Free Software Foundation, Inc. ;; It started from public domain code by Mike Clarkson ;; but has been greatly altered. ;; This file is part of GNU Emacs. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY. No author or distributor ;; accepts responsibility to anyone for the consequences of using it ;; or for whether it serves any particular purpose or works at all, ;; unless he says so in writing. Refer to the GNU Emacs General Public ;; License for full details. ;; Everyone is granted permission to copy, modify and redistribute ;; GNU Emacs, but only under the conditions described in the ;; GNU Emacs General Public License. A copy of this license is ;; supposed to have been given to you along with GNU Emacs so you ;; can know your rights and responsibilities. It should be in a ;; file named COPYING. Among other things, the copyright notice ;; and this notice must be preserved on all copies. ;; Latest revisions 5/8/87 Peter Mroz: ;; o Disabled on-off capability. When you invoke edt-mode, it's there till ;; you exit emacs. I saw no reason to enable/disable this mode. ;; o Disabled some of the keybindings - the only edt stuff available is the ;; keypad. everything else is gnu emacs. somebody really went wild with ;; gold key bindings in the previous edt emulation. ;; o "Simplified" how the gold key works (maybe!). When you hit the gold ;; key, it sets the value of gold-key-active to t. When you hit another ;; keypad key, that function resets gold-key-active to nil. Modeled after ;; some code I got from Skip Montanaro. If you hit RESET (.) the gold ;; key is deactivated. ;; o Also "simplified" how advance and backup work. When you hit those keys, ;; you set edt-direction to 1 and -1 respectively. The direction is still ;; shown in the mode line as a minor mode. ;; o Added help screen for PF2; GOLD-PF2 performs an apropos. The EDT help ;; screen is kind of sneaky - it only shows on half of the screen. To ;; see the whole thing one has to start learning Gnu Emacs commands! See ;; the definition of edt-map below for the help screen. ;; o The SUBS key (GOLD-ENTER) works differently than it does in EDT. It ;; prompts for everything and then invokes replace-string. ;; o The ENTER key does not work. Use a carriage return. ;; o To invoke edt-mode, either M-x load-file "edt.el" or esc-esc ;; (load "edt") or put it into your .emacs file ;; modified 7/8/87 has ;; o Simplified the helps window and added the means to toggle the GOLD off. ;; o Changed the ENTER key to enter the extended command mode. ;;* * * * * * * * * * * * * * * * * * * * * ;;* * * * * * * Global variables* * * * * * (defvar edt-last-deleted-lines "" "Last text deleted by an EDT emulation line-delete command.") (defvar edt-delete-buffer "edt-delete" "Buffer used by the edt replace command") (defvar edt-find-string "" "search string used by edt fndnxt command") (defvar edt-last-deleted-words "" "Last text deleted by an EDT emulation word-delete command.") (defvar edt-last-deleted-chars "" "Last text deleted by an EDT emulation character-delete command.") (defvar edt-direction '1 "Current direction for gnu emacs edt mode 1=advance, -1=backup") (defvar edt-direction-string " ADVANCE" "Direction of edt commands, shown in the mode line as a minor mode") (defvar gold-key-active nil "Flag to tell whether or not the gold key has been hit") (defvar edt-map nil "maps VT100/VT200 numeric keypad functions to edt-like functions.") ;* * * * * * * * * * * * * * * * * * * * * ; Bind the numeric keypad keys (if (not edt-map) (progn (setq edt-map (make-keymap)) ; normal / gold function (define-key edt-map "P" 'edt-pf1) ; gold key (define-key edt-map "Q" 'edt-pf2) ; help (define-key edt-map "R" 'edt-pf3) ; fndnxt / find (define-key edt-map "S" 'edt-pf4) ; del l / und l (define-key edt-map "w" 'edt-7) ; page / command (define-key edt-map "x" 'edt-8) ; sect / fill (define-key edt-map "y" 'edt-9) ; append / replace (define-key edt-map "m" 'edt-minus) ; del w / und w (define-key edt-map "t" 'edt-4) ; advance / backup (define-key edt-map "u" 'edt-5) ; backup / top (define-key edt-map "v" 'edt-6) ; cut / paste (define-key edt-map "l" 'edt-comma) ; del c / und c (define-key edt-map "q" 'edt-1) ; word / chngcase (define-key edt-map "r" 'edt-2) ; eol / del eol (define-key edt-map "s" 'edt-3) ; char / specins (define-key edt-map "M" 'edt-enter) ; enter / subs (define-key edt-map "p" 'edt-0) ; line / open-line (define-key edt-map "n" 'edt-period))) ; select / reset ;* * * * * * * * * * * * * * * * * * * * * (defun edt-mode () "Emulation of DEC's EDT editor keypad functions. NOTE: THIS IS NOT EDT. +--------+--------+--------+--------+ |PF1 |PF2 |PF3 |PF4 | Ctrl-X b to remove *Help* window. | | | FNDNXT | DEL L | | GOLD | HELP | FIND | UND L | global MEAD key bindings: +--------+--------+--------+--------+ Ctrl-G cancel command |7 |8 |9 |- | Ctrl-Z pause emacs + goto DCL | PAGE | SECT | APPEND | DEL W | Ctrl-L Refresh screen | COMMAND| FILL | REPLACE| UND W | ESC-N Enter NOTES into DIARY +--------+--------+--------+--------+ ESC-Q Quit back to form/menu |4 |5 |6 |, | ESC-R Return to ROOT menu | ADVANCE| BACKUP | CUT | DEL C | ESC-M Enter Browse-Models form | BOTTOM | TOP | PASTE | UND C | ESC-E Enter Browse-Components f. +--------+--------+--------+--------+ Hit HELP for more. |1 |2 |3 |Enter * | For a tutorial on gnu emacs type C-H t | WORD | EOL | CHAR | | |CHNGCASE| DEL EOL| SPECINS| | Box meaning: +------------------+ +--------+--------+--------+ | |keypad key | |0 |. | | | GOLD function | | OPEN LINE | RESET | SUBS | +------------------+ +-----------------+--------+--------+ * NOTE: Use RET in place of ENTER" (interactive) ; disable default binding of esc [ (global-unset-key "\e[") ; VT100 arrow keys (global-set-key "\e[A" 'previous-line) (global-set-key "\e[B" 'next-line) (global-set-key "\e[C" 'forward-char) (global-set-key "\e[D" 'backward-char) (global-set-key "\eOA" 'previous-line) (global-set-key "\eOB" 'next-line) (global-set-key "\eOC" 'forward-char) (global-set-key "\eOD" 'backward-char) ; Create edt's delete buffer (get-buffer-create edt-delete-buffer) ; Make direction of motion show in mode line. Note that in this version ; edt emulation is always on (or (assq 'edt-direction-string minor-mode-alist) (setq minor-mode-alist (cons '(edt-direction-string edt-direction-string) minor-mode-alist))) (define-key global-map "\eO" edt-map) (setq major-mode 'edt-mode) (setq mode-name "EDT") (message "EDT Keypad profile installed.")) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-delete-current-line (num) "Delete one or specified number of lines after point. This includes the newline character at the end of each line. They are saved for the EDT undelete-lines command." (interactive "p") (let ((beg (point))) (forward-line num) (if (not (eq (preceding-char) ?\n)) (insert "\n")) (setq edt-last-deleted-lines (buffer-substring beg (point))) (delete-region beg (point)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-delete-to-eol (num) "Delete text up to end of line. With argument, delete up to to Nth line-end past point. They are saved for the EDT undelete-lines command." (interactive "p") (let ((beg (point))) (forward-char 1) (end-of-line num) (setq edt-last-deleted-lines (buffer-substring beg (point))) (delete-region beg (point)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-delete-current-word (num) "Delete one or specified number of words after or before point, depending on the sign of num. They are saved for the EDT undelete-words command." (interactive "p") (let ((beg (point))) (forward-word num) (setq edt-last-deleted-words (buffer-substring beg (point))) (delete-region beg (point)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-delete-current-char (num) "Delete one or specified number of characters before or after point, depending on the sign of num. They are saved for the EDT undelete-chars command." (interactive "p") (let ((beg (+ (point) num))) ; Make sure beg is a valid spot in the buffer (setq beg (max (point-min) (min (point-max) beg))) (setq edt-last-deleted-chars (buffer-substring (point) beg)) (delete-region (point) beg))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-undelete-lines () "Yank lines deleted by last EDT line-deletion command." (interactive) (insert edt-last-deleted-lines)) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-undelete-words () "Yank words deleted by last EDT word-deletion command." (interactive) (insert edt-last-deleted-words)) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-undelete-chars () "Yank characters deleted by last EDT character-deletion command." (interactive) (insert edt-last-deleted-chars)) ;* * * * * * * * * * * * * * * * * * * * * (defun goto-percent (perc) "Move point to ARG percentage of the buffer." (interactive "NGoto-percentage: ") (if (or (> perc 100) (< perc 0)) (error "Percentage %d out of range 0 < percent < 100" perc) (goto-char (/ (* (point-max) perc) 100)))) ;* * * * * * * * * * * * * * * * * * * * * (defun update-mode-line () "Make sure mode-line in the current buffer reflects all changes." (set-buffer-modified-p (buffer-modified-p)) (sit-for 0)) ;* * * * * * * * * * * * * * * * * * * * * (defun beginning-of-window () "Home cursor to top of window." (interactive) (move-to-window-line 0)) ;* * * * * * * * * * * * * * * * * * * * * (defun line-to-bottom-of-window () "Move the current line to the top of the window." (interactive) (recenter -1)) ;* * * * * * * * * * * * * * * * * * * * * (defun line-to-top-of-window () "Move the current line to the top of the window." (interactive) (recenter 0)) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-case-flip-character (num) "Change the case of the character under the cursor. Accepts a prefix argument of the number of characters to invert." (interactive "p") (while (> num 0) (funcall (if (<= ?a (following-char)) 'upcase-region 'downcase-region) (point) (1+ (point))) (forward-char 1) (setq num (1- num)))) ;* * * * * * * * * * * * * * * * * * * * * (defun indent-or-fill-region () "Fill region in text modes, indent region in programming language modes." (interactive) (if (string= paragraph-start "^$\\|^ ") (indent-region (point) (mark) nil) (fill-region (point) (mark)))) ;* * * * * * * * * * * * * * * * * * * * * (defun mark-section-wisely () "Mark the section in a manner consistent with the major-mode. Uses mark-defun for emacs-lisp, lisp, mark-c-function for C, and mark-paragraph for other modes. This function isn't bound to anything but it is useful" (interactive) (cond ((eq major-mode 'emacs-lisp-mode) (mark-defun)) ((eq major-mode 'lisp-mode) (mark-defun)) ((eq major-mode 'c-mode) (mark-c-function)) (t (mark-paragraph)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-0 (num) "NORMAL: move by a LINE in the current direction GOLD: OPEN LINE" (interactive "p") (if gold-key-active ; OPEN LINE (progn (open-line num) (setq gold-key-active nil)) ; else LINE (forward-line (* edt-direction num)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-1 (num) "NORMAL: move by a WORD in the current direction GOLD: CHNGCASE" (interactive "p") (if gold-key-active ; CHNGCASE (progn (edt-case-flip-character num) (setq gold-key-active nil)) ; else WORD (forward-word (* edt-direction num)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-2 (num) "NORMAL: EOL move to the end of the line GOLD: DEL EOL" (interactive "p") (if gold-key-active ; DEL EOL (progn (edt-delete-to-eol num) (setq gold-key-active nil)) ; else EOL (end-of-line (* edt-direction num)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-3 (num) "NORMAL: move by a CHAR in the current direction GOLD: SPECINS for control characters or octal codes" (interactive "p") (if gold-key-active ; SPECINS (progn (message "SPECINS (hit a control character or enter the octal code): ") (quoted-insert '1) (setq gold-key-active nil)) ; CHAR (forward-char (* edt-direction num)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-4 () "NORMAL: change direction to ADVANCE GOLD: go to the BOTTOM of the file" (interactive) (if gold-key-active ; BOTTOM (progn (goto-char (point-max)) (message "Bottom of file") (setq gold-key-active nil)) ; else ADVANCE (setq edt-direction '1) (setq edt-direction-string " ADVANCE") (update-mode-line))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-5 () "NORMAL: change direction to BACKUP GOLD: go to the TOP of the file" (interactive) (if gold-key-active ; TOP (progn (goto-char (point-min)) (message "Top of file") (setq gold-key-active nil)) ; else BACKUP (setq edt-direction '-1) (setq edt-direction-string " BACKUP") (update-mode-line))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-6 () "NORMAL: CUT from the current position to the mark GOLD: PASTE what was cut starting at the current position. Uses the yank buffer" (interactive) (if gold-key-active ; PASTE (progn (yank) (setq gold-key-active nil)) ; else CUT (kill-region (mark) (point)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-7 (num) "NORMAL: move by a PAGE in the current direction GOLD: COMMAND execute an emacs command. A page is usually delimited by ^L." (interactive "p") (if gold-key-active ; COMMAND (progn (execute-extended-command nil) (setq gold-key-active nil)) ; else PAGE (if (eq edt-direction '1) (forward-page num) (backward-page num)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-8 (num) "NORMAL: move by a SECTion in the current direction GOLD: FILL a text region; indent a program" (interactive "p") (if gold-key-active ; FILL (progn (indent-or-fill-region) (setq gold-key-active nil)) ; else SECT (scroll-up (* edt-direction (- (* (window-height) num) 2))))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-9 (num) "NORMAL: APPEND GOLD: REPLACE text between point and mark with the kill buffer. The APPEND function deletes text between point and mark and appends it to the kill buffer" (interactive "p") (if gold-key-active ; REPLACE (progn (copy-to-buffer edt-delete-buffer (mark) (point)) (delete-region (mark) (point)) (yank) (setq gold-key-active nil)) ; else APPEND (append-next-kill) (kill-region (mark) (point)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-pf1 () "NORMAL: turn on the GOLD key functions GOLD: same" (interactive) (if gold-key-active (progn (message "") (setq gold-key-active nil)) (message "GOLD-") (setq gold-key-active t))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-pf2 () "NORMAL: EDT Help GOLD: apropos on a selected topic - try edt" (interactive) (if gold-key-active (progn (apropos (read-input "Help topic: ")) (setq gold-key-active nil)) ; otherwise display a help screen the way edt does (with-output-to-temp-buffer "*Help*" (princ (documentation 'edt-mode))) (other-window '1) (delete-other-windows) (message "Hit C-X b to remove *Help* window."))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-pf3 () "NORMAL: FNDNXT GOLD: FIND a string in the current direction FNDNXT finds the next occurrence of the find string" (interactive) (if gold-key-active (progn ; FIND (setq edt-find-string (read-input "Search for: ")) (setq gold-key-active nil))) ; FIND and FNDNXT (message (concat "Searching for " "\"" edt-find-string "\"")) (if (eq '1 edt-direction) (search-forward edt-find-string (point-max) nil) (search-backward edt-find-string (point-min) nil))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-pf4 (num) "NORMAL: delete a line GOLD: undelete a line" (interactive "p") (if gold-key-active (progn ; UND L (edt-undelete-lines) (setq gold-key-active nil)) ; DEL L (edt-delete-current-line num))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-period () "NORMAL: SELECT set the mark at the current cursor position GOLD: RESET cancels the effect of the Gold key, sets the current direction to forward" (interactive) (if gold-key-active (progn ; RESET (redraw-display) (setq gold-key-active nil) ; Set the current direction to forward (edt-4)) ; else SELECT by setting the mark (push-mark (point)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-enter () "NORMAL: Enter MEAD COMMAND MODE GOLD: SUBS replace string starting from current position" (interactive) (if gold-key-active (progn ; SUBS (let (old-string new-string) (setq old-string (read-input "Replace string: ")) (setq new-string (read-input (concat "Replace string " old-string " with: "))) (replace-string old-string new-string nil) (setq gold-key-active nil))) ; else the user must hit RET instead of the ENTER key. Sorry . . . (execute-extended-command nil))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-comma (num) "NORMAL: delete a character in current direction GOLD: undelete a character" (interactive "p") (if gold-key-active (progn ; UND C (edt-undelete-chars) (setq gold-key-active nil)) ; DEL C (edt-delete-current-char (* edt-direction num)))) ;* * * * * * * * * * * * * * * * * * * * * (defun edt-minus (num) "NORMAL: delete a word in the current direction GOLD: undelete a word" (interactive "p") (if gold-key-active (progn ; UND W (edt-undelete-words) (setq gold-key-active nil)) ; DEL W (edt-delete-current-word (* edt-direction num)))) Peter Mroz General Electric | ARPA: mroz@ge-crd.arpa Corporate Research and Development | UUCP: mroz@moose.steinmetz.ge.com PO Box 8, 37-2081 | clever saying stuck in here Schenectady, NY 12301 | 518-387-6021