goer@quads.uchicago.edu (Richard L. Goerwitz) (03/10/91)
I received several helpful responses in my search for a decent and full
wy50.el file. Here's a "summary" in the form of a wy50.el file which I
pieced together. I confess to considerable ignorance about the internals
of emacs.
-Richard
;
; WY50.EL
;
; This file sets up wy50 function keys and also various editing keys,
; such as Prev/Next PAGE, Home, Line/Char INS, Line/Char DEL,
; Scrn/Line CLR, and Ins/Repl. The editing keys do pretty much what
; their names imply. The function keys are set up pretty logically.
; F1 is help. F2 is switch-to-buffer, F3 other-window, F4 set-mark,
; F5 mark-word, F6 mark-sentence, F7 mark-paragraph, F8 mark-whole-
; buffer. F9 is forward-word, F10 forward-sentence, F11 forward-para-
; graph, F12 end-of-buffer. F13 is isearch-forward-regexp, F14 query-
; replace-regexp. F15 is goto-line. F16 is 80-column-mode. Note
; that shifting the function keys normally gets you a related
; function. For example, F6 is mark-sentence. Shift-F6 is
; kill-sentence. F9 is forward-word. Shift-F6 is backward-word. F13
; is isearch-forward-regexp, and shift-F13 is isarch-backward-regexp.
; Note that F16/shift-F16 toggle you in and out of 132-column mode.
; The arrow keys work as expected.
;
; I assembled this file rather haphazardly out of several that were
; sent to me, including Lynn Slater's wy50.el file, and one written by
; Ph. Baque. Probably any inelegant code you find here was written by
; me :-).
;
; -Richard Goerwitz (goer@sophist.uchicago.edu)
;
;;
;; 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.
(defun start-up-emacs-wyse ()
(global-unset-key "\C-H")
(aset global-map 8 'backward-char) ; make ^H work like left arrow
(aset esc-map 63 'help-command) ; make ESC-? work like ^H used to
(setq-default term-setup-hook 'after-the-beginning)
(setq-default kill-emacs-hook 'this-is-the-end)
)
(start-up-emacs-wyse)
(defvar UP-ARROW "\C-k") (global-set-key UP-ARROW 'previous-line)
(defvar DOWN-ARROW "\C-J") (global-set-key DOWN-ARROW 'next-line) ; LFD
(defvar RIGHT-ARROW "\C-l") (global-set-key RIGHT-ARROW 'forward-char)
(defvar LEFT-ARROW "\C-H") (global-set-key LEFT-ARROW 'backward-char)
(defvar PREV-PAGE "\M-K") (global-set-key PREV-PAGE 'scroll-up)
(defvar NEXT-PAGE "\M-J") (global-set-key NEXT-PAGE 'scroll-down)
(defvar LINE-INS "\M-E") (global-set-key LINE-INS 'open-line)
(defvar LINE-DEL "\M-R") (global-set-key LINE-DEL 'kill-line)
(defvar CHAR-INS "\M-Q") (global-set-key CHAR-INS 'insert-space)
(defvar CHAR-DEL "\M-W") (global-set-key CHAR-DEL 'delete-char)
(defvar CLR-LINE "\M-T") (global-set-key CLR-LINE 'kill-line)
(defvar CLR-SCRN "\M-Y") (global-set-key CLR-SCRN 'recenter)
(defvar INS "\M-q") (global-set-key INS 'overwrite-off)
(defvar REPL "\M-r") (global-set-key REPL 'overwrite-on)
(defvar HOME "\C-^") (global-set-key HOME 'beginning-of-line)
(defun function-key-not-defined ()
"Used to display a message about a function key not being defined."
(interactive)
(beep)
(message "Function key not defined."))
(defun prev-complex-command ()
"Select Previous-complex-command"
(interactive)
(if (zerop (minibuffer-depth))
(repeat-complex-command 1)
(previous-complex-command 1)))
(defun rerun-prev-command ()
"Repeat Previous-complex-command."
(interactive)
(eval (nth 0 command-history)))
;;; user should (setq wy50-esc-bracket nil) in ~/.emacs to preserve
;;; old keybindings
(defvar wy50-esc-bracket t
"If non-nil (the default) the former binding of esc-[ is replaced
and esc-[ becomes the prefix character for wy50 function keys.")
(defvar wy50-setup-softkeys t
"If non-nil (the default) special control sequences are sent to the wy50
to define the softkeys to emacs-compatable meanings.")
(defvar wy50-raw-map (make-sparse-keymap)
"*Keymap for ESC-[ encoded wy50 softkeys")
(defun wy50-softkey (number &optional shiftedp)
"Returns the special unique key associated with the requested
shifted or unshifted softkey. For lack of any better binding,
the values are taken from the wy50 manual, page 4-8."
(let ((index (if shiftedp (+ 16 number) number)))
(substring "@ABCDEFGHIJKLMNO`abcdefghijklmno" (1- index) index)))
(defun wy50-init-softkeys ()
"Initiliazes the wy50 softkeys for emacs bindings."
(interactive)
(let ((i 0)
(char))
(setq wy50-esc-bracket t);; must be there or why bother
(while (< i 32)
(setq char (aref "@ABCDEFGHIJKLMNO`abcdefghijklmno" i))
(send-string-to-terminal (format "z%c[%c" char char))
(setq i (1+ i)))))
(if wy50-setup-softkeys (wy50-init-softkeys))
(if wy50-esc-bracket
(progn
(define-key esc-map "[" wy50-raw-map) ; Install wy50-raw-map
(define-key wy50-raw-map (wy50-softkey 1) 'help-for-help)
(define-key wy50-raw-map (wy50-softkey 1 t) 'Helper-help)
;; note: control softkey1 also sets the mark by fortunate chance
(define-key wy50-raw-map (wy50-softkey 2) 'switch-to-buffer)
(define-key wy50-raw-map (wy50-softkey 2 t) 'switch-to-buffer-other-window)
(define-key wy50-raw-map (wy50-softkey 3) 'other-window)
(define-key wy50-raw-map (wy50-softkey 3 t) 'find-file-other-window)
(define-key wy50-raw-map (wy50-softkey 4) 'set-mark-command)
(define-key wy50-raw-map (wy50-softkey 4 t) 'exchange-point-and-mark)
(define-key wy50-raw-map (wy50-softkey 5) 'mark-word)
(define-key wy50-raw-map (wy50-softkey 5 t) 'kill-word)
(define-key wy50-raw-map (wy50-softkey 6) 'mark-this-sentence)
(define-key wy50-raw-map (wy50-softkey 6 t) 'kill-sentence)
(define-key wy50-raw-map (wy50-softkey 7) 'mark-paragraph)
(define-key wy50-raw-map (wy50-softkey 7 t) 'kill-paragraph)
(define-key wy50-raw-map (wy50-softkey 8) 'mark-whole-buffer)
(define-key wy50-raw-map (wy50-softkey 8 t) 'kill-buffer)
(define-key wy50-raw-map (wy50-softkey 9) 'forward-word)
(define-key wy50-raw-map (wy50-softkey 9 t) 'backward-word)
(define-key wy50-raw-map (wy50-softkey 10) 'forward-sentence)
(define-key wy50-raw-map (wy50-softkey 10 t) 'backward-sentence)
(define-key wy50-raw-map (wy50-softkey 11) 'forward-paragraph)
(define-key wy50-raw-map (wy50-softkey 11 t) 'backward-paragraph)
(define-key wy50-raw-map (wy50-softkey 12) 'end-of-buffer)
(define-key wy50-raw-map (wy50-softkey 12 t) 'beginning-of-buffer)
(define-key wy50-raw-map (wy50-softkey 13) 'isearch-forward-regexp)
(define-key wy50-raw-map (wy50-softkey 13 t) 'isearch-backward-regexp)
(define-key wy50-raw-map (wy50-softkey 14) 'query-replace-regexp)
(define-key wy50-raw-map (wy50-softkey 14 t) 'query-replace-regexp)
(define-key wy50-raw-map (wy50-softkey 15) 'goto-line)
(define-key wy50-raw-map (wy50-softkey 15 t) 'what-line)
(define-key wy50-raw-map (wy50-softkey 16) 'set-80-column-mode)
(define-key wy50-raw-map (wy50-softkey 16 t) 'set-132-column-mode)
))
;;; Since .emacs gets loaded before this file, a hook is supplied
;;; for you to put your own bindings in.
(defvar wy50-softkey-hooks nil
"List of forms to evaluate after setting up the wy50 softkeys.")
(let ((hooks wy50-softkey-hooks))
(while hooks
(eval (car hooks))
(setq hooks (cdr hooks))
))
;-----------------------------------------------------------------------
(defun after-the-beginning ()
; (message-inverse)
(fundamental-mode))
; ----------------------------------------------------------------------
(defun this-is-the-end ()
(send-string-to-terminal "\e*") ;;
; (send-string-to-terminal "\eA30") ;;
(send-string-to-terminal "\e`:") ;; passage systematique en 80 colonnes
)
; ----------------------------------------------------------------------
(defun mark-this-sentence ()
"Put point at beginning of sentence, mark at end."
(interactive)
(forward-sentence)
(set-mark-command nil)
(backward-sentence)
)
; ----------------------------------------------------------------------
(defun insert-space () (interactive)
"Insert a space. It is useful in OverWrite-mode"
(insert-string " "))
;-----------------------------------------------------------------------
(defun overwrite-on () (interactive)
"Put Emacs in OverWrite mode, in this mode you replace any character
you type. "
(overwrite-mode 1))
; -----------------------
(defun overwrite-off ()
"Put Emacs in (natural) Insert mode, in this mode you insert any
character typed."
(interactive) (overwrite-mode -1))
;------------------------
(defun wyse-width-132 () (send-string-to-terminal "\e`;"))
(defun wyse-width-80 () (send-string-to-terminal "\e`:") )
(defun message-normal () (send-string-to-terminal "\eA30"))
(defun message-inverse () (send-string-to-terminal "\eA34"))
(defun message-souligne () (send-string-to-terminal "\eA38"))
;----------------------------------
(defun set-80-column-mode () (interactive)
"Set 80 column mode ..."
(label-wyse-erase)
; (message-souligne)
(wyse-width-80)
(set-screen-width 79)
)
;----------------------------------
(defun set-132-column-mode () (interactive)
"Set 132 column mode ..."
(label-wyse-erase)
; (message-souligne)
(wyse-width-132)
(set-screen-width 131)
)
;----------------------------------------
(defun label-wyse-erase ()
"clear label field"
(send-string-to-terminal "\ez0
(send-string-to-terminal "\ez1
(send-string-to-terminal "\ez2
(send-string-to-terminal "\ez3
(send-string-to-terminal "\ez4
(send-string-to-terminal "\ez5
(send-string-to-terminal "\ez6
(send-string-to-terminal "\ez7
(send-string-to-terminal "\ez8
(send-string-to-terminal "\ez9
(send-string-to-terminal "\ez:
(send-string-to-terminal "\ez;
(send-string-to-terminal "\ez<
(send-string-to-terminal "\ez=
(send-string-to-terminal "\ez>
(send-string-to-terminal "\ez?
(send-string-to-terminal "\ezP
(send-string-to-terminal "\ezQ
(send-string-to-terminal "\ezR
(send-string-to-terminal "\ezS
(send-string-to-terminal "\ezT
(send-string-to-terminal "\ezU
(send-string-to-terminal "\ezV
(send-string-to-terminal "\ezW
(send-string-to-terminal "\ezX
(send-string-to-terminal "\ezY
(send-string-to-terminal "\ezZ
(send-string-to-terminal "\ez[
; (send-string-to-terminal (concat "\ez" ?\ "
(send-string-to-terminal "\ez]
; (send-string-to-terminal (concat "\ez" ?^ "
(send-string-to-terminal "\ez_
)