home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / modes / dw-edt < prev    next >
Encoding:
Internet Message Format  |  1990-07-22  |  31.5 KB

  1. From: wickham@decwet.enet.dec.com (Charlie Wickham, DECWest Engr.)
  2. Newsgroups: gnu.emacs.bug
  3. Subject: improved EDT emulation and keypad support for x11term.c
  4. Message-ID: <8907181803.AA18784@decwrl.dec.com>
  5. Date: 18 Jul 89 15:03:00 GMT
  6. Distribution: gnu
  7. Organization: GNUs Not Usenet
  8. Lines: 948
  9.  
  10. Hi....
  11.  
  12. Here is a new, more faithful version of an emulated EDT. Development
  13. was based on the original EDT released with GNU. This version works
  14. with 18.52 and 18.53. We added code to x11term.c to support the LK201
  15. keypad and its google of keys.
  16.  
  17. There are 3 parts: stuff for your .emacs, the lisp code, and context diffs
  18. for x11term.c to support the keypad keys. The diffs are for 18.52. The
  19. parts are separated by lines of `='. The last two patches in the diff fix a
  20. problem with decwindows on VMS: VMS DWs really wants the formal parameter
  21. to XOpenDisplay to be NULL (zero and not a pointer to a null string). This
  22. fix works on both ultrix and vms.
  23.  
  24. No documentation is available; we should probably write a texinfo
  25. file, but don't hold your breath. :-)
  26.  
  27. Sorry if this is the wrong account to send new features to; I
  28. couldn't figure out if I should have sent this directly to Stallman or
  29. to the bugs address. oh well....
  30.  
  31. charlie
  32. internet: wickham@decwet.enet.dec.com
  33. =====================================================
  34. ; Init file for GNU Emacs
  35. ;
  36. (load "dw-edt" )         ;** Comment out of you don't want our edt-mode
  37. ;
  38. ; vt200 keypad stuff
  39. ;
  40. (defun vt200-app-keypad-on ()
  41.    "Send the escape sequence to turn Vt200 application keypad on."
  42.    (interactive)
  43.    (send-string-to-terminal "\e>")
  44. )
  45.  
  46. (defun vt200-app-keypad-off ()
  47.    "Send the escape sequence to turn Vt200 application keypad off."
  48.    (interactive)
  49.    (send-string-to-terminal "\e=")
  50. )
  51. ;
  52. ; Other hooks
  53. (setq suspend-hook ; this gets executed on ^z-like suspend
  54.    (function (lambda ()
  55.       ;+ add code here to be executed when suspending
  56.       (vt200-app-keypad-on)
  57.       ;
  58.       (message "Emacs Suspending!")
  59.       (not (sit-for 0)))))
  60.  
  61. (setq suspend-resume-hook ; this gets executed when resuming from ^z
  62.    (function (lambda ()
  63.       ;+ add code here to be executed when resuming
  64.       (vt200-app-keypad-off)
  65.       ;
  66.       (message (concat "Current default directory is " default-directory))
  67.       (not (sit-for 0)))))
  68.  
  69.  
  70. ; This hook is where you set up changes you want on startup
  71. ;
  72. (setq term-setup-hook           ;!!
  73.    (function (lambda ()           ;!!
  74.       (vt200-app-keypad-off)       ;!! makes Keypad give ESC seq's vs numbers
  75.       (enable-arrow-keys)          ;** Enable arrow keys 
  76.       (edt-emulation-on)           ;** Enables EDT-like bindings
  77.       (vms-screen-editing-keys-on) ;** Enables VMS-like ^a,^b,^e,^u etc.
  78.       )))                          ;!!
  79. =========================================================
  80. ;; dw-edt.el
  81. ;; modified version of GNU Emacs emacs_library:[lisp]edt.el
  82. ;; David W. Snow 10/28/88
  83. ;; Benn Schreiber 12/16/88
  84. ;;
  85. ;; David W. Snow 1/31/89 moved items from .emacs to here to
  86. ;; simplify users getting started on Emacs, also made arrow and edit
  87. ;; keys look more like TPU than EDT also changed the PF3 search function
  88. ;; from isearch to somthing that looks more like EDT.
  89. ;; Since the gold-grey keys have a bug I currently have the grey-find
  90. ;; key bound to isearch. Added "two" & "one" commands like TPU
  91. ;; Added TPU-like "include" to include a file.
  92. ;;
  93. ;; F20 is bound to toggle VMS Line Editing Keys ^a,^e,^u,^w etc.
  94. ;; between VMS usage and emacs usage,
  95. ;;
  96. ;; David W. Snow 2/6/89
  97. ;; Changed Gold-3 to be quote, which is similar to EDT's specins
  98. ;;
  99. ;; R. Kim Peterson 2/20/89 changed gold left and right arrows to be indentation
  100. ;;
  101. ;; R. Kim Peterson 2/3/89 changed operation of word operations to more closely 
  102. mimic edt.
  103. ;; Note: word operations do not use argument-count.
  104. ;; Changed undelete char, word, and line to maintain current position.
  105. ;;
  106.    (setq dws-edt "0.33") ; version 
  107. ;
  108. ;
  109. ;;---------------------------------------------------------------
  110. ;; Copyright (C) 1986 Free Software Foundation, Inc.
  111. ;;  It started from public domain code by Mike Clarkson
  112. ;;  but has been greatly altered.
  113.  
  114. ;; This file is part of GNU Emacs.
  115.  
  116. ;; GNU Emacs is distributed in the hope that it will be useful,
  117. ;; but WITHOUT ANY WARRANTY.  No author or distributor
  118. ;; accepts responsibility to anyone for the consequences of using it
  119. ;; or for whether it serves any particular purpose or works at all,
  120. ;; unless he says so in writing.  Refer to the GNU Emacs General Public
  121. ;; License for full details.
  122.  
  123. ;; Everyone is granted permission to copy, modify and redistribute
  124. ;; GNU Emacs, but only under the conditions described in the
  125. ;; GNU Emacs General Public License.   A copy of this license is
  126. ;; supposed to have been given to you along with GNU Emacs so you
  127. ;; can know your rights and responsibilities.  It should be in a
  128. ;; file named COPYING.  Among other things, the copyright notice
  129. ;; and this notice must be preserved on all copies.
  130. ;;
  131. ;; Bug with GOLD EDT keypad fixed by temp hack to use LK201 codes --- dws
  132. ;;
  133. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  134. ;; Several changes made to make GOLD function keys work, and the
  135. ;; keypad to look more like EDT or TPU in EDT mode.
  136. ;; New functions added include:
  137. ;;       (toggle-screen-width) Which switches from 80 to 132 column and back
  138. ;;       (delete-to-bol) Which acts like DEC's ^u
  139. ;;       (vms-screen-editing-keys-on) for ^a^b^e^u^w^l
  140. ;;       (exit-emacs) more like exit in TPU/EDT
  141. ;;       (toggle-overwrite-mode) toggle between insert/overstrike mode
  142. ;;       (insert-ff) insert a form feed
  143. ;;
  144.  
  145. (require 'keypad)
  146.  
  147. (defvar edt-last-deleted-lines ""
  148.   "Last text deleted by an EDT emulation line-delete command.")
  149. (defvar edt-last-deleted-words ""
  150.   "Last text deleted by an EDT emulation word-delete command.")
  151. (defvar edt-last-deleted-chars ""
  152.   "Last text deleted by an EDT emulation character-delete command.")
  153. (defvar edt-search-string ""
  154.   "Last string searched for by edt-like search command.")
  155.  
  156. (defun forward-to-word (num)
  157.   "Move to next word-beginning."
  158.   (interactive "p")
  159.   (if (or (char-equal (char-syntax (following-char)) ?w) (char-equal 
  160. (char-syntax (following-char)) ?_))
  161.     (forward-word 2)
  162.     (forward-word 1))
  163.   (forward-word -1))
  164.  
  165. (defun backward-to-word (num)
  166.   "Move back to word-beginning."
  167.   (interactive "p")
  168.   (if (and
  169.        (or (char-equal (char-syntax (preceding-char)) ?w) (char-equal 
  170. (char-syntax (preceding-char)) ?_))
  171.        (or (char-equal (char-syntax (following-char)) ?w) (char-equal 
  172. (char-syntax (following-char)) ?_)))
  173.       (progn (forward-word 1)(forward-word -1))
  174.       (progn (forward-word 1)(forward-word -2))))
  175.  
  176. (defun delete-current-word (num)
  177.   "Delete one or specified number of words after point.
  178. They are saved for the EDT undelete-words command."
  179.   (interactive "p")
  180.   (let ((beg (point)))
  181.     (forward-to-word num)
  182.     (setq edt-last-deleted-words
  183.       (buffer-substring beg (point)))
  184.     (delete-region beg (point))))
  185.  
  186. (defun delete-previous-word (num)
  187.   "Delete one or specified number of words before point.
  188. They are saved for the EDT undelete-words command."
  189.   (interactive "p")
  190.   (let ((beg (point)))
  191.     (backward-to-word num)
  192.     (setq edt-last-deleted-words
  193.       (buffer-substring (point) beg))
  194.     (delete-region beg (point))))
  195.  
  196. (defun undelete-words ()
  197.   "Yank words deleted by last EDT word-deletion command and position at 
  198. beginning."
  199.   (interactive)
  200.   (let ((beg (point)))
  201.   (insert edt-last-deleted-words)
  202.   (goto-char beg)))
  203.  
  204. (defun edt-like-search (string)
  205.   "EDT-like prompt and search."
  206.   (interactive "sSearch for: ")
  207.   (setq edt-search-string string)
  208.   (if (string= edt-direction-string " ADVANCE")
  209.       (search-forward edt-search-string)
  210.   ;else
  211.       (search-backward edt-search-string)
  212.   )
  213. )
  214.  
  215. (defun two ()
  216.  "TPU-like split window"
  217.  (interactive)
  218.  (split-window-vertically)
  219.  (setq edt-window-string " MANY")
  220. )
  221.  
  222. (defun one ()
  223.  "TPU-like one window"
  224.  (interactive)
  225.  (delete-other-windows)
  226.  (setq edt-window-string " ONE")
  227. )
  228.  
  229. (defun toggle-window ()
  230.   "TPU-like window toggling mechanism"
  231.   (interactive)
  232.   (if (string= edt-window-string " ONE")
  233.        (split-window-vertically)
  234.   ;else
  235.        (delete-other-windows)
  236.   )
  237.   (if (string= edt-window-string " ONE")
  238.        (setq edt-window-string " MANY")
  239.   ;else
  240.        (setq edt-window-string " ONE")
  241.   )
  242. )
  243.  
  244. (defun include (file)
  245.  "TPU-like include file"
  246.  (interactive "fInclude file:")
  247.  (insert-file file)
  248. )
  249.  
  250. (defun edt-like-research ()
  251.   "EDT-like prompt and search, to repeat the search."
  252.   (interactive)
  253.   (if (string= edt-direction-string " ADVANCE")
  254.       (search-forward edt-search-string)
  255.   ;else
  256.       (search-backward edt-search-string)
  257.   )
  258. )
  259.  
  260. (defun delete-current-line (num)
  261.   "Delete one or specified number of lines after point.
  262. This includes the newline character at the end of each line.
  263. They are saved for the EDT undelete-lines command."
  264.   (interactive "p")
  265.   (let ((beg (point)))
  266.     (forward-line num)
  267.     (if (not (eq (preceding-char) ?\n))
  268.     (insert "\n"))
  269.     (setq edt-last-deleted-lines
  270.       (buffer-substring beg (point)))
  271.     (delete-region beg (point))))
  272.  
  273. (defun delete-to-eol (num)
  274.   "Delete text up to end of line.
  275. With argument, delete up to to Nth line-end past point.
  276. They are saved for the EDT undelete-lines command."
  277.   (interactive "p")
  278.   (let ((beg (point)))
  279.     (forward-char 1)
  280.     (end-of-line num)
  281.     (setq edt-last-deleted-lines
  282.       (buffer-substring beg (point)))
  283.     (delete-region beg (point))))
  284.  
  285. (defun delete-current-char (num)
  286.   "Delete one or specified number of characters after point.
  287. They are saved for the EDT undelete-chars command."
  288.   (interactive "p")
  289.   (setq edt-last-deleted-chars
  290.     (buffer-substring (point) (min (point-max) (+ (point) num))))
  291.   (delete-region (point) (min (point-max) (+ (point) num))))
  292.  
  293. (defun delete-previous-char (num)
  294.   "Delete one or specified number of characters before point.
  295. They are saved for the EDT undelete-chars command."
  296.   (interactive "p")
  297.   (setq edt-last-deleted-chars
  298.     (buffer-substring (max (point-min) (- (point) num)) (point)))
  299.   (delete-region (max (point-min) (- (point) num)) (point)))
  300.  
  301. (defun undelete-lines ()
  302.   "Yank lines deleted by last EDT line-deletion command."
  303.   (interactive)
  304.   (let ((beg (point)))
  305.     (insert edt-last-deleted-lines)
  306.     (goto-char beg)))
  307.  
  308. (defun undelete-chars ()
  309.   "Yank characters deleted by last EDT character-deletion command."
  310.   (interactive)
  311.   (let ((beg (point)))
  312.     (insert edt-last-deleted-chars)
  313.     (goto-char beg)))
  314.  
  315. (defun next-end-of-line (num)
  316.   "Move to end of line; if at end, move to end of next line.
  317. Accepts a prefix argument for the number of lines to move."
  318.   (interactive "p")
  319.   (forward-char)
  320.   (end-of-line num))
  321.  
  322. (defun previous-end-of-line (num)
  323.   "Move EOL upward.
  324. Accepts a prefix argument for the number of lines to move."
  325.   (interactive "p")
  326.   (end-of-line (- 1 num)))
  327.  
  328. (defun backward-line (num)
  329.   "Move point to start of previous line.
  330. Prefix argument serves as repeat-count."
  331.   (interactive "p")
  332.   (forward-line (- num)))
  333.  
  334. (defun scroll-window-down (num)
  335.   "Scroll the display down a window-full.
  336. Accepts a prefix argument for the number of window-fulls to scroll."
  337.   (interactive "p")
  338.   (scroll-down (- (* (window-height) num) 2)))
  339.  
  340. (defun scroll-window-up (num)
  341.   "Scroll the display up a window-full.
  342. Accepts a prefix argument for the number of window-fulls to scroll."
  343.   (interactive "p")
  344.   (scroll-up (- (* (window-height) num) 2)))
  345.  
  346. (defun next-paragraph (num)
  347.   "Move to beginning of the next indented paragraph.
  348. Accepts a prefix argument for the number of paragraphs."
  349.   (interactive "p")
  350.   (while (> num 0)
  351.     (next-line 1)
  352.     (forward-paragraph)
  353.     (previous-line 1)
  354.     (if (eolp) (next-line 1))
  355.     (setq num (1- num))))
  356.  
  357. (defun previous-paragraph (num)
  358.   "Move to beginning of previous indented paragraph.
  359. Accepts a prefix argument for the number of paragraphs."
  360.   (interactive "p")
  361.   (while (> num 0)
  362.     (backward-paragraph)
  363.     (previous-line 1)
  364.     (if (eolp) (next-line 1))
  365.     (setq num (1- num))))
  366.  
  367. (defun move-to-beginning ()
  368.   "Move cursor to the beginning of buffer, but don't set the mark."
  369.   (interactive)
  370.   (goto-char (point-min)))
  371.  
  372. (defun move-to-end ()
  373.   "Move cursor to the end of buffer, but don't set the mark."
  374.   (interactive)
  375.   (goto-char (point-max)))
  376.  
  377. (defun goto-percent (perc)
  378.   "Move point to ARG percentage of the buffer."
  379.   (interactive "NGoto-percentage: ")
  380.   (if (or (> perc 100) (< perc 0))
  381.       (error "Percentage %d out of range 0 < percent < 100" perc)
  382.     (goto-char (/ (* (point-max) perc) 100))))
  383.  
  384. (defun update-mode-line ()
  385.   "Make sure mode-line in the current buffer reflects all changes."
  386.   (set-buffer-modified-p (buffer-modified-p))
  387.   (sit-for 0))
  388.  
  389. (defun advance-direction ()
  390.   "Set EDT Advance mode so keypad commands move forward."
  391.   (interactive)
  392.   (setq edt-direction-string " ADVANCE")
  393. ;  I search has been replaced by an edt-like search
  394. ;  (define-key function-keymap "\eOR" 'isearch-forward) ; PF3
  395. ;  (global-set-key  "\eOP\eOR" 'isearch-forward)        ; Gold "PF3"
  396.   (define-key function-keymap "8" 'scroll-window-up)   ; "8"
  397.   (define-key function-keymap "7" 'next-paragraph)     ; "7"
  398.   (define-key function-keymap "1" 'forward-to-word)    ; "1"
  399.   (define-key function-keymap "2" 'next-end-of-line)   ; "2"
  400.   (define-key function-keymap "3" 'forward-char)       ; "3"
  401.   (define-key function-keymap "0" 'forward-line)       ; "0"
  402.   (define-key function-keymap "f" 'isearch-forward)    ; Find
  403.   (update-mode-line))
  404.  
  405. (defun backup-direction ()
  406.   "Set EDT Backup mode so keypad commands move backward."
  407.   (interactive)
  408.   (setq edt-direction-string " BACKUP")
  409. ;  I search has been replaced by an edt-like search
  410. ;  (define-key function-keymap "\eOR" 'isearch-backward); PF3
  411. ;  (global-set-key  "\eOP\eOR" 'isearch-backward)       ; Gold "PF3"
  412.   (define-key function-keymap "8" 'scroll-window-down) ; "8"
  413.   (define-key function-keymap "7" 'backward-page)      ; "7"
  414.   (define-key function-keymap "1" 'backward-to-word)   ; "1"
  415.   (define-key function-keymap "2" 'previous-end-of-line); "2"
  416.   (define-key function-keymap "3" 'backward-char)      ; "3"
  417.   (define-key function-keymap "0" 'backward-line)      ; "0"
  418.   (define-key function-keymap "f" 'isearch-backward)   ; Find
  419.   (update-mode-line))
  420.  
  421. (defun beginning-of-window ()
  422.   "Home cursor to top of window."
  423.   (interactive)
  424.   (move-to-window-line 0))
  425.  
  426. (defun line-to-bottom-of-window ()
  427.   "Move the current line to the top of the window."
  428.   (interactive)
  429.   (recenter -1))
  430.  
  431. (defun line-to-top-of-window ()
  432.   "Move the current line to the top of the window."
  433.   (interactive)
  434.   (recenter 0))
  435.  
  436. (defun case-flip-character (num)
  437.   "Change the case of the character under the cursor.
  438. Accepts a prefix argument of the number of characters to invert."
  439.   (interactive "p")
  440.   (while (> num 0)
  441.     (funcall (if (<= ?a (following-char))
  442.          'upcase-region 'downcase-region)
  443.          (point) (1+ (point)))
  444.     (forward-char 1)
  445.     (setq num (1- num))))
  446.  
  447. (defun indent-or-fill-region ()
  448.   "Fill region in text modes, indent region in programming language modes."
  449.   (interactive)
  450.   (if (string= paragraph-start "^$\\|^ ")
  451.       (indent-region (point) (mark) nil)
  452.     (fill-region (point) (mark))))
  453.  
  454. (defun indent-positive ()
  455.   "Indent region by four in all modes."
  456.   (interactive)
  457.   (if (> (point) (mark))
  458.       (indent-rigidly (mark) (point) 4)
  459.     (indent-rigidly (point) (mark) 4)))
  460.  
  461. (defun indent-negative ()
  462.   "Indent region by negative four in all modes."
  463.   (interactive)
  464.   (if (> (point) (mark))
  465.       (indent-rigidly (mark) (point) -4)
  466.     (indent-rigidly (point) (mark) -4)))
  467.  
  468. (defun mark-section-wisely ()
  469.   "Mark the section in a manner consistent with the major-mode.
  470. Uses mark-defun for emacs-lisp, lisp,
  471. mark-c-function for C,
  472. and mark-paragraph for other modes."
  473.   (interactive)
  474.   (cond  ((eq major-mode 'emacs-lisp-mode)
  475.       (mark-defun))
  476.      ((eq major-mode 'lisp-mode)
  477.       (mark-defun))
  478.      ((eq major-mode 'c-mode)
  479.       (mark-c-function))
  480.      (t (mark-paragraph))))
  481.  
  482. (defun exit-or-kill( )
  483.    "An exit from both recursive and regular modes."
  484.    (interactive)
  485.   (if (not (eq (recursion-depth) 0))
  486.     (exit-recursive-edit)
  487.   ;else
  488.     (save-buffers-kill-emacs)
  489.   )
  490. )
  491.  
  492. (defun quit-emacs ()
  493.    "Exits Emacs by saving buffers and exiting cleanly."
  494.    (interactive)
  495.    (exit-or-kill))
  496.  
  497.  
  498. (defun toggle-screen-width ()
  499.   "Switch a VT200 (and maybe a VT100) between 80 and 132 columns"
  500.   (interactive)
  501.   (if (= (screen-width) 80)
  502.       (progn (send-string-to-terminal "\e[?3h")
  503.          (set-screen-width 132))
  504.     (send-string-to-terminal "\e[?3l")
  505.     (set-screen-width 80))
  506.   (message "Terminal width is now %s." (screen-width)))
  507.  
  508. (defun delete-to-bol (num)
  509.   "Delete text up to beginning of line.
  510. With argument, delete up to to Nth line-end past point.
  511. They are saved for the EDT undelete-lines command."
  512.   (interactive "p")
  513.   (let ((beg (point)))
  514. ;    (forward-char 1)
  515.     (beginning-of-line num)
  516.     (setq edt-last-deleted-lines
  517.       (buffer-substring beg (point)))
  518.     (delete-region beg (point))))
  519.  
  520. (defun toggle-overwrite-mode ()
  521.    "Switches in and out of overwrite mode"
  522.    (interactive)
  523.    (if overwrite-mode
  524.        (overwrite-mode 0)
  525.        (overwrite-mode 1)))
  526.  
  527. (defun insert-ff ()
  528.    "Inserts a form feed"
  529.    (interactive)
  530.    (insert "\f"))
  531. ; Save the state of old VMS keys
  532. ;
  533.    (setq edt-mode-old-c-a (lookup-key global-map "\C-a"))
  534.    (setq edt-mode-old-c-e (lookup-key global-map "\C-e"))
  535.    (setq edt-mode-old-c-h (lookup-key global-map "\C-h"))
  536.    (setq edt-mode-old-c-l (lookup-key global-map "\C-l"))
  537.    (setq edt-mode-old-c-u (lookup-key global-map "\C-u"))
  538.    (setq edt-mode-old-c-w (lookup-key global-map "\C-w"))
  539.  
  540. (defun vms-screen-editing-keys-off ()
  541.     "Returns the key bindings back to original, before
  542. vms-screen-editing-keys-on was done."
  543.     (interactive)
  544.     (global-set-key "\C-a" edt-mode-old-c-a)
  545.     (global-set-key "\C-b" edt-mode-old-c-b)
  546.     (global-set-key "\C-e" edt-mode-old-c-e)
  547.     (global-set-key "\C-h" edt-mode-old-c-h)
  548.     (global-set-key "\C-l" edt-mode-old-c-l)
  549.     (global-set-key "\C-u" edt-mode-old-c-u)
  550.     (global-set-key "\C-w" edt-mode-old-c-w)
  551.     (global-set-key "\e[34~" 'vms-screen-editing-keys-on) ; F20
  552.     (message "VMS  line editing keys are now off!")(sit-for 0)
  553. )
  554.  
  555. (defun vms-screen-editing-keys-on ()
  556.    "Turns on the VMS editing keys ^a,^e,^h,^l,^u,^w Etc. 
  557. and remaps the old binding to GOLD and the old key"
  558.    (interactive)
  559.    ;
  560.    (global-set-key "\eOP\C-a" (lookup-key global-map "\C-a")) ; ^a to Gold ^a
  561.    (global-set-key "\C-a" 'toggle-overwrite-mode)             ; ^a
  562.    ;
  563.    (setq edt-mode-old-c-b (lookup-key global-map "\C-b"))
  564.    (global-set-key "\C-b" 'repeat-complex-command)            ; ^b
  565.    ;
  566.    (global-set-key "\eOP\C-e" (lookup-key global-map "\C-e")) ; ^e to Gold ^e
  567.    (global-set-key "\C-e" 'end-of-line)                       ; ^e
  568.    ;
  569.    ;  Don't want to mess up help
  570. ;   (global-set-key "\eOP\C-h" (lookup-key global-map "\C-h")) ; ^h to Gold ^h
  571. ;   (global-set-key "\C-h" 'beginning-of-line)                 ; ^h
  572.    ;
  573.    (global-set-key "\C-l" (lookup-key global-map "\C-l"))     ; ^l to Gold ^l
  574.    (global-set-key "\C-l" 'insert-ff)                         ; ^l
  575.    ;
  576.    (global-set-key "\eOP\C-u" (lookup-key global-map "\C-u")) ; ^u to Gold ^u
  577.    (global-set-key "\C-u" 'delete-to-bol)                     ; ^u
  578.    ;
  579.    (global-set-key "\C-w" (lookup-key global-map "\C-w"))     ; ^w to Gold ^w
  580.    (global-set-key "\C-w" 'redraw-display)                    ; ^w
  581.    ;   
  582.    (global-set-key "\e[34~" 'vms-screen-editing-keys-off) ; F20
  583.    (message "VMS  line editing keys are now on!")(sit-for 0)
  584.    )   
  585.  
  586.  
  587. ;;; Key Bindings
  588. (defun edt-emulation-on ()
  589.   "Begin emulating DEC's EDT editor.
  590. Certain keys are rebound; including nearly all keypad keys.
  591. Use \\[edt-emulation-off] to undo all rebindings except the keypad keys.
  592. Note that this function does not work if called directly from the .emacs file.
  593. Instead, the .emacs file should do (setq term-setup-hook 'edt-emulation-on)
  594. Then this function will be called at the time when it will work."
  595.   (interactive)
  596.   (advance-direction)
  597.   (setq edt-window-string " ONE")
  598.   (edt-bind-gold-keypad)    ;Must do this *after* $TERM.el is loaded
  599.   (setq edt-mode-old-c-\\ (lookup-key global-map "\C-\\"))
  600.   (global-set-key "\C-\\" 'quoted-insert)
  601.   (setq edt-mode-old-delete (lookup-key global-map "\177"))
  602.   (global-set-key "\177" 'delete-previous-char)      ;"Delete"
  603.   (setq edt-mode-old-lisp-delete (lookup-key emacs-lisp-mode-map "\177"))
  604.   (define-key emacs-lisp-mode-map "\177" 'delete-previous-char) ;"Delete"
  605.   (define-key lisp-mode-map "\177" 'delete-previous-char) ;"Delete"
  606.   (setq edt-mode-old-linefeed (lookup-key global-map "\C-j"))
  607.   (global-set-key "\C-j" 'delete-previous-word)           ;"LineFeed"
  608.   (define-key esc-map "?" 'apropos))                      ;"<ESC>?"
  609.  
  610. (defun edt-emulation-off ()
  611.   "Return from EDT emulation to normal Emacs key bindings.
  612. The keys redefined by \\[edt-emulation-on] are given their old definitions."
  613.   (interactive)
  614.   (setq edt-direction-string nil)
  615.   (setq edt-window-string nil)
  616.   (global-set-key "\C-\\" edt-mode-old-c-\\)
  617.   (global-set-key "\177" edt-mode-old-delete)        ;"Delete"
  618.   (define-key emacs-lisp-mode-map "\177" edt-mode-old-lisp-delete) ;"Delete"
  619.   (define-key lisp-mode-map "\177" edt-mode-old-lisp-delete) ;"Delete"
  620.   (global-set-key "\C-j" edt-mode-old-linefeed))           ;"LineFeed"
  621.  
  622. (define-key function-keymap "u" 'previous-line)        ;Up arrow
  623. (define-key function-keymap "d" 'next-line)        ;down arrow
  624. (define-key function-keymap "l" 'backward-char)        ;left arrow
  625. (define-key function-keymap "r" 'forward-char)        ;right arrow
  626. (define-key function-keymap "h" 'beginning-of-window)    ;home
  627. ;
  628. (define-key function-keymap "I" 'yank)                  ; Insert Here
  629. (define-key function-keymap "k" 'kill-region)           ; Remove
  630. (define-key function-keymap "s" 'set-mark-command)      ; Select
  631. (define-key function-keymap "P" 'scroll-window-down)    ; Prev Screen
  632. (define-key function-keymap "N" 'scroll-window-up)      ; Next Screen
  633. ;
  634. ;(define-key function-keymap "\C-f" ');F6
  635. ;(define-key function-keymap "\C-g" ');F7
  636. ;(define-key function-keymap "\C-h" ');F8
  637. ;(define-key function-keymap "\C-i" ');F9
  638. (define-key function-keymap "\C-j" 'exit-or-kill)           ; F10 (exit)
  639. (define-key function-keymap "\C-l" 'beginning-of-line)        ; F12 (backspace)
  640. (define-key function-keymap "\C-m" 'delete-previous-word)   ; F13 (linefeed) 
  641. (define-key function-keymap "\C-n" 'tab-to-tab-stop)        ; F14
  642.  
  643. (define-key function-keymap "?" 'help-for-help)                ; help
  644. (define-key help-map "\e28~"  'help-for-help)
  645. (define-key function-keymap "\C-q" 'other-window)           ; F17
  646. (define-key function-keymap "\C-r" 'goto-line)              ; F18
  647. (define-key function-keymap "\C-s" 'switch-to-buffer)       ; F19
  648. ;(define-key function-keymap "\C-t" 'toggle-window)         ; F20
  649. (define-key function-keymap "x" 'execute-extended-command)  ; DO
  650.  
  651. ; keys (8,7,1,2,3,0,find) handled in advacnce and back
  652. (define-key function-keymap "\C-b" 'describe-key)    ;PF2
  653. (define-key function-keymap "\C-c" 'edt-like-research)  ;PF3
  654. (define-key function-keymap "\C-d" 'delete-current-line);PF4
  655. (define-key function-keymap "9" 'append-to-buffer)    ;9 keypad key, etc.
  656. (define-key function-keymap "-" 'delete-current-word)
  657. (define-key function-keymap "4" 'advance-direction)
  658. (define-key function-keymap "5" 'backup-direction)
  659. (define-key function-keymap "6" 'kill-region)
  660. (define-key function-keymap "," 'delete-current-char)
  661. (define-key function-keymap "." 'set-mark-command)
  662. (define-key function-keymap "e" 'newline)        ; enter key
  663. (define-key function-keymap "\C-a" 'GOLD-prefix)    ;PF1 ("gold")
  664.  
  665. (setq GOLD-map (make-keymap))
  666. (fset 'GOLD-prefix GOLD-map)
  667.  
  668. (defvar GOLD-map nil
  669.    "GOLD-map maps the function keys on the VT100 keyboard preceeded
  670. by the PF1 key.  GOLD is the ASCII the 7-bit escape sequence <ESC>OP.")
  671.  
  672. (defun define-keypad-key (keymap function-keymap-slot definition)
  673.   (let ((function-key-sequence (function-key-sequence function-keymap-slot)))
  674.     (if function-key-sequence
  675.     (define-key keymap function-key-sequence definition))))
  676.  
  677. ;;Bind GOLD/Keyboard keys
  678.  
  679. (define-key GOLD-map "\C-g"  'keyboard-quit)            ; just for safety
  680. (define-key GOLD-map "\177" 'delete-window)             ;"Delete"
  681. (define-key GOLD-map "\C-m" 'newline-and-indent)        ;"Return"
  682. (define-key GOLD-map " " 'undo)                ;"Spacebar"
  683. (define-key GOLD-map "%" 'goto-percent)                 ; "%"
  684. (define-key GOLD-map "=" 'goto-line)                    ; "="
  685. (define-key GOLD-map "`" 'what-line)                    ; "`"
  686. (define-key GOLD-map "]" 'toggle-screen-width)          ; "]"
  687. ;(define-key GOLD-map "\C-\\" 'split-window-vertically) ; "Control-\"
  688.  
  689. ; GOLD letter combinations:
  690. (define-key GOLD-map "b" 'buffer-menu)                  ; "b"
  691. (define-key GOLD-map "B" 'buffer-menu)                  ; "B"
  692. (define-key GOLD-map "d" 'delete-window)                ; "d"
  693. (define-key GOLD-map "D" 'delete-window)                ; "D"
  694. (define-key GOLD-map "e" 'compile)                      ; "e"
  695. (define-key GOLD-map "E" 'compile)                      ; "E"
  696. (define-key GOLD-map "f" 'find-file)                    ; "f"
  697. (define-key GOLD-map "F" 'find-file)                    ; "F"
  698. (define-key GOLD-map "i" 'insert-file)                  ; "i"
  699. (define-key GOLD-map "I" 'insert-file)                  ; "I"
  700. (define-key GOLD-map "l" 'goto-line)                    ; "l"
  701. (define-key GOLD-map "L" 'goto-line)                    ; "L"
  702. (define-key GOLD-map "m" 'save-some-buffers)        ; "m"
  703. (define-key GOLD-map "M" 'save-some-buffers)        ; "m"
  704. (define-key GOLD-map "n" 'next-error)                           ; "n"
  705. (define-key GOLD-map "N" 'next-error)                           ; "N"
  706. (define-key GOLD-map "o" 'switch-to-buffer-other-window)        ; "o"
  707. (define-key GOLD-map "O" 'switch-to-buffer-other-window)        ; "O"
  708. (define-key GOLD-map "r" 'query-replace)                        ; "r"
  709. (define-key GOLD-map "R" 'query-replace)                        ; "R"
  710. (define-key GOLD-map "s" 'save-buffer)                          ; "s"
  711. (define-key GOLD-map "S" 'save-buffer)                          ; "S"
  712. (define-key GOLD-map "v" 'find-file-other-window)               ; "v"
  713. (define-key GOLD-map "V" 'find-file-other-window)               ; "V"
  714. (define-key GOLD-map "w" 'write-file)                           ; "w"
  715. (define-key GOLD-map "W" 'write-file)                   ; "W"
  716. ;(define-key GOLD-map "z" 'shrink-window)                 ; "z"
  717. ;(define-key GOLD-map "Z" 'shrink-window)                 ; "z"
  718.  
  719. ;Bind GOLD/Keypad keys
  720. (defun edt-bind-gold-keypad ()
  721.   "Define GOLD EDT function on keypad"
  722.   (interactive)
  723.   (global-set-key  "\eOP\eOA" 'line-to-top-of-window)   ; "up-arrow"
  724.   (global-set-key  "\eOP\eOB" 'line-to-bottom-of-window); "down-arrow"
  725.   (global-set-key  "\eOP\eOD" 'indent-negative)         ; "left-arrow"
  726.   (global-set-key  "\eOP\eOC" 'indent-positive)         ; "right-arrow"
  727.   (global-set-key  "\eOP\eOQ" 'describe-function)    ; "PF2"
  728.   (global-set-key  "\eOP\eOR" 'edt-like-search)         ; "PF3"
  729.   (global-set-key  "\eOP\eOS" 'undelete-lines)          ; "PF4"
  730.   (global-set-key  "\eOP\eOp" 'open-line)               ; "0"
  731.   (global-set-key  "\eOP\eOq" 'case-flip-character)     ; "1"
  732.   (global-set-key  "\eOP\eOr" 'delete-to-eol)           ; "2"
  733.   (global-set-key  "\eOP\eOs" 'quote)                   ; "3"
  734.   (global-set-key  "\eOP\eOt" 'move-to-end)             ; "4"
  735.   (global-set-key  "\eOP\eOu" 'move-to-beginning)       ; "5"
  736.   (global-set-key  "\eOP\eOv" 'yank)                    ; "6"
  737.   (global-set-key  "\eOP\eOw" 'execute-extended-command); "7"
  738.   (global-set-key  "\eOP\eOx" 'indent-or-fill-region)   ; "8"
  739.   (global-set-key  "\eOP\eOy" 'replace-regexp)          ; "9"
  740.   (global-set-key  "\eOP\eOm" 'undelete-words)          ; "-"
  741.   (global-set-key  "\eOP\eOl" 'undelete-chars)          ; ","
  742.   (global-set-key  "\eOP\eOn" 'keyboard-quit)           ; "." ;almost a reset
  743.   (global-set-key  "\eOP\eOM" 'query-replace)           ;"ENTER"
  744.   )
  745. ;; Make direction of motion show in mode line
  746. ;; while EDT emulation is turned on.
  747. ;; Note that the keypad is always turned on when in Emacs.
  748. (or (assq 'edt-direction-string minor-mode-alist)
  749.     (setq minor-mode-alist (cons '(edt-direction-string edt-direction-string)
  750.                  minor-mode-alist)))
  751. =============================================================
  752.     
  753. *** x11term.c.orig    Sat Feb  4 14:06:53 1989
  754. --- x11term.c    Tue Jun 20 08:32:48 1989
  755. ***************
  756. *** 1203,1208
  757.           return("-1");
  758.       }
  759.   }
  760.   #endif /* not sun */
  761.       
  762.   internal_socket_read(bufp, numchars)
  763.  
  764. --- 1203,1254 -----
  765.           return("-1");
  766.       }
  767.   }
  768. + /* dws 2/7/89 */
  769. + char *stringKeypadVal(keycode)
  770. +     KeySym keycode;
  771. + {
  772. +     switch (keycode) {
  773. +     case XK_KP_Enter:
  774. +         return("M");
  775. +     case XK_KP_F1:
  776. +         return("P");
  777. +     case XK_KP_F2:
  778. +         return("Q");
  779. +     case XK_KP_F3:
  780. +         return("R");
  781. +     case XK_KP_F4:
  782. +         return("S");
  783. +     case XK_KP_Separator:
  784. +         return("l");
  785. +     case XK_KP_Subtract:
  786. +         return("m");
  787. +     case XK_KP_Decimal:
  788. +         return("n");
  789. +     case XK_KP_0:
  790. +         return("p");
  791. +     case XK_KP_1:
  792. +         return("q");
  793. +     case XK_KP_2:
  794. +         return("r");
  795. +     case XK_KP_3:
  796. +         return("s");
  797. +     case XK_KP_4:
  798. +         return("t");
  799. +     case XK_KP_5:
  800. +         return("u");
  801. +     case XK_KP_6:
  802. +         return("v");
  803. +     case XK_KP_7:
  804. +         return("w");
  805. +     case XK_KP_8:
  806. +         return("x");
  807. +     case XK_KP_9:
  808. +         return("y");
  809. +     default:
  810. +         return ("-1");
  811. +     }
  812. + }
  813. + /* end dws 2/7/89 */
  814.   #endif /* not sun */
  815.   
  816.   internal_socket_read(bufp, numchars)
  817. ***************
  818. *** 1204,1210
  819.       }
  820.   }
  821.   #endif /* not sun */
  822. !     
  823.   internal_socket_read(bufp, numchars)
  824.       register unsigned char *bufp;
  825.       register int numchars;
  826.  
  827. --- 1250,1256 -----
  828.   }
  829.   /* end dws 2/7/89 */
  830.   #endif /* not sun */
  831.   internal_socket_read(bufp, numchars)
  832.       register unsigned char *bufp;
  833.       register int numchars;
  834. ***************
  835. *** 1337,1342
  836.   #endif /* sun */
  837.       nbytes = strlen(mapping_buf);
  838.         }
  839.         else {
  840.       switch (keysym) {
  841.       case XK_Left:
  842.  
  843. --- 1383,1393 -----
  844.   #endif /* sun */
  845.       nbytes = strlen(mapping_buf);
  846.         }
  847. +         else if (IsPFKey(keysym) || IsKeypadKey(keysym)) {
  848. +             strcpy(mapping_buf,"\033O");
  849. +             strcat(mapping_buf,stringKeypadVal(keysym));
  850. +             nbytes = strlen(mapping_buf);
  851. +         }
  852.         else {
  853.       switch (keysym) {
  854.             case XK_Left:
  855. ***************
  856. *** 1339,1345
  857.         }
  858.         else {
  859.       switch (keysym) {
  860. !     case XK_Left:
  861.         strcpy(mapping_buf,"\002");
  862.         nbytes = 1;
  863.         break;
  864.  
  865. --- 1390,1426 -----
  866.           }
  867.         else {
  868.       switch (keysym) {
  869. !           case XK_Left:
  870. !         strcpy(mapping_buf,"\033[D");
  871. !         nbytes = 3;
  872. !         break;
  873. !           case XK_Right:
  874. !         strcpy(mapping_buf,"\033[C");
  875. !         nbytes = 3;
  876. !         break;
  877. !           case XK_Up:
  878. !         strcpy(mapping_buf,"\033[A");
  879. !         nbytes = 3;
  880. !         break;
  881. !           case XK_Down:
  882. !         strcpy(mapping_buf,"\033[B");
  883. !         nbytes = 3;
  884. !         break;
  885. !           case XK_Prior:
  886. !         strcpy(mapping_buf,"\033[5~");
  887. !         nbytes = 4;
  888. !         break;
  889. !           case XK_Next:
  890. !         strcpy(mapping_buf,"\033[6~");
  891. !         nbytes = 4;
  892. !         break;
  893. !           case DXK_Remove:
  894. !         strcpy(mapping_buf,"\033[3~");
  895. !         nbytes = 4;
  896. !         break;
  897. !         } /* switch */
  898. ! /* dws 2/6/89 end of keypad stuff */
  899. ! /* case XK_Left:
  900.         strcpy(mapping_buf,"\002");
  901.         nbytes = 1;
  902.         break;
  903. ***************
  904. *** 1356,1361
  905.         nbytes = 1;
  906.         break;
  907.       }
  908.         }
  909.         if (nbytes) {
  910.       if (event.xkey.state & Mod1Mask)
  911.  
  912. --- 1437,1443 -----
  913.         nbytes = 1;
  914.         break;
  915.       }
  916. + */
  917.         }
  918.         if (nbytes) {
  919.       if (event.xkey.state & Mod1Mask)
  920. ***************
  921. *** 1493,1499
  922.       int  ix;
  923.       
  924.   
  925. !     vardisplay = (alternate_display ? alternate_display : "");
  926.       if (!vardisplay) {
  927.           fprintf (stderr, "DISPLAY environment variable must be set\n");
  928.           exit (-200);
  929.  
  930. --- 1575,1582 -----
  931.       int  ix;
  932.       
  933.   
  934. !     vardisplay = (alternate_display ? alternate_display : 0);
  935. ! /*
  936.       if (!vardisplay) {
  937.           fprintf (stderr, "DISPLAY environment variable must be set\n");
  938.           exit (-200);
  939. ***************
  940. *** 1498,1503
  941.           fprintf (stderr, "DISPLAY environment variable must be set\n");
  942.           exit (-200);
  943.       }
  944.   
  945.       XXdisplay = XOpenDisplay (vardisplay);
  946.       if (XXdisplay == (Display *) 0) {
  947.  
  948. --- 1581,1587 -----
  949.           fprintf (stderr, "DISPLAY environment variable must be set\n");
  950.           exit (-200);
  951.       }
  952. + */
  953.   
  954.       XXdisplay = XOpenDisplay (vardisplay);
  955.       if (XXdisplay == (Display *) 0) {
  956.